aboutsummaryrefslogtreecommitdiffstats
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
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.
-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
-rw-r--r--spec/fixtures/files/raw_emails/3.email19
-rw-r--r--spec/fixtures/incoming_messages.yml4
-rw-r--r--spec/fixtures/info_request_events.yml12
-rw-r--r--spec/fixtures/public_bodies.yml2
-rw-r--r--spec/fixtures/raw_emails.yml9
-rw-r--r--spec/integration/search_request_spec.rb23
10 files changed, 108 insertions, 41 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
diff --git a/spec/fixtures/files/raw_emails/3.email b/spec/fixtures/files/raw_emails/3.email
new file mode 100644
index 000000000..a6e780fe5
--- /dev/null
+++ b/spec/fixtures/files/raw_emails/3.email
@@ -0,0 +1,19 @@
+From: "The Minister" <msw@localhost>
+To: "Bob Smith" <bob@localhost>
+Date: Tue, 13 Nov 2009 11:39:55 +0000
+Bcc:
+Subject: Re: Your message
+Reply-To:
+In-Reply-To: <471f1eae5d1cb_7347..fdbe67386165@cat.tmail>
+Content-Type: text/plain; charset=utf-8
+
+Dear “Bob”,
+
+In the financial year 2010–2011, this Ministry spent precisely
+no money at all on the purchase or repair of boring equipment.
+
+Yours most sincerely,
+
+Martin Kibble-von Scratsching,
+Chief Assistant to the Assistant Chief,
+Ministry of Silly Walks
diff --git a/spec/fixtures/incoming_messages.yml b/spec/fixtures/incoming_messages.yml
index a32052413..918d4fd11 100644
--- a/spec/fixtures/incoming_messages.yml
+++ b/spec/fixtures/incoming_messages.yml
@@ -14,7 +14,7 @@ useful_incoming_message:
another_useful_incoming_message:
id: 3
- info_request_id: 105
- raw_email_id: 2
+ info_request_id: 106
+ raw_email_id: 3
created_at: 2007-11-13 18:09:20
updated_at: 2007-11-13 18:09:20
diff --git a/spec/fixtures/info_request_events.yml b/spec/fixtures/info_request_events.yml
index ec6abbf57..3fdeb16e9 100644
--- a/spec/fixtures/info_request_events.yml
+++ b/spec/fixtures/info_request_events.yml
@@ -1,37 +1,37 @@
useless_outgoing_message_event:
+ id: 900
params_yaml: "--- \n\
:outgoing_message_id: 1\n"
- id: 900
info_request_id: 101
event_type: sent
created_at: 2007-10-12 01:56:58.586598
described_state:
outgoing_message_id: 1
silly_outgoing_message_event:
+ id: 901
params_yaml: "--- \n\
:outgoing_message_id: 2\n"
- id: 901
info_request_id: 103
event_type: sent
created_at: 2007-10-14 10:41:12.686264
described_state:
outgoing_message_id: 2
useless_incoming_message_event:
+ id: 902
params_yaml: "--- \n\
:incoming_message_id: 1\n"
- id: 902
info_request_id: 101
event_type: response
created_at: 2007-11-13 18:09:20.042061
described_state:
incoming_message_id: 1
silly_comment_event:
+ id: 903
params_yaml: "--- \n\
:comment_id: 1\n"
incoming_message_id:
last_described_at:
described_state:
- id: "903"
info_request_id: 101
comment_id: 1
calculated_state:
@@ -39,9 +39,9 @@ silly_comment_event:
outgoing_message_id:
created_at: 2008-08-12 23:05:12.500942
badger_outgoing_message_event:
+ id: 904
params_yaml: "--- \n\
:outgoing_message_id: 3\n"
- id: 904
info_request_id: 104
event_type: sent
created_at: 2011-10-12 01:56:58.586598
@@ -92,7 +92,7 @@ another_useful_incoming_message_event:
described_state: successful
calculated_state: successful
-another_comment_event:
+another_comment_event:
id: 909
info_request_id: 105
comment_id: 2
diff --git a/spec/fixtures/public_bodies.yml b/spec/fixtures/public_bodies.yml
index 737fe203f..2ac99f99e 100644
--- a/spec/fixtures/public_bodies.yml
+++ b/spec/fixtures/public_bodies.yml
@@ -16,7 +16,7 @@ humpadink_public_body:
updated_at: 2007-10-25 10:51:01.161639
last_edit_comment: Not sure what this new department does.
request_email: humpadink-requests@localhost
- id: "3"
+ id: 3
version: "2"
last_edit_editor: "francis"
short_name: DfH
diff --git a/spec/fixtures/raw_emails.yml b/spec/fixtures/raw_emails.yml
index 32e039cab..6c5b6a6bb 100644
--- a/spec/fixtures/raw_emails.yml
+++ b/spec/fixtures/raw_emails.yml
@@ -1,5 +1,14 @@
+# The actual email messages are in fixtures/files/raw_emails
+#
+# Note that the words "money" and "bob" are used in some tests
+# of the search functions, so if you use either of these words
+# in the email text then some tests will have to be updated.
+
useless_raw_email:
id: 1
useful_raw_email:
id: 2
+
+another_useful_raw_email:
+ id: 3
diff --git a/spec/integration/search_request_spec.rb b/spec/integration/search_request_spec.rb
index 317a3cab7..61f8df313 100644
--- a/spec/integration/search_request_spec.rb
+++ b/spec/integration/search_request_spec.rb
@@ -34,21 +34,34 @@ describe "When searching" do
end
it "should correctly filter searches for requests" do
- request_via_redirect("post", "/search/bob/requests")
+ request_via_redirect("post", "/search/bob/requests")
response.body.should_not include("One person found")
- response.body.should include("FOI requests 1 to 2 of 2")
+ n = 4 # The number of requests that contain the word "bob" somewhere
+ # in the email text. At present this is:
+ # - fancy_dog_request
+ # - naughty_chicken_request
+ # - boring_request
+ # - another_boring_request
+ #
+ # In other words it is all requests made by Bob Smith
+ # except for badger_request, which he did not sign.
+ response.body.should include("FOI requests 1 to #{n} of #{n}")
end
it "should correctly filter searches for users" do
- request_via_redirect("post", "/search/bob/users")
+ request_via_redirect("post", "/search/bob/users")
response.body.should include("One person found")
- response.body.should_not include("FOI requests 1 to 2 of 2")
+ response.body.should_not include("FOI requests 1 to")
end
it "should correctly filter searches for successful requests" do
request_via_redirect("post", "/search/requests",
:query => "bob",
:latest_status => ['successful'])
- response.body.should include("no results matching your query")
+ n = 2 # The number of *successful* requests that contain the word "bob" somewhere
+ # in the email text. At present this is:
+ # - boring_request
+ # - another_boring_request
+ response.body.should include("FOI requests 1 to #{n} of #{n}")
end
it "should correctly filter searches for comments" do