mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-30 10:58:31 -05:00
3e50313fdc
Since rspec-rails 3, the default installation creates two helper files: * `spec_helper.rb` * `rails_helper.rb` `spec_helper.rb` is intended as a way of running specs that do not require Rails, whereas `rails_helper.rb` loads Rails (as Discourse's current `spec_helper.rb` does). For more information: https://www.relishapp.com/rspec/rspec-rails/docs/upgrade#default-helper-files In this commit, I've simply replaced all instances of `spec_helper` with `rails_helper`, and renamed the original `spec_helper.rb`. This brings the Discourse project closer to the standard usage of RSpec in a Rails app. At present, every spec relies on loading Rails, but there are likely many that don't need to. In a future pull request, I hope to introduce a separate, minimal `spec_helper.rb` which can be used in tests which don't rely on Rails.
102 lines
3 KiB
Ruby
102 lines
3 KiB
Ruby
require 'rails_helper'
|
|
require_dependency 'post_destroyer'
|
|
|
|
describe PostAlertObserver do
|
|
|
|
before do
|
|
ActiveRecord::Base.observers.enable :post_alert_observer
|
|
end
|
|
|
|
let!(:evil_trout) { Fabricate(:evil_trout) }
|
|
let(:post) { Fabricate(:post) }
|
|
|
|
context 'liking' do
|
|
context 'when liking a post' do
|
|
it 'creates a notification' do
|
|
expect {
|
|
PostAction.act(evil_trout, post, PostActionType.types[:like])
|
|
# one like (welcome badge deferred)
|
|
}.to change(Notification, :count).by(1)
|
|
end
|
|
end
|
|
|
|
context 'when removing a liked post' do
|
|
before do
|
|
PostAction.act(evil_trout, post, PostActionType.types[:like])
|
|
end
|
|
|
|
it 'removes a notification' do
|
|
expect {
|
|
PostAction.remove_act(evil_trout, post, PostActionType.types[:like])
|
|
}.to change(Notification, :count).by(-1)
|
|
end
|
|
end
|
|
end
|
|
|
|
context 'when editing a post' do
|
|
it 'notifies a user of the revision' do
|
|
expect {
|
|
post.revise(evil_trout, { raw: "world is the new body of the message" })
|
|
}.to change(post.user.notifications, :count).by(1)
|
|
end
|
|
|
|
context "edit notifications are disabled" do
|
|
|
|
before { SiteSetting.stubs(:disable_edit_notifications).returns(true) }
|
|
|
|
|
|
it 'notifies a user of the revision made by another user' do
|
|
expect {
|
|
post.revise(evil_trout, { raw: "world is the new body of the message" })
|
|
}.to change(post.user.notifications, :count).by(1)
|
|
end
|
|
|
|
it 'does not notifiy a user of the revision made by the system user' do
|
|
expect {
|
|
post.revise(Discourse.system_user, { raw: "world is the new body of the message" })
|
|
}.not_to change(post.user.notifications, :count)
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
context 'private message' do
|
|
let(:user) { Fabricate(:user) }
|
|
let(:mention_post) { Fabricate(:post, user: user, raw: 'Hello @eviltrout')}
|
|
let(:topic) do
|
|
topic = mention_post.topic
|
|
topic.update_columns archetype: Archetype.private_message, category_id: nil
|
|
topic
|
|
end
|
|
|
|
it "won't notify someone who can't see the post" do
|
|
expect {
|
|
Guardian.any_instance.expects(:can_see?).with(instance_of(Post)).returns(false)
|
|
mention_post
|
|
PostAlerter.post_created(mention_post)
|
|
}.not_to change(evil_trout.notifications, :count)
|
|
end
|
|
|
|
it 'creates like notifications' do
|
|
other_user = Fabricate(:user)
|
|
topic.allowed_users << user << other_user
|
|
expect {
|
|
PostAction.act(other_user, mention_post, PostActionType.types[:like])
|
|
}.to change(user.notifications, :count)
|
|
end
|
|
end
|
|
|
|
context 'moderator action post' do
|
|
let(:user) { Fabricate(:user) }
|
|
let(:first_post) { Fabricate(:post, user: user, raw: 'A useless post for you.')}
|
|
let(:topic) { first_post.topic }
|
|
|
|
it 'should not notify anyone' do
|
|
expect {
|
|
Fabricate(:post, topic: topic, raw: 'This topic is CLOSED', post_type: Post.types[:moderator_action])
|
|
}.to_not change { Notification.count }
|
|
end
|
|
end
|
|
|
|
end
|