mirror of
https://github.com/discourse/discourse.git
synced 2025-02-21 11:25:24 +00:00
speed up tests, fix notification of mentioned users in pms
This commit is contained in:
parent
05bcd499d5
commit
437142424c
@ -15,6 +15,8 @@ class PostAlertObserver < ActiveRecord::Observer
|
||||
|
||||
# We need to consider new people to mention / quote when a post is edited
|
||||
def after_save_post(post)
|
||||
return if post.topic.private_message?
|
||||
|
||||
mentioned_users = extract_mentioned_users(post)
|
||||
quoted_users = extract_quoted_users(post)
|
||||
|
||||
|
@ -146,6 +146,7 @@ describe PostCreator do
|
||||
|
||||
end
|
||||
|
||||
# more integration testing ... maximise our testing
|
||||
context 'existing topic' do
|
||||
let!(:topic) { Fabricate(:topic, user: user) }
|
||||
let(:creator) { PostCreator.new(user, raw: 'test reply', topic_id: topic.id, reply_to_post_number: 4) }
|
||||
@ -156,44 +157,36 @@ describe PostCreator do
|
||||
end
|
||||
|
||||
context 'success' do
|
||||
it 'should create the post' do
|
||||
lambda { creator.create }.should change(Post, :count).by(1)
|
||||
it 'create correctly' do
|
||||
post = creator.create
|
||||
Post.count.should == 1
|
||||
Topic.count.should == 1
|
||||
post.reply_to_post_number.should == 4
|
||||
end
|
||||
|
||||
it "doesn't create a topic" do
|
||||
lambda { creator.create }.should_not change(Topic, :count)
|
||||
end
|
||||
|
||||
it "passes through the reply_to_post_number" do
|
||||
creator.create.reply_to_post_number.should == 4
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# integration test ... minimise db work
|
||||
context 'private message' do
|
||||
let(:target_user1) { Fabricate(:coding_horror) }
|
||||
let(:target_user2) { Fabricate(:moderator) }
|
||||
let(:unrelated) { Fabricate(:user) }
|
||||
let(:post) do
|
||||
PostCreator.create(user, title: 'hi there welcome to my topic',
|
||||
raw: "this is my awesome message @#{unrelated.username_lower}",
|
||||
archetype: Archetype.private_message,
|
||||
target_usernames: [target_user1.username, target_user2.username].join(','))
|
||||
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 'acts correctly' do
|
||||
post.topic.archetype.should == Archetype.private_message
|
||||
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
|
||||
# does not notify an unrelated user
|
||||
unrelated.notifications.count.should == 0
|
||||
post.topic.subtype.should == TopicSubtype.user_to_user
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user