Add subtype to topics to classify private messages

This commit is contained in:
Neil Lalonde
2013-04-16 16:56:18 -04:00
parent 2b5a2b5fce
commit 3b6aeb14c7
16 changed files with 223 additions and 43 deletions
+19 -12
View File
@@ -1,5 +1,6 @@
require 'spec_helper'
require 'post_creator'
require 'topic_subtype'
describe PostCreator do
@@ -173,22 +174,28 @@ describe PostCreator do
context 'private message' do
let(:target_user1) { Fabricate(:coding_horror) }
let(:target_user2) { Fabricate(:moderator) }
let(:post) do
PostCreator.create(user, title: 'hi there welcome to my topic',
raw: 'this is my awesome message',
archetype: Archetype.private_message,
target_usernames: [target_user1.username, target_user2.username].join(','))
end
it 'has the right archetype' do
post.topic.archetype.should == Archetype.private_message
end
describe 'regular user to user' do
let(:post) do
PostCreator.create(user, title: 'hi there welcome to my topic',
raw: 'this is my awesome message',
archetype: Archetype.private_message,
target_usernames: [target_user1.username, target_user2.username].join(','))
end
it 'has the right count (me and 2 other users)' do
post.topic.topic_allowed_users.count.should == 3
it 'has the right archetype' do
post.topic.archetype.should == Archetype.private_message
end
it 'has the right count (me and 2 other users)' do
post.topic.topic_allowed_users.count.should == 3
end
it 'has the right subtype' do
post.topic.subtype.should == TopicSubtype.user_to_user
end
end
end
end
+5
View File
@@ -1,5 +1,6 @@
require 'spec_helper'
require 'system_message'
require 'topic_subtype'
describe SystemMessage do
@@ -20,6 +21,10 @@ describe SystemMessage do
topic.should be_private_message
end
it 'should have the correct topic subtype' do
topic.subtype.should == TopicSubtype.system_message
end
it 'should be visible by the user' do
topic.allowed_users.include?(user).should be_true
end
+1
View File
@@ -68,6 +68,7 @@ Fabricator(:private_message_post, from: :post) do
Fabricate( :private_message_topic,
user: attrs[:user],
created_at: attrs[:created_at],
subtype: TopicSubtype.user_to_user,
topic_allowed_users: [
Fabricate.build(:topic_allowed_user, user_id: attrs[:user].id),
Fabricate.build(:topic_allowed_user, user_id: Fabricate(:user).id)
+35 -11
View File
@@ -18,19 +18,43 @@ describe PostAction do
let(:bookmark) { PostAction.new(user_id: post.user_id, post_action_type_id: PostActionType.types[:bookmark] , post_id: post.id) }
describe "messaging" do
it "sends an email to all moderators if selected" do
PostAction.stubs(:create)
PostAction.expects(:target_moderators).returns("bob")
PostCreator.any_instance.expects(:create).returns(nil)
PostAction.act(build(:user), build(:post), PostActionType.types[:notify_moderators], "this is my special message");
describe 'notify_moderators' do
before do
PostAction.stubs(:create)
PostAction.expects(:target_moderators).returns("bob")
end
it "sends an email to all moderators if selected" do
PostCreator.any_instance.expects(:create).returns(nil)
PostAction.act(build(:user), build(:post), PostActionType.types[:notify_moderators], "this is my special message");
end
it "uses the correct topic subtype" do
PostCreator.expects(:new).with do |user, opts|
opts[:subtype] == TopicSubtype.notify_moderators
end.returns(stub_everything)
PostAction.act(build(:user), build(:post), PostActionType.types[:notify_moderators], "this is my special message");
end
end
it "sends an email to user if selected" do
PostAction.stubs(:create)
PostCreator.any_instance.expects(:create).returns(nil)
post = build(:post)
post.user = build(:user)
PostAction.act(build(:user), post, PostActionType.types[:notify_user], "this is my special message");
describe "notify_user" do
before do
PostAction.stubs(:create)
post = build(:post)
post.user = build(:user)
end
it "sends an email to user if selected" do
PostCreator.any_instance.expects(:create).returns(nil)
PostAction.act(build(:user), post, PostActionType.types[:notify_user], "this is my special message");
end
it "uses the correct topic subtype" do
PostCreator.expects(:new).with do |user, opts|
opts[:subtype] == TopicSubtype.notify_user
end.returns(stub_everything)
PostAction.act(build(:user), post, PostActionType.types[:notify_user], "this is my special message");
end
end
end
+1 -1
View File
@@ -61,7 +61,7 @@ describe Report do
end
describe 'private messages' do
let(:report) { Report.find('private_messages') }
let(:report) { Report.find('user_to_user_private_messages') }
it 'topic report should not include private messages' do
Fabricate(:private_message_topic, created_at: 1.hour.ago)