diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/request_controller_spec.rb | 86 | ||||
-rw-r--r-- | spec/fixtures/raw_emails.yml | 2 | ||||
-rw-r--r-- | spec/models/incoming_message_spec.rb | 3 | ||||
-rw-r--r-- | spec/models/outgoing_mailer_spec.rb | 47 | ||||
-rw-r--r-- | spec/spec_helper.rb | 2 |
5 files changed, 138 insertions, 2 deletions
diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 2d9ff9208..27647e04e 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -1111,6 +1111,92 @@ describe RequestController, "when viewing comments" do end +describe RequestController, "authority uploads a response from the web interface" do + fixtures :info_requests, :info_request_events, :public_bodies, :users + + before(:all) do + # domain after the @ is used for authentication of FOI officers, so to test it + # we need a user which isn't at localhost. + @normal_user = User.new(:name => "Mr. Normal", :email => "normal-user@flourish.org", + :password => PostRedirect.generate_random_token) + @normal_user.save! + + @foi_officer_user = User.new(:name => "The Geraldine Quango", :email => "geraldine-requests@localhost", + :password => PostRedirect.generate_random_token) + @foi_officer_user.save! + end + + it "should require login to view the form to upload" do + @ir = info_requests(:fancy_dog_request) + @ir.public_body.is_foi_officer?(@normal_user).should == false + session[:user_id] = @normal_user.id + + get :upload_response, :url_title => 'why_do_you_have_such_a_fancy_dog' + response.should render_template('user/wrong_user') + end + + it "should let you view upload form if you are an FOI officer" do + @ir = info_requests(:fancy_dog_request) + @ir.public_body.is_foi_officer?(@foi_officer_user).should == true + session[:user_id] = @foi_officer_user.id + + get :upload_response, :url_title => 'why_do_you_have_such_a_fancy_dog' + response.should render_template('request/upload_response') + end + + it "should prevent uploads if you are not a requester" do + @ir = info_requests(:fancy_dog_request) + incoming_before = @ir.incoming_messages.size + session[:user_id] = @normal_user.id + + # post up a photo of the parrot + parrot_upload = fixture_file_upload('parrot.png','image/png') + post :upload_response, :url_title => 'why_do_you_have_such_a_fancy_dog', + :body => "Find attached a picture of a parrot", + :file_1 => parrot_upload, + :submitted_upload_response => 1 + response.should render_template('user/wrong_user') + end + + it "should prevent entirely blank uploads" do + session[:user_id] = @foi_officer_user.id + + post :upload_response, :url_title => 'why_do_you_have_such_a_fancy_dog', :body => "", :submitted_upload_response => 1 + response.should render_template('request/upload_response') + flash[:error].should match(/Please type a message/) + end + + # How do I test a file upload in rails? + # http://stackoverflow.com/questions/1178587/how-do-i-test-a-file-upload-in-rails + it "should let the requester upload a file" do + @ir = info_requests(:fancy_dog_request) + incoming_before = @ir.incoming_messages.size + session[:user_id] = @foi_officer_user.id + + # post up a photo of the parrot + parrot_upload = fixture_file_upload('parrot.png','image/png') + post :upload_response, :url_title => 'why_do_you_have_such_a_fancy_dog', + :body => "Find attached a picture of a parrot", + :file_1 => parrot_upload, + :submitted_upload_response => 1 + + response.should redirect_to(:action => 'show', :url_title => 'why_do_you_have_such_a_fancy_dog') + flash[:notice].should match(/Thank you for responding to this FOI request/) + + # check there is a new attachment + incoming_after = @ir.incoming_messages.size + incoming_after.should == incoming_before + 1 + + # check new attachment looks vaguely OK + new_im = @ir.incoming_messages[-1] + new_im.mail.body.should match(/Find attached a picture of a parrot/) + attachments = new_im.get_attachments_for_display + attachments.size.should == 1 + attachments[0].filename.should == "parrot.png" + attachments[0].display_size.should == "94K" + end +end + diff --git a/spec/fixtures/raw_emails.yml b/spec/fixtures/raw_emails.yml index 4930e9966..d24b61854 100644 --- a/spec/fixtures/raw_emails.yml +++ b/spec/fixtures/raw_emails.yml @@ -6,7 +6,7 @@ useless_raw_email: Date: Tue, 13 Nov 2007 11:39:55 +0000 NoCc: foi+request-1-4b571715@cat Bcc: - Subject: Re: Freedom of Information Request - Why do you have such a fancy dog? + Subject: Geraldine FOI Code AZXB421 Reply-To: In-Reply-To: <471f1eae5d1cb_7347..fdbe67386163@cat.tmail> diff --git a/spec/models/incoming_message_spec.rb b/spec/models/incoming_message_spec.rb index cf8db63cb..cf51c8a42 100644 --- a/spec/models/incoming_message_spec.rb +++ b/spec/models/incoming_message_spec.rb @@ -157,6 +157,9 @@ describe IncomingMessage, " when censoring data" do data.should == "His email was x\000x\000x\000@\000x\000x\000x\000.\000x\000x\000x\000, indeed" end + # As at March 9th 2010: This test fails with pdftk 1.41+dfsg-1 installed + # which is in Ubuntu Karmic. It works again for the lasest version + # 1.41+dfsg-7 in Debian unstable. And it works for Debian stable. it "should replace everything in PDF files" do orig_pdf = load_file_fixture('tfl.pdf') pdf = orig_pdf.dup diff --git a/spec/models/outgoing_mailer_spec.rb b/spec/models/outgoing_mailer_spec.rb index de59b09b2..0bbe39cad 100644 --- a/spec/models/outgoing_mailer_spec.rb +++ b/spec/models/outgoing_mailer_spec.rb @@ -66,4 +66,51 @@ describe OutgoingMailer, " when working out follow up addresses" do end +describe OutgoingMailer, "when working out follow up subjects" do + fixtures :info_requests, :incoming_messages, :outgoing_messages + + it "should prefix the title with 'Freedom of Information request -' for initial requests" do + ir = info_requests(:fancy_dog_request) + im = ir.incoming_messages[0] + + ir.email_subject_request.should == "Freedom of Information request - Why do you have & such a fancy dog?" + end + + it "should use 'Re:' and inital request subject for followups which aren't replies to particular messages" do + ir = info_requests(:fancy_dog_request) + om = outgoing_messages(:useless_outgoing_message) + + OutgoingMailer.subject_for_followup(ir, om).should == "Re: Freedom of Information request - Why do you have & such a fancy dog?" + end + + it "should prefix with Re: the subject of the message being replied to" do + ir = info_requests(:fancy_dog_request) + im = ir.incoming_messages[0] + om = outgoing_messages(:useless_outgoing_message) + om.incoming_message_followup = im + + OutgoingMailer.subject_for_followup(ir, om).should == "Re: Geraldine FOI Code AZXB421" + end + + it "should not add Re: prefix if there already is such a prefix" do + ir = info_requests(:fancy_dog_request) + im = ir.incoming_messages[0] + om = outgoing_messages(:useless_outgoing_message) + om.incoming_message_followup = im + + im.raw_email.data = im.raw_email.data.sub("Subject: Geraldine FOI Code AZXB421", "Subject: Re: Geraldine FOI Code AZXB421") + OutgoingMailer.subject_for_followup(ir, om).should == "Re: Geraldine FOI Code AZXB421" + end + + it "should not add Re: prefix if there already is a lower case re: prefix" do + ir = info_requests(:fancy_dog_request) + im = ir.incoming_messages[0] + om = outgoing_messages(:useless_outgoing_message) + om.incoming_message_followup = im + + im.raw_email.data = im.raw_email.data.sub("Subject: Geraldine FOI Code AZXB421", "Subject: re: Geraldine FOI Code AZXB421") + OutgoingMailer.subject_for_followup(ir, om).should == "re: Geraldine FOI Code AZXB421" + end +end + diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 72457815a..ddb9ab14b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -7,7 +7,7 @@ require 'spec/rails' Spec::Runner.configure do |config| config.use_transactional_fixtures = true config.use_instantiated_fixtures = false - config.fixture_path = RAILS_ROOT + '/spec/fixtures' + config.fixture_path = RAILS_ROOT + '/spec/fixtures/' # You can declare fixtures for each behaviour like this: # describe "...." do |