Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2018-08-01 18:21:24 +0300
committerRémy Coutable <remy@rymai.me>2018-08-01 18:21:24 +0300
commit83a0db0c551236518bdec1a7ae3a1ed1d05f5aaa (patch)
treee13ad022ea223e7bde5202a31ee81169225fec99 /spec/services
parentea6fc714bb0306ac8ca56b5dafe4b6777aafe5fc (diff)
parent12095251c3777c5231cab97854d5dca69d31cc5d (diff)
Merge branch 'bvl-user-status-message-35463' into 'master'
Allow users to set a status Closes #35463 See merge request gitlab-org/gitlab-ce!20614
Diffstat (limited to 'spec/services')
-rw-r--r--spec/services/users/set_status_service_spec.rb58
-rw-r--r--spec/services/users/update_service_spec.rb21
2 files changed, 79 insertions, 0 deletions
diff --git a/spec/services/users/set_status_service_spec.rb b/spec/services/users/set_status_service_spec.rb
new file mode 100644
index 00000000000..8a8458ab9de
--- /dev/null
+++ b/spec/services/users/set_status_service_spec.rb
@@ -0,0 +1,58 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Users::SetStatusService do
+ let(:current_user) { create(:user) }
+ subject(:service) { described_class.new(current_user, params) }
+
+ describe '#execute' do
+ context 'when when params are set' do
+ let(:params) { { emoji: 'taurus', message: 'a random status' } }
+
+ it 'creates a status' do
+ service.execute
+
+ expect(current_user.status.emoji).to eq('taurus')
+ expect(current_user.status.message).to eq('a random status')
+ end
+
+ it 'updates a status if it already existed' do
+ create(:user_status, user: current_user)
+
+ expect { service.execute }.not_to change { UserStatus.count }
+ expect(current_user.status.message).to eq('a random status')
+ end
+
+ context 'for another user' do
+ let(:target_user) { create(:user) }
+ let(:params) do
+ { emoji: 'taurus', message: 'a random status', user: target_user }
+ end
+
+ context 'the current user is admin' do
+ let(:current_user) { create(:admin) }
+
+ it 'changes the status when the current user is allowed to do that' do
+ expect { service.execute }.to change { target_user.status }
+ end
+ end
+
+ it 'does not update the status if the current user is not allowed' do
+ expect { service.execute }.not_to change { target_user.status }
+ end
+ end
+ end
+
+ context 'without params' do
+ let(:params) { {} }
+
+ it 'deletes the status' do
+ status = create(:user_status, user: current_user)
+
+ expect { service.execute }
+ .to change { current_user.reload.status }.from(status).to(nil)
+ end
+ end
+ end
+end
diff --git a/spec/services/users/update_service_spec.rb b/spec/services/users/update_service_spec.rb
index a4b7fe4674f..529c8485202 100644
--- a/spec/services/users/update_service_spec.rb
+++ b/spec/services/users/update_service_spec.rb
@@ -30,6 +30,27 @@ describe Users::UpdateService do
expect(result[:message]).to eq('Username has already been taken')
end
+ it 'updates the status if status params were given' do
+ update_user(user, status: { message: "On a call" })
+
+ expect(user.status.message).to eq("On a call")
+ end
+
+ it 'does not delete the status if no status param was passed' do
+ create(:user_status, user: user, message: 'Busy!')
+
+ update_user(user, name: 'New name')
+
+ expect(user.status.message).to eq('Busy!')
+ end
+
+ it 'includes status error messages' do
+ result = update_user(user, status: { emoji: "Moo!" })
+
+ expect(result[:status]).to eq(:error)
+ expect(result[:message]).to eq("Emoji is not included in the list")
+ end
+
def update_user(user, opts)
described_class.new(user, opts.merge(user: user)).execute
end