diff options
author | Matthew Landauer <matthew@openaustralia.org> | 2013-03-01 15:15:20 +1100 |
---|---|---|
committer | Matthew Landauer <matthew@openaustralia.org> | 2013-03-02 14:49:14 +1100 |
commit | 82f9d1f8618dd22bb7bb34456446ceaf8c742d54 (patch) | |
tree | 7ac655ca31986fd93e9c17f6b7efc4e8be38c8d8 | |
parent | e55dfcf46e2b3821a9b0d6d796b5dbf50875dd24 (diff) |
InfoRequestEvent should know about its event types
-rw-r--r-- | app/models/info_request.rb | 4 | ||||
-rw-r--r-- | app/models/info_request_event.rb | 8 | ||||
-rw-r--r-- | spec/models/info_request_spec.rb | 4 |
3 files changed, 12 insertions, 4 deletions
diff --git a/app/models/info_request.rb b/app/models/info_request.rb index 4951ea3b8..b1a5c905c 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -715,7 +715,7 @@ public end def response_events - self.info_request_events.select{|e| e.event_type == 'response'} + self.info_request_events.select{|e| e.response?} end # The last response is the default one people might want to reply to @@ -730,7 +730,7 @@ public end def outgoing_events - info_request_events.select{|e| [ 'sent', 'followup_sent' ].include?(e.event_type) } + info_request_events.select{|e| e.outgoing? } end # The last outgoing message diff --git a/app/models/info_request_event.rb b/app/models/info_request_event.rb index 024ae97a1..595c82d34 100644 --- a/app/models/info_request_event.rb +++ b/app/models/info_request_event.rb @@ -370,6 +370,14 @@ class InfoRequestEvent < ActiveRecord::Base ['followup_sent', 'followup_resent'].include?(event_type) end + def outgoing? + ['sent', 'followup_sent'].include?(event_type) + end + + def response? + event_type == 'response' + end + def same_email_as_previous_send? prev_addr = self.info_request.get_previous_email_sent_to(self) curr_addr = self.params[:email] diff --git a/spec/models/info_request_spec.rb b/spec/models/info_request_spec.rb index 544852f91..728a538f9 100644 --- a/spec/models/info_request_spec.rb +++ b/spec/models/info_request_spec.rb @@ -426,8 +426,8 @@ describe InfoRequest do before do Time.stub!(:now).and_return(Time.utc(2007, 11, 9, 23, 59)) - @mock_comment_event = safe_mock_model(InfoRequestEvent, :created_at => Time.now - 23.days, :event_type => 'comment') - @mock_response_event = safe_mock_model(InfoRequestEvent, :created_at => Time.now - 22.days, :event_type => 'response') + @mock_comment_event = safe_mock_model(InfoRequestEvent, :created_at => Time.now - 23.days, :event_type => 'comment', :response? => false) + @mock_response_event = safe_mock_model(InfoRequestEvent, :created_at => Time.now - 22.days, :event_type => 'response', :response? => true) @info_request = InfoRequest.new(:prominence => 'normal', :awaiting_description => true, :info_request_events => [@mock_response_event, @mock_comment_event]) |