aboutsummaryrefslogtreecommitdiffstats
path: root/spec/models/outgoing_message_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models/outgoing_message_spec.rb')
-rw-r--r--spec/models/outgoing_message_spec.rb101
1 files changed, 100 insertions, 1 deletions
diff --git a/spec/models/outgoing_message_spec.rb b/spec/models/outgoing_message_spec.rb
index 60164fb31..8c000665b 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,10 +66,85 @@ 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
-describe IncomingMessage, " when censoring data" do
+describe OutgoingMessage, " when censoring data" do
before do
@om = outgoing_messages(:useless_outgoing_message)
@@ -73,4 +164,12 @@ describe IncomingMessage, " when censoring data" do
end
end
+describe OutgoingMessage, "when validating the format of the message body", :focus => true do
+ it 'should handle a salutation with a bracket in it' do
+ outgoing_message = FactoryGirl.build(:initial_request)
+ outgoing_message.stub!(:get_salutation).and_return("Dear Bob (Robert,")
+ lambda{ outgoing_message.valid? }.should_not raise_error(RegexpError)
+ end
+
+end