diff options
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/environment_spec.rb | 5 | ||||
-rw-r--r-- | spec/models/issue_spec.rb | 65 | ||||
-rw-r--r-- | spec/models/project_services/mattermost_slash_commands_service_spec.rb | 5 | ||||
-rw-r--r-- | spec/models/project_spec.rb | 46 | ||||
-rw-r--r-- | spec/models/todo_spec.rb | 8 |
5 files changed, 112 insertions, 17 deletions
diff --git a/spec/models/environment_spec.rb b/spec/models/environment_spec.rb index b2e06541e66..eba392044bf 100644 --- a/spec/models/environment_spec.rb +++ b/spec/models/environment_spec.rb @@ -288,6 +288,11 @@ describe Environment, models: true do "1-foo" => "env-1-foo" + SUFFIX, "1/foo" => "env-1-foo" + SUFFIX, "foo-" => "foo" + SUFFIX, + "foo--bar" => "foo-bar" + SUFFIX, + "foo**bar" => "foo-bar" + SUFFIX, + "*-foo" => "env-foo" + SUFFIX, + "staging-12345678-" => "staging-12345678" + SUFFIX, + "staging-12345678-01234567" => "staging-12345678" + SUFFIX, }.each do |name, matcher| it "returns a slug matching #{matcher}, given #{name}" do slug = described_class.new(name: name).generate_slug diff --git a/spec/models/issue_spec.rb b/spec/models/issue_spec.rb index 40c0a75c364..bba9058f394 100644 --- a/spec/models/issue_spec.rb +++ b/spec/models/issue_spec.rb @@ -23,21 +23,74 @@ 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 + + context 'when full is true' do + it 'returns complete path to the issue' do + expect(issue.to_reference(full: true)).to eq 'sample-namespace/sample-project#1' + expect(issue.to_reference(project, full: true)).to eq 'sample-namespace/sample-project#1' + expect(issue.to_reference(group, full: true)).to eq 'sample-namespace/sample-project#1' + end + end - it 'returns a String reference to the object' do - expect(issue.to_reference).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 another_project = build(:empty_project, name: 'another-project', namespace: project.namespace) expect(issue.to_reference(another_project)).to eq "sample-project#1" end + + 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 describe '#is_being_reassigned?' do diff --git a/spec/models/project_services/mattermost_slash_commands_service_spec.rb b/spec/models/project_services/mattermost_slash_commands_service_spec.rb index c879edddfdd..98f3d420c8a 100644 --- a/spec/models/project_services/mattermost_slash_commands_service_spec.rb +++ b/spec/models/project_services/mattermost_slash_commands_service_spec.rb @@ -113,10 +113,7 @@ describe MattermostSlashCommandsService, :models do end it 'shows error messages' do - teams, message = subject - - expect(teams).to be_empty - expect(message).to eq('Failed to get team list.') + expect(subject).to eq([[], "Failed to get team list."]) end end end diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 646a1311462..48b085781e7 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -282,9 +282,10 @@ 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 @@ -292,6 +293,14 @@ describe Project, models: true do end end + context 'when full is true' do + it 'returns complete path to the project' do + expect(project.to_reference(full: true)).to eq 'sample-namespace/sample-project' + expect(project.to_reference(project, full: true)).to eq 'sample-namespace/sample-project' + expect(project.to_reference(group, full: true)).to eq 'sample-namespace/sample-project' + end + end + context 'when same project argument' do it 'returns nil' do expect(project.to_reference(project)).to be_nil @@ -309,10 +318,33 @@ describe Project, models: true do context 'when same namespace / cross-project argument' do let(:another_project) { create(:empty_project, namespace: namespace) } - it 'returns complete path to the project' do + it 'returns path to the project' do expect(project.to_reference(another_project)).to eq 'sample-project' end end + + 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 describe '#to_human_reference' do @@ -1801,6 +1833,14 @@ describe Project, models: true do end end + describe 'inside_path' do + let!(:project1) { create(:empty_project) } + let!(:project2) { create(:empty_project) } + let!(:path) { project1.namespace.path } + + it { expect(Project.inside_path(path)).to eq([project1]) } + end + def enable_lfs allow(Gitlab.config.lfs).to receive(:enabled).and_return(true) end diff --git a/spec/models/todo_spec.rb b/spec/models/todo_spec.rb index 8017d1c3324..581305ad39f 100644 --- a/spec/models/todo_spec.rb +++ b/spec/models/todo_spec.rb @@ -109,7 +109,7 @@ describe Todo, models: true do end describe '#target_reference' do - it 'returns the short commit id for commits' do + it 'returns commit full reference with short id' do project = create(:project, :repository) commit = project.commit @@ -117,12 +117,12 @@ describe Todo, models: true do subject.target_type = 'Commit' subject.commit_id = commit.id - expect(subject.target_reference).to eq commit.short_id + expect(subject.target_reference).to eq commit.reference_link_text(full: true) end - it 'returns reference for issuables' do + it 'returns full reference for issuables' do subject.target = issue - expect(subject.target_reference).to eq issue.to_reference + expect(subject.target_reference).to eq issue.to_reference(full: true) end end end |