diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/request_controller_spec.rb | 52 | ||||
-rw-r--r-- | spec/controllers/request_game_controller_spec.rb | 3 | ||||
-rw-r--r-- | spec/controllers/track_controller_spec.rb | 5 | ||||
-rw-r--r-- | spec/controllers/user_controller_spec.rb | 3 | ||||
-rw-r--r-- | spec/fixtures/files/useless_raw_email.email | 15 | ||||
-rw-r--r-- | spec/fixtures/raw_emails.yml | 17 | ||||
-rw-r--r-- | spec/models/incoming_message_spec.rb | 6 | ||||
-rw-r--r-- | spec/models/outgoing_mailer_spec.rb | 12 | ||||
-rw-r--r-- | spec/models/raw_email_spec.rb | 4 | ||||
-rw-r--r-- | spec/models/request_mailer_spec.rb | 3 | ||||
-rw-r--r-- | spec/models/xapian_spec.rb | 18 | ||||
-rw-r--r-- | spec/spec_helper.rb | 11 |
12 files changed, 121 insertions, 28 deletions
diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 9d91bf8c2..69c1433f2 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -8,7 +8,7 @@ require 'json' describe RequestController, "when listing recent requests" do - before(:all) do + before(:each) do rebuild_xapian_index end @@ -35,11 +35,14 @@ describe RequestController, "when listing recent requests" do end end - describe RequestController, "when showing one request" do fixtures :info_requests, :info_request_events, :public_bodies, :public_body_translations, :public_body_translations, :users, :incoming_messages, :raw_emails, :outgoing_messages, :comments # all needed as integrating views - + + before(:each) do + load_raw_emails_data(raw_emails) + end + it "should be successful" do get :show, :url_title => 'why_do_you_have_such_a_fancy_dog' response.should be_success @@ -198,6 +201,10 @@ end describe RequestController, "when changing prominence of a request" do fixtures :info_requests, :info_request_events, :public_bodies, :public_body_translations, :users, :incoming_messages, :raw_emails, :outgoing_messages # all needed as integrating views + before(:each) do + load_raw_emails_data(raw_emails) + end + it "should not show hidden requests" do ir = info_requests(:fancy_dog_request) ir.prominence = 'hidden' @@ -363,6 +370,9 @@ describe RequestController, "when creating a new request" do mail.body.should =~ /This is a silly letter. It is too short to be interesting./ response.should redirect_to(:action => 'show', :url_title => ir.url_title) + # This test uses an explicit path because it's relied in + # Google Analytics goals: + response.redirected_to.should =~ /request\/why_is_your_quango_called_gerald\/new$/ end it "should give an error if the same request is submitted twice" do @@ -454,7 +464,11 @@ end describe RequestController, "when viewing an individual response for reply/followup" do integrate_views fixtures :info_requests, :info_request_events, :public_bodies, :public_body_translations, :users, :incoming_messages, :raw_emails, :outgoing_messages, :comments # all needed as integrating views - + + before(:each) do + load_raw_emails_data(raw_emails) + end + it "should ask for login if you are logged in as wrong person" do session[:user_id] = users(:silly_name_user).id get :show_response, :id => info_requests(:fancy_dog_request).id, :incoming_message_id => incoming_messages(:useless_incoming_message) @@ -486,6 +500,7 @@ describe RequestController, "when classifying an information request" do @dog_request = info_requests(:fancy_dog_request) @dog_request.stub!(:is_old_unclassified?).and_return(false) InfoRequest.stub!(:find).and_return(@dog_request) + load_raw_emails_data(raw_emails) end def post_status(status) @@ -895,7 +910,11 @@ end describe RequestController, "sending overdue request alerts" do integrate_views fixtures :info_requests, :info_request_events, :public_bodies, :public_body_translations, :users, :incoming_messages, :raw_emails, :outgoing_messages # all needed as integrating views - + + before(:each) do + load_raw_emails_data(raw_emails) + end + it "should send an overdue alert mail to creators of overdue requests" do chicken_request = info_requests(:naughty_chicken_request) chicken_request.outgoing_messages[0].last_sent_at = Time.now() - 30.days @@ -979,7 +998,11 @@ end describe RequestController, "sending unclassified new response reminder alerts" do integrate_views fixtures :info_requests, :info_request_events, :public_bodies, :public_body_translations, :users, :incoming_messages, :raw_emails, :outgoing_messages, :comments # all needed as integrating views - + + before(:each) do + load_raw_emails_data(raw_emails) + end + it "should send an alert" do RequestMailer.alert_new_response_reminders @@ -1006,7 +1029,10 @@ end describe RequestController, "clarification required alerts" do integrate_views fixtures :info_requests, :info_request_events, :public_bodies, :public_body_translations, :users, :incoming_messages, :raw_emails, :outgoing_messages # all needed as integrating views - + before(:each) do + load_raw_emails_data(raw_emails) + end + it "should send an alert" do ir = info_requests(:fancy_dog_request) ir.set_described_state('waiting_clarification') @@ -1057,6 +1083,9 @@ end describe RequestController, "comment alerts" do integrate_views fixtures :info_requests, :info_request_events, :public_bodies, :public_body_translations, :users, :incoming_messages, :raw_emails, :outgoing_messages, :comments # all needed as integrating views + before(:each) do + load_raw_emails_data(raw_emails) + end it "should send an alert (once and once only)" do # delete ficture comment and make new one, so is in last month (as @@ -1128,7 +1157,10 @@ end describe RequestController, "when viewing comments" do integrate_views - fixtures :users + fixtures :users, :raw_emails, :incoming_messages, :info_requests + before(:each) do + load_raw_emails_data(raw_emails) + end it "should link to the user who submitted it" do session[:user_id] = users(:bob_smith_user).id @@ -1237,6 +1269,10 @@ describe RequestController, "when showing JSON version for API" do fixtures :info_requests, :info_request_events, :public_bodies, :public_body_translations, :users, :incoming_messages, :raw_emails, :outgoing_messages, :comments + before(:each) do + load_raw_emails_data(raw_emails) + end + it "should return data in JSON form" do get :show, :url_title => 'why_do_you_have_such_a_fancy_dog', :format => 'json' diff --git a/spec/controllers/request_game_controller_spec.rb b/spec/controllers/request_game_controller_spec.rb index ce507fad1..4883bfdd6 100644 --- a/spec/controllers/request_game_controller_spec.rb +++ b/spec/controllers/request_game_controller_spec.rb @@ -3,6 +3,9 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe RequestGameController, "when playing the game" do fixtures :info_requests, :info_request_events, :public_bodies, :public_body_translations, :users, :incoming_messages, :raw_emails, :outgoing_messages # all needed as integrating views + before(:each) do + load_raw_emails_data(raw_emails) + end it "should show the game homepage" do get :play diff --git a/spec/controllers/track_controller_spec.rb b/spec/controllers/track_controller_spec.rb index 0a8919268..f7002a9d4 100644 --- a/spec/controllers/track_controller_spec.rb +++ b/spec/controllers/track_controller_spec.rb @@ -37,6 +37,9 @@ describe TrackController, "when sending alerts for a track" do integrate_views fixtures :info_requests, :outgoing_messages, :incoming_messages, :raw_emails, :info_request_events, :users, :track_things, :track_things_sent_emails, :public_bodies, :public_body_translations include LinkToHelper # for main_url + before(:each) do + load_raw_emails_data(raw_emails) + end before do rebuild_xapian_index @@ -100,6 +103,7 @@ describe TrackController, "when viewing RSS feed for a track" do before do rebuild_xapian_index + load_raw_emails_data(raw_emails) end it "should get the RSS feed" do @@ -125,6 +129,7 @@ describe TrackController, "when viewing JSON version of a track feed" do before do rebuild_xapian_index + load_raw_emails_data(raw_emails) end it "should get the feed" do diff --git a/spec/controllers/user_controller_spec.rb b/spec/controllers/user_controller_spec.rb index c6817fbc6..0b5e96711 100644 --- a/spec/controllers/user_controller_spec.rb +++ b/spec/controllers/user_controller_spec.rb @@ -8,6 +8,9 @@ require 'json' describe UserController, "when showing a user" do integrate_views fixtures :users, :outgoing_messages, :incoming_messages, :raw_emails, :info_requests, :info_request_events, :comments, :public_bodies, :public_body_translations + before(:each) do + load_raw_emails_data(raw_emails) + end it "should be successful" do get :show, :url_name => "bob_smith" diff --git a/spec/fixtures/files/useless_raw_email.email b/spec/fixtures/files/useless_raw_email.email new file mode 100644 index 000000000..2e4585af7 --- /dev/null +++ b/spec/fixtures/files/useless_raw_email.email @@ -0,0 +1,15 @@ +From: "FOI Person" <foiperson@localhost> +To: "Bob Smith" <bob@localhost> +Date: Tue, 13 Nov 2007 11:39:55 +0000 +Bcc: +Subject: Geraldine FOI Code AZXB421 +Reply-To: +In-Reply-To: <471f1eae5d1cb_7347..fdbe67386163@cat.tmail> + +No way! I'm not going to tell you that in a month of Thursdays. + +The Geraldine Quango + +On Wed, Oct 24, 2007 at 11:30:06AM +0100, Bob Smith wrote: +> Why do you have such a fancy dog? + diff --git a/spec/fixtures/raw_emails.yml b/spec/fixtures/raw_emails.yml index d24b61854..8ef9248a3 100644 --- a/spec/fixtures/raw_emails.yml +++ b/spec/fixtures/raw_emails.yml @@ -1,19 +1,2 @@ useless_raw_email: id: 1 - data_binary: | - From: "FOI Person" <foiperson@localhost> - To: "Bob Smith" <bob@localhost> - Date: Tue, 13 Nov 2007 11:39:55 +0000 - NoCc: foi+request-1-4b571715@cat - Bcc: - Subject: Geraldine FOI Code AZXB421 - Reply-To: - In-Reply-To: <471f1eae5d1cb_7347..fdbe67386163@cat.tmail> - - No way! I'm not going to tell you that in a month of Thursdays. - - The Geraldine Quango - - On Wed, Oct 24, 2007 at 11:30:06AM +0100, Bob Smith wrote: - > Why do you have such a fancy dog? - diff --git a/spec/models/incoming_message_spec.rb b/spec/models/incoming_message_spec.rb index abbe94a47..42ea748fd 100644 --- a/spec/models/incoming_message_spec.rb +++ b/spec/models/incoming_message_spec.rb @@ -1,10 +1,11 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe IncomingMessage, " when dealing with incoming mail" do - fixtures :incoming_messages, :raw_emails + fixtures :incoming_messages, :raw_emails, :info_requests before do @im = incoming_messages(:useless_incoming_message) + load_raw_emails_data(raw_emails) end it "should return the mail Date header date for sent at" do @@ -129,6 +130,8 @@ describe IncomingMessage, " when censoring data" do @censor_rule_2.last_edit_editor = "unknown" @censor_rule_2.last_edit_comment = "none" @im.info_request.censor_rules << @censor_rule_2 + + load_raw_emails_data(raw_emails) end it "should do nothing to a JPEG" do @@ -212,6 +215,7 @@ describe IncomingMessage, " when censoring whole users" do @censor_rule_1.last_edit_editor = "unknown" @censor_rule_1.last_edit_comment = "none" @im.info_request.user.censor_rules << @censor_rule_1 + load_raw_emails_data(raw_emails) end it "should apply censor rules to HTML files" do diff --git a/spec/models/outgoing_mailer_spec.rb b/spec/models/outgoing_mailer_spec.rb index 3073c5ffd..d7587cb41 100644 --- a/spec/models/outgoing_mailer_spec.rb +++ b/spec/models/outgoing_mailer_spec.rb @@ -5,6 +5,9 @@ describe OutgoingMailer, " when working out follow up addresses" do # calls TMail. XXX untangle it and make these tests spread out and using # mocks. Put parts of the tests in spec/lib/tmail_extensions.rb fixtures :info_requests, :incoming_messages, :raw_emails, :public_bodies, :public_body_translations + before(:each) do + load_raw_emails_data(raw_emails) + end it "should parse them right" do ir = info_requests(:fancy_dog_request) @@ -67,8 +70,12 @@ 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 - + fixtures :info_requests, :incoming_messages, :outgoing_messages, :raw_emails + + before(:each) do + load_raw_emails_data(raw_emails) + end + 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] @@ -105,6 +112,7 @@ describe OutgoingMailer, "when working out follow up subjects" do 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] + puts im.raw_email.data om = outgoing_messages(:useless_outgoing_message) om.incoming_message_followup = im diff --git a/spec/models/raw_email_spec.rb b/spec/models/raw_email_spec.rb index 6f3a8acd6..ff2830a62 100644 --- a/spec/models/raw_email_spec.rb +++ b/spec/models/raw_email_spec.rb @@ -3,6 +3,10 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe User, "manipulating a raw email" do before do @raw_email = RawEmail.new + incoming_message = mock_model(IncomingMessage) + info_request = mock_model(InfoRequest) + incoming_message.stub!(:info_request).and_return(info_request) + @raw_email.stub!(:incoming_message).and_return(incoming_message) end it 'putting data in comes back out' do diff --git a/spec/models/request_mailer_spec.rb b/spec/models/request_mailer_spec.rb index a8311e8f8..a5f59b9bf 100644 --- a/spec/models/request_mailer_spec.rb +++ b/spec/models/request_mailer_spec.rb @@ -2,6 +2,9 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe RequestMailer, " when receiving incoming mail" do fixtures :info_requests, :incoming_messages, :raw_emails, :users, :public_bodies, :public_body_translations + before(:each) do + load_raw_emails_data(raw_emails) + end it "should append it to the appropriate request" do ir = info_requests(:fancy_dog_request) diff --git a/spec/models/xapian_spec.rb b/spec/models/xapian_spec.rb index 79ffc4839..37e68b145 100644 --- a/spec/models/xapian_spec.rb +++ b/spec/models/xapian_spec.rb @@ -35,6 +35,9 @@ end describe PublicBody, " when indexing public bodies with Xapian" do fixtures :public_bodies, :public_body_translations, :incoming_messages, :outgoing_messages, :raw_emails, :comments + before(:each) do + load_raw_emails_data(raw_emails) + end it "should search index the main name field" do rebuild_xapian_index @@ -126,6 +129,9 @@ end describe User, " when indexing requests by user they are from" do fixtures :users, :info_request_events, :info_requests, :incoming_messages, :outgoing_messages, :raw_emails, :comments + before(:each) do + load_raw_emails_data(raw_emails) + end it "should find requests from the user" do rebuild_xapian_index @@ -210,6 +216,9 @@ end describe User, " when indexing comments by user they are by" do fixtures :users, :info_request_events, :info_requests, :comments, :incoming_messages, :outgoing_messages, :raw_emails, :comments + before(:each) do + load_raw_emails_data(raw_emails) + end it "should find requests from the user" do rebuild_xapian_index @@ -244,6 +253,9 @@ end describe InfoRequest, " when indexing requests by their title" do fixtures :info_request_events, :info_requests, :incoming_messages, :raw_emails, :comments + before(:each) do + load_raw_emails_data(raw_emails) + end it "should find events for the request" do rebuild_xapian_index @@ -272,6 +284,9 @@ end describe InfoRequest, " when indexing requests by tag" do fixtures :info_request_events, :info_requests, :incoming_messages, :raw_emails, :comments + before(:each) do + load_raw_emails_data(raw_emails) + end it "should find request by tag, even when changes" do rebuild_xapian_index @@ -291,6 +306,9 @@ end describe PublicBody, " when indexing authorities by tag" do fixtures :public_bodies, :public_body_translations, :incoming_messages, :outgoing_messages, :raw_emails, :comments + before(:each) do + load_raw_emails_data(raw_emails) + end it "should find request by tag, even when changes" do rebuild_xapian_index diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 5e6d9ec4a..42c5ff6bf 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -13,6 +13,7 @@ config['ADMIN_PASSWORD'] = 'baz' # tests assume 20 days config['REPLY_LATE_AFTER_DAYS'] = 20 + # Uncomment the next line to use webrat's matchers #require 'webrat/integrations/rspec-rails' @@ -26,6 +27,7 @@ Spec::Runner.configure do |config| # in your config/boot.rb config.fixture_path = RAILS_ROOT + '/spec/fixtures/' + # == Fixtures # # You can declare fixtures for each example_group like this: @@ -144,3 +146,12 @@ if $tempfilecount.nil? puts "WARNING: HTML validation script " + $html_validation_script + " not found" end end + +def load_raw_emails_data(raw_emails) + raw_email = raw_emails(:useless_raw_email) + begin + raw_email.destroy_file_representation! + rescue Errno::ENOENT + end + raw_email.data = load_file_fixture("useless_raw_email.email") +end |