diff options
author | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2016-11-14 20:42:22 -0200 |
---|---|---|
committer | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2016-11-17 15:10:13 -0200 |
commit | 0aac2e0706cd767993148826d723aa3641cbb2a4 (patch) | |
tree | d3f1708529146be7d3f27fd2227c96068062f37a /spec/models/concerns | |
parent | 346f58249242c0ccf278175c78fc000976912771 (diff) | |
download | gitlab-ce-0aac2e0706cd767993148826d723aa3641cbb2a4.tar.gz |
Allow subscriptions to be created without a project
Diffstat (limited to 'spec/models/concerns')
-rw-r--r-- | spec/models/concerns/subscribable_spec.rb | 109 |
1 files changed, 84 insertions, 25 deletions
diff --git a/spec/models/concerns/subscribable_spec.rb b/spec/models/concerns/subscribable_spec.rb index 0a96cbbe166..58f5c164116 100644 --- a/spec/models/concerns/subscribable_spec.rb +++ b/spec/models/concerns/subscribable_spec.rb @@ -3,23 +3,43 @@ require 'spec_helper' describe Subscribable, 'Subscribable' do let(:project) { create(:empty_project) } let(:resource) { create(:issue, project: project) } - let(:user) { create(:user) } + let(:user_1) { create(:user) } describe '#subscribed?' do - it 'returns false when no subcription exists' do - expect(resource.subscribed?(user, project)).to be_falsey - end + context 'without project' do + it 'returns false when no subscription exists' do + expect(resource.subscribed?(user_1)).to be_falsey + end + + it 'returns true when a subcription exists and subscribed is true' do + resource.subscriptions.create(user: user_1, subscribed: true) + + expect(resource.subscribed?(user_1)).to be_truthy + end - it 'returns true when a subcription exists and subscribed is true' do - resource.subscriptions.create(user: user, project: project, subscribed: true) + it 'returns false when a subcription exists and subscribed is false' do + resource.subscriptions.create(user: user_1, subscribed: false) - expect(resource.subscribed?(user, project)).to be_truthy + expect(resource.subscribed?(user_1)).to be_falsey + end end - it 'returns false when a subcription exists and subscribed is false' do - resource.subscriptions.create(user: user, project: project, subscribed: false) + context 'with project' do + it 'returns false when no subscription exists' do + expect(resource.subscribed?(user_1, project)).to be_falsey + end + + it 'returns true when a subcription exists and subscribed is true' do + resource.subscriptions.create(user: user_1, project: project, subscribed: true) + + expect(resource.subscribed?(user_1, project)).to be_truthy + end - expect(resource.subscribed?(user, project)).to be_falsey + it 'returns false when a subcription exists and subscribed is false' do + resource.subscriptions.create(user: user_1, project: project, subscribed: false) + + expect(resource.subscribed?(user_1, project)).to be_falsey + end end end @@ -29,41 +49,80 @@ describe Subscribable, 'Subscribable' do end it 'returns the subscribed users' do - resource.subscriptions.create(user: user, project: project, subscribed: true) + user_2 = create(:user) + resource.subscriptions.create(user: user_1, subscribed: true) + resource.subscriptions.create(user: user_2, project: project, subscribed: true) resource.subscriptions.create(user: create(:user), project: project, subscribed: false) - expect(resource.subscribers(project)).to eq [user] + expect(resource.subscribers(project)).to contain_exactly(user_1, user_2) end end describe '#toggle_subscription' do - it 'toggles the current subscription state for the given user' do - expect(resource.subscribed?(user, project)).to be_falsey + context 'without project' do + it 'toggles the current subscription state for the given user' do + expect(resource.subscribed?(user_1)).to be_falsey + + resource.toggle_subscription(user_1) + + expect(resource.subscribed?(user_1)).to be_truthy + end + end - resource.toggle_subscription(user, project) + context 'with project' do + it 'toggles the current subscription state for the given user' do + expect(resource.subscribed?(user_1, project)).to be_falsey - expect(resource.subscribed?(user, project)).to be_truthy + resource.toggle_subscription(user_1, project) + + expect(resource.subscribed?(user_1, project)).to be_truthy + end end end describe '#subscribe' do - it 'subscribes the given user' do - expect(resource.subscribed?(user, project)).to be_falsey + context 'without project' do + it 'subscribes the given user' do + expect(resource.subscribed?(user_1)).to be_falsey + + resource.subscribe(user_1) + + expect(resource.subscribed?(user_1)).to be_truthy + end + end + + context 'with project' do + it 'subscribes the given user' do + expect(resource.subscribed?(user_1, project)).to be_falsey - resource.subscribe(user, project) + resource.subscribe(user_1, project) - expect(resource.subscribed?(user, project)).to be_truthy + expect(resource.subscribed?(user_1, project)).to be_truthy + end end end describe '#unsubscribe' do - it 'unsubscribes the given current user' do - resource.subscriptions.create(user: user, project: project, subscribed: true) - expect(resource.subscribed?(user, project)).to be_truthy + context 'without project' do + it 'unsubscribes the given current user' do + resource.subscriptions.create(user: user_1, subscribed: true) + expect(resource.subscribed?(user_1)).to be_truthy + + resource.unsubscribe(user_1) + + expect(resource.subscribed?(user_1)).to be_falsey + end + end + + context 'with project' do + it 'unsubscribes the given current user' do + resource.subscriptions.create(user: user_1, project: project, subscribed: true) + expect(resource.subscribed?(user_1, project)).to be_truthy - resource.unsubscribe(user, project) + resource.unsubscribe(user_1, project) - expect(resource.subscribed?(user, project)).to be_falsey + expect(resource.subscribed?(user_1, project)).to be_falsey + end end end end |