aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/admin_public_body_controller.rb2
-rw-r--r--app/views/general/frontpage.rhtml62
-rw-r--r--public/stylesheets/main.css52
-rw-r--r--spec/controllers/admin_public_body_controller_spec.rb73
-rw-r--r--spec/controllers/general_controller_spec.rb12
-rw-r--r--spec/controllers/public_body_controller_spec.rb30
-rw-r--r--spec/controllers/request_controller_spec.rb59
-rw-r--r--spec/controllers/user_controller_spec.rb17
-rw-r--r--spec/fixtures/incoming_messages.yml16
-rw-r--r--spec/fixtures/info_request_events.yml27
-rw-r--r--spec/fixtures/info_requests.yml15
-rw-r--r--spec/fixtures/outgoing_messages.yml10
-rw-r--r--spec/fixtures/public_bodies.yml13
-rw-r--r--spec/fixtures/public_body_translations.yml19
-rw-r--r--spec/fixtures/raw_emails.yml3
-rw-r--r--spec/models/public_body_spec.rb44
-rw-r--r--spec/models/xapian_spec.rb28
17 files changed, 316 insertions, 166 deletions
diff --git a/app/controllers/admin_public_body_controller.rb b/app/controllers/admin_public_body_controller.rb
index 0c24d47c1..c6904da95 100644
--- a/app/controllers/admin_public_body_controller.rb
+++ b/app/controllers/admin_public_body_controller.rb
@@ -27,7 +27,7 @@ class AdminPublicBodyController < AdminController
end
@public_bodies = PublicBody.paginate :order => "public_body_translations.name", :page => @page, :per_page => 100,
:conditions => @query.nil? ? "public_body_translations.locale = '#{@locale}'" :
- ["(lower(public_body_translations.name) like lower('%'||?||'%') or
+ ["(lower(public_body_translations.name) like lower('%'||?||'%') or
lower(public_body_translations.short_name) like lower('%'||?||'%') or
lower(public_body_translations.request_email) like lower('%'||?||'%' )) AND (public_body_translations.locale = '#{@locale}')", @query, @query, @query],
:joins => :translations
diff --git a/app/views/general/frontpage.rhtml b/app/views/general/frontpage.rhtml
index da45a8c37..38133e7ab 100644
--- a/app/views/general/frontpage.rhtml
+++ b/app/views/general/frontpage.rhtml
@@ -12,20 +12,20 @@
<div id="right_column">
<div id="frontpage_search_box">
<h2>
- <%= _("Search over<br/>
+ <%= _("Search over<br/>
<strong>{{number_of_requests}} requests</strong> <span>and</span><br/>
<strong>{{number_of_authorities}} authorities</strong>",
- :number_of_requests => InfoRequest.count, :number_of_authorities => PublicBody.count) %>
+ :number_of_requests => InfoRequest.count, :number_of_authorities => PublicBody.count) %>
</h2>
<% form_tag({:action => "search_redirect"}, {:id => "search_form"}) do %>
- <div>
- <%= text_field_tag 'query', params[:query], { :size => 30 } %>
- <%= submit_tag _('Search') %>
- </div>
+ <div>
+ <%= text_field_tag 'query', params[:query], { :size => 30 } %>
+ <%= submit_tag _('Search') %>
+ </div>
<% end %>
</div>
<div id="frontpage_right_to_know">
- <%= render :partial => 'frontpage_intro_sentence' %>
+ <%= render :partial => 'frontpage_intro_sentence' %>
</div>
</div>
<div style="clear:both"></div>
@@ -34,38 +34,38 @@
<div id="frontpage_examples">
<% if @popular_bodies.size > 0 %>
<div id="examples_0">
- <h3><%= _("Who can I request information from?") %></h3>
- <%= _("{{site_name}} covers requests to {{number_of_authorities}} authorities, including:",
- :site_name => site_name, :number_of_authorities => PublicBody.count) %>
- <ul>
+ <h3><%= _("Who can I request information from?") %></h3>
+ <%= _("{{site_name}} covers requests to {{number_of_authorities}} authorities, including:",
+ :site_name => site_name, :number_of_authorities => PublicBody.count) %>
+ <ul>
<% for popular_body in @popular_bodies %>
<li><%=public_body_link(popular_body)%>
<%= n_('%d request', '%d requests', popular_body.info_requests.count) % popular_body.info_requests.count %>
</li>
<% end%>
- </ul>
- <p><strong>
- <%= link_to _('Browse all authorities...'), list_public_bodies_default %>
- </strong></p>
- </div>
+ </ul>
+ <p><strong>
+ <%= link_to _('Browse all authorities...'), list_public_bodies_default %>
+ </strong></p>
+ </div>
<% end %>
- <div id="examples_1">
- <h3><%= _("What information has been released?") %></h3>
- <%= _("{{site_name}} users have made {{number_of_requests}} requests, including:",
- :site_name => site_name, :number_of_requests => InfoRequest.count) %>
- <ul>
- <% for event in @request_events %>
- <li>
- <%= public_body_link(event.info_request.public_body) %> <%= _('answered a request about') %>
- <%=link_to h(event.info_request.title), request_url(event.info_request)%>
+ <div id="examples_1">
+ <h3><%= _("What information has been released?") %></h3>
+ <%= _("{{site_name}} users have made {{number_of_requests}} requests, including:",
+ :site_name => site_name, :number_of_requests => InfoRequest.count) %>
+ <ul>
+ <% for event in @request_events %>
+ <li>
+ <%= public_body_link(event.info_request.public_body) %> <%= _('answered a request about') %>
+ <%=link_to h(event.info_request.title), request_url(event.info_request)%>
<%= _('{{length_of_time}} ago', :length_of_time => time_ago_in_words(event.described_at)) %>
- <p class="excerpt" onclick="document.location.href='<%=request_url(event.info_request)%>'"><%= excerpt(event.search_text_main(true), "", 200) %></p>
- </li>
- <% end %>
- </ul>
- <p><strong><%=link_to _('More successful requests...'), request_list_successful_url %></strong></p>
- </div>
+ <p class="excerpt" onclick="document.location.href='<%=request_url(event.info_request)%>'"><%= excerpt(event.search_text_main(true), "", 200) %></p>
+ </li>
+ <% end %>
+ </ul>
+ <p><strong><%=link_to _('More successful requests...'), request_list_successful_url %></strong></p>
+ </div>
</div>
diff --git a/public/stylesheets/main.css b/public/stylesheets/main.css
index ad55af570..cd617c115 100644
--- a/public/stylesheets/main.css
+++ b/public/stylesheets/main.css
@@ -2,7 +2,7 @@ body {
text-align:center;
color:#444;
font-size:15px;
-font-family:Arial, sans-serif;
+font-family: sans-serif;
margin:0;
padding:0;
}
@@ -78,8 +78,8 @@ margin:0;
padding:0;
}
-#topnav li a:hover {
-color:#000;
+#topnav li a:hover, a:hover {
+color:purple;
}
#logged_in_bar {
@@ -87,7 +87,7 @@ clear:none;
font-size:0.9em;
z-index:200;
color:#444;
-top:18px;
+top:14px;
right:22em;
float:none;
position:absolute;
@@ -423,7 +423,7 @@ border-width:1px;
padding:0.2em;
}
-#notice, {
+#notice, .notice {
color:#16C132;
font-size:1.4em;
font-weight:700;
@@ -664,14 +664,14 @@ margin-left:25%;
}
#signup .form_item_note,#signin .form_note {
-font-size:0.8em;
+font-size:0.9em;
margin-left:11.5em;
width:24em;
}
div.controller_help dt a,div.controller_help h1 a,div#help_unhappy h1 a.hover_a {
text-decoration:none;
-font-size:0.8em;
+font-size:0.9em;
background-color:#fff;
}
@@ -731,7 +731,7 @@ margin:0.5em 0;
float:right;
clear:none;
width:20em;
-font-size:0.8em;
+font-size:0.9em;
margin:0 0 2em 2em;
}
@@ -791,13 +791,13 @@ padding:0.5em 1em;
#user_public_banned .details {
margin-left:4em;
margin-right:4em;
-font-size:0.8em;
+font-size:0.9em;
font-style:italic;
}
div.lang {
text-align:right;
-font-size:0.8em;
+font-size:0.9em;
right:0;
z-index:200;
top:40px;
@@ -850,7 +850,7 @@ margin-top:1em;
}
.form_explanation,div[id|="comment"] p {
-font-size:0.8em;
+font-size:0.9em;
}
.undescribed_requests,#preview_form p,.attachment {
@@ -862,11 +862,11 @@ clear:left;
}
.correspondence_text,.comment_in_request_text {
-margin:0 1.2em 0 0.8em;
+margin:0 1.2em 0 0.9em;
}
#request_header_text,#request_search_ahead_results {
-font-size:0.8em;
+font-size:0.9em;
margin-left:11em;
}
@@ -910,7 +910,7 @@ border:none;
#navigation_search input[type=image] {
border:0;
-margin-bottom:-9px;
+margin-bottom:-8px;
margin-left:-4px;
}
@@ -918,7 +918,7 @@ margin-left:-4px;
border-radius:5px 0 0 5px;
-moz-border-radius:5px 0 0 5px;
border-color:#222;
-padding:5px 5px 4px;
+height: 14px;
}
#topnav ul li {
@@ -938,6 +938,23 @@ float:left;
#request_header_text {
margin-left:110px;
+width: 30em;
+border-radius:3px;
+-moz-border-radius:3px;
+margin-top: 10px;
+background-color:#D5FFD8;
+border-color:#1EFF38;
+border-style:solid;
+border-width:1px;
+padding:0.5em;
+
+font-style: italic;
+
+
+}
+
+#request_header_text h3 {
+ font-size: 1em;
}
#stepwise_make_request a img {
@@ -1139,6 +1156,7 @@ margin-left:117px;
}
span#to_public_body {
+font-weight: bold;
}
#left_column {
@@ -1226,9 +1244,9 @@ border:solid 1px #69952F;
border-radius:2px;
-moz-border-radius:2px;
text-shadow:1px 1px 0 #5B841D;
-font-size:14px;
+font-size:18px;
cursor:hand;
-padding:5px 11px;
+padding:5px 6px;
}
a.link_button_green_large {
diff --git a/spec/controllers/admin_public_body_controller_spec.rb b/spec/controllers/admin_public_body_controller_spec.rb
index 2670f2add..6954e22a1 100644
--- a/spec/controllers/admin_public_body_controller_spec.rb
+++ b/spec/controllers/admin_public_body_controller_spec.rb
@@ -25,9 +25,9 @@ describe AdminPublicBodyController, "when administering public bodies" do
end
it "creates a new public body" do
- PublicBody.count.should == 2
+ n = PublicBody.count
post :create, { :public_body => { :name => "New Quango", :short_name => "", :tag_string => "blah", :request_email => 'newquango@localhost', :last_edit_comment => 'From test code' } }
- PublicBody.count.should == 3
+ PublicBody.count.should == n + 1
end
it "edits a public body" do
@@ -42,13 +42,19 @@ describe AdminPublicBodyController, "when administering public bodies" do
pb.name.should == "Renamed"
end
+ it "does not destroy a public body that has associated requests" do
+ id = public_bodies(:humpadink_public_body).id
+ n = PublicBody.count
+ post :destroy, { :id => id }
+ response.should redirect_to(:controller=>'admin_public_body', :action=>'show', :id => id)
+ PublicBody.count.should == n
+ end
+
it "destroys a public body" do
- PublicBody.count.should == 2
- info_request_events(:badger_outgoing_message_event).destroy
- outgoing_messages(:badger_outgoing_message).destroy
- info_requests(:badger_request).destroy
- post :destroy, { :id => 3 }
- PublicBody.count.should == 1
+ n = PublicBody.count
+ post :destroy, { :id => public_bodies(:forlorn_public_body).id }
+ response.should redirect_to(:controller=>'admin_public_body', :action=>'list')
+ PublicBody.count.should == n - 1
end
it "sets a using_admin flag" do
@@ -64,10 +70,10 @@ describe AdminPublicBodyController, "when administering public bodies and paying
it "disallows non-authenticated users to do anything" do
@request.env["HTTP_AUTHORIZATION"] = ""
- PublicBody.count.should == 2
+ n = PublicBody.count.should
post :destroy, { :id => 3 }
response.code.should == "401"
- PublicBody.count.should == 2
+ PublicBody.count.should == n
session[:using_admin].should == nil
end
@@ -76,25 +82,22 @@ describe AdminPublicBodyController, "when administering public bodies and paying
config['ADMIN_USERNAME'] = ''
config['ADMIN_PASSWORD'] = ''
@request.env["HTTP_AUTHORIZATION"] = ""
- PublicBody.count.should == 2
- info_request_events(:badger_outgoing_message_event).destroy
- outgoing_messages(:badger_outgoing_message).destroy
- info_requests(:badger_request).destroy
- post :destroy, { :id => 3 }
- PublicBody.count.should == 1
+
+ n = PublicBody.count
+ post :destroy, { :id => public_bodies(:forlorn_public_body).id }
+ PublicBody.count.should == n - 1
session[:using_admin].should == 1
end
+
it "skips admin authorisation when no username set" do
config = MySociety::Config.load_default()
config['ADMIN_USERNAME'] = ''
config['ADMIN_PASSWORD'] = 'fuz'
@request.env["HTTP_AUTHORIZATION"] = ""
- PublicBody.count.should == 2
- info_request_events(:badger_outgoing_message_event).destroy
- outgoing_messages(:badger_outgoing_message).destroy
- info_requests(:badger_request).destroy
- post :destroy, { :id => 3 }
- PublicBody.count.should == 1
+
+ n = PublicBody.count
+ post :destroy, { :id => public_bodies(:forlorn_public_body).id }
+ PublicBody.count.should == n - 1
session[:using_admin].should == 1
end
it "forces authorisation when password and username set" do
@@ -102,14 +105,11 @@ describe AdminPublicBodyController, "when administering public bodies and paying
config['ADMIN_USERNAME'] = 'biz'
config['ADMIN_PASSWORD'] = 'fuz'
@request.env["HTTP_AUTHORIZATION"] = ""
- PublicBody.count.should == 2
+ n = PublicBody.count.should
basic_auth_login(@request, "baduser", "badpassword")
- info_request_events(:badger_outgoing_message_event).destroy
- outgoing_messages(:badger_outgoing_message).destroy
- info_requests(:badger_request).destroy
- post :destroy, { :id => 3 }
+ post :destroy, { :id => public_bodies(:forlorn_public_body).id }
response.code.should == "401"
- PublicBody.count.should == 2
+ PublicBody.count.should == n
session[:using_admin].should == nil
end
@@ -179,12 +179,9 @@ describe AdminPublicBodyController, "when administering public bodies with i18n"
end
it "destroy a public body" do
- PublicBody.count.should == 2
- info_request_events(:badger_outgoing_message_event).destroy
- outgoing_messages(:badger_outgoing_message).destroy
- info_requests(:badger_request).destroy
- post :destroy, { :id => 3 }
- PublicBody.count.should == 1
+ n = PublicBody.count
+ post :destroy, { :id => public_bodies(:forlorn_public_body).id }
+ PublicBody.count.should == n - 1
end
end
@@ -207,23 +204,23 @@ describe AdminPublicBodyController, "when creating public bodies with i18n" do
it "creates a new public body in one locale" do
- PublicBody.count.should == 2
+ n = PublicBody.count
post :create, { :public_body => { :name => "New Quango", :short_name => "", :tag_string => "blah", :request_email => 'newquango@localhost', :last_edit_comment => 'From test code' } }
- PublicBody.count.should == 3
+ PublicBody.count.should == n + 1
body = PublicBody.find_by_name("New Quango")
response.should redirect_to(:controller=>'admin_public_body', :action=>'show', :id=>body.id)
end
it "creates a new public body with multiple locales" do
- PublicBody.count.should == 2
+ n = PublicBody.count
post :create, {
:public_body => {
:name => "New Quango", :short_name => "", :tag_string => "blah", :request_email => 'newquango@localhost', :last_edit_comment => 'From test code',
:translated_versions => [{ :locale => "es", :name => "Mi Nuevo Quango", :short_name => "", :request_email => 'newquango@localhost' }]
}
}
- PublicBody.count.should == 3
+ PublicBody.count.should == n + 1
body = PublicBody.find_by_name("New Quango")
body.translations.map {|t| t.locale.to_s}.sort.should == ["en", "es"]
diff --git a/spec/controllers/general_controller_spec.rb b/spec/controllers/general_controller_spec.rb
index 2750a33f3..c4fd46c14 100644
--- a/spec/controllers/general_controller_spec.rb
+++ b/spec/controllers/general_controller_spec.rb
@@ -108,6 +108,18 @@ describe GeneralController, "when searching" do
I18n.available_locales = old_i18n_available_locales
end
end
+
+ describe 'when constructing the list of recent requests' do
+ before(:each) do
+ load_raw_emails_data(raw_emails)
+ rebuild_xapian_index
+ end
+
+ it 'should list the successful request first' do
+ get :frontpage
+ assigns[:request_events].first.info_request.should == info_requests(:boring_request)
+ end
+ end
describe 'when using xapian search' do
diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb
index 131412a90..4b657849a 100644
--- a/spec/controllers/public_body_controller_spec.rb
+++ b/spec/controllers/public_body_controller_spec.rb
@@ -26,13 +26,23 @@ describe PublicBodyController, "when showing a body" do
assigns[:public_body].should == public_bodies(:humpadink_public_body)
end
- it "should assign the requests" do
+ it "should assign the requests (1)" do
get :show, :url_name => "tgq", :view => 'all'
- assigns[:xapian_requests].results.count.should == 2
+ assigns[:xapian_requests].results.map{|x|x[:model].info_request}.should =~ InfoRequest.all(
+ :conditions => ["public_body_id = ?", public_bodies(:geraldine_public_body).id])
+ end
+
+ it "should assign the requests (2)" do
get :show, :url_name => "tgq", :view => 'successful'
- assigns[:xapian_requests].results.count.should == 0
+ assigns[:xapian_requests].results.map{|x|x[:model].info_request}.should =~ InfoRequest.all(
+ :conditions => ["described_state = ? and public_body_id = ?",
+ "successful", public_bodies(:geraldine_public_body).id])
+ end
+
+ it "should assign the requests (3)" do
get :show, :url_name => "dfh", :view => 'all'
- assigns[:xapian_requests].results.count.should == 1
+ assigns[:xapian_requests].results.map{|x|x[:model].info_request}.should =~ InfoRequest.all(
+ :conditions => ["public_body_id = ?", public_bodies(:humpadink_public_body).id])
end
it "should assign the body using different locale from that used for url_name" do
@@ -81,16 +91,16 @@ describe PublicBodyController, "when listing bodies" do
it "should list all bodies from default locale, even when there are no translations for selected locale" do
PublicBody.with_locale(:en) do
- english_only = PublicBody.new(:name => 'English only',
+ @english_only = PublicBody.new(:name => 'English only',
:short_name => 'EO',
:request_email => 'english@flourish.org',
:last_edit_editor => 'test',
:last_edit_comment => '')
- english_only.save
+ @english_only.save
end
PublicBody.with_locale(:es) do
get :list
- assigns[:public_bodies].length.should == 3
+ assigns[:public_bodies].include?(@english_only).should == true
end
end
@@ -99,7 +109,7 @@ describe PublicBodyController, "when listing bodies" do
response.should render_template('list')
- assigns[:public_bodies].should == [ public_bodies(:humpadink_public_body), public_bodies(:geraldine_public_body) ]
+ assigns[:public_bodies].should == PublicBody.all(:order => "name", :conditions => "id <> #{PublicBody.internal_admin_body.id}")
assigns[:tag].should == "all"
assigns[:description].should == ""
end
@@ -135,11 +145,11 @@ describe PublicBodyController, "when listing bodies" do
get :list, :tag => "other"
response.should render_template('list')
- assigns[:public_bodies].should == [ public_bodies(:geraldine_public_body) ]
+ assigns[:public_bodies].should =~ PublicBody.all(:conditions => "id not in (#{public_bodies(:humpadink_public_body).id}, #{PublicBody.internal_admin_body.id})")
get :list
response.should render_template('list')
- assigns[:public_bodies].count.should == 2
+ assigns[:public_bodies].should =~ PublicBody.all(:conditions => "id <> #{PublicBody.internal_admin_body.id}")
end
diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb
index 055c9b3d4..a77d1ac27 100644
--- a/spec/controllers/request_controller_spec.rb
+++ b/spec/controllers/request_controller_spec.rb
@@ -23,20 +23,42 @@ describe RequestController, "when listing recent requests" do
it "should filter requests" do
get :list, :view => 'all'
- assigns[:list_results].size.should == 3
+ assigns[:list_results].map(&:info_request).should =~ InfoRequest.all
+
# default sort order is the request with the most recently created event first
- assigns[:list_results][0].info_request.id.should == 104
+ assigns[:list_results].map(&:info_request).should == InfoRequest.all(
+ :order => "(select max(info_request_events.created_at) from info_request_events where info_request_events.info_request_id = info_requests.id) DESC")
+
get :list, :view => 'successful'
- assigns[:list_results].size.should == 0
+ assigns[:list_results].map(&:info_request).should =~ InfoRequest.all(
+ :conditions => "id in (
+ select info_request_id
+ from info_request_events
+ where not exists (
+ select *
+ from info_request_events later_events
+ where later_events.created_at > info_request_events.created_at
+ and later_events.info_request_id = info_request_events.info_request_id
+ )
+ and info_request_events.described_state in ('successful', 'partially_successful')
+ )")
end
it "should filter requests by date" do
+ # The semantics of the search are that it finds any InfoRequest
+ # that has any InfoRequestEvent created in the specified range
+
get :list, :view => 'all', :request_date_before => '13/10/2007'
- assigns[:list_results].size.should == 1
+ assigns[:list_results].map(&:info_request).should =~ InfoRequest.all(
+ :conditions => "id in (select info_request_id from info_request_events where created_at < '2007-10-13'::date)")
+
get :list, :view => 'all', :request_date_after => '13/10/2007'
- assigns[:list_results].size.should == 3
+ assigns[:list_results].map(&:info_request).should =~ InfoRequest.all(
+ :conditions => "id in (select info_request_id from info_request_events where created_at > '2007-10-13'::date)")
+
get :list, :view => 'all', :request_date_after => '13/10/2007', :request_date_before => '01/11/2007'
- assigns[:list_results].size.should == 1
+ assigns[:list_results].map(&:info_request).should =~ InfoRequest.all(
+ :conditions => "id in (select info_request_id from info_request_events where created_at between '2007-10-13'::date and '2007-11-01'::date)")
end
it "should make a sane-sized cache tag" do
@@ -46,13 +68,32 @@ describe RequestController, "when listing recent requests" do
it "should list internal_review requests as unresolved ones" do
get :list, :view => 'awaiting'
- assigns[:list_results].size.should == 0
+
+ # This doesn’t precisely duplicate the logic of the actual
+ # query, but it is close enough to give the same result with
+ # the current set of test data.
+ assigns[:list_results].should =~ InfoRequestEvent.all(
+ :conditions => "described_state in (
+ 'waiting_response', 'waiting_clarification',
+ 'internal_review', 'gone_postal', 'error_message', 'requires_admin'
+ ) and not exists (
+ select *
+ from info_request_events later_events
+ where later_events.created_at > info_request_events.created_at
+ and later_events.info_request_id = info_request_events.info_request_id
+ )")
+
+
+ get :list, :view => 'awaiting'
+ assigns[:list_results].map(&:info_request).include?(info_requests(:fancy_dog_request)).should == false
+
event = info_request_events(:useless_incoming_message_event)
- event.calculated_state = "internal_review"
+ event.described_state = event.calculated_state = "internal_review"
event.save!
rebuild_xapian_index
+
get :list, :view => 'awaiting'
- assigns[:list_results].size.should == 1
+ assigns[:list_results].map(&:info_request).include?(info_requests(:fancy_dog_request)).should == true
end
it "should assign the first page of results" do
diff --git a/spec/controllers/user_controller_spec.rb b/spec/controllers/user_controller_spec.rb
index a90fa18df..81d3ff2e5 100644
--- a/spec/controllers/user_controller_spec.rb
+++ b/spec/controllers/user_controller_spec.rb
@@ -46,16 +46,19 @@ 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.count.should == 3
+ 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.count.should == 1
+ assigns[:xapian_requests].results.map{|x|x[:model].info_request}.should == [info_requests(:naughty_chicken_request)]
end
-# Error handling not quite good enough for this yet
-# it "should not show unconfirmed users" do
-# get :show, :url_name => "silly_emnameem"
-# assigns[:display_users].should == [ users(:silly_name_user) ]
-# end
+ it "should not show unconfirmed users" do
+ begin
+ get :show, :url_name => "unconfirmed_user"
+ rescue => e
+ end
+ e.should be_an_instance_of(ActiveRecord::RecordNotFound)
+ end
end
diff --git a/spec/fixtures/incoming_messages.yml b/spec/fixtures/incoming_messages.yml
index e15a466ca..2a5dd872b 100644
--- a/spec/fixtures/incoming_messages.yml
+++ b/spec/fixtures/incoming_messages.yml
@@ -1,7 +1,13 @@
useless_incoming_message:
- id: 1
- info_request_id: 101
- updated_at: 2007-11-13 18:09:20.042061
- raw_email_id: 1
- created_at: 2007-11-13 18:09:20.042061
+ id: 1
+ info_request_id: 101
+ updated_at: 2007-11-13 18:09:20.042061
+ raw_email_id: 1
+ created_at: 2007-11-13 18:09:20.042061
+useful_incoming_message:
+ id: 2
+ info_request_id: 105
+ raw_email_id: 2
+ created_at: 2012-01-26 10:19:23
+ updated_at: 2012-01-26 10:19:23
diff --git a/spec/fixtures/info_request_events.yml b/spec/fixtures/info_request_events.yml
index 9c6aa393d..b19845345 100644
--- a/spec/fixtures/info_request_events.yml
+++ b/spec/fixtures/info_request_events.yml
@@ -32,8 +32,8 @@ silly_comment_event:
last_described_at:
described_state:
id: "903"
- info_request_id: "101"
- comment_id: "1"
+ info_request_id: 101
+ comment_id: 1
calculated_state:
event_type: comment
outgoing_message_id:
@@ -45,6 +45,27 @@ badger_outgoing_message_event:
info_request_id: 104
event_type: sent
created_at: 2011-10-12 01:56:58.586598
- described_state:
+ described_state: waiting_response
+ calculated_state: waiting_response
outgoing_message_id: 3
+boring_outgoing_message_event:
+ id: 905
+ params_yaml: "--- \n\
+ :outgoing_message_id: 4\n"
+ outgoing_message_id: 4
+ info_request_id: 105
+ event_type: sent
+ created_at: 2006-01-12 01:56:58.586598
+ described_state: waiting_response
+ calculated_state: waiting_response
+useful_incoming_message_event:
+ id: 906
+ params_yaml: "--- \n\
+ :incoming_message_id: 2\n"
+ incoming_message_id: 2
+ info_request_id: 105
+ event_type: response
+ created_at: 2007-11-13 18:09:20.042061
+ described_state: successful
+ calculated_state: successful
diff --git a/spec/fixtures/info_requests.yml b/spec/fixtures/info_requests.yml
index 7b7e55ba6..9f767e7f3 100644
--- a/spec/fixtures/info_requests.yml
+++ b/spec/fixtures/info_requests.yml
@@ -18,7 +18,7 @@ naughty_chicken_request:
public_body_id: 2
user_id: 1
described_state: waiting_response
- awaiting_description: false
+ awaiting_description: false
idhash: e8d18c84
badger_request:
id: 104
@@ -29,5 +29,16 @@ badger_request:
public_body_id: 3
user_id: 1
described_state: waiting_response
- awaiting_description: false
+ awaiting_description: false
idhash: e8d18c84
+boring_request:
+ id: 105
+ title: The cost of boring
+ url_title: the_cost_of_boring
+ created_at: 2012-01-26 10:19:23
+ updated_at: 2012-01-26 10:19:23
+ public_body_id: 3
+ user_id: 1
+ described_state: successful
+ awaiting_description: false
+ idhash: 173fd003
diff --git a/spec/fixtures/outgoing_messages.yml b/spec/fixtures/outgoing_messages.yml
index 0cebdd5c5..3afce92f5 100644
--- a/spec/fixtures/outgoing_messages.yml
+++ b/spec/fixtures/outgoing_messages.yml
@@ -43,6 +43,16 @@ badger_outgoing_message:
last_sent_at: 2011-10-14 10:41:12.686264
created_at: 2011-10-14 01:56:58.586598
what_doing: normal_sort
+boring_outgoing_message:
+ id: 4
+ info_request_id: 105
+ message_type: initial_request
+ status: sent
+ updated_at: 2012-01-14 01:56:58.586598
+ body: "How much was spent on boring equipment in the 2010-2011 financial year?"
+ last_sent_at: 2012-01-14 10:41:12.686264
+ created_at: 2012-01-14 01:56:58.586598
+ what_doing: normal_sort
diff --git a/spec/fixtures/public_bodies.yml b/spec/fixtures/public_bodies.yml
index 191dd68bb..93fd0fb2e 100644
--- a/spec/fixtures/public_bodies.yml
+++ b/spec/fixtures/public_bodies.yml
@@ -23,3 +23,16 @@ humpadink_public_body:
url_name: dfh
created_at: 2007-10-25 10:51:01.161639
notes: An albatross told me!!!
+forlorn_public_body:
+ name: "Department of Loneliness"
+ first_letter: D
+ updated_at: 2011-01-26 14:11:02.12345
+ last_edit_comment: 'Aw, bless.'
+ request_email: forlorn-requests@localhost
+ id: 4
+ version: 1
+ last_edit_editor: "robin"
+ short_name: DoL
+ url_name: lonely
+ created_at: 2011-01-26 14:11:02.12345
+ notes: A very lonely public body that no one has corresponded with
diff --git a/spec/fixtures/public_body_translations.yml b/spec/fixtures/public_body_translations.yml
index b5e947044..08727e45c 100644
--- a/spec/fixtures/public_body_translations.yml
+++ b/spec/fixtures/public_body_translations.yml
@@ -24,8 +24,8 @@ humpadink_es_public_body_translation:
name: "El Department for Humpadinking"
first_letter: E
request_email: humpadink-requests@localhost
- id: "3"
- public_body_id: "3"
+ id: 3
+ public_body_id: 3
short_name: eDfH
url_name: edfh
locale: es
@@ -35,9 +35,20 @@ humpadink_en_public_body_translation:
name: "Department for Humpadinking"
first_letter: D
request_email: humpadink-requests@localhost
- id: "4"
- public_body_id: "3"
+ id: 4
+ public_body_id: 3
short_name: DfH
url_name: dfh
locale: en
notes: An albatross told me!!!
+
+forlorn_en_public_body_translation:
+ name: "Department of Loneliness"
+ first_letter: D
+ request_email: forlorn-requests@localhost
+ id: 5
+ public_body_id: 4
+ short_name: DoL
+ url_name: lonely
+ locale: en
+ notes: A very lonely public body that no one has corresponded with
diff --git a/spec/fixtures/raw_emails.yml b/spec/fixtures/raw_emails.yml
index 8ef9248a3..32e039cab 100644
--- a/spec/fixtures/raw_emails.yml
+++ b/spec/fixtures/raw_emails.yml
@@ -1,2 +1,5 @@
useless_raw_email:
id: 1
+
+useful_raw_email:
+ id: 2
diff --git a/spec/models/public_body_spec.rb b/spec/models/public_body_spec.rb
index 07e8f291d..97fa04f93 100644
--- a/spec/models/public_body_spec.rb
+++ b/spec/models/public_body_spec.rb
@@ -239,6 +239,7 @@ describe PublicBody, " when dealing public body locales" do
end
describe PublicBody, " when loading CSV files" do
+ fixtures :public_bodies, :public_body_versions, :public_body_translations
before(:each) do
# InternalBody is created the first time it's accessed, which happens sometimes during imports,
# depending on the tag used. By accessing it here before every test, it doesn't disturb our checks later on
@@ -248,11 +249,10 @@ describe PublicBody, " when loading CSV files" do
it "should import even if no email is provided" do
errors, notes = PublicBody.import_csv("1,aBody", '', 'replace', true, 'someadmin') # true means dry run
errors.should == []
+ puts "notes = #{notes.inspect}"
notes.size.should == 2
- notes.should == [
- "line 1: creating new authority 'aBody' (locale: en):\n\t{\"name\":\"aBody\"}",
- "Notes: Some bodies are in database, but not in CSV file:\n Department for Humpadinking\n Geraldine Quango\nYou may want to delete them manually.\n"
- ]
+ notes[0].should == "line 1: creating new authority 'aBody' (locale: en):\n\t{\"name\":\"aBody\"}"
+ notes[1].should =~ /Notes: Some bodies are in database, but not in CSV file:\n( [A-Za-z ]+\n)*You may want to delete them manually.\n/
end
it "should do a dry run successfully" do
@@ -262,12 +262,12 @@ describe PublicBody, " when loading CSV files" do
errors, notes = PublicBody.import_csv(csv_contents, '', 'replace', true, 'someadmin') # true means dry run
errors.should == []
notes.size.should == 4
- notes.should == [
+ notes[0..2].should == [
"line 1: creating new authority 'North West Fake Authority' (locale: en):\n\t\{\"name\":\"North West Fake Authority\",\"request_email\":\"north_west_foi@localhost\"\}",
"line 2: creating new authority 'Scottish Fake Authority' (locale: en):\n\t\{\"name\":\"Scottish Fake Authority\",\"request_email\":\"scottish_foi@localhost\"\}",
"line 3: creating new authority 'Fake Authority of Northern Ireland' (locale: en):\n\t\{\"name\":\"Fake Authority of Northern Ireland\",\"request_email\":\"ni_foi@localhost\"\}",
- "Notes: Some bodies are in database, but not in CSV file:\n Department for Humpadinking\n Geraldine Quango\nYou may want to delete them manually.\n"
- ]
+ ]
+ notes[3].should =~ /Notes: Some bodies are in database, but not in CSV file:\n( [A-Za-z ]+\n)*You may want to delete them manually.\n/
PublicBody.count.should == original_count
end
@@ -279,12 +279,12 @@ describe PublicBody, " when loading CSV files" do
errors, notes = PublicBody.import_csv(csv_contents, '', 'replace', false, 'someadmin') # false means real run
errors.should == []
notes.size.should == 4
- notes.should == [
+ notes[0..2].should == [
"line 1: creating new authority 'North West Fake Authority' (locale: en):\n\t\{\"name\":\"North West Fake Authority\",\"request_email\":\"north_west_foi@localhost\"\}",
"line 2: creating new authority 'Scottish Fake Authority' (locale: en):\n\t\{\"name\":\"Scottish Fake Authority\",\"request_email\":\"scottish_foi@localhost\"\}",
"line 3: creating new authority 'Fake Authority of Northern Ireland' (locale: en):\n\t\{\"name\":\"Fake Authority of Northern Ireland\",\"request_email\":\"ni_foi@localhost\"\}",
- "Notes: Some bodies are in database, but not in CSV file:\n Department for Humpadinking\n Geraldine Quango\nYou may want to delete them manually.\n"
- ]
+ ]
+ notes[3].should =~ /Notes: Some bodies are in database, but not in CSV file:\n( [A-Za-z ]+\n)*You may want to delete them manually.\n/
PublicBody.count.should == original_count + 3
end
@@ -296,12 +296,12 @@ describe PublicBody, " when loading CSV files" do
errors, notes = PublicBody.import_csv(csv_contents, '', 'replace', false, 'someadmin') # false means real run
errors.should == []
notes.size.should == 4
- notes.should == [
+ notes[0..2].should == [
"line 1: creating new authority 'North West Fake Authority' (locale: en):\n\t\{\"name\":\"North West Fake Authority\",\"request_email\":\"north_west_foi@localhost\"\}",
"line 2: creating new authority 'Scottish Fake Authority' (locale: en):\n\t\{\"name\":\"Scottish Fake Authority\",\"request_email\":\"scottish_foi@localhost\"\}",
"line 3: creating new authority 'Fake Authority of Northern Ireland' (locale: en):\n\t\{\"name\":\"Fake Authority of Northern Ireland\",\"request_email\":\"ni_foi@localhost\"\}",
- "Notes: Some bodies are in database, but not in CSV file:\n Department for Humpadinking\n Geraldine Quango\nYou may want to delete them manually.\n"
- ]
+ ]
+ notes[3].should =~ /Notes: Some bodies are in database, but not in CSV file:\n( [A-Za-z ]+\n)*You may want to delete them manually.\n/
PublicBody.count.should == original_count + 3
end
@@ -312,12 +312,12 @@ describe PublicBody, " when loading CSV files" do
errors, notes = PublicBody.import_csv(csv_contents, '', 'replace', true, 'someadmin') # true means dry run
errors.should == []
notes.size.should == 4
- notes.should == [
+ notes[0..2].should == [
"line 2: creating new authority 'North West Fake Authority' (locale: en):\n\t\{\"name\":\"North West Fake Authority\",\"request_email\":\"north_west_foi@localhost\",\"home_page\":\"http://northwest.org\"\}",
"line 3: creating new authority 'Scottish Fake Authority' (locale: en):\n\t\{\"name\":\"Scottish Fake Authority\",\"request_email\":\"scottish_foi@localhost\",\"home_page\":\"http://scottish.org\",\"tag_string\":\"scottish\"\}",
"line 4: creating new authority 'Fake Authority of Northern Ireland' (locale: en):\n\t\{\"name\":\"Fake Authority of Northern Ireland\",\"request_email\":\"ni_foi@localhost\",\"tag_string\":\"fake aTag\"\}",
- "Notes: Some bodies are in database, but not in CSV file:\n Department for Humpadinking\n Geraldine Quango\nYou may want to delete them manually.\n"
- ]
+ ]
+ notes[3].should =~ /Notes: Some bodies are in database, but not in CSV file:\n( [A-Za-z ]+\n)*You may want to delete them manually.\n/
PublicBody.count.should == original_count
end
@@ -366,15 +366,15 @@ describe PublicBody, " when loading CSV files" do
errors, notes = PublicBody.import_csv(csv_contents, '', 'replace', false, 'someadmin', [:en, :es])
errors.should == []
notes.size.should == 7
- notes.should == [
+ notes[0..5].should == [
"line 2: creating new authority 'North West Fake Authority' (locale: en):\n\t{\"name\":\"North West Fake Authority\",\"request_email\":\"north_west_foi@localhost\",\"home_page\":\"http://northwest.org\"}",
"line 2: creating new authority 'North West Fake Authority' (locale: es):\n\t{\"name\":\"Autoridad del Nordeste\"}",
"line 3: creating new authority 'Scottish Fake Authority' (locale: en):\n\t{\"name\":\"Scottish Fake Authority\",\"request_email\":\"scottish_foi@localhost\",\"home_page\":\"http://scottish.org\",\"tag_string\":\"scottish\"}",
"line 3: creating new authority 'Scottish Fake Authority' (locale: es):\n\t{\"name\":\"Autoridad Escocesa\"}",
"line 4: creating new authority 'Fake Authority of Northern Ireland' (locale: en):\n\t{\"name\":\"Fake Authority of Northern Ireland\",\"request_email\":\"ni_foi@localhost\",\"tag_string\":\"fake aTag\"}",
"line 4: creating new authority 'Fake Authority of Northern Ireland' (locale: es):\n\t{\"name\":\"Autoridad Irlandesa\"}",
- "Notes: Some bodies are in database, but not in CSV file:\n Department for Humpadinking\n Geraldine Quango\nYou may want to delete them manually.\n"
- ]
+ ]
+ notes[6].should =~ /Notes: Some bodies are in database, but not in CSV file:\n( [A-Za-z ]+\n)*You may want to delete them manually.\n/
PublicBody.count.should == original_count + 3
@@ -395,12 +395,12 @@ describe PublicBody, " when loading CSV files" do
errors, notes = PublicBody.import_csv(csv_contents, '', 'replace', true, 'someadmin', ['en', :xx]) # true means dry run
errors.should == []
notes.size.should == 4
- notes.should == [
+ notes[0..2].should == [
"line 2: creating new authority 'North West Fake Authority' (locale: en):\n\t{\"name\":\"North West Fake Authority\",\"request_email\":\"north_west_foi@localhost\",\"home_page\":\"http://northwest.org\"}",
"line 3: creating new authority 'Scottish Fake Authority' (locale: en):\n\t{\"name\":\"Scottish Fake Authority\",\"request_email\":\"scottish_foi@localhost\",\"home_page\":\"http://scottish.org\",\"tag_string\":\"scottish\"}",
"line 4: creating new authority 'Fake Authority of Northern Ireland' (locale: en):\n\t{\"name\":\"Fake Authority of Northern Ireland\",\"request_email\":\"ni_foi@localhost\",\"tag_string\":\"fake aTag\"}",
- "Notes: Some bodies are in database, but not in CSV file:\n Department for Humpadinking\n Geraldine Quango\nYou may want to delete them manually.\n"
- ]
+ ]
+ notes[3].should =~ /Notes: Some bodies are in database, but not in CSV file:\n( [A-Za-z ]+\n)*You may want to delete them manually.\n/
PublicBody.count.should == original_count
end
diff --git a/spec/models/xapian_spec.rb b/spec/models/xapian_spec.rb
index 412146b53..6f4f49373 100644
--- a/spec/models/xapian_spec.rb
+++ b/spec/models/xapian_spec.rb
@@ -60,14 +60,11 @@ describe PublicBody, " when indexing public bodies with Xapian" do
xapian_object.results.size.should == 1
xapian_object.results[0][:model].should == public_bodies(:humpadink_public_body)
- info_request_events(:badger_outgoing_message_event).destroy
- outgoing_messages(:badger_outgoing_message).destroy
- info_requests(:badger_request).destroy
- public_bodies(:humpadink_public_body).destroy
+ public_bodies(:forlorn_public_body).destroy
update_xapian_index
- xapian_object = InfoRequest.full_search([PublicBody], "albatross", 'created_at', true, nil, 100, 1)
- xapian_object.results.size.should == 0
+ xapian_object = InfoRequest.full_search([PublicBody], "lonely", 'created_at', true, nil, 100, 1)
+ xapian_object.results.should == []
end
end
@@ -130,7 +127,7 @@ describe PublicBody, " when indexing requests by body they are to" do
end
describe User, " when indexing requests by user they are from" do
- fixtures :users, :info_requests, :raw_emails, :incoming_messages, :outgoing_messages, :comments, :info_request_events, :track_things
+ fixtures :users, :info_requests, :raw_emails, :incoming_messages, :outgoing_messages, :comments, :info_request_events, :track_things, :public_bodies, :public_body_versions, :public_body_translations
before(:each) do
load_raw_emails_data(raw_emails)
rebuild_xapian_index
@@ -138,13 +135,13 @@ describe User, " when indexing requests by user they are from" do
it "should find requests from the user" do
xapian_object = InfoRequest.full_search([InfoRequestEvent], "requested_by:bob_smith", 'created_at', true, nil, 100, 1)
- xapian_object.results.size.should == 5
+ xapian_object.results.map{|x|x[:model]}.should =~ InfoRequestEvent.all(:conditions => "info_request_id in (select id from info_requests where user_id = #{users(:bob_smith_user).id})")
end
it "should find just the sent message events from a particular user" do
# def InfoRequest.full_search(models, query, order, ascending, collapse, per_page, page)
xapian_object = InfoRequest.full_search([InfoRequestEvent], "requested_by:bob_smith variety:sent", 'created_at', true, nil, 100, 1)
- xapian_object.results.size.should == 3
+ xapian_object.results.map{|x|x[:model]}.should =~ InfoRequestEvent.all(:conditions => "info_request_id in (select id from info_requests where user_id = #{users(:bob_smith_user).id}) and event_type = 'sent'")
xapian_object.results[2][:model].should == info_request_events(:useless_outgoing_message_event)
xapian_object.results[1][:model].should == info_request_events(:silly_outgoing_message_event)
end
@@ -159,8 +156,7 @@ describe User, " when indexing requests by user they are from" do
# def InfoRequest.full_search(models, query, order, ascending, collapse, per_page, page)
xapian_object = InfoRequest.full_search([InfoRequestEvent], "requested_by:bob_smith", 'created_at', true, 'request_collapse', 100, 1)
- xapian_object.results.size.should == 2
- xapian_object.results[1][:model].should == info_request_events(:silly_comment_event)
+ xapian_object.results.map{|x|x[:model].info_request}.should =~ InfoRequest.all(:conditions => "user_id = #{users(:bob_smith_user).id}")
end
it "should not get confused searching for requests when one user has a name which has same stem as another" do
@@ -190,7 +186,7 @@ describe User, " when indexing requests by user they are from" do
it "should update index correctly when URL name of user changes" do
# initial search
xapian_object = InfoRequest.full_search([InfoRequestEvent], "requested_by:bob_smith", 'created_at', true, nil, 100, 1)
- xapian_object.results.size.should == 5
+ xapian_object.results.map{|x|x[:model]}.should =~ InfoRequestEvent.all(:conditions => "info_request_id in (select id from info_requests where user_id = #{users(:bob_smith_user).id})")
models_found_before = xapian_object.results.map { |x| x[:model] }
# change the URL name of the body
@@ -204,9 +200,7 @@ describe User, " when indexing requests by user they are from" do
xapian_object = InfoRequest.full_search([InfoRequestEvent], "requested_by:bob_smith", 'created_at', true, nil, 100, 1)
xapian_object.results.size.should == 0
xapian_object = InfoRequest.full_search([InfoRequestEvent], "requested_by:robert_smith", 'created_at', true, nil, 100, 1)
- xapian_object.results.size.should == 5
models_found_after = xapian_object.results.map { |x| x[:model] }
-
models_found_before.should == models_found_after
end
end
@@ -347,7 +341,7 @@ describe PublicBody, " when only indexing selected things on a rebuild" do
xapian_object = InfoRequest.full_search([PublicBody], "frobzn", 'created_at', true, nil, 100, 1)
xapian_object.results.size.should == 0
xapian_object = InfoRequest.full_search([PublicBody], "variety:authority", 'created_at', true, nil, 100, 1)
- xapian_object.results.size.should == 2
+ xapian_object.results.map{|x|x[:model]}.should =~ PublicBody.all
# only reindex 'tag' and text
dropfirst = true
terms = "U"
@@ -370,7 +364,7 @@ describe PublicBody, " when only indexing selected things on a rebuild" do
xapian_object = InfoRequest.full_search([PublicBody], "frobzn", 'created_at', true, nil, 100, 1)
xapian_object.results.size.should == 1
xapian_object = InfoRequest.full_search([PublicBody], "variety:authority", 'created_at', true, nil, 100, 1)
- xapian_object.results.size.should == 2
+ xapian_object.results.map{|x|x[:model]}.should =~ PublicBody.all
# only reindex 'variety' term, blowing away existing data
dropfirst = true
rebuild_xapian_index(terms, values, texts, dropfirst)
@@ -379,7 +373,7 @@ describe PublicBody, " when only indexing selected things on a rebuild" do
xapian_object = InfoRequest.full_search([PublicBody], "frobzn", 'created_at', true, nil, 100, 1)
xapian_object.results.size.should == 0
xapian_object = InfoRequest.full_search([PublicBody], "variety:authority", 'created_at', true, nil, 100, 1)
- xapian_object.results.size.should == 2
+ xapian_object.results.map{|x|x[:model]}.should =~ PublicBody.all
end
end