blob: 95a077d610031a6cdffd59458198f638f7342c71 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Users::UnblockService, feature_category: :user_management do
let_it_be(:current_user) { create(:admin) }
subject(:service) { described_class.new(current_user) }
describe '#execute' do
subject(:operation) { service.execute(user) }
context 'when successful' do
let(:user) { create(:user, :blocked) }
it { expect(operation.success?).to eq(true) }
it "change the user's state" do
expect { operation }.to change { user.active? }.to(true)
end
it 'saves a custom attribute', :aggregate_failures, :freeze_time, feature_category: :insider_threat do
operation
custom_attribute = user.custom_attributes.last
expect(custom_attribute.key).to eq(UserCustomAttribute::UNBLOCKED_BY)
expect(custom_attribute.value).to eq("#{current_user.username}/#{current_user.id}+#{Time.current}")
end
end
context 'when failed' do
let(:user) { create(:user) }
it 'returns error result', :aggregate_failures do
expect(operation.error?).to eq(true)
expect(operation[:message]).to include(/State cannot transition/)
end
it "does not change the user's state" do
expect { operation }.not_to change { user.state }
end
end
end
end
|