diff options
Diffstat (limited to 'spec/models/info_request_spec.rb')
-rw-r--r-- | spec/models/info_request_spec.rb | 42 |
1 files changed, 26 insertions, 16 deletions
diff --git a/spec/models/info_request_spec.rb b/spec/models/info_request_spec.rb index cbcf7eecc..09b258ee4 100644 --- a/spec/models/info_request_spec.rb +++ b/spec/models/info_request_spec.rb @@ -195,7 +195,7 @@ describe InfoRequest do :order => anything, :conditions=> anything, :limit => 5}) - InfoRequest.find_old_unclassified(limit=5) + InfoRequest.find_old_unclassified(:limit => 5) end it 'should not limit the number of requests returned by default' do @@ -206,12 +206,21 @@ describe InfoRequest do InfoRequest.find_old_unclassified end - it 'should ask the database for requests that are awaiting description, older than 10 days old and not backpaged' do + it 'should add extra conditions if supplied' 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 order by created_at desc limit 1) as last_event_time", - :order=>"last_event_time", - :conditions=>["awaiting_description = ? and (select created_at from info_request_events where info_request_events.info_request_id = info_requests.id order by created_at desc limit 1) < ? and prominence != 'backpage'", - true, Time.now - 10.days]}) + {: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 prominence != 'backpage'", + true, Time.now - 14.days]}) + 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 14 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'", + true, Time.now - 14.days]}) InfoRequest.find_old_unclassified end @@ -221,28 +230,29 @@ describe InfoRequest do before do Time.stub!(:now).and_return(Time.utc(2007, 11, 12, 23, 59)) - @mock_event = mock_model(InfoRequestEvent, :created_at => Time.now - 11.days) + @mock_comment_event = mock_model(InfoRequestEvent, :created_at => Time.now - 16.days, :event_type => 'comment') + @mock_response_event = mock_model(InfoRequestEvent, :created_at => Time.now - 15.days, :event_type => 'response') @info_request = InfoRequest.new(:prominence => 'normal', :awaiting_description => true, - :info_request_events => [@mock_event]) + :info_request_events => [@mock_response_event, @mock_comment_event]) end - it 'should return false if it is not awaiting description' do - @info_request.stub!(:awaiting_description).and_return(false) + it 'should return false if it is the holding pen' do + @info_request.stub!(:url_title).and_return('holding_pen') @info_request.is_old_unclassified?.should be_false end - it 'should return false if it\'s last event occurred less than 10 days ago' do - @mock_event.stub!(:created_at).and_return(Time.now - 9.days) + it 'should return false if it is not awaiting description' do + @info_request.stub!(:awaiting_description).and_return(false) @info_request.is_old_unclassified?.should be_false end - it 'should return false if it\'s backpaged' do - @info_request.stub!(:prominence).and_return('backpage') - @info_request.is_old_unclassified?.should be_false + it 'should return false if it\'s last response event occurred less than 14 days ago' do + @mock_response_event.stub!(:created_at).and_return(Time.now - 13.days) + @info_request.is_old_unclassified?.should be_false end - it 'should return true if it is awaiting description, hasn\'t had an event in 10 days and is not backpaged' do + it 'should return true if it is awaiting description, isn\'t the holding pen and hasn\'t had an event in 14 days' do @info_request.is_old_unclassified?.should be_true end |