Remove default value for `project` argument on subscribable concern

parent b3249bc2
...@@ -12,7 +12,7 @@ class SentNotificationsController < ApplicationController ...@@ -12,7 +12,7 @@ class SentNotificationsController < ApplicationController
def unsubscribe_and_redirect def unsubscribe_and_redirect
noteable = @sent_notification.noteable noteable = @sent_notification.noteable
noteable.unsubscribe(@sent_notification.recipient) noteable.unsubscribe(@sent_notification.recipient, @sent_notification.project)
flash[:notice] = "You have been unsubscribed from this thread." flash[:notice] = "You have been unsubscribed from this thread."
......
...@@ -12,45 +12,43 @@ module Subscribable ...@@ -12,45 +12,43 @@ module Subscribable
has_many :subscriptions, dependent: :destroy, as: :subscribable has_many :subscriptions, dependent: :destroy, as: :subscribable
end end
def subscribed?(user, to_project = nil) def subscribed?(user, project)
if subscription = subscriptions.find_by(user: user, project: (to_project || project)) if subscription = subscriptions.find_by(user: user, project: project)
subscription.subscribed subscription.subscribed
else else
subscribed_without_subscriptions?(user, to_project) subscribed_without_subscriptions?(user, project)
end end
end end
# Override this method to define custom logic to consider a subscribable as # Override this method to define custom logic to consider a subscribable as
# subscribed without an explicit subscription record. # subscribed without an explicit subscription record.
def subscribed_without_subscriptions?(user, to_project = nil) def subscribed_without_subscriptions?(user, project)
false false
end end
def subscribers(to_project = nil) def subscribers(project)
subscriptions.where(project: (to_project || project), subscribed: true).map(&:user) subscriptions.where(project: project, subscribed: true).map(&:user)
end end
def toggle_subscription(user, to_project = nil) def toggle_subscription(user, project)
subscribed = subscribed?(user, (to_project || project)) find_or_initialize_subscription(user, project).
update(subscribed: !subscribed?(user, project))
find_or_initialize_subscription(user, to_project).
update(subscribed: !subscribed)
end end
def subscribe(user, to_project = nil) def subscribe(user, project)
find_or_initialize_subscription(user, to_project). find_or_initialize_subscription(user, project).
update(subscribed: true) update(subscribed: true)
end end
def unsubscribe(user, to_project = nil) def unsubscribe(user, project)
find_or_initialize_subscription(user, to_project). find_or_initialize_subscription(user, project).
update(subscribed: false) update(subscribed: false)
end end
private private
def find_or_initialize_subscription(user, to_project = nil) def find_or_initialize_subscription(user, project)
subscriptions. subscriptions.
find_or_initialize_by(user_id: user.id, project_id: (to_project || project).id) find_or_initialize_by(user_id: user.id, project_id: project.id)
end end
end end
...@@ -266,7 +266,7 @@ class Issue < ActiveRecord::Base ...@@ -266,7 +266,7 @@ class Issue < ActiveRecord::Base
def as_json(options = {}) def as_json(options = {})
super(options).tap do |json| super(options).tap do |json|
json[:subscribed] = subscribed?(options[:user]) if options.has_key?(:user) && options[:user] json[:subscribed] = subscribed?(options[:user], project) if options.has_key?(:user) && options[:user]
if options.has_key?(:labels) if options.has_key?(:labels)
json[:labels] = labels.as_json( json[:labels] = labels.as_json(
......
...@@ -212,9 +212,9 @@ class IssuableBaseService < BaseService ...@@ -212,9 +212,9 @@ class IssuableBaseService < BaseService
def change_subscription(issuable) def change_subscription(issuable)
case params.delete(:subscription_event) case params.delete(:subscription_event)
when 'subscribe' when 'subscribe'
issuable.subscribe(current_user) issuable.subscribe(current_user, project)
when 'unsubscribe' when 'unsubscribe'
issuable.unsubscribe(current_user) issuable.unsubscribe(current_user, project)
end end
end end
......
...@@ -193,7 +193,7 @@ module SlashCommands ...@@ -193,7 +193,7 @@ module SlashCommands
desc 'Subscribe' desc 'Subscribe'
condition do condition do
issuable.persisted? && issuable.persisted? &&
!issuable.subscribed?(current_user) !issuable.subscribed?(current_user, project)
end end
command :subscribe do command :subscribe do
@updates[:subscription_event] = 'subscribe' @updates[:subscription_event] = 'subscribe'
...@@ -202,7 +202,7 @@ module SlashCommands ...@@ -202,7 +202,7 @@ module SlashCommands
desc 'Unsubscribe' desc 'Unsubscribe'
condition do condition do
issuable.persisted? && issuable.persisted? &&
issuable.subscribed?(current_user) issuable.subscribed?(current_user, project)
end end
command :unsubscribe do command :unsubscribe do
@updates[:subscription_event] = 'unsubscribe' @updates[:subscription_event] = 'unsubscribe'
......
...@@ -140,7 +140,7 @@ ...@@ -140,7 +140,7 @@
= render "shared/issuable/participants", participants: issuable.participants(current_user) = render "shared/issuable/participants", participants: issuable.participants(current_user)
- if current_user - if current_user
- subscribed = issuable.subscribed?(current_user) - subscribed = issuable.subscribed?(current_user, @project)
.block.light.subscription{data: {url: toggle_subscription_path(issuable)}} .block.light.subscription{data: {url: toggle_subscription_path(issuable)}}
.sidebar-collapsed-icon .sidebar-collapsed-icon
= icon('rss') = icon('rss')
......
...@@ -218,7 +218,7 @@ module API ...@@ -218,7 +218,7 @@ module API
expose :assignee, :author, using: Entities::UserBasic expose :assignee, :author, using: Entities::UserBasic
expose :subscribed do |issue, options| expose :subscribed do |issue, options|
issue.subscribed?(options[:current_user]) issue.subscribed?(options[:current_user], options[:project] || issue.project)
end end
expose :user_notes_count expose :user_notes_count
expose :upvotes, :downvotes expose :upvotes, :downvotes
...@@ -248,7 +248,7 @@ module API ...@@ -248,7 +248,7 @@ module API
expose :diff_head_sha, as: :sha expose :diff_head_sha, as: :sha
expose :merge_commit_sha expose :merge_commit_sha
expose :subscribed do |merge_request, options| expose :subscribed do |merge_request, options|
merge_request.subscribed?(options[:current_user]) merge_request.subscribed?(options[:current_user], options[:project])
end end
expose :user_notes_count expose :user_notes_count
expose :should_remove_source_branch?, as: :should_remove_source_branch expose :should_remove_source_branch?, as: :should_remove_source_branch
......
...@@ -120,7 +120,7 @@ module API ...@@ -120,7 +120,7 @@ module API
issues = issues.reorder(issuable_order_by => issuable_sort) issues = issues.reorder(issuable_order_by => issuable_sort)
present paginate(issues), with: Entities::Issue, current_user: current_user present paginate(issues), with: Entities::Issue, current_user: current_user, project: user_project
end end
# Get a single project issue # Get a single project issue
...@@ -132,7 +132,7 @@ module API ...@@ -132,7 +132,7 @@ module API
# GET /projects/:id/issues/:issue_id # GET /projects/:id/issues/:issue_id
get ":id/issues/:issue_id" do get ":id/issues/:issue_id" do
@issue = find_project_issue(params[:issue_id]) @issue = find_project_issue(params[:issue_id])
present @issue, with: Entities::Issue, current_user: current_user present @issue, with: Entities::Issue, current_user: current_user, project: user_project
end end
# Create a new project issue # Create a new project issue
...@@ -174,7 +174,7 @@ module API ...@@ -174,7 +174,7 @@ module API
end end
if issue.valid? if issue.valid?
present issue, with: Entities::Issue, current_user: current_user present issue, with: Entities::Issue, current_user: current_user, project: user_project
else else
render_validation_error!(issue) render_validation_error!(issue)
end end
...@@ -217,7 +217,7 @@ module API ...@@ -217,7 +217,7 @@ module API
issue = ::Issues::UpdateService.new(user_project, current_user, attrs).execute(issue) issue = ::Issues::UpdateService.new(user_project, current_user, attrs).execute(issue)
if issue.valid? if issue.valid?
present issue, with: Entities::Issue, current_user: current_user present issue, with: Entities::Issue, current_user: current_user, project: user_project
else else
render_validation_error!(issue) render_validation_error!(issue)
end end
...@@ -239,7 +239,7 @@ module API ...@@ -239,7 +239,7 @@ module API
begin begin
issue = ::Issues::MoveService.new(user_project, current_user).execute(issue, new_project) issue = ::Issues::MoveService.new(user_project, current_user).execute(issue, new_project)
present issue, with: Entities::Issue, current_user: current_user present issue, with: Entities::Issue, current_user: current_user, project: user_project
rescue ::Issues::MoveService::MoveError => error rescue ::Issues::MoveService::MoveError => error
render_api_error!(error.message, 400) render_api_error!(error.message, 400)
end end
......
...@@ -60,7 +60,7 @@ module API ...@@ -60,7 +60,7 @@ module API
end end
merge_requests = merge_requests.reorder(issuable_order_by => issuable_sort) merge_requests = merge_requests.reorder(issuable_order_by => issuable_sort)
present paginate(merge_requests), with: Entities::MergeRequest, current_user: current_user present paginate(merge_requests), with: Entities::MergeRequest, current_user: current_user, project: user_project
end end
desc 'Create a merge request' do desc 'Create a merge request' do
...@@ -87,7 +87,7 @@ module API ...@@ -87,7 +87,7 @@ module API
merge_request = ::MergeRequests::CreateService.new(user_project, current_user, mr_params).execute merge_request = ::MergeRequests::CreateService.new(user_project, current_user, mr_params).execute
if merge_request.valid? if merge_request.valid?
present merge_request, with: Entities::MergeRequest, current_user: current_user present merge_request, with: Entities::MergeRequest, current_user: current_user, project: user_project
else else
handle_merge_request_errors! merge_request.errors handle_merge_request_errors! merge_request.errors
end end
...@@ -120,7 +120,7 @@ module API ...@@ -120,7 +120,7 @@ module API
get path do get path do
merge_request = user_project.merge_requests.find(params[:merge_request_id]) merge_request = user_project.merge_requests.find(params[:merge_request_id])
authorize! :read_merge_request, merge_request authorize! :read_merge_request, merge_request
present merge_request, with: Entities::MergeRequest, current_user: current_user present merge_request, with: Entities::MergeRequest, current_user: current_user, project: user_project
end end
desc 'Get the commits of a merge request' do desc 'Get the commits of a merge request' do
...@@ -167,7 +167,7 @@ module API ...@@ -167,7 +167,7 @@ module API
merge_request = ::MergeRequests::UpdateService.new(user_project, current_user, mr_params).execute(merge_request) merge_request = ::MergeRequests::UpdateService.new(user_project, current_user, mr_params).execute(merge_request)
if merge_request.valid? if merge_request.valid?
present merge_request, with: Entities::MergeRequest, current_user: current_user present merge_request, with: Entities::MergeRequest, current_user: current_user, project: user_project
else else
handle_merge_request_errors! merge_request.errors handle_merge_request_errors! merge_request.errors
end end
...@@ -212,7 +212,7 @@ module API ...@@ -212,7 +212,7 @@ module API
execute(merge_request) execute(merge_request)
end end
present merge_request, with: Entities::MergeRequest, current_user: current_user present merge_request, with: Entities::MergeRequest, current_user: current_user, project: user_project
end end
desc 'Cancel merge if "Merge when build succeeds" is enabled' do desc 'Cancel merge if "Merge when build succeeds" is enabled' do
......
...@@ -114,7 +114,7 @@ module API ...@@ -114,7 +114,7 @@ module API
} }
issues = IssuesFinder.new(current_user, finder_params).execute issues = IssuesFinder.new(current_user, finder_params).execute
present paginate(issues), with: Entities::Issue, current_user: current_user present paginate(issues), with: Entities::Issue, current_user: current_user, project: user_project
end end
end end
end end
......
...@@ -25,7 +25,7 @@ describe Projects::Boards::IssuesController do ...@@ -25,7 +25,7 @@ describe Projects::Boards::IssuesController do
create(:labeled_issue, project: project, labels: [planning]) create(:labeled_issue, project: project, labels: [planning])
create(:labeled_issue, project: project, labels: [development], due_date: Date.tomorrow) create(:labeled_issue, project: project, labels: [development], due_date: Date.tomorrow)
create(:labeled_issue, project: project, labels: [development], assignee: johndoe) create(:labeled_issue, project: project, labels: [development], assignee: johndoe)
issue.subscribe(johndoe) issue.subscribe(johndoe, project)
list_issues user: user, board: board, list: list2 list_issues user: user, board: board, list: list2
......
...@@ -3,7 +3,7 @@ require 'rails_helper' ...@@ -3,7 +3,7 @@ require 'rails_helper'
describe SentNotificationsController, type: :controller do describe SentNotificationsController, type: :controller do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:project) { create(:empty_project) } let(:project) { create(:empty_project) }
let(:sent_notification) { create(:sent_notification, noteable: issue, recipient: user) } let(:sent_notification) { create(:sent_notification, project: project, noteable: issue, recipient: user) }
let(:issue) do let(:issue) do
create(:issue, project: project, author: user) do |issue| create(:issue, project: project, author: user) do |issue|
...@@ -17,7 +17,7 @@ describe SentNotificationsController, type: :controller do ...@@ -17,7 +17,7 @@ describe SentNotificationsController, type: :controller do
before { get(:unsubscribe, id: sent_notification.reply_key, force: true) } before { get(:unsubscribe, id: sent_notification.reply_key, force: true) }
it 'unsubscribes the user' do it 'unsubscribes the user' do
expect(issue.subscribed?(user)).to be_falsey expect(issue.subscribed?(user, project)).to be_falsey
end end
it 'sets the flash message' do it 'sets the flash message' do
...@@ -33,7 +33,7 @@ describe SentNotificationsController, type: :controller do ...@@ -33,7 +33,7 @@ describe SentNotificationsController, type: :controller do
before { get(:unsubscribe, id: sent_notification.reply_key) } before { get(:unsubscribe, id: sent_notification.reply_key) }
it 'does not unsubscribe the user' do it 'does not unsubscribe the user' do
expect(issue.subscribed?(user)).to be_truthy expect(issue.subscribed?(user, project)).to be_truthy
end end
it 'does not set the flash message' do it 'does not set the flash message' do
...@@ -53,7 +53,7 @@ describe SentNotificationsController, type: :controller do ...@@ -53,7 +53,7 @@ describe SentNotificationsController, type: :controller do
before { get(:unsubscribe, id: sent_notification.reply_key.reverse) } before { get(:unsubscribe, id: sent_notification.reply_key.reverse) }
it 'does not unsubscribe the user' do it 'does not unsubscribe the user' do
expect(issue.subscribed?(user)).to be_truthy expect(issue.subscribed?(user, project)).to be_truthy
end end
it 'does not set the flash message' do it 'does not set the flash message' do
...@@ -69,7 +69,7 @@ describe SentNotificationsController, type: :controller do ...@@ -69,7 +69,7 @@ describe SentNotificationsController, type: :controller do
before { get(:unsubscribe, id: sent_notification.reply_key, force: true) } before { get(:unsubscribe, id: sent_notification.reply_key, force: true) }
it 'unsubscribes the user' do it 'unsubscribes the user' do
expect(issue.subscribed?(user)).to be_falsey expect(issue.subscribed?(user, project)).to be_falsey
end end
it 'sets the flash message' do it 'sets the flash message' do
...@@ -88,11 +88,11 @@ describe SentNotificationsController, type: :controller do ...@@ -88,11 +88,11 @@ describe SentNotificationsController, type: :controller do
merge_request.subscriptions.create(user: user, project: project, subscribed: true) merge_request.subscriptions.create(user: user, project: project, subscribed: true)
end end
end end
let(:sent_notification) { create(:sent_notification, noteable: merge_request, recipient: user) } let(:sent_notification) { create(:sent_notification, project: project, noteable: merge_request, recipient: user) }
before { get(:unsubscribe, id: sent_notification.reply_key) } before { get(:unsubscribe, id: sent_notification.reply_key) }
it 'unsubscribes the user' do it 'unsubscribes the user' do
expect(merge_request.subscribed?(user)).to be_falsey expect(merge_request.subscribed?(user, project)).to be_falsey
end end
it 'sets the flash message' do it 'sets the flash message' do
......
...@@ -26,11 +26,11 @@ describe 'Unsubscribe links', feature: true do ...@@ -26,11 +26,11 @@ describe 'Unsubscribe links', feature: true do
expect(current_path).to eq unsubscribe_sent_notification_path(SentNotification.last) expect(current_path).to eq unsubscribe_sent_notification_path(SentNotification.last)
expect(page).to have_text(%(Unsubscribe from issue #{issue.title} (#{issue.to_reference}))) expect(page).to have_text(%(Unsubscribe from issue #{issue.title} (#{issue.to_reference})))
expect(page).to have_text(%(Are you sure you want to unsubscribe from issue #{issue.title} (#{issue.to_reference})?)) expect(page).to have_text(%(Are you sure you want to unsubscribe from issue #{issue.title} (#{issue.to_reference})?))
expect(issue.subscribed?(recipient)).to be_truthy expect(issue.subscribed?(recipient, project)).to be_truthy
click_link 'Unsubscribe' click_link 'Unsubscribe'
expect(issue.subscribed?(recipient)).to be_falsey expect(issue.subscribed?(recipient, project)).to be_falsey
expect(current_path).to eq new_user_session_path expect(current_path).to eq new_user_session_path
end end
...@@ -38,11 +38,11 @@ describe 'Unsubscribe links', feature: true do ...@@ -38,11 +38,11 @@ describe 'Unsubscribe links', feature: true do
visit body_link visit body_link
expect(current_path).to eq unsubscribe_sent_notification_path(SentNotification.last) expect(current_path).to eq unsubscribe_sent_notification_path(SentNotification.last)
expect(issue.subscribed?(recipient)).to be_truthy expect(issue.subscribed?(recipient, project)).to be_truthy
click_link 'Cancel' click_link 'Cancel'
expect(issue.subscribed?(recipient)).to be_truthy expect(issue.subscribed?(recipient, project)).to be_truthy
expect(current_path).to eq new_user_session_path expect(current_path).to eq new_user_session_path
end end
end end
...@@ -51,7 +51,7 @@ describe 'Unsubscribe links', feature: true do ...@@ -51,7 +51,7 @@ describe 'Unsubscribe links', feature: true do
visit header_link visit header_link
expect(page).to have_text('unsubscribed') expect(page).to have_text('unsubscribed')
expect(issue.subscribed?(recipient)).to be_falsey expect(issue.subscribed?(recipient, project)).to be_falsey
end end
end end
...@@ -62,14 +62,14 @@ describe 'Unsubscribe links', feature: true do ...@@ -62,14 +62,14 @@ describe 'Unsubscribe links', feature: true do
visit body_link visit body_link
expect(page).to have_text('unsubscribed') expect(page).to have_text('unsubscribed')
expect(issue.subscribed?(recipient)).to be_falsey expect(issue.subscribed?(recipient, project)).to be_falsey
end end
it 'unsubscribes from the issue when visiting the link from the header' do it 'unsubscribes from the issue when visiting the link from the header' do
visit header_link visit header_link
expect(page).to have_text('unsubscribed') expect(page).to have_text('unsubscribed')
expect(issue.subscribed?(recipient)).to be_falsey expect(issue.subscribed?(recipient, project)).to be_falsey
end end
end end
end end
...@@ -182,19 +182,19 @@ describe Issue, "Issuable" do ...@@ -182,19 +182,19 @@ describe Issue, "Issuable" do
before { allow(issue).to receive(:participants).with(user).and_return([]) } before { allow(issue).to receive(:participants).with(user).and_return([]) }
it 'returns false when no subcription exists' do it 'returns false when no subcription exists' do
expect(issue.subscribed?(user)).to be_falsey expect(issue.subscribed?(user, project)).to be_falsey
end end
it 'returns true when a subcription exists and subscribed is true' do it 'returns true when a subcription exists and subscribed is true' do
issue.subscriptions.create(user: user, project: project, subscribed: true) issue.subscriptions.create(user: user, project: project, subscribed: true)
expect(issue.subscribed?(user)).to be_truthy expect(issue.subscribed?(user, project)).to be_truthy
end end
it 'returns false when a subcription exists and subscribed is false' do it 'returns false when a subcription exists and subscribed is false' do
issue.subscriptions.create(user: user, project: project, subscribed: false) issue.subscriptions.create(user: user, project: project, subscribed: false)
expect(issue.subscribed?(user)).to be_falsey expect(issue.subscribed?(user, project)).to be_falsey
end end
end end
...@@ -202,19 +202,19 @@ describe Issue, "Issuable" do ...@@ -202,19 +202,19 @@ describe Issue, "Issuable" do
before { allow(issue).to receive(:participants).with(user).and_return([user]) } before { allow(issue).to receive(:participants).with(user).and_return([user]) }
it 'returns false when no subcription exists' do it 'returns false when no subcription exists' do
expect(issue.subscribed?(user)).to be_truthy expect(issue.subscribed?(user, project)).to be_truthy
end end
it 'returns true when a subcription exists and subscribed is true' do it 'returns true when a subcription exists and subscribed is true' do
issue.subscriptions.create(user: user, project: project, subscribed: true) issue.subscriptions.create(user: user, project: project, subscribed: true)
expect(issue.subscribed?(user)).to be_truthy expect(issue.subscribed?(user, project)).to be_truthy
end end
it 'returns false when a subcription exists and subscribed is false' do it 'returns false when a subcription exists and subscribed is false' do
issue.subscriptions.create(user: user, project: project, subscribed: false) issue.subscriptions.create(user: user, project: project, subscribed: false)
expect(issue.subscribed?(user)).to be_falsey expect(issue.subscribed?(user, project)).to be_falsey
end end
end end
end end
......
...@@ -637,7 +637,7 @@ describe API::API, api: true do ...@@ -637,7 +637,7 @@ describe API::API, api: true do
it "sends notifications for subscribers of newly added labels" do it "sends notifications for subscribers of newly added labels" do
label = project.labels.first label = project.labels.first
label.toggle_subscription(user2) label.toggle_subscription(user2, project)
perform_enqueued_jobs do perform_enqueued_jobs do
post api("/projects/#{project.id}/issues", user), post api("/projects/#{project.id}/issues", user),
...@@ -828,7 +828,7 @@ describe API::API, api: true do ...@@ -828,7 +828,7 @@ describe API::API, api: true do
it "sends notifications for subscribers of newly added labels when issue is updated" do it "sends notifications for subscribers of newly added labels when issue is updated" do
label = create(:label, title: 'foo', color: '#FFAABB', project: project) label = create(:label, title: 'foo', color: '#FFAABB', project: project)
label.toggle_subscription(user2) label.toggle_subscription(user2, project)
perform_enqueued_jobs do perform_enqueued_jobs do
put api("/projects/#{project.id}/issues/#{issue.id}", user), put api("/projects/#{project.id}/issues/#{issue.id}", user),
......
...@@ -339,7 +339,7 @@ describe API::API, api: true do ...@@ -339,7 +339,7 @@ describe API::API, api: true do
end end
context "when user is already subscribed to label" do context "when user is already subscribed to label" do
before { label1.subscribe(user) } before { label1.subscribe(user, project) }
it "returns 304" do it "returns 304" do
post api("/projects/#{project.id}/labels/#{label1.id}/subscription", user) post api("/projects/#{project.id}/labels/#{label1.id}/subscription", user)
...@@ -358,7 +358,7 @@ describe API::API, api: true do ...@@ -358,7 +358,7 @@ describe API::API, api: true do
end end
describe "DELETE /projects/:id/labels/:label_id/subscription" do describe "DELETE /projects/:id/labels/:label_id/subscription" do
before { label1.subscribe(user) } before { label1.subscribe(user, project) }
context "when label_id is a label title" do context "when label_id is a label title" do
it "unsubscribes from the label" do it "unsubscribes from the label" do
...@@ -381,7 +381,7 @@ describe API::API, api: true do ...@@ -381,7 +381,7 @@ describe API::API, api: true do
end end
context "when user is already unsubscribed from label" do context "when user is already unsubscribed from label" do
before { label1.unsubscribe(user) } before { label1.unsubscribe(user, project) }
it "returns 304" do it "returns 304" do
delete api("/projects/#{project.id}/labels/#{label1.id}/subscription", user) delete api("/projects/#{project.id}/labels/#{label1.id}/subscription", user)
......
...@@ -260,7 +260,7 @@ describe Issuable::BulkUpdateService, services: true do ...@@ -260,7 +260,7 @@ describe Issuable::BulkUpdateService, services: true do
it 'subscribes the given user' do it 'subscribes the given user' do
bulk_update(issues, subscription_event: 'subscribe') bulk_update(issues, subscription_event: 'subscribe')
expect(issues).to all(be_subscribed(user)) expect(issues).to all(be_subscribed(user, project))
end end
end end
...@@ -275,7 +275,7 @@ describe Issuable::BulkUpdateService, services: true do ...@@ -275,7 +275,7 @@ describe Issuable::BulkUpdateService, services: true do
bulk_update(issues, subscription_event: 'unsubscribe') bulk_update(issues, subscription_event: 'unsubscribe')
issues.each do |issue| issues.each do |issue|
expect(issue).not_to be_subscribed(user) expect(issue).not_to be_subscribed(user, project)
end end
end end
end end
......
...@@ -215,7 +215,7 @@ describe Issues::UpdateService, services: true do ...@@ -215,7 +215,7 @@ describe Issues::UpdateService, services: true do
let!(:subscriber) do let!(:subscriber) do
create(:user).tap do |u| create(:user).tap do |u|
label.toggle_subscription(u) label.toggle_subscription(u, project)
project.team << [u, :developer] project.team << [u, :developer]
end end
end end
......
...@@ -199,7 +199,7 @@ describe MergeRequests::UpdateService, services: true do ...@@ -199,7 +199,7 @@ describe MergeRequests::UpdateService, services: true do
context 'when the issue is relabeled' do context 'when the issue is relabeled' do
let!(:non_subscriber) { create(:user) } let!(:non_subscriber) { create(:user) }
let!(:subscriber) { create(:user).tap { |u| label.toggle_subscription(u) } } let!(:subscriber) { create(:user) { |u| label.toggle_subscription(u, project) } }
before do before do
project.team << [non_subscriber, :developer] project.team << [non_subscriber, :developer]
......
...@@ -385,7 +385,7 @@ describe NotificationService, services: true do ...@@ -385,7 +385,7 @@ describe NotificationService, services: true do
label = create(:label, project: project, issues: [issue]) label = create(:label, project: project, issues: [issue])
group_label = create(:group_label, group: group, issues: [issue]) group_label = create(:group_label, group: group, issues: [issue])
issue.reload issue.reload
label.toggle_subscription(user_1) label.toggle_subscription(user_1, project)
group_label.toggle_subscription(user_2, project) group_label.toggle_subscription(user_2, project)
group_label.toggle_subscription(user_3, another_project) group_label.toggle_subscription(user_3, another_project)
...@@ -411,12 +411,12 @@ describe NotificationService, services: true do ...@@ -411,12 +411,12 @@ describe NotificationService, services: true do
label = create(:label, project: project, issues: [confidential_issue]) label = create(:label, project: project, issues: [confidential_issue])
confidential_issue.reload confidential_issue.reload
label.toggle_subscription(non_member) label.toggle_subscription(non_member, project)
label.toggle_subscription(author) label.toggle_subscription(author, project)
label.toggle_subscription(assignee) label.toggle_subscription(assignee, project)
label.toggle_subscription(member) label.toggle_subscription(member, project)
label.toggle_subscription(guest) label.toggle_subscription(guest, project)
label.toggle_subscription(admin) label.toggle_subscription(admin, project)
reset_delivered_emails! reset_delivered_emails!
...@@ -568,11 +568,11 @@ describe NotificationService, services: true do ...@@ -568,11 +568,11 @@ describe NotificationService, services: true do
let(:group_label_2) { create(:group_label, group: group, title: 'Group Label 2') } let(:group_label_2) { create(:group_label, group: group, title: 'Group Label 2') }
let(:label_1) { create(:label, project: project, title: 'Label 1', issues: [issue]) } let(:label_1) { create(:label, project: project, title: 'Label 1', issues: [issue]) }
let(:label_2) { create(:label, project: project, title: 'Label 2') } let(:label_2) { create(:label, project: project, title: 'Label 2') }
let!(:subscriber_to_group_label_1) { create(:user).tap { |u| group_label_1.toggle_subscription(u, project) } } let!(:subscriber_to_group_label_1) { create(:user) { |u| group_label_1.toggle_subscription(u, project) } }
let!(:subscriber_to_group_label_2) { create(:user).tap { |u| group_label_2.toggle_subscription(u, project) } } let!(:subscriber_to_group_label_2) { create(:user) { |u| group_label_2.toggle_subscription(u, project) } }
let!(:subscriber_to_group_label_2_on_another_project) { create(:user).tap { |u| group_label_2.toggle_subscription(u, another_project) } } let!(:subscriber_to_group_label_2_on_another_project) { create(:user) { |u| group_label_2.toggle_subscription(u, another_project) } }
let!(:subscriber_to_label_1) { create(:user).tap { |u| label_1.toggle_subscription(u) } } let!(:subscriber_to_label_1) { create(:user) { |u| label_1.toggle_subscription(u, project) } }
let!(:subscriber_to_label_2) { create(:user).tap { |u| label_2.toggle_subscription(u) } } let!(:subscriber_to_label_2) { create(:user) { |u| label_2.toggle_subscription(u, project) } }
it "emails subscribers of the issue's added labels only" do it "emails subscribers of the issue's added labels only" do
notification.relabeled_issue(issue, [group_label_2, label_2], @u_disabled) notification.relabeled_issue(issue, [group_label_2, label_2], @u_disabled)
...@@ -618,12 +618,12 @@ describe NotificationService, services: true do ...@@ -618,12 +618,12 @@ describe NotificationService, services: true do
project.team << [member, :developer] project.team << [member, :developer]
project.team << [guest, :guest] project.team << [guest, :guest]
label_2.toggle_subscription(non_member) label_2.toggle_subscription(non_member, project)
label_2.toggle_subscription(author) label_2.toggle_subscription(author, project)
label_2.toggle_subscription(assignee) label_2.toggle_subscription(assignee, project)
label_2.toggle_subscription(member) label_2.toggle_subscription(member, project)
label_2.toggle_subscription(guest) label_2.toggle_subscription(guest, project)
label_2.toggle_subscription(admin) label_2.toggle_subscription(admin, project)
reset_delivered_emails! reset_delivered_emails!
...@@ -786,7 +786,7 @@ describe NotificationService, services: true do ...@@ -786,7 +786,7 @@ describe NotificationService, services: true do
user_3 = create(:user) user_3 = create(:user)
label = create(:label, project: project, merge_requests: [merge_request]) label = create(:label, project: project, merge_requests: [merge_request])
group_label = create(:group_label, group: group, merge_requests: [merge_request]) group_label = create(:group_label, group: group, merge_requests: [merge_request])
label.toggle_subscription(user_1) label.toggle_subscription(user_1, project)
group_label.toggle_subscription(user_2, project) group_label.toggle_subscription(user_2, project)
group_label.toggle_subscription(user_3, another_project) group_label.toggle_subscription(user_3, another_project)
...@@ -892,11 +892,11 @@ describe NotificationService, services: true do ...@@ -892,11 +892,11 @@ describe NotificationService, services: true do
let(:group_label_2) { create(:group_label, group: group, title: 'Group Label 2') } let(:group_label_2) { create(:group_label, group: group, title: 'Group Label 2') }
let(:label_1) { create(:label, project: project, title: 'Label 1', merge_requests: [merge_request]) } let(:label_1) { create(:label, project: project, title: 'Label 1', merge_requests: [merge_request]) }
let(:label_2) { create(:label, project: project, title: 'Label 2') } let(:label_2) { create(:label, project: project, title: 'Label 2') }
let!(:subscriber_to_group_label_1) { create(:user).tap { |u| group_label_1.toggle_subscription(u, project) } } let!(:subscriber_to_group_label_1) { create(:user) { |u| group_label_1.toggle_subscription(u, project) } }
let!(:subscriber_to_group_label_2) { create(:user).tap { |u| group_label_2.toggle_subscription(u, project) } } let!(:subscriber_to_group_label_2) { create(:user) { |u| group_label_2.toggle_subscription(u, project) } }
let!(:subscriber_to_group_label_2_on_another_project) { create(:user).tap { |u| group_label_2.toggle_subscription(u, another_project) } } let!(:subscriber_to_group_label_2_on_another_project) { create(:user) { |u| group_label_2.toggle_subscription(u, another_project) } }
let!(:subscriber_to_label_1) { create(:user).tap { |u| label_1.toggle_subscription(u) } } let!(:subscriber_to_label_1) { create(:user) { |u| label_1.toggle_subscription(u, project) } }
let!(:subscriber_to_label_2) { create(:user).tap { |u| label_2.toggle_subscription(u) } } let!(:subscriber_to_label_2) { create(:user) { |u| label_2.toggle_subscription(u, project) } }
it "emails subscribers of the merge request's added labels only" do it "emails subscribers of the merge request's added labels only" do
notification.relabeled_merge_request(merge_request, [group_label_2, label_2], @u_disabled) notification.relabeled_merge_request(merge_request, [group_label_2, label_2], @u_disabled)
......
...@@ -169,7 +169,7 @@ describe SlashCommands::InterpretService, services: true do ...@@ -169,7 +169,7 @@ describe SlashCommands::InterpretService, services: true do
shared_examples 'unsubscribe command' do shared_examples 'unsubscribe command' do
it 'populates subscription_event: "unsubscribe" if content contains /unsubscribe' do it 'populates subscription_event: "unsubscribe" if content contains /unsubscribe' do
issuable.subscribe(developer) issuable.subscribe(developer, project)
_, updates = service.execute(content, issuable) _, updates = service.execute(content, issuable)
expect(updates).to eq(subscription_event: 'unsubscribe') expect(updates).to eq(subscription_event: 'unsubscribe')
......
...@@ -230,31 +230,31 @@ shared_examples 'issuable record that supports slash commands in its description ...@@ -230,31 +230,31 @@ shared_examples 'issuable record that supports slash commands in its description
context "with a note subscribing to the #{issuable_type}" do context "with a note subscribing to the #{issuable_type}" do
it "creates a new todo for the #{issuable_type}" do it "creates a new todo for the #{issuable_type}" do
expect(issuable.subscribed?(master)).to be_falsy expect(issuable.subscribed?(master, project)).to be_falsy
write_note("/subscribe") write_note("/subscribe")
expect(page).not_to have_content '/subscribe' expect(page).not_to have_content '/subscribe'
expect(page).to have_content 'Your commands have been executed!' expect(page).to have_content 'Your commands have been executed!'
expect(issuable.subscribed?(master)).to be_truthy expect(issuable.subscribed?(master, project)).to be_truthy
end end
end end
context "with a note unsubscribing to the #{issuable_type} as done" do context "with a note unsubscribing to the #{issuable_type} as done" do
before do before do
issuable.subscribe(master) issuable.subscribe(master, project)
end end
it "creates a new todo for the #{issuable_type}" do it "creates a new todo for the #{issuable_type}" do
expect(issuable.subscribed?(master)).to be_truthy expect(issuable.subscribed?(master, project)).to be_truthy
write_note("/unsubscribe") write_note("/unsubscribe")
expect(page).not_to have_content '/unsubscribe' expect(page).not_to have_content '/unsubscribe'
expect(page).to have_content 'Your commands have been executed!' expect(page).to have_content 'Your commands have been executed!'
expect(issuable.subscribed?(master)).to be_falsy expect(issuable.subscribed?(master, project)).to be_falsy
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment