aboutsummaryrefslogtreecommitdiffstats
path: root/spec/models/outgoing_message_spec.rb
diff options
context:
space:
mode:
authorLouise Crow <louise.crow@gmail.com>2013-09-24 11:29:31 +0100
committerLouise Crow <louise.crow@gmail.com>2013-09-24 11:29:31 +0100
commitd8deb8418b4cd26c68eb1301959e156c19b111e2 (patch)
tree99c346db95d17be9c5105ce47d5f3ac8e943e952 /spec/models/outgoing_message_spec.rb
parent8459314b691f5b02277035219cd58f510d100a77 (diff)
parent75542416a1cc36b353ade557b1bc4f729b02423a (diff)
Merge branch 'release/0.14'0.14
Conflicts: locale/bg/app.po locale/fr/app.po locale/fr_CA/app.po locale/he_IL/app.po locale/hr/app.po locale/it/app.po locale/nb_NO/app.po locale/pl/app.po locale/sv/app.po locale/vi/app.po
Diffstat (limited to 'spec/models/outgoing_message_spec.rb')
-rw-r--r--spec/models/outgoing_message_spec.rb93
1 files changed, 91 insertions, 2 deletions
diff --git a/spec/models/outgoing_message_spec.rb b/spec/models/outgoing_message_spec.rb
index 60164fb31..1e05e09f1 100644
--- a/spec/models/outgoing_message_spec.rb
+++ b/spec/models/outgoing_message_spec.rb
@@ -1,3 +1,19 @@
+# == Schema Information
+#
+# Table name: outgoing_messages
+#
+# id :integer not null, primary key
+# info_request_id :integer not null
+# body :text not null
+# status :string(255) not null
+# message_type :string(255) not null
+# created_at :datetime not null
+# updated_at :datetime not null
+# last_sent_at :datetime
+# incoming_message_followup_id :integer
+# what_doing :string(255) not null
+#
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe OutgoingMessage, " when making an outgoing message" do
@@ -50,6 +66,81 @@ describe OutgoingMessage, " when making an outgoing message" do
outgoing_message.body.should include(expected_text)
end
+ describe 'when asked if a user can view it' do
+
+ before do
+ @info_request = FactoryGirl.create(:info_request)
+ @outgoing_message = @info_request.outgoing_messages.first
+ end
+
+ context 'if the prominence is hidden' do
+
+ before do
+ @outgoing_message.prominence = 'hidden'
+ end
+
+ it 'should return true for an admin user' do
+ @outgoing_message.user_can_view?(FactoryGirl.create(:admin_user)).should be_true
+ end
+
+ it 'should return false for a non-admin user' do
+ @outgoing_message.user_can_view?(FactoryGirl.create(:user)).should be_false
+ end
+
+ end
+
+ context 'if the prominence is requester_only' do
+
+ before do
+ @outgoing_message.prominence = 'requester_only'
+ end
+
+ it 'should return true if the user owns the associated request' do
+ @outgoing_message.user_can_view?(@info_request.user).should be_true
+ end
+
+ it 'should return false if the user does not own the associated request' do
+ @outgoing_message.user_can_view?(FactoryGirl.create(:user)).should be_false
+ end
+ end
+
+ context 'if the prominence is normal' do
+
+ before do
+ @outgoing_message.prominence = 'normal'
+ end
+
+ it 'should return true for a non-admin user' do
+ @outgoing_message.user_can_view?(FactoryGirl.create(:user)).should be_true
+ end
+
+ end
+
+ end
+
+ describe 'when asked if it is indexed by search' do
+
+ before do
+ @info_request = FactoryGirl.create(:info_request)
+ @outgoing_message = @info_request.outgoing_messages.first
+ end
+
+ it 'should return false if it has prominence "hidden"' do
+ @outgoing_message.prominence = 'hidden'
+ @outgoing_message.indexed_by_search?.should be_false
+ end
+
+ it 'should return false if it has prominence "requester_only"' do
+ @outgoing_message.prominence = 'requester_only'
+ @outgoing_message.indexed_by_search?.should be_false
+ end
+
+ it 'should return true if it has prominence "normal"' do
+ @outgoing_message.prominence = 'normal'
+ @outgoing_message.indexed_by_search?.should be_true
+ end
+
+ end
end
@@ -72,5 +163,3 @@ describe IncomingMessage, " when censoring data" do
@om.body.should match(/fancy cat/)
end
end
-
-