aboutsummaryrefslogtreecommitdiffstats
path: root/spec/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'spec/controllers')
-rw-r--r--spec/controllers/public_body_controller_spec.rb10
-rw-r--r--spec/controllers/request_controller_spec.rb48
-rw-r--r--spec/controllers/user_controller_spec.rb18
3 files changed, 64 insertions, 12 deletions
diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb
index 8182e1331..3996bd520 100644
--- a/spec/controllers/public_body_controller_spec.rb
+++ b/spec/controllers/public_body_controller_spec.rb
@@ -175,20 +175,20 @@ describe PublicBodyController, "when doing type ahead searches" do
fixtures :public_bodies, :public_body_translations, :public_body_versions, :users, :info_requests, :raw_emails, :incoming_messages, :outgoing_messages, :comments, :info_request_events, :track_things
it "should return nothing for the empty query string" do
- get :search_typeahead, :q => ""
+ get :search_typeahead, :query => ""
response.should render_template('public_body/_search_ahead')
assigns[:xapian_requests].should be_nil
end
it "should return a body matching the given keyword, but not users with a matching description" do
- get :search_typeahead, :q => "Geraldine"
+ get :search_typeahead, :query => "Geraldine"
response.should render_template('public_body/_search_ahead')
assigns[:xapian_requests].results.size.should == 1
assigns[:xapian_requests].results[0][:model].name.should == public_bodies(:geraldine_public_body).name
end
it "should return all requests matching any of the given keywords" do
- get :search_typeahead, :q => "Geraldine Humpadinking"
+ get :search_typeahead, :query => "Geraldine Humpadinking"
response.should render_template('public_body/_search_ahead')
assigns[:xapian_requests].results.size.should == 2
assigns[:xapian_requests].results[0][:model].name.should == public_bodies(:humpadink_public_body).name
@@ -196,14 +196,14 @@ describe PublicBodyController, "when doing type ahead searches" do
end
it "should return requests matching the given keywords in any of their locales" do
- get :search_typeahead, :q => "baguette" # part of the spanish notes
+ get :search_typeahead, :query => "baguette" # part of the spanish notes
response.should render_template('public_body/_search_ahead')
assigns[:xapian_requests].results.size.should == 1
assigns[:xapian_requests].results[0][:model].name.should == public_bodies(:humpadink_public_body).name
end
it "should not return matches for short words" do
- get :search_typeahead, :q => "b"
+ get :search_typeahead, :query => "b"
response.should render_template('public_body/_search_ahead')
assigns[:xapian_requests].should be_nil
end
diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb
index 4994c2a8f..96786a0a3 100644
--- a/spec/controllers/request_controller_spec.rb
+++ b/spec/controllers/request_controller_spec.rb
@@ -158,6 +158,15 @@ describe RequestController, "when showing one request" do
response.should have_text(/Second hello/)
end
+ it "should generate valid HTML verson of PDF attachments " do
+ ir = info_requests(:fancy_dog_request)
+ receive_incoming_mail('incoming-request-pdf-attachment.email', ir.incoming_email)
+ ir.reload
+ get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => ['fs_50379341.pdf.html'], :skip_cache => 1
+ response.content_type.should == "text/html"
+ response.should have_text(/Walberswick Parish Council/)
+ end
+
it "should not cause a reparsing of the raw email, even when the result would be a 404 " do
ir = info_requests(:fancy_dog_request)
receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email)
@@ -287,7 +296,7 @@ describe RequestController, "when showing one request" do
old_path = assigns[:url_path]
response.location.should have_text(/#{assigns[:url_path]}$/)
zipfile = Zip::ZipFile.open(File.join(File.dirname(__FILE__), "../../cache/zips", old_path)) { |zipfile|
- zipfile.count.should == 2
+ zipfile.count.should == 1 # just the message
}
receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email)
get :download_entire_request, :url_title => title
@@ -295,14 +304,14 @@ describe RequestController, "when showing one request" do
old_path = assigns[:url_path]
response.location.should have_text(/#{assigns[:url_path]}$/)
zipfile = Zip::ZipFile.open(File.join(File.dirname(__FILE__), "../../cache/zips", old_path)) { |zipfile|
- zipfile.count.should == 2
+ zipfile.count.should == 3 # the message plus two "hello.txt" files
}
receive_incoming_mail('incoming-request-attachment-unknown-extension.email', ir.incoming_email)
get :download_entire_request, :url_title => title
assigns[:url_path].should have_text(/#{title}.zip$/)
response.location.should have_text(/#{assigns[:url_path]}/)
zipfile = Zip::ZipFile.open(File.join(File.dirname(__FILE__), "../../cache/zips", assigns[:url_path])) { |zipfile|
- zipfile.count.should == 4
+ zipfile.count.should == 5 # the message, two hello.txt, the unknown attachment, and its empty message
}
assigns[:url_path].should_not == old_path
end
@@ -411,7 +420,7 @@ describe RequestController, "when searching for an authority" do
get :select_authority, :query => ""
response.should render_template('select_authority')
- assigns[:xapian_requests].results.size == 0
+ assigns[:xapian_requests].should == nil
end
it "should return matching bodies" do
@@ -422,6 +431,18 @@ describe RequestController, "when searching for an authority" do
assigns[:xapian_requests].results.size == 1
assigns[:xapian_requests].results[0][:model].name.should == public_bodies(:geraldine_public_body).name
end
+
+ it "should not give an error when user users unintended search operators" do
+ for phrase in ["Marketing/PR activities - Aldborough E-Act Free Schoo",
+ "Request for communications between DCMS/Ed Vaizey and ICO from Jan 1st 2011 - May ",
+ "Bellevue Road Ryde Isle of Wight PO33 2AR - what is the",
+ "NHS Ayrshire & Arran",
+ " cardiff"]
+ lambda {
+ get :select_authority, :query => phrase
+ }.should_not raise_error(StandardError)
+ end
+ end
end
describe RequestController, "when creating a new request" do
@@ -1478,11 +1499,28 @@ describe RequestController, "when doing type ahead searches" do
assigns[:xapian_requests].results[1][:model].title.should == info_requests(:naughty_chicken_request).title
end
- it "should not return matches for short words" do
+ it "should not return matches for short words" do
get :search_typeahead, :q => "a"
response.should render_template('request/_search_ahead.rhtml')
assigns[:xapian_requests].should be_nil
end
+
+ it "should not give an error when user users unintended search operators" do
+ for phrase in ["Marketing/PR activities - Aldborough E-Act Free Schoo",
+ "Request for communications between DCMS/Ed Vaizey and ICO from Jan 1st 2011 - May ",
+ "Bellevue Road Ryde Isle of Wight PO33 2AR - what is the",
+ "NHS Ayrshire & Arran"]
+ lambda {
+ get :search_typeahead, :q => phrase
+ }.should_not raise_error(StandardError)
+ end
+ end
+
+ it "should return all requests matching any of the given keywords" do
+ get :search_typeahead, :q => "dog -chicken"
+ assigns[:xapian_requests].results.size.should == 1
+ end
+
end
diff --git a/spec/controllers/user_controller_spec.rb b/spec/controllers/user_controller_spec.rb
index cf50bcc7a..30ad61706 100644
--- a/spec/controllers/user_controller_spec.rb
+++ b/spec/controllers/user_controller_spec.rb
@@ -32,10 +32,10 @@ describe UserController, "when showing a user" do
session[:user_id] = users(:bob_smith_user).id
get :show, :url_name => "bob_smith", :view => 'requests'
response.body.should_not include("Change your password")
- response.body.should include("Freedom of Information requests")
+ response.body.should match(/Your [0-9]+ Freedom of Information requests/)
get :show, :url_name => "bob_smith", :view => 'profile'
response.body.should include("Change your password")
- response.body.should_not include("Freedom of Information requests")
+ response.body.should_not match(/Your [0-9]+ Freedom of Information requests/)
end
it "should assign the user" do
@@ -109,6 +109,20 @@ describe UserController, "when signing in" do
response.should_not send_email
end
+ it "should not log you in if you use an invalid PostRedirect token, and shouldn't give 500 error either" do
+ ActionController::Routing::Routes.filters.clear
+ post_redirect = "something invalid"
+ lambda {
+ post :signin, { :user_signin => { :email => 'bob@localhost', :password => 'jonespassword' },
+ :token => post_redirect
+ }
+ }.should_not raise_error(NoMethodError)
+ post :signin, { :user_signin => { :email => 'bob@localhost', :password => 'jonespassword' },
+ :token => post_redirect }
+ response.should render_template('sign')
+ assigns[:post_redirect].should == nil
+ end
+
# No idea how to test this in the test framework :(
# it "should have set a long lived cookie if they picked remember me, session cookie if they didn't" do
# get :signin, :r => "/list"