aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/admin_censor_rule_controller_spec.rb10
-rw-r--r--spec/controllers/public_body_controller_spec.rb5
-rw-r--r--spec/controllers/request_controller_spec.rb4
-rw-r--r--spec/controllers/track_controller_spec.rb3
-rw-r--r--spec/fixtures/files/incoming-request-empty.email8
-rw-r--r--spec/fixtures/info_request_events.yml11
-rw-r--r--spec/fixtures/info_requests.yml12
-rw-r--r--spec/fixtures/outgoing_messages.yml11
-rw-r--r--spec/fixtures/public_bodies.yml15
-rw-r--r--spec/fixtures/public_body_translations.yml13
-rw-r--r--spec/fixtures/users.yml22
-rw-r--r--spec/helpers/link_to_helper_spec.rb42
-rw-r--r--spec/models/purge_request_spec.rb9
-rw-r--r--spec/models/request_mailer_spec.rb34
-rw-r--r--spec/script/mailin-spec.rb21
-rw-r--r--spec/script/mailin_spec.rb37
-rw-r--r--spec/spec_helper.rb77
-rw-r--r--spec/views/public_body/show.rhtml_spec.rb5
-rw-r--r--spec/views/request/show.rhtml_spec.rb4
19 files changed, 185 insertions, 158 deletions
diff --git a/spec/controllers/admin_censor_rule_controller_spec.rb b/spec/controllers/admin_censor_rule_controller_spec.rb
index 8893a858b..fb9ddf594 100644
--- a/spec/controllers/admin_censor_rule_controller_spec.rb
+++ b/spec/controllers/admin_censor_rule_controller_spec.rb
@@ -2,10 +2,14 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe AdminCensorRuleController, "when making censor rules from the admin interface" do
integrate_views
- before { basic_auth_login @request }
-
+ before do
+ basic_auth_login @request
+ PurgeRequest.destroy_all
+ end
+
+
it "should create a censor rule and purge the corresponding request from varnish" do
- ir = info_requests(:fancy_dog_request)
+ ir = info_requests(:fancy_dog_request)
post :create, :censor_rule => {
:text => "meat",
:replacement => "tofu",
diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb
index 29ece18cb..5f4012737 100644
--- a/spec/controllers/public_body_controller_spec.rb
+++ b/spec/controllers/public_body_controller_spec.rb
@@ -67,6 +67,11 @@ describe PublicBodyController, "when showing a body" do
ActionController::Routing::Routes.filters = old_filters
end
+ it "should remember the filter (view) setting on redirecting" do
+ get :show, :show_locale => "es", :url_name => "tgq", :view => 'successful'
+ response.should redirect_to show_public_body_successful_url(:url_name => "etgq")
+ end
+
it "should redirect to newest name if you use historic name of public body in URL" do
get :show, :url_name => "hdink", :view => 'all'
response.should redirect_to(:controller => 'public_body', :action => 'show', :url_name => "dfh")
diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb
index 6f25b605a..21dd0853a 100644
--- a/spec/controllers/request_controller_spec.rb
+++ b/spec/controllers/request_controller_spec.rb
@@ -121,7 +121,9 @@ end
describe RequestController, "when changing things that appear on the request page" do
- integrate_views
+ before do
+ PurgeRequest.destroy_all
+ end
it "should purge the downstream cache when mail is received" do
ir = info_requests(:fancy_dog_request)
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/files/incoming-request-empty.email b/spec/fixtures/files/incoming-request-empty.email
new file mode 100644
index 000000000..890a14f21
--- /dev/null
+++ b/spec/fixtures/files/incoming-request-empty.email
@@ -0,0 +1,8 @@
+From: EMAIL_FROM
+To: FOI Person <EMAIL_TO>
+Bcc:
+Subject: Re: Nothing to see here.
+Reply-To:
+In-Reply-To: <471f1eae5d1cb_7347..fdbe67386163@cat.tmail>
+
+
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/purge_request_spec.rb b/spec/models/purge_request_spec.rb
index 94fe01317..7b67fca52 100644
--- a/spec/models/purge_request_spec.rb
+++ b/spec/models/purge_request_spec.rb
@@ -1,12 +1,13 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
require 'fakeweb'
-describe PurgeRequest, "purging things" do
+describe PurgeRequest, "purging things" do
before do
+ PurgeRequest.destroy_all
FakeWeb.last_request = nil
end
- it 'should issue purge requests to the server' do
+ it 'should issue purge requests to the server' do
req = PurgeRequest.new(:url => "/begone_from_here",
:model => "don't care",
:model_id => "don't care")
@@ -16,7 +17,7 @@ describe PurgeRequest, "purging things" do
PurgeRequest.all().count.should == 0
end
- it 'should fail silently for a misconfigured server' do
+ it 'should fail silently for a misconfigured server' do
FakeWeb.register_uri(:get, %r|brokenv|, :body => "BROKEN")
config = MySociety::Config.load_default()
config['VARNISH_HOST'] = "brokencache"
@@ -29,4 +30,4 @@ describe PurgeRequest, "purging things" do
PurgeRequest.all().count.should == 0
end
end
-
+
diff --git a/spec/models/request_mailer_spec.rb b/spec/models/request_mailer_spec.rb
index 5edc8edb6..dd5a322fb 100644
--- a/spec/models/request_mailer_spec.rb
+++ b/spec/models/request_mailer_spec.rb
@@ -1,3 +1,4 @@
+# encoding: utf-8
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe RequestMailer, " when receiving incoming mail" do
@@ -327,6 +328,27 @@ describe RequestMailer, 'when sending mail when someone has updated an old uncla
end
+
+describe RequestMailer, 'when sending a new response email' do
+
+ before do
+ @user = mock_model(User, :name_and_email => 'test name and email')
+ @public_body = mock_model(PublicBody, :name => 'Test public body')
+ @info_request = mock_model(InfoRequest, :user => @user,
+ :law_used_full => 'Freedom of Information',
+ :title => 'Here is a character that needs quoting …',
+ :public_body => @public_body,
+ :display_status => 'Refused.',
+ :url_title => 'test_request')
+ @incoming_message = mock_model(IncomingMessage, :info_request => @info_request)
+ end
+
+ it 'should not error when sending mails requests with characters requiring quoting in the subject' do
+ @mail = RequestMailer.create_new_response(@info_request, @incoming_message)
+ end
+
+end
+
describe RequestMailer, 'requires_admin' do
before(:each) do
user = mock_model(User, :name_and_email => 'Bruce Jones',
@@ -344,16 +366,4 @@ describe RequestMailer, 'requires_admin' do
mail.body.should include('http://test.host/en/admin/request/show/123')
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
deleted file mode 100644
index d80789635..000000000
--- a/spec/script/mailin-spec.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
-require "external_command"
-
-def mailin_test(email_filename)
- Dir.chdir Rails.root do
- xc = ExternalCommand.new("script/mailin")
- xc.run(load_file_fixture(email_filename))
- xc.err.should == ""
- return xc
- end
-end
-
-describe "When importing mail into the application" do
-
- it "should not produce any output and should return a 0 code on importing a plain email" do
- r = mailin_test("incoming-request-plain.email")
- r.status.should == 0
- r.out.should == ""
- end
-
-end \ No newline at end of file
diff --git a/spec/script/mailin_spec.rb b/spec/script/mailin_spec.rb
new file mode 100644
index 000000000..acd06ff3b
--- /dev/null
+++ b/spec/script/mailin_spec.rb
@@ -0,0 +1,37 @@
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+require "external_command"
+
+def mailin_test(email_filename)
+ Dir.chdir Rails.root do
+ xc = ExternalCommand.new("script/mailin")
+ mail = load_file_fixture(email_filename)
+ ir = info_requests(:other_request)
+ mail.gsub!('EMAIL_TO', ir.incoming_email)
+ mail.gsub!('EMAIL_FROM', 'responder@localhost')
+ xc.run(mail)
+ xc.err.should == ""
+ return xc
+ end
+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 561a75da6..e05ef75dd 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -1,3 +1,16 @@
+require 'simplecov'
+require 'coveralls'
+
+# Generate coverage locally in html as well as in coveralls.io
+SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
+ SimpleCov::Formatter::HTMLFormatter,
+ Coveralls::SimpleCov::Formatter
+]
+SimpleCov.start('rails') do
+ add_filter 'commonlib'
+ add_filter 'vendor/plugins'
+end
+
# This file is copied to ~/spec when you run 'ruby script/generate rspec'
# from the project root directory.
ENV["RAILS_ENV"] = 'test'
@@ -173,76 +186,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