aboutsummaryrefslogtreecommitdiffstats
path: root/spec/controllers
diff options
context:
space:
mode:
authorRobin Houston <robin.houston@gmail.com>2012-01-29 16:35:06 +0000
committerRobin Houston <robin.houston@gmail.com>2012-01-29 16:35:06 +0000
commit9613b118b148dff0d54100d7f931189b59f3535c (patch)
treeed9334c8905aac38f96de6eca1ade8fcfa6f1a54 /spec/controllers
parent5aa2bd13042110e73212f83564c35b3a1d672bbb (diff)
More test data, and fix tests
Add some more test data, and fix the tests to accommodate both this new test data and the fact that raw emails are now correctly loaded into the test environment.
Diffstat (limited to 'spec/controllers')
-rw-r--r--spec/controllers/general_controller_spec.rb22
-rw-r--r--spec/controllers/public_body_controller_spec.rb15
-rw-r--r--spec/controllers/request_controller_spec.rb35
-rw-r--r--spec/controllers/user_controller_spec.rb8
4 files changed, 53 insertions, 27 deletions
diff --git a/spec/controllers/general_controller_spec.rb b/spec/controllers/general_controller_spec.rb
index 8eb445146..00239c14e 100644
--- a/spec/controllers/general_controller_spec.rb
+++ b/spec/controllers/general_controller_spec.rb
@@ -158,21 +158,31 @@ describe GeneralController, "when searching" do
it "should filter results based on end of URL being 'all'" do
get :search, :combined => ['"bob"', "all"]
- assigns[:xapian_requests].results.size.should == 2
- assigns[:xapian_users].results.size.should == 1
- assigns[:xapian_bodies].results.size.should == 0
+ assigns[:xapian_requests].results.map{|x| x[:model]}.should =~ [
+ info_request_events(:useless_outgoing_message_event),
+ info_request_events(:silly_outgoing_message_event),
+ info_request_events(:useful_incoming_message_event),
+ info_request_events(:another_useful_incoming_message_event),
+ ]
+ assigns[:xapian_users].results.map{|x| x[:model]}.should == [users(:bob_smith_user)]
+ assigns[:xapian_bodies].results.should == []
end
it "should filter results based on end of URL being 'users'" do
get :search, :combined => ['"bob"', "users"]
assigns[:xapian_requests].should == nil
- assigns[:xapian_users].results.size.should == 1
+ assigns[:xapian_users].results.map{|x| x[:model]}.should == [users(:bob_smith_user)]
assigns[:xapian_bodies].should == nil
end
it "should filter results based on end of URL being 'requests'" do
get :search, :combined => ['"bob"', "requests"]
- assigns[:xapian_requests].results.size.should == 2
+ assigns[:xapian_requests].results.map{|x|x[:model]}.should =~ [
+ info_request_events(:useless_outgoing_message_event),
+ info_request_events(:silly_outgoing_message_event),
+ info_request_events(:useful_incoming_message_event),
+ info_request_events(:another_useful_incoming_message_event),
+ ]
assigns[:xapian_users].should == nil
assigns[:xapian_bodies].should == nil
end
@@ -181,7 +191,7 @@ describe GeneralController, "when searching" do
get :search, :combined => ['"quango"', "bodies"]
assigns[:xapian_requests].should == nil
assigns[:xapian_users].should == nil
- assigns[:xapian_bodies].results.size.should == 1
+ assigns[:xapian_bodies].results.map{|x|x[:model]}.should == [public_bodies(:geraldine_public_body)]
end
it "should show help when searching for nothing" do
diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb
index bf9888685..a285a8900 100644
--- a/spec/controllers/public_body_controller_spec.rb
+++ b/spec/controllers/public_body_controller_spec.rb
@@ -199,6 +199,11 @@ 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
integrate_views
+
+ before(:each) do
+ load_raw_emails_data
+ rebuild_xapian_index
+ end
it "should return nothing for the empty query string" do
get :search_typeahead, :query => ""
@@ -217,16 +222,16 @@ describe PublicBodyController, "when doing type ahead searches" do
it "should return all requests matching any of the given keywords" do
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
- assigns[:xapian_requests].results[1][:model].name.should == public_bodies(:geraldine_public_body).name
+ assigns[:xapian_requests].results.map{|x|x[:model]}.should =~ [
+ public_bodies(:humpadink_public_body),
+ public_bodies(:geraldine_public_body),
+ ]
end
it "should return requests matching the given keywords in any of their locales" do
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
+ assigns[:xapian_requests].results.map{|x|x[:model]}.should =~ [public_bodies(:humpadink_public_body)]
end
it "should not return matches for short words" do
diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb
index e43d8ea3d..77652b26d 100644
--- a/spec/controllers/request_controller_spec.rb
+++ b/spec/controllers/request_controller_spec.rb
@@ -209,7 +209,8 @@ describe RequestController, "when showing one request" do
it "should download attachments" do
ir = info_requests(:fancy_dog_request)
- ir.incoming_messages.each { |x| x.parse_raw_email! }
+ ir.incoming_messages.each { |x| x.parse_raw_email!(true) }
+
get :show, :url_title => 'why_do_you_have_such_a_fancy_dog'
response.content_type.should == "text/html"
size_before = assigns[:info_request_events].size
@@ -221,11 +222,11 @@ describe RequestController, "when showing one request" do
(assigns[:info_request_events].size - size_before).should == 1
ir.reload
- get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => ['hello.txt']
+ get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => ['hello.txt'], :skip_cache => 1
response.content_type.should == "text/plain"
response.should have_text(/Second hello/)
- get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 3, :file_name => ['hello.txt']
+ get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 3, :file_name => ['hello.txt'], :skip_cache => 1
response.content_type.should == "text/plain"
response.should have_text(/First hello/)
end
@@ -321,7 +322,7 @@ describe RequestController, "when showing one request" do
receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email)
lambda {
- get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2,
+ get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2,
:file_name => ['http://trying.to.hack']
}.should raise_error(ActiveRecord::RecordNotFound)
end
@@ -335,12 +336,16 @@ describe RequestController, "when showing one request" do
censor_rule.last_edit_editor = "unknown"
censor_rule.last_edit_comment = "none"
ir.censor_rules << censor_rule
+
+ begin
+ receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email)
- receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email)
-
- get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => ['hello.txt']
- response.content_type.should == "text/plain"
- response.should have_text(/xxxxxx hello/)
+ get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => ['hello.txt'], :skip_cache => 1
+ response.content_type.should == "text/plain"
+ response.should have_text(/xxxxxx hello/)
+ ensure
+ ir.censor_rules.clear
+ end
end
it "should censor with rules on the user (rather than the request)" do
@@ -507,11 +512,11 @@ describe RequestController, "when changing prominence of a request" do
ir.save!
receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email)
- get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2
+ get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :skip_cache => 1
response.content_type.should == "text/html"
response.should_not have_text(/Second hello/)
response.should render_template('request/hidden')
- get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 3
+ get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 3, :skip_cache => 1
response.content_type.should == "text/html"
response.should_not have_text(/First hello/)
response.should render_template('request/hidden')
@@ -1621,9 +1626,11 @@ describe RequestController, "when doing type ahead searches" do
it "should return all requests matching any of the given keywords" do
get :search_typeahead, :q => "money dog"
response.should render_template('request/_search_ahead.rhtml')
- assigns[:xapian_requests].results.size.should == 2
- assigns[:xapian_requests].results[0][:model].title.should == info_requests(:fancy_dog_request).title
- assigns[:xapian_requests].results[1][:model].title.should == info_requests(:naughty_chicken_request).title
+ assigns[:xapian_requests].results.map{|x|x[:model].info_request}.should =~ [
+ info_requests(:fancy_dog_request),
+ info_requests(:naughty_chicken_request),
+ info_requests(:another_boring_request),
+ ]
end
it "should not return matches for short words" do
diff --git a/spec/controllers/user_controller_spec.rb b/spec/controllers/user_controller_spec.rb
index 101fb716e..4e14aeaa3 100644
--- a/spec/controllers/user_controller_spec.rb
+++ b/spec/controllers/user_controller_spec.rb
@@ -46,10 +46,14 @@ describe UserController, "when showing a user" do
it "should search the user's contributions" do
get :show, :url_name => "bob_smith"
- assigns[:xapian_requests].results.map{|x|x[:model].info_request}.should =~ InfoRequest.all(:conditions => "user_id = #{users(:bob_smith_user).id}")
+ assigns[:xapian_requests].results.map{|x|x[:model].info_request}.should =~ InfoRequest.all(
+ :conditions => "user_id = #{users(:bob_smith_user).id}")
get :show, :url_name => "bob_smith", :user_query => "money"
- assigns[:xapian_requests].results.map{|x|x[:model].info_request}.should == [info_requests(:naughty_chicken_request)]
+ assigns[:xapian_requests].results.map{|x|x[:model].info_request}.should =~ [
+ info_requests(:naughty_chicken_request),
+ info_requests(:another_boring_request),
+ ]
end
it "should not show unconfirmed users" do