diff options
author | Berna Castro <bernacas@gmail.com> | 2016-12-15 17:51:50 +0300 |
---|---|---|
committer | Oswaldo Ferreira <oswaldo@gitlab.com> | 2017-01-28 01:20:17 +0300 |
commit | ac66268443b05029cbc45cc358f62b764f1ff165 (patch) | |
tree | 1c662775a6c480449ba2a074ec0bb4397dc38700 /spec/models | |
parent | 08481a710319073065776fb6297b337dc1dc7ae8 (diff) |
Refactor Project#to_reference and make full_path a keyword argument
Refactor overall code and fix failing specs
Fix Project#to_reference
Fix wrong spaces and update changelog
Refactor #to_reference for Project & Issue
Fix and improves Project#to_reference
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/issue_spec.rb | 66 | ||||
-rw-r--r-- | spec/models/project_spec.rb | 38 |
2 files changed, 87 insertions, 17 deletions
diff --git a/spec/models/issue_spec.rb b/spec/models/issue_spec.rb index 5c37141e3ad..623238e9d86 100644 --- a/spec/models/issue_spec.rb +++ b/spec/models/issue_spec.rb @@ -23,19 +23,37 @@ describe Issue, models: true do end describe '#to_reference' do - let(:project) { build(:empty_project, name: 'sample-project') } - let(:issue) { build(:issue, iid: 1, project: project) } + let(:namespace) { build(:namespace, path: 'sample-namespace') } + let(:project) { build(:empty_project, name: 'sample-project', namespace: namespace) } + let(:issue) { build(:issue, iid: 1, project: project) } + let(:group) { create(:group, name: 'Group', path: 'sample-group') } + + context 'when nil argument' do + it 'returns issue id' do + expect(issue.to_reference).to eq "#1" + end + end - it 'returns a String reference to the object' do - expect(issue.to_reference).to eq "#{project.namespace.name}/sample-project#1" + context 'when full_path is true' do + it 'returns complete path to the issue' do + expect(issue.to_reference(full_path: true)).to eq 'sample-namespace/sample-project#1' + expect(issue.to_reference(project, full_path: true)).to eq 'sample-namespace/sample-project#1' + expect(issue.to_reference(group, full_path: true)).to eq 'sample-namespace/sample-project#1' + end end - it 'supports a project reference' do - expect(issue.to_reference(project)).to eq "#1" + context 'when same project argument' do + it 'returns issue id' do + expect(issue.to_reference(project)).to eq("#1") + end end - it 'returns a String reference with the full path' do - expect(issue.to_reference(full: true)).to eq(project.path_with_namespace + '#1') + context 'when cross namespace project argument' do + let(:another_namespace_project) { create(:empty_project, name: 'another-project') } + + it 'returns complete path to the issue' do + expect(issue.to_reference(another_namespace_project)).to eq 'sample-namespace/sample-project#1' + end end it 'supports a cross-project reference' do @@ -43,9 +61,35 @@ describe Issue, models: true do expect(issue.to_reference(another_project)).to eq "sample-project#1" end - it 'supports a group reference' do - group = build(:group, name: 'sample-group') - expect(issue.to_reference(nil, group)).to eq("sample-project#1") + context 'when same namespace / cross-project argument' do + let(:another_project) { create(:empty_project, namespace: namespace) } + + it 'returns path to the issue with the project name' do + expect(issue.to_reference(another_project)).to eq 'sample-project#1' + end + end + + context 'when different namespace / cross-project argument' do + let(:another_namespace) { create(:namespace, path: 'another-namespace') } + let(:another_project) { create(:empty_project, path: 'another-project', namespace: another_namespace) } + + it 'returns full path to the issue' do + expect(issue.to_reference(another_project)).to eq 'sample-namespace/sample-project#1' + end + end + + context 'when argument is a namespace' do + context 'with same project path' do + it 'returns path to the issue with the project name' do + expect(issue.to_reference(namespace)).to eq 'sample-project#1' + end + end + + context 'with different project path' do + it 'returns full path to the issue' do + expect(issue.to_reference(group)).to eq 'sample-namespace/sample-project#1' + end + end end end diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index d99c18ebe1e..7d61c26a6e9 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -282,13 +282,22 @@ describe Project, models: true do end describe '#to_reference' do - let(:owner) { create(:user, name: 'Gitlab') } + let(:owner) { create(:user, name: 'Gitlab') } let(:namespace) { create(:namespace, path: 'sample-namespace', owner: owner) } - let(:project) { create(:empty_project, path: 'sample-project', namespace: namespace) } + let(:project) { create(:empty_project, path: 'sample-project', namespace: namespace) } + let(:group) { create(:group, name: 'Group', path: 'sample-group', owner: owner) } context 'when nil argument' do + it 'returns nil' do + expect(project.to_reference).to be_nil + end + end + + context 'when full_path is true' do it 'returns complete path to the project' do - expect(project.to_reference).to eq 'sample-namespace/sample-project' + expect(project.to_reference(full_path: true)).to eq 'sample-namespace/sample-project' + expect(project.to_reference(project, full_path: true)).to eq 'sample-namespace/sample-project' + expect(project.to_reference(group, full_path: true)).to eq 'sample-namespace/sample-project' end end @@ -314,9 +323,26 @@ describe Project, models: true do end end - context 'when group argument' do - it 'returns path to the project' do - expect(project.to_reference(nil, namespace)).to eq 'sample-project' + context 'when different namespace / cross-project argument' do + let(:another_namespace) { create(:namespace, path: 'another-namespace', owner: owner) } + let(:another_project) { create(:empty_project, path: 'another-project', namespace: another_namespace) } + + it 'returns full path to the project' do + expect(project.to_reference(another_project)).to eq 'sample-namespace/sample-project' + end + end + + context 'when argument is a namespace' do + context 'with same project path' do + it 'returns path to the project' do + expect(project.to_reference(namespace)).to eq 'sample-project' + end + end + + context 'with different project path' do + it 'returns full path to the project' do + expect(project.to_reference(group)).to eq 'sample-namespace/sample-project' + end end end end |