aboutsummaryrefslogtreecommitdiffstats
path: root/spec/models
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/info_request_spec.rb59
-rw-r--r--spec/models/public_body_spec.rb18
-rw-r--r--spec/models/request_mailer_spec.rb33
3 files changed, 90 insertions, 20 deletions
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