2019-09-30 05:06:31 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-11-01 13:35:14 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe IssueEntity do
|
|
|
|
let(:project) { create(:project) }
|
|
|
|
let(:resource) { create(:issue, project: project) }
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
let(:request) { double('request', current_user: user) }
|
|
|
|
|
|
|
|
subject { described_class.new(resource, request: request).as_json }
|
|
|
|
|
|
|
|
it 'has Issuable attributes' do
|
|
|
|
expect(subject).to include(:id, :iid, :author_id, :description, :lock_version, :milestone_id,
|
|
|
|
:title, :updated_by_id, :created_at, :updated_at, :milestone, :labels)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has time estimation attributes' do
|
|
|
|
expect(subject).to include(:time_estimate, :total_time_spent, :human_time_estimate, :human_total_time_spent)
|
|
|
|
end
|
2019-07-10 16:04:02 -04:00
|
|
|
|
|
|
|
context 'when issue got moved' do
|
|
|
|
let(:public_project) { create(:project, :public) }
|
|
|
|
let(:member) { create(:user) }
|
|
|
|
let(:non_member) { create(:user) }
|
|
|
|
let(:issue) { create(:issue, project: public_project) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
project.add_developer(member)
|
|
|
|
public_project.add_developer(member)
|
|
|
|
Issues::MoveService.new(public_project, member).execute(issue, project)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user cannot read target project' do
|
|
|
|
it 'does not return moved_to_id' do
|
|
|
|
request = double('request', current_user: non_member)
|
|
|
|
|
|
|
|
response = described_class.new(issue, request: request).as_json
|
|
|
|
|
|
|
|
expect(response[:moved_to_id]).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user can read target project' do
|
|
|
|
it 'returns moved moved_to_id' do
|
|
|
|
request = double('request', current_user: member)
|
|
|
|
|
|
|
|
response = described_class.new(issue, request: request).as_json
|
|
|
|
|
|
|
|
expect(response[:moved_to_id]).to eq(issue.moved_to_id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-09-13 09:26:31 -04:00
|
|
|
|
|
|
|
context 'when issue got duplicated' do
|
|
|
|
let(:private_project) { create(:project, :private) }
|
|
|
|
let(:member) { create(:user) }
|
|
|
|
let(:issue) { create(:issue, project: project) }
|
|
|
|
let(:new_issue) { create(:issue, project: private_project) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
Issues::DuplicateService
|
|
|
|
.new(project, member)
|
|
|
|
.execute(issue, new_issue)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user cannot read new issue' do
|
|
|
|
let(:non_member) { create(:user) }
|
|
|
|
|
|
|
|
it 'does not return duplicated_to_id' do
|
|
|
|
request = double('request', current_user: non_member)
|
|
|
|
|
|
|
|
response = described_class.new(issue, request: request).as_json
|
|
|
|
|
|
|
|
expect(response[:duplicated_to_id]).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user can read target project' do
|
|
|
|
before do
|
|
|
|
project.add_developer(member)
|
|
|
|
private_project.add_developer(member)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns duplicated duplicated_to_id' do
|
|
|
|
request = double('request', current_user: member)
|
|
|
|
|
|
|
|
response = described_class.new(issue, request: request).as_json
|
|
|
|
|
|
|
|
expect(response[:duplicated_to_id]).to eq(issue.duplicated_to_id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-11-01 13:35:14 -04:00
|
|
|
end
|