2011-12-19 15:30:14 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2012-12-17 10:39:53 +00:00
|
|
|
def set_data
|
|
|
|
@user = FactoryGirl.create(:user)
|
|
|
|
@stranger = FactoryGirl.create(:user)
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_issue issue_owner
|
|
|
|
ActionMailer::Base.deliveries = []
|
2014-01-21 04:51:49 +00:00
|
|
|
@issue = FactoryGirl.create(:issue, project_id: @project.id,
|
|
|
|
user: issue_owner, assignee: nil)
|
2012-12-17 10:39:53 +00:00
|
|
|
end
|
|
|
|
|
2011-12-19 15:30:14 +00:00
|
|
|
describe Issue do
|
2012-12-17 10:39:53 +00:00
|
|
|
before do
|
|
|
|
stub_symlink_methods
|
2015-02-19 01:28:02 +00:00
|
|
|
allow_any_instance_of(Project).to receive(:versions).and_return(%w(v1.0 v2.0))
|
2012-12-17 10:39:53 +00:00
|
|
|
end
|
2014-10-20 20:18:34 +01:00
|
|
|
|
|
|
|
|
|
|
|
context '#update_statistic' do
|
|
|
|
it 'updates styatistics' do
|
2015-05-11 09:07:10 +01:00
|
|
|
expect { FactoryGirl.create(:issue) }.to change(Statistic, :count).by(1)
|
2014-10-20 20:18:34 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-12-17 10:39:53 +00:00
|
|
|
context 'for project admin user' do
|
|
|
|
before(:each) do
|
|
|
|
set_data
|
2014-01-21 04:51:49 +00:00
|
|
|
@project = FactoryGirl.create(:project, owner: @user)
|
2012-12-17 10:39:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should send an e-mail' do
|
2013-01-11 14:01:10 +00:00
|
|
|
create_issue(@stranger)
|
2015-05-11 09:07:10 +01:00
|
|
|
expect(ActionMailer::Base.deliveries.count).to eq(1)
|
|
|
|
expect(ActionMailer::Base.deliveries.last.to).to include(@user.email)
|
2012-12-17 10:39:53 +00:00
|
|
|
end
|
2013-01-11 14:01:10 +00:00
|
|
|
|
|
|
|
it 'should not send an e-mail to creator' do
|
|
|
|
create_issue(@user)
|
2015-05-11 09:07:10 +01:00
|
|
|
expect(ActionMailer::Base.deliveries.count).to eq(0)
|
2013-01-11 14:01:10 +00:00
|
|
|
end
|
2013-07-10 18:44:18 +01:00
|
|
|
|
|
|
|
it 'should create automatic comment from another issue' do
|
|
|
|
create_issue(@user)
|
2014-01-21 04:51:49 +00:00
|
|
|
another_issue = FactoryGirl.create(:issue, project: @project, title: "[##{@issue.serial_id}]")
|
2015-05-11 09:07:10 +01:00
|
|
|
expect(Comment.where(automatic: true, commentable_type: 'Issue',
|
|
|
|
created_from_issue_id: another_issue.id).count).to eq(1)
|
2013-07-10 18:44:18 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should create automatic comment after updating another issue body' do
|
|
|
|
create_issue(@user)
|
2014-01-21 04:51:49 +00:00
|
|
|
another_issue = FactoryGirl.create(:issue, project: @project)
|
2015-04-07 21:44:39 +01:00
|
|
|
another_issue = Issue.find another_issue.id
|
2013-07-10 18:44:18 +01:00
|
|
|
another_issue.update_attribute(:title, "[##{@issue.serial_id}]")
|
|
|
|
|
2015-05-11 09:07:10 +01:00
|
|
|
expect(Comment.where(automatic: true, commentable_type: 'Issue',
|
|
|
|
created_from_issue_id: another_issue.id).count).to eq(1)
|
2013-07-10 18:44:18 +01:00
|
|
|
end
|
2013-07-11 12:19:18 +01:00
|
|
|
|
|
|
|
it 'should send email message to new assignee' do
|
|
|
|
create_issue(@user)
|
|
|
|
ActionMailer::Base.deliveries = []
|
2015-04-07 21:44:39 +01:00
|
|
|
@issue = Issue.find @issue.id
|
2013-07-11 12:19:18 +01:00
|
|
|
@issue.update_attribute :assignee_id, @user.id
|
2015-04-07 21:44:39 +01:00
|
|
|
|
2015-05-11 09:07:10 +01:00
|
|
|
expect(ActionMailer::Base.deliveries.count).to eq(1)
|
2013-07-11 12:19:18 +01:00
|
|
|
end
|
2012-12-17 10:39:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'for member-group' do
|
|
|
|
before(:each) do
|
|
|
|
set_data
|
2014-01-21 04:51:49 +00:00
|
|
|
@project = FactoryGirl.create(:project, owner: @user)
|
2012-12-17 10:39:53 +00:00
|
|
|
|
|
|
|
@group = FactoryGirl.create(:group)
|
2013-04-17 21:53:17 +01:00
|
|
|
@reader = FactoryGirl.create :user
|
2014-03-18 09:31:01 +00:00
|
|
|
create_actor_relation(@group, @reader, 'reader')
|
2012-12-17 10:39:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should send an e-mail to all members of the admin group' do
|
2014-03-18 09:31:01 +00:00
|
|
|
create_relation(@project, @group, 'admin')
|
2012-12-17 10:39:53 +00:00
|
|
|
|
|
|
|
create_issue(@stranger)
|
2015-05-11 09:07:10 +01:00
|
|
|
expect(ActionMailer::Base.deliveries.count).to eq(3) # 1 owner + 2 group member. enough?
|
2012-12-17 10:39:53 +00:00
|
|
|
end
|
|
|
|
|
2013-01-11 14:01:10 +00:00
|
|
|
it 'should send an e-mail to all members of the admin group except creator' do
|
2014-03-18 09:31:01 +00:00
|
|
|
create_relation(@project, @group, 'admin')
|
2013-01-11 14:01:10 +00:00
|
|
|
|
|
|
|
create_issue(@group.owner)
|
2015-05-11 09:07:10 +01:00
|
|
|
expect(ActionMailer::Base.deliveries.count).to eq(2) # 1 owner + 1 group member. enough?
|
2013-01-11 14:01:10 +00:00
|
|
|
end
|
|
|
|
|
2015-05-11 09:07:10 +01:00
|
|
|
it 'should send emails to members of the reader group' do
|
2014-03-18 09:31:01 +00:00
|
|
|
create_relation(@project, @group, 'reader')
|
2012-12-17 10:39:53 +00:00
|
|
|
create_issue(@stranger)
|
2015-05-11 09:07:10 +01:00
|
|
|
expect(ActionMailer::Base.deliveries.count).to eq(3) # project owner + group owner + group member
|
2012-12-17 10:39:53 +00:00
|
|
|
end
|
2013-04-17 21:53:17 +01:00
|
|
|
|
|
|
|
it 'should reset issue assignee after remove him from group' do
|
2014-03-18 09:31:01 +00:00
|
|
|
create_relation(@project, @group, 'reader')
|
2013-04-17 21:53:17 +01:00
|
|
|
create_issue(@group.owner)
|
|
|
|
@issue.update_column :assignee_id, @reader.id
|
|
|
|
@group.remove_member @reader
|
2015-05-11 09:07:10 +01:00
|
|
|
expect(@issue.reload.assignee_id).to be_nil
|
2013-04-17 21:53:17 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not reset issue assignee' do
|
2014-03-18 09:31:01 +00:00
|
|
|
create_relation(@project, @group, 'reader')
|
|
|
|
create_relation(@project, @reader, 'reader')
|
2013-04-17 21:53:17 +01:00
|
|
|
create_issue(@group.owner)
|
|
|
|
@issue.update_column :assignee_id, @reader.id
|
|
|
|
@group.remove_member @reader
|
2015-05-11 09:07:10 +01:00
|
|
|
expect(@issue.reload.assignee_id).to eq(@reader.id)
|
2013-04-17 21:53:17 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should reset issue assignee after remove him from project' do
|
2014-03-18 09:31:01 +00:00
|
|
|
create_relation(@project, @reader, 'reader')
|
2013-04-17 21:53:17 +01:00
|
|
|
create_issue(@reader)
|
|
|
|
@issue.update_column :assignee_id, @reader.id
|
2013-04-18 12:19:48 +01:00
|
|
|
@project.remove_member @reader # via api
|
2015-05-11 09:07:10 +01:00
|
|
|
expect(@issue.reload.assignee_id).to be_nil
|
2013-04-17 21:53:17 +01:00
|
|
|
end
|
|
|
|
|
2012-12-17 10:39:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'Group project' do
|
|
|
|
before(:each) do
|
|
|
|
set_data
|
2014-01-21 04:51:49 +00:00
|
|
|
@group = FactoryGirl.create(:group, owner: @user)
|
|
|
|
@project = FactoryGirl.create(:project, owner: @group)
|
2012-12-17 10:39:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'for admin of the group' do
|
|
|
|
it 'should send an e-mail' do
|
|
|
|
create_issue(@stranger)
|
2015-05-11 09:07:10 +01:00
|
|
|
expect(ActionMailer::Base.deliveries.count).to eq(1)
|
|
|
|
expect(ActionMailer::Base.deliveries.last.to).to include(@user.email)
|
2012-12-17 10:39:53 +00:00
|
|
|
end
|
2013-01-11 14:01:10 +00:00
|
|
|
|
|
|
|
it 'should not send an e-mail to creator' do
|
|
|
|
create_issue(@user)
|
2015-05-11 09:07:10 +01:00
|
|
|
expect(ActionMailer::Base.deliveries.count).to eq(0)
|
2013-01-11 14:01:10 +00:00
|
|
|
end
|
2012-12-17 10:39:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'for reader of the group' do
|
2015-05-11 09:07:10 +01:00
|
|
|
it 'should send an email' do
|
2012-12-17 10:39:53 +00:00
|
|
|
reader = FactoryGirl.create :user
|
2014-03-18 09:31:01 +00:00
|
|
|
create_actor_relation(@group, reader, 'reader')
|
2012-12-17 10:39:53 +00:00
|
|
|
create_issue(@stranger)
|
2015-05-11 09:07:10 +01:00
|
|
|
expect(ActionMailer::Base.deliveries.count).to eq(2) # group owner + group reader
|
2012-12-17 10:39:53 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2011-12-19 15:30:14 +00:00
|
|
|
end
|