summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-01-26 19:20:01 -0200
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-02-02 11:25:44 -0200
commit718b1dddfe8d7422e8de8b2fbbd8357fc1c3b5e4 (patch)
tree13950c0ea38a77ff198e038ce32a093801f99a06 /spec
parenta2bbf004779db402e67a918db893c166502f5050 (diff)
downloadgitlab-ce-718b1dddfe8d7422e8de8b2fbbd8357fc1c3b5e4.tar.gz
Refactor Admin::SpamLogsController to block user before destroying
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/admin/spam_logs_controller_spec.rb35
-rw-r--r--spec/models/spam_log_spec.rb14
2 files changed, 28 insertions, 21 deletions
diff --git a/spec/controllers/admin/spam_logs_controller_spec.rb b/spec/controllers/admin/spam_logs_controller_spec.rb
index 2486298fc78..6beebc362e9 100644
--- a/spec/controllers/admin/spam_logs_controller_spec.rb
+++ b/spec/controllers/admin/spam_logs_controller_spec.rb
@@ -1,8 +1,10 @@
require 'spec_helper'
describe Admin::SpamLogsController do
- let(:admin) { create(:admin) }
- let(:spam_log) { create(:spam_log, user: admin) }
+ let(:admin) { create(:admin) }
+ let(:user) { create(:user) }
+ let!(:first_spam) { create(:spam_log, user: user) }
+ let!(:second_spam) { create(:spam_log, user: user) }
before do
sign_in(admin)
@@ -11,37 +13,28 @@ describe Admin::SpamLogsController do
describe '#index' do
it 'lists all spam logs' do
get :index
+
expect(response.status).to eq(200)
end
end
describe '#destroy' do
- it 'destroys just spam log' do
- user = spam_log.user
- delete :destroy, id: spam_log.id
+ it 'removes only the spam log when removing log' do
+ expect {
+ delete :destroy, id: first_spam.id
+ }.to change { SpamLog.count }.by(-1)
- expect(SpamLog.all.count).to eq(0)
expect(User.find(user.id)).to be_truthy
- expect(response.status).to eq(302)
+ expect(response.status).to eq(200)
end
- it 'destroys user and his spam logs' do
- user = spam_log.user
- delete :destroy, id: spam_log.id, remove_user: true
+ it 'removes user and his spam logs when removing the user' do
+ delete :destroy, id: first_spam.id, remove_user: true
- expect(SpamLog.all.count).to eq(0)
- expect { User.find(user.id) }.to raise_error(ActiveRecord::RecordNotFound)
+ expect(flash[:notice]).to eq "User #{user.username} was successfully removed."
expect(response.status).to eq(302)
- end
-
- it 'destroys user and his spam logs with JSON format' do
- user = spam_log.user
- delete :destroy, id: spam_log.id, remove_user: true, format: :json
-
- expect(SpamLog.all.count).to eq(0)
+ expect(SpamLog.count).to eq(0)
expect { User.find(user.id) }.to raise_error(ActiveRecord::RecordNotFound)
- expect(JSON.parse(response.body)).to eq({})
- expect(response.status).to eq(200)
end
end
end
diff --git a/spec/models/spam_log_spec.rb b/spec/models/spam_log_spec.rb
index 076f3e44c70..c4ec7625cb0 100644
--- a/spec/models/spam_log_spec.rb
+++ b/spec/models/spam_log_spec.rb
@@ -8,4 +8,18 @@ describe SpamLog, models: true do
describe 'validations' do
it { is_expected.to validate_presence_of(:user) }
end
+
+ describe '#remove_user' do
+ it 'blocks the user' do
+ spam_log = build(:spam_log)
+
+ expect { spam_log.remove_user }.to change { spam_log.user.blocked? }.to(true)
+ end
+
+ it 'removes the user' do
+ spam_log = build(:spam_log)
+
+ expect { spam_log.remove_user }.to change { User.count }.by(-1)
+ end
+ end
end