From 0d533ce1d56e1ec1446774cc6fff52451a844f3f Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Sun, 9 Dec 2012 18:35:39 +1100 Subject: Switch to new method name --- spec/controllers/admin_public_body_controller_spec.rb | 10 +++++----- spec/controllers/public_body_controller_spec.rb | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/admin_public_body_controller_spec.rb b/spec/controllers/admin_public_body_controller_spec.rb index 504ddc5cc..289be07df 100644 --- a/spec/controllers/admin_public_body_controller_spec.rb +++ b/spec/controllers/admin_public_body_controller_spec.rb @@ -288,7 +288,7 @@ describe AdminPublicBodyController, "when administering public bodies with i18n" end it "saves edits to a public body" do - PublicBody.with_locale(:es) do + PublicBody.with_locales(:es) do pb = PublicBody.find(id=3) pb.name.should == "El Department for Humpadinking" post :update, { @@ -308,10 +308,10 @@ describe AdminPublicBodyController, "when administering public bodies with i18n" end pb = PublicBody.find(public_bodies(:humpadink_public_body).id) - PublicBody.with_locale(:es) do + PublicBody.with_locales(:es) do pb.name.should == "Renamed" end - PublicBody.with_locale(:en) do + PublicBody.with_locales(:en) do pb.name.should == "Department for Humpadinking" end end @@ -357,12 +357,12 @@ describe AdminPublicBodyController, "when creating public bodies with i18n" do body = PublicBody.find_by_name("New Quango") body.translations.map {|t| t.locale.to_s}.sort.should == ["en", "es"] - PublicBody.with_locale(:en) do + PublicBody.with_locales(:en) do body.name.should == "New Quango" body.url_name.should == "new_quango" body.first_letter.should == "N" end - PublicBody.with_locale(:es) do + PublicBody.with_locales(:es) do body.name.should == "Mi Nuevo Quango" body.url_name.should == "mi_nuevo_quango" body.first_letter.should == "M" diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb index 29ece18cb..e97db5a12 100644 --- a/spec/controllers/public_body_controller_spec.rb +++ b/spec/controllers/public_body_controller_spec.rb @@ -44,14 +44,14 @@ describe PublicBodyController, "when showing a body" do end it "should assign the body using different locale from that used for url_name" do - PublicBody.with_locale(:es) do + PublicBody.with_locales(:es) do get :show, {:url_name => "dfh", :view => 'all'} assigns[:public_body].notes.should == "Baguette" end end it "should assign the body using same locale as that used in url_name" do - PublicBody.with_locale(:es) do + PublicBody.with_locales(:es) do get :show, {:url_name => "edfh", :view => 'all'} assigns[:public_body].notes.should == "Baguette" end @@ -87,7 +87,7 @@ describe PublicBodyController, "when listing bodies" do end it "should list all bodies from default locale, even when there are no translations for selected locale" do - PublicBody.with_locale(:en) do + PublicBody.with_locales(:en) do @english_only = PublicBody.new(:name => 'English only', :short_name => 'EO', :request_email => 'english@flourish.org', @@ -95,7 +95,7 @@ describe PublicBodyController, "when listing bodies" do :last_edit_comment => '') @english_only.save end - PublicBody.with_locale(:es) do + PublicBody.with_locales(:es) do get :list assigns[:public_bodies].include?(@english_only).should == true end -- cgit v1.2.3 From 64a93911ebae4eaa2a1bc2b9e09d1468d77aadb9 Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Sun, 9 Dec 2012 19:08:59 +1100 Subject: Remove interlock as it's not compatible with Rails 3 and is unmaintained --- spec/controllers/request_controller_spec.rb | 13 ------------- 1 file changed, 13 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index f40eecfff..e930e570b 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -59,19 +59,6 @@ describe RequestController, "when listing recent requests" do :conditions => "id in (select info_request_id from info_request_events where created_at between '2007-10-13'::date and '2007-11-01'::date)") end - it "should make a sane-sized cache tag" do - get :list, :view => 'all', :request_date_after => '13/10/2007', :request_date_before => '01/11/2007' - assigns[:cache_tag].size.should <= 32 - end - - it "should vary the cache tag with locale" do - get :list, :view => 'all', :request_date_after => '13/10/2007', :request_date_before => '01/11/2007' - en_tag = assigns[:cache_tag] - session[:locale] = :es - get :list, :view => 'all', :request_date_after => '13/10/2007', :request_date_before => '01/11/2007' - assigns[:cache_tag].should_not == en_tag - end - it "should list internal_review requests as unresolved ones" do get :list, :view => 'awaiting' -- cgit v1.2.3 From 1f8bc6560b5240a7aa84ac8d6bdc47eea5d2d781 Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Mon, 10 Dec 2012 00:09:55 +1100 Subject: The with_locale has been removed in Globalize3 I think Globalize is supposed to pick up the locale from I18n anyway so I don't know if these are needed. I think I still haven't done the right thing but it's time to move on. --- spec/controllers/admin_public_body_controller_spec.rb | 10 +++++----- spec/controllers/public_body_controller_spec.rb | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/admin_public_body_controller_spec.rb b/spec/controllers/admin_public_body_controller_spec.rb index 289be07df..255eacbd0 100644 --- a/spec/controllers/admin_public_body_controller_spec.rb +++ b/spec/controllers/admin_public_body_controller_spec.rb @@ -288,7 +288,7 @@ describe AdminPublicBodyController, "when administering public bodies with i18n" end it "saves edits to a public body" do - PublicBody.with_locales(:es) do + I18n.with_locale(:es) do pb = PublicBody.find(id=3) pb.name.should == "El Department for Humpadinking" post :update, { @@ -308,10 +308,10 @@ describe AdminPublicBodyController, "when administering public bodies with i18n" end pb = PublicBody.find(public_bodies(:humpadink_public_body).id) - PublicBody.with_locales(:es) do + I18n.with_locale(:es) do pb.name.should == "Renamed" end - PublicBody.with_locales(:en) do + I18n.with_locale(:en) do pb.name.should == "Department for Humpadinking" end end @@ -357,12 +357,12 @@ describe AdminPublicBodyController, "when creating public bodies with i18n" do body = PublicBody.find_by_name("New Quango") body.translations.map {|t| t.locale.to_s}.sort.should == ["en", "es"] - PublicBody.with_locales(:en) do + I18n.with_locale(:en) do body.name.should == "New Quango" body.url_name.should == "new_quango" body.first_letter.should == "N" end - PublicBody.with_locales(:es) do + I18n.with_locale(:es) do body.name.should == "Mi Nuevo Quango" body.url_name.should == "mi_nuevo_quango" body.first_letter.should == "M" diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb index e97db5a12..9c7f7dc7f 100644 --- a/spec/controllers/public_body_controller_spec.rb +++ b/spec/controllers/public_body_controller_spec.rb @@ -44,14 +44,14 @@ describe PublicBodyController, "when showing a body" do end it "should assign the body using different locale from that used for url_name" do - PublicBody.with_locales(:es) do + I18n.with_locale(:es) do get :show, {:url_name => "dfh", :view => 'all'} assigns[:public_body].notes.should == "Baguette" end end it "should assign the body using same locale as that used in url_name" do - PublicBody.with_locales(:es) do + I18n.with_locale(:es) do get :show, {:url_name => "edfh", :view => 'all'} assigns[:public_body].notes.should == "Baguette" end @@ -87,7 +87,7 @@ describe PublicBodyController, "when listing bodies" do end it "should list all bodies from default locale, even when there are no translations for selected locale" do - PublicBody.with_locales(:en) do + I18n.with_locale(:en) do @english_only = PublicBody.new(:name => 'English only', :short_name => 'EO', :request_email => 'english@flourish.org', @@ -95,7 +95,7 @@ describe PublicBodyController, "when listing bodies" do :last_edit_comment => '') @english_only.save end - PublicBody.with_locales(:es) do + I18n.with_locale(:es) do get :list assigns[:public_bodies].include?(@english_only).should == true end -- cgit v1.2.3 From c9feb6a4002fc4b63021aeb5ffd6b2846ada7748 Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Tue, 11 Dec 2012 15:00:40 +1100 Subject: integrate_views is render_views RSpec 2 --- .../admin_censor_rule_controller_spec.rb | 2 +- spec/controllers/admin_general_controller_spec.rb | 2 +- .../admin_public_body_controller_spec.rb | 8 +++--- spec/controllers/admin_request_controller_spec.rb | 4 +-- spec/controllers/admin_track_controller_spec.rb | 2 +- spec/controllers/admin_user_controller_spec.rb | 2 +- spec/controllers/comment_controller_spec.rb | 2 +- spec/controllers/general_controller_spec.rb | 4 +-- spec/controllers/help_controller_spec.rb | 2 +- spec/controllers/public_body_controller_spec.rb | 6 ++--- spec/controllers/request_controller_spec.rb | 30 +++++++++++----------- spec/controllers/services_controller_spec.rb | 4 +-- spec/controllers/track_controller_spec.rb | 8 +++--- spec/controllers/user_controller_spec.rb | 18 ++++++------- 14 files changed, 47 insertions(+), 47 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/admin_censor_rule_controller_spec.rb b/spec/controllers/admin_censor_rule_controller_spec.rb index 8893a858b..c4860da3f 100644 --- a/spec/controllers/admin_censor_rule_controller_spec.rb +++ b/spec/controllers/admin_censor_rule_controller_spec.rb @@ -1,7 +1,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe AdminCensorRuleController, "when making censor rules from the admin interface" do - integrate_views + render_views before { basic_auth_login @request } it "should create a censor rule and purge the corresponding request from varnish" do diff --git a/spec/controllers/admin_general_controller_spec.rb b/spec/controllers/admin_general_controller_spec.rb index dc1eb0d97..b0b65857f 100644 --- a/spec/controllers/admin_general_controller_spec.rb +++ b/spec/controllers/admin_general_controller_spec.rb @@ -4,7 +4,7 @@ describe AdminGeneralController do describe "when viewing front page of admin interface" do - integrate_views + render_views before { basic_auth_login @request } it "should render the front page" do diff --git a/spec/controllers/admin_public_body_controller_spec.rb b/spec/controllers/admin_public_body_controller_spec.rb index 255eacbd0..c1d3f5014 100644 --- a/spec/controllers/admin_public_body_controller_spec.rb +++ b/spec/controllers/admin_public_body_controller_spec.rb @@ -1,7 +1,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe AdminPublicBodyController, "when administering public bodies" do - integrate_views + render_views before do @old_filters = ActionController::Routing::Routes.filters @@ -154,7 +154,7 @@ end describe AdminPublicBodyController, "when administering public bodies and paying attention to authentication" do - integrate_views + render_views before do config = MySociety::Config.load_default() @@ -263,7 +263,7 @@ describe AdminPublicBodyController, "when administering public bodies and paying end describe AdminPublicBodyController, "when administering public bodies with i18n" do - integrate_views + render_views it "shows the index page" do get :index @@ -325,7 +325,7 @@ describe AdminPublicBodyController, "when administering public bodies with i18n" end describe AdminPublicBodyController, "when creating public bodies with i18n" do - integrate_views + render_views before do @old_filters = ActionController::Routing::Routes.filters diff --git a/spec/controllers/admin_request_controller_spec.rb b/spec/controllers/admin_request_controller_spec.rb index 8a3934685..0709f6b0b 100644 --- a/spec/controllers/admin_request_controller_spec.rb +++ b/spec/controllers/admin_request_controller_spec.rb @@ -1,7 +1,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe AdminRequestController, "when administering requests" do - integrate_views + render_views before { basic_auth_login @request } before(:each) do @@ -82,7 +82,7 @@ describe AdminRequestController, "when administering requests" do end describe AdminRequestController, "when administering the holding pen" do - integrate_views + render_views before(:each) do basic_auth_login @request load_raw_emails_data diff --git a/spec/controllers/admin_track_controller_spec.rb b/spec/controllers/admin_track_controller_spec.rb index 728c79f1f..f2de6c0d3 100644 --- a/spec/controllers/admin_track_controller_spec.rb +++ b/spec/controllers/admin_track_controller_spec.rb @@ -1,7 +1,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe AdminTrackController, "when administering tracks" do - integrate_views + render_views it "shows the list page" do get :list diff --git a/spec/controllers/admin_user_controller_spec.rb b/spec/controllers/admin_user_controller_spec.rb index cf3665c9f..a6e5a0d7e 100644 --- a/spec/controllers/admin_user_controller_spec.rb +++ b/spec/controllers/admin_user_controller_spec.rb @@ -1,7 +1,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe AdminUserController, "when administering users" do - integrate_views + render_views it "shows the index/list page" do get :index diff --git a/spec/controllers/comment_controller_spec.rb b/spec/controllers/comment_controller_spec.rb index 4a7acee23..c03615ce2 100644 --- a/spec/controllers/comment_controller_spec.rb +++ b/spec/controllers/comment_controller_spec.rb @@ -1,7 +1,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe CommentController, "when commenting on a request" do - integrate_views + render_views it "should give an error and render 'new' template when body text is just some whitespace" do post :new, :url_title => info_requests(:naughty_chicken_request).url_title, diff --git a/spec/controllers/general_controller_spec.rb b/spec/controllers/general_controller_spec.rb index 642ed0e05..9684732a5 100644 --- a/spec/controllers/general_controller_spec.rb +++ b/spec/controllers/general_controller_spec.rb @@ -35,7 +35,7 @@ end describe GeneralController, "when showing the frontpage" do - integrate_views + render_views before do public_body = mock_model(PublicBody, :name => "Example Public Body", @@ -235,7 +235,7 @@ end describe GeneralController, 'when using xapian search' do - integrate_views + render_views # rebuild xapian index after fixtures loaded before(:each) do diff --git a/spec/controllers/help_controller_spec.rb b/spec/controllers/help_controller_spec.rb index 28fd08c80..0f6f75eb9 100644 --- a/spec/controllers/help_controller_spec.rb +++ b/spec/controllers/help_controller_spec.rb @@ -1,7 +1,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe HelpController, "when using help" do - integrate_views + render_views it "shows the about page" do get :about diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb index 9c7f7dc7f..a0841b621 100644 --- a/spec/controllers/public_body_controller_spec.rb +++ b/spec/controllers/public_body_controller_spec.rb @@ -2,7 +2,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe PublicBodyController, "when showing a body" do - integrate_views + render_views before(:each) do load_raw_emails_data @@ -79,7 +79,7 @@ describe PublicBodyController, "when showing a body" do end describe PublicBodyController, "when listing bodies" do - integrate_views + render_views it "should be successful" do get :list @@ -193,7 +193,7 @@ end describe PublicBodyController, "when doing type ahead searches" do - integrate_views + render_views before(:each) do load_raw_emails_data diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index e930e570b..9e14153a7 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -121,7 +121,7 @@ end describe RequestController, "when changing things that appear on the request page" do - integrate_views + render_views it "should purge the downstream cache when mail is received" do ir = info_requests(:fancy_dog_request) @@ -187,7 +187,7 @@ describe RequestController, "when changing things that appear on the request pag end describe RequestController, "when showing one request" do - integrate_views + render_views before(:each) do load_raw_emails_data @@ -445,7 +445,7 @@ describe RequestController, "when showing one request" do describe 'when handling incoming mail' do - integrate_views + render_views it "should receive incoming messages, send email to creator, and show them" do ir = info_requests(:fancy_dog_request) @@ -895,7 +895,7 @@ describe RequestController, "when searching for an authority" do end describe RequestController, "when creating a new request" do - integrate_views + render_views before do @user = users(:bob_smith_user) @@ -1131,7 +1131,7 @@ describe RequestController, "when making a new request" do end describe RequestController, "when viewing an individual response for reply/followup" do - integrate_views + render_views before(:each) do load_raw_emails_data @@ -1564,7 +1564,7 @@ describe RequestController, "when classifying an information request" do end describe RequestController, "when sending a followup message" do - integrate_views + render_views before(:each) do load_raw_emails_data @@ -1646,7 +1646,7 @@ end # it can't check the URLs in the emails I don't think, ugh. describe RequestController, "sending overdue request alerts" do - integrate_views + render_views before(:each) do load_raw_emails_data @@ -1791,7 +1791,7 @@ describe RequestController, "sending overdue request alerts" do end describe RequestController, "sending unclassified new response reminder alerts" do - integrate_views + render_views before(:each) do load_raw_emails_data @@ -1821,7 +1821,7 @@ describe RequestController, "sending unclassified new response reminder alerts" end describe RequestController, "clarification required alerts" do - integrate_views + render_views before(:each) do load_raw_emails_data end @@ -1874,7 +1874,7 @@ describe RequestController, "clarification required alerts" do end describe RequestController, "comment alerts" do - integrate_views + render_views before(:each) do load_raw_emails_data end @@ -1953,7 +1953,7 @@ describe RequestController, "comment alerts" do end describe RequestController, "when viewing comments" do - integrate_views + render_views before(:each) do load_raw_emails_data end @@ -1976,7 +1976,7 @@ end describe RequestController, "authority uploads a response from the web interface" do - integrate_views + render_views before(:each) do # domain after the @ is used for authentication of FOI officers, so to test it @@ -2086,7 +2086,7 @@ end describe RequestController, "when doing type ahead searches" do - integrate_views + render_views it "should return nothing for the empty query string" do get :search_typeahead, :q => "" @@ -2144,7 +2144,7 @@ describe RequestController, "when doing type ahead searches" do end describe RequestController, "when showing similar requests" do - integrate_views + render_views it "should work" do get :similar, :url_title => info_requests(:badger_request).url_title @@ -2178,7 +2178,7 @@ describe RequestController, "when reporting a request when not logged in" do end describe RequestController, "when reporting a request (logged in)" do - integrate_views + render_views before do @user = users(:robin_user) diff --git a/spec/controllers/services_controller_spec.rb b/spec/controllers/services_controller_spec.rb index a701ae247..d2d22826a 100644 --- a/spec/controllers/services_controller_spec.rb +++ b/spec/controllers/services_controller_spec.rb @@ -3,7 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe ServicesController, "when using web services" do - integrate_views + render_views # store and restore the locale in the context of the test suite to isolate # changes made in these tests @@ -40,4 +40,4 @@ describe ServicesController, "when using web services" do FastGettext.set_locale(@old_locale) end -end \ No newline at end of file +end diff --git a/spec/controllers/track_controller_spec.rb b/spec/controllers/track_controller_spec.rb index c785960b5..cd7932e90 100644 --- a/spec/controllers/track_controller_spec.rb +++ b/spec/controllers/track_controller_spec.rb @@ -56,7 +56,7 @@ describe TrackController, "when making a new track on a request" do end describe TrackController, "when sending alerts for a track" do - integrate_views + render_views include LinkToHelper # for main_url before(:each) do @@ -134,7 +134,7 @@ describe TrackController, "when sending alerts for a track" do end describe TrackController, "when viewing RSS feed for a track" do - integrate_views + render_views before(:each) do load_raw_emails_data @@ -164,7 +164,7 @@ end describe TrackController, "when viewing JSON version of a track feed" do - integrate_views + render_views before(:each) do load_raw_emails_data @@ -206,7 +206,7 @@ end describe TrackController, "when tracking a public body" do - integrate_views + render_views before(:each) do load_raw_emails_data diff --git a/spec/controllers/user_controller_spec.rb b/spec/controllers/user_controller_spec.rb index 23006803b..db64bdcaf 100644 --- a/spec/controllers/user_controller_spec.rb +++ b/spec/controllers/user_controller_spec.rb @@ -5,7 +5,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') # http://rspec.rubyforge.org/rspec-rails/1.1.12/classes/Spec/Rails/Example/ControllerExampleGroup.html describe UserController, "when showing a user" do - integrate_views + render_views before(:each) do load_raw_emails_data get_fixtures_xapian_index @@ -64,7 +64,7 @@ describe UserController, "when showing a user" do end describe UserController, "when signing in" do - integrate_views + render_views def get_last_postredirect post_redirects = PostRedirect.find_by_sql("select * from post_redirects order by id desc limit 1") @@ -228,7 +228,7 @@ describe UserController, "when signing in" do end describe UserController, "when signing up" do - integrate_views + render_views it "should be an error if you type the password differently each time" do post :signup, { :user_signup => { :email => 'new@localhost', :name => 'New Person', @@ -285,7 +285,7 @@ describe UserController, "when signing up" do end describe UserController, "when signing out" do - integrate_views + render_views it "should log you out and redirect to the home page" do session[:user_id] = users(:bob_smith_user).id @@ -309,7 +309,7 @@ describe UserController, "when signing out" do end describe UserController, "when sending another user a message" do - integrate_views + render_views it "should redirect to signin page if you go to the contact form and aren't signed in" do get :contact, :id => users(:silly_name_user) @@ -346,7 +346,7 @@ describe UserController, "when sending another user a message" do end describe UserController, "when changing password" do - integrate_views + render_views it "should show the email form when not logged in" do get :signchangepassword @@ -416,7 +416,7 @@ describe UserController, "when changing password" do end describe UserController, "when changing email address" do - integrate_views + render_views it "should require login" do get :signchangeemail @@ -561,7 +561,7 @@ describe UserController, "when changing email address" do end describe UserController, "when using profile photos" do - integrate_views + render_views before do @user = users(:bob_smith_user) @@ -631,7 +631,7 @@ describe UserController, "when showing JSON version for API" do end describe UserController, "when viewing the wall" do - integrate_views + render_views before(:each) do get_fixtures_xapian_index -- cgit v1.2.3 From 5b35eaa1e976b824d7f55786f05854fa7aff9d69 Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Fri, 4 Jan 2013 12:00:43 +1100 Subject: Get rid of resetting of ActionController::Routing::Routes.filters --- spec/controllers/admin_public_body_controller_spec.rb | 18 ------------------ spec/controllers/admin_request_controller_spec.rb | 10 ---------- 2 files changed, 28 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/admin_public_body_controller_spec.rb b/spec/controllers/admin_public_body_controller_spec.rb index c1d3f5014..0fdc20338 100644 --- a/spec/controllers/admin_public_body_controller_spec.rb +++ b/spec/controllers/admin_public_body_controller_spec.rb @@ -3,15 +3,6 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe AdminPublicBodyController, "when administering public bodies" do render_views - before do - @old_filters = ActionController::Routing::Routes.filters - ActionController::Routing::Routes.filters = RoutingFilter::Chain.new - end - - after do - ActionController::Routing::Routes.filters = @old_filters - end - it "shows the index page" do get :index end @@ -327,15 +318,6 @@ end describe AdminPublicBodyController, "when creating public bodies with i18n" do render_views - before do - @old_filters = ActionController::Routing::Routes.filters - ActionController::Routing::Routes.filters = RoutingFilter::Chain.new - end - - after do - ActionController::Routing::Routes.filters = @old_filters - end - it "creates a new public body in one locale" do n = PublicBody.count post :create, { :public_body => { :name => "New Quango", :short_name => "", :tag_string => "blah", :request_email => 'newquango@localhost', :last_edit_comment => 'From test code' } } diff --git a/spec/controllers/admin_request_controller_spec.rb b/spec/controllers/admin_request_controller_spec.rb index 0709f6b0b..6d7ab611e 100644 --- a/spec/controllers/admin_request_controller_spec.rb +++ b/spec/controllers/admin_request_controller_spec.rb @@ -6,11 +6,6 @@ describe AdminRequestController, "when administering requests" do before(:each) do load_raw_emails_data - @old_filters = ActionController::Routing::Routes.filters - ActionController::Routing::Routes.filters = RoutingFilter::Chain.new - end - after do - ActionController::Routing::Routes.filters = @old_filters end it "shows the index/list page" do @@ -86,11 +81,6 @@ describe AdminRequestController, "when administering the holding pen" do before(:each) do basic_auth_login @request load_raw_emails_data - @old_filters = ActionController::Routing::Routes.filters - ActionController::Routing::Routes.filters = RoutingFilter::Chain.new - end - after do - ActionController::Routing::Routes.filters = @old_filters end it "shows a rejection reason for an incoming message from an invalid address" do -- cgit v1.2.3 From c8de5ff799bb282a586185dbc6c86dad412e6204 Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Fri, 4 Jan 2013 12:18:07 +1100 Subject: response.status now returns an integer --- spec/controllers/api_controller_spec.rb | 10 +++++----- spec/controllers/general_controller_spec.rb | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/api_controller_spec.rb b/spec/controllers/api_controller_spec.rb index 1c320f85c..aeb452afe 100644 --- a/spec/controllers/api_controller_spec.rb +++ b/spec/controllers/api_controller_spec.rb @@ -173,7 +173,7 @@ describe ApiController, "when using the API" do "body" => "xxx" }.to_json - response.status.should == "500 Internal Server Error" + response.status.should == 500 ActiveSupport::JSON.decode(response.body)["errors"].should == [ "Request #{request_id} cannot be updated using the API"] @@ -195,7 +195,7 @@ describe ApiController, "when using the API" do "body" => "xxx" }.to_json - response.status.should == "500 Internal Server Error" + response.status.should == 500 ActiveSupport::JSON.decode(response.body)["errors"].should == [ "You do not own request #{request_id}"] @@ -218,7 +218,7 @@ describe ApiController, "when using the API" do # Make sure it worked - response.status.to_i.should == 500 + response.status.should == 500 errors = ActiveSupport::JSON.decode(response.body)["errors"] errors.should == ["You cannot attach files to messages in the 'request' direction"] end @@ -360,7 +360,7 @@ describe ApiController, "when using the API" do "sent_at" => sent_at, "body" => response_body }.to_json - response.status.should == "404 Not Found" + response.status.should == 404 ActiveSupport::JSON.decode(response.body)["errors"].should == ["Could not find request 123459876"] end @@ -376,7 +376,7 @@ describe ApiController, "when using the API" do "sent_at" => sent_at, "body" => response_body }.to_json - response.status.should == "500 Internal Server Error" + response.status.should == 500 ActiveSupport::JSON.decode(response.body)["errors"].should == ["Request #{request_id} cannot be updated using the API"] end end diff --git a/spec/controllers/general_controller_spec.rb b/spec/controllers/general_controller_spec.rb index 9684732a5..fcd121df6 100644 --- a/spec/controllers/general_controller_spec.rb +++ b/spec/controllers/general_controller_spec.rb @@ -12,7 +12,7 @@ describe GeneralController, "when trying to show the blog" do it "should fail silently if the blog is returning an error" do FakeWeb.register_uri(:get, %r|.*|, :body => "Error", :status => ["500", "Error"]) get :blog - response.status.should == "200 OK" + response.status.should == 200 assigns[:blog_items].count.should == 0 end end -- cgit v1.2.3 From fc326e9b3d1750c28cacd680d944c8bed302bc61 Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Fri, 4 Jan 2013 12:24:42 +1100 Subject: No need to specify extension when testing particular template is rendered --- spec/controllers/api_controller_spec.rb | 4 ++-- spec/controllers/request_controller_spec.rb | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/api_controller_spec.rb b/spec/controllers/api_controller_spec.rb index aeb452afe..8dc8e2990 100644 --- a/spec/controllers/api_controller_spec.rb +++ b/spec/controllers/api_controller_spec.rb @@ -286,7 +286,7 @@ describe ApiController, "when using the API" do :feed_type => "atom" response.should be_success - response.should render_template("api/request_events.atom") + response.should render_template("api/request_events") assigns[:events].size.should > 0 assigns[:events].each do |event| event.info_request.public_body.should == public_bodies(:geraldine_public_body) @@ -341,7 +341,7 @@ describe ApiController, "when using the API" do :feed_type => "atom" response.should be_success - response.should render_template("api/request_events.atom") + response.should render_template("api/request_events") assigns[:events].size.should > 0 assigns[:events].each do |event| event.created_at.should >= Date.new(2010, 1, 1) diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 9e14153a7..6b5e3e216 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -2090,20 +2090,20 @@ describe RequestController, "when doing type ahead searches" do it "should return nothing for the empty query string" do get :search_typeahead, :q => "" - response.should render_template('request/_search_ahead.rhtml') + response.should render_template('request/_search_ahead') assigns[:xapian_requests].should be_nil end it "should return a request matching the given keyword, but not users with a matching description" do get :search_typeahead, :q => "chicken" - response.should render_template('request/_search_ahead.rhtml') + response.should render_template('request/_search_ahead') assigns[:xapian_requests].results.size.should == 1 assigns[:xapian_requests].results[0][:model].title.should == info_requests(:naughty_chicken_request).title end it "should return all requests matching any of the given keywords" do get :search_typeahead, :q => "money dog" - response.should render_template('request/_search_ahead.rhtml') + response.should render_template('request/_search_ahead') assigns[:xapian_requests].results.map{|x|x[:model].info_request}.should =~ [ info_requests(:fancy_dog_request), info_requests(:naughty_chicken_request), @@ -2113,13 +2113,13 @@ describe RequestController, "when doing type ahead searches" do it "should not return matches for short words" do get :search_typeahead, :q => "a" - response.should render_template('request/_search_ahead.rhtml') + response.should render_template('request/_search_ahead') assigns[:xapian_requests].should be_nil end it "should do partial matches for longer words" do get :search_typeahead, :q => "chick" - response.should render_template('request/_search_ahead.rhtml') + response.should render_template('request/_search_ahead') assigns[:xapian_requests].results.size.should ==1 end -- cgit v1.2.3 From 16abab79f431a5a6fa3d5980ef7747135bd436a0 Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Wed, 16 Jan 2013 19:07:54 +1100 Subject: Set locale in controller test by passing parameter in get Also using I18n.locale to pass the current locale around. --- spec/controllers/public_body_controller_spec.rb | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb index 29ece18cb..14d32f303 100644 --- a/spec/controllers/public_body_controller_spec.rb +++ b/spec/controllers/public_body_controller_spec.rb @@ -43,18 +43,14 @@ describe PublicBodyController, "when showing a body" do :conditions => ["public_body_id = ?", public_bodies(:humpadink_public_body).id]) end - it "should assign the body using different locale from that used for url_name" do - PublicBody.with_locale(:es) do - get :show, {:url_name => "dfh", :view => 'all'} - assigns[:public_body].notes.should == "Baguette" - end + it "should redirect to the canonical name in the chosen locale" do + get :show, {:url_name => "dfh", :view => 'all', :show_locale => "es"} + response.should redirect_to "http://test.host/es/body/edfh" end it "should assign the body using same locale as that used in url_name" do - PublicBody.with_locale(:es) do - get :show, {:url_name => "edfh", :view => 'all'} - assigns[:public_body].notes.should == "Baguette" - end + get :show, {:url_name => "edfh", :view => 'all', :show_locale => "es"} + response.should include_text("Baguette") end it "should redirect use to the relevant locale even when url_name is for a different locale" do -- cgit v1.2.3 From 5f6a7a29bc1ea3784728a9c57edfa4be73d4196f Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Thu, 17 Jan 2013 05:26:54 +1100 Subject: Set locale with I18n rather than through globalize --- spec/controllers/admin_public_body_controller_spec.rb | 10 +++++----- spec/controllers/public_body_controller_spec.rb | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/admin_public_body_controller_spec.rb b/spec/controllers/admin_public_body_controller_spec.rb index 504ddc5cc..255eacbd0 100644 --- a/spec/controllers/admin_public_body_controller_spec.rb +++ b/spec/controllers/admin_public_body_controller_spec.rb @@ -288,7 +288,7 @@ describe AdminPublicBodyController, "when administering public bodies with i18n" end it "saves edits to a public body" do - PublicBody.with_locale(:es) do + I18n.with_locale(:es) do pb = PublicBody.find(id=3) pb.name.should == "El Department for Humpadinking" post :update, { @@ -308,10 +308,10 @@ describe AdminPublicBodyController, "when administering public bodies with i18n" end pb = PublicBody.find(public_bodies(:humpadink_public_body).id) - PublicBody.with_locale(:es) do + I18n.with_locale(:es) do pb.name.should == "Renamed" end - PublicBody.with_locale(:en) do + I18n.with_locale(:en) do pb.name.should == "Department for Humpadinking" end end @@ -357,12 +357,12 @@ describe AdminPublicBodyController, "when creating public bodies with i18n" do body = PublicBody.find_by_name("New Quango") body.translations.map {|t| t.locale.to_s}.sort.should == ["en", "es"] - PublicBody.with_locale(:en) do + I18n.with_locale(:en) do body.name.should == "New Quango" body.url_name.should == "new_quango" body.first_letter.should == "N" end - PublicBody.with_locale(:es) do + I18n.with_locale(:es) do body.name.should == "Mi Nuevo Quango" body.url_name.should == "mi_nuevo_quango" body.first_letter.should == "M" diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb index 14d32f303..267a854cd 100644 --- a/spec/controllers/public_body_controller_spec.rb +++ b/spec/controllers/public_body_controller_spec.rb @@ -83,7 +83,7 @@ describe PublicBodyController, "when listing bodies" do end it "should list all bodies from default locale, even when there are no translations for selected locale" do - PublicBody.with_locale(:en) do + I18n.with_locale(:en) do @english_only = PublicBody.new(:name => 'English only', :short_name => 'EO', :request_email => 'english@flourish.org', @@ -91,7 +91,7 @@ describe PublicBodyController, "when listing bodies" do :last_edit_comment => '') @english_only.save end - PublicBody.with_locale(:es) do + I18n.with_locale(:es) do get :list assigns[:public_bodies].include?(@english_only).should == true end -- cgit v1.2.3 From 1184061cb54853dad2304b90552d359cc51792b2 Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Wed, 23 Jan 2013 16:15:37 +1100 Subject: Change method name as it conflicts with globalize3 method name --- spec/controllers/admin_public_body_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/controllers') diff --git a/spec/controllers/admin_public_body_controller_spec.rb b/spec/controllers/admin_public_body_controller_spec.rb index 0fdc20338..3fcc9b36d 100644 --- a/spec/controllers/admin_public_body_controller_spec.rb +++ b/spec/controllers/admin_public_body_controller_spec.rb @@ -273,7 +273,7 @@ describe AdminPublicBodyController, "when administering public bodies with i18n" get :edit, {:id => 3, :locale => :en} # When editing a body, the controller returns all available translations - assigns[:public_body].translation("es").name.should == 'El Department for Humpadinking' + assigns[:public_body].find_translation_by_locale("es").name.should == 'El Department for Humpadinking' assigns[:public_body].name.should == 'Department for Humpadinking' response.should render_template('edit') end -- cgit v1.2.3 From 8ab884f0da68b17f33577a197ebd0e7d412a28ed Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Fri, 25 Jan 2013 11:23:43 +1100 Subject: Disable routing filter in tests by using RoutingFilter.active rather than writing to ActionController::Routing::Routes.filters --- spec/controllers/public_body_controller_spec.rb | 5 ++--- spec/controllers/request_controller_spec.rb | 5 ++--- spec/controllers/track_controller_spec.rb | 5 ++--- spec/controllers/user_controller_spec.rb | 25 ++++++++++--------------- 4 files changed, 16 insertions(+), 24 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb index a0841b621..3a42b535f 100644 --- a/spec/controllers/public_body_controller_spec.rb +++ b/spec/controllers/public_body_controller_spec.rb @@ -58,13 +58,12 @@ describe PublicBodyController, "when showing a body" do end it "should redirect use to the relevant locale even when url_name is for a different locale" do - old_filters = ActionController::Routing::Routes.filters - ActionController::Routing::Routes.filters = RoutingFilter::Chain.new + RoutingFilter.active = false get :show, {:url_name => "edfh", :view => 'all'} response.should redirect_to "http://test.host/body/dfh" - ActionController::Routing::Routes.filters = old_filters + RoutingFilter.active = true end it "should redirect to newest name if you use historic name of public body in URL" do diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index da05785c5..2a812a1fb 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -1513,11 +1513,10 @@ describe RequestController, "when classifying an information request" do @dog_request = info_requests(:fancy_dog_request) @dog_request.stub!(:each).and_return([@dog_request]) InfoRequest.stub!(:find).and_return(@dog_request) - @old_filters = ActionController::Routing::Routes.filters - ActionController::Routing::Routes.filters = RoutingFilter::Chain.new + RoutingFilter.active = false end after do - ActionController::Routing::Routes.filters = @old_filters + RoutingFilter.active = true end def request_url diff --git a/spec/controllers/track_controller_spec.rb b/spec/controllers/track_controller_spec.rb index cd7932e90..009ef2f4a 100644 --- a/spec/controllers/track_controller_spec.rb +++ b/spec/controllers/track_controller_spec.rb @@ -66,8 +66,7 @@ describe TrackController, "when sending alerts for a track" do it "should send alerts" do # Don't do clever locale-insertion-unto-URL stuff - old_filters = ActionController::Routing::Routes.filters - ActionController::Routing::Routes.filters = RoutingFilter::Chain.new + RoutingFilter.active = false # set the time the comment event happened at to within the last week ire = info_request_events(:silly_comment_event) @@ -115,7 +114,7 @@ describe TrackController, "when sending alerts for a track" do deliveries.size.should == 0 # Restore the routing filters - ActionController::Routing::Routes.filters = old_filters + RoutingFilter.active = true end it "should send localised alerts" do diff --git a/spec/controllers/user_controller_spec.rb b/spec/controllers/user_controller_spec.rb index db64bdcaf..dcd08dfaa 100644 --- a/spec/controllers/user_controller_spec.rb +++ b/spec/controllers/user_controller_spec.rb @@ -100,8 +100,7 @@ describe UserController, "when signing in" do end it "should log in when you give right email/password, and redirect to where you were" do - old_filters = ActionController::Routing::Routes.filters - ActionController::Routing::Routes.filters = RoutingFilter::Chain.new + RoutingFilter.active = false get :signin, :r => "/list" response.should render_template('sign') @@ -114,12 +113,11 @@ describe UserController, "when signing in" do response.should redirect_to(:controller => 'request', :action => 'list', :post_redirect => 1) response.should_not send_email - ActionController::Routing::Routes.filters = old_filters + RoutingFilter.active = true end it "should not log you in if you use an invalid PostRedirect token, and shouldn't give 500 error either" do - old_filters = ActionController::Routing::Routes.filters - ActionController::Routing::Routes.filters = RoutingFilter::Chain.new + RoutingFilter.active = false post_redirect = "something invalid" lambda { @@ -132,7 +130,7 @@ describe UserController, "when signing in" do response.should render_template('sign') assigns[:post_redirect].should == nil - ActionController::Routing::Routes.filters = old_filters + RoutingFilter.active = true end # No idea how to test this in the test framework :( @@ -156,8 +154,7 @@ describe UserController, "when signing in" do end it "should confirm your email, log you in and redirect you to where you were after you click an email link" do - old_filters = ActionController::Routing::Routes.filters - ActionController::Routing::Routes.filters = RoutingFilter::Chain.new + RoutingFilter.active = false get :signin, :r => "/list" post_redirect = get_last_postredirect @@ -185,12 +182,11 @@ describe UserController, "when signing in" do session[:user_id].should == users(:unconfirmed_user).id response.should redirect_to(:controller => 'request', :action => 'list', :post_redirect => 1) - ActionController::Routing::Routes.filters = old_filters + RoutingFilter.active = true end it "should keep you logged in if you click a confirmation link and are already logged in as an admin" do - old_filters = ActionController::Routing::Routes.filters - ActionController::Routing::Routes.filters = RoutingFilter::Chain.new + RoutingFilter.active = false get :signin, :r => "/list" post_redirect = get_last_postredirect @@ -222,7 +218,7 @@ describe UserController, "when signing in" do # And the redirect should still work, of course response.should redirect_to(:controller => 'request', :action => 'list', :post_redirect => 1) - ActionController::Routing::Routes.filters = old_filters + RoutingFilter.active = true end end @@ -295,15 +291,14 @@ describe UserController, "when signing out" do end it "should log you out and redirect you to where you were" do - old_filters = ActionController::Routing::Routes.filters - ActionController::Routing::Routes.filters = RoutingFilter::Chain.new + RoutingFilter.active = false session[:user_id] = users(:bob_smith_user).id get :signout, :r => '/list' session[:user_id].should be_nil response.should redirect_to(:controller => 'request', :action => 'list') - ActionController::Routing::Routes.filters = old_filters + RoutingFilter.active = true end end -- cgit v1.2.3 From bc0ce470ade27fed5376e983d72e9f495d4c0405 Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Mon, 28 Jan 2013 16:33:17 +1100 Subject: Use preceding slash on paths to fixtures files --- spec/controllers/api_controller_spec.rb | 4 ++-- spec/controllers/request_controller_spec.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/api_controller_spec.rb b/spec/controllers/api_controller_spec.rb index 8dc8e2990..2de1c5071 100644 --- a/spec/controllers/api_controller_spec.rb +++ b/spec/controllers/api_controller_spec.rb @@ -213,7 +213,7 @@ describe ApiController, "when using the API" do "body" => "Are you joking, or are you serious?" }.to_json, :attachments => [ - fixture_file_upload("files/tfl.pdf") + fixture_file_upload("/files/tfl.pdf") ] @@ -242,7 +242,7 @@ describe ApiController, "when using the API" do "body" => response_body }.to_json, :attachments => [ - fixture_file_upload("files/tfl.pdf") + fixture_file_upload("/files/tfl.pdf") ] # And make sure it worked diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 2a812a1fb..a85919f2c 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -2060,7 +2060,7 @@ describe RequestController, "authority uploads a response from the web interface session[:user_id] = @normal_user.id # post up a photo of the parrot - parrot_upload = fixture_file_upload('files/parrot.png','image/png') + parrot_upload = fixture_file_upload('/files/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, @@ -2088,7 +2088,7 @@ describe RequestController, "authority uploads a response from the web interface session[:user_id] = @foi_officer_user.id # post up a photo of the parrot - parrot_upload = fixture_file_upload('files/parrot.png','image/png') + parrot_upload = fixture_file_upload('/files/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, -- cgit v1.2.3 From b37586c7165afb7b3447dfe2780169a88cb0a942 Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Mon, 28 Jan 2013 19:44:22 +1100 Subject: Replace use of have_tag with have_selector from webrat --- spec/controllers/general_controller_spec.rb | 8 +++--- spec/controllers/request_controller_spec.rb | 42 ++++++++++++++--------------- spec/controllers/user_controller_spec.rb | 2 +- 3 files changed, 26 insertions(+), 26 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/general_controller_spec.rb b/spec/controllers/general_controller_spec.rb index fcd121df6..152943121 100644 --- a/spec/controllers/general_controller_spec.rb +++ b/spec/controllers/general_controller_spec.rb @@ -58,14 +58,14 @@ describe GeneralController, "when showing the frontpage" do it "should render the front page with default language" do get :frontpage - response.should have_tag('html[lang="en"]') + response.should have_selector('html[lang="en"]') end it "should render the front page with default language" do old_default_locale = I18n.default_locale I18n.default_locale = "es" get :frontpage - response.should have_tag('html[lang="es"]') + response.should have_selector('html[lang="es"]') I18n.default_locale = old_default_locale end @@ -77,7 +77,7 @@ describe GeneralController, "when showing the frontpage" do old_default_locale = I18n.default_locale I18n.default_locale = "es" get :frontpage - response.should have_tag('html[lang="es"]') + response.should have_selector('html[lang="es"]') I18n.default_locale = old_default_locale end @@ -87,7 +87,7 @@ describe GeneralController, "when showing the frontpage" do accept_language = "es-ES,en-GB,en-US;q=0.8,en;q=0.6" request.env['HTTP_ACCEPT_LANGUAGE'] = accept_language get :frontpage - response.should have_tag('html[lang="es"]') + response.should have_selector('html[lang="es"]') request.env['HTTP_ACCEPT_LANGUAGE'] = nil end diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index a85919f2c..f952eecc6 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -222,14 +222,14 @@ describe RequestController, "when showing one request" do it 'should show actions the request owner can take' do get :show, :url_title => 'why_do_you_have_such_a_fancy_dog' - response.should have_tag('div#owner_actions') + response.should have_selector('div#owner_actions') end describe 'when the request does allow comments' do it 'should have a comment link' do get :show, { :url_title => 'why_do_you_have_such_a_fancy_dog' }, { :user_id => users(:admin_user).id } - response.should have_tag('#anyone_actions', /Add an annotation/) + response.should have_selector('#anyone_actions', :content => "Add an annotation") end end @@ -237,7 +237,7 @@ describe RequestController, "when showing one request" do it 'should not have a comment link' do get :show, { :url_title => 'spam_1' }, { :user_id => users(:admin_user).id } - response.should_not have_tag('#anyone_actions', /Add an annotation/) + response.should_not have_selector('#anyone_actions', :content => "Add an annotation") end end @@ -254,13 +254,13 @@ describe RequestController, "when showing one request" do it 'should show the describe state form' do get :show, { :url_title => 'why_do_you_have_such_a_fancy_dog' }, { :user_id => users(:admin_user).id } - response.should have_tag('div.describe_state_form') + response.should have_selector('div.describe_state_form') end it 'should ask the user to use the describe state from' do get :show, { :url_title => 'why_do_you_have_such_a_fancy_dog' }, { :user_id => users(:admin_user).id } - response.should have_tag('p#request_status', :text => /answer the question above/) + response.should have_selector('p#request_status', :text => /answer the question above/) end end @@ -278,7 +278,7 @@ describe RequestController, "when showing one request" do it 'should give a link to requesting an internal review' do get :show, { :url_title => 'why_do_you_have_such_a_fancy_dog' }, { :user_id => users(:admin_user).id } - response.should have_tag('p#request_status', :text =>/requesting an internal review/) + response.should have_selector('p#request_status', :text =>/requesting an internal review/) end end @@ -296,7 +296,7 @@ describe RequestController, "when showing one request" do it 'should give a link to make a followup' do get :show, { :url_title => 'why_do_you_have_such_a_fancy_dog' }, { :user_id => users(:admin_user).id } - response.should have_tag('p#request_status a', :text =>/send a follow up message/) + response.should have_selector('p#request_status a', :text =>/send a follow up message/) end end @@ -313,7 +313,7 @@ describe RequestController, "when showing one request" do it 'should not display actions the request owner can take' do get :show, :url_title => 'balalas' - response.should_not have_tag('div#owner_actions') + response.should_not have_selector('div#owner_actions') end end @@ -339,12 +339,12 @@ describe RequestController, "when showing one request" do it 'should not show the describe state form' do make_request - response.should_not have_tag('div.describe_state_form') + response.should_not have_selector('div.describe_state_form') end it 'should not ask the user to use the describe state form' do make_request - response.should_not have_tag('p#request_status', :text => /answer the question above/) + response.should_not have_selector('p#request_status', :content => "answer the question above") end end @@ -361,7 +361,7 @@ describe RequestController, "when showing one request" do it 'should not give a link to requesting an internal review' do make_request - response.should_not have_tag('p#request_status', :text =>/requesting an internal review/) + response.should_not have_selector('p#request_status', :content => "requesting an internal review") end end @@ -377,12 +377,12 @@ describe RequestController, "when showing one request" do it 'should not give a link to make a followup' do make_request - response.should_not have_tag('p#request_status a', :text =>/send a follow up message/) + response.should_not have_selector('p#request_status a', :content => "send a follow up message") end it 'should not give a link to sign in (in the request status paragraph)' do make_request - response.should_not have_tag('p#request_status a', :text => /sign in/) + response.should_not have_selector('p#request_status a', :content => "sign in") end end @@ -696,7 +696,7 @@ describe RequestController, "when showing one request" do # so at this point, assigns[:info_request].incoming_messages[1].get_attachments_for_display is returning stuff, but the equivalent thing in the template isn't. # but something odd is that the above is return a whole load of attachments which aren't there in the controller - response.body.should have_tag("p.attachment strong", /hello.txt/m) + response.body.should have_selector("p.attachment strong", :content => "hello.txt") censor_rule = CensorRule.new() censor_rule.text = "hello.txt" @@ -706,7 +706,7 @@ describe RequestController, "when showing one request" do ir.censor_rules << censor_rule begin get :show, :url_title => 'why_do_you_have_such_a_fancy_dog' - response.body.should have_tag("p.attachment strong", /goodbye.txt/m) + response.body.should have_selector("p.attachment strong", :content => "goodbye.txt") ensure ir.censor_rules.clear end @@ -1199,7 +1199,7 @@ describe RequestController, "when viewing an individual response for reply/follo it "should offer the opportunity to reply to the main address" do session[:user_id] = users(:bob_smith_user).id get :show_response, :id => info_requests(:fancy_dog_request).id, :incoming_message_id => incoming_messages(:useless_incoming_message) - response.body.should have_tag("div#other_recipients ul li", /the main FOI contact address for/) + response.body.should have_selector("div#other_recipients ul li", :content => "the main FOI contact address for") end it "should offer an opportunity to reply to another address" do @@ -1209,7 +1209,7 @@ describe RequestController, "when viewing an individual response for reply/follo ir.save! receive_incoming_mail('incoming-request-plain.email', ir.incoming_email, "Frob ") get :show_response, :id => ir.id, :incoming_message_id => incoming_messages(:useless_incoming_message) - response.body.should have_tag("div#other_recipients ul li", /Frob/) + response.body.should have_selector("div#other_recipients ul li", :content => "Frob") end it "should not show individual responses if request hidden, even if request owner" do @@ -2007,15 +2007,15 @@ describe RequestController, "when viewing comments" do it "should link to the user who submitted it" do session[:user_id] = users(:bob_smith_user).id get :show, :url_title => 'why_do_you_have_such_a_fancy_dog' - response.body.should have_tag("div#comment-1 h2", /Silly.*left an annotation/m) - response.body.should_not have_tag("div#comment-1 h2", /You.*left an annotation/m) + response.body.should have_selector("div#comment-1 h2", :content => "Silly.*left an annotation") + response.body.should_not have_selector("div#comment-1 h2", :content => "You.*left an annotation") end it "should link to the user who submitted to it, even if it is you" do session[:user_id] = users(:silly_name_user).id get :show, :url_title => 'why_do_you_have_such_a_fancy_dog' - response.body.should have_tag("div#comment-1 h2", /Silly.*left an annotation/m) - response.body.should_not have_tag("div#comment-1 h2", /You.*left an annotation/m) + response.body.should have_selector("div#comment-1 h2", :content => "Silly.*left an annotation") + response.body.should_not have_selector("div#comment-1 h2", :content => "You.*left an annotation") end end diff --git a/spec/controllers/user_controller_spec.rb b/spec/controllers/user_controller_spec.rb index dcd08dfaa..81360d78c 100644 --- a/spec/controllers/user_controller_spec.rb +++ b/spec/controllers/user_controller_spec.rb @@ -74,7 +74,7 @@ describe UserController, "when signing in" do it "should show sign in / sign up page" do get :signin - response.should have_tag("input#signin_token") + response.should have_selector("input#signin_token") end it "should create post redirect to / when you just go to /signin" do -- cgit v1.2.3 From e3f045826c0c48cbcffb94816028948784bfd4a3 Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Tue, 29 Jan 2013 09:49:21 +1100 Subject: Correct use of have_selector in b37586c7165afb7b3447dfe2780169a88cb0a942. --- spec/controllers/request_controller_spec.rb | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index f952eecc6..36af1cd96 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -260,7 +260,7 @@ describe RequestController, "when showing one request" do it 'should ask the user to use the describe state from' do get :show, { :url_title => 'why_do_you_have_such_a_fancy_dog' }, { :user_id => users(:admin_user).id } - response.should have_selector('p#request_status', :text => /answer the question above/) + response.should have_selector('p#request_status', :content => "answer the question above") end end @@ -278,7 +278,7 @@ describe RequestController, "when showing one request" do it 'should give a link to requesting an internal review' do get :show, { :url_title => 'why_do_you_have_such_a_fancy_dog' }, { :user_id => users(:admin_user).id } - response.should have_selector('p#request_status', :text =>/requesting an internal review/) + response.should have_selector('p#request_status', :content => "requesting an internal review") end end @@ -296,7 +296,7 @@ describe RequestController, "when showing one request" do it 'should give a link to make a followup' do get :show, { :url_title => 'why_do_you_have_such_a_fancy_dog' }, { :user_id => users(:admin_user).id } - response.should have_selector('p#request_status a', :text =>/send a follow up message/) + response.should have_selector('p#request_status a', :content => "send a follow up message") end end @@ -696,7 +696,9 @@ describe RequestController, "when showing one request" do # so at this point, assigns[:info_request].incoming_messages[1].get_attachments_for_display is returning stuff, but the equivalent thing in the template isn't. # but something odd is that the above is return a whole load of attachments which aren't there in the controller - response.body.should have_selector("p.attachment strong", :content => "hello.txt") + response.body.should have_selector("p.attachment strong") do |s| + s.should contain /hello.txt/m + end censor_rule = CensorRule.new() censor_rule.text = "hello.txt" @@ -706,7 +708,9 @@ describe RequestController, "when showing one request" do ir.censor_rules << censor_rule begin get :show, :url_title => 'why_do_you_have_such_a_fancy_dog' - response.body.should have_selector("p.attachment strong", :content => "goodbye.txt") + response.body.should have_selector("p.attachment strong") do |s| + s.should contain /goodbye.txt/m + end ensure ir.censor_rules.clear end @@ -2007,15 +2011,19 @@ describe RequestController, "when viewing comments" do it "should link to the user who submitted it" do session[:user_id] = users(:bob_smith_user).id get :show, :url_title => 'why_do_you_have_such_a_fancy_dog' - response.body.should have_selector("div#comment-1 h2", :content => "Silly.*left an annotation") - response.body.should_not have_selector("div#comment-1 h2", :content => "You.*left an annotation") + response.body.should have_selector("div#comment-1 h2") do |s| + s.should contain /Silly.*left an annotation/m + s.should_not contain /You.*left an annotation/m + end end it "should link to the user who submitted to it, even if it is you" do session[:user_id] = users(:silly_name_user).id get :show, :url_title => 'why_do_you_have_such_a_fancy_dog' - response.body.should have_selector("div#comment-1 h2", :content => "Silly.*left an annotation") - response.body.should_not have_selector("div#comment-1 h2", :content => "You.*left an annotation") + response.body.should have_selector("div#comment-1 h2") do |s| + s.should contain /Silly.*left an annotation/m + s.should_not contain /You.*left an annotation/m + end end end -- cgit v1.2.3 From c0360fa374b096964b67ff5195e86ef83936c62f Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Tue, 29 Jan 2013 10:40:07 +1100 Subject: Replace use of have_text with contain from webrat or match --- spec/controllers/admin_request_controller_spec.rb | 4 +-- spec/controllers/general_controller_spec.rb | 18 +++++----- spec/controllers/request_controller_spec.rb | 44 +++++++++++------------ 3 files changed, 33 insertions(+), 33 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/admin_request_controller_spec.rb b/spec/controllers/admin_request_controller_spec.rb index 6d7ab611e..d16235717 100644 --- a/spec/controllers/admin_request_controller_spec.rb +++ b/spec/controllers/admin_request_controller_spec.rb @@ -90,7 +90,7 @@ describe AdminRequestController, "when administering the holding pen" do ir.save! receive_incoming_mail('incoming-request-plain.email', ir.incoming_email, "frob@nowhere.com") get :show_raw_email, :id => InfoRequest.holding_pen_request.get_last_response.raw_email.id - response.should have_text(/Only the authority can reply to this request/) + response.should contain "Only the authority can reply to this request" end it "allows redelivery even to a closed request" do @@ -154,7 +154,7 @@ describe AdminRequestController, "when administering the holding pen" do receive_incoming_mail('incoming-request-plain.email', ir.incoming_email, "") InfoRequest.holding_pen_request.incoming_messages.length.should == 2 get :show_raw_email, :id => interesting_email - response.should have_text(/Could not identify the request/) + response.should contain "Could not identify the request" assigns[:info_requests][0].should == ir end diff --git a/spec/controllers/general_controller_spec.rb b/spec/controllers/general_controller_spec.rb index 152943121..c7d9b5ce3 100644 --- a/spec/controllers/general_controller_spec.rb +++ b/spec/controllers/general_controller_spec.rb @@ -120,13 +120,13 @@ describe GeneralController, "when showing the frontpage" do it 'should generate URLs without a locale prepended' do get :frontpage - response.should_not have_text(@default_lang_home_link) + response.should_not contain @default_lang_home_link end it 'should render the front page in the default language when no locale param is present and the session locale is not the default' do get(:frontpage, {}, {:locale => 'es'}) - response.should_not have_text(@other_lang_home_link) + response.should_not contain @other_lang_home_link end end @@ -134,7 +134,7 @@ describe GeneralController, "when showing the frontpage" do INCLUDE_DEFAULT_LOCALE_IN_URLS is true' do set_default_locale_in_urls(true) get :frontpage - response.should have_text(@default_lang_home_link) + response.body.should match /#{@default_lang_home_link}/ end after do @@ -150,28 +150,28 @@ describe GeneralController, "when showing the frontpage" do it "should generate URLs with a locale prepended when there's more than one locale set" do get :frontpage - response.should have_text(home_link_regex) + response.body.should match home_link_regex end it "should use our test PO files rather than the application one" do I18n.default_locale = :es get :frontpage - response.should have_text(/XOXO/) + response.body.should match /XOXO/ I18n.default_locale = :en end it "should generate URLs that include the locale when using one that includes an underscore" do I18n.default_locale = :"en_GB" get :frontpage - response.should have_text(/href="\/en_GB\//) + response.body.should match /href="\/en_GB\// I18n.default_locale = :en end it "should fall back to the language if the territory is unknown" do I18n.default_locale = :"en_US" get :frontpage - response.should have_text(/href="\/en\//) - response.should_not have_text(/href="\/en_US\//) + response.body.should match /href="\/en\// + response.body.should_not match /href="\/en_US\// I18n.default_locale = :en end @@ -181,7 +181,7 @@ describe GeneralController, "when showing the frontpage" do FastGettext.default_available_locales = I18n.available_locales = ['en'] get :frontpage - response.should_not have_text(home_link_regex) + response.should_not contain home_link_regex FastGettext.default_available_locales = old_fgt_available_locales I18n.available_locales = old_i18n_available_locales diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 36af1cd96..5f9ead973 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -481,11 +481,11 @@ describe RequestController, "when showing one request" do get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => ['hello.txt'], :skip_cache => 1 response.content_type.should == "text/plain" - response.should have_text(/Second hello/) + response.should contain "Second hello" get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 3, :file_name => ['hello.txt'], :skip_cache => 1 response.content_type.should == "text/plain" - response.should have_text(/First hello/) + response.should contain "First hello" end it 'should cache an attachment on a request with normal prominence' do @@ -504,7 +504,7 @@ describe RequestController, "when showing one request" do ir = info_requests(:fancy_dog_request) receive_incoming_mail('iso8859_2_raw_email.email', ir.incoming_email) get :show, :url_title => 'why_do_you_have_such_a_fancy_dog' - response.should have_text(/tĆ«nde/u) + response.should contain "tĆ«nde" end it "should generate valid HTML verson of plain text attachments" do @@ -513,7 +513,7 @@ describe RequestController, "when showing one request" do ir.reload get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => ['hello.txt.html'], :skip_cache => 1 response.content_type.should == "text/html" - response.should have_text(/Second hello/) + response.should contain "Second hello" end # This is a regression test for a bug where URLs of this form were causing 500 errors @@ -578,7 +578,7 @@ describe RequestController, "when showing one request" do ir.reload get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => ['fs_50379341.pdf.html'], :skip_cache => 1 response.content_type.should == "text/html" - response.should have_text(/Walberswick Parish Council/) + response.should contain "Walberswick Parish Council" end it "should not cause a reparsing of the raw email, even when the result would be a 404" do @@ -586,7 +586,7 @@ describe RequestController, "when showing one request" do receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email) ir.reload attachment = IncomingMessage.get_attachment_by_url_part_number(ir.incoming_messages[1].get_attachments_for_display, 2) - attachment.body.should have_text(/Second hello/) + attachment.body.should contain "Second hello" # change the raw_email associated with the message; this only be reparsed when explicitly asked for ir.incoming_messages[1].raw_email.data = ir.incoming_messages[1].raw_email.data.sub("Second", "Third") @@ -598,19 +598,19 @@ describe RequestController, "when showing one request" do }.should raise_error(ActiveRecord::RecordNotFound) attachment = IncomingMessage.get_attachment_by_url_part_number(ir.incoming_messages[1].get_attachments_for_display, 2) - attachment.body.should have_text(/Second hello/) + attachment.body.should contain "Second hello" # ...nor should asking for it by its correct filename... get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => ['hello.txt.html'], :skip_cache => 1 - response.should_not have_text(/Third hello/) + response.should_not contain "Third hello" # ...but if we explicitly ask for attachments to be extracted, then they should be force = true ir.incoming_messages[1].parse_raw_email!(force) attachment = IncomingMessage.get_attachment_by_url_part_number(ir.incoming_messages[1].get_attachments_for_display, 2) - attachment.body.should have_text(/Second hello/) + attachment.body.should contain "Second hello" get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => ['hello.txt.html'], :skip_cache => 1 - response.should have_text(/Third hello/) + response.should contain "Third hello" end it "should treat attachments with unknown extensions as binary" do @@ -620,7 +620,7 @@ describe RequestController, "when showing one request" do get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => ['hello.qwglhm'], :skip_cache => 1 response.content_type.should == "application/octet-stream" - response.should have_text(/an unusual sort of file/) + response.should contain "an unusual sort of file" end it "should not download attachments with wrong file name" do @@ -648,7 +648,7 @@ describe RequestController, "when showing one request" do get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => ['hello.txt'], :skip_cache => 1 response.content_type.should == "text/plain" - response.should have_text(/xxxxxx hello/) + response.should contain "xxxxxx hello" ensure ir.censor_rules.clear end @@ -670,7 +670,7 @@ describe RequestController, "when showing one request" do get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => ['hello.txt'], :skip_cache => 1 response.content_type.should == "text/plain" - response.should have_text(/xxxxxx hello/) + response.should contain "xxxxxx hello" ensure ir.user.censor_rules.clear end @@ -733,17 +733,17 @@ describe RequestController, "when showing one request" do ir = info_requests(:fancy_dog_request) session[:user_id] = ir.user.id # bob_smith_user get :download_entire_request, :url_title => title - assigns[:url_path].should have_text(/#{title}.zip$/) + assigns[:url_path].should contain /#{title}.zip$/ old_path = assigns[:url_path] - response.location.should have_text(/#{assigns[:url_path]}$/) + response.location.should contain /#{assigns[:url_path]}$/ zipfile = Zip::ZipFile.open(File.join(File.dirname(__FILE__), "../../cache/zips", old_path)) { |zipfile| zipfile.count.should == 1 # just the message } receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email) get :download_entire_request, :url_title => title - assigns[:url_path].should have_text(/#{title}.zip$/) + assigns[:url_path].should contain /#{title}.zip$/ old_path = assigns[:url_path] - response.location.should have_text(/#{assigns[:url_path]}$/) + response.location.should contain /#{assigns[:url_path]}$/ zipfile = Zip::ZipFile.open(File.join(File.dirname(__FILE__), "../../cache/zips", old_path)) { |zipfile| zipfile.count.should == 3 # the message plus two "hello.txt" files } @@ -754,9 +754,9 @@ describe RequestController, "when showing one request" do sleep 1 receive_incoming_mail('incoming-request-attachment-unknown-extension.email', ir.incoming_email) get :download_entire_request, :url_title => title - assigns[:url_path].should have_text(/#{title}.zip$/) + assigns[:url_path].should contain /#{title}.zip$/ assigns[:url_path].should_not == old_path - response.location.should have_text(/#{assigns[:url_path]}/) + response.location.should contain assigns[:url_path] zipfile = Zip::ZipFile.open(File.join(File.dirname(__FILE__), "../../cache/zips", assigns[:url_path])) { |zipfile| zipfile.count.should == 4 # the message, two hello.txt plus the unknown attachment } @@ -766,7 +766,7 @@ describe RequestController, "when showing one request" do info_request = info_requests(:external_request) get :download_entire_request, { :url_title => info_request.url_title }, { :user_id => users(:bob_smith_user) } - response.location.should have_text(/#{assigns[:url_path]}$/) + response.location.should contain /#{assigns[:url_path]}$/ end end end @@ -855,14 +855,14 @@ describe RequestController, "when changing prominence of a request" do :part => 2, :skip_cache => 1 response.content_type.should == "text/html" - response.should_not have_text(/Second hello/) + response.should_not contain "Second hello" response.should render_template('request/hidden') get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 3, :skip_cache => 1 response.content_type.should == "text/html" - response.should_not have_text(/First hello/) + response.should_not contain "First hello" response.should render_template('request/hidden') response.code.should == '410' end -- cgit v1.2.3 From 10e7fe18316f03b525a467c3d8a6e2115391c83e Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Tue, 29 Jan 2013 13:04:00 +1100 Subject: Reset Actionmailer deliveries on controller tests. Apparently rspec isn't now doing this automatically --- spec/controllers/request_controller_spec.rb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'spec/controllers') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 5f9ead973..847031674 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -2,6 +2,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe RequestController, "when listing recent requests" do + before { ActionMailer::Base.deliveries = [] } before(:each) do load_raw_emails_data @@ -120,6 +121,7 @@ describe RequestController, "when listing recent requests" do end describe RequestController, "when changing things that appear on the request page" do + before { ActionMailer::Base.deliveries = [] } render_views @@ -187,6 +189,7 @@ describe RequestController, "when changing things that appear on the request pag end describe RequestController, "when showing one request" do + before { ActionMailer::Base.deliveries = [] } render_views before(:each) do @@ -445,6 +448,8 @@ describe RequestController, "when showing one request" do describe 'when handling incoming mail' do + before { ActionMailer::Base.deliveries = [] } + render_views it "should receive incoming messages, send email to creator, and show them" do @@ -773,6 +778,7 @@ describe RequestController, "when showing one request" do end describe RequestController, "when changing prominence of a request" do + before { ActionMailer::Base.deliveries = [] } before(:each) do load_raw_emails_data @@ -906,6 +912,7 @@ end # end describe RequestController, "when searching for an authority" do + before { ActionMailer::Base.deliveries = [] } # Whether or not sign-in is required for this step is configurable, # so we make sure we're logged in, just in case @@ -946,6 +953,8 @@ describe RequestController, "when searching for an authority" do end describe RequestController, "when creating a new request" do + + before { ActionMailer::Base.deliveries = [] } render_views before do @@ -1133,6 +1142,7 @@ end # These go with the previous set, but use mocks instead of fixtures. # TODO harmonise these describe RequestController, "when making a new request" do + before { ActionMailer::Base.deliveries = [] } before do @user = mock_model(User, :id => 3481, :name => 'Testy') @@ -1182,6 +1192,7 @@ describe RequestController, "when making a new request" do end describe RequestController, "when viewing an individual response for reply/followup" do + before { ActionMailer::Base.deliveries = [] } render_views before(:each) do @@ -1244,6 +1255,8 @@ describe RequestController, "when viewing an individual response for reply/follo end describe RequestController, "when classifying an information request" do + + before { ActionMailer::Base.deliveries = [] } describe 'if the request is external' do @@ -1614,6 +1627,7 @@ describe RequestController, "when classifying an information request" do end describe RequestController, "when sending a followup message" do + before { ActionMailer::Base.deliveries = [] } render_views before(:each) do @@ -1700,6 +1714,7 @@ describe RequestController, "sending overdue request alerts" do before(:each) do load_raw_emails_data + ActionMailer::Base.deliveries = [] end it "should send an overdue alert mail to creators of overdue requests" do @@ -1841,6 +1856,7 @@ describe RequestController, "sending overdue request alerts" do end describe RequestController, "sending unclassified new response reminder alerts" do + before { ActionMailer::Base.deliveries = [] } render_views before(:each) do @@ -1871,6 +1887,7 @@ describe RequestController, "sending unclassified new response reminder alerts" end describe RequestController, "clarification required alerts" do + before { ActionMailer::Base.deliveries = [] } render_views before(:each) do load_raw_emails_data @@ -1924,6 +1941,7 @@ describe RequestController, "clarification required alerts" do end describe RequestController, "comment alerts" do + before { ActionMailer::Base.deliveries = [] } render_views before(:each) do load_raw_emails_data @@ -2003,6 +2021,7 @@ describe RequestController, "comment alerts" do end describe RequestController, "when viewing comments" do + before { ActionMailer::Base.deliveries = [] } render_views before(:each) do load_raw_emails_data @@ -2030,6 +2049,7 @@ end describe RequestController, "authority uploads a response from the web interface" do + before { ActionMailer::Base.deliveries = [] } render_views before(:each) do @@ -2120,6 +2140,7 @@ describe RequestController, "authority uploads a response from the web interface end describe RequestController, "when showing JSON version for API" do + before { ActionMailer::Base.deliveries = [] } before(:each) do load_raw_emails_data @@ -2139,6 +2160,7 @@ describe RequestController, "when showing JSON version for API" do end describe RequestController, "when doing type ahead searches" do + before { ActionMailer::Base.deliveries = [] } render_views @@ -2198,6 +2220,7 @@ describe RequestController, "when doing type ahead searches" do end describe RequestController, "when showing similar requests" do + before { ActionMailer::Base.deliveries = [] } render_views it "should work" do @@ -2232,6 +2255,7 @@ end describe RequestController, "when reporting a request when not logged in" do + before { ActionMailer::Base.deliveries = [] } it "should only allow logged-in users to report requests" do get :report_request, :url_title => info_requests(:badger_request).url_title post_redirect = PostRedirect.get_last_post_redirect @@ -2240,6 +2264,7 @@ describe RequestController, "when reporting a request when not logged in" do end describe RequestController, "when reporting a request (logged in)" do + before { ActionMailer::Base.deliveries = [] } render_views before do @@ -2316,6 +2341,7 @@ describe RequestController, "when reporting a request (logged in)" do end describe RequestController, "when caching fragments" do + before { ActionMailer::Base.deliveries = [] } it "should not fail with long filenames" do long_name = "blahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblah.txt" -- cgit v1.2.3 From 30ef245a8ccb31c120a35eef1df35478877b43bf Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Tue, 29 Jan 2013 13:05:21 +1100 Subject: When mocking ActsAsXapian can't use mock_model because it's not a model --- spec/controllers/request_controller_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 847031674..53bae9f9c 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -91,7 +91,7 @@ describe RequestController, "when listing recent requests" do end it "should assign the first page of results" do - xap_results = mock_model(ActsAsXapian::Search, + xap_results = mock(ActsAsXapian::Search, :results => (1..25).to_a.map { |m| { :model => m } }, :matches_estimated => 1000000) @@ -104,7 +104,7 @@ describe RequestController, "when listing recent requests" do end it "should return 404 for pages we don't want to serve up" do - xap_results = mock_model(ActsAsXapian::Search, + xap_results = mock(ActsAsXapian::Search, :results => (1..25).to_a.map { |m| { :model => m } }, :matches_estimated => 1000000) lambda { -- cgit v1.2.3 From e975b6b9448c72781665a69e671f2356d35b900f Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Tue, 29 Jan 2013 13:05:55 +1100 Subject: Pass string to paremeter in test --- spec/controllers/request_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/controllers') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 53bae9f9c..2f5251276 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -219,7 +219,7 @@ describe RequestController, "when showing one request" do end it "should redirect from a numeric URL to pretty one" do - get :show, :url_title => info_requests(:naughty_chicken_request).id + get :show, :url_title => info_requests(:naughty_chicken_request).id.to_s response.should redirect_to(:action => 'show', :url_title => info_requests(:naughty_chicken_request).url_title) end -- cgit v1.2.3 From 166b6d90bc2dc79536d8d2d145281fa340075735 Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Tue, 29 Jan 2013 13:32:55 +1100 Subject: Email address returned from mail doesn't have the name part anymore --- spec/controllers/request_controller_spec.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 2f5251276..11175542e 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -1496,7 +1496,7 @@ describe RequestController, "when classifying an information request" do deliveries.size.should == 1 mail = deliveries[0] mail.body.should =~ /as needing admin/ - mail.from_addrs.first.to_s.should == @request_owner.name_and_email + mail.from_addrs.first.to_s.should == @request_owner.email end it 'should say it is showing advice as to what to do next' do @@ -1681,7 +1681,7 @@ describe RequestController, "when sending a followup message" do deliveries.size.should == 1 mail = deliveries[0] mail.body.should =~ /What a useless response! You suck./ - mail.to_addrs.first.to_s.should == "FOI Person " + mail.to_addrs.first.to_s.should == "foiperson@localhost" response.should redirect_to(:action => 'show', :url_title => info_requests(:fancy_dog_request).url_title) @@ -1729,7 +1729,7 @@ describe RequestController, "sending overdue request alerts" do mail = chicken_mails[0] mail.body.should =~ /promptly, as normally/ - mail.to_addrs.first.to_s.should == info_requests(:naughty_chicken_request).user.name_and_email + mail.to_addrs.first.to_s.should == info_requests(:naughty_chicken_request).user.email mail.body =~ /(http:\/\/.*\/c\/(.*))/ mail_url = $1 @@ -1758,7 +1758,7 @@ describe RequestController, "sending overdue request alerts" do mail = chicken_mails[0] mail.body.should =~ /promptly, as normally/ - mail.to_addrs.first.to_s.should == info_requests(:naughty_chicken_request).user.name_and_email + mail.to_addrs.first.to_s.should == info_requests(:naughty_chicken_request).user.email end it "should send not actually send the overdue alert if the user is banned but should @@ -1786,7 +1786,7 @@ describe RequestController, "sending overdue request alerts" do mail = chicken_mails[0] mail.body.should =~ /required by law/ - mail.to_addrs.first.to_s.should == info_requests(:naughty_chicken_request).user.name_and_email + mail.to_addrs.first.to_s.should == info_requests(:naughty_chicken_request).user.email mail.body =~ /(http:\/\/.*\/c\/(.*))/ mail_url = $1 @@ -1870,7 +1870,7 @@ describe RequestController, "sending unclassified new response reminder alerts" deliveries.size.should == 3 # sufficiently late it sends reminders too mail = deliveries[0] mail.body.should =~ /To let everyone know/ - mail.to_addrs.first.to_s.should == info_requests(:fancy_dog_request).user.name_and_email + mail.to_addrs.first.to_s.should == info_requests(:fancy_dog_request).user.email mail.body =~ /(http:\/\/.*\/c\/(.*))/ mail_url = $1 mail_token = $2 @@ -1907,7 +1907,7 @@ describe RequestController, "clarification required alerts" do deliveries.size.should == 1 mail = deliveries[0] mail.body.should =~ /asked you to explain/ - mail.to_addrs.first.to_s.should == info_requests(:fancy_dog_request).user.name_and_email + mail.to_addrs.first.to_s.should == info_requests(:fancy_dog_request).user.email mail.body =~ /(http:\/\/.*\/c\/(.*))/ mail_url = $1 mail_token = $2 @@ -1961,7 +1961,7 @@ describe RequestController, "comment alerts" do deliveries = ActionMailer::Base.deliveries mail = deliveries[0] mail.body.should =~ /has annotated your/ - mail.to_addrs.first.to_s.should == info_requests(:fancy_dog_request).user.name_and_email + mail.to_addrs.first.to_s.should == info_requests(:fancy_dog_request).user.email mail.body =~ /(http:\/\/.*)/ mail_url = $1 mail_url.should match("/request/why_do_you_have_such_a_fancy_dog#comment-#{new_comment.id}") @@ -2011,7 +2011,7 @@ describe RequestController, "comment alerts" do deliveries.size.should == 1 mail = deliveries[0] mail.body.should =~ /There are 2 new annotations/ - mail.to_addrs.first.to_s.should == info_requests(:fancy_dog_request).user.name_and_email + mail.to_addrs.first.to_s.should == info_requests(:fancy_dog_request).user.email mail.body =~ /(http:\/\/.*)/ mail_url = $1 mail_url.should match("/request/why_do_you_have_such_a_fancy_dog#comment-#{comments(:silly_comment).id}") -- cgit v1.2.3 From 531698075c2d20232f110f64a95f705b5bf686f0 Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Tue, 29 Jan 2013 13:33:29 +1100 Subject: When matching the body of an email to a regex cast it to a string --- spec/controllers/request_controller_spec.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 11175542e..6a012d2b9 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -1731,7 +1731,7 @@ describe RequestController, "sending overdue request alerts" do mail.body.should =~ /promptly, as normally/ mail.to_addrs.first.to_s.should == info_requests(:naughty_chicken_request).user.email - mail.body =~ /(http:\/\/.*\/c\/(.*))/ + mail.body.to_s =~ /(http:\/\/.*\/c\/(.*))/ mail_url = $1 mail_token = $2 @@ -1788,7 +1788,7 @@ describe RequestController, "sending overdue request alerts" do mail.body.should =~ /required by law/ mail.to_addrs.first.to_s.should == info_requests(:naughty_chicken_request).user.email - mail.body =~ /(http:\/\/.*\/c\/(.*))/ + mail.body.to_s =~ /(http:\/\/.*\/c\/(.*))/ mail_url = $1 mail_token = $2 @@ -1871,7 +1871,7 @@ describe RequestController, "sending unclassified new response reminder alerts" mail = deliveries[0] mail.body.should =~ /To let everyone know/ mail.to_addrs.first.to_s.should == info_requests(:fancy_dog_request).user.email - mail.body =~ /(http:\/\/.*\/c\/(.*))/ + mail.body.to_s =~ /(http:\/\/.*\/c\/(.*))/ mail_url = $1 mail_token = $2 @@ -1908,7 +1908,7 @@ describe RequestController, "clarification required alerts" do mail = deliveries[0] mail.body.should =~ /asked you to explain/ mail.to_addrs.first.to_s.should == info_requests(:fancy_dog_request).user.email - mail.body =~ /(http:\/\/.*\/c\/(.*))/ + mail.body.to_s =~ /(http:\/\/.*\/c\/(.*))/ mail_url = $1 mail_token = $2 @@ -1962,7 +1962,7 @@ describe RequestController, "comment alerts" do mail = deliveries[0] mail.body.should =~ /has annotated your/ mail.to_addrs.first.to_s.should == info_requests(:fancy_dog_request).user.email - mail.body =~ /(http:\/\/.*)/ + mail.body.to_s =~ /(http:\/\/.*)/ mail_url = $1 mail_url.should match("/request/why_do_you_have_such_a_fancy_dog#comment-#{new_comment.id}") @@ -2012,7 +2012,7 @@ describe RequestController, "comment alerts" do mail = deliveries[0] mail.body.should =~ /There are 2 new annotations/ mail.to_addrs.first.to_s.should == info_requests(:fancy_dog_request).user.email - mail.body =~ /(http:\/\/.*)/ + mail.body.to_s =~ /(http:\/\/.*)/ mail_url = $1 mail_url.should match("/request/why_do_you_have_such_a_fancy_dog#comment-#{comments(:silly_comment).id}") -- cgit v1.2.3 From 1e5344db0a4365da174e95ae419dae4b06fd7e47 Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Tue, 29 Jan 2013 16:26:07 +1100 Subject: modernise redirect tests by converting to using url helpers --- spec/controllers/request_controller_spec.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 6a012d2b9..b7e3f1f57 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -1044,7 +1044,7 @@ describe RequestController, "when creating a new request" do mail = deliveries[0] 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) + response.should redirect_to show_new_request_url(: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$/ @@ -1082,7 +1082,7 @@ describe RequestController, "when creating a new request" do ir.url_title.should_not == ir2.url_title - response.should redirect_to(:action => 'show', :url_title => ir2.url_title) + response.should redirect_to show_new_request_url(:url_title => ir2.url_title) end it 'should respect the rate limit' do @@ -1094,14 +1094,14 @@ describe RequestController, "when creating a new request" do :title => "What is the answer to the ultimate question?", :tag_string => "" }, :outgoing_message => { :body => "Please supply the answer from your files." }, :submitted_new_request => 1, :preview => 0 - response.should redirect_to(:action => 'show', :url_title => 'what_is_the_answer_to_the_ultima') + response.should redirect_to show_new_request_url(:url_title => 'what_is_the_answer_to_the_ultima') post :new, :info_request => { :public_body_id => @body.id, :title => "Why did the chicken cross the road?", :tag_string => "" }, :outgoing_message => { :body => "Please send me all the relevant documents you hold." }, :submitted_new_request => 1, :preview => 0 - response.should redirect_to(:action => 'show', :url_title => 'why_did_the_chicken_cross_the_ro') + response.should redirect_to show_new_request_url(:url_title => 'why_did_the_chicken_cross_the_ro') post :new, :info_request => { :public_body_id => @body.id, :title => "What's black and white and red all over?", :tag_string => "" }, @@ -1121,20 +1121,20 @@ describe RequestController, "when creating a new request" do :title => "What is the answer to the ultimate question?", :tag_string => "" }, :outgoing_message => { :body => "Please supply the answer from your files." }, :submitted_new_request => 1, :preview => 0 - response.should redirect_to(:action => 'show', :url_title => 'what_is_the_answer_to_the_ultima') + response.should redirect_to show_new_request_url(:url_title => 'what_is_the_answer_to_the_ultima') post :new, :info_request => { :public_body_id => @body.id, :title => "Why did the chicken cross the road?", :tag_string => "" }, :outgoing_message => { :body => "Please send me all the relevant documents you hold." }, :submitted_new_request => 1, :preview => 0 - response.should redirect_to(:action => 'show', :url_title => 'why_did_the_chicken_cross_the_ro') + response.should redirect_to show_new_request_url(:url_title => 'why_did_the_chicken_cross_the_ro') post :new, :info_request => { :public_body_id => @body.id, :title => "What's black and white and red all over?", :tag_string => "" }, :outgoing_message => { :body => "Please send all minutes of meetings and email records that address this question." }, :submitted_new_request => 1, :preview => 0 - response.should redirect_to(:action => 'show', :url_title => 'whats_black_and_white_and_red_al') + response.should redirect_to show_new_request_url(:url_title => 'whats_black_and_white_and_red_al') end end -- cgit v1.2.3 From 0925f8b6ddd30f6edc19741e1ebee348d08f4a61 Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Tue, 29 Jan 2013 17:53:45 +1100 Subject: Clear out ActionMailer::Base.deliveries before each test. Rspec should be doing this but isn't for controller tests --- spec/controllers/request_controller_spec.rb | 33 ----------------------------- 1 file changed, 33 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index b7e3f1f57..e9a08e39e 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -2,8 +2,6 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe RequestController, "when listing recent requests" do - before { ActionMailer::Base.deliveries = [] } - before(:each) do load_raw_emails_data get_fixtures_xapian_index @@ -121,8 +119,6 @@ describe RequestController, "when listing recent requests" do end describe RequestController, "when changing things that appear on the request page" do - before { ActionMailer::Base.deliveries = [] } - render_views it "should purge the downstream cache when mail is received" do @@ -189,7 +185,6 @@ describe RequestController, "when changing things that appear on the request pag end describe RequestController, "when showing one request" do - before { ActionMailer::Base.deliveries = [] } render_views before(:each) do @@ -448,8 +443,6 @@ describe RequestController, "when showing one request" do describe 'when handling incoming mail' do - before { ActionMailer::Base.deliveries = [] } - render_views it "should receive incoming messages, send email to creator, and show them" do @@ -778,8 +771,6 @@ describe RequestController, "when showing one request" do end describe RequestController, "when changing prominence of a request" do - before { ActionMailer::Base.deliveries = [] } - before(:each) do load_raw_emails_data end @@ -912,8 +903,6 @@ end # end describe RequestController, "when searching for an authority" do - before { ActionMailer::Base.deliveries = [] } - # Whether or not sign-in is required for this step is configurable, # so we make sure we're logged in, just in case before do @@ -953,8 +942,6 @@ describe RequestController, "when searching for an authority" do end describe RequestController, "when creating a new request" do - - before { ActionMailer::Base.deliveries = [] } render_views before do @@ -1142,7 +1129,6 @@ end # These go with the previous set, but use mocks instead of fixtures. # TODO harmonise these describe RequestController, "when making a new request" do - before { ActionMailer::Base.deliveries = [] } before do @user = mock_model(User, :id => 3481, :name => 'Testy') @@ -1192,7 +1178,6 @@ describe RequestController, "when making a new request" do end describe RequestController, "when viewing an individual response for reply/followup" do - before { ActionMailer::Base.deliveries = [] } render_views before(:each) do @@ -1255,8 +1240,6 @@ describe RequestController, "when viewing an individual response for reply/follo end describe RequestController, "when classifying an information request" do - - before { ActionMailer::Base.deliveries = [] } describe 'if the request is external' do @@ -1627,7 +1610,6 @@ describe RequestController, "when classifying an information request" do end describe RequestController, "when sending a followup message" do - before { ActionMailer::Base.deliveries = [] } render_views before(:each) do @@ -1714,7 +1696,6 @@ describe RequestController, "sending overdue request alerts" do before(:each) do load_raw_emails_data - ActionMailer::Base.deliveries = [] end it "should send an overdue alert mail to creators of overdue requests" do @@ -1856,7 +1837,6 @@ describe RequestController, "sending overdue request alerts" do end describe RequestController, "sending unclassified new response reminder alerts" do - before { ActionMailer::Base.deliveries = [] } render_views before(:each) do @@ -1887,7 +1867,6 @@ describe RequestController, "sending unclassified new response reminder alerts" end describe RequestController, "clarification required alerts" do - before { ActionMailer::Base.deliveries = [] } render_views before(:each) do load_raw_emails_data @@ -1941,7 +1920,6 @@ describe RequestController, "clarification required alerts" do end describe RequestController, "comment alerts" do - before { ActionMailer::Base.deliveries = [] } render_views before(:each) do load_raw_emails_data @@ -2021,7 +1999,6 @@ describe RequestController, "comment alerts" do end describe RequestController, "when viewing comments" do - before { ActionMailer::Base.deliveries = [] } render_views before(:each) do load_raw_emails_data @@ -2049,7 +2026,6 @@ end describe RequestController, "authority uploads a response from the web interface" do - before { ActionMailer::Base.deliveries = [] } render_views before(:each) do @@ -2140,8 +2116,6 @@ describe RequestController, "authority uploads a response from the web interface end describe RequestController, "when showing JSON version for API" do - before { ActionMailer::Base.deliveries = [] } - before(:each) do load_raw_emails_data end @@ -2160,8 +2134,6 @@ describe RequestController, "when showing JSON version for API" do end describe RequestController, "when doing type ahead searches" do - before { ActionMailer::Base.deliveries = [] } - render_views it "should return nothing for the empty query string" do @@ -2220,7 +2192,6 @@ describe RequestController, "when doing type ahead searches" do end describe RequestController, "when showing similar requests" do - before { ActionMailer::Base.deliveries = [] } render_views it "should work" do @@ -2255,7 +2226,6 @@ end describe RequestController, "when reporting a request when not logged in" do - before { ActionMailer::Base.deliveries = [] } it "should only allow logged-in users to report requests" do get :report_request, :url_title => info_requests(:badger_request).url_title post_redirect = PostRedirect.get_last_post_redirect @@ -2264,7 +2234,6 @@ describe RequestController, "when reporting a request when not logged in" do end describe RequestController, "when reporting a request (logged in)" do - before { ActionMailer::Base.deliveries = [] } render_views before do @@ -2341,8 +2310,6 @@ describe RequestController, "when reporting a request (logged in)" do end describe RequestController, "when caching fragments" do - before { ActionMailer::Base.deliveries = [] } - it "should not fail with long filenames" do long_name = "blahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblah.txt" info_request = mock(InfoRequest, :user_can_view? => true, -- cgit v1.2.3 From 97c4683e47bdbac4d170780cf2b765940fcd0168 Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Tue, 29 Jan 2013 18:49:26 +1100 Subject: Replace use of response.should send_email with checking ActionMailer::Base.deliveries --- spec/controllers/user_controller_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/user_controller_spec.rb b/spec/controllers/user_controller_spec.rb index 81360d78c..519e17441 100644 --- a/spec/controllers/user_controller_spec.rb +++ b/spec/controllers/user_controller_spec.rb @@ -111,7 +111,7 @@ describe UserController, "when signing in" do session[:user_id].should == users(:bob_smith_user).id # response doesn't contain /en/ but redirect_to does... response.should redirect_to(:controller => 'request', :action => 'list', :post_redirect => 1) - response.should_not send_email + ActionMailer::Base.deliveries.should be_empty RoutingFilter.active = true end @@ -150,7 +150,7 @@ describe UserController, "when signing in" do :token => post_redirect.token } response.should render_template('confirm') - response.should send_email + ActionMailer::Base.deliveries.should_not be_empty end it "should confirm your email, log you in and redirect you to where you were after you click an email link" do @@ -162,7 +162,7 @@ describe UserController, "when signing in" do post :signin, { :user_signin => { :email => 'unconfirmed@localhost', :password => 'jonespassword' }, :token => post_redirect.token } - response.should send_email + ActionMailer::Base.deliveries.should_not be_empty deliveries = ActionMailer::Base.deliveries deliveries.size.should == 1 @@ -194,7 +194,7 @@ describe UserController, "when signing in" do post :signin, { :user_signin => { :email => 'unconfirmed@localhost', :password => 'jonespassword' }, :token => post_redirect.token } - response.should send_email + ActionMailer::Base.deliveries.should_not be_empty deliveries = ActionMailer::Base.deliveries deliveries.size.should == 1 -- cgit v1.2.3 From b02d852a1458a39e1d83b6b58d74b93320764892 Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Tue, 29 Jan 2013 18:50:23 +1100 Subject: When matching mail.body with regex cast to string first --- spec/controllers/user_controller_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/user_controller_spec.rb b/spec/controllers/user_controller_spec.rb index 519e17441..2692cada4 100644 --- a/spec/controllers/user_controller_spec.rb +++ b/spec/controllers/user_controller_spec.rb @@ -167,7 +167,7 @@ describe UserController, "when signing in" do deliveries = ActionMailer::Base.deliveries deliveries.size.should == 1 mail = deliveries[0] - mail.body =~ /(http:\/\/.*(\/c\/(.*)))/ + mail.body.to_s =~ /(http:\/\/.*(\/c\/(.*)))/ mail_url = $1 mail_path = $2 mail_token = $3 @@ -199,7 +199,7 @@ describe UserController, "when signing in" do deliveries = ActionMailer::Base.deliveries deliveries.size.should == 1 mail = deliveries[0] - mail.body =~ /(http:\/\/.*(\/c\/(.*)))/ + mail.body.to_s =~ /(http:\/\/.*(\/c\/(.*)))/ mail_url = $1 mail_path = $2 mail_token = $3 @@ -498,7 +498,7 @@ describe UserController, "when changing email address" do mail.body.should include("confirm that you want to change") mail.to.should == [ 'newbob@localhost' ] - mail.body =~ /(http:\/\/.*(\/c\/(.*)))/ + mail.body.to_s =~ /(http:\/\/.*(\/c\/(.*)))/ mail_url = $1 mail_path = $2 mail_token = $3 -- cgit v1.2.3 From 49045c68f845c60110c5795c5b793653abcf3489 Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Tue, 29 Jan 2013 18:51:11 +1100 Subject: params_from doesn't exist anymore --- spec/controllers/user_controller_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/user_controller_spec.rb b/spec/controllers/user_controller_spec.rb index 2692cada4..9a446e704 100644 --- a/spec/controllers/user_controller_spec.rb +++ b/spec/controllers/user_controller_spec.rb @@ -174,7 +174,7 @@ describe UserController, "when signing in" do # check is right confirmation URL mail_token.should == post_redirect.email_token - params_from(:get, mail_path).should == { :controller => 'user', :action => 'confirm', :email_token => mail_token } + Rails.application.routes.recognize_path(mail_path).should == { :controller => 'user', :action => 'confirm', :email_token => mail_token } # check confirmation URL works session[:user_id].should be_nil @@ -206,7 +206,7 @@ describe UserController, "when signing in" do # check is right confirmation URL mail_token.should == post_redirect.email_token - params_from(:get, mail_path).should == { :controller => 'user', :action => 'confirm', :email_token => mail_token } + Rails.application.routes.recognize_path(mail_path).should == { :controller => 'user', :action => 'confirm', :email_token => mail_token } # Log in as an admin session[:user_id] = users(:admin_user).id -- cgit v1.2.3 From 20c20a5e403f04dd4aa221a323e8b9ed3967dc52 Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Tue, 29 Jan 2013 18:52:01 +1100 Subject: errors returns an array now --- spec/controllers/user_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/controllers') diff --git a/spec/controllers/user_controller_spec.rb b/spec/controllers/user_controller_spec.rb index 9a446e704..4033bf0b6 100644 --- a/spec/controllers/user_controller_spec.rb +++ b/spec/controllers/user_controller_spec.rb @@ -230,7 +230,7 @@ describe UserController, "when signing up" do post :signup, { :user_signup => { :email => 'new@localhost', :name => 'New Person', :password => 'sillypassword', :password_confirmation => 'sillypasswordtwo' } } - assigns[:user_signup].errors[:password].should == 'Please enter the same password twice' + assigns[:user_signup].errors[:password].should == ['Please enter the same password twice'] end it "should be an error to sign up with a misformatted email" do -- cgit v1.2.3 From 154cae159b90b3b2a8d60cd71d383f4fa1831878 Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Tue, 29 Jan 2013 18:52:32 +1100 Subject: mail from_addrs now doesn't return the name --- spec/controllers/user_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/controllers') diff --git a/spec/controllers/user_controller_spec.rb b/spec/controllers/user_controller_spec.rb index 4033bf0b6..a4a97acc7 100644 --- a/spec/controllers/user_controller_spec.rb +++ b/spec/controllers/user_controller_spec.rb @@ -335,7 +335,7 @@ describe UserController, "when sending another user a message" do mail.body.should include("Bob Smith has used #{Configuration::site_name} to send you the message below") mail.body.should include("Just a test!") #mail.to_addrs.first.to_s.should == users(:silly_name_user).name_and_email # XXX fix some nastiness with quoting name_and_email - mail.from_addrs.first.to_s.should == users(:bob_smith_user).name_and_email + mail.from_addrs.first.to_s.should == users(:bob_smith_user).email end end -- cgit v1.2.3 From 4e4ec14ebcc9ddd161bc61a5bbce9ce0cd4e3610 Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Wed, 30 Jan 2013 08:16:28 +1100 Subject: Find is now being called with an integer rather than a string. All good --- spec/controllers/admin_request_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/controllers') diff --git a/spec/controllers/admin_request_controller_spec.rb b/spec/controllers/admin_request_controller_spec.rb index d16235717..c9d325b03 100644 --- a/spec/controllers/admin_request_controller_spec.rb +++ b/spec/controllers/admin_request_controller_spec.rb @@ -226,7 +226,7 @@ describe AdminRequestController, "when administering the holding pen" do :user => nil, :user_name => 'External User', :is_external? => true) - InfoRequest.stub!(:find).with(@info_request.id.to_s).and_return(@info_request) + InfoRequest.stub!(:find).with(@info_request.id).and_return(@info_request) @default_params = { :id => @info_request.id, :explanation => 'Foo', :reason => 'vexatious' } -- cgit v1.2.3 From 581475dddb48e000dc5143937677dd8b412569b5 Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Wed, 30 Jan 2013 08:41:44 +1100 Subject: Updated test to correctly test what it was testing --- spec/controllers/admin_general_controller_spec.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/admin_general_controller_spec.rb b/spec/controllers/admin_general_controller_spec.rb index b0b65857f..971960762 100644 --- a/spec/controllers/admin_general_controller_spec.rb +++ b/spec/controllers/admin_general_controller_spec.rb @@ -14,8 +14,7 @@ describe AdminGeneralController do it "should redirect to include trailing slash" do get :index - response.should redirect_to(:controller => 'admin_general', - :action => 'index') + response.should redirect_to admin_general_index_url(:trailing_slash => true) end end -- cgit v1.2.3 From 9fb05a3eea9836de793831cbf3ebfbf1363e0417 Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Thu, 31 Jan 2013 11:21:49 +1100 Subject: Test result of test with examples rather than another implementation --- spec/controllers/public_body_controller_spec.rb | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb index 445128db7..38e874469 100644 --- a/spec/controllers/public_body_controller_spec.rb +++ b/spec/controllers/public_body_controller_spec.rb @@ -102,9 +102,11 @@ describe PublicBodyController, "when listing bodies" do response.should render_template('list') - assigns[:public_bodies].should == PublicBody.all( - :conditions => "id <> #{PublicBody.internal_admin_body.id}", - :order => "(select name from public_body_translations where public_body_id=public_bodies.id and locale='en')") + assigns[:public_bodies].should == [ public_bodies(:humpadink_public_body), + public_bodies(:forlorn_public_body), + public_bodies(:geraldine_public_body), + public_bodies(:sensible_walks_public_body), + public_bodies(:silly_walks_public_body) ] assigns[:tag].should == "all" assigns[:description].should == "" end @@ -142,11 +144,18 @@ describe PublicBodyController, "when listing bodies" do get :list, :tag => "other" response.should render_template('list') - assigns[:public_bodies].should =~ PublicBody.all(:conditions => "id not in (#{public_bodies(:humpadink_public_body).id}, #{PublicBody.internal_admin_body.id})") + assigns[:public_bodies].should == [ public_bodies(:forlorn_public_body), + public_bodies(:geraldine_public_body), + public_bodies(:sensible_walks_public_body), + public_bodies(:silly_walks_public_body) ] get :list response.should render_template('list') - assigns[:public_bodies].should =~ PublicBody.all(:conditions => "id <> #{PublicBody.internal_admin_body.id}") + assigns[:public_bodies].should == [ public_bodies(:humpadink_public_body), + public_bodies(:forlorn_public_body), + public_bodies(:geraldine_public_body), + public_bodies(:sensible_walks_public_body), + public_bodies(:silly_walks_public_body) ] end it "should list a machine tagged thing, should get it in both ways" do -- cgit v1.2.3 From 5acd5cced50f72d0e88a4524f5aef23525511554 Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Thu, 31 Jan 2013 12:52:34 +1100 Subject: Cast mail.body to string before matching with a regex --- spec/controllers/track_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/controllers') diff --git a/spec/controllers/track_controller_spec.rb b/spec/controllers/track_controller_spec.rb index 009ef2f4a..63192c99e 100644 --- a/spec/controllers/track_controller_spec.rb +++ b/spec/controllers/track_controller_spec.rb @@ -80,7 +80,7 @@ describe TrackController, "when sending alerts for a track" do mail = deliveries[0] mail.body.should =~ /Alter your subscription/ mail.to_addrs.first.to_s.should include(users(:silly_name_user).email) - mail.body =~ /(http:\/\/.*\/c\/(.*))/ + mail.body.to_s =~ /(http:\/\/.*\/c\/(.*))/ mail_url = $1 mail_token = $2 -- cgit v1.2.3 From 2c00d9b1a4bf42bba92def1ee8e0f750db9b4905 Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Fri, 1 Feb 2013 14:52:34 +1100 Subject: Handling of globbed parameters in routes has changed --- spec/controllers/general_controller_spec.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/general_controller_spec.rb b/spec/controllers/general_controller_spec.rb index c7d9b5ce3..d4aa034a7 100644 --- a/spec/controllers/general_controller_spec.rb +++ b/spec/controllers/general_controller_spec.rb @@ -249,7 +249,7 @@ describe GeneralController, 'when using xapian search' do end it "should find info request when searching for '\"fancy dog\"'" do - get :search, :combined => ['"fancy dog"'] + get :search, :combined => '"fancy dog"' response.should render_template('search') assigns[:xapian_requests].matches_estimated.should == 1 assigns[:xapian_requests].results.size.should == 1 @@ -259,7 +259,7 @@ describe GeneralController, 'when using xapian search' do end it "should find public body and incoming message when searching for 'geraldine quango'" do - get :search, :combined => ['geraldine quango'] + get :search, :combined => 'geraldine quango' response.should render_template('search') assigns[:xapian_requests].matches_estimated.should == 1 @@ -272,7 +272,7 @@ describe GeneralController, 'when using xapian search' do end it "should filter results based on end of URL being 'all'" do - get :search, :combined => ['"bob"', "all"] + get :search, :combined => "bob/all" assigns[:xapian_requests].results.map{|x| x[:model]}.should =~ [ info_request_events(:useless_outgoing_message_event), info_request_events(:silly_outgoing_message_event), @@ -284,14 +284,14 @@ describe GeneralController, 'when using xapian search' do end it "should filter results based on end of URL being 'users'" do - get :search, :combined => ['"bob"', "users"] + get :search, :combined => "bob/users" assigns[:xapian_requests].should == nil assigns[:xapian_users].results.map{|x| x[:model]}.should == [users(:bob_smith_user)] assigns[:xapian_bodies].should == nil end it "should filter results based on end of URL being 'requests'" do - get :search, :combined => ['"bob"', "requests"] + get :search, :combined => "bob/requests" assigns[:xapian_requests].results.map{|x|x[:model]}.should =~ [ info_request_events(:useless_outgoing_message_event), info_request_events(:silly_outgoing_message_event), @@ -303,7 +303,7 @@ describe GeneralController, 'when using xapian search' do end it "should filter results based on end of URL being 'bodies'" do - get :search, :combined => ['"quango"', "bodies"] + get :search, :combined => "quango/bodies" assigns[:xapian_requests].should == nil assigns[:xapian_users].should == nil assigns[:xapian_bodies].results.map{|x|x[:model]}.should == [public_bodies(:geraldine_public_body)] @@ -317,7 +317,7 @@ describe GeneralController, 'when using xapian search' do end it "should not show unconfirmed users" do - get :search, :combined => ["unconfirmed", "users"] + get :search, :combined => "unconfirmed/users" response.should render_template('search') assigns[:xapian_users].results.map{|x|x[:model]}.should == [] end @@ -328,13 +328,13 @@ describe GeneralController, 'when using xapian search' do u.save! update_xapian_index - get :search, :combined => ["unconfirmed", "users"] + get :search, :combined => "unconfirmed/users" response.should render_template('search') assigns[:xapian_users].results.map{|x|x[:model]}.should == [u] end it "should show tracking links for requests-only searches" do - get :search, :combined => ['"bob"', "requests"] + get :search, :combined => "bob/requests" response.body.should include('Track this search') end -- cgit v1.2.3 From cf0b371f6bc8454fbdd331e2a6fd19c6b67b540b Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Thu, 7 Feb 2013 18:39:50 +1100 Subject: This parameter is typecast in Rails 3 --- spec/controllers/user_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/controllers') diff --git a/spec/controllers/user_controller_spec.rb b/spec/controllers/user_controller_spec.rb index a4a97acc7..cfff5c901 100644 --- a/spec/controllers/user_controller_spec.rb +++ b/spec/controllers/user_controller_spec.rb @@ -516,7 +516,7 @@ describe UserController, "when changing email address" do post_redirect = PostRedirect.find_by_email_token(mail_token) post_redirect.circumstance.should == 'change_email' post_redirect.user.should == users(:bob_smith_user) - post_redirect.post_params.should == {"submitted_signchangeemail_do"=>"1", + post_redirect.post_params.should == {"submitted_signchangeemail_do"=>1, "action"=>"signchangeemail", "signchangeemail"=>{ "old_email"=>"bob@localhost", -- cgit v1.2.3 From 8f1caab7990dc417e32b14cbb5f00c34a0ddc10c Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Thu, 14 Feb 2013 19:02:03 +1100 Subject: Spec is deprecated in favour of RSpec --- spec/controllers/api_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/controllers') diff --git a/spec/controllers/api_controller_spec.rb b/spec/controllers/api_controller_spec.rb index 2de1c5071..749be9f85 100644 --- a/spec/controllers/api_controller_spec.rb +++ b/spec/controllers/api_controller_spec.rb @@ -7,7 +7,7 @@ def normalise_whitespace(s) return s end -Spec::Matchers.define :be_equal_modulo_whitespace_to do |expected| +RSpec::Matchers.define :be_equal_modulo_whitespace_to do |expected| match do |actual| normalise_whitespace(actual) == normalise_whitespace(expected) end -- cgit v1.2.3 From 2a98c2587c3e933e705154768c0f46a34777a56f Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Wed, 20 Feb 2013 16:01:01 +1100 Subject: Mark this test as pending until it's fixed. See #819 --- spec/controllers/request_controller_spec.rb | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index e9a08e39e..195d1e214 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -571,12 +571,15 @@ describe RequestController, "when showing one request" do end it "should generate valid HTML verson of PDF attachments" do - ir = info_requests(:fancy_dog_request) - receive_incoming_mail('incoming-request-pdf-attachment.email', ir.incoming_email) - ir.reload - get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => ['fs_50379341.pdf.html'], :skip_cache => 1 - response.content_type.should == "text/html" - response.should contain "Walberswick Parish Council" + pending "Disabled during Rails 3 upgrade: https://github.com/mysociety/alaveteli/issues/819" + + # TODO: Fix HTML validation and enable test + # ir = info_requests(:fancy_dog_request) + # receive_incoming_mail('incoming-request-pdf-attachment.email', ir.incoming_email) + # ir.reload + # get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => ['fs_50379341.pdf.html'], :skip_cache => 1 + # response.content_type.should == "text/html" + # response.should contain "Walberswick Parish Council" end it "should not cause a reparsing of the raw email, even when the result would be a 404" do -- cgit v1.2.3 From 75afaee10ab4ce41dd4e2dc0054a8fb1a2392f12 Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Thu, 21 Feb 2013 17:42:17 +1100 Subject: Correct syntax and reload for Ruby 1.9.3 --- spec/controllers/user_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/controllers') diff --git a/spec/controllers/user_controller_spec.rb b/spec/controllers/user_controller_spec.rb index cfff5c901..0825d12bf 100644 --- a/spec/controllers/user_controller_spec.rb +++ b/spec/controllers/user_controller_spec.rb @@ -381,7 +381,7 @@ describe UserController, "when changing password" do post :signchangepassword, { :user => { :password => 'ooo', :password_confirmation => 'ooo' }, :submitted_signchangepassword_do => 1 } - users(:bob_smith_user).hashed_password.should != old_hash + users(:bob_smith_user).reload.hashed_password.should_not == old_hash response.should redirect_to(:controller => 'user', :action => 'show', :url_name => users(:bob_smith_user).url_name) end -- cgit v1.2.3 From fb4be794911d6f01ee46bb31753d47c414d682a1 Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Mon, 25 Feb 2013 15:15:03 +1100 Subject: response.flash has been deprecated --- spec/controllers/admin_public_body_controller_spec.rb | 6 +++--- spec/controllers/admin_request_controller_spec.rb | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/admin_public_body_controller_spec.rb b/spec/controllers/admin_public_body_controller_spec.rb index 3fcc9b36d..c7cf48017 100644 --- a/spec/controllers/admin_public_body_controller_spec.rb +++ b/spec/controllers/admin_public_body_controller_spec.rb @@ -29,7 +29,7 @@ describe AdminPublicBodyController, "when administering public bodies" do it "saves edits to a public body" do public_bodies(:humpadink_public_body).name.should == "Department for Humpadinking" post :update, { :id => 3, :public_body => { :name => "Renamed", :short_name => "", :tag_string => "some tags", :request_email => 'edited@localhost', :last_edit_comment => 'From test code' } } - response.flash[:notice].should include('successful') + request.flash[:notice].should include('successful') pb = PublicBody.find(public_bodies(:humpadink_public_body).id) pb.name.should == "Renamed" end @@ -57,7 +57,7 @@ describe AdminPublicBodyController, "when administering public bodies" do it "mass assigns tags" do n = PublicBody.count post :mass_tag_add, { :new_tag => "department", :table_name => "substring" } - response.flash[:notice].should == "Added tag to table of bodies." + request.flash[:notice].should == "Added tag to table of bodies." response.should redirect_to(:action=>'list') PublicBody.find_by_tag("department").count.should == n end @@ -295,7 +295,7 @@ describe AdminPublicBodyController, "when administering public bodies with i18n" } } } - response.flash[:notice].should include('successful') + request.flash[:notice].should include('successful') end pb = PublicBody.find(public_bodies(:humpadink_public_body).id) diff --git a/spec/controllers/admin_request_controller_spec.rb b/spec/controllers/admin_request_controller_spec.rb index c9d325b03..f644e0146 100644 --- a/spec/controllers/admin_request_controller_spec.rb +++ b/spec/controllers/admin_request_controller_spec.rb @@ -34,7 +34,7 @@ describe AdminRequestController, "when administering requests" do :awaiting_description => false, :allow_new_responses_from => 'anybody', :handle_rejected_responses => 'bounce' } } - response.flash[:notice].should include('successful') + request.flash[:notice].should include('successful') ir = InfoRequest.find(info_requests(:fancy_dog_request).id) ir.title.should == "Renamed" end @@ -59,7 +59,7 @@ describe AdminRequestController, "when administering requests" do it "saves edits to an outgoing_message" do outgoing_messages(:useless_outgoing_message).body.should include("fancy dog") post :update_outgoing, { :id => outgoing_messages(:useless_outgoing_message), :outgoing_message => { :body => "Why do you have such a delicious cat?" } } - response.flash[:notice].should include('successful') + request.flash[:notice].should include('successful') ir = OutgoingMessage.find(outgoing_messages(:useless_outgoing_message).id) ir.body.should include("delicious cat") end @@ -256,7 +256,7 @@ describe AdminRequestController, "when administering the holding pen" do it 'should add a notice to the flash saying that the request has been hidden' do make_request - response.flash[:notice].should == "This external request has been hidden" + request.flash[:notice].should == "This external request has been hidden" end it 'should expire the file cache for the request' do -- cgit v1.2.3 From 532a21ba4941197a13524ac3f1ce9267a46bec1d Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Mon, 25 Feb 2013 17:25:59 +1100 Subject: Update to new mail sending API --- spec/controllers/admin_request_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/controllers') diff --git a/spec/controllers/admin_request_controller_spec.rb b/spec/controllers/admin_request_controller_spec.rb index f644e0146..b51aaa9ad 100644 --- a/spec/controllers/admin_request_controller_spec.rb +++ b/spec/controllers/admin_request_controller_spec.rb @@ -250,7 +250,7 @@ describe AdminRequestController, "when administering the holding pen" do end it 'should not send a notification email' do - ContactMailer.should_not_receive(:deliver_from_admin_message) + ContactMailer.should_not_receive(:from_admin_message) make_request end -- cgit v1.2.3 From 3e4ef4da5374c1dd6d32ac9351decc9bb6851355 Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Mon, 25 Feb 2013 18:16:12 +1100 Subject: Update to new mail sending API --- spec/controllers/request_controller_spec.rb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 195d1e214..b5612e1f9 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -1297,7 +1297,9 @@ describe RequestController, "when classifying an information request" do before do @dog_request.stub!(:is_old_unclassified?).and_return(true) - RequestMailer.stub!(:deliver_old_unclassified_updated) + mail_mock = mock("mail") + mail_mock.stub(:deliver) + RequestMailer.stub!(:old_unclassified_updated).and_return(mail_mock) end describe 'when the user is not logged in' do @@ -1334,7 +1336,7 @@ describe RequestController, "when classifying an information request" do end it 'should send an email to the requester letting them know someone has updated the status of their request' do - RequestMailer.should_receive(:deliver_old_unclassified_updated) + RequestMailer.should_receive(:old_unclassified_updated) post_status('rejected') end @@ -1385,7 +1387,9 @@ describe RequestController, "when classifying an information request" do end it 'should send an email to the requester letting them know someone has updated the status of their request' do - RequestMailer.should_receive(:deliver_old_unclassified_updated) + mail_mock = mock("mail") + mail_mock.stub :deliver + RequestMailer.should_receive(:old_unclassified_updated).and_return(mail_mock) post_status('rejected') end @@ -1424,7 +1428,7 @@ describe RequestController, "when classifying an information request" do end it 'should not send an email to the requester letting them know someone has updated the status of their request' do - RequestMailer.should_not_receive(:deliver_old_unclassified_updated) + RequestMailer.should_not_receive(:old_unclassified_updated) post_status('rejected') end @@ -1465,7 +1469,7 @@ describe RequestController, "when classifying an information request" do end it 'should not send an email to the requester letting them know someone has updated the status of their request' do - RequestMailer.should_not_receive(:deliver_old_unclassified_updated) + RequestMailer.should_not_receive(:old_unclassified_updated) post_status('rejected') end -- cgit v1.2.3 From 90edee32bf6ad91522b3e1e772bca1e778a5ba7a Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Tue, 26 Feb 2013 13:39:43 +1100 Subject: file_name is passed as a string not an array --- spec/controllers/request_controller_spec.rb | 43 ++++++++++++++--------------- 1 file changed, 21 insertions(+), 22 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index b5612e1f9..663588303 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -477,11 +477,11 @@ describe RequestController, "when showing one request" do (assigns[:info_request_events].size - size_before).should == 1 ir.reload - get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => ['hello.txt'], :skip_cache => 1 + get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => 'hello.txt', :skip_cache => 1 response.content_type.should == "text/plain" response.should contain "Second hello" - get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 3, :file_name => ['hello.txt'], :skip_cache => 1 + get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 3, :file_name => 'hello.txt', :skip_cache => 1 response.content_type.should == "text/plain" response.should contain "First hello" end @@ -494,8 +494,7 @@ describe RequestController, "when showing one request" do get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, - :file_name => ['hello.txt'] - + :file_name => 'hello.txt' end it "should convert message body to UTF8" do @@ -509,7 +508,7 @@ describe RequestController, "when showing one request" do ir = info_requests(:fancy_dog_request) receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email) ir.reload - get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => ['hello.txt.html'], :skip_cache => 1 + get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => 'hello.txt.html', :skip_cache => 1 response.content_type.should == "text/html" response.should contain "Second hello" end @@ -530,11 +529,11 @@ describe RequestController, "when showing one request" do ir.reload ugly_id = "55195" lambda { - get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ugly_id, :part => 2, :file_name => ['hello.txt.html'], :skip_cache => 1 + get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ugly_id, :part => 2, :file_name => 'hello.txt.html', :skip_cache => 1 }.should raise_error(ActiveRecord::RecordNotFound) lambda { - get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ugly_id, :part => 2, :file_name => ['hello.txt'], :skip_cache => 1 + get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ugly_id, :part => 2, :file_name => 'hello.txt', :skip_cache => 1 }.should raise_error(ActiveRecord::RecordNotFound) end it "should return 404 when incoming message and request ids don't match" do @@ -543,7 +542,7 @@ describe RequestController, "when showing one request" do receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email) ir.reload lambda { - get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => wrong_id, :part => 2, :file_name => ['hello.txt.html'], :skip_cache => 1 + get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => wrong_id, :part => 2, :file_name => 'hello.txt.html', :skip_cache => 1 }.should raise_error(ActiveRecord::RecordNotFound) end it "should return 404 for ugly URLs contain a request id that isn't an integer, even if the integer prefix refers to an actual request" do @@ -553,11 +552,11 @@ describe RequestController, "when showing one request" do ugly_id = "%d95" % [info_requests(:naughty_chicken_request).id] lambda { - get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ugly_id, :part => 2, :file_name => ['hello.txt.html'], :skip_cache => 1 + get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ugly_id, :part => 2, :file_name => 'hello.txt.html', :skip_cache => 1 }.should raise_error(ActiveRecord::RecordNotFound) lambda { - get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ugly_id, :part => 2, :file_name => ['hello.txt'], :skip_cache => 1 + get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ugly_id, :part => 2, :file_name => 'hello.txt', :skip_cache => 1 }.should raise_error(ActiveRecord::RecordNotFound) end it "should return 404 when incoming message and request ids don't match" do @@ -566,7 +565,7 @@ describe RequestController, "when showing one request" do receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email) ir.reload lambda { - get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => wrong_id, :part => 2, :file_name => ['hello.txt.html'], :skip_cache => 1 + get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => wrong_id, :part => 2, :file_name => 'hello.txt.html', :skip_cache => 1 }.should raise_error(ActiveRecord::RecordNotFound) end @@ -577,7 +576,7 @@ describe RequestController, "when showing one request" do # ir = info_requests(:fancy_dog_request) # receive_incoming_mail('incoming-request-pdf-attachment.email', ir.incoming_email) # ir.reload - # get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => ['fs_50379341.pdf.html'], :skip_cache => 1 + # get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => 'fs_50379341.pdf.html', :skip_cache => 1 # response.content_type.should == "text/html" # response.should contain "Walberswick Parish Council" end @@ -595,14 +594,14 @@ describe RequestController, "when showing one request" do # in a 404 for browsing users. This shouldn't cause a # re-parse... lambda { - get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => ['hello.txt.baz.html'], :skip_cache => 1 + get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => 'hello.txt.baz.html', :skip_cache => 1 }.should raise_error(ActiveRecord::RecordNotFound) attachment = IncomingMessage.get_attachment_by_url_part_number(ir.incoming_messages[1].get_attachments_for_display, 2) attachment.body.should contain "Second hello" # ...nor should asking for it by its correct filename... - get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => ['hello.txt.html'], :skip_cache => 1 + get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => 'hello.txt.html', :skip_cache => 1 response.should_not contain "Third hello" # ...but if we explicitly ask for attachments to be extracted, then they should be @@ -610,7 +609,7 @@ describe RequestController, "when showing one request" do ir.incoming_messages[1].parse_raw_email!(force) attachment = IncomingMessage.get_attachment_by_url_part_number(ir.incoming_messages[1].get_attachments_for_display, 2) attachment.body.should contain "Second hello" - get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => ['hello.txt.html'], :skip_cache => 1 + get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => 'hello.txt.html', :skip_cache => 1 response.should contain "Third hello" end @@ -619,7 +618,7 @@ describe RequestController, "when showing one request" do receive_incoming_mail('incoming-request-attachment-unknown-extension.email', ir.incoming_email) ir.reload - get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => ['hello.qwglhm'], :skip_cache => 1 + get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => 'hello.qwglhm', :skip_cache => 1 response.content_type.should == "application/octet-stream" response.should contain "an unusual sort of file" end @@ -630,7 +629,7 @@ describe RequestController, "when showing one request" do lambda { get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, - :file_name => ['http://trying.to.hack'] + :file_name => 'http://trying.to.hack' }.should raise_error(ActiveRecord::RecordNotFound) end @@ -647,7 +646,7 @@ describe RequestController, "when showing one request" do begin receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email) - get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => ['hello.txt'], :skip_cache => 1 + get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => 'hello.txt', :skip_cache => 1 response.content_type.should == "text/plain" response.should contain "xxxxxx hello" ensure @@ -669,7 +668,7 @@ describe RequestController, "when showing one request" do receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email) ir.reload - get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => ['hello.txt'], :skip_cache => 1 + get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => 'hello.txt', :skip_cache => 1 response.content_type.should == "text/plain" response.should contain "xxxxxx hello" ensure @@ -878,7 +877,7 @@ describe RequestController, "when changing prominence of a request" do get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, - :file_name => ['hello.txt'] + :file_name => 'hello.txt' end.should raise_error(ActiveRecord::RecordNotFound) end @@ -893,7 +892,7 @@ describe RequestController, "when changing prominence of a request" do get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, - :file_name => ['hello.txt'] + :file_name => 'hello.txt' end.should raise_error(ActiveRecord::RecordNotFound) end @@ -2332,7 +2331,7 @@ describe RequestController, "when caching fragments" do IncomingMessage.stub!(:find).with("44").and_return(incoming_message) IncomingMessage.stub!(:get_attachment_by_url_part_number).and_return(attachment) InfoRequest.stub!(:find).with("132").and_return(info_request) - params = { :file_name => [long_name], + params = { :file_name => long_name, :controller => "request", :action => "get_attachment_as_html", :id => "132", -- cgit v1.2.3 From 835b51c1de0d49e652fe9c9a60f0974275de070c Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Wed, 27 Feb 2013 10:34:47 +1100 Subject: Rename ALL THE TEMPLATES!!1!!!one!!1!! .rhtml is deprecated in favour of .erb in Rails 3 --- spec/controllers/request_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/controllers') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 663588303..ffc15ebe8 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -692,7 +692,7 @@ describe RequestController, "when showing one request" do get :show, :url_title => 'why_do_you_have_such_a_fancy_dog' assert assigns[:info_request].info_request_events[3].incoming_message.get_attachments_for_display.count == 2 # the issue is that the info_request_events have got cached on them the old info_requests. - # where i'm at: trying to replace those fields that got re-read from the raw email. however tests are failing in very strange ways. currently I don't appear to be getting any attachments parsed in at all when in the template (see "*****" in _correspondence.rhtml) but do when I'm in the code. + # where i'm at: trying to replace those fields that got re-read from the raw email. however tests are failing in very strange ways. currently I don't appear to be getting any attachments parsed in at all when in the template (see "*****" in _correspondence.html.erb) but do when I'm in the code. # so at this point, assigns[:info_request].incoming_messages[1].get_attachments_for_display is returning stuff, but the equivalent thing in the template isn't. # but something odd is that the above is return a whole load of attachments which aren't there in the controller -- cgit v1.2.3 From 1e463f086ae0e5250392ac553368fccc7b12bd98 Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Sun, 3 Mar 2013 13:45:44 +1100 Subject: response.redirected_to is deprecated --- spec/controllers/request_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/controllers') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index ffc15ebe8..1f6b0a516 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -1036,7 +1036,7 @@ describe RequestController, "when creating a new request" do response.should redirect_to show_new_request_url(: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$/ + response.redirect_url.should =~ /request\/why_is_your_quango_called_gerald\/new$/ end it "should give an error if the same request is submitted twice" do -- cgit v1.2.3 From cbdff06aa95a7987b54c712dc6729e138f608eca Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Sun, 3 Mar 2013 14:52:30 +1100 Subject: Rename Configuration class to avoid conflict with ActiveSupport::Configurable --- spec/controllers/general_controller_spec.rb | 8 ++++---- spec/controllers/services_controller_spec.rb | 8 ++++---- spec/controllers/user_controller_spec.rb | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/general_controller_spec.rb b/spec/controllers/general_controller_spec.rb index d4aa034a7..9a88dbc3a 100644 --- a/spec/controllers/general_controller_spec.rb +++ b/spec/controllers/general_controller_spec.rb @@ -20,13 +20,13 @@ end describe GeneralController, 'when getting the blog feed' do it 'should add a lang param correctly to a url with no querystring' do - Configuration.stub!(:blog_feed).and_return("http://blog.example.com") + AlaveteliConfiguration.stub!(:blog_feed).and_return("http://blog.example.com") get :blog assigns[:feed_url].should == "http://blog.example.com?lang=en" end it 'should add a lang param correctly to a url with an existing querystring' do - Configuration.stub!(:blog_feed).and_return("http://blog.example.com?alt=rss") + AlaveteliConfiguration.stub!(:blog_feed).and_return("http://blog.example.com?alt=rss") get :blog assigns[:feed_url].should == "http://blog.example.com?alt=rss&lang=en" end @@ -104,11 +104,11 @@ describe GeneralController, "when showing the frontpage" do before do @default_lang_home_link = /href=".*\/en\// @other_lang_home_link = /href=".*\/es\// - @old_include_default_locale_in_urls = Configuration::include_default_locale_in_urls + @old_include_default_locale_in_urls = AlaveteliConfiguration::include_default_locale_in_urls end def set_default_locale_in_urls(value) - Configuration.stub!(:include_default_locale_in_urls).and_return(value) + AlaveteliConfiguration.stub!(:include_default_locale_in_urls).and_return(value) load Rails.root.join("config/initializers/fast_gettext.rb") end diff --git a/spec/controllers/services_controller_spec.rb b/spec/controllers/services_controller_spec.rb index 796c6b63d..399f48acb 100644 --- a/spec/controllers/services_controller_spec.rb +++ b/spec/controllers/services_controller_spec.rb @@ -54,27 +54,27 @@ describe ServicesController, "when returning a message for people in other count it "should return the 'another country' message if the service responds OK" do config = MySociety::Config.load_default() config['ISO_COUNTRY_CODE'] = "DE" - Configuration.stub!(:gaze_url).and_return('http://denmark.com') + AlaveteliConfiguration.stub!(:gaze_url).and_return('http://denmark.com') FakeWeb.register_uri(:get, %r|denmark.com|, :body => "DK") get :other_country_message response.should be_success response.body.should == 'Hello! We have an important message for visitors outside Deutschland X' end it "should default to no message if the country_from_ip domain doesn't exist" do - Configuration.stub!(:gaze_url).and_return('http://12123sdf14qsd.com') + AlaveteliConfiguration.stub!(:gaze_url).and_return('http://12123sdf14qsd.com') get :other_country_message response.should be_success response.body.should == '' end it "should default to no message if the country_from_ip service doesn't exist" do - Configuration.stub!(:gaze_url).and_return('http://www.google.com') + AlaveteliConfiguration.stub!(:gaze_url).and_return('http://www.google.com') get :other_country_message response.should be_success response.body.should == '' end it "should default to no message if the country_from_ip service returns an error" do FakeWeb.register_uri(:get, %r|500.com|, :body => "Error", :status => ["500", "Error"]) - Configuration.stub!(:gaze_url).and_return('http://500.com') + AlaveteliConfiguration.stub!(:gaze_url).and_return('http://500.com') get :other_country_message response.should be_success response.body.should == '' diff --git a/spec/controllers/user_controller_spec.rb b/spec/controllers/user_controller_spec.rb index 0825d12bf..6cd1c099f 100644 --- a/spec/controllers/user_controller_spec.rb +++ b/spec/controllers/user_controller_spec.rb @@ -332,7 +332,7 @@ describe UserController, "when sending another user a message" do deliveries = ActionMailer::Base.deliveries deliveries.size.should == 1 mail = deliveries[0] - mail.body.should include("Bob Smith has used #{Configuration::site_name} to send you the message below") + mail.body.should include("Bob Smith has used #{AlaveteliConfiguration::site_name} to send you the message below") mail.body.should include("Just a test!") #mail.to_addrs.first.to_s.should == users(:silly_name_user).name_and_email # XXX fix some nastiness with quoting name_and_email mail.from_addrs.first.to_s.should == users(:bob_smith_user).email -- cgit v1.2.3 From 34361f13ce0ef60a66bb1da01e7eaca5a0a9b25d Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Sun, 3 Mar 2013 16:44:06 +1100 Subject: We use info_request_id in the view so we should use it in the test --- spec/controllers/admin_censor_rule_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/controllers') diff --git a/spec/controllers/admin_censor_rule_controller_spec.rb b/spec/controllers/admin_censor_rule_controller_spec.rb index c4860da3f..37ffd9764 100644 --- a/spec/controllers/admin_censor_rule_controller_spec.rb +++ b/spec/controllers/admin_censor_rule_controller_spec.rb @@ -10,7 +10,7 @@ describe AdminCensorRuleController, "when making censor rules from the admin int :text => "meat", :replacement => "tofu", :last_edit_comment => "none", - :info_request => ir + :info_request_id => ir } PurgeRequest.all().first.model_id.should == ir.id end -- cgit v1.2.3 From 56afb23d947c53cdb99ba8f1e88a47e8a8eb552c Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Sun, 3 Mar 2013 17:00:20 +1100 Subject: We can't mock this in Rails 3.1 so switch to using fixture_file_upload instead --- spec/controllers/admin_public_body_controller_spec.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/admin_public_body_controller_spec.rb b/spec/controllers/admin_public_body_controller_spec.rb index c7cf48017..2070eb10c 100644 --- a/spec/controllers/admin_public_body_controller_spec.rb +++ b/spec/controllers/admin_public_body_controller_spec.rb @@ -77,8 +77,7 @@ describe AdminPublicBodyController, "when administering public bodies" do before do PublicBody.stub!(:import_csv).and_return([[],[]]) - @file_object = mock("a file upload", :read => 'some contents', - :original_filename => 'contents.txt') + @file_object = fixture_file_upload('/files/fake-authority-type.csv') end it 'should handle a nil csv file param' do @@ -97,7 +96,7 @@ describe AdminPublicBodyController, "when administering public bodies" do it 'should assign the original filename to the view' do post :import_csv, { :csv_file => @file_object, :commit => 'Dry run'} - assigns[:original_csv_file].should == 'contents.txt' + assigns[:original_csv_file].should == 'fake-authority-type.csv' end end -- cgit v1.2.3 From 28bb502677289e4b2f44252f0cf839684cc3fb28 Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Sun, 3 Mar 2013 17:14:58 +1100 Subject: Params are passed through as strings in Rails 3.1 --- spec/controllers/admin_request_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/controllers') diff --git a/spec/controllers/admin_request_controller_spec.rb b/spec/controllers/admin_request_controller_spec.rb index b51aaa9ad..b7b726507 100644 --- a/spec/controllers/admin_request_controller_spec.rb +++ b/spec/controllers/admin_request_controller_spec.rb @@ -226,7 +226,7 @@ describe AdminRequestController, "when administering the holding pen" do :user => nil, :user_name => 'External User', :is_external? => true) - InfoRequest.stub!(:find).with(@info_request.id).and_return(@info_request) + InfoRequest.stub!(:find).with(@info_request.id.to_s).and_return(@info_request) @default_params = { :id => @info_request.id, :explanation => 'Foo', :reason => 'vexatious' } -- cgit v1.2.3 From baf809ed810c6bc419e062e0a4333424b21200f5 Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Mon, 4 Mar 2013 15:20:10 +1100 Subject: This is cast to a string in Rails 3.1 --- spec/controllers/user_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/controllers') diff --git a/spec/controllers/user_controller_spec.rb b/spec/controllers/user_controller_spec.rb index 6cd1c099f..4fc4bb279 100644 --- a/spec/controllers/user_controller_spec.rb +++ b/spec/controllers/user_controller_spec.rb @@ -516,7 +516,7 @@ describe UserController, "when changing email address" do post_redirect = PostRedirect.find_by_email_token(mail_token) post_redirect.circumstance.should == 'change_email' post_redirect.user.should == users(:bob_smith_user) - post_redirect.post_params.should == {"submitted_signchangeemail_do"=>1, + post_redirect.post_params.should == {"submitted_signchangeemail_do"=>"1", "action"=>"signchangeemail", "signchangeemail"=>{ "old_email"=>"bob@localhost", -- cgit v1.2.3 From 069ad6fbacd9420bbe0838cb8d8af1928a5dd40d Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Mon, 4 Mar 2013 15:20:28 +1100 Subject: Use built in fixture_file_upload --- spec/controllers/user_controller_spec.rb | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/user_controller_spec.rb b/spec/controllers/user_controller_spec.rb index 4fc4bb279..1f86c070f 100644 --- a/spec/controllers/user_controller_spec.rb +++ b/spec/controllers/user_controller_spec.rb @@ -561,11 +561,8 @@ describe UserController, "when using profile photos" do before do @user = users(:bob_smith_user) - @uploadedfile = File.open(file_fixture_name("parrot.png")) - @uploadedfile.stub!(:original_filename).and_return('parrot.png') - - @uploadedfile_2 = File.open(file_fixture_name("parrot.jpg")) - @uploadedfile_2.stub!(:original_filename).and_return('parrot.jpg') + @uploadedfile = fixture_file_upload("/files/parrot.png") + @uploadedfile_2 = fixture_file_upload("/files/parrot.jpg") end it "should not let you change profile photo if you're not logged in as the user" do -- cgit v1.2.3 From ac412859a4ba0ac625feb7d2f212213444b7ae41 Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Mon, 4 Mar 2013 16:51:18 +1100 Subject: Reload the object after reparsing (Rails 3.1 caching) --- spec/controllers/request_controller_spec.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'spec/controllers') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 1f6b0a516..1daa239cc 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -607,6 +607,7 @@ describe RequestController, "when showing one request" do # ...but if we explicitly ask for attachments to be extracted, then they should be force = true ir.incoming_messages[1].parse_raw_email!(force) + ir.reload attachment = IncomingMessage.get_attachment_by_url_part_number(ir.incoming_messages[1].get_attachments_for_display, 2) attachment.body.should contain "Second hello" get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => 'hello.txt.html', :skip_cache => 1 -- cgit v1.2.3 From 889a9b28f188a144553cb91b698e5a2d7c96c1a2 Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Mon, 4 Mar 2013 16:51:52 +1100 Subject: Surely we expect the modified body here --- spec/controllers/request_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/controllers') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 1daa239cc..842b4e47c 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -609,7 +609,7 @@ describe RequestController, "when showing one request" do ir.incoming_messages[1].parse_raw_email!(force) ir.reload attachment = IncomingMessage.get_attachment_by_url_part_number(ir.incoming_messages[1].get_attachments_for_display, 2) - attachment.body.should contain "Second hello" + attachment.body.should contain "Third hello" get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => 'hello.txt.html', :skip_cache => 1 response.should contain "Third hello" end -- cgit v1.2.3 From 10a76a091bce366a30850b3f60354e5fe52abf5e Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Tue, 5 Mar 2013 14:08:12 +1100 Subject: Fix track searches by changing the way the routing works --- spec/controllers/track_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/controllers') diff --git a/spec/controllers/track_controller_spec.rb b/spec/controllers/track_controller_spec.rb index 63192c99e..8d9d7637b 100644 --- a/spec/controllers/track_controller_spec.rb +++ b/spec/controllers/track_controller_spec.rb @@ -49,7 +49,7 @@ describe TrackController, "when making a new track on a request" do it "should save a search track and redirect to the right place" do session[:user_id] = @user.id @track_thing.should_receive(:save!) - get :track_search_query, :query_array => ["bob variety:sent"], :feed => 'track' + get :track_search_query, :query_array => "bob variety:sent", :feed => 'track' response.should redirect_to(:controller => 'general', :action => 'search', :combined => ["bob", "requests"]) end -- cgit v1.2.3 From 8fa171594df6905e2d03359b896e550b260b0d8f Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Tue, 5 Mar 2013 14:47:42 +1100 Subject: Be a bit more exact --- spec/controllers/user_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/controllers') diff --git a/spec/controllers/user_controller_spec.rb b/spec/controllers/user_controller_spec.rb index 1f86c070f..a18554114 100644 --- a/spec/controllers/user_controller_spec.rb +++ b/spec/controllers/user_controller_spec.rb @@ -495,7 +495,7 @@ describe UserController, "when changing email address" do deliveries = ActionMailer::Base.deliveries deliveries.size.should == 1 mail = deliveries[0] - mail.body.should include("confirm that you want to change") + mail.body.should include("confirm that you want to \nchange") mail.to.should == [ 'newbob@localhost' ] mail.body.to_s =~ /(http:\/\/.*(\/c\/(.*)))/ -- cgit v1.2.3 From a4f111b763863d7a2acc4a6dcd08bebc887eb875 Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Fri, 15 Mar 2013 15:35:16 +1100 Subject: Update to current matcher API --- spec/controllers/request_controller_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 396182f00..f020ef9d7 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -337,12 +337,12 @@ describe RequestController, "when showing one request" do it 'should not show the describe state form' do make_request - response.should_not have_tag('div.describe_state_form') + response.should_not have_selector('div.describe_state_form') end it 'should not ask the user to use the describe state form' do make_request - response.should_not have_tag('p#request_status', :text => /answer the question above/) + response.should_not have_selector('p#request_status', :content => "answer the question above") end end -- cgit v1.2.3 From c5e5cb765399b0839704a7636757f0a89ef6a484 Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Fri, 15 Mar 2013 16:01:23 +1100 Subject: Changed in 166b6d90bc2dc79536d8d2d145281fa340075735 --- spec/controllers/request_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/controllers') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index f020ef9d7..fa9a2326c 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -1367,7 +1367,7 @@ describe RequestController, "when classifying an information request" do deliveries = ActionMailer::Base.deliveries deliveries.size.should == 1 mail = deliveries[0] - mail.from_addrs.first.to_s.should == users(:silly_name_user).name_and_email + mail.from_addrs.first.to_s.should == users(:silly_name_user).email end end end -- cgit v1.2.3 From c5a0ac1f191e1ca0b2bcd71f7949c12b214cd5bd Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Fri, 15 Mar 2013 17:03:47 +1100 Subject: Use a real example instead of a helper --- spec/controllers/public_body_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/controllers') diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb index 7b2876aff..e9aff9c26 100644 --- a/spec/controllers/public_body_controller_spec.rb +++ b/spec/controllers/public_body_controller_spec.rb @@ -64,7 +64,7 @@ describe PublicBodyController, "when showing a body" do it "should remember the filter (view) setting on redirecting" do get :show, :show_locale => "es", :url_name => "tgq", :view => 'successful' - response.should redirect_to show_public_body_successful_url(:url_name => "etgq") + response.should redirect_to 'http://test.host/es/body/etgq/successful' end it "should redirect to newest name if you use historic name of public body in URL" do -- cgit v1.2.3 From 4dbac2efe4bd002155e2eb9b79f41ce10d2c854e Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Fri, 15 Mar 2013 17:09:32 +1100 Subject: We've added a new fixture since the last merge --- spec/controllers/public_body_controller_spec.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb index e9aff9c26..22d8418c9 100644 --- a/spec/controllers/public_body_controller_spec.rb +++ b/spec/controllers/public_body_controller_spec.rb @@ -107,7 +107,8 @@ describe PublicBodyController, "when listing bodies" do response.should render_template('list') - assigns[:public_bodies].should == [ public_bodies(:humpadink_public_body), + assigns[:public_bodies].should == [ public_bodies(:other_public_body), + public_bodies(:humpadink_public_body), public_bodies(:forlorn_public_body), public_bodies(:geraldine_public_body), public_bodies(:sensible_walks_public_body), @@ -149,14 +150,16 @@ describe PublicBodyController, "when listing bodies" do get :list, :tag => "other" response.should render_template('list') - assigns[:public_bodies].should == [ public_bodies(:forlorn_public_body), + assigns[:public_bodies].should == [ public_bodies(:other_public_body), + public_bodies(:forlorn_public_body), public_bodies(:geraldine_public_body), public_bodies(:sensible_walks_public_body), public_bodies(:silly_walks_public_body) ] get :list response.should render_template('list') - assigns[:public_bodies].should == [ public_bodies(:humpadink_public_body), + assigns[:public_bodies].should == [ public_bodies(:other_public_body), + public_bodies(:humpadink_public_body), public_bodies(:forlorn_public_body), public_bodies(:geraldine_public_body), public_bodies(:sensible_walks_public_body), -- cgit v1.2.3 From 2800c08f7579d37d3730d1589db14e6225061911 Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Sat, 16 Mar 2013 13:30:51 +1100 Subject: Reenable test now that we don't do HTML validation in the test suite --- spec/controllers/request_controller_spec.rb | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index fa9a2326c..9fda29bf8 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -570,15 +570,12 @@ describe RequestController, "when showing one request" do end it "should generate valid HTML verson of PDF attachments" do - pending "Disabled during Rails 3 upgrade: https://github.com/mysociety/alaveteli/issues/819" - - # TODO: Fix HTML validation and enable test - # ir = info_requests(:fancy_dog_request) - # receive_incoming_mail('incoming-request-pdf-attachment.email', ir.incoming_email) - # ir.reload - # get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => 'fs_50379341.pdf.html', :skip_cache => 1 - # response.content_type.should == "text/html" - # response.should contain "Walberswick Parish Council" + ir = info_requests(:fancy_dog_request) + receive_incoming_mail('incoming-request-pdf-attachment.email', ir.incoming_email) + ir.reload + get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => 'fs_50379341.pdf.html', :skip_cache => 1 + response.content_type.should == "text/html" + response.should contain "Walberswick Parish Council" end it "should not cause a reparsing of the raw email, even when the result would be a 404" do -- cgit v1.2.3 From 8132738c60f23d5608837d48aa0f8b3b38bc1bd1 Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Tue, 19 Mar 2013 14:01:51 +1100 Subject: Another order dependent test issue fixed --- spec/controllers/request_controller_spec.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'spec/controllers') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 9fda29bf8..582fb6be0 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -918,6 +918,8 @@ describe RequestController, "when searching for an authority" do end it "should return matching bodies" do + get_fixtures_xapian_index + session[:user_id] = @user.id get :select_authority, :query => "Quango" -- cgit v1.2.3 From f7878a229b597b5fc7ba8172c8e8c94a8fd9d7b6 Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Tue, 19 Mar 2013 16:11:44 +1100 Subject: Fix another order dependent test issue --- spec/controllers/request_controller_spec.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'spec/controllers') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 582fb6be0..ccbf6b8ab 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -2199,6 +2199,10 @@ end describe RequestController, "when doing type ahead searches" do render_views + before :each do + get_fixtures_xapian_index + end + it "should return nothing for the empty query string" do get :search_typeahead, :q => "" response.should render_template('request/_search_ahead') -- cgit v1.2.3 From d5cc6f136f34a53aef16160e6af2b449201040ff Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Tue, 19 Mar 2013 19:13:01 -0700 Subject: Update Configuration references to new name. --- spec/controllers/admin_public_body_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/controllers') diff --git a/spec/controllers/admin_public_body_controller_spec.rb b/spec/controllers/admin_public_body_controller_spec.rb index f6c25451c..8a72db724 100644 --- a/spec/controllers/admin_public_body_controller_spec.rb +++ b/spec/controllers/admin_public_body_controller_spec.rb @@ -207,7 +207,7 @@ describe AdminPublicBodyController, "when administering public bodies and paying it "doesn't let people with good emergency account credentials log in if the emergency user is disabled" do setup_emergency_credentials('biz', 'fuz') - Configuration.stub!(:disable_emergency_user).and_return(true) + AlaveteliConfiguration.stub!(:disable_emergency_user).and_return(true) n = PublicBody.count basic_auth_login(@request, "biz", "fuz") post :show, { :id => public_bodies(:humpadink_public_body).id, :emergency => 1} -- cgit v1.2.3 From 35dc277233b3e87dca9a86c1b579c0e4d968b571 Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Tue, 26 Mar 2013 12:57:02 +1100 Subject: Fixup test issue found with config.order = 'random:5549' --- spec/controllers/request_controller_spec.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'spec/controllers') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index ccbf6b8ab..4161f1118 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -2268,6 +2268,8 @@ describe RequestController, "when showing similar requests" do end it "should show similar requests" do + get_fixtures_xapian_index + badger_request = info_requests(:badger_request) get :similar, :url_title => badger_request.url_title -- cgit v1.2.3 From a8f925a87075c8cc36d3ed29f7f64f51bc820b1e Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Tue, 30 Apr 2013 16:09:10 +0100 Subject: Remove debian-specific require clause and use Gemfile to specify non-standard require - bundler should be supplying the gem now. --- spec/controllers/general_controller_spec.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'spec/controllers') diff --git a/spec/controllers/general_controller_spec.rb b/spec/controllers/general_controller_spec.rb index 9a88dbc3a..4a1c8b134 100644 --- a/spec/controllers/general_controller_spec.rb +++ b/spec/controllers/general_controller_spec.rb @@ -19,8 +19,11 @@ end describe GeneralController, 'when getting the blog feed' do - it 'should add a lang param correctly to a url with no querystring' do + before do AlaveteliConfiguration.stub!(:blog_feed).and_return("http://blog.example.com") + end + + it 'should add a lang param correctly to a url with no querystring' do get :blog assigns[:feed_url].should == "http://blog.example.com?lang=en" end @@ -31,6 +34,12 @@ describe GeneralController, 'when getting the blog feed' do assigns[:feed_url].should == "http://blog.example.com?alt=rss&lang=en" end + it 'should parse an item from an example feed' do + controller.stub!(:quietly_try_to_open).and_return(load_file_fixture("blog_feed.atom")) + get :blog + assigns[:blog_items].count.should == 1 + end + end describe GeneralController, "when showing the frontpage" do -- cgit v1.2.3 From ef7be8c296a39d403193cd1ff6a9e0826a8790ac Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Wed, 1 May 2013 11:39:55 +0100 Subject: The test "should work" relies on the xapian index existing - make sure this is true for all tests in this group. --- spec/controllers/request_controller_spec.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 4161f1118..20420b96d 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -2261,6 +2261,10 @@ end describe RequestController, "when showing similar requests" do render_views + before do + get_fixtures_xapian_index + end + it "should work" do get :similar, :url_title => info_requests(:badger_request).url_title response.should render_template("request/similar") @@ -2268,8 +2272,6 @@ describe RequestController, "when showing similar requests" do end it "should show similar requests" do - get_fixtures_xapian_index - badger_request = info_requests(:badger_request) get :similar, :url_title => badger_request.url_title -- cgit v1.2.3 From 5009bfcf52f99c26896ccdcb33d9f52377c04d6d Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Thu, 2 May 2013 15:56:46 +0100 Subject: All the tests in this group rely on having the xapian db - make it part of the setup. --- spec/controllers/request_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/controllers') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 20420b96d..657837c72 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -907,6 +907,7 @@ describe RequestController, "when searching for an authority" do # so we make sure we're logged in, just in case before do @user = users(:bob_smith_user) + get_fixtures_xapian_index end it "should return nothing for the empty query string" do @@ -918,7 +919,6 @@ describe RequestController, "when searching for an authority" do end it "should return matching bodies" do - get_fixtures_xapian_index session[:user_id] = @user.id get :select_authority, :query => "Quango" -- cgit v1.2.3 From 16ca4662692125290f8df336d71dc098af4b937b Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Mon, 13 May 2013 16:40:09 +0100 Subject: Add call to load_raw_emails_data to fix dependency on raw emails exposed in https://travis-ci.org/mysociety/alaveteli/jobs/7126060. --- spec/controllers/user_controller_spec.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'spec/controllers') diff --git a/spec/controllers/user_controller_spec.rb b/spec/controllers/user_controller_spec.rb index a18554114..1d8e3dcc3 100644 --- a/spec/controllers/user_controller_spec.rb +++ b/spec/controllers/user_controller_spec.rb @@ -626,6 +626,7 @@ describe UserController, "when viewing the wall" do render_views before(:each) do + load_raw_emails_data get_fixtures_xapian_index end -- cgit v1.2.3 From 9a5ef164ba29a8f56b3e2f42edf83d732613738f Mon Sep 17 00:00:00 2001 From: Mark Longair Date: Thu, 9 May 2013 14:19:50 +0100 Subject: Switch to just loading fixtures in tests as binary strings The data loaded with load_file_fixture is generally used in the tests as if it were binary data received from the MTA, so just load it as binary data - in Ruby 1.9 this means that it will end up with the encoding ASCII-8BIT. The same is the case when reading data from a fixture file in receive_incoming_mail. --- spec/controllers/api_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/controllers') diff --git a/spec/controllers/api_controller_spec.rb b/spec/controllers/api_controller_spec.rb index 749be9f85..66b8e33f0 100644 --- a/spec/controllers/api_controller_spec.rb +++ b/spec/controllers/api_controller_spec.rb @@ -259,7 +259,7 @@ describe ApiController, "when using the API" do attachments.size.should == 1 attachment = attachments[0] attachment.filename.should == "tfl.pdf" - attachment.body.should == load_file_fixture("tfl.pdf", as_binary=true) + attachment.body.should == load_file_fixture("tfl.pdf") end it "should show information about a request" do -- cgit v1.2.3 From 501b2b8672d294268b2eb112092e70ffc2728539 Mon Sep 17 00:00:00 2001 From: Mark Longair Date: Fri, 24 May 2013 18:50:16 +0100 Subject: Check that display_filename matches URL part number or fallback If the display_filename of the attachment found from the URL part number doesn't match the passed in display_filename then the email may have been reparsed, causing a reordering. In that case, look to see if there is another attachment that uniquely matches that filename, and, if so, return that other attachment. If no matching uniquely matching filename is found, redirect to the incoming message, rather than returning a 404. --- spec/controllers/request_controller_spec.rb | 50 ++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 15 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 657837c72..67fed572a 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -578,23 +578,21 @@ describe RequestController, "when showing one request" do response.should contain "Walberswick Parish Council" end - it "should not cause a reparsing of the raw email, even when the result would be a 404" do + it "should not cause a reparsing of the raw email, even when the attachment can't be found" do ir = info_requests(:fancy_dog_request) receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email) ir.reload - attachment = IncomingMessage.get_attachment_by_url_part_number(ir.incoming_messages[1].get_attachments_for_display, 2) + attachment = IncomingMessage.get_attachment_by_url_part_number_and_filename(ir.incoming_messages[1].get_attachments_for_display, 2, 'hello.txt') attachment.body.should contain "Second hello" # change the raw_email associated with the message; this only be reparsed when explicitly asked for ir.incoming_messages[1].raw_email.data = ir.incoming_messages[1].raw_email.data.sub("Second", "Third") - # asking for an attachment by the wrong filename results - # in a 404 for browsing users. This shouldn't cause a - # re-parse... - lambda { - get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => 'hello.txt.baz.html', :skip_cache => 1 - }.should raise_error(ActiveRecord::RecordNotFound) + # asking for an attachment by the wrong filename should result in redirecting + # back to the incoming message, but shouldn't cause a reparse: + get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => 'hello.txt.baz.html', :skip_cache => 1 + response.status.should == 303 - attachment = IncomingMessage.get_attachment_by_url_part_number(ir.incoming_messages[1].get_attachments_for_display, 2) + attachment = IncomingMessage.get_attachment_by_url_part_number_and_filename(ir.incoming_messages[1].get_attachments_for_display, 2, 'hello.txt') attachment.body.should contain "Second hello" # ...nor should asking for it by its correct filename... @@ -605,12 +603,36 @@ describe RequestController, "when showing one request" do force = true ir.incoming_messages[1].parse_raw_email!(force) ir.reload - attachment = IncomingMessage.get_attachment_by_url_part_number(ir.incoming_messages[1].get_attachments_for_display, 2) + attachment = IncomingMessage.get_attachment_by_url_part_number_and_filename(ir.incoming_messages[1].get_attachments_for_display, 2, 'hello.txt') attachment.body.should contain "Third hello" get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => 'hello.txt.html', :skip_cache => 1 response.should contain "Third hello" end + it "should redirect to the incoming message if there's a wrong part number and an ambiguous filename" do + ir = info_requests(:fancy_dog_request) + receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email) + ir.reload + + im = ir.incoming_messages[1] + + attachment = IncomingMessage.get_attachment_by_url_part_number_and_filename(im.get_attachments_for_display, 5, 'hello world.txt') + attachment.should be_nil + + get :get_attachment_as_html, :incoming_message_id => im.id, :id => ir.id, :part => 5, :file_name => 'hello world.txt', :skip_cache => 1 + response.status.should == 303 + new_location = response.header['Location'] + new_location.should match(/request\/#{ir.url_title}#incoming-#{im.id}/) + end + + it "should find a uniquely named filename even if the URL part number was wrong" do + ir = info_requests(:fancy_dog_request) + receive_incoming_mail('incoming-request-pdf-attachment.email', ir.incoming_email) + ir.reload + get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 5, :file_name => 'fs 50379341.pdf', :skip_cache => 1 + response.content_type.should == "application/pdf" + end + it "should treat attachments with unknown extensions as binary" do ir = info_requests(:fancy_dog_request) receive_incoming_mail('incoming-request-attachment-unknown-extension.email', ir.incoming_email) @@ -625,10 +647,8 @@ describe RequestController, "when showing one request" do ir = info_requests(:fancy_dog_request) receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email) - lambda { - get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, - :file_name => 'http://trying.to.hack' - }.should raise_error(ActiveRecord::RecordNotFound) + get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => 'http://trying.to.hack' + response.status.should == 303 end it "should censor attachments downloaded as binary" do @@ -2394,7 +2414,7 @@ describe RequestController, "when caching fragments" do attachment = mock(FoiAttachment, :display_filename => long_name, :body_as_html => ['some text', 'wrapper']) IncomingMessage.stub!(:find).with("44").and_return(incoming_message) - IncomingMessage.stub!(:get_attachment_by_url_part_number).and_return(attachment) + IncomingMessage.stub!(:get_attachment_by_url_part_number_and_filename).and_return(attachment) InfoRequest.stub!(:find).with("132").and_return(info_request) params = { :file_name => long_name, :controller => "request", -- cgit v1.2.3 From 84371abc33bd637d51600017bd91807cc2f70384 Mon Sep 17 00:00:00 2001 From: Mark Longair Date: Fri, 24 May 2013 11:52:24 +0100 Subject: Make an attachment filename in test fixtures more difficult This commit changes 'hello.txt' to 'hello-world.txt' in the incoming-request-two-same-name.email fixture. The reasoning for this change is that if there are no special characters in the filename then filename and display_filename will be the same and the tests won't pick up any confusion between the two. The test requests to :get_attachment and :get_attachment_as_html should get the display_filename rather than filename. --- spec/controllers/request_controller_spec.rb | 48 ++++++++++++++--------------- 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 67fed572a..231efca36 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -477,11 +477,11 @@ describe RequestController, "when showing one request" do (assigns[:info_request_events].size - size_before).should == 1 ir.reload - get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => 'hello.txt', :skip_cache => 1 + get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => 'hello world.txt', :skip_cache => 1 response.content_type.should == "text/plain" response.should contain "Second hello" - get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 3, :file_name => 'hello.txt', :skip_cache => 1 + get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 3, :file_name => 'hello world.txt', :skip_cache => 1 response.content_type.should == "text/plain" response.should contain "First hello" end @@ -494,7 +494,7 @@ describe RequestController, "when showing one request" do get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, - :file_name => 'hello.txt' + :file_name => 'hello world.txt' end it "should convert message body to UTF8" do @@ -508,7 +508,7 @@ describe RequestController, "when showing one request" do ir = info_requests(:fancy_dog_request) receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email) ir.reload - get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => 'hello.txt.html', :skip_cache => 1 + get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => 'hello world.txt.html', :skip_cache => 1 response.content_type.should == "text/html" response.should contain "Second hello" end @@ -529,11 +529,11 @@ describe RequestController, "when showing one request" do ir.reload ugly_id = "55195" lambda { - get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ugly_id, :part => 2, :file_name => 'hello.txt.html', :skip_cache => 1 + get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ugly_id, :part => 2, :file_name => 'hello world.txt.html', :skip_cache => 1 }.should raise_error(ActiveRecord::RecordNotFound) lambda { - get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ugly_id, :part => 2, :file_name => 'hello.txt', :skip_cache => 1 + get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ugly_id, :part => 2, :file_name => 'hello world.txt', :skip_cache => 1 }.should raise_error(ActiveRecord::RecordNotFound) end it "should return 404 when incoming message and request ids don't match" do @@ -542,7 +542,7 @@ describe RequestController, "when showing one request" do receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email) ir.reload lambda { - get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => wrong_id, :part => 2, :file_name => 'hello.txt.html', :skip_cache => 1 + get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => wrong_id, :part => 2, :file_name => 'hello world.txt.html', :skip_cache => 1 }.should raise_error(ActiveRecord::RecordNotFound) end it "should return 404 for ugly URLs contain a request id that isn't an integer, even if the integer prefix refers to an actual request" do @@ -552,11 +552,11 @@ describe RequestController, "when showing one request" do ugly_id = "%d95" % [info_requests(:naughty_chicken_request).id] lambda { - get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ugly_id, :part => 2, :file_name => 'hello.txt.html', :skip_cache => 1 + get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ugly_id, :part => 2, :file_name => 'hello world.txt.html', :skip_cache => 1 }.should raise_error(ActiveRecord::RecordNotFound) lambda { - get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ugly_id, :part => 2, :file_name => 'hello.txt', :skip_cache => 1 + get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ugly_id, :part => 2, :file_name => 'hello world.txt', :skip_cache => 1 }.should raise_error(ActiveRecord::RecordNotFound) end it "should return 404 when incoming message and request ids don't match" do @@ -565,7 +565,7 @@ describe RequestController, "when showing one request" do receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email) ir.reload lambda { - get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => wrong_id, :part => 2, :file_name => 'hello.txt.html', :skip_cache => 1 + get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => wrong_id, :part => 2, :file_name => 'hello world.txt.html', :skip_cache => 1 }.should raise_error(ActiveRecord::RecordNotFound) end @@ -582,30 +582,30 @@ describe RequestController, "when showing one request" do ir = info_requests(:fancy_dog_request) receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email) ir.reload - attachment = IncomingMessage.get_attachment_by_url_part_number_and_filename(ir.incoming_messages[1].get_attachments_for_display, 2, 'hello.txt') + attachment = IncomingMessage.get_attachment_by_url_part_number_and_filename(ir.incoming_messages[1].get_attachments_for_display, 2, 'hello world.txt') attachment.body.should contain "Second hello" # change the raw_email associated with the message; this only be reparsed when explicitly asked for ir.incoming_messages[1].raw_email.data = ir.incoming_messages[1].raw_email.data.sub("Second", "Third") # asking for an attachment by the wrong filename should result in redirecting # back to the incoming message, but shouldn't cause a reparse: - get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => 'hello.txt.baz.html', :skip_cache => 1 + get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => 'hello world.txt.baz.html', :skip_cache => 1 response.status.should == 303 - attachment = IncomingMessage.get_attachment_by_url_part_number_and_filename(ir.incoming_messages[1].get_attachments_for_display, 2, 'hello.txt') + attachment = IncomingMessage.get_attachment_by_url_part_number_and_filename(ir.incoming_messages[1].get_attachments_for_display, 2, 'hello world.txt') attachment.body.should contain "Second hello" # ...nor should asking for it by its correct filename... - get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => 'hello.txt.html', :skip_cache => 1 + get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => 'hello world.txt.html', :skip_cache => 1 response.should_not contain "Third hello" # ...but if we explicitly ask for attachments to be extracted, then they should be force = true ir.incoming_messages[1].parse_raw_email!(force) ir.reload - attachment = IncomingMessage.get_attachment_by_url_part_number_and_filename(ir.incoming_messages[1].get_attachments_for_display, 2, 'hello.txt') + attachment = IncomingMessage.get_attachment_by_url_part_number_and_filename(ir.incoming_messages[1].get_attachments_for_display, 2, 'hello world.txt') attachment.body.should contain "Third hello" - get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => 'hello.txt.html', :skip_cache => 1 + get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => 'hello world.txt.html', :skip_cache => 1 response.should contain "Third hello" end @@ -664,7 +664,7 @@ describe RequestController, "when showing one request" do begin receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email) - get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => 'hello.txt', :skip_cache => 1 + get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => 'hello world.txt', :skip_cache => 1 response.content_type.should == "text/plain" response.should contain "xxxxxx hello" ensure @@ -686,7 +686,7 @@ describe RequestController, "when showing one request" do receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email) ir.reload - get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => 'hello.txt', :skip_cache => 1 + get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => 'hello world.txt', :skip_cache => 1 response.content_type.should == "text/plain" response.should contain "xxxxxx hello" ensure @@ -715,11 +715,11 @@ describe RequestController, "when showing one request" do # so at this point, assigns[:info_request].incoming_messages[1].get_attachments_for_display is returning stuff, but the equivalent thing in the template isn't. # but something odd is that the above is return a whole load of attachments which aren't there in the controller response.body.should have_selector("p.attachment strong") do |s| - s.should contain /hello.txt/m + s.should contain /hello world.txt/m end censor_rule = CensorRule.new() - censor_rule.text = "hello.txt" + censor_rule.text = "hello-world.txt" censor_rule.replacement = "goodbye.txt" censor_rule.last_edit_editor = "unknown" censor_rule.last_edit_comment = "none" @@ -763,7 +763,7 @@ describe RequestController, "when showing one request" do old_path = assigns[:url_path] response.location.should contain /#{assigns[:url_path]}$/ zipfile = Zip::ZipFile.open(File.join(File.dirname(__FILE__), "../../cache/zips", old_path)) { |zipfile| - zipfile.count.should == 3 # the message plus two "hello.txt" files + zipfile.count.should == 3 # the message plus two "hello-world.txt" files } # The path of the zip file is based on the hash of the timestamp of the last request @@ -776,7 +776,7 @@ describe RequestController, "when showing one request" do assigns[:url_path].should_not == old_path response.location.should contain assigns[:url_path] zipfile = Zip::ZipFile.open(File.join(File.dirname(__FILE__), "../../cache/zips", assigns[:url_path])) { |zipfile| - zipfile.count.should == 4 # the message, two hello.txt plus the unknown attachment + zipfile.count.should == 4 # the message, two hello-world.txt plus the unknown attachment } end @@ -895,7 +895,7 @@ describe RequestController, "when changing prominence of a request" do get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, - :file_name => 'hello.txt' + :file_name => 'hello world.txt' end.should raise_error(ActiveRecord::RecordNotFound) end @@ -910,7 +910,7 @@ describe RequestController, "when changing prominence of a request" do get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, - :file_name => 'hello.txt' + :file_name => 'hello world.txt' end.should raise_error(ActiveRecord::RecordNotFound) end -- cgit v1.2.3 From 395e2273dd02286242f69231b7d61a474ddd0e01 Mon Sep 17 00:00:00 2001 From: Mark Longair Date: Fri, 24 May 2013 11:58:08 +0100 Subject: The file_name on getting an attachment should be the display filename Previously the behaviour would have been the same, since we weren't checking the filename so strictly. --- spec/controllers/request_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/controllers') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 231efca36..b87a4ade8 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -573,7 +573,7 @@ describe RequestController, "when showing one request" do ir = info_requests(:fancy_dog_request) receive_incoming_mail('incoming-request-pdf-attachment.email', ir.incoming_email) ir.reload - get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => 'fs_50379341.pdf.html', :skip_cache => 1 + get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => 'fs 50379341.pdf.html', :skip_cache => 1 response.content_type.should == "text/html" response.should contain "Walberswick Parish Council" end -- cgit v1.2.3 From f8cc81a7791c6055dc6cf829e25138b7f6261a3e Mon Sep 17 00:00:00 2001 From: Mark Longair Date: Fri, 24 May 2013 11:50:26 +0100 Subject: Add a comment about the behaviour of the censor rules --- spec/controllers/request_controller_spec.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'spec/controllers') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index b87a4ade8..9cc60a103 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -719,6 +719,8 @@ describe RequestController, "when showing one request" do end censor_rule = CensorRule.new() + # Note that the censor rule applies to the original filename, + # not the display_filename: censor_rule.text = "hello-world.txt" censor_rule.replacement = "goodbye.txt" censor_rule.last_edit_editor = "unknown" -- cgit v1.2.3 From 2376834e80b736e4eb4f4dcbdbb3988cafa6cc5b Mon Sep 17 00:00:00 2001 From: Mark Longair Date: Wed, 29 May 2013 15:25:02 +0100 Subject: Make sure Atom feeds are served with content type application/atom+xml Fixes #961 --- spec/controllers/track_controller_spec.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'spec/controllers') diff --git a/spec/controllers/track_controller_spec.rb b/spec/controllers/track_controller_spec.rb index e9501b1ed..5a766b1e1 100644 --- a/spec/controllers/track_controller_spec.rb +++ b/spec/controllers/track_controller_spec.rb @@ -144,6 +144,7 @@ describe TrackController, "when viewing RSS feed for a track" do get :track_request, :feed => 'feed', :url_title => track_thing.info_request.url_title response.should render_template('track/atom_feed') + response.content_type.should == 'application/atom+xml' # XXX should check it is an atom.builder type being rendered, not sure how to assigns[:xapian_object].matches_estimated.should == 3 -- cgit v1.2.3 From d9d9997a1d0f6d361097a8a4bdf1aa0fee24edaa Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Mon, 3 Jun 2013 16:41:14 +0100 Subject: Handle json requests for hidden info requests. --- spec/controllers/request_controller_spec.rb | 39 +++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 7 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 9cc60a103..83e2b1767 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -816,6 +816,16 @@ describe RequestController, "when changing prominence of a request" do response.should render_template('hidden') end + it 'should not show hidden requests if requested using json' do + ir = info_requests(:fancy_dog_request) + ir.prominence = 'hidden' + ir.save! + + session[:user_id] = ir.user.id # bob_smith_user + get :show, :url_title => 'why_do_you_have_such_a_fancy_dog', :format => 'json' + response.code.should == '410' + end + it "should show hidden requests if logged in as super user" do ir = info_requests(:fancy_dog_request) ir.prominence = 'hidden' @@ -1236,14 +1246,29 @@ describe RequestController, "when viewing an individual response for reply/follo response.body.should have_selector("div#other_recipients ul li", :content => "Frob") end - it "should not show individual responses if request hidden, even if request owner" do - ir = info_requests(:fancy_dog_request) - ir.prominence = 'hidden' - ir.save! + context 'when a request is hidden' do + + before do + ir = info_requests(:fancy_dog_request) + ir.prominence = 'hidden' + ir.save! + + session[:user_id] = users(:bob_smith_user).id + end + + it "should not show individual responses, even if request owner" do + get :show_response, :id => info_requests(:fancy_dog_request).id, :incoming_message_id => incoming_messages(:useless_incoming_message) + response.should render_template('request/hidden') + end + + it 'should respond to a json request for a hidden request with a 410 code and no body' do + get :show_response, :id => info_requests(:fancy_dog_request).id, + :incoming_message_id => incoming_messages(:useless_incoming_message), + :format => 'json' + + response.code.should == '410' + end - session[:user_id] = users(:bob_smith_user).id - get :show_response, :id => info_requests(:fancy_dog_request).id, :incoming_message_id => incoming_messages(:useless_incoming_message) - response.should render_template('request/hidden') end describe 'when viewing a response for an external request' do -- cgit v1.2.3