mirror of
https://github.com/discourse/discourse.git
synced 2024-11-28 05:53:44 +08:00
b8cbe51026
This conversion is done by Transpec 3.1.0 with the following command: transpec * 424 conversions from: obj.should to: expect(obj).to * 325 conversions from: == expected to: eq(expected) * 38 conversions from: obj.should_not to: expect(obj).not_to * 15 conversions from: =~ /pattern/ to: match(/pattern/) * 9 conversions from: it { should ... } to: it { is_expected.to ... } * 5 conversions from: lambda { }.should_not to: expect { }.not_to * 4 conversions from: lambda { }.should to: expect { }.to * 2 conversions from: -> { }.should to: expect { }.to * 2 conversions from: -> { }.should_not to: expect { }.not_to * 1 conversion from: === expected to: be === expected * 1 conversion from: =~ [1, 2] to: match_array([1, 2]) For more details: https://github.com/yujinakayama/transpec#supported-conversions
107 lines
2.9 KiB
Ruby
107 lines
2.9 KiB
Ruby
require 'spec_helper'
|
|
|
|
describe UserBlocker do
|
|
|
|
before do
|
|
SystemMessage.stubs(:create)
|
|
end
|
|
|
|
describe 'block' do
|
|
let(:user) { stub_everything(save: true) }
|
|
let(:blocker) { UserBlocker.new(user) }
|
|
subject(:block_user) { blocker.block }
|
|
|
|
it 'blocks the user' do
|
|
u = Fabricate(:user)
|
|
expect { UserBlocker.block(u) }.to change { u.reload.blocked? }
|
|
end
|
|
|
|
it 'hides posts' do
|
|
blocker.expects(:hide_posts)
|
|
block_user
|
|
end
|
|
|
|
context 'given a staff user argument' do
|
|
it 'sends the correct message to the blocked user' do
|
|
SystemMessage.unstub(:create)
|
|
SystemMessage.expects(:create).with(user, :blocked_by_staff).returns(true)
|
|
UserBlocker.block(user, Fabricate.build(:admin))
|
|
end
|
|
|
|
# TODO: it 'logs the action'
|
|
end
|
|
|
|
context 'not given a staff user argument' do
|
|
it 'sends a default message to the user' do
|
|
SystemMessage.unstub(:create)
|
|
SystemMessage.expects(:create).with(user, :blocked_by_staff).returns(true)
|
|
UserBlocker.block(user, Fabricate.build(:admin))
|
|
end
|
|
end
|
|
|
|
context 'given a message option' do
|
|
it 'sends that message to the user' do
|
|
SystemMessage.unstub(:create)
|
|
SystemMessage.expects(:create).with(user, :the_custom_message).returns(true)
|
|
UserBlocker.block(user, Fabricate.build(:admin), {message: :the_custom_message})
|
|
end
|
|
end
|
|
|
|
it "doesn't send a pm if save fails" do
|
|
user.stubs(:save).returns(false)
|
|
SystemMessage.unstub(:create)
|
|
SystemMessage.expects(:create).never
|
|
block_user
|
|
end
|
|
|
|
it "doesn't send a pm if the user is already blocked" do
|
|
user.stubs(:blocked?).returns(true)
|
|
SystemMessage.unstub(:create)
|
|
SystemMessage.expects(:create).never
|
|
expect(block_user).to eq(false)
|
|
end
|
|
end
|
|
|
|
describe 'unblock' do
|
|
let(:user) { stub_everything(save: true) }
|
|
subject(:unblock_user) { UserBlocker.unblock(user, Fabricate.build(:admin)) }
|
|
|
|
it 'unblocks the user' do
|
|
u = Fabricate(:user, blocked: true)
|
|
expect { UserBlocker.unblock(u) }.to change { u.reload.blocked? }
|
|
end
|
|
|
|
it 'sends a message to the user' do
|
|
SystemMessage.unstub(:create)
|
|
SystemMessage.expects(:create).with(user, :unblocked).returns(true)
|
|
unblock_user
|
|
end
|
|
|
|
it "doesn't send a pm if save fails" do
|
|
user.stubs(:save).returns(false)
|
|
SystemMessage.unstub(:create)
|
|
SystemMessage.expects(:create).never
|
|
unblock_user
|
|
end
|
|
|
|
# TODO: it 'logs the action'
|
|
end
|
|
|
|
describe 'hide_posts' do
|
|
let(:user) { Fabricate(:user) }
|
|
let!(:post) { Fabricate(:post, user: user) }
|
|
subject { UserBlocker.new(user) }
|
|
|
|
it "hides all the user's posts" do
|
|
subject.block
|
|
expect(post.reload).to be_hidden
|
|
end
|
|
|
|
it "hides the topic if the post was the first post" do
|
|
subject.block
|
|
expect(post.topic.reload).to_not be_visible
|
|
end
|
|
end
|
|
|
|
end
|