aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/admin_censor_rule_controller_spec.rb2
-rw-r--r--spec/controllers/admin_public_body_controller_spec.rb10
-rw-r--r--spec/controllers/general_controller_spec.rb4
-rw-r--r--spec/controllers/public_body_controller_spec.rb2
-rw-r--r--spec/controllers/request_controller_spec.rb40
-rw-r--r--spec/controllers/services_controller_spec.rb10
-rw-r--r--spec/controllers/user_controller_spec.rb4
-rw-r--r--spec/lib/alaveteli_text_masker_spec.rb2
-rw-r--r--spec/lib/health_checks/checks/days_ago_check_spec.rb6
-rw-r--r--spec/lib/health_checks/health_checkable_spec.rb22
-rw-r--r--spec/lib/health_checks/health_checks_spec.rb6
-rw-r--r--spec/lib/languages_spec.rb22
-rw-r--r--spec/lib/mail_handler/mail_handler_spec.rb10
-rw-r--r--spec/mailers/application_mailer_spec.rb2
-rw-r--r--spec/mailers/request_mailer_spec.rb2
-rw-r--r--spec/models/foi_attachment_spec.rb80
-rw-r--r--spec/models/incoming_message_spec.rb24
-rw-r--r--spec/models/info_request_event_spec.rb2
-rw-r--r--spec/models/info_request_spec.rb2
-rw-r--r--spec/models/outgoing_message_spec.rb2
-rw-r--r--spec/models/public_body_category/category_collection_spec.rb14
-rw-r--r--spec/models/public_body_change_request_spec.rb2
-rw-r--r--spec/models/purge_request_spec.rb18
-rw-r--r--spec/models/spam_address_spec.rb2
-rw-r--r--spec/models/xapian_spec.rb2
-rw-r--r--spec/support/xapian_index.rb2
-rw-r--r--spec/views/public_body/show.html.erb_spec.rb3
27 files changed, 165 insertions, 132 deletions
diff --git a/spec/controllers/admin_censor_rule_controller_spec.rb b/spec/controllers/admin_censor_rule_controller_spec.rb
index a2014808c..b9f936836 100644
--- a/spec/controllers/admin_censor_rule_controller_spec.rb
+++ b/spec/controllers/admin_censor_rule_controller_spec.rb
@@ -585,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_public_body_controller_spec.rb b/spec/controllers/admin_public_body_controller_spec.rb
index 035c478bf..1b960ccc3 100644
--- a/spec/controllers/admin_public_body_controller_spec.rb
+++ b/spec/controllers/admin_public_body_controller_spec.rb
@@ -651,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
@@ -678,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
@@ -758,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/general_controller_spec.rb b/spec/controllers/general_controller_spec.rb
index d466625b7..495624403 100644
--- a/spec/controllers/general_controller_spec.rb
+++ b/spec/controllers/general_controller_spec.rb
@@ -112,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
@@ -123,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/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb
index 02e37684c..c5c94a45c 100644
--- a/spec/controllers/public_body_controller_spec.rb
+++ b/spec/controllers/public_body_controller_spec.rb
@@ -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/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb
index eb4ea5e7d..a5534e9ff 100644
--- a/spec/controllers/request_controller_spec.rb
+++ b/spec/controllers/request_controller_spec.rb
@@ -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
diff --git a/spec/controllers/services_controller_spec.rb b/spec/controllers/services_controller_spec.rb
index d4a3e5939..6ab527bc9 100644
--- a/spec/controllers/services_controller_spec.rb
+++ b/spec/controllers/services_controller_spec.rb
@@ -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/user_controller_spec.rb b/spec/controllers/user_controller_spec.rb
index 2d3b36f70..fb03615f8 100644
--- a/spec/controllers/user_controller_spec.rb
+++ b/spec/controllers/user_controller_spec.rb
@@ -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/lib/alaveteli_text_masker_spec.rb b/spec/lib/alaveteli_text_masker_spec.rb
index 8f7c530b3..f2d52c1cc 100644
--- a/spec/lib/alaveteli_text_masker_spec.rb
+++ b/spec/lib/alaveteli_text_masker_spec.rb
@@ -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')
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 829b8e71e..4fbc1913b 100644
--- a/spec/lib/health_checks/checks/days_ago_check_spec.rb
+++ b/spec/lib/health_checks/checks/days_ago_check_spec.rb
@@ -16,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 301585bbd..59d76c337 100644
--- a/spec/lib/health_checks/health_checkable_spec.rb
+++ b/spec/lib/health_checks/health_checkable_spec.rb
@@ -32,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
@@ -93,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
@@ -110,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 335e10b3a..0b97725db 100644
--- a/spec/lib/health_checks/health_checks_spec.rb
+++ b/spec/lib/health_checks/health_checks_spec.rb
@@ -7,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
@@ -21,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/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/mail_handler_spec.rb b/spec/lib/mail_handler/mail_handler_spec.rb
index 7f0070a8a..27a7a3db4 100644
--- a/spec/lib/mail_handler/mail_handler_spec.rb
+++ b/spec/lib/mail_handler/mail_handler_spec.rb
@@ -158,6 +158,16 @@ describe 'when asked for all the addresses a mail has been sent to' do
mail = MailHandler.mail_from_raw_email(mail_data)
MailHandler.get_all_addresses(mail).should == ["request-5555-xxxxxxxx@whatdotheyknow.com"]
end
+
+ it 'should not return invalid addresses' do
+ mail_data = load_file_fixture('autoresponse-header.email')
+ mail_data.gsub!('To: FOI Person <EMAIL_TO>',
+ 'To: <request-5555-xxxxxxxx>')
+ mail = MailHandler.mail_from_raw_email(mail_data)
+ MailHandler.get_all_addresses(mail).should == []
+ end
+
+
end
describe 'when asked for auto_submitted' do
diff --git a/spec/mailers/application_mailer_spec.rb b/spec/mailers/application_mailer_spec.rb
index a5c5a5cf2..1854e4741 100644
--- a/spec/mailers/application_mailer_spec.rb
+++ b/spec/mailers/application_mailer_spec.rb
@@ -14,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/request_mailer_spec.rb b/spec/mailers/request_mailer_spec.rb
index 5c8b8a3de..12d83ca62 100644
--- a/spec/mailers/request_mailer_spec.rb
+++ b/spec/mailers/request_mailer_spec.rb
@@ -301,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|
diff --git a/spec/models/foi_attachment_spec.rb b/spec/models/foi_attachment_spec.rb
index 88afc24a4..9583f4c76 100644
--- a/spec/models/foi_attachment_spec.rb
+++ b/spec/models/foi_attachment_spec.rb
@@ -18,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/incoming_message_spec.rb b/spec/models/incoming_message_spec.rb
index f4b450370..10bb3de62 100644
--- a/spec/models/incoming_message_spec.rb
+++ b/spec/models/incoming_message_spec.rb
@@ -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_event_spec.rb b/spec/models/info_request_event_spec.rb
index 401a5f712..ff20ab059 100644
--- a/spec/models/info_request_event_spec.rb
+++ b/spec/models/info_request_event_spec.rb
@@ -111,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 cddf1f880..18120fbb5 100644
--- a/spec/models/info_request_spec.rb
+++ b/spec/models/info_request_spec.rb
@@ -31,7 +31,7 @@ describe InfoRequest do
describe :new do
it 'sets the default law used' do
- expect(InfoRequest.new().law_used).to eq('foi')
+ expect(InfoRequest.new.law_used).to eq('foi')
end
it 'sets the default law used if a body is eir-only' do
diff --git a/spec/models/outgoing_message_spec.rb b/spec/models/outgoing_message_spec.rb
index 336e5a605..8d43e2ef1 100644
--- a/spec/models/outgoing_message_spec.rb
+++ b/spec/models/outgoing_message_spec.rb
@@ -114,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
diff --git a/spec/models/public_body_category/category_collection_spec.rb b/spec/models/public_body_category/category_collection_spec.rb
index 29fa6a699..9ee684982 100644
--- a/spec/models/public_body_category/category_collection_spec.rb
+++ b/spec/models/public_body_category/category_collection_spec.rb
@@ -16,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
@@ -31,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
@@ -39,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
@@ -51,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"
}
@@ -72,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_change_request_spec.rb b/spec/models/public_body_change_request_spec.rb
index 90abf0b6b..e35ffa692 100644
--- a/spec/models/public_body_change_request_spec.rb
+++ b/spec/models/public_body_change_request_spec.rb
@@ -22,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/purge_request_spec.rb b/spec/models/purge_request_spec.rb
index 617e082a8..642d5d2e2 100644
--- a/spec/models/purge_request_spec.rb
+++ b/spec/models/purge_request_spec.rb
@@ -23,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 edef79bed..670b969b0 100644
--- a/spec/models/spam_address_spec.rb
+++ b/spec/models/spam_address_spec.rb
@@ -16,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/xapian_spec.rb b/spec/models/xapian_spec.rb
index b8ef341bd..b3f2e2b3c 100644
--- a/spec/models/xapian_spec.rb
+++ b/spec/models/xapian_spec.rb
@@ -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/support/xapian_index.rb b/spec/support/xapian_index.rb
index bfdffd281..3f5f900fd 100644
--- a/spec/support/xapian_index.rb
+++ b/spec/support/xapian_index.rb
@@ -23,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 adf78d307..a4edcfc22 100644
--- a/spec/views/public_body/show.html.erb_spec.rb
+++ b/spec/views/public_body/show.html.erb_spec.rb
@@ -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