diff options
Diffstat (limited to 'spec')
148 files changed, 1076 insertions, 211 deletions
diff --git a/spec/controllers/admin_censor_rule_controller_spec.rb b/spec/controllers/admin_censor_rule_controller_spec.rb index 68eaecd6a..b9f936836 100644 --- a/spec/controllers/admin_censor_rule_controller_spec.rb +++ b/spec/controllers/admin_censor_rule_controller_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe AdminCensorRuleController do @@ -584,7 +585,7 @@ describe AdminCensorRuleController, "when making censor rules from the admin int :replacement => "tofu", :last_edit_comment => "none" } - PurgeRequest.all().first.model_id.should == ir.id + PurgeRequest.all.first.model_id.should == ir.id end end diff --git a/spec/controllers/admin_comment_controller_spec.rb b/spec/controllers/admin_comment_controller_spec.rb index f87231e3b..00b6e6cc9 100644 --- a/spec/controllers/admin_comment_controller_spec.rb +++ b/spec/controllers/admin_comment_controller_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe AdminCommentController do diff --git a/spec/controllers/admin_general_controller_spec.rb b/spec/controllers/admin_general_controller_spec.rb index cc2ec41b4..b2e8b233f 100644 --- a/spec/controllers/admin_general_controller_spec.rb +++ b/spec/controllers/admin_general_controller_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe AdminGeneralController do diff --git a/spec/controllers/admin_holiday_imports_controller_spec.rb b/spec/controllers/admin_holiday_imports_controller_spec.rb index dd23a022f..42dfadd47 100644 --- a/spec/controllers/admin_holiday_imports_controller_spec.rb +++ b/spec/controllers/admin_holiday_imports_controller_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require 'spec_helper' describe AdminHolidayImportsController do diff --git a/spec/controllers/admin_holidays_controller_spec.rb b/spec/controllers/admin_holidays_controller_spec.rb index 21cb51d29..93f51707b 100644 --- a/spec/controllers/admin_holidays_controller_spec.rb +++ b/spec/controllers/admin_holidays_controller_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require 'spec_helper' describe AdminHolidaysController do diff --git a/spec/controllers/admin_incoming_message_controller_spec.rb b/spec/controllers/admin_incoming_message_controller_spec.rb index 24a526ca4..39355c054 100644 --- a/spec/controllers/admin_incoming_message_controller_spec.rb +++ b/spec/controllers/admin_incoming_message_controller_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe AdminIncomingMessageController, "when administering incoming messages" do diff --git a/spec/controllers/admin_info_request_event_controller_spec.rb b/spec/controllers/admin_info_request_event_controller_spec.rb index 23300a0b8..dfa425374 100644 --- a/spec/controllers/admin_info_request_event_controller_spec.rb +++ b/spec/controllers/admin_info_request_event_controller_spec.rb @@ -1,4 +1,4 @@ -# coding: utf-8 +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe AdminInfoRequestEventController do diff --git a/spec/controllers/admin_outgoing_message_controller_spec.rb b/spec/controllers/admin_outgoing_message_controller_spec.rb index a46a077da..f231311ae 100644 --- a/spec/controllers/admin_outgoing_message_controller_spec.rb +++ b/spec/controllers/admin_outgoing_message_controller_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe AdminOutgoingMessageController do diff --git a/spec/controllers/admin_public_body_categories_controller_spec.rb b/spec/controllers/admin_public_body_categories_controller_spec.rb index 1131b3c0b..1aa8a145e 100644 --- a/spec/controllers/admin_public_body_categories_controller_spec.rb +++ b/spec/controllers/admin_public_body_categories_controller_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require 'spec_helper' describe AdminPublicBodyCategoriesController do @@ -310,7 +311,7 @@ describe AdminPublicBodyCategoriesController do post :update, :id => category.id, :public_body_category => category.serializable_hash.except(:title, :description) - expect(assigns(:tagged_public_bodies)).to eq(expected_bodies) + expect(assigns(:tagged_public_bodies)).to match_array(expected_bodies) end it "saves edits to a public body category's heading associations" do diff --git a/spec/controllers/admin_public_body_change_requests_controller_spec.rb b/spec/controllers/admin_public_body_change_requests_controller_spec.rb index 003510e60..b0a9ebd79 100644 --- a/spec/controllers/admin_public_body_change_requests_controller_spec.rb +++ b/spec/controllers/admin_public_body_change_requests_controller_spec.rb @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe AdminPublicBodyChangeRequestsController, "editing a change request" do diff --git a/spec/controllers/admin_public_body_controller_spec.rb b/spec/controllers/admin_public_body_controller_spec.rb index 50a373d9d..1b960ccc3 100644 --- a/spec/controllers/admin_public_body_controller_spec.rb +++ b/spec/controllers/admin_public_body_controller_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe AdminPublicBodyController, "when showing the index of public bodies" do @@ -650,17 +651,17 @@ describe AdminPublicBodyController, "when administering public bodies and paying render_views before do - config = MySociety::Config.load_default() + config = MySociety::Config.load_default config['SKIP_ADMIN_AUTH'] = false basic_auth_login @request end after do - config = MySociety::Config.load_default() + config = MySociety::Config.load_default config['SKIP_ADMIN_AUTH'] = true end def setup_emergency_credentials(username, password) - config = MySociety::Config.load_default() + config = MySociety::Config.load_default config['SKIP_ADMIN_AUTH'] = false config['ADMIN_USERNAME'] = username config['ADMIN_PASSWORD'] = password @@ -677,7 +678,7 @@ describe AdminPublicBodyController, "when administering public bodies and paying end it "skips admin authorisation when SKIP_ADMIN_AUTH set" do - config = MySociety::Config.load_default() + config = MySociety::Config.load_default config['SKIP_ADMIN_AUTH'] = true @request.env["HTTP_AUTHORIZATION"] = "" n = PublicBody.count @@ -757,7 +758,7 @@ describe AdminPublicBodyController, "when administering public bodies and paying end it 'returns the REMOTE_USER value from the request environment when skipping admin auth' do - config = MySociety::Config.load_default() + config = MySociety::Config.load_default config['SKIP_ADMIN_AUTH'] = true @request.env["HTTP_AUTHORIZATION"] = "" @request.env["REMOTE_USER"] = "i_am_admin" diff --git a/spec/controllers/admin_public_body_headings_controller_spec.rb b/spec/controllers/admin_public_body_headings_controller_spec.rb index ccdfdecfb..0e0337e3e 100644 --- a/spec/controllers/admin_public_body_headings_controller_spec.rb +++ b/spec/controllers/admin_public_body_headings_controller_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require 'spec_helper' describe AdminPublicBodyHeadingsController do diff --git a/spec/controllers/admin_raw_email_controller_spec.rb b/spec/controllers/admin_raw_email_controller_spec.rb index 77c57c38b..9039286bc 100644 --- a/spec/controllers/admin_raw_email_controller_spec.rb +++ b/spec/controllers/admin_raw_email_controller_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe AdminRawEmailController do diff --git a/spec/controllers/admin_request_controller_spec.rb b/spec/controllers/admin_request_controller_spec.rb index 4eb463963..61827bfd1 100644 --- a/spec/controllers/admin_request_controller_spec.rb +++ b/spec/controllers/admin_request_controller_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe AdminRequestController, "when administering requests" do diff --git a/spec/controllers/admin_spam_addresses_controller_spec.rb b/spec/controllers/admin_spam_addresses_controller_spec.rb index a1e434159..8f6d57b01 100644 --- a/spec/controllers/admin_spam_addresses_controller_spec.rb +++ b/spec/controllers/admin_spam_addresses_controller_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require 'spec_helper' describe AdminSpamAddressesController do diff --git a/spec/controllers/admin_track_controller_spec.rb b/spec/controllers/admin_track_controller_spec.rb index d29db4966..b77570a27 100644 --- a/spec/controllers/admin_track_controller_spec.rb +++ b/spec/controllers/admin_track_controller_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe AdminTrackController, "when administering tracks" do diff --git a/spec/controllers/admin_user_controller_spec.rb b/spec/controllers/admin_user_controller_spec.rb index e979355cf..9341feec6 100644 --- a/spec/controllers/admin_user_controller_spec.rb +++ b/spec/controllers/admin_user_controller_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe AdminUserController, "when administering users" do diff --git a/spec/controllers/api_controller_spec.rb b/spec/controllers/api_controller_spec.rb index 323ef4cd4..d8af59ad8 100644 --- a/spec/controllers/api_controller_spec.rb +++ b/spec/controllers/api_controller_spec.rb @@ -1,4 +1,4 @@ -# coding: utf-8 +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe ApiController, "when using the API" do diff --git a/spec/controllers/comment_controller_spec.rb b/spec/controllers/comment_controller_spec.rb index 480c85ad7..cfd7166f4 100644 --- a/spec/controllers/comment_controller_spec.rb +++ b/spec/controllers/comment_controller_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe CommentController, "when commenting on a request" do diff --git a/spec/controllers/general_controller_spec.rb b/spec/controllers/general_controller_spec.rb index 844fcd4e6..495624403 100644 --- a/spec/controllers/general_controller_spec.rb +++ b/spec/controllers/general_controller_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') require 'fakeweb' @@ -111,7 +112,7 @@ describe GeneralController, "when showing the frontpage" do it "should render the front page with default language and ignore the browser setting" do - config = MySociety::Config.load_default() + config = MySociety::Config.load_default config['USE_DEFAULT_BROWSER_LANGUAGE'] = false accept_language = "en-GB,en-US;q=0.8,en;q=0.6" request.env['HTTP_ACCEPT_LANGUAGE'] = accept_language @@ -122,7 +123,7 @@ describe GeneralController, "when showing the frontpage" do end it "should render the front page with browser-selected language when there's no default set" do - config = MySociety::Config.load_default() + config = MySociety::Config.load_default config['USE_DEFAULT_BROWSER_LANGUAGE'] = true accept_language = "es-ES,en-GB,en-US;q=0.8,en;q=0.6" request.env['HTTP_ACCEPT_LANGUAGE'] = accept_language diff --git a/spec/controllers/health_checks_controller_spec.rb b/spec/controllers/health_checks_controller_spec.rb index f7ad6d6a4..2403fb3c8 100644 --- a/spec/controllers/health_checks_controller_spec.rb +++ b/spec/controllers/health_checks_controller_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe HealthChecksController do diff --git a/spec/controllers/help_controller_spec.rb b/spec/controllers/help_controller_spec.rb index 9453c9461..338a86380 100644 --- a/spec/controllers/help_controller_spec.rb +++ b/spec/controllers/help_controller_spec.rb @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe HelpController do diff --git a/spec/controllers/info_request_batch_controller_spec.rb b/spec/controllers/info_request_batch_controller_spec.rb index d08f02e10..866a1d0dc 100644 --- a/spec/controllers/info_request_batch_controller_spec.rb +++ b/spec/controllers/info_request_batch_controller_spec.rb @@ -1,4 +1,4 @@ -# coding: utf-8 +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe InfoRequestBatchController, "when showing a request" do diff --git a/spec/controllers/public_body_change_requests_controller_spec.rb b/spec/controllers/public_body_change_requests_controller_spec.rb index 4053b2f40..a8f149cc6 100644 --- a/spec/controllers/public_body_change_requests_controller_spec.rb +++ b/spec/controllers/public_body_change_requests_controller_spec.rb @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe PublicBodyChangeRequestsController, "making a new change request" do diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb index ff0a70a6f..c5c94a45c 100644 --- a/spec/controllers/public_body_controller_spec.rb +++ b/spec/controllers/public_body_controller_spec.rb @@ -1,4 +1,4 @@ -# coding: utf-8 +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') require 'nokogiri' @@ -336,7 +336,7 @@ end describe PublicBodyController, "when showing public body statistics" do it "should render the right template with the right data" do - config = MySociety::Config.load_default() + config = MySociety::Config.load_default config['MINIMUM_REQUESTS_FOR_STATISTICS'] = 1 config['PUBLIC_BODY_STATISTICS_PAGE'] = true get :statistics diff --git a/spec/controllers/reports_controller_spec.rb b/spec/controllers/reports_controller_spec.rb index fa8c72eaa..91be67fd8 100644 --- a/spec/controllers/reports_controller_spec.rb +++ b/spec/controllers/reports_controller_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require 'spec_helper' describe ReportsController, "when reporting a request when not logged in" do diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 02237b29d..a5534e9ff 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe RequestController, "when listing recent requests" do @@ -40,41 +40,41 @@ describe RequestController, "when changing things that appear on the request pag it "should purge the downstream cache when mail is received" do ir = info_requests(:fancy_dog_request) receive_incoming_mail('incoming-request-plain.email', ir.incoming_email) - PurgeRequest.all().first.model_id.should == ir.id + PurgeRequest.all.first.model_id.should == ir.id end it "should purge the downstream cache when a comment is added" do ir = info_requests(:fancy_dog_request) new_comment = info_requests(:fancy_dog_request).add_comment('I also love making annotations.', users(:bob_smith_user)) - PurgeRequest.all().first.model_id.should == ir.id + PurgeRequest.all.first.model_id.should == ir.id end it "should purge the downstream cache when a followup is made" do session[:user_id] = users(:bob_smith_user).id ir = info_requests(:fancy_dog_request) post :show_response, :outgoing_message => { :body => "What a useless response! You suck.", :what_doing => 'normal_sort' }, :id => ir.id, :submitted_followup => 1 - PurgeRequest.all().first.model_id.should == ir.id + PurgeRequest.all.first.model_id.should == ir.id end it "should purge the downstream cache when the request is categorised" do ir = info_requests(:fancy_dog_request) ir.set_described_state('waiting_clarification') - PurgeRequest.all().first.model_id.should == ir.id + PurgeRequest.all.first.model_id.should == ir.id end it "should purge the downstream cache when the authority data is changed" do ir = info_requests(:fancy_dog_request) ir.public_body.name = "Something new" ir.public_body.save! - PurgeRequest.all().map{|x| x.model_id}.should =~ ir.public_body.info_requests.map{|x| x.id} + PurgeRequest.all.map{|x| x.model_id}.should =~ ir.public_body.info_requests.map{|x| x.id} end it "should purge the downstream cache when the user name is changed" do ir = info_requests(:fancy_dog_request) ir.user.name = "Something new" ir.user.save! - PurgeRequest.all().map{|x| x.model_id}.should =~ ir.user.info_requests.map{|x| x.id} + PurgeRequest.all.map{|x| x.model_id}.should =~ ir.user.info_requests.map{|x| x.id} end it "should not purge the downstream cache when non-visible user details are changed" do ir = info_requests(:fancy_dog_request) ir.user.hashed_password = "some old hash" ir.user.save! - PurgeRequest.all().count.should == 0 + PurgeRequest.all.count.should == 0 end it "should purge the downstream cache when censor rules have changed" do # TODO: really, CensorRules should execute expiry logic as part @@ -86,17 +86,17 @@ describe RequestController, "when changing things that appear on the request pag ir = info_requests(:fancy_dog_request) ir.prominence = 'hidden' ir.save! - PurgeRequest.all().first.model_id.should == ir.id + PurgeRequest.all.first.model_id.should == ir.id end it "should not create more than one entry for any given resource" do ir = info_requests(:fancy_dog_request) ir.prominence = 'hidden' ir.save! - PurgeRequest.all().count.should == 1 + PurgeRequest.all.count.should == 1 ir = info_requests(:fancy_dog_request) ir.prominence = 'hidden' ir.save! - PurgeRequest.all().count.should == 1 + PurgeRequest.all.count.should == 1 end end @@ -611,7 +611,7 @@ describe RequestController, "when showing one request" do it "should censor attachments downloaded as binary" do ir = info_requests(:fancy_dog_request) - censor_rule = CensorRule.new() + censor_rule = CensorRule.new censor_rule.text = "Second" censor_rule.replacement = "Mouse" censor_rule.last_edit_editor = "unknown" @@ -632,7 +632,7 @@ describe RequestController, "when showing one request" do it "should censor with rules on the user (rather than the request)" do ir = info_requests(:fancy_dog_request) - censor_rule = CensorRule.new() + censor_rule = CensorRule.new censor_rule.text = "Second" censor_rule.replacement = "Mouse" censor_rule.last_edit_editor = "unknown" @@ -675,7 +675,7 @@ describe RequestController, "when showing one request" do s.should contain /hello world.txt/m end - censor_rule = CensorRule.new() + censor_rule = CensorRule.new # Note that the censor rule applies to the original filename, # not the display_filename: censor_rule.text = "hello-world.txt" @@ -1471,7 +1471,7 @@ describe RequestController, "when classifying an information request" do it 'should record a classification' do event = mock_model(InfoRequestEvent) - @dog_request.stub!(:log_event).with("status_update", anything()).and_return(event) + @dog_request.stub!(:log_event).with("status_update", anything).and_return(event) RequestClassification.should_receive(:create!).with(:user_id => @admin_user.id, :info_request_event_id => event.id) post_status('rejected') @@ -1915,7 +1915,7 @@ describe RequestController, "sending overdue request alerts" do it "should send an overdue alert mail to creators of overdue requests" do chicken_request = info_requests(:naughty_chicken_request) - chicken_request.outgoing_messages[0].last_sent_at = Time.now() - 30.days + chicken_request.outgoing_messages[0].last_sent_at = Time.now - 30.days chicken_request.outgoing_messages[0].save! RequestMailer.alert_overdue_requests @@ -1941,7 +1941,7 @@ describe RequestController, "sending overdue request alerts" do it "should include clause for schools when sending an overdue alert mail to creators of overdue requests" do chicken_request = info_requests(:naughty_chicken_request) - chicken_request.outgoing_messages[0].last_sent_at = Time.now() - 30.days + chicken_request.outgoing_messages[0].last_sent_at = Time.now - 30.days chicken_request.outgoing_messages[0].save! chicken_request.public_body.tag_string = "school" @@ -1972,7 +1972,7 @@ describe RequestController, "sending overdue request alerts" do it "should send a very overdue alert mail to creators of very overdue requests" do chicken_request = info_requests(:naughty_chicken_request) - chicken_request.outgoing_messages[0].last_sent_at = Time.now() - 60.days + chicken_request.outgoing_messages[0].last_sent_at = Time.now - 60.days chicken_request.outgoing_messages[0].save! RequestMailer.alert_overdue_requests @@ -1998,7 +1998,7 @@ describe RequestController, "sending overdue request alerts" do it "should not resend alerts to people who've already received them" do chicken_request = info_requests(:naughty_chicken_request) - chicken_request.outgoing_messages[0].last_sent_at = Time.now() - 60.days + chicken_request.outgoing_messages[0].last_sent_at = Time.now - 60.days chicken_request.outgoing_messages[0].save! RequestMailer.alert_overdue_requests chicken_mails = ActionMailer::Base.deliveries.select{|x| x.body =~ /chickens/} @@ -2011,7 +2011,7 @@ describe RequestController, "sending overdue request alerts" do it 'should send alerts for requests where the last event forming the initial request is a followup being sent following a request for clarification' do chicken_request = info_requests(:naughty_chicken_request) - chicken_request.outgoing_messages[0].last_sent_at = Time.now() - 60.days + chicken_request.outgoing_messages[0].last_sent_at = Time.now - 60.days chicken_request.outgoing_messages[0].save! RequestMailer.alert_overdue_requests chicken_mails = ActionMailer::Base.deliveries.select{|x| x.body =~ /chickens/} @@ -2048,7 +2048,7 @@ describe RequestController, "sending overdue request alerts" do chicken_mails.size.should == 1 # Make the followup older - outgoing_message.last_sent_at = Time.now() - 60.days + outgoing_message.last_sent_at = Time.now - 60.days outgoing_message.save! # Now it should be alerted on @@ -2764,4 +2764,3 @@ describe RequestController, "#select_authorities" do end end - diff --git a/spec/controllers/request_game_controller_spec.rb b/spec/controllers/request_game_controller_spec.rb index 7247cd388..c3f00d58d 100644 --- a/spec/controllers/request_game_controller_spec.rb +++ b/spec/controllers/request_game_controller_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe RequestGameController, "when playing the game" do diff --git a/spec/controllers/services_controller_spec.rb b/spec/controllers/services_controller_spec.rb index 621dbaaac..6ab527bc9 100644 --- a/spec/controllers/services_controller_spec.rb +++ b/spec/controllers/services_controller_spec.rb @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') require 'fakeweb' @@ -9,7 +9,7 @@ describe ServicesController, "when returning a message for people in other count # store and restore the locale in the context of the test suite to isolate # changes made in these tests before do - @old_locale = FastGettext.locale() + @old_locale = FastGettext.locale end it 'keeps the flash' do @@ -21,7 +21,7 @@ describe ServicesController, "when returning a message for people in other count end it "should show no alaveteli message when in the deployed country" do - config = MySociety::Config.load_default() + config = MySociety::Config.load_default config['ISO_COUNTRY_CODE'] = "DE" controller.stub!(:country_from_ip).and_return('DE') get :other_country_message @@ -29,7 +29,7 @@ describe ServicesController, "when returning a message for people in other count end it "should show an alaveteli message when not in the deployed country and in a country with no FOI website" do - config = MySociety::Config.load_default() + config = MySociety::Config.load_default config['ISO_COUNTRY_CODE'] = "DE" controller.stub!(:country_from_ip).and_return('ZZ') get :other_country_message @@ -37,7 +37,7 @@ describe ServicesController, "when returning a message for people in other count end it "should show link to other FOI website when not in the deployed country" do - config = MySociety::Config.load_default() + config = MySociety::Config.load_default config['ISO_COUNTRY_CODE'] = "ZZ" controller.stub!(:country_from_ip).and_return('ES') request.env['HTTP_ACCEPT_LANGUAGE'] = "es" @@ -60,7 +60,7 @@ describe ServicesController, "when returning a message for people in other count end it "should return the 'another country' message if the service responds OK" do - config = MySociety::Config.load_default() + config = MySociety::Config.load_default config['ISO_COUNTRY_CODE'] = "DE" AlaveteliConfiguration.stub!(:gaze_url).and_return('http://denmark.com') FakeWeb.register_uri(:get, %r|denmark.com|, :body => "DK") diff --git a/spec/controllers/track_controller_spec.rb b/spec/controllers/track_controller_spec.rb index 29f5c7fe1..b453fde8c 100644 --- a/spec/controllers/track_controller_spec.rb +++ b/spec/controllers/track_controller_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe TrackController, "when making a new track on a request" do diff --git a/spec/controllers/user_controller_spec.rb b/spec/controllers/user_controller_spec.rb index 443856cf3..fb03615f8 100644 --- a/spec/controllers/user_controller_spec.rb +++ b/spec/controllers/user_controller_spec.rb @@ -1,4 +1,4 @@ -# coding: utf-8 +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe UserController do @@ -76,11 +76,11 @@ describe UserController, "when redirecting a show request to a canonical url" do end it 'should not redirect a long canonical name that has a numerical suffix' do - User.stub!(:find).with(:first, anything()).and_return(mock_model(User, + User.stub!(:find).with(:first, anything).and_return(mock_model(User, :url_name => 'bob_smithbob_smithbob_smithbob_s_2', :name => 'Bob Smith Bob Smith Bob Smith Bob Smith', :info_requests => [])) - User.stub!(:find).with(:all, anything()).and_return([]) + User.stub!(:find).with(:all, anything).and_return([]) get :show, :url_name => 'bob_smithbob_smithbob_smithbob_s_2' response.should be_success end diff --git a/spec/controllers/widgets_controller_spec.rb b/spec/controllers/widgets_controller_spec.rb new file mode 100644 index 000000000..95396671b --- /dev/null +++ b/spec/controllers/widgets_controller_spec.rb @@ -0,0 +1,181 @@ +# -*- encoding : utf-8 -*- +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe WidgetsController do + + include LinkToHelper + + describe "#show" do + + before do + @info_request = FactoryGirl.create(:info_request) + AlaveteliConfiguration.stub!(:enable_widgets).and_return(true) + end + + it 'should render the widget template' do + get :show, :request_id => @info_request.id + expect(response).to render_template('show') + end + + it 'should find the info request' do + get :show, :request_id => @info_request.id + assigns[:info_request].should == @info_request + end + + it 'should create a track thing for the request' do + get :show, :request_id => @info_request.id + assigns[:track_thing].info_request.should == @info_request + end + + it 'should assign the request status' do + get :show, :request_id => @info_request.id + assigns[:status].should == @info_request.calculate_status + end + + it 'should not send an x-frame-options header' do + get :show, :request_id => @info_request.id + response.headers["X-Frame-Options"].should be_nil + end + + context 'for a non-logged-in user' do + + context 'if no widget-vote cookie is set' do + + it 'should set a widget-vote cookie' do + cookies[:widget_vote].should be_nil + get :show, :request_id => @info_request.id + cookies[:widget_vote].should_not be_nil + end + + end + + end + + context 'when widgets are not enabled' do + + it 'should return a 404' do + AlaveteliConfiguration.stub!(:enable_widgets).and_return(false) + lambda{ get :show, :request_id => @info_request.id }.should + raise_error(ActiveRecord::RecordNotFound) + end + + end + + context "when the request's prominence is not 'normal'" do + + it 'should return a 403' do + @info_request.prominence = 'hidden' + @info_request.save! + get :show, :request_id => @info_request.id + response.code.should == "403" + end + + end + + end + + describe "#new" do + + before do + @info_request = FactoryGirl.create(:info_request) + AlaveteliConfiguration.stub!(:enable_widgets).and_return(true) + end + + it 'should render the create widget template' do + get :new, :request_id => @info_request.id + expect(response).to render_template('new') + end + + it 'should find the info request' do + get :new, :request_id => @info_request.id + assigns[:info_request].should == @info_request + end + + context 'when widgets are not enabled' do + + it 'should return a 404' do + AlaveteliConfiguration.stub!(:enable_widgets).and_return(false) + lambda{ get :new, :request_id => @info_request.id }.should + raise_error(ActiveRecord::RecordNotFound) + end + + end + + context "when the request's prominence is not 'normal'" do + + it 'should return a 403' do + @info_request.prominence = 'hidden' + @info_request.save! + get :show, :request_id => @info_request.id + response.code.should == "403" + end + + end + + end + + describe :update do + + before do + @info_request = FactoryGirl.create(:info_request) + AlaveteliConfiguration.stub!(:enable_widgets).and_return(true) + end + + it 'should find the info request' do + get :update, :request_id => @info_request.id + assigns[:info_request].should == @info_request + end + + it 'should redirect to the track path for the info request' do + get :update, :request_id => @info_request.id + track_thing = TrackThing.create_track_for_request(@info_request) + expect(response).to redirect_to(do_track_path(track_thing)) + end + + context 'when there is no logged-in user and a widget vote cookie' do + + before do + @cookie_value = 'x' * 20 + end + + it 'should create a widget vote if none exists for the info request and cookie' do + @info_request.widget_votes.where(:cookie => @cookie_value).size.should == 0 + request.cookies['widget_vote'] = @cookie_value + get :update, :request_id => @info_request.id + @info_request.widget_votes.where(:cookie => @cookie_value).size.should == 1 + end + + it 'should not create a widget vote if one exists for the info request and cookie' do + @info_request.widget_votes.create(:cookie => @cookie_value) + request.cookies['widget_vote'] = @cookie_value + get :update, :request_id => @info_request.id + @info_request.widget_votes.where(:cookie => @cookie_value).size.should == 1 + end + + end + + context 'when widgets are not enabled' do + + it 'should raise ActiveRecord::RecordNotFound' do + AlaveteliConfiguration.stub!(:enable_widgets).and_return(false) + lambda{ get :update, :request_id => @info_request.id }.should + raise_error(ActiveRecord::RecordNotFound) + end + + end + + context "when the request's prominence is not 'normal'" do + + it 'should return a 403' do + @info_request.prominence = 'hidden' + @info_request.save! + get :show, :request_id => @info_request.id + response.code.should == "403" + end + + end + + end + +end + diff --git a/spec/factories/censor_rules.rb b/spec/factories/censor_rules.rb index 2c0b2c822..5ae60b1f1 100644 --- a/spec/factories/censor_rules.rb +++ b/spec/factories/censor_rules.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- FactoryGirl.define do factory :censor_rule do diff --git a/spec/factories/comments.rb b/spec/factories/comments.rb index 1e0861dad..905d7580f 100644 --- a/spec/factories/comments.rb +++ b/spec/factories/comments.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- FactoryGirl.define do factory :comment do diff --git a/spec/factories/foi_attchments.rb b/spec/factories/foi_attchments.rb index a1d04ccf0..64486dcda 100644 --- a/spec/factories/foi_attchments.rb +++ b/spec/factories/foi_attchments.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- FactoryGirl.define do factory :foi_attachment do diff --git a/spec/factories/holidays.rb b/spec/factories/holidays.rb index 531130c8a..28bbe6c52 100644 --- a/spec/factories/holidays.rb +++ b/spec/factories/holidays.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- FactoryGirl.define do factory :holiday do diff --git a/spec/factories/incoming_messages.rb b/spec/factories/incoming_messages.rb index b29fe8ce9..127e0f94e 100644 --- a/spec/factories/incoming_messages.rb +++ b/spec/factories/incoming_messages.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- FactoryGirl.define do factory :incoming_message do diff --git a/spec/factories/info_request_batches.rb b/spec/factories/info_request_batches.rb index 960db6ec5..c92aa76cc 100644 --- a/spec/factories/info_request_batches.rb +++ b/spec/factories/info_request_batches.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- FactoryGirl.define do factory :info_request_batch do diff --git a/spec/factories/info_request_events.rb b/spec/factories/info_request_events.rb index cdd303ad6..d585049e7 100644 --- a/spec/factories/info_request_events.rb +++ b/spec/factories/info_request_events.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- FactoryGirl.define do factory :info_request_event do diff --git a/spec/factories/info_requests.rb b/spec/factories/info_requests.rb index 8052625cd..084712243 100644 --- a/spec/factories/info_requests.rb +++ b/spec/factories/info_requests.rb @@ -1,7 +1,8 @@ +# -*- encoding : utf-8 -*- FactoryGirl.define do factory :info_request do - title "Example Title" + sequence(:title) { |n| "Example Title #{n}" } public_body user diff --git a/spec/factories/outgoing_messages.rb b/spec/factories/outgoing_messages.rb index e11cbdfb9..6e88085b4 100644 --- a/spec/factories/outgoing_messages.rb +++ b/spec/factories/outgoing_messages.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- FactoryGirl.define do factory :outgoing_message do diff --git a/spec/factories/public_bodies.rb b/spec/factories/public_bodies.rb index 44769f7c2..a823d536a 100644 --- a/spec/factories/public_bodies.rb +++ b/spec/factories/public_bodies.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- FactoryGirl.define do factory :public_body do diff --git a/spec/factories/public_body_categories.rb b/spec/factories/public_body_categories.rb index baa474c6b..da7dec65c 100644 --- a/spec/factories/public_body_categories.rb +++ b/spec/factories/public_body_categories.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- FactoryGirl.define do factory :public_body_category do diff --git a/spec/factories/public_body_category_links.rb b/spec/factories/public_body_category_links.rb index 7663b1f52..7e796a08d 100644 --- a/spec/factories/public_body_category_links.rb +++ b/spec/factories/public_body_category_links.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- FactoryGirl.define do factory :public_body_category_link do association :public_body_category diff --git a/spec/factories/public_body_change_requests.rb b/spec/factories/public_body_change_requests.rb index 2bacb9b9b..a074c6feb 100644 --- a/spec/factories/public_body_change_requests.rb +++ b/spec/factories/public_body_change_requests.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- FactoryGirl.define do factory :public_body_change_request do diff --git a/spec/factories/public_body_headings.rb b/spec/factories/public_body_headings.rb index ed54ddada..b7f83ffda 100644 --- a/spec/factories/public_body_headings.rb +++ b/spec/factories/public_body_headings.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- FactoryGirl.define do factory :public_body_heading do sequence(:name) { |n| "Example Public Body Heading #{n}" } diff --git a/spec/factories/raw_emails.rb b/spec/factories/raw_emails.rb index b271515d2..a6e3c21ac 100644 --- a/spec/factories/raw_emails.rb +++ b/spec/factories/raw_emails.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- FactoryGirl.define do factory :raw_email end diff --git a/spec/factories/spam_addresses.rb b/spec/factories/spam_addresses.rb index bafb7cd50..6853c7f2e 100644 --- a/spec/factories/spam_addresses.rb +++ b/spec/factories/spam_addresses.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- FactoryGirl.define do factory :spam_address do sequence(:email) { |n| "spam-#{ n }@example.org" } diff --git a/spec/factories/track_things.rb b/spec/factories/track_things.rb index cf76b00b3..f8e4dce69 100644 --- a/spec/factories/track_things.rb +++ b/spec/factories/track_things.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- FactoryGirl.define do factory :track_thing do diff --git a/spec/factories/users.rb b/spec/factories/users.rb index ab782fbf7..1f7eba530 100644 --- a/spec/factories/users.rb +++ b/spec/factories/users.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- FactoryGirl.define do factory :user do diff --git a/spec/factories/widget_votes.rb b/spec/factories/widget_votes.rb new file mode 100644 index 000000000..7ceb4f7e9 --- /dev/null +++ b/spec/factories/widget_votes.rb @@ -0,0 +1,8 @@ +# -*- encoding : utf-8 -*- +require 'securerandom' +FactoryGirl.define do + factory :widget_vote do + info_request + cookie { SecureRandom.hex(10) } + end +end diff --git a/spec/fixtures/files/non-utf8-filename.email b/spec/fixtures/files/non-utf8-filename.email new file mode 100644 index 000000000..ed1f1a9f5 --- /dev/null +++ b/spec/fixtures/files/non-utf8-filename.email @@ -0,0 +1,52 @@ +From authority@example.org Tue Dec 3 11:13:02 2013 +Return-path: <authority@example.org> +Envelope-to: requester@example.org +Delivery-date: Tue, 03 Dec 2013 11:13:00 +0000 +From: Test Authority <authority@example.org> +To: requester@example.org +Subject: testing a PDF attachment with the wrong content-type +Date: Tue, 03 Dec 2013 11:12:45 +0000 +Message-ID: <87li09xuasdfasdfpoija@blahblah> +Content-Type: multipart/mixed; + boundary="_006_939C1F941DBEE94A9BEF493DF88519F71F13B5FCWDCEXMAIL02woki_" +MIME-Version: 1.0 +X-GlobalCerts-Milter: WDC-SECUREMAIL02.wokingham.gov.uk 13Feb2014-16:41:39.109 +X-Scanned-By: MailControl 26514.0 (www.mailcontrol.com) on 10.70.0.132 + +--_006_939C1F941DBEE94A9BEF493DF88519F71F13B5FCWDCEXMAIL02woki_ +Content-Type: multipart/alternative; + boundary="_000_939C1F941DBEE94A9BEF493DF88519F71F13B5FCWDCEXMAIL02woki_" + +--_000_939C1F941DBEE94A9BEF493DF88519F71F13B5FCWDCEXMAIL02woki_ +Content-Type: text/plain; charset="iso-8859-1" +Content-Transfer-Encoding: quoted-printable + +Some text + +--_000_939C1F941DBEE94A9BEF493DF88519F71F13B5FCWDCEXMAIL02woki_ +Content-Type: text/html; charset="iso-8859-1" +Content-Transfer-Encoding: quoted-printable + +Some html + +--_000_939C1F941DBEE94A9BEF493DF88519F71F13B5FCWDCEXMAIL02woki_-- + + +--_006_939C1F941DBEE94A9BEF493DF88519F71F13B5FCWDCEXMAIL02woki_ +Content-Type: application/vnd.ms-excel; + name="RV %A312000 or more.xls" +Content-Description: RV %A312000 or more.xls +Content-Disposition: attachment; creation-date="Thu, 13 Feb 2014 16:36:59 GMT"; filename="RV %A312000 or more.xls"; modification-date="Thu, 13 Feb 2014 16:41:36 GMT"; size="332288" +Content-Transfer-Encoding: base64 + +some base 64as;dm mklasd + +--_006_939C1F941DBEE94A9BEF493DF88519F71F13B5FCWDCEXMAIL02woki_ +Content-Type: application/vnd.ms-excel; name="other.xls" +Content-Description: other.xls +Content-Disposition: attachment; creation-date="Thu, 13 Feb 2014 16:37:02 GMT"; filename="other.xls"; modification-date="Thu, 13 Feb 2014 16:41:36 GMT"; size="33280" +Content-Transfer-Encoding: base64 + +some base 64 + +--_006_939C1F941DBEE94A9BEF493DF88519F71F13B5FCWDCEXMAIL02woki_--
\ No newline at end of file diff --git a/spec/helpers/admin_helper_spec.rb b/spec/helpers/admin_helper_spec.rb index 804fcc7fd..1f0155c98 100644 --- a/spec/helpers/admin_helper_spec.rb +++ b/spec/helpers/admin_helper_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe AdminHelper do diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index 6407eaf3a..2035c343a 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe ApplicationHelper do diff --git a/spec/helpers/date_time_helper_spec.rb b/spec/helpers/date_time_helper_spec.rb index c4fdee1d1..f69a0ef80 100644 --- a/spec/helpers/date_time_helper_spec.rb +++ b/spec/helpers/date_time_helper_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe DateTimeHelper do diff --git a/spec/helpers/health_checks_helper_spec.rb b/spec/helpers/health_checks_helper_spec.rb index 7d4083da5..9418864b5 100644 --- a/spec/helpers/health_checks_helper_spec.rb +++ b/spec/helpers/health_checks_helper_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe HealthChecksHelper do @@ -10,6 +11,11 @@ describe HealthChecksHelper do expect(check_status(check)).to include('red') end + it 'sets style to a blank string if ok' do + check = double(:message => '', :ok? => true) + expect(check_status(check)).to include('style=""') + end + end end diff --git a/spec/helpers/highlight_helper_spec.rb b/spec/helpers/highlight_helper_spec.rb index e1be7e153..2641a4400 100644 --- a/spec/helpers/highlight_helper_spec.rb +++ b/spec/helpers/highlight_helper_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe HighlightHelper do diff --git a/spec/helpers/link_to_helper_spec.rb b/spec/helpers/link_to_helper_spec.rb index 261e1ef3e..fbb0c2313 100644 --- a/spec/helpers/link_to_helper_spec.rb +++ b/spec/helpers/link_to_helper_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe LinkToHelper do diff --git a/spec/helpers/public_body_helper_spec.rb b/spec/helpers/public_body_helper_spec.rb index d4f3acf78..8db07b979 100644 --- a/spec/helpers/public_body_helper_spec.rb +++ b/spec/helpers/public_body_helper_spec.rb @@ -1,4 +1,4 @@ -# encoding: UTF-8 +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe PublicBodyHelper do diff --git a/spec/helpers/track_helper_spec.rb b/spec/helpers/track_helper_spec.rb index b6252ab39..bc1266338 100644 --- a/spec/helpers/track_helper_spec.rb +++ b/spec/helpers/track_helper_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe TrackHelper do diff --git a/spec/helpers/widget_helper_spec.rb b/spec/helpers/widget_helper_spec.rb new file mode 100644 index 000000000..614ed92ad --- /dev/null +++ b/spec/helpers/widget_helper_spec.rb @@ -0,0 +1,29 @@ +# -*- encoding : utf-8 -*- +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe WidgetHelper do + + include WidgetHelper + + describe :status_description do + + before do + @info_request = FactoryGirl.build(:info_request) + end + + it 'should return "Awaiting classification" for "waiting_classification' do + expect(status_description(@info_request, 'waiting_classification')).to eq('Awaiting classification') + end + + it 'should call theme_display_status for a theme status' do + @info_request.stub!(:theme_display_status).and_return("Special status") + expect(status_description(@info_request, 'special_status')).to eq('Special status') + end + + it 'should return unknown for an unknown status' do + expect(status_description(@info_request, 'special_status')).to eq('Unknown') + end + + end + +end diff --git a/spec/integration/admin_public_body_category_edit_spec.rb b/spec/integration/admin_public_body_category_edit_spec.rb index 043524189..4e210de82 100644 --- a/spec/integration/admin_public_body_category_edit_spec.rb +++ b/spec/integration/admin_public_body_category_edit_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') require File.expand_path(File.dirname(__FILE__) + '/alaveteli_dsl') diff --git a/spec/integration/admin_public_body_edit_spec.rb b/spec/integration/admin_public_body_edit_spec.rb index aeec3e65a..ed51f414b 100644 --- a/spec/integration/admin_public_body_edit_spec.rb +++ b/spec/integration/admin_public_body_edit_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') require File.expand_path(File.dirname(__FILE__) + '/alaveteli_dsl') @@ -39,7 +40,7 @@ describe 'Editing a Public Body' do end end - it 'can add a translation for multiple locales', :focus => true do + it 'can add a translation for multiple locales' do @admin.visit edit_admin_body_path(@body) @admin.fill_in 'public_body_name__en', :with => 'New Quango EN' @admin.click_button 'Save' diff --git a/spec/integration/admin_public_body_heading_edit_spec.rb b/spec/integration/admin_public_body_heading_edit_spec.rb index 6c7a5a74b..f37d033f3 100644 --- a/spec/integration/admin_public_body_heading_edit_spec.rb +++ b/spec/integration/admin_public_body_heading_edit_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') require File.expand_path(File.dirname(__FILE__) + '/alaveteli_dsl') diff --git a/spec/integration/admin_spec.rb b/spec/integration/admin_spec.rb index bdd6e9d8c..552b465bd 100644 --- a/spec/integration/admin_spec.rb +++ b/spec/integration/admin_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') require File.expand_path(File.dirname(__FILE__) + '/alaveteli_dsl') diff --git a/spec/integration/alaveteli_dsl.rb b/spec/integration/alaveteli_dsl.rb index d7485a094..1ff60664c 100644 --- a/spec/integration/alaveteli_dsl.rb +++ b/spec/integration/alaveteli_dsl.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- module AlaveteliDsl def browses_request(url_title) diff --git a/spec/integration/cookie_stripping_spec.rb b/spec/integration/cookie_stripping_spec.rb index 897899fd5..e28e7b8e4 100644 --- a/spec/integration/cookie_stripping_spec.rb +++ b/spec/integration/cookie_stripping_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') require File.expand_path(File.dirname(__FILE__) + '/alaveteli_dsl') diff --git a/spec/integration/create_request_spec.rb b/spec/integration/create_request_spec.rb index 84fad12f9..9b579c448 100644 --- a/spec/integration/create_request_spec.rb +++ b/spec/integration/create_request_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') require File.expand_path(File.dirname(__FILE__) + '/alaveteli_dsl') diff --git a/spec/integration/download_request_spec.rb b/spec/integration/download_request_spec.rb index 48b42b11d..1050e6792 100644 --- a/spec/integration/download_request_spec.rb +++ b/spec/integration/download_request_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') require File.expand_path(File.dirname(__FILE__) + '/alaveteli_dsl') @@ -143,7 +144,8 @@ describe 'when making a zipfile available' do it "should update the contents of the zipfile when the request changes" do - info_request = FactoryGirl.create(:info_request_with_incoming) + info_request = FactoryGirl.create(:info_request_with_incoming, + :title => 'Example Title') request_owner = login(info_request.user) inspect_zip_download(request_owner, info_request) do |zip| zip.count.should == 1 # just the message diff --git a/spec/integration/errors_spec.rb b/spec/integration/errors_spec.rb index 39f1279ce..64145cce0 100644 --- a/spec/integration/errors_spec.rb +++ b/spec/integration/errors_spec.rb @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe "When errors occur" do diff --git a/spec/integration/ip_spoofing_spec.rb b/spec/integration/ip_spoofing_spec.rb index 073f71ad6..ce11bcf0b 100644 --- a/spec/integration/ip_spoofing_spec.rb +++ b/spec/integration/ip_spoofing_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe 'when getting a country message' do diff --git a/spec/integration/localisation_spec.rb b/spec/integration/localisation_spec.rb index 037603ad5..f96cd4c3a 100644 --- a/spec/integration/localisation_spec.rb +++ b/spec/integration/localisation_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe "when generating urls" do diff --git a/spec/integration/request_controller_spec.rb b/spec/integration/request_controller_spec.rb index f5de692b8..1ef6814f9 100644 --- a/spec/integration/request_controller_spec.rb +++ b/spec/integration/request_controller_spec.rb @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') require File.expand_path(File.dirname(__FILE__) + '/alaveteli_dsl') diff --git a/spec/integration/search_request_spec.rb b/spec/integration/search_request_spec.rb index 699eb2c6c..7a09c78fb 100644 --- a/spec/integration/search_request_spec.rb +++ b/spec/integration/search_request_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') require File.expand_path(File.dirname(__FILE__) + '/alaveteli_dsl') diff --git a/spec/integration/view_request_spec.rb b/spec/integration/view_request_spec.rb index 4d04c97d7..ed84ec2e2 100644 --- a/spec/integration/view_request_spec.rb +++ b/spec/integration/view_request_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') require File.expand_path(File.dirname(__FILE__) + '/alaveteli_dsl') diff --git a/spec/integration/xapian_search_highlighting_spec.rb b/spec/integration/xapian_search_highlighting_spec.rb index c0834a2c1..eea9893a8 100644 --- a/spec/integration/xapian_search_highlighting_spec.rb +++ b/spec/integration/xapian_search_highlighting_spec.rb @@ -1,10 +1,14 @@ -# encoding: utf-8 +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe 'highlighting search results' do include HighlightHelper + before do + get_fixtures_xapian_index + end + it 'ignores stopwords' do phrase = 'department of humpadinking' search = ActsAsXapian::Search.new([PublicBody], phrase, :limit => 1) diff --git a/spec/lib/ability_spec.rb b/spec/lib/ability_spec.rb index f075d0f32..4c5d50990 100644 --- a/spec/lib/ability_spec.rb +++ b/spec/lib/ability_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe Ability do diff --git a/spec/lib/alaveteli_external_command_spec.rb b/spec/lib/alaveteli_external_command_spec.rb index 18afeda33..f76e26152 100644 --- a/spec/lib/alaveteli_external_command_spec.rb +++ b/spec/lib/alaveteli_external_command_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') require 'alaveteli_external_command' diff --git a/spec/lib/alaveteli_text_masker_spec.rb b/spec/lib/alaveteli_text_masker_spec.rb index 1a4782a83..f2d52c1cc 100644 --- a/spec/lib/alaveteli_text_masker_spec.rb +++ b/spec/lib/alaveteli_text_masker_spec.rb @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe AlaveteliTextMasker do @@ -60,7 +60,7 @@ describe AlaveteliTextMasker do end def pdf_replacement_test(use_ghostscript_compression) - config = MySociety::Config.load_default() + config = MySociety::Config.load_default previous = config['USE_GHOSTSCRIPT_COMPRESSION'] config['USE_GHOSTSCRIPT_COMPRESSION'] = use_ghostscript_compression orig_pdf = load_file_fixture('tfl.pdf') @@ -92,6 +92,23 @@ describe AlaveteliTextMasker do pdf.should_not == "" end + it 'should keep the uncensored original if uncompression of a PDF fails' do + orig_pdf = load_file_fixture('tfl.pdf') + pdf = orig_pdf.dup + stub!(:uncompress_pdf).and_return nil + apply_masks!(pdf, "application/pdf") + pdf.should == orig_pdf + end + + it 'should use the uncompressed PDF text if re-compression of a compressed PDF fails' do + orig_pdf = load_file_fixture('tfl.pdf') + pdf = orig_pdf.dup + stub!(:uncompress_pdf).and_return "something about foi@tfl.gov.uk" + stub!(:compress_pdf).and_return nil + apply_masks!(pdf, "application/pdf") + pdf.should match "something about xxx@xxx.xxx.xx" + end + it "should apply hard-coded privacy rules to HTML files" do data = "http://test.host/c/cheese" apply_masks!(data, 'text/html') diff --git a/spec/lib/attachment_to_html/adapters/could_not_convert_spec.rb b/spec/lib/attachment_to_html/adapters/could_not_convert_spec.rb index afdc5c552..040f02bae 100644 --- a/spec/lib/attachment_to_html/adapters/could_not_convert_spec.rb +++ b/spec/lib/attachment_to_html/adapters/could_not_convert_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') describe AttachmentToHTML::Adapters::CouldNotConvert do diff --git a/spec/lib/attachment_to_html/adapters/google_docs_viewer_spec.rb b/spec/lib/attachment_to_html/adapters/google_docs_viewer_spec.rb index e7aafb40d..b1a97ea9b 100644 --- a/spec/lib/attachment_to_html/adapters/google_docs_viewer_spec.rb +++ b/spec/lib/attachment_to_html/adapters/google_docs_viewer_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') describe AttachmentToHTML::Adapters::GoogleDocsViewer do diff --git a/spec/lib/attachment_to_html/adapters/pdf_spec.rb b/spec/lib/attachment_to_html/adapters/pdf_spec.rb index ceb438be8..f4b60fb93 100644 --- a/spec/lib/attachment_to_html/adapters/pdf_spec.rb +++ b/spec/lib/attachment_to_html/adapters/pdf_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') describe AttachmentToHTML::Adapters::PDF do diff --git a/spec/lib/attachment_to_html/adapters/rtf_spec.rb b/spec/lib/attachment_to_html/adapters/rtf_spec.rb index 2c53b5272..59aef69d1 100644 --- a/spec/lib/attachment_to_html/adapters/rtf_spec.rb +++ b/spec/lib/attachment_to_html/adapters/rtf_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') describe AttachmentToHTML::Adapters::RTF do diff --git a/spec/lib/attachment_to_html/adapters/text_spec.rb b/spec/lib/attachment_to_html/adapters/text_spec.rb index b2e8141e0..0eddacb05 100644 --- a/spec/lib/attachment_to_html/adapters/text_spec.rb +++ b/spec/lib/attachment_to_html/adapters/text_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') describe AttachmentToHTML::Adapters::Text do diff --git a/spec/lib/attachment_to_html/attachment_to_html_spec.rb b/spec/lib/attachment_to_html/attachment_to_html_spec.rb index 1cf7debb7..59c13f501 100644 --- a/spec/lib/attachment_to_html/attachment_to_html_spec.rb +++ b/spec/lib/attachment_to_html/attachment_to_html_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') describe AttachmentToHTML do diff --git a/spec/lib/attachment_to_html/view_spec.rb b/spec/lib/attachment_to_html/view_spec.rb index 50179b0f7..ffe2c0d2d 100644 --- a/spec/lib/attachment_to_html/view_spec.rb +++ b/spec/lib/attachment_to_html/view_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') describe AttachmentToHTML::View do diff --git a/spec/lib/basic_encoding_spec.rb b/spec/lib/basic_encoding_spec.rb index 43a65eab9..d77465ad8 100644 --- a/spec/lib/basic_encoding_spec.rb +++ b/spec/lib/basic_encoding_spec.rb @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') def bytes_to_binary_string( bytes, claimed_encoding = nil ) @@ -103,7 +103,7 @@ end describe "convert_string_to_utf8_or_binary" do - describe "when passed uniterpretable character data" do + describe "when passed uninterpretable character data" do it "should return it as a binary string" do @@ -155,3 +155,58 @@ describe "convert_string_to_utf8_or_binary" do end end + +describe "convert_string_to_utf8" do + + describe "when passed uninterpretable character data" do + + it "should return it as a utf8 string" do + + converted = convert_string_to_utf8 random_string + converted.should == random_string + + if String.method_defined?(:encode) + converted.encoding.to_s.should == 'UTF-8' + end + + converted = convert_string_to_utf8 random_string,'UTF-8' + converted.should == random_string + + if String.method_defined?(:encode) + converted.encoding.to_s.should == 'UTF-8' + end + + end + end + + describe "when passed unlabelled Windows 1252 data" do + + it "should correctly convert it to UTF-8" do + + converted = convert_string_to_utf8 windows_1252_string + + converted.should == "DASH – DASH" + + if String.method_defined?(:encode) + converted.encoding.to_s.should == 'UTF-8' + end + end + + end + + describe "when passed GB 18030 data" do + + it "should correctly convert it to UTF-8 if unlabelled" do + + converted = convert_string_to_utf8 gb_18030_spam_string + + converted.should start_with("贵公司负责人") + + if String.method_defined?(:encode) + converted.encoding.to_s.should == 'UTF-8' + end + end + + end + +end
\ No newline at end of file diff --git a/spec/lib/confidence_intervals_spec.rb b/spec/lib/confidence_intervals_spec.rb index cb8717f3d..58f1f3d79 100644 --- a/spec/lib/confidence_intervals_spec.rb +++ b/spec/lib/confidence_intervals_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require 'confidence_intervals' describe "ci_bounds" do diff --git a/spec/lib/date_quarter_spec.rb b/spec/lib/date_quarter_spec.rb index 5af6fa334..02d2c2551 100644 --- a/spec/lib/date_quarter_spec.rb +++ b/spec/lib/date_quarter_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe DateQuarter do diff --git a/spec/lib/health_checks/checks/days_ago_check_spec.rb b/spec/lib/health_checks/checks/days_ago_check_spec.rb index 33b4642cd..4fbc1913b 100644 --- a/spec/lib/health_checks/checks/days_ago_check_spec.rb +++ b/spec/lib/health_checks/checks/days_ago_check_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') describe HealthChecks::Checks::DaysAgoCheck do @@ -15,16 +16,16 @@ describe HealthChecks::Checks::DaysAgoCheck do expect(check.days).to eq(4) end - describe :check do + describe :ok? do it 'is successful if the subject is in the last day' do check = HealthChecks::Checks::DaysAgoCheck.new { Time.now } - expect(check.check).to be_true + expect(check.ok?).to be_true end it 'fails if the subject is over a day ago' do check = HealthChecks::Checks::DaysAgoCheck.new { 2.days.ago } - expect(check.check).to be_false + expect(check.ok?).to be_false end end diff --git a/spec/lib/health_checks/health_checkable_spec.rb b/spec/lib/health_checks/health_checkable_spec.rb index abfeb5c21..59d76c337 100644 --- a/spec/lib/health_checks/health_checkable_spec.rb +++ b/spec/lib/health_checks/health_checkable_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') describe HealthChecks::HealthCheckable do @@ -31,24 +32,10 @@ describe HealthChecks::HealthCheckable do end - describe :check do - - it 'is intended to be overridden by the includer' do - expect{ @subject.check }.to raise_error(NotImplementedError) - end - - end - describe :ok? do - it 'returns true if the check was successful' do - @subject.stub(:check => true) - expect(@subject.ok?).to be_true - end - - it 'returns false if the check failed' do - @subject.stub(:check => false) - expect(@subject.ok?).to be_false + it 'is intended to be overridden by the includer' do + expect{ @subject.ok? }.to raise_error(NotImplementedError) end end @@ -92,7 +79,7 @@ describe HealthChecks::HealthCheckable do context 'if the check succeeds' do before(:each) do - @subject.stub(:check => true) + @subject.stub(:ok? => true) end it 'returns the default success message' do @@ -109,7 +96,7 @@ describe HealthChecks::HealthCheckable do context 'if the check fails' do before(:each) do - @subject.stub(:check => false) + @subject.stub(:ok? => false) end it 'returns the default failure message' do diff --git a/spec/lib/health_checks/health_checks_spec.rb b/spec/lib/health_checks/health_checks_spec.rb index c7037b813..0b97725db 100644 --- a/spec/lib/health_checks/health_checks_spec.rb +++ b/spec/lib/health_checks/health_checks_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') describe HealthChecks do @@ -6,7 +7,7 @@ describe HealthChecks do describe :add do it 'adds a check to the collection and returns the check' do - check = double('MockCheck', :check => true) + check = double('MockCheck', :ok? => true) expect(add(check)).to eq(check) end @@ -20,8 +21,8 @@ describe HealthChecks do describe :all do it 'returns all the checks' do - check1 = double('MockCheck', :check => true) - check2 = double('AnotherCheck', :check => false) + check1 = double('MockCheck', :ok? => true) + check2 = double('AnotherCheck', :ok? => false) add(check1) add(check2) expect(all).to include(check1, check2) diff --git a/spec/lib/i18n_interpolation_spec.rb b/spec/lib/i18n_interpolation_spec.rb index 47037ecdb..8c5b8d1b5 100644 --- a/spec/lib/i18n_interpolation_spec.rb +++ b/spec/lib/i18n_interpolation_spec.rb @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe "when using i18n" do @@ -58,7 +58,7 @@ describe "gettext_interpolate" do result = gettext_interpolate(string, :a => "foo".html_safe) result.should == "Hello foo" result.should_not be_html_safe - end + end end context "html safe string" do @@ -74,6 +74,6 @@ describe "gettext_interpolate" do result = gettext_interpolate(string, :a => "foo&".html_safe) result.should == "Hello foo&" result.should be_html_safe - end + end end end diff --git a/spec/lib/languages_spec.rb b/spec/lib/languages_spec.rb new file mode 100644 index 000000000..38f611087 --- /dev/null +++ b/spec/lib/languages_spec.rb @@ -0,0 +1,22 @@ +# -*- encoding : utf-8 -*- +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe LanguageNames do + + describe :get_language_name do + + it 'should return the name assigned to the language' do + LanguageNames.get_language_name('en').should == 'English' + end + + it 'should return the name assigned to the language when there is no specific location' do + LanguageNames.get_language_name('pt_BR').should == 'Português' + end + + it 'should return the name assigned to the language/location combination' do + LanguageNames.get_language_name('zh_HK').should == '中文(香港)' + end + + end + +end diff --git a/spec/lib/mail_handler/backends/mail_backend_spec.rb b/spec/lib/mail_handler/backends/mail_backend_spec.rb index eb1d4b167..91d9e1b5a 100644 --- a/spec/lib/mail_handler/backends/mail_backend_spec.rb +++ b/spec/lib/mail_handler/backends/mail_backend_spec.rb @@ -1,4 +1,4 @@ -# coding: utf-8 +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '../../../../spec_helper') describe MailHandler::Backends::MailBackend do @@ -37,6 +37,15 @@ describe MailHandler::Backends::MailBackend do get_part_file_name(part).should be_nil end + it 'turns an invalid UTF-8 name into a valid one' do + mail = get_fixture_mail('non-utf8-filename.email') + part = mail.attachments.first + filename = get_part_file_name(part) + if filename.respond_to?(:valid_encoding) + filename.valid_encoding?.should == true + end + end + end describe :get_part_body do diff --git a/spec/lib/mail_handler/mail_handler_spec.rb b/spec/lib/mail_handler/mail_handler_spec.rb index be6da5c4f..27a7a3db4 100644 --- a/spec/lib/mail_handler/mail_handler_spec.rb +++ b/spec/lib/mail_handler/mail_handler_spec.rb @@ -1,4 +1,4 @@ -# coding: utf-8 +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '../../../spec_helper') def create_message_from(from_field) @@ -9,7 +9,7 @@ end describe 'when creating a mail object from raw data' do - it "should be able to parse a large email without raising an exception", :focus => true do + it "should be able to parse a large email without raising an exception" do m = Mail.new m.add_file(:filename => "attachment.data", :content => "a" * (8 * 1024 * 1024)) raw_email = "From jamis_buck@byu.edu Mon May 2 16:07:05 2005\r\n#{m.to_s}" @@ -22,7 +22,7 @@ describe 'when creating a mail object from raw data' do mail.multipart?.should == true end - it "should not fail on invalid byte sequence in content-disposition header", :focus => true do + it "should not fail on invalid byte sequence in content-disposition header" do part = Mail::Part.new("Content-Disposition: inline; filename=a\xB8z\r\n\r\nThis is the body text.") lambda { part.inline? }.should_not raise_error end diff --git a/spec/lib/public_body_csv_spec.rb b/spec/lib/public_body_csv_spec.rb index e3cc4be6e..5c57c9533 100644 --- a/spec/lib/public_body_csv_spec.rb +++ b/spec/lib/public_body_csv_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe PublicBodyCSV do diff --git a/spec/lib/theme_spec.rb b/spec/lib/theme_spec.rb index 829c1a269..b7259078f 100644 --- a/spec/lib/theme_spec.rb +++ b/spec/lib/theme_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe "theme_url_to_theme_name" do diff --git a/spec/lib/timezone_fixes_spec.rb b/spec/lib/timezone_fixes_spec.rb index 8a9a3bf31..c44479fd7 100644 --- a/spec/lib/timezone_fixes_spec.rb +++ b/spec/lib/timezone_fixes_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # This is a test of the monkey patches in timezone_fixes.rb # We use MailServerLogDone here just as a totally random model that has a datetime type. diff --git a/spec/lib/whatdotheyknow/strip_empty_sessions_spec.rb b/spec/lib/whatdotheyknow/strip_empty_sessions_spec.rb index fcd729b48..d4f668671 100644 --- a/spec/lib/whatdotheyknow/strip_empty_sessions_spec.rb +++ b/spec/lib/whatdotheyknow/strip_empty_sessions_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') describe WhatDoTheyKnow::StripEmptySessions do diff --git a/spec/mailers/application_mailer_spec.rb b/spec/mailers/application_mailer_spec.rb index 718ac47fb..1854e4741 100644 --- a/spec/mailers/application_mailer_spec.rb +++ b/spec/mailers/application_mailer_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') @@ -13,7 +14,7 @@ describe ApplicationMailer do end def add_mail_methods(method_names) - method_names.each{ |method_name| ApplicationMailer.send(:define_method, method_name){ mail() } } + method_names.each{ |method_name| ApplicationMailer.send(:define_method, method_name){ mail } } end def remove_mail_methods(method_names) diff --git a/spec/mailers/info_request_batch_mailer_spec.rb b/spec/mailers/info_request_batch_mailer_spec.rb index 19791e163..146735e73 100644 --- a/spec/mailers/info_request_batch_mailer_spec.rb +++ b/spec/mailers/info_request_batch_mailer_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe InfoRequestBatchMailer do diff --git a/spec/mailers/outgoing_mailer_spec.rb b/spec/mailers/outgoing_mailer_spec.rb index 3df5018fe..d2bdc49dd 100644 --- a/spec/mailers/outgoing_mailer_spec.rb +++ b/spec/mailers/outgoing_mailer_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe OutgoingMailer, " when working out follow up names and addresses" do diff --git a/spec/mailers/request_mailer_spec.rb b/spec/mailers/request_mailer_spec.rb index 6a45d0e94..12d83ca62 100644 --- a/spec/mailers/request_mailer_spec.rb +++ b/spec/mailers/request_mailer_spec.rb @@ -1,6 +1,8 @@ -# encoding: utf-8 +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') +# TODO: Combine all these separate "describe" blocks to tidy things up + describe RequestMailer, " when receiving incoming mail" do before(:each) do load_raw_emails_data @@ -299,7 +301,7 @@ describe RequestMailer, "when sending reminders to requesters to classify a resp ORDER BY created_at desc LIMIT 1) < ? AND url_title != 'holding_pen' AND user_id IS NOT NULL".split(' ').join(' '), - true, Time.now() - 7.days ] + true, Time.now - 7.days ] # compare the query string ignoring any spacing differences InfoRequest.should_receive(:find) do |all, query_params| @@ -432,6 +434,10 @@ describe RequestMailer, 'when sending a new response email' do @mail = RequestMailer.new_response(@info_request, @incoming_message) end + it 'should not create HTML entities in the subject line' do + mail = RequestMailer.new_response(FactoryGirl.create(:info_request, :title => "Here's a request"), FactoryGirl.create(:incoming_message)) + expect(mail.subject).to eq "New response to your FOI request - Here's a request" + end end describe RequestMailer, 'requires_admin' do @@ -440,7 +446,7 @@ describe RequestMailer, 'requires_admin' do :name => 'Bruce Jones') @info_request = mock_model(InfoRequest, :user => user, :described_state => 'error_message', - :title => 'Test request', + :title => "It's a Test request", :url_title => 'test_request', :law_used_short => 'FOI', :id => 123) @@ -456,4 +462,42 @@ describe RequestMailer, 'requires_admin' do mail.body.should include 'Something has gone wrong' end + it 'should not create HTML entities in the subject line' do + expect(RequestMailer.requires_admin(@info_request).subject).to eq "FOI response requires admin (error_message) - It's a Test request" + end +end + +describe RequestMailer, "overdue_alert" do + it 'should not create HTML entities in the subject line' do + mail = RequestMailer.overdue_alert(FactoryGirl.create(:info_request, :title => "Here's a request"), FactoryGirl.create(:user)) + expect(mail.subject).to eq "Delayed response to your FOI request - Here's a request" + end +end + +describe RequestMailer, "very_overdue_alert" do + it 'should not create HTML entities in the subject line' do + mail = RequestMailer.very_overdue_alert(FactoryGirl.create(:info_request, :title => "Here's a request"), FactoryGirl.create(:user)) + expect(mail.subject).to eq "You're long overdue a response to your FOI request - Here's a request" + end +end + +describe RequestMailer, "not_clarified_alert" do + it 'should not create HTML entities in the subject line' do + mail = RequestMailer.not_clarified_alert(FactoryGirl.create(:info_request, :title => "Here's a request"), FactoryGirl.create(:incoming_message)) + expect(mail.subject).to eq "Clarify your FOI request - Here's a request" + end +end + +describe RequestMailer, "comment_on_alert" do + it 'should not create HTML entities in the subject line' do + mail = RequestMailer.comment_on_alert(FactoryGirl.create(:info_request, :title => "Here's a request"), FactoryGirl.create(:comment)) + expect(mail.subject).to eq "Somebody added a note to your FOI request - Here's a request" + end +end + +describe RequestMailer, "comment_on_alert_plural" do + it 'should not create HTML entities in the subject line' do + mail = RequestMailer.comment_on_alert_plural(FactoryGirl.create(:info_request, :title => "Here's a request"), 2, FactoryGirl.create(:comment)) + expect(mail.subject).to eq "Some notes have been added to your FOI request - Here's a request" + end end diff --git a/spec/mailers/track_mailer_spec.rb b/spec/mailers/track_mailer_spec.rb index e8094b692..56e0c18f6 100644 --- a/spec/mailers/track_mailer_spec.rb +++ b/spec/mailers/track_mailer_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe TrackMailer do diff --git a/spec/models/about_me_validator_spec.rb b/spec/models/about_me_validator_spec.rb index 5610cead8..c8078f44a 100644 --- a/spec/models/about_me_validator_spec.rb +++ b/spec/models/about_me_validator_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe AboutMeValidator do diff --git a/spec/models/censor_rule_spec.rb b/spec/models/censor_rule_spec.rb index 4ecd2d3e1..314b060d2 100644 --- a/spec/models/censor_rule_spec.rb +++ b/spec/models/censor_rule_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: censor_rules @@ -17,6 +18,42 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') +describe CensorRule do + + describe :apply_to_text do + + it 'applies the rule to the text' do + rule = FactoryGirl.build(:censor_rule, :text => 'secret') + text = 'Some secret text' + expect(rule.apply_to_text(text)).to eq('Some [REDACTED] text') + end + + it 'does not mutate the input' do + rule = FactoryGirl.build(:censor_rule, :text => 'secret') + text = 'Some secret text' + rule.apply_to_text(text) + expect(text).to eq('Some secret text') + end + + it 'returns the text if the rule is unmatched' do + rule = FactoryGirl.build(:censor_rule, :text => 'secret') + text = 'Some text' + expect(rule.apply_to_text(text)).to eq('Some text') + end + end + + describe :apply_to_text! do + + it 'mutates the input' do + rule = FactoryGirl.build(:censor_rule, :text => 'secret') + text = 'Some secret text' + rule.apply_to_text!(text) + expect(text).to eq('Some [REDACTED] text') + end + + end +end + describe CensorRule, "substituting things" do describe 'when using a text rule' do diff --git a/spec/models/change_email_validator_spec.rb b/spec/models/change_email_validator_spec.rb index b667a23d1..efa8ca819 100644 --- a/spec/models/change_email_validator_spec.rb +++ b/spec/models/change_email_validator_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') def validator_with_user_and_params(user, params = {}) diff --git a/spec/models/contact_validator_spec.rb b/spec/models/contact_validator_spec.rb index 0f5403967..9d7c192a3 100644 --- a/spec/models/contact_validator_spec.rb +++ b/spec/models/contact_validator_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe ContactValidator do diff --git a/spec/models/customstates.rb b/spec/models/customstates.rb index 942e1fcde..453453f20 100644 --- a/spec/models/customstates.rb +++ b/spec/models/customstates.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- module InfoRequestCustomStates def self.included(base) diff --git a/spec/models/foi_attachment_spec.rb b/spec/models/foi_attachment_spec.rb index 882723d1e..9583f4c76 100644 --- a/spec/models/foi_attachment_spec.rb +++ b/spec/models/foi_attachment_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: foi_attachments @@ -17,45 +18,59 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe FoiAttachment do - before(:each) do - load_raw_emails_data - end + describe :body= do + + it "sets the body" do + attachment = FoiAttachment.new + attachment.body = "baz" + attachment.body.should == "baz" + end + + it "sets the size" do + attachment = FoiAttachment.new + attachment.body = "baz" + attachment.body.should == "baz" + attachment.display_size.should == "0K" + end + + it "reparses the body if it disappears" do + load_raw_emails_data + im = incoming_messages(:useless_incoming_message) + im.extract_attachments! + main = im.get_main_body_text_part + orig_body = main.body + main.delete_cached_file! + lambda { + im.get_main_body_text_part.body + }.should_not raise_error(Errno::ENOENT) + main.delete_cached_file! + main = im.get_main_body_text_part + main.body.should == orig_body + end - it "sets the body" do - attachment = FoiAttachment.new - attachment.body = "baz" - attachment.body.should == "baz" - end - it "sets the size" do - attachment = FoiAttachment.new - attachment.body = "baz" - attachment.body.should == "baz" - attachment.update_display_size! - attachment.display_size.should == "0K" end - it "reparses the body if it disappears" do - im = incoming_messages(:useless_incoming_message) - im.extract_attachments! - main = im.get_main_body_text_part - orig_body = main.body - main.delete_cached_file! - lambda { - im.get_main_body_text_part.body - }.should_not raise_error(Errno::ENOENT) - main.delete_cached_file! - main = im.get_main_body_text_part - main.body.should == orig_body + + describe :ensure_filename! do + + it 'should create a filename for an instance with a blank filename' do + attachment = FoiAttachment.new + attachment.filename = '' + attachment.ensure_filename! + attachment.filename.should == 'attachment.bin' + end end -end -describe FoiAttachment, "when ensuring a filename is present" do + describe :has_body_as_html? do + + it 'should be true for a pdf attachment' do + FactoryGirl.build(:pdf_attachment).has_body_as_html?.should be_true + end + + it 'should be false for an html attachment' do + FactoryGirl.build(:html_attachment).has_body_as_html?.should be_false + end - it 'should create a filename for an instance with a blank filename' do - attachment = FoiAttachment.new - attachment.filename = '' - attachment.ensure_filename! - attachment.filename.should == 'attachment.bin' end end diff --git a/spec/models/has_tag_string_tag_spec.rb b/spec/models/has_tag_string_tag_spec.rb index 759b3396f..bbcb00ca2 100644 --- a/spec/models/has_tag_string_tag_spec.rb +++ b/spec/models/has_tag_string_tag_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe HasTagString::HasTagStringTag, " when fiddling with tag strings" do diff --git a/spec/models/holiday_import_spec.rb b/spec/models/holiday_import_spec.rb index 7ec5c04d5..eb0b33e0e 100644 --- a/spec/models/holiday_import_spec.rb +++ b/spec/models/holiday_import_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe HolidayImport do diff --git a/spec/models/holiday_spec.rb b/spec/models/holiday_spec.rb index 2f8eeabd9..bd73e672b 100644 --- a/spec/models/holiday_spec.rb +++ b/spec/models/holiday_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: holidays diff --git a/spec/models/incoming_message_spec.rb b/spec/models/incoming_message_spec.rb index ca9bbe39e..10bb3de62 100644 --- a/spec/models/incoming_message_spec.rb +++ b/spec/models/incoming_message_spec.rb @@ -1,4 +1,4 @@ -# coding: utf-8 +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: incoming_messages @@ -263,7 +263,7 @@ describe IncomingMessage, " when dealing with incoming mail" do incoming_message = InfoRequest.holding_pen_request.incoming_messages[0] # This will raise an error if the bug in TMail hasn't been fixed - incoming_message.get_body_for_html_display() + incoming_message.get_body_for_html_display end @@ -282,7 +282,7 @@ end describe IncomingMessage, " display attachments" do it "should not show slashes in filenames" do - foi_attachment = FoiAttachment.new() + foi_attachment = FoiAttachment.new # http://www.whatdotheyknow.com/request/post_commercial_manager_librarie#incoming-17233 foi_attachment.filename = "FOI/09/066 RESPONSE TO FOI REQUEST RECEIVED 21st JANUARY 2009.txt" expected_display_filename = foi_attachment.filename.gsub(/\//, " ") @@ -290,7 +290,7 @@ describe IncomingMessage, " display attachments" do end it "should not show slashes in subject generated filenames" do - foi_attachment = FoiAttachment.new() + foi_attachment = FoiAttachment.new # http://www.whatdotheyknow.com/request/post_commercial_manager_librarie#incoming-17233 foi_attachment.within_rfc822_subject = "FOI/09/066 RESPONSE TO FOI REQUEST RECEIVED 21st JANUARY 2009" foi_attachment.content_type = 'text/plain' @@ -312,20 +312,20 @@ describe IncomingMessage, " folding quoted parts of emails" do it 'should fold a plain text lotus notes quoted part correctly' do text = "FOI Team\n\n\nInfo Requester <xxx@whatdotheyknow.com>=20\nSent by: Info Requester <request-bounce-xxxxx@whatdotheyknow.com>\n06/03/08 10:00\nPlease respond to\nInfo Requester <request-xxxx@whatdotheyknow.com>" - @incoming_message = IncomingMessage.new() + @incoming_message = IncomingMessage.new @incoming_message.stub_chain(:info_request, :user_name).and_return("Info Requester") @incoming_message.remove_lotus_quoting(text).should match(/FOLDED_QUOTED_SECTION/) end it 'should not error when trying to fold lotus notes quoted parts on a request with no user_name' do text = "hello" - @incoming_message = IncomingMessage.new() + @incoming_message = IncomingMessage.new @incoming_message.stub_chain(:info_request, :user_name).and_return(nil) @incoming_message.remove_lotus_quoting(text).should == 'hello' end it "cope with [ in user names properly" do - @incoming_message = IncomingMessage.new() + @incoming_message = IncomingMessage.new @incoming_message.stub_chain(:info_request, :user_name).and_return("Sir [ Bobble") # this gives a warning if [ is in the name text = @incoming_message.remove_lotus_quoting("Sir [ Bobble \nSent by: \n") @@ -357,7 +357,7 @@ describe IncomingMessage, " checking validity to reply to" do MailHandler.stub!(:get_from_address).and_return(email) MailHandler.stub!(:empty_return_path?).with(@mail).and_return(empty_return_path) MailHandler.stub!(:get_auto_submitted).with(@mail).and_return(autosubmitted) - @incoming_message = IncomingMessage.new() + @incoming_message = IncomingMessage.new @incoming_message.stub!(:mail).and_return(@mail) @incoming_message._calculate_valid_to_reply_to.should == result end @@ -431,21 +431,21 @@ describe IncomingMessage, " when censoring data" do @im = incoming_messages(:useless_incoming_message) - @censor_rule_1 = CensorRule.new() + @censor_rule_1 = CensorRule.new @censor_rule_1.text = "Stilton" @censor_rule_1.replacement = "Jarlsberg" @censor_rule_1.last_edit_editor = "unknown" @censor_rule_1.last_edit_comment = "none" @im.info_request.censor_rules << @censor_rule_1 - @censor_rule_2 = CensorRule.new() + @censor_rule_2 = CensorRule.new @censor_rule_2.text = "blue" @censor_rule_2.replacement = "yellow" @censor_rule_2.last_edit_editor = "unknown" @censor_rule_2.last_edit_comment = "none" @im.info_request.censor_rules << @censor_rule_2 - @regex_censor_rule = CensorRule.new() + @regex_censor_rule = CensorRule.new @regex_censor_rule.text = 'm[a-z][a-z][a-z]e' @regex_censor_rule.regexp = true @regex_censor_rule.replacement = 'cat' @@ -477,7 +477,7 @@ describe IncomingMessage, " when censoring whole users" do @im = incoming_messages(:useless_incoming_message) - @censor_rule_1 = CensorRule.new() + @censor_rule_1 = CensorRule.new @censor_rule_1.text = "Stilton" @censor_rule_1.replacement = "Gorgonzola" @censor_rule_1.last_edit_editor = "unknown" @@ -534,7 +534,7 @@ describe IncomingMessage, " when uudecoding bad messages" do im.stub!(:mail).and_return(mail) ir = info_requests(:fancy_dog_request) - @censor_rule = CensorRule.new() + @censor_rule = CensorRule.new @censor_rule.text = "moo" @censor_rule.replacement = "bah" @censor_rule.last_edit_editor = "unknown" diff --git a/spec/models/info_request_batch_spec.rb b/spec/models/info_request_batch_spec.rb index 2881e7745..a8572e7ba 100644 --- a/spec/models/info_request_batch_spec.rb +++ b/spec/models/info_request_batch_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: info_request_batches @@ -80,7 +81,7 @@ describe InfoRequestBatch, "when finding an existing batch" do end end -describe InfoRequestBatch, "when creating a batch", :focus => true do +describe InfoRequestBatch, "when creating a batch" do before do @title = 'A test title' diff --git a/spec/models/info_request_event_spec.rb b/spec/models/info_request_event_spec.rb index 53c83bd46..ff20ab059 100644 --- a/spec/models/info_request_event_spec.rb +++ b/spec/models/info_request_event_spec.rb @@ -1,4 +1,4 @@ -# coding: utf-8 +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: info_request_events @@ -30,6 +30,12 @@ describe InfoRequestEvent do ire.params.should == example_params end + it "should restore UTF8-heavy params stored under ruby 1.8 as UTF-8" do + ire = InfoRequestEvent.new + utf8_params = "--- \n:foo: !binary |\n 0KLQvtCz0LDRiCDR\n" + ire.params_yaml = utf8_params + ire.params[:foo].encoding.to_s.should == 'UTF-8' if ire.params[:foo].respond_to?(:encoding) + end end describe 'when deciding if it is indexed by search' do @@ -105,7 +111,7 @@ describe InfoRequestEvent do describe "should know" do it "that it's an incoming message" do - event = InfoRequestEvent.new() + event = InfoRequestEvent.new event.stub!(:incoming_message_selective_columns).and_return(1) event.is_incoming_message?.should be_true event.is_outgoing_message?.should be_false diff --git a/spec/models/info_request_spec.rb b/spec/models/info_request_spec.rb index 9d1e02442..18120fbb5 100644 --- a/spec/models/info_request_spec.rb +++ b/spec/models/info_request_spec.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: info_requests @@ -28,6 +28,117 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe InfoRequest do + describe :new do + + it 'sets the default law used' do + expect(InfoRequest.new.law_used).to eq('foi') + end + + it 'sets the default law used if a body is eir-only' do + body = FactoryGirl.create(:public_body, :tag_string => 'eir_only') + expect(body.info_requests.build.law_used).to eq('eir') + end + + it 'does not try to set the law used for existing requests' do + info_request = FactoryGirl.create(:info_request) + body = FactoryGirl.create(:public_body, :tag_string => 'eir_only') + info_request.update_attributes(:public_body_id => body.id) + InfoRequest.any_instance.should_not_receive(:law_used=).and_call_original + InfoRequest.find(info_request.id) + end + end + + describe :move_to_public_body do + + context 'with no options' do + + it 'requires an :editor option' do + request = FactoryGirl.create(:info_request) + new_body = FactoryGirl.create(:public_body) + expect { + request.move_to_public_body(new_body) + }.to raise_error IndexError + end + + end + + context 'with the :editor option' do + + it 'moves the info request to the new public body' do + request = FactoryGirl.create(:info_request) + new_body = FactoryGirl.create(:public_body) + user = FactoryGirl.create(:user) + request.move_to_public_body(new_body, :editor => user) + request.reload + expect(request.public_body).to eq(new_body) + end + + it 'logs the move' do + request = FactoryGirl.create(:info_request) + old_body = request.public_body + new_body = FactoryGirl.create(:public_body) + user = FactoryGirl.create(:user) + request.move_to_public_body(new_body, :editor => user) + request.reload + event = request.info_request_events.last + + expect(event.event_type).to eq('move_request') + expect(event.params[:editor]).to eq(user) + expect(event.params[:public_body_url_name]).to eq(new_body.url_name) + expect(event.params[:old_public_body_url_name]).to eq(old_body.url_name) + end + + it 'updates the law_used to the new body law' do + request = FactoryGirl.create(:info_request) + new_body = FactoryGirl.create(:public_body, :tag_string => 'eir_only') + user = FactoryGirl.create(:user) + request.move_to_public_body(new_body, :editor => user) + request.reload + expect(request.law_used).to eq('eir') + end + + it 'returns the new public body' do + request = FactoryGirl.create(:info_request) + new_body = FactoryGirl.create(:public_body) + user = FactoryGirl.create(:user) + expect(request.move_to_public_body(new_body, :editor => user)).to eq(new_body) + end + + it 'retains the existing body if the new body does not exist' do + request = FactoryGirl.create(:info_request) + user = FactoryGirl.create(:user) + existing_body = request.public_body + request.move_to_public_body(nil, :editor => user) + request.reload + expect(request.public_body).to eq(existing_body) + end + + it 'returns nil if the body cannot be updated' do + request = FactoryGirl.create(:info_request) + user = FactoryGirl.create(:user) + expect(request.move_to_public_body(nil, :editor => user)).to eq(nil) + end + + it 'reindexes the info request' do + request = FactoryGirl.create(:info_request) + new_body = FactoryGirl.create(:public_body) + user = FactoryGirl.create(:user) + reindex_job = ActsAsXapian::ActsAsXapianJob. + where(:model => 'InfoRequestEvent'). + delete_all + + request.move_to_public_body(new_body, :editor => user) + request.reload + + reindex_job = ActsAsXapian::ActsAsXapianJob. + where(:model => 'InfoRequestEvent'). + last + expect(reindex_job.model_id).to eq(request.info_request_events.last.id) + end + + end + end + describe 'when validating' do it 'should accept a summary with ascii characters' do @@ -42,7 +153,7 @@ describe InfoRequest do info_request.errors[:title].should be_empty end - it 'should not accept a summary with no ascii or unicode characters' do + it 'should not accept a summary with no ascii or unicode characters' do info_request = InfoRequest.new(:title => '55555') info_request.valid? info_request.errors[:title].should_not be_empty @@ -547,17 +658,22 @@ describe InfoRequest do before do Time.stub!(:now).and_return(Time.utc(2007, 11, 9, 23, 59)) - @mock_comment_event = mock_model(InfoRequestEvent, :created_at => Time.now - 23.days, - :event_type => 'comment', - :response? => false) - mock_incoming_message = mock_model(IncomingMessage, :all_can_view? => true) - @mock_response_event = mock_model(InfoRequestEvent, :created_at => Time.now - 22.days, - :event_type => 'response', - :response? => true, - :incoming_message => mock_incoming_message) - @info_request = InfoRequest.new(:prominence => 'normal', - :awaiting_description => true, - :info_request_events => [@mock_response_event, @mock_comment_event]) + @info_request = FactoryGirl.create(:info_request, + :prominence => 'normal', + :awaiting_description => true) + @comment_event = FactoryGirl.create(:info_request_event, + :created_at => Time.now - 23.days, + :event_type => 'comment', + :info_request => @info_request) + @incoming_message = FactoryGirl.create(:incoming_message, + :prominence => 'normal', + :info_request => @info_request) + @response_event = FactoryGirl.create(:info_request_event, + :info_request => @info_request, + :created_at => Time.now - 22.days, + :event_type => 'response', + :incoming_message => @incoming_message) + @info_request.update_attribute(:awaiting_description, true) end it 'should return false if it is the holding pen' do @@ -571,7 +687,7 @@ describe InfoRequest do end it 'should return false if its last response event occurred less than 21 days ago' do - @mock_response_event.stub!(:created_at).and_return(Time.now - 20.days) + @response_event.update_attribute(:created_at, Time.now - 20.days) @info_request.is_old_unclassified?.should be_false end @@ -1314,4 +1430,20 @@ describe InfoRequest do end + + describe 'when destroying a message' do + + it 'can destroy a request with comments and censor rules' do + info_request = FactoryGirl.create(:info_request) + censor_rule = FactoryGirl.create(:censor_rule, :info_request => info_request) + comment = FactoryGirl.create(:comment, :info_request => info_request) + info_request.reload + info_request.fully_destroy + + InfoRequest.where(:id => info_request.id).should be_empty + CensorRule.where(:id => censor_rule.id).should be_empty + Comment.where(:id => comment.id).should be_empty + end + + end end diff --git a/spec/models/mail_server_log_spec.rb b/spec/models/mail_server_log_spec.rb index 67709b130..6b38e1270 100644 --- a/spec/models/mail_server_log_spec.rb +++ b/spec/models/mail_server_log_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: mail_server_logs diff --git a/spec/models/outgoing_message_spec.rb b/spec/models/outgoing_message_spec.rb index a3e2d1c68..8d43e2ef1 100644 --- a/spec/models/outgoing_message_spec.rb +++ b/spec/models/outgoing_message_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: outgoing_messages @@ -18,6 +19,93 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') +describe OutgoingMessage do + + describe :initialize do + + it 'does not censor the #body' do + attrs = { :status => 'ready', + :message_type => 'initial_request', + :body => 'abc', + :what_doing => 'normal_sort' } + + message = FactoryGirl.create(:outgoing_message, attrs) + + OutgoingMessage.any_instance.should_not_receive(:body).and_call_original + OutgoingMessage.find(message.id) + end + + end + + describe :body do + + it 'returns the body attribute' do + attrs = { :status => 'ready', + :message_type => 'initial_request', + :body => 'abc', + :what_doing => 'normal_sort' } + + message = FactoryGirl.build(:outgoing_message, attrs) + expect(message.body).to eq('abc') + end + + it 'strips the body of leading and trailing whitespace' do + attrs = { :status => 'ready', + :message_type => 'initial_request', + :body => ' abc ', + :what_doing => 'normal_sort' } + + message = FactoryGirl.build(:outgoing_message, attrs) + expect(message.body).to eq('abc') + end + + it 'removes excess linebreaks that unnecessarily space it out' do + attrs = { :status => 'ready', + :message_type => 'initial_request', + :body => "ab\n\nc\n\n", + :what_doing => 'normal_sort' } + + message = FactoryGirl.build(:outgoing_message, attrs) + expect(message.body).to eq("ab\n\nc") + end + + it "applies the associated request's censor rules to the text" do + attrs = { :status => 'ready', + :message_type => 'initial_request', + :body => 'This sensitive text contains secret info!', + :what_doing => 'normal_sort' } + message = FactoryGirl.build(:outgoing_message, attrs) + + rules = [FactoryGirl.build(:censor_rule, :text => 'secret'), + FactoryGirl.build(:censor_rule, :text => 'sensitive')] + InfoRequest.any_instance.stub(:censor_rules).and_return(rules) + + expected = 'This [REDACTED] text contains [REDACTED] info!' + expect(message.body).to eq(expected) + end + + it "applies the given censor rules to the text" do + attrs = { :status => 'ready', + :message_type => 'initial_request', + :body => 'This sensitive text contains secret info!', + :what_doing => 'normal_sort' } + message = FactoryGirl.build(:outgoing_message, attrs) + + request_rules = [FactoryGirl.build(:censor_rule, :text => 'secret'), + FactoryGirl.build(:censor_rule, :text => 'sensitive')] + InfoRequest.any_instance.stub(:censor_rules).and_return(request_rules) + + censor_rules = [FactoryGirl.build(:censor_rule, :text => 'text'), + FactoryGirl.build(:censor_rule, :text => 'contains')] + + expected = 'This sensitive [REDACTED] [REDACTED] secret info!' + expect(message.body(:censor_rules => censor_rules)).to eq(expected) + end + + end + +end + describe OutgoingMessage, " when making an outgoing message" do before do @@ -26,7 +114,7 @@ describe OutgoingMessage, " when making an outgoing message" do :status => 'ready', :message_type => 'initial_request', :body => 'This request contains a foo@bar.com email address', - :last_sent_at => Time.now(), + :last_sent_at => Time.now, :what_doing => 'normal_sort' }) end @@ -57,6 +145,7 @@ describe OutgoingMessage, " when making an outgoing message" do info_request = mock_model(InfoRequest, :public_body => public_body, :url_title => 'a_test_title', :title => 'A test title', + :applicable_censor_rules => [], :apply_censor_rules_to_text! => nil, :is_batch_request_template? => false) outgoing_message = OutgoingMessage.new({ @@ -155,27 +244,6 @@ describe OutgoingMessage, " when making an outgoing message" do end end - -describe OutgoingMessage, " when censoring data" do - - before do - @om = outgoing_messages(:useless_outgoing_message) - - @censor_rule = CensorRule.new() - @censor_rule.text = "dog" - @censor_rule.replacement = "cat" - @censor_rule.last_edit_editor = "unknown" - @censor_rule.last_edit_comment = "none" - - @om.info_request.censor_rules << @censor_rule - end - - it "should apply censor rules to outgoing messages" do - @om.read_attribute(:body).should match(/fancy dog/) - @om.body.should match(/fancy cat/) - end -end - describe OutgoingMessage, "when validating the format of the message body" do it 'should handle a salutation with a bracket in it' do diff --git a/spec/models/post_redirect_spec.rb b/spec/models/post_redirect_spec.rb index 73740e914..7d0dfe395 100644 --- a/spec/models/post_redirect_spec.rb +++ b/spec/models/post_redirect_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: post_redirects @@ -65,11 +66,18 @@ describe PostRedirect, " when accessing values" do end it "should convert reason parameters into YAML and back successfully" do - pr = PostRedirect.new + pr = PostRedirect.new example_reason_params = { :foo => 'this is stuff', :bar => 83, :humbug => "yikes!!!" } pr.reason_params = example_reason_params pr.reason_params_yaml.should == example_reason_params.to_yaml pr.reason_params.should == example_reason_params end + + it "should restore UTF8-heavy params stored under ruby 1.8 as UTF-8" do + pr = PostRedirect.new + utf8_params = "--- \n:foo: !binary |\n 0KLQvtCz0LDRiCDR\n" + pr.reason_params_yaml = utf8_params + pr.reason_params[:foo].encoding.to_s.should == 'UTF-8' if pr.reason_params[:foo].respond_to?(:encoding) + end end diff --git a/spec/models/profile_photo_spec.rb b/spec/models/profile_photo_spec.rb index e70f474a0..199c87500 100644 --- a/spec/models/profile_photo_spec.rb +++ b/spec/models/profile_photo_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: profile_photos diff --git a/spec/models/public_body_category/category_collection_spec.rb b/spec/models/public_body_category/category_collection_spec.rb index 1fbcbe739..9ee684982 100644 --- a/spec/models/public_body_category/category_collection_spec.rb +++ b/spec/models/public_body_category/category_collection_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') describe PublicBodyCategory::CategoryCollection do @@ -15,7 +16,7 @@ describe PublicBodyCategory::CategoryCollection do describe 'when asked for headings' do it 'should return a list of headings' do - @categories.headings().should == ['Local and regional', 'Miscellaneous'] + @categories.headings.should == ['Local and regional', 'Miscellaneous'] end end @@ -30,7 +31,7 @@ describe PublicBodyCategory::CategoryCollection do "Miscellaneous", ["other", "Miscellaneous", "miscellaneous"]] - @categories.with_headings().should == expected_categories + @categories.with_headings.should == expected_categories end end @@ -38,7 +39,7 @@ describe PublicBodyCategory::CategoryCollection do describe 'when asked for tags by headings' do it 'should return a hash of tags keyed by heading' do - @categories.by_heading().should == {'Local and regional' => ['local_council'], + @categories.by_heading.should == {'Local and regional' => ['local_council'], 'Miscellaneous' => ['other']} end end @@ -50,19 +51,19 @@ describe PublicBodyCategory::CategoryCollection do ["local_council", "Local councils", "a local council"], ["other", "Miscellaneous", "miscellaneous"] ] - @categories.with_description().should == expected_categories + @categories.with_description.should == expected_categories end end describe 'when asked for tags' do it 'should return a list of tags' do - @categories.tags().should == ["local_council", "other"] + @categories.tags.should == ["local_council", "other"] end end describe 'when asked for categories by tag' do it 'should return a hash of categories keyed by tag' do - @categories.by_tag().should == { + @categories.by_tag.should == { "local_council" => "Local councils", "other" => "Miscellaneous" } @@ -71,7 +72,7 @@ describe PublicBodyCategory::CategoryCollection do describe 'when asked for singular_by_tag' do it 'should return a hash of category descriptions keyed by tag' do - @categories.singular_by_tag().should == { + @categories.singular_by_tag.should == { "local_council" => "a local council", "other" => "miscellaneous" } diff --git a/spec/models/public_body_category_link_spec.rb b/spec/models/public_body_category_link_spec.rb index fd5608480..564f4126f 100644 --- a/spec/models/public_body_category_link_spec.rb +++ b/spec/models/public_body_category_link_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: public_body_category_links diff --git a/spec/models/public_body_category_spec.rb b/spec/models/public_body_category_spec.rb index 297bd096a..c6b2a8fde 100644 --- a/spec/models/public_body_category_spec.rb +++ b/spec/models/public_body_category_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: public_body_categories diff --git a/spec/models/public_body_change_request_spec.rb b/spec/models/public_body_change_request_spec.rb index 0c4cea67b..e35ffa692 100644 --- a/spec/models/public_body_change_request_spec.rb +++ b/spec/models/public_body_change_request_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: public_body_change_requests @@ -21,7 +22,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe PublicBodyChangeRequest, 'when validating' do it 'should not be valid without a public body name' do - change_request = PublicBodyChangeRequest.new() + change_request = PublicBodyChangeRequest.new change_request.valid?.should be_false change_request.errors[:public_body_name].should == ['Please enter the name of the authority'] end diff --git a/spec/models/public_body_heading_spec.rb b/spec/models/public_body_heading_spec.rb index be3e7c7d2..8b46181b6 100644 --- a/spec/models/public_body_heading_spec.rb +++ b/spec/models/public_body_heading_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: public_body_headings diff --git a/spec/models/public_body_spec.rb b/spec/models/public_body_spec.rb index 7b55efda1..d6abf7b5f 100644 --- a/spec/models/public_body_spec.rb +++ b/spec/models/public_body_spec.rb @@ -1,4 +1,4 @@ -# encoding: UTF-8 +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: public_bodies @@ -1237,6 +1237,33 @@ describe PublicBody do end + describe :request_email do + context "when the email is set" do + subject(:public_body) { FactoryGirl.create(:public_body, :request_email => "request@example.com") } + + it "should return the set email address" do + expect(public_body.request_email).to eq("request@example.com") + end + + it "should return a different email address when overridden in configuration" do + AlaveteliConfiguration.stub!(:override_all_public_body_request_emails).and_return("tester@example.com") + expect(public_body.request_email).to eq("tester@example.com") + end + end + + context "when no email is set" do + subject(:public_body) { FactoryGirl.create(:public_body, :request_email => "") } + + it "should return a blank email address" do + expect(public_body.request_email).to be_blank + end + + it "should still return a blank email address when overridden in configuration" do + AlaveteliConfiguration.stub!(:override_all_public_body_request_emails).and_return("tester@example.com") + expect(public_body.request_email).to be_blank + end + end + end end describe PublicBody::Translation do diff --git a/spec/models/purge_request_spec.rb b/spec/models/purge_request_spec.rb index 02b3d685d..642d5d2e2 100644 --- a/spec/models/purge_request_spec.rb +++ b/spec/models/purge_request_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: purge_requests @@ -22,23 +23,23 @@ describe PurgeRequest, "purging things" do req = PurgeRequest.new(:url => "/begone_from_here", :model => "don't care", :model_id => "don't care") - req.save() - PurgeRequest.all().count.should == 1 - PurgeRequest.purge_all() - PurgeRequest.all().count.should == 0 + req.save + PurgeRequest.all.count.should == 1 + PurgeRequest.purge_all + PurgeRequest.all.count.should == 0 end it 'should fail silently for a misconfigured server' do FakeWeb.register_uri(:get, %r|brokenv|, :body => "BROKEN") - config = MySociety::Config.load_default() + config = MySociety::Config.load_default config['VARNISH_HOST'] = "brokencache" req = PurgeRequest.new(:url => "/begone_from_here", :model => "don't care", :model_id => "don't care") - req.save() - PurgeRequest.all().count.should == 1 - PurgeRequest.purge_all() - PurgeRequest.all().count.should == 0 + req.save + PurgeRequest.all.count.should == 1 + PurgeRequest.purge_all + PurgeRequest.all.count.should == 0 end end diff --git a/spec/models/spam_address_spec.rb b/spec/models/spam_address_spec.rb index f28440121..670b969b0 100644 --- a/spec/models/spam_address_spec.rb +++ b/spec/models/spam_address_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: spam_addresses @@ -15,7 +16,7 @@ describe SpamAddress do describe :new do it 'requres an email address' do - SpamAddress.new().should_not be_valid + SpamAddress.new.should_not be_valid SpamAddress.new(:email => 'spam@example.org').should be_valid end diff --git a/spec/models/track_thing_spec.rb b/spec/models/track_thing_spec.rb index 3edf2d1ad..251a50803 100644 --- a/spec/models/track_thing_spec.rb +++ b/spec/models/track_thing_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: track_things diff --git a/spec/models/track_things_sent_email_spec.rb b/spec/models/track_things_sent_email_spec.rb index 4675d0847..b31a989db 100644 --- a/spec/models/track_things_sent_email_spec.rb +++ b/spec/models/track_things_sent_email_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: track_things_sent_emails diff --git a/spec/models/user_info_request_sent_alert_spec.rb b/spec/models/user_info_request_sent_alert_spec.rb index 69be1092b..6b4efa575 100644 --- a/spec/models/user_info_request_sent_alert_spec.rb +++ b/spec/models/user_info_request_sent_alert_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: user_info_request_sent_alerts diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 2245a024f..009045bdf 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # == Schema Information # # Table name: users diff --git a/spec/models/widget_vote_spec.rb b/spec/models/widget_vote_spec.rb new file mode 100644 index 000000000..1a6d3833c --- /dev/null +++ b/spec/models/widget_vote_spec.rb @@ -0,0 +1,54 @@ +# -*- encoding : utf-8 -*- +# == Schema Information +# +# Table name: widget_votes +# +# id :integer not null, primary key +# cookie :string(255) +# info_request_id :integer +# created_at :datetime not null +# updated_at :datetime not null +# + +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe WidgetVote do + + describe :new do + + it 'requires an info request' do + widget_vote = WidgetVote.new + widget_vote.should_not be_valid + widget_vote.errors[:info_request].should == ["can't be blank"] + end + + it 'validates the cookie length' do + widget_vote = WidgetVote.new + widget_vote.should_not be_valid + widget_vote.errors[:cookie].should == ["is the wrong length (should be 20 characters)"] + end + + it 'is valid with a cookie and info request' do + widget_vote = FactoryGirl.create(:widget_vote) + widget_vote.should be_valid + end + + it 'enforces uniqueness of cookie per info request' do + info_request = FactoryGirl.create(:info_request) + widget_vote = info_request.widget_votes.create(:cookie => 'x' * 20) + duplicate_vote = info_request.widget_votes.build(:cookie => 'x' * 20) + duplicate_vote.should_not be_valid + duplicate_vote.errors[:cookie].should == ["has already been taken"] + end + + it 'allows the same cookie to be used across info requests' do + info_request = FactoryGirl.create(:info_request) + second_info_request = FactoryGirl.create(:info_request) + widget_vote = info_request.widget_votes.create(:cookie => 'x' * 20) + second_request_vote = second_info_request.widget_votes.build(:cookie => 'x' * 20) + second_request_vote.should be_valid + end + + end + +end diff --git a/spec/models/xapian_spec.rb b/spec/models/xapian_spec.rb index ca6cd7db7..212a1cc7e 100644 --- a/spec/models/xapian_spec.rb +++ b/spec/models/xapian_spec.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe User, " when indexing users with Xapian" do @@ -102,7 +102,7 @@ describe PublicBody, " when indexing requests by body they are to" do end # if you index via the Xapian TermGenerator, it ignores terms of this length, - # this checks we're using Document:::add_term() instead + # this checks we're using Document:::add_term instead it "should work with URL names that are longer than 64 characters" do # change the URL name of the body body = public_bodies(:geraldine_public_body) diff --git a/spec/script/handle-mail-replies_spec.rb b/spec/script/handle-mail-replies_spec.rb index 62d5c1dab..399d0d51d 100644 --- a/spec/script/handle-mail-replies_spec.rb +++ b/spec/script/handle-mail-replies_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') require "external_command" diff --git a/spec/script/mailin_spec.rb b/spec/script/mailin_spec.rb index 0ff094c2b..6cdc1308e 100644 --- a/spec/script/mailin_spec.rb +++ b/spec/script/mailin_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') require "external_command" diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 93bcfa1ba..d9feba6cd 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require 'rubygems' require 'spork' @@ -124,13 +125,6 @@ Spork.prefork do end end - # TODO: No idea what namespace/class/module to put this in - # Create a clean xapian index based on the fixture files and the raw_email data. - def create_fixtures_xapian_index - load_raw_emails_data - rebuild_xapian_index - end - # Use the before create job hook to simulate a race condition with # another process by creating an acts_as_xapian_job record for the # same model: diff --git a/spec/support/email_helpers.rb b/spec/support/email_helpers.rb index 252b1f137..8f2abdbfa 100644 --- a/spec/support/email_helpers.rb +++ b/spec/support/email_helpers.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- def load_raw_emails_data raw_emails_yml = File.join(RSpec.configuration.fixture_path, "raw_emails.yml") for raw_email_id in YAML::load_file(raw_emails_yml).map{|k,v| v["id"]} do diff --git a/spec/support/load_file_fixtures.rb b/spec/support/load_file_fixtures.rb index a54505e99..4370a1b3d 100644 --- a/spec/support/load_file_fixtures.rb +++ b/spec/support/load_file_fixtures.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- def file_fixture_name(file_name) return File.join(RSpec.configuration.fixture_path, "files", file_name) end diff --git a/spec/support/xapian_index.rb b/spec/support/xapian_index.rb index 344c28ebb..3f5f900fd 100644 --- a/spec/support/xapian_index.rb +++ b/spec/support/xapian_index.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- # Rebuild the current xapian index def rebuild_xapian_index(terms = true, values = true, texts = true, dropfirst = true) if dropfirst @@ -22,7 +23,7 @@ end # Copy the xapian index created in create_fixtures_xapian_index to a temporary # copy at the same level and point xapian at the copy -def get_fixtures_xapian_index() +def get_fixtures_xapian_index # Create a base index for the fixtures if not already created $existing_xapian_db ||= create_fixtures_xapian_index # Store whatever the xapian db path is originally diff --git a/spec/views/public_body/show.html.erb_spec.rb b/spec/views/public_body/show.html.erb_spec.rb index 6ebc39caa..a4edcfc22 100644 --- a/spec/views/public_body/show.html.erb_spec.rb +++ b/spec/views/public_body/show.html.erb_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.join('..', '..', '..', 'spec_helper'), __FILE__) describe "public_body/show" do @@ -13,7 +14,6 @@ describe "public_body/show" do :publication_scheme => '', :disclosure_log => '', :calculated_home_page => '') - @pb.stub!(:override_request_email).and_return(nil) @pb.stub!(:is_requestable?).and_return(true) @pb.stub!(:special_not_requestable_reason?).and_return(false) @pb.stub!(:has_notes?).and_return(false) @@ -30,6 +30,7 @@ describe "public_body/show" do assign(:xapian_requests, @xap) assign(:page, 1) assign(:per_page, 10) + assign(:number_of_visible_requests, 4) end it "should be successful" do @@ -48,7 +49,7 @@ describe "public_body/show" do end it "should cope with no results" do - @pb.stub!(:info_requests).and_return([]) + assign(:number_of_visible_requests, 0) render response.should have_selector('p', :content => "Nobody has made any Freedom of Information requests") end diff --git a/spec/views/reports/new.erb_spec.rb b/spec/views/reports/new.erb_spec.rb index 66b738261..d599100b9 100644 --- a/spec/views/reports/new.erb_spec.rb +++ b/spec/views/reports/new.erb_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.join('..', '..', '..', 'spec_helper'), __FILE__) describe 'reports/new.html.erb' do diff --git a/spec/views/request/_after_actions.html.erb_spec.rb b/spec/views/request/_after_actions.html.erb_spec.rb index 833323d68..7a58731ce 100644 --- a/spec/views/request/_after_actions.html.erb_spec.rb +++ b/spec/views/request/_after_actions.html.erb_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.join('..', '..', '..', 'spec_helper'), __FILE__) describe 'when displaying actions that can be taken with regard to a request' do diff --git a/spec/views/request/_describe_state.html.erb_spec.rb b/spec/views/request/_describe_state.html.erb_spec.rb index 88dea53c5..1026ad2f3 100644 --- a/spec/views/request/_describe_state.html.erb_spec.rb +++ b/spec/views/request/_describe_state.html.erb_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.join('..', '..', '..', 'spec_helper'), __FILE__) describe 'when showing the form for describing the state of a request' do diff --git a/spec/views/request/show.html.erb_spec.rb b/spec/views/request/show.html.erb_spec.rb index 6e63b9b43..71057f028 100644 --- a/spec/views/request/show.html.erb_spec.rb +++ b/spec/views/request/show.html.erb_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.join('..', '..', '..', 'spec_helper'), __FILE__) describe 'request/show' do diff --git a/spec/views/request_game/play.html.erb_spec.rb b/spec/views/request_game/play.html.erb_spec.rb index b5cf57c23..37a84b211 100644 --- a/spec/views/request_game/play.html.erb_spec.rb +++ b/spec/views/request_game/play.html.erb_spec.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require File.expand_path(File.join('..', '..', '..', 'spec_helper'), __FILE__) describe 'request_game/play' do |