diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-31 18:06:53 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-31 18:06:53 +0000 |
commit | 996f700997805b3590da8d8afdd19d193989078a (patch) | |
tree | fb555d6012ea1a6f018694b62bba5c68c8c623e1 /spec/models/concerns | |
parent | 083d64c6468a070ae7b0b406ead8d87da27d1d22 (diff) | |
download | gitlab-ce-996f700997805b3590da8d8afdd19d193989078a.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models/concerns')
-rw-r--r-- | spec/models/concerns/subscribable_spec.rb | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/spec/models/concerns/subscribable_spec.rb b/spec/models/concerns/subscribable_spec.rb index 2f88adf08dd..f189cd7633c 100644 --- a/spec/models/concerns/subscribable_spec.rb +++ b/spec/models/concerns/subscribable_spec.rb @@ -133,4 +133,60 @@ describe Subscribable, 'Subscribable' do end end end + + describe '#set_subscription' do + shared_examples 'setting subscriptions' do + context 'when desired_state is set to true' do + context 'when a user is subscribed to the resource' do + it 'keeps the user subscribed' do + resource.subscriptions.create(user: user_1, subscribed: true, project: resource_project) + + resource.set_subscription(user_1, true, resource_project) + + expect(resource.subscribed?(user_1, resource_project)).to be_truthy + end + end + + context 'when a user is not subscribed to the resource' do + it 'subscribes the user to the resource' do + expect { resource.set_subscription(user_1, true, resource_project) } + .to change { resource.subscribed?(user_1, resource_project) } + .from(false).to(true) + end + end + end + + context 'when desired_state is set to false' do + context 'when a user is subscribed to the resource' do + it 'unsubscribes the user from the resource' do + resource.subscriptions.create(user: user_1, subscribed: true, project: resource_project) + + expect { resource.set_subscription(user_1, false, resource_project) } + .to change { resource.subscribed?(user_1, resource_project) } + .from(true).to(false) + end + end + + context 'when a user is not subscribed to the resource' do + it 'keeps the user unsubscribed' do + resource.set_subscription(user_1, false, resource_project) + + expect(resource.subscribed?(user_1, resource_project)).to be_falsey + end + end + end + end + + context 'without project' do + let(:resource_project) { nil } + + it_behaves_like 'setting subscriptions' + end + + context 'with project' do + let(:resource_project) { project } + + it_behaves_like 'setting subscriptions' + end + end end |