debian-mirror-gitlab/spec/models/concerns/subscribable_spec.rb

129 lines
3.9 KiB
Ruby
Raw Normal View History

2016-06-02 11:05:42 +05:30
require 'spec_helper'
describe Subscribable, 'Subscribable' do
2017-08-17 22:00:37 +05:30
let(:project) { create(:empty_project) }
let(:resource) { create(:issue, project: project) }
let(:user_1) { create(:user) }
2016-06-02 11:05:42 +05:30
describe '#subscribed?' do
2017-08-17 22:00:37 +05:30
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
2016-06-02 11:05:42 +05:30
2017-08-17 22:00:37 +05:30
it 'returns false when a subcription exists and subscribed is false' do
resource.subscriptions.create(user: user_1, subscribed: false)
2016-06-02 11:05:42 +05:30
2017-08-17 22:00:37 +05:30
expect(resource.subscribed?(user_1)).to be_falsey
end
2016-06-02 11:05:42 +05:30
end
2017-08-17 22:00:37 +05:30
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
2016-06-02 11:05:42 +05:30
2017-08-17 22:00:37 +05:30
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
2016-06-02 11:05:42 +05:30
end
end
2017-08-17 22:00:37 +05:30
2016-06-02 11:05:42 +05:30
describe '#subscribers' do
it 'returns [] when no subcribers exists' do
2017-08-17 22:00:37 +05:30
expect(resource.subscribers(project)).to be_empty
2016-06-02 11:05:42 +05:30
end
it 'returns the subscribed users' do
2017-08-17 22:00:37 +05:30
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)
2016-06-02 11:05:42 +05:30
2017-08-17 22:00:37 +05:30
expect(resource.subscribers(project)).to contain_exactly(user_1, user_2)
2016-06-02 11:05:42 +05:30
end
end
describe '#toggle_subscription' do
2017-08-17 22:00:37 +05:30
context 'without project' do
it 'toggles the current subscription state for the given user' do
expect(resource.subscribed?(user_1)).to be_falsey
2016-06-02 11:05:42 +05:30
2017-08-17 22:00:37 +05:30
resource.toggle_subscription(user_1)
2016-06-02 11:05:42 +05:30
2017-08-17 22:00:37 +05:30
expect(resource.subscribed?(user_1)).to be_truthy
end
end
context 'with project' do
it 'toggles the current subscription state for the given user' do
expect(resource.subscribed?(user_1, project)).to be_falsey
resource.toggle_subscription(user_1, project)
expect(resource.subscribed?(user_1, project)).to be_truthy
end
2016-06-02 11:05:42 +05:30
end
end
describe '#subscribe' do
2017-08-17 22:00:37 +05:30
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
2016-06-02 11:05:42 +05:30
2017-08-17 22:00:37 +05:30
resource.subscribe(user_1, project)
2016-06-02 11:05:42 +05:30
2017-08-17 22:00:37 +05:30
expect(resource.subscribed?(user_1, project)).to be_truthy
end
2016-06-02 11:05:42 +05:30
end
end
describe '#unsubscribe' do
2017-08-17 22:00:37 +05:30
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
2016-06-02 11:05:42 +05:30
2017-08-17 22:00:37 +05:30
resource.unsubscribe(user_1, project)
2016-06-02 11:05:42 +05:30
2017-08-17 22:00:37 +05:30
expect(resource.subscribed?(user_1, project)).to be_falsey
end
2016-06-02 11:05:42 +05:30
end
end
end