diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/admin_general_controller_spec.rb | 45 | ||||
-rw-r--r-- | spec/controllers/api_controller_spec.rb | 15 | ||||
-rw-r--r-- | spec/controllers/request_controller_spec.rb | 14 | ||||
-rw-r--r-- | spec/fixtures/public_bodies.yml | 14 | ||||
-rw-r--r-- | spec/fixtures/public_body_translations.yml | 17 | ||||
-rw-r--r-- | spec/models/info_request_spec.rb | 59 | ||||
-rw-r--r-- | spec/models/public_body_spec.rb | 18 | ||||
-rw-r--r-- | spec/models/request_mailer_spec.rb | 33 |
8 files changed, 171 insertions, 44 deletions
diff --git a/spec/controllers/admin_general_controller_spec.rb b/spec/controllers/admin_general_controller_spec.rb index 820d1e7f3..dc1eb0d97 100644 --- a/spec/controllers/admin_general_controller_spec.rb +++ b/spec/controllers/admin_general_controller_spec.rb @@ -1,18 +1,39 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') -describe AdminGeneralController, "when viewing front page of admin interface" do - integrate_views - before { basic_auth_login @request } - - it "should render the front page" do - get :index, :suppress_redirect => 1 - response.should render_template('index') - end +describe AdminGeneralController do + + describe "when viewing front page of admin interface" do + + integrate_views + before { basic_auth_login @request } + + it "should render the front page" do + get :index, :suppress_redirect => 1 + response.should render_template('index') + end + + it "should redirect to include trailing slash" do + get :index + response.should redirect_to(:controller => 'admin_general', + :action => 'index') + end - it "should redirect to include trailing slash" do - get :index - response.should redirect_to(:controller => 'admin_general', - :action => 'index') end + describe 'when viewing the timeline' do + + it 'should assign an array of events in order of descending date to the view' do + get :timeline, :all => 1 + previous_event = nil + previous_event_at = nil + assigns[:events].each do |event, event_at| + if previous_event + (event_at <= previous_event_at).should be_true + end + previous_event = event + previous_event_at = event_at + end + end + + end end diff --git a/spec/controllers/api_controller_spec.rb b/spec/controllers/api_controller_spec.rb index 925b7adb4..ded9a040a 100644 --- a/spec/controllers/api_controller_spec.rb +++ b/spec/controllers/api_controller_spec.rb @@ -320,6 +320,21 @@ describe ApiController, "when using the API" do assigns[:event_data].should == [first_event] end + it "should honour the since_date parameter for the Atom feed" do + get :body_request_events, + :id => public_bodies(:humpadink_public_body).id, + :k => public_bodies(:humpadink_public_body).api_key, + :since_date => "2010-01-01", + :feed_type => "atom" + + response.should be_success + response.should render_template("api/request_events.atom") + assigns[:events].size.should > 0 + assigns[:events].each do |event| + event.created_at.should >= Date.new(2010, 1, 1) + end + end + it "should return a JSON 404 error for non-existent requests" do request_id = 123459876 # Let's hope this doesn't exist! sent_at = "2012-05-28T12:35:39+01:00" diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index b8425613c..95737a250 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -1275,7 +1275,8 @@ describe RequestController, "when classifying an information request" do expected_params = {:user_id => users(:silly_name_user).id, :old_described_state => 'waiting_response', :described_state => 'rejected'} - @dog_request.should_receive(:log_event).with("status_update", expected_params) + event = mock_model(InfoRequestEvent) + @dog_request.should_receive(:log_event).with("status_update", expected_params).and_return(event) post_status('rejected') end @@ -1314,10 +1315,19 @@ describe RequestController, "when classifying an information request" do end it 'should log a status update event' do + event = mock_model(InfoRequestEvent) expected_params = {:user_id => @admin_user.id, :old_described_state => 'waiting_response', :described_state => 'rejected'} - @dog_request.should_receive(:log_event).with("status_update", expected_params) + @dog_request.should_receive(:log_event).with("status_update", expected_params).and_return(event) + post_status('rejected') + end + + it 'should record a classification' do + event = mock_model(InfoRequestEvent) + @dog_request.stub!(:log_event).with("status_update", anything()).and_return(event) + RequestClassification.should_receive(:create!).with(:user_id => @admin_user.id, + :info_request_event_id => event.id) post_status('rejected') end diff --git a/spec/fixtures/public_bodies.yml b/spec/fixtures/public_bodies.yml index 367e0fc50..615c4bcb6 100644 --- a/spec/fixtures/public_bodies.yml +++ b/spec/fixtures/public_bodies.yml @@ -1,4 +1,4 @@ -geraldine_public_body: +geraldine_public_body: name: The Geraldine Quango first_letter: T updated_at: 2007-10-24 10:51:01.161639 @@ -11,7 +11,8 @@ geraldine_public_body: url_name: tgq created_at: 2007-10-24 10:51:01.161639 api_key: 1 -humpadink_public_body: + info_requests_count: 4 +humpadink_public_body: name: "Department for Humpadinking" first_letter: D updated_at: 2007-10-25 10:51:01.161639 @@ -25,6 +26,7 @@ humpadink_public_body: created_at: 2007-10-25 10:51:01.161639 notes: An albatross told me!!! api_key: 2 + info_requests_count: 2 forlorn_public_body: name: "Department of Loneliness" first_letter: D @@ -39,7 +41,8 @@ forlorn_public_body: created_at: 2011-01-26 14:11:02.12345 notes: A very lonely public body that no one has corresponded with api_key: 3 -silly_walks_public_body: + info_requests_count: 0 +silly_walks_public_body: id: 5 version: 1 name: "Ministry of Silly Walks" @@ -53,7 +56,8 @@ silly_walks_public_body: created_at: 2007-10-25 10:51:01.161639 notes: You know the one. api_key: 4 -sensible_walks_public_body: + info_requests_count: 2 +sensible_walks_public_body: id: 6 version: 1 name: "Ministry of Sensible Walks" @@ -67,4 +71,4 @@ sensible_walks_public_body: last_edit_editor: robin created_at: 2008-10-25 10:51:01.161639 api_key: 5 - + info_requests_count: 1 diff --git a/spec/fixtures/public_body_translations.yml b/spec/fixtures/public_body_translations.yml index cbb55bb0c..f3453e853 100644 --- a/spec/fixtures/public_body_translations.yml +++ b/spec/fixtures/public_body_translations.yml @@ -1,4 +1,4 @@ -geraldine_es_public_body_translation: +geraldine_es_public_body_translation: name: El A Geraldine Quango first_letter: E request_email: geraldine-requests@localhost @@ -8,8 +8,9 @@ geraldine_es_public_body_translation: url_name: etgq locale: es notes: "" + publication_scheme: "" -geraldine_en_public_body_translation: +geraldine_en_public_body_translation: name: Geraldine Quango first_letter: G request_email: geraldine-requests@localhost @@ -19,8 +20,9 @@ geraldine_en_public_body_translation: url_name: tgq locale: en notes: "" + publication_scheme: "" -humpadink_es_public_body_translation: +humpadink_es_public_body_translation: name: "El Department for Humpadinking" first_letter: E request_email: humpadink-requests@localhost @@ -30,8 +32,9 @@ humpadink_es_public_body_translation: url_name: edfh locale: es notes: Baguette + publication_scheme: "" -humpadink_en_public_body_translation: +humpadink_en_public_body_translation: name: "Department for Humpadinking" first_letter: D request_email: humpadink-requests@localhost @@ -41,8 +44,9 @@ humpadink_en_public_body_translation: url_name: dfh locale: en notes: An albatross told me!!! + publication_scheme: "" -forlorn_en_public_body_translation: +forlorn_en_public_body_translation: name: "Department of Loneliness" first_letter: D request_email: forlorn-requests@localhost @@ -52,6 +56,7 @@ forlorn_en_public_body_translation: url_name: lonely locale: en notes: A very lonely public body that no one has corresponded with + publication_scheme: "" silly_walks_en_public_body_translation: id: 6 @@ -63,6 +68,7 @@ silly_walks_en_public_body_translation: short_name: MSW url_name: msw notes: You know the one. + publication_scheme: "" sensible_walks_en_public_body_translation: id: 7 @@ -74,3 +80,4 @@ sensible_walks_en_public_body_translation: short_name: SenseWalk url_name: sensible_walks notes: I bet you’ve never heard of it. + publication_scheme: "" diff --git a/spec/models/info_request_spec.rb b/spec/models/info_request_spec.rb index c55127992..204c600d9 100644 --- a/spec/models/info_request_spec.rb +++ b/spec/models/info_request_spec.rb @@ -341,6 +341,14 @@ describe InfoRequest do InfoRequest.find_old_unclassified(:limit => 5) end + it 'should ask for requests using any offset param supplied' do + InfoRequest.should_receive(:find).with(:all, {:select => anything, + :order => anything, + :conditions=> anything, + :offset => 100}) + InfoRequest.find_old_unclassified(:offset => 100) + end + it 'should not limit the number of requests returned by default' do InfoRequest.should_not_receive(:find).with(:all, {:select => anything, :order => anything, @@ -350,20 +358,49 @@ describe InfoRequest do end it 'should add extra conditions if supplied' do - InfoRequest.should_receive(:find).with(:all, - {:select=> anything, - :order=> anything, - :conditions=>["awaiting_description = ? and (select created_at from info_request_events where info_request_events.info_request_id = info_requests.id and info_request_events.event_type = 'response' order by created_at desc limit 1) < ? and url_title != 'holding_pen' and user_id is not null and prominence != 'backpage'", - true, Time.now - 21.days]}) + expected_conditions = ["awaiting_description = ? + AND (SELECT created_at + FROM info_request_events + WHERE info_request_events.info_request_id = info_requests.id + AND info_request_events.event_type = 'response' + ORDER BY created_at desc LIMIT 1) < ? + AND url_title != 'holding_pen' + AND user_id IS NOT NULL + AND prominence != 'backpage'".split(' ').join(' '), + true, Time.now - 21.days] + # compare conditions ignoring whitespace differences + InfoRequest.should_receive(:find) do |all, query_params| + query_string = query_params[:conditions][0] + query_params[:conditions][0] = query_string.split(' ').join(' ') + query_params[:conditions].should == expected_conditions + end InfoRequest.find_old_unclassified({:conditions => ["prominence != 'backpage'"]}) end - it 'should ask the database for requests that are awaiting description, have a last response older than 21 days old, are not the holding pen and are not backpaged' do - InfoRequest.should_receive(:find).with(:all, - {:select=>"*, (select created_at from info_request_events where info_request_events.info_request_id = info_requests.id and info_request_events.event_type = 'response' order by created_at desc limit 1) as last_response_time", - :order=>"last_response_time", - :conditions=>["awaiting_description = ? and (select created_at from info_request_events where info_request_events.info_request_id = info_requests.id and info_request_events.event_type = 'response' order by created_at desc limit 1) < ? and url_title != 'holding_pen' and user_id is not null", - true, Time.now - 21.days]}) + it 'should ask the database for requests that are awaiting description, have a last response older + than 21 days old, have a user, are not the holding pen and are not backpaged' do + expected_conditions = ["awaiting_description = ? + AND (SELECT created_at + FROM info_request_events + WHERE info_request_events.info_request_id = info_requests.id + AND info_request_events.event_type = 'response' + ORDER BY created_at desc LIMIT 1) < ? + AND url_title != 'holding_pen' + AND user_id IS NOT NULL".split(' ').join(' '), + true, Time.now - 21.days] + expected_select = "*, (SELECT created_at + FROM info_request_events + WHERE info_request_events.info_request_id = info_requests.id + AND info_request_events.event_type = 'response' + ORDER BY created_at desc LIMIT 1) + AS last_response_time".split(' ').join(' ') + InfoRequest.should_receive(:find) do |all, query_params| + query_string = query_params[:conditions][0] + query_params[:conditions][0] = query_string.split(' ').join(' ') + query_params[:conditions].should == expected_conditions + query_params[:select].split(' ').join(' ').should == expected_select + query_params[:order].should == "last_response_time" + end InfoRequest.find_old_unclassified end diff --git a/spec/models/public_body_spec.rb b/spec/models/public_body_spec.rb index 8ff6afde3..011824190 100644 --- a/spec/models/public_body_spec.rb +++ b/spec/models/public_body_spec.rb @@ -222,6 +222,10 @@ describe PublicBody, "when searching" do body.name.should == "El A Geraldine Quango" end end + + it 'should not raise an error on a name with a single quote in it' do + body = PublicBody.find_by_url_name_with_historic("belfast city council'") + end end describe PublicBody, " when dealing public body locales" do @@ -403,6 +407,7 @@ describe PublicBody, " when loading CSV files" do end describe PublicBody do + describe "calculated home page" do it "should return the home page verbatim if it's present" do public_body = PublicBody.new @@ -434,4 +439,17 @@ describe PublicBody do public_body.calculated_home_page.should == "https://example.com" end end + + describe 'when asked for notes without html' do + + before do + @public_body = PublicBody.new(:notes => 'some <a href="/notes">notes</a>') + end + + it 'should remove simple tags from notes' do + @public_body.notes_without_html.should == 'some notes' + end + + end + end diff --git a/spec/models/request_mailer_spec.rb b/spec/models/request_mailer_spec.rb index ea75ec765..98681a9e9 100644 --- a/spec/models/request_mailer_spec.rb +++ b/spec/models/request_mailer_spec.rb @@ -29,7 +29,7 @@ describe RequestMailer, " when receiving incoming mail" do InfoRequest.holding_pen_request.incoming_messages.size.should == 1 last_event = InfoRequest.holding_pen_request.incoming_messages[0].info_request.get_last_event last_event.params[:rejected_reason].should == "Could not identify the request from the email address" - + deliveries = ActionMailer::Base.deliveries deliveries.size.should == 1 mail = deliveries[0] @@ -49,7 +49,7 @@ describe RequestMailer, " when receiving incoming mail" do InfoRequest.holding_pen_request.incoming_messages.size.should == 1 last_event = InfoRequest.holding_pen_request.incoming_messages[0].info_request.get_last_event last_event.params[:rejected_reason].should =~ /there is no "From" address/ - + deliveries = ActionMailer::Base.deliveries deliveries.size.should == 1 mail = deliveries[0] @@ -69,7 +69,7 @@ describe RequestMailer, " when receiving incoming mail" do InfoRequest.holding_pen_request.incoming_messages.size.should == 1 last_event = InfoRequest.holding_pen_request.incoming_messages[0].info_request.get_last_event last_event.params[:rejected_reason].should =~ /Only the authority can reply/ - + deliveries = ActionMailer::Base.deliveries deliveries.size.should == 1 mail = deliveries[0] @@ -222,12 +222,27 @@ describe RequestMailer, "when sending reminders to requesters to classify a resp RequestMailer.alert_new_response_reminders_internal(7, 'new_response_reminder_1') end - it 'should ask for all requests that are awaiting description and whose latest response is older than the number of days given and that are not the holding pen' do - expected_params = {:conditions => [ "awaiting_description = ? and (select created_at from info_request_events where info_request_events.info_request_id = info_requests.id and info_request_events.event_type = 'response' order by created_at desc limit 1) < ? and url_title != 'holding_pen' and user_id is not null", - true, Time.now() - 7.days ], - :include => [ :user ], - :order => "info_requests.id"} - InfoRequest.should_receive(:find).with(:all, expected_params).and_return([]) + it 'should ask for all requests that are awaiting description and whose latest response is older + than the number of days given and that are not the holding pen' do + expected_conditions = [ "awaiting_description = ? + AND (SELECT created_at + FROM info_request_events + WHERE info_request_events.info_request_id = info_requests.id + AND info_request_events.event_type = 'response' + ORDER BY created_at desc LIMIT 1) < ? + AND url_title != 'holding_pen' + AND user_id IS NOT NULL".split(' ').join(' '), + true, Time.now() - 7.days ] + + # compare the query string ignoring any spacing differences + InfoRequest.should_receive(:find) do |all, query_params| + query_string = query_params[:conditions][0] + query_params[:conditions][0] = query_string.split(' ').join(' ') + query_params[:conditions].should == expected_conditions + query_params[:include].should == [ :user ] + query_params[:order].should == 'info_requests.id' + end + send_alerts end |