aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSeb Bacon <seb.bacon@gmail.com>2011-08-26 13:54:05 +0100
committerSeb Bacon <seb.bacon@gmail.com>2011-08-29 09:44:33 +0100
commit33bd0e919528e1d7eda4be4200db91b042984c97 (patch)
tree3c872a9482a87b9f1d64ef745e87add403852d9c
parent5f0c0d59ded4301efa085c4103b84a42a9fa61f6 (diff)
Fixes to get tests to pass following addition of new search / filter functionality
-rw-r--r--app/controllers/application_controller.rb2
-rw-r--r--app/views/admin_public_body/edit.rhtml2
-rw-r--r--app/views/admin_public_body/new.rhtml2
-rw-r--r--app/views/general/blog.rhtml2
-rw-r--r--app/views/general/search.rhtml6
-rw-r--r--app/views/public_body/list.rhtml2
-rw-r--r--app/views/request/_request_filter_form.rhtml12
-rw-r--r--config/routes.rb1
-rw-r--r--spec/controllers/general_controller_spec.rb2
-rw-r--r--spec/controllers/public_body_controller_spec.rb25
-rw-r--r--spec/controllers/request_controller_spec.rb6
-rw-r--r--spec/views/public_body/show.rhtml_spec.rb5
12 files changed, 38 insertions, 29 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index caf613f8d..cb7f3b23d 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -383,7 +383,7 @@ class ApplicationController < ActionController::Base
params[:latest_status] = [params[:latest_status]]
end
if params[:latest_status].include?("recent") || params[:latest_status].include?("all")
- query += " (variety:sent)"
+ query += " variety:sent"
end
if params[:latest_status].include? "successful"
statuses << ['latest_status:successful', 'latest_status:partially_successful']
diff --git a/app/views/admin_public_body/edit.rhtml b/app/views/admin_public_body/edit.rhtml
index 1883eb083..b91f15a2e 100644
--- a/app/views/admin_public_body/edit.rhtml
+++ b/app/views/admin_public_body/edit.rhtml
@@ -1,6 +1,6 @@
<h1><%=@title%></h1>
-<script>
+<script type="text/javascript">
$(function() {
$("#div-locales").tabs();
});
diff --git a/app/views/admin_public_body/new.rhtml b/app/views/admin_public_body/new.rhtml
index 11186ee47..b859fdf6a 100644
--- a/app/views/admin_public_body/new.rhtml
+++ b/app/views/admin_public_body/new.rhtml
@@ -2,7 +2,7 @@
<h1><%=@title%></h1>
-<script>
+<script type="text/javascript">
$(function() {
$("#div-locales").tabs();
});
diff --git a/app/views/general/blog.rhtml b/app/views/general/blog.rhtml
index c9387c24f..f5bd66ebd 100644
--- a/app/views/general/blog.rhtml
+++ b/app/views/general/blog.rhtml
@@ -6,7 +6,7 @@
<% if !@twitter_user.empty? %>
<div id="twitter">
<script src="http://widgets.twimg.com/j/2/widget.js"></script>
-<script>
+<script type="text/javascript">
new TWTR.Widget({
version: 2,
type: 'profile',
diff --git a/app/views/general/search.rhtml b/app/views/general/search.rhtml
index 853765a8a..694ab932f 100644
--- a/app/views/general/search.rhtml
+++ b/app/views/general/search.rhtml
@@ -10,7 +10,7 @@
<% @include_request_link_in_authority_listing = true %>
<h1><%=@title%></h1>
-<script>
+<script type="text/javascript">
$(function() {
$(".use-datepicker").datepicker({dateFormat: 'yy-mm-dd'});
});
@@ -28,9 +28,9 @@
<% else %>
+<% form_tag(request.url, :method => "get") do %>
<div id="list-filter">
<div id="simple-search-box">
- <% form_tag(request.url, :method => "get") do %>
<%= label_tag(:query, _("Search for:")) %>
<%= text_field_tag(:query, params[:query], { :size => 40 }) %>
<%= submit_tag("Search") %>
@@ -109,9 +109,9 @@
</div>
<% end %>
<%= submit_tag("Filter") %>
-<% end %>
</fieldset>
</div>
+<% end %>
<p><%= link_to(_("Advanced search"), advanced_search_url) %></p>
diff --git a/app/views/public_body/list.rhtml b/app/views/public_body/list.rhtml
index b3e945907..c8a89ed3a 100644
--- a/app/views/public_body/list.rhtml
+++ b/app/views/public_body/list.rhtml
@@ -39,9 +39,11 @@
<h1><%=@title%></h1>
<% form_tag(request.url, :method => "get") do %>
+ <div>
<%= label_tag(:public_body_query, _("Search:")) %>
<%= text_field_tag(:public_body_query, params[:public_body_query]) %>
<%= submit_tag(_("Search")) %>
+ </div>
<% end %>
<p class="subtitle">
diff --git a/app/views/request/_request_filter_form.rhtml b/app/views/request/_request_filter_form.rhtml
index fd1fc5910..122da9d33 100644
--- a/app/views/request/_request_filter_form.rhtml
+++ b/app/views/request/_request_filter_form.rhtml
@@ -1,4 +1,4 @@
-<script>
+<script type="text/javascript">
$(function() {
$(".use-datepicker").datepicker();
});
@@ -14,10 +14,12 @@
["awaiting", _("unresolved requests")]] %>
<li>
<% if params[:view] != status %>
- <% if params[:controller] == "public_body" %>
- <%= link_to label, url_for(:controller => "public_body", :action => "show", :view => status, :url_name => @public_body.url_name) + "?#{request.query_string}" %>
+ <% if params[:controller] == "public_body"
+
+ %>
+ <%= link_to label, url_for(:controller => "public_body", :action => "show", :view => status, :url_name => @public_body.url_name) + "?" + request.query_string %>
<% else %>
- <%= link_to label, url_for(:controller => "request", :action => "list", :view => status) + "?#{request.query_string}" %>
+ <%= link_to label, url_for(:controller => "request", :action => "list", :view => status) + "?" + request.query_string %>
<% end %>
<% else %>
<%= label %>
@@ -26,8 +28,8 @@
<% end %>
</ul>
</div>
+ <% form_tag(request.path, :method => "get") do %>
<div class="list-filter-item">
- <% form_tag({}, :method => "get") do %>
<%= label_tag(:query, _("Search for:")) %>
<%= text_field_tag(:query, params[:query]) %>
</div>
diff --git a/config/routes.rb b/config/routes.rb
index 48ad16fc2..c067de4e5 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -23,6 +23,7 @@ ActionController::Routing::Routes.draw do |map|
# Couldn't find a way to do this in routes which also picked up multiple other slashes
# and dots and other characters that can appear in search query. So we sort it all
# out in the controller.
+ general.search_general '/search/*combined/all', :action => 'search', :view => 'all'
general.search_general '/search/*combined', :action => 'search'
general.advanced_search '/advancedsearch', :action => 'search_redirect', :advanced => true
diff --git a/spec/controllers/general_controller_spec.rb b/spec/controllers/general_controller_spec.rb
index 3640a8148..a76cdd3b6 100644
--- a/spec/controllers/general_controller_spec.rb
+++ b/spec/controllers/general_controller_spec.rb
@@ -64,7 +64,7 @@ describe GeneralController, "when searching" do
it "should redirect from search query URL to pretty URL" do
post :search_redirect, :query => "mouse" # query hidden in POST parameters
- response.should redirect_to(:action => 'search', :combined => "mouse") # URL /search/:query
+ response.should redirect_to(:action => 'search', :combined => "mouse", :view => "all") # URL /search/:query/all
end
describe "when using different locale settings" do
diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb
index 0050678d2..0ac2726ea 100644
--- a/spec/controllers/public_body_controller_spec.rb
+++ b/spec/controllers/public_body_controller_spec.rb
@@ -7,47 +7,54 @@ describe PublicBodyController, "when showing a body" do
fixtures :public_bodies, :public_body_translations, :public_body_versions
it "should be successful" do
- get :show, :url_name => "dfh"
+ get :show, :url_name => "dfh", :view => 'all'
response.should be_success
end
it "should render with 'show' template" do
- get :show, :url_name => "dfh"
+ get :show, :url_name => "dfh", :view => 'all'
response.should render_template('show')
end
it "should assign the body" do
- get :show, :url_name => "dfh"
+ get :show, :url_name => "dfh", :view => 'all'
assigns[:public_body].should == public_bodies(:humpadink_public_body)
end
+ it "should assign the requests" do
+ get :show, :url_name => "tgq", :view => 'all'
+ assigns[:xapian_requests].results.count.should == 2
+ get :show, :url_name => "tgq", :view => 'successful'
+ assigns[:xapian_requests].results.count.should == 0
+ end
+
it "should assign the body using different locale from that used for url_name" do
PublicBody.with_locale(:es) do
- get :show, {:url_name => "dfh"}
+ get :show, {:url_name => "dfh", :view => 'all'}
assigns[:public_body].notes.should == "Baguette"
end
end
it "should assign the body using same locale as that used in url_name" do
PublicBody.with_locale(:es) do
- get :show, {:url_name => "edfh"}
+ get :show, {:url_name => "edfh", :view => 'all'}
assigns[:public_body].notes.should == "Baguette"
end
end
it "should redirect use to the relevant locale even when url_name is for a different locale" do
ActionController::Routing::Routes.filters.clear
- get :show, {:url_name => "edfh"}
+ get :show, {:url_name => "edfh", :view => 'all'}
response.should redirect_to "http://test.host/body/dfh"
end
it "should redirect to newest name if you use historic name of public body in URL" do
- get :show, :url_name => "hdink"
+ get :show, :url_name => "hdink", :view => 'all'
response.should redirect_to(:controller => 'public_body', :action => 'show', :url_name => "dfh")
end
it "should redirect to lower case name if you use mixed case name in URL" do
- get :show, :url_name => "dFh"
+ get :show, :url_name => "dFh", :view => 'all'
response.should redirect_to(:controller => 'public_body', :action => 'show', :url_name => "dfh")
end
end
@@ -128,7 +135,7 @@ describe PublicBodyController, "when showing JSON version for API" do
fixtures :public_bodies, :public_body_translations
it "should be successful" do
- get :show, :url_name => "dfh", :format => "json"
+ get :show, :url_name => "dfh", :format => "json", :view => 'all'
pb = JSON.parse(response.body)
pb.class.to_s.should == 'Hash'
diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb
index f69cf414c..7d0cd2c1a 100644
--- a/spec/controllers/request_controller_spec.rb
+++ b/spec/controllers/request_controller_spec.rb
@@ -1,7 +1,3 @@
-# £2k p/a
-# talk about margins
-#
-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
require 'json'
@@ -30,7 +26,7 @@ describe RequestController, "when listing recent requests" do
:matches_estimated => 103)
InfoRequest.should_receive(:full_search).
- with([InfoRequestEvent],"variety:sent", "created_at", anything, anything, anything, anything).
+ with([InfoRequestEvent]," variety:sent", "created_at", anything, anything, anything, anything).
and_return(xap_results)
get :list, :view => 'recent'
assigns[:list_results].size.should == 25
diff --git a/spec/views/public_body/show.rhtml_spec.rb b/spec/views/public_body/show.rhtml_spec.rb
index 7793b9b38..f859b0679 100644
--- a/spec/views/public_body/show.rhtml_spec.rb
+++ b/spec/views/public_body/show.rhtml_spec.rb
@@ -1,7 +1,6 @@
require File.dirname(__FILE__) + '/../../spec_helper'
describe "when viewing a body" do
-
before do
@pb = mock_model(PublicBody,
:name => 'Test Quango',
@@ -28,6 +27,8 @@ describe "when viewing a body" do
assigns[:xapian_requests] = @xap
assigns[:page] = 1
assigns[:per_page] = 10
+ # work round a bug in ActionController::TestRequest; allows request.query_string to work in the template
+ request.env["REQUEST_URI"] = ""
end
it "should be successful" do
@@ -51,7 +52,7 @@ describe "when viewing a body" do
end
it "should cope with no results" do
- @xap.stub!(:results).and_return([])
+ @pb.stub!(:info_requests).and_return([])
render "public_body/show"
response.should have_tag("p", /Nobody has made any Freedom of Information requests/m)
end