diff options
-rw-r--r-- | app/models/incoming_message.rb | 4 | ||||
-rw-r--r-- | app/models/info_request_event.rb | 4 | ||||
-rw-r--r-- | spec/models/incoming_message_spec.rb | 23 | ||||
-rw-r--r-- | spec/models/info_request_event_spec.rb | 41 |
4 files changed, 72 insertions, 0 deletions
diff --git a/app/models/incoming_message.rb b/app/models/incoming_message.rb index f444e92ad..37acc6a99 100644 --- a/app/models/incoming_message.rb +++ b/app/models/incoming_message.rb @@ -76,6 +76,10 @@ class IncomingMessage < ActiveRecord::Base Ability.can_view_with_prominence?(self.prominence, self.info_request, user) end + def indexed_by_search? + self.prominence == 'normal' + end + # Return a cached structured mail object def mail(force = nil) if (!force.nil? || @mail.nil?) && !self.raw_email.nil? diff --git a/app/models/info_request_event.rb b/app/models/info_request_event.rb index 6c8d21f99..78c800ad1 100644 --- a/app/models/info_request_event.rb +++ b/app/models/info_request_event.rb @@ -235,6 +235,9 @@ class InfoRequestEvent < ActiveRecord::Base if !self.info_request.indexed_by_search? return false end + if self.event_type == 'response' && !self.incoming_message.indexed_by_search? + return false + end if self.event_type == 'comment' && !self.comment.visible return false end @@ -243,6 +246,7 @@ class InfoRequestEvent < ActiveRecord::Base return false end end + def variety self.event_type end diff --git a/spec/models/incoming_message_spec.rb b/spec/models/incoming_message_spec.rb index 51df16194..c0a7e5340 100644 --- a/spec/models/incoming_message_spec.rb +++ b/spec/models/incoming_message_spec.rb @@ -112,6 +112,29 @@ describe IncomingMessage, 'when asked if a user can view it' do end +describe 'when asked if it is indexed by search' do + + before do + @incoming_message = IncomingMessage.new + end + + it 'should return false if it has prominence "hidden"' do + @incoming_message.prominence = 'hidden' + @incoming_message.indexed_by_search?.should be_false + end + + it 'should return false if it has prominence "requester_only"' do + @incoming_message.prominence = 'requester_only' + @incoming_message.indexed_by_search?.should be_false + end + + it 'should return true if it has prominence "normal"' do + @incoming_message.prominence = 'normal' + @incoming_message.indexed_by_search?.should be_true + end + +end + describe IncomingMessage, " when dealing with incoming mail" do before(:each) do diff --git a/spec/models/info_request_event_spec.rb b/spec/models/info_request_event_spec.rb index 7f485454d..5feb3560a 100644 --- a/spec/models/info_request_event_spec.rb +++ b/spec/models/info_request_event_spec.rb @@ -32,6 +32,47 @@ describe InfoRequestEvent do end + describe 'when deciding if it is indexed by search' do + + before do + @comment = mock_model(Comment) + @incoming_message = mock_model(IncomingMessage) + @info_request = mock_model(InfoRequest, :indexed_by_search? => true) + end + + it 'should return false for a comment that is not visible' do + @comment.stub!(:visible).and_return(false) + @info_request_event = InfoRequestEvent.new(:event_type => 'comment', + :comment => @comment, + :info_request => @info_request) + @info_request_event.indexed_by_search?.should be_false + end + + it 'should return true for a comment that is visible' do + @comment.stub!(:visible).and_return(true) + @info_request_event = InfoRequestEvent.new(:event_type => 'comment', + :comment => @comment, + :info_request => @info_request) + @info_request_event.indexed_by_search?.should be_true + end + + it 'should return false for an incoming message that is not indexed by search' do + @incoming_message.stub!(:indexed_by_search?).and_return false + @info_request_event = InfoRequestEvent.new(:event_type => 'response', + :incoming_message => @incoming_message, + :info_request => @info_request) + @info_request_event.indexed_by_search?.should be_false + end + + it 'should return true for an incoming message with prominence "normal"' do + @incoming_message.stub!(:indexed_by_search?).and_return true + @info_request_event = InfoRequestEvent.new(:event_type => 'response', + :incoming_message => @incoming_message, + :info_request => @info_request) + @info_request_event.indexed_by_search?.should be_true + end + end + describe 'after saving' do it 'should mark the model for reindexing in xapian if there is no no_xapian_reindex flag on the object' do |