diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/track_controller_spec.rb | 3 | ||||
-rw-r--r-- | spec/fixtures/info_request_events.yml | 11 | ||||
-rw-r--r-- | spec/fixtures/info_requests.yml | 12 | ||||
-rw-r--r-- | spec/fixtures/outgoing_messages.yml | 11 | ||||
-rw-r--r-- | spec/fixtures/public_bodies.yml | 15 | ||||
-rw-r--r-- | spec/fixtures/public_body_translations.yml | 13 | ||||
-rw-r--r-- | spec/fixtures/users.yml | 22 | ||||
-rw-r--r-- | spec/helpers/link_to_helper_spec.rb | 42 | ||||
-rw-r--r-- | spec/models/request_mailer_spec.rb | 11 | ||||
-rw-r--r-- | spec/script/mailin_spec.rb | 14 | ||||
-rw-r--r-- | spec/spec_helper.rb | 64 | ||||
-rw-r--r-- | spec/views/public_body/show.rhtml_spec.rb | 5 | ||||
-rw-r--r-- | spec/views/request/show.rhtml_spec.rb | 4 |
13 files changed, 98 insertions, 129 deletions
diff --git a/spec/controllers/track_controller_spec.rb b/spec/controllers/track_controller_spec.rb index c785960b5..5505afe59 100644 --- a/spec/controllers/track_controller_spec.rb +++ b/spec/controllers/track_controller_spec.rb @@ -57,7 +57,6 @@ end describe TrackController, "when sending alerts for a track" do integrate_views - include LinkToHelper # for main_url before(:each) do load_raw_emails_data @@ -105,7 +104,7 @@ describe TrackController, "when sending alerts for a track" do # Given we can't click the link, check the token is right instead post_redirect = PostRedirect.find_by_email_token(mail_token) - expected_url = main_url("/user/" + users(:silly_name_user).url_name + "#email_subscriptions") # XXX can't call URL making functions here, what is correct way to do this? + expected_url = show_user_url(:url_name => users(:silly_name_user).url_name, :anchor => "email_subscriptions") post_redirect.uri.should == expected_url # Check nothing more is delivered if we try again diff --git a/spec/fixtures/info_request_events.yml b/spec/fixtures/info_request_events.yml index c1a00ad47..3907703d8 100644 --- a/spec/fixtures/info_request_events.yml +++ b/spec/fixtures/info_request_events.yml @@ -171,3 +171,14 @@ anonymous_external_outgoing_message_event: created_at: 2009-01-03 02:23:45.6789100 described_state: waiting_response calculated_state: waiting_response + +other_request_outgoing_message_event: + id: 916 + params_yaml: "--- \n\ + :outgoing_message_id: 10\n" + outgoing_message_id: 10 + info_request_id: 111 + event_type: sent + created_at: <%= Time.now %> + described_state: waiting_response + calculated_state: waiting_response diff --git a/spec/fixtures/info_requests.yml b/spec/fixtures/info_requests.yml index 9361ec486..97effd036 100644 --- a/spec/fixtures/info_requests.yml +++ b/spec/fixtures/info_requests.yml @@ -107,3 +107,15 @@ anonymous_external_request: awaiting_description: false comments_allowed: true idhash: 7654321a +other_request: + id: 111 + title: Another request + url_title: another_request + created_at: 2010-01-01 02:23:45.6789100 + updated_at: 2010-01-01 02:23:45.6789100 + public_body_id: 7 + user_id: 6 + described_state: waiting_response + awaiting_description: false + comments_allowed: true + idhash: b234567 diff --git a/spec/fixtures/outgoing_messages.yml b/spec/fixtures/outgoing_messages.yml index 55df8473e..c71ee08bf 100644 --- a/spec/fixtures/outgoing_messages.yml +++ b/spec/fixtures/outgoing_messages.yml @@ -108,3 +108,14 @@ anonymous_external_outgoing_message: updated_at: 2009-01-12 01:56:58.586598 what_doing: normal_sort +other_outgoing_message: + id: 10 + info_request_id: 111 + message_type: initial_request + status: sent + body: "Just another request" + last_sent_at: <%= Time.now %> + created_at: 2009-01-12 01:56:58.586598 + updated_at: 2009-01-12 01:56:58.586598 + what_doing: normal_sort + diff --git a/spec/fixtures/public_bodies.yml b/spec/fixtures/public_bodies.yml index 615c4bcb6..65cba4b28 100644 --- a/spec/fixtures/public_bodies.yml +++ b/spec/fixtures/public_bodies.yml @@ -72,3 +72,18 @@ sensible_walks_public_body: created_at: 2008-10-25 10:51:01.161639 api_key: 5 info_requests_count: 1 +other_public_body: + id: 7 + version: 1 + name: 'Another Public Body' + first_letter: A + request_email: other@localhost + short_name: Another Public Body + url_name: another_public_body + notes: More notes + updated_at: 2008-10-25 10:51:01.161639 + last_edit_comment: Another edit + last_edit_editor: louise + created_at: 2008-10-25 10:51:01.161639 + api_key: 6 + info_requests_count: 0 diff --git a/spec/fixtures/public_body_translations.yml b/spec/fixtures/public_body_translations.yml index 24b14c470..61e07fb5b 100644 --- a/spec/fixtures/public_body_translations.yml +++ b/spec/fixtures/public_body_translations.yml @@ -88,3 +88,16 @@ sensible_walks_en_public_body_translation: notes: I bet you’ve never heard of it. publication_scheme: "" disclosure_log: "" + +other_public_body_translation: + id: 8 + public_body_id: 7 + locale: en + name: "Another Public Body" + first_letter: A + request_email: other@localhost + short_name: Another Public Body + url_name: another_public_body + notes: More notes + publication_scheme: "" + disclosure_log: "" diff --git a/spec/fixtures/users.yml b/spec/fixtures/users.yml index d6391c5e8..c9730d855 100644 --- a/spec/fixtures/users.yml +++ b/spec/fixtures/users.yml @@ -1,4 +1,4 @@ -bob_smith_user: +bob_smith_user: id: "1" name: Bob Smith url_name: bob_smith @@ -13,7 +13,7 @@ bob_smith_user: locale: 'en' about_me: 'I like making requests about fancy dogs and naughty chickens and stuff.' receive_email_alerts: true -silly_name_user: +silly_name_user: id: "2" name: "Silly <em>Name</em>" url_name: silly_emnameem @@ -28,7 +28,7 @@ silly_name_user: locale: 'en' about_me: '' receive_email_alerts: true -admin_user: +admin_user: id: "3" name: Joe Admin url_name: joe_admin @@ -43,7 +43,7 @@ admin_user: locale: '' about_me: '' receive_email_alerts: true -unconfirmed_user: +unconfirmed_user: id: "4" name: "Unconfirmed" url_name: unconfirmed @@ -71,3 +71,17 @@ robin_user: ban_text: '' about_me: 'I am the best' receive_email_alerts: true +another_user: + id: 6 + name: Another User + url_name: another_user + email: another@localhost + salt: "-6116981980.392287733335677" + hashed_password: 6b7cd45a5f35fd83febc0452a799530398bfb6e8 # jonespassword + updated_at: 2012-01-01 10:39:15.491593 + created_at: 2012-01-01 10:39:15.491593 + email_confirmed: true + admin_level: 'none' + ban_text: '' + about_me: 'Just another user' + receive_email_alerts: true diff --git a/spec/helpers/link_to_helper_spec.rb b/spec/helpers/link_to_helper_spec.rb index 030fd612d..3e997f9f9 100644 --- a/spec/helpers/link_to_helper_spec.rb +++ b/spec/helpers/link_to_helper_spec.rb @@ -17,27 +17,15 @@ describe LinkToHelper do it 'should return a path like /request/test_title' do - request_url(@mock_request).should == '/request/test_title' + request_path(@mock_request).should == '/request/test_title' end it 'should return a path including any extra parameters passed' do - request_url(@mock_request, {:update_status => 1}).should == '/request/test_title?update_status=1' + request_path(@mock_request, {:update_status => 1}).should == '/request/test_title?update_status=1' end end - describe "when appending something to a URL" do - it 'should append to things without query strings' do - main_url('/a', '.json').should == 'http://test.host/a.json' - end - it 'should append to things with query strings' do - main_url('/a?z=1', '.json').should == 'http://test.host/a.json?z=1' - end - it 'should fail silently with invalid URLs' do - main_url('/a?z=9%', '.json').should == 'http://test.host/a?z=9%' - end - end - describe 'when displaying a user admin link for a request' do it 'should return the text "An anonymous user (external)" in the case where there is no external username' do @@ -48,32 +36,6 @@ describe LinkToHelper do end - describe 'admin_url' do - context 'with no ADMIN_BASE_URL set' do - it 'should prepend the admin general index path to a simple string' do - admin_url('unclassified').should == 'http://test.host/en/admin/unclassified' - end - - it 'should prepend the admin general index path to a deeper URL' do - admin_url('request/show/123').should == 'http://test.host/en/admin/request/show/123' - end - end - - context 'with ADMIN_BASE_URL set' do - before(:each) do - Configuration::should_receive(:admin_base_url).and_return('https://www.example.com/secure/alaveteli-admin/') - end - - it 'should prepend the admin base URL to a simple string' do - admin_url('unclassified').should == 'https://www.example.com/secure/alaveteli-admin/unclassified' - end - - it 'should prepend the admin base URL to a deeper URL' do - admin_url('request/show/123').should == 'https://www.example.com/secure/alaveteli-admin/request/show/123' - end - end - end - describe 'simple_date' do it 'should respect time zones' do Time.use_zone('Australia/Sydney') do diff --git a/spec/models/request_mailer_spec.rb b/spec/models/request_mailer_spec.rb index 09f129bb0..40133eedc 100644 --- a/spec/models/request_mailer_spec.rb +++ b/spec/models/request_mailer_spec.rb @@ -372,15 +372,4 @@ describe RequestMailer, 'requires_admin' do mail.body.should include 'Something has gone wrong' end - context 'has an ADMIN_BASE_URL set' do - before(:each) do - Configuration::should_receive(:admin_base_url).and_return('http://our.proxy.server/admin/alaveteli/') - end - - it 'body should contain the full admin URL' do - mail = RequestMailer.deliver_requires_admin(@info_request) - - mail.body.should include('http://our.proxy.server/admin/alaveteli/request/show/123') - end - end end diff --git a/spec/script/mailin_spec.rb b/spec/script/mailin_spec.rb index f0bca2297..acd06ff3b 100644 --- a/spec/script/mailin_spec.rb +++ b/spec/script/mailin_spec.rb @@ -5,7 +5,7 @@ def mailin_test(email_filename) Dir.chdir Rails.root do xc = ExternalCommand.new("script/mailin") mail = load_file_fixture(email_filename) - ir = info_requests(:boring_request) + ir = info_requests(:other_request) mail.gsub!('EMAIL_TO', ir.incoming_email) mail.gsub!('EMAIL_FROM', 'responder@localhost') xc.run(mail) @@ -16,10 +16,22 @@ end describe "When importing mail into the application" do + # Turn off transactional fixtures for this suite - incoming message is imported + # outside the transaction via ExternalCommand, so needs to be destroyed outside the + # transaction + self.use_transactional_fixtures = false + it "should not produce any output and should return a 0 code on importing a plain email" do r = mailin_test("incoming-request-empty.email") r.status.should == 0 r.out.should == "" end + # Destroy the incoming message so that it doesn't affect other tests + after do + ir = info_requests(:other_request) + incoming_message = ir.incoming_messages[0] + incoming_message.fully_destroy + end + end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 215a4957c..33e39e6e4 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -187,76 +187,12 @@ def get_fixtures_xapian_index() ActsAsXapian.db_path = temp_path end -# Validate an entire HTML page -def validate_html(html) - $tempfilecount = $tempfilecount + 1 - tempfilename = File.join(Dir::tmpdir, "railshtmlvalidate."+$$.to_s+"."+$tempfilecount.to_s+".html") - File.open(tempfilename, "w+") do |f| - f.puts html - end - if not system($html_validation_script, *($html_validation_script_options +[tempfilename])) - raise "HTML validation error in " + tempfilename + " HTTP status: " + @response.response_code.to_s - end - File.unlink(tempfilename) - return true -end - -# Validate HTML fragment by wrapping it as the <body> of a page -def validate_as_body(html) - validate_html('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">' + - "<html><head><title>Test</title></head><body>#{html}</body></html>") -end - def basic_auth_login(request, username = nil, password = nil) username = Configuration::admin_username if username.nil? password = Configuration::admin_password if password.nil? request.env["HTTP_AUTHORIZATION"] = "Basic " + Base64::encode64("#{username}:#{password}") end -# Monkeypatch! Validate HTML in tests. -$html_validation_script_found = false -Configuration::utility_search_path.each do |d| - $html_validation_script = File.join(d, "validate") - $html_validation_script_options = ["--charset=utf-8"] - if File.file? $html_validation_script and File.executable? $html_validation_script - $html_validation_script_found = true - break - end -end -if $tempfilecount.nil? - $tempfilecount = 0 - if $html_validation_script_found - module ActionController - module TestProcess - # Hook into the process function, so can automatically get HTML after each request - alias :original_process :process - def is_fragment - # XXX there must be a better way of doing this! - return @request.query_parameters["action"] == "search_typeahead" - end - def process(action, parameters = nil, session = nil, flash = nil, http_method = 'GET') - self.original_process(action, parameters, session, flash, http_method) - # don't validate auto-generated HTML - return if @request.query_parameters["action"] == "get_attachment_as_html" - # XXX Is there a better way to check this than calling a private method? - return unless @response.template.controller.instance_eval { integrate_views? } - # And then if HTML, not a redirect (302, 301) - if @response.content_type == "text/html" && ! [301,302,401].include?(@response.response_code) - if !is_fragment - validate_html(@response.body) - else - # it's a partial - validate_as_body(@response.body) - end - end - end - end - end - else - puts "WARNING: HTML validation script " + $html_validation_script + " not found" - end -end - # to_ary differs in Ruby 1.8 and 1.9 # @see http://yehudakatz.com/2010/01/02/the-craziest-fing-bug-ive-ever-seen/ def safe_mock_model(model, args = {}) diff --git a/spec/views/public_body/show.rhtml_spec.rb b/spec/views/public_body/show.rhtml_spec.rb index b68b3f43b..23e92dedd 100644 --- a/spec/views/public_body/show.rhtml_spec.rb +++ b/spec/views/public_body/show.rhtml_spec.rb @@ -38,11 +38,6 @@ describe "when viewing a body" do response.should be_success end - it "should be valid HTML" do - render "public_body/show" - validate_as_body response.body - end - it "should show the body's name" do render "public_body/show" response.should have_tag("h1", "Test Quango") diff --git a/spec/views/request/show.rhtml_spec.rb b/spec/views/request/show.rhtml_spec.rb index 4429e9e58..a22f29951 100644 --- a/spec/views/request/show.rhtml_spec.rb +++ b/spec/views/request/show.rhtml_spec.rb @@ -98,7 +98,7 @@ describe 'when viewing an information request' do it 'should show a link to follow up the last response with clarification' do request_page - expected_url = "http://test.host/request/#{@mock_request.id}/response/#{@mock_response.id}#followup" + expected_url = "/request/#{@mock_request.id}/response/#{@mock_response.id}#followup" response.should have_tag("a[href=#{expected_url}]", :text => 'send a follow up message') end @@ -118,7 +118,7 @@ describe 'when viewing an information request' do it 'should show a link to follow up the request without reference to a specific response' do request_page - expected_url = "http://test.host/request/#{@mock_request.id}/response#followup" + expected_url = "/request/#{@mock_request.id}/response#followup" response.should have_tag("a[href=#{expected_url}]", :text => 'send a follow up message') end end |