Permalink
Browse files

* added public/download to .gitignore

* completed BackupsController new/show views
* added part in BackupsController create to display error messages (hack)
  • Loading branch information...
1 parent c84c243 commit f1ad26e9cf3929c696e768d2e02ad0d860855eec @hone committed Jan 10, 2009
View
@@ -6,3 +6,4 @@ tags
public/cache/**/*
doc/*
coverage/*
+public/download/*
@@ -8,21 +8,29 @@ def new
end
def create
+ @remote_mail = RemoteMail.new( params[:remote_mail] )
+ # hack needed to display errors
+ @remote_mail.save
@pop3 = Pop3.new( params[:remote_mail] )
- @pop3.setup_mailer
- result = @pop3.download
-
respond_to do |format|
- case result[:status]
- when Pop3::OK_FLAG
- flash[:notice] = "Backup successfully created"
- format.html { redirect_to( :action => :show, :mbox => { :inbox => result[:mbox_name] } ) }
- when Pop3::AUTHENTICATION_ERROR_FLAG
- flash[:notice] = "Could not create backup due to authentication problems"
- format.html { render :action => :new }
- # TODO add stuff here
- when Pop3::TIMEOUT_ERROR_FLAG
- flash[:notice] = "Could not create backup due to timeout error"
+ if @pop3.valid?
+ @pop3.setup_mailer
+ result = @pop3.download
+
+ case result[:status]
+ when Pop3::OK_FLAG
+ flash[:notice] = "Backup successfully created"
+ format.html { redirect_to( :action => :show, :mbox => { :inbox => result[:mbox_name] } ) }
+ when Pop3::AUTHENTICATION_ERROR_FLAG
+ flash[:notice] = "Could not create backup due to authentication problems"
+ format.html { render :action => :new }
+ # TODO add stuff here
+ when Pop3::TIMEOUT_ERROR_FLAG
+ flash[:notice] = "Could not create backup due to timeout error"
+ format.html { render :action => :new }
+ end
+ else
+ flash[:notice] = "Problems with backing up mail, invalid input"
format.html { render :action => :new }
end
end
@@ -0,0 +1,33 @@
+<h1>BackupMyMail</h1>
+
+<% form_for :remote_mail, :url => { :action => :create } do |f| %>
+ <%= f.error_messages %>
+
+ <p>
+ <%= f.label :email_address %>
+ <%= f.text_field :email_address %>
+ </p>
+ <p>
+ <%= f.label :server %>
+ <%= f.text_field :server %>
+ </p>
+ <p>
+ <%= f.label :username %>
+ <%= f.text_field :username %>
+ </p>
+ <p>
+ <%= f.label :password %>
+ <%= f.password_field :password %>
+ </p>
+ <p>
+ <%= f.label :ssl, "SSL" %>
+ <%= f.check_box :ssl %>
+ </p>
+ <p>
+ <%= f.label :port %>
+ <%= f.text_field :port %>
+ </p>
+ <p>
+ <%= f.submit "Backup!" %>
+ </p>
+<% end %>
@@ -0,0 +1,5 @@
+<h1>BackupMyMail Downloads</h1>
+<p>To download, right click on the link and left click on "Save as" or your browser's equivalent."</p>
+<% @downloads.each do |name, filename| %>
+<p><%= link_to name, "/download/#{filename}" %></p>
+<% end %>
@@ -3,6 +3,7 @@
module BackupsControllerSpecHelper
def setup_create( result )
Pop3.should_receive(:new).once.and_return(@pop3)
+ @pop3.should_receive(:valid?).once.and_return(true)
@pop3.should_receive(:setup_mailer).once
@pop3.should_receive(:download).once.and_return( result )
end
@@ -77,6 +78,7 @@ def do_get
before do
@pop3 = mock_model( Pop3 )
Pop3.stub!(:new).and_return(@pop3)
+ @pop3.stub!(:valid).and_return(true)
@params = {
:email_address => 'test.otherinbox@gmail.com',
:server => 'pop.gmail.com',
@@ -105,6 +107,16 @@ def do_post
flash[:notice].should match /success/i
end
+ it "should render new page if invalid RemoteMail" do
+ @params = nil
+ @pop3.should_receive(:valid?).once.and_return(false)
+
+ do_post
+ response.should be_success
+ response.should render_template( :new )
+ flash[:notice].should match /problems/i
+ end
+
it "should show error for authentication problem" do
result =
{
View
@@ -2,14 +2,7 @@
module Pop3SpecHelper
def setup_pop3( opts = {}, setup_mailer = true )
- @valid_attributes = {
- :email_address => 'test.otherinbox@gmail.com',
- :server => 'pop.gmail.com',
- :username => 'test.otherinbox@gmail.com',
- :password => '0th3r1nb0x', # TODO need to encrypt this
- :ssl => true,
- :port => 995
- }.merge( opts )
+ @valid_attributes = valid_pop3_attributes.merge( opts )
@pop3 = Pop3.new
@pop3.attributes = @valid_attributes
View
@@ -60,3 +60,14 @@ def setup_mock_time
Time.stub!(:now).and_return(@time)
@time.stub!(:to_s).and_return( 'Thu Jan 08 01:22:01 -0500 2009' )
end
+
+def valid_pop3_attributes
+ @valid_attributes = {
+ :email_address => 'test.otherinbox@gmail.com',
+ :server => 'pop.gmail.com',
+ :username => 'test.otherinbox@gmail.com',
+ :password => '0th3r1nb0x', # TODO need to encrypt this
+ :ssl => true,
+ :port => 995
+ }
+end
@@ -0,0 +1,35 @@
+require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
+
+describe "/backups/new" do
+ before(:each) do
+ @remote_mail = mock_model( RemoteMail )
+ valid_pop3_attributes.each do |key, value|
+ @remote_mail.stub!(key).and_return( value )
+ end
+ assigns[:remote_mail] = @remote_mail
+ end
+
+ it "should render new form" do
+ render 'backups/new'
+ response.should have_tag("form[action=?][method=post]", '/backups/create') do
+ with_tag( "input#remote_mail_email_address[name=?]", "remote_mail[email_address]" )
+ with_tag( "input#remote_mail_server[name=?]", "remote_mail[server]" )
+ with_tag( "input#remote_mail_username[name=?]", "remote_mail[username]" )
+ with_tag( "input#remote_mail_password[name=?][type=password]", "remote_mail[password]" )
+ with_tag( "input#remote_mail_ssl[name=?]", "remote_mail[ssl]" )
+ with_tag( "input#remote_mail_port[name=?]", "remote_mail[port]" )
+ with_tag( "input[type=submit]" )
+ end
+ end
+
+ it "should display error notices" do
+ @remote_mail = RemoteMail.new
+ @remote_mail.save
+ assigns[:remote_mail] = @remote_mail
+ render 'backups/new'
+
+ response.should have_tag("form[action=?][method=post]", '/backups/create') do
+ with_tag( "div[id=errorExplanation]" )
+ end
+ end
+end
@@ -0,0 +1,12 @@
+require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
+
+describe "/backups/show" do
+ before(:each) do
+ assigns[:downloads] = { :inbox => MBOX_NAME }
+ render 'backups/show'
+ end
+
+ it "should show download link" do
+ response.should have_tag( "a[href=?]", "/download/#{MBOX_NAME}", "inbox" )
+ end
+end

0 comments on commit f1ad26e

Please sign in to comment.