diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/general_controller_spec.rb | 11 | ||||
-rw-r--r-- | spec/fixtures/public_body_translations.yml | 20 | ||||
-rw-r--r-- | spec/lib/mail_handler/mail_handler_spec.rb | 2 | ||||
-rw-r--r-- | spec/lib/sendmail_return_path_spec.rb | 88 | ||||
-rw-r--r-- | spec/mailers/application_mailer_spec.rb | 2 | ||||
-rw-r--r-- | spec/mailers/request_mailer_spec.rb | 21 | ||||
-rw-r--r-- | spec/models/info_request_spec.rb | 27 | ||||
-rw-r--r-- | spec/models/public_body_spec.rb | 32 | ||||
-rw-r--r-- | spec/models/xapian_spec.rb | 2 | ||||
-rw-r--r-- | spec/spec_helper.rb | 4 |
10 files changed, 91 insertions, 118 deletions
diff --git a/spec/controllers/general_controller_spec.rb b/spec/controllers/general_controller_spec.rb index e67cc9492..7590a5b42 100644 --- a/spec/controllers/general_controller_spec.rb +++ b/spec/controllers/general_controller_spec.rb @@ -42,6 +42,17 @@ describe GeneralController, 'when getting the blog feed' do assigns[:blog_items].count.should == 1 end + context 'if no feed is configured' do + + before do + AlaveteliConfiguration.stub!(:blog_feed).and_return('') + end + + it 'should raise an ActiveRecord::RecordNotFound error' do + lambda{ get :blog }.should raise_error(ActiveRecord::RecordNotFound) + end + end + end describe GeneralController, "when showing the frontpage" do diff --git a/spec/fixtures/public_body_translations.yml b/spec/fixtures/public_body_translations.yml index 2030804ac..225bd74e2 100644 --- a/spec/fixtures/public_body_translations.yml +++ b/spec/fixtures/public_body_translations.yml @@ -10,6 +10,8 @@ geraldine_es_public_body_translation: notes: "" publication_scheme: "" disclosure_log: "" + created_at: 2007-10-24 10:51:01.161639 + updated_at: 2007-10-24 10:51:01.161639 geraldine_en_public_body_translation: name: Geraldine Quango @@ -23,6 +25,8 @@ geraldine_en_public_body_translation: notes: "" publication_scheme: "" disclosure_log: "" + created_at: 2007-10-24 10:51:01.161639 + updated_at: 2007-10-24 10:51:01.161639 humpadink_es_public_body_translation: name: "El Department for Humpadinking" @@ -36,6 +40,8 @@ humpadink_es_public_body_translation: notes: Baguette publication_scheme: "" disclosure_log: "" + created_at: 2007-10-24 10:51:01.161639 + updated_at: 2007-10-24 10:51:01.161639 humpadink_en_public_body_translation: name: "Department for Humpadinking" @@ -49,6 +55,8 @@ humpadink_en_public_body_translation: notes: An albatross told me!!! publication_scheme: "" disclosure_log: "" + created_at: 2007-10-24 10:51:01.161639 + updated_at: 2007-10-24 10:51:01.161639 forlorn_en_public_body_translation: name: "Department of Loneliness" @@ -62,6 +70,8 @@ forlorn_en_public_body_translation: notes: A very lonely public body that no one has corresponded with publication_scheme: "" disclosure_log: "" + created_at: 2007-10-24 10:51:01.161639 + updated_at: 2007-10-24 10:51:01.161639 silly_walks_en_public_body_translation: id: 6 @@ -75,6 +85,8 @@ silly_walks_en_public_body_translation: notes: You know the one. publication_scheme: "" disclosure_log: "" + created_at: 2007-10-24 10:51:01.161639 + updated_at: 2007-10-24 10:51:01.161639 sensible_walks_en_public_body_translation: id: 7 @@ -88,6 +100,8 @@ sensible_walks_en_public_body_translation: notes: I bet you’ve never heard of it. publication_scheme: "" disclosure_log: "" + created_at: 2008-10-25 10:51:01.161639 + updated_at: 2008-10-25 10:51:01.161639 other_public_body_translation: id: 8 @@ -101,6 +115,8 @@ other_public_body_translation: notes: More notes publication_scheme: "" disclosure_log: "" + created_at: 2008-10-25 10:51:01.161639 + updated_at: 2008-10-25 10:51:01.161639 humpadink_he_IL_public_body_translation: name: "Hebrew Humpadinking" @@ -114,6 +130,8 @@ humpadink_he_IL_public_body_translation: notes: An albatross told me!!! publication_scheme: "" disclosure_log: "" + created_at: 2007-10-24 10:51:01.161639 + updated_at: 2007-10-24 10:51:01.161639 accented_public_body_translation: id: 10 @@ -127,3 +145,5 @@ accented_public_body_translation: notes: This is to test unicode handling in body names publication_scheme: "" disclosure_log: "" + created_at: 2008-10-25 10:51:01.161639 + updated_at: 2008-10-25 10:51:01.161639 diff --git a/spec/lib/mail_handler/mail_handler_spec.rb b/spec/lib/mail_handler/mail_handler_spec.rb index f62b1d6fc..49a65dade 100644 --- a/spec/lib/mail_handler/mail_handler_spec.rb +++ b/spec/lib/mail_handler/mail_handler_spec.rb @@ -235,7 +235,7 @@ describe 'when deriving a name, email and formatted address from a message from it 'should quote a name with quotes in it' do should_render_from_address('"FOI \" Person" <foiperson@localhost>', - ['FOI \" Person', + ['FOI " Person', 'foiperson@localhost', '"FOI \" Person" <foiperson@localhost>']) end diff --git a/spec/lib/sendmail_return_path_spec.rb b/spec/lib/sendmail_return_path_spec.rb deleted file mode 100644 index 83436c2bd..000000000 --- a/spec/lib/sendmail_return_path_spec.rb +++ /dev/null @@ -1,88 +0,0 @@ -# This is a test of the monkey patches in sendmail_return_path.rb - -# In Rails 3 the monkeypatches are not needed anymore because sendmail now has the "-f" flag -# set correctly. So, strictly these tests are testing the Rails internals. So, that means we really -# should delete them. Let's do that later when things have settled down. For the time being leave -# them in - -require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') - -describe "when sending email with an altered return path" do - before(:each) { ActionMailer::Base.deliveries = [] } - - it "should default to delivery method test" do - ActionMailer::Base.delivery_method.should == :test - end - - it "should let the helper change the method" do - with_delivery_method :smtp do - ActionMailer::Base.delivery_method.should == :smtp - end - ActionMailer::Base.delivery_method.should == :test - end - - # Documentation for fancy mock functions: http://rspec.info/documentation/mocks/message_expectations.html - it "should set the return path when sending email using SMTP" do - mock_smtp = mock("smtp") - mock_smtp_session = mock("smtp_session") - - mock_smtp.should_receive(:start).once.and_yield(mock_smtp_session) - # the second parameter to the SMTP session is the sender (return path) - mock_smtp_session.should_receive(:sendmail).once.with(anything(), "test@localhost", anything()) - - Net::SMTP.stub!(:new).and_return(mock_smtp) - - with_delivery_method :smtp do - ContactMailer.to_admin_message( - "Mr. Test", "test@localhost", "Test script spec/lib/sendmail_return_path_spec.rb", - "This is just a test for a test script", nil, nil, nil - ).deliver - end - - deliveries = ActionMailer::Base.deliveries - deliveries.size.should == 0 - end - - it "should set the return path when sending email using sendmail" do - with_stub_popen do - IO.should_receive(:popen).once.with('/usr/sbin/sendmail -i -t -f "test@localhost" postmaster@localhost', "w+") - with_delivery_method :sendmail do - ContactMailer.to_admin_message( - "Mr. Test", "test@localhost", "Test script spec/lib/sendmail_return_path_spec.rb", - "This is just a test for a test script", nil, nil, nil - ).deliver - end - end - - deliveries = ActionMailer::Base.deliveries - deliveries.size.should == 0 - end - - - protected - # Change the way Rails delivers memory, just for current scope - def with_delivery_method(new_delivery_method) - old_delivery_method, ActionMailer::Base.delivery_method = ActionMailer::Base.delivery_method, new_delivery_method - yield - ensure - ActionMailer::Base.delivery_method = old_delivery_method - end - - # By default, we can't stub popen, presumably because it is a builtin written in C. - # Replace it entirely with a normal method that just calls the C one, so we can stub it - - # this leaves IO working afterwards (for other tests that run in the same instance). - def with_stub_popen() - IO.class_eval "@orig_popen = self.method(:popen); def self.popen(a, b, &c); @orig_popen.call(a, b, &c); end" - begin - yield - ensure - # in theory would undo the popen alterations and return IO to a pristine state, but - # don't know how to (much fiddling with alias bind and the like didn't help). It - # doesn't matter - the new popen should behave just the same. - end - end - - -end - - diff --git a/spec/mailers/application_mailer_spec.rb b/spec/mailers/application_mailer_spec.rb index d8993f78f..718ac47fb 100644 --- a/spec/mailers/application_mailer_spec.rb +++ b/spec/mailers/application_mailer_spec.rb @@ -13,7 +13,7 @@ describe ApplicationMailer do end def add_mail_methods(method_names) - method_names.each{ |method_name| ApplicationMailer.send(:define_method, method_name){} } + 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 4e0765921..516d13127 100644 --- a/spec/mailers/request_mailer_spec.rb +++ b/spec/mailers/request_mailer_spec.rb @@ -332,6 +332,27 @@ describe RequestMailer, 'when sending mail when someone has updated an old uncla end +describe RequestMailer, 'when generating a fake response for an upload' do + + before do + @foi_officer = mock_model(User, :name_and_email => "FOI officer's name and email") + @request_user = mock_model(User) + @public_body = mock_model(PublicBody, :name => 'Test public body') + @info_request = mock_model(InfoRequest, :user => @request_user, + :email_subject_followup => 'Re: Freedom of Information - Test request', + :incoming_name_and_email => 'Someone <someone@example.org>') + end + + it 'should should generate a "fake response" email with a reasonable subject line' do + fake_email = RequestMailer.fake_response(@info_request, + @foi_officer, + "The body of the email...", + "blah.txt", + "The content of blah.txt") + fake_email.subject.should == "Re: Freedom of Information - Test request" + end + +end describe RequestMailer, 'when sending a new response email' do diff --git a/spec/models/info_request_spec.rb b/spec/models/info_request_spec.rb index 22ec1d6b7..dcc94e967 100644 --- a/spec/models/info_request_spec.rb +++ b/spec/models/info_request_spec.rb @@ -550,33 +550,6 @@ describe InfoRequest do end - describe 'when an instance is asked if all can view it' do - - before do - @info_request = InfoRequest.new - end - - it 'should return true if its prominence is normal' do - @info_request.prominence = 'normal' - @info_request.all_can_view?.should == true - end - - it 'should return true if its prominence is backpage' do - @info_request.prominence = 'backpage' - @info_request.all_can_view?.should == true - end - - it 'should return false if its prominence is hidden' do - @info_request.prominence = 'hidden' - @info_request.all_can_view?.should == false - end - - it 'should return false if its prominence is requester_only' do - @info_request.prominence = 'requester_only' - @info_request.all_can_view?.should == false - end - end - describe 'when applying censor rules' do before do diff --git a/spec/models/public_body_spec.rb b/spec/models/public_body_spec.rb index 23842ccff..ed24ced52 100644 --- a/spec/models/public_body_spec.rb +++ b/spec/models/public_body_spec.rb @@ -213,6 +213,15 @@ describe PublicBody, " when saving" do public_body.name.should == "Mark's Public Body" end + it 'should update the right translation when in a locale with an underscore' do + AlaveteliLocalization.set_locales('he_IL', 'he_IL') + public_body = public_bodies(:humpadink_public_body) + translation_count = public_body.translations.size + public_body.name = 'Renamed' + public_body.save! + public_body.translations.size.should == translation_count + end + it 'should not create a new version when nothing has changed' do @public_body.versions.size.should == 0 set_default_attributes(@public_body) @@ -473,6 +482,20 @@ describe PublicBody, " when loading CSV files" do PublicBody.count.should == original_count end + + it "should be able to load CSV from a file as well as a string" do + # Essentially the same code is used for import_csv_from_file + # as import_csv, so this is just a basic check that + # import_csv_from_file can load from a file at all. (It would + # be easy to introduce a regression that broke this, because + # of the confusing change in behaviour of CSV.parse between + # Ruby 1.8 and 1.9.) + original_count = PublicBody.count + filename = file_fixture_name('fake-authority-type-with-field-names.csv') + PublicBody.import_csv_from_file(filename, '', 'replace', false, 'someadmin') + PublicBody.count.should == original_count + 3 + end + end describe PublicBody do @@ -604,3 +627,12 @@ describe PublicBody, "when calculating statistics" do end end + +describe PublicBody, 'when asked for popular bodies' do + + it 'should return bodies correctly when passed the hyphenated version of the locale' do + AlaveteliConfiguration.stub!(:frontpage_publicbody_examples).and_return('') + PublicBody.popular_bodies('he-IL').should == [public_bodies(:humpadink_public_body)] + end + +end diff --git a/spec/models/xapian_spec.rb b/spec/models/xapian_spec.rb index 3c9fff784..a1e060d8e 100644 --- a/spec/models/xapian_spec.rb +++ b/spec/models/xapian_spec.rb @@ -370,7 +370,7 @@ describe PublicBody, " when only indexing selected things on a rebuild" do end end -# I would expect ActsAsXapian to have some tests under vendor/plugins/acts_as_xapian, but +# I would expect ActsAsXapian to have some tests under lib/acts_as_xapian, but # it looks like this is not the case. Putting a test here instead. describe ActsAsXapian::Search, "#words_to_highlight" do before(:each) do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d22f3c0ff..1eeb8603b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -13,6 +13,10 @@ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[ SimpleCov.start('rails') do add_filter 'commonlib' add_filter 'vendor/plugins' + add_filter 'lib/strip_attributes' + add_filter 'lib/has_tag_string' + add_filter 'lib/acts_as_xapian' + add_filter 'lib/themes' end Spork.prefork do |