summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2015-05-02 23:11:21 -0400
committerRobert Speicher <rspeicher@gmail.com>2015-05-26 15:48:30 -0400
commitc0faf91ff23815404a95cf4510b43dcf5e331c4f (patch)
tree81769f125569dd6ea012920544ada1e8666ba4e5 /spec
parentb06dc74d611192744d34acda944d7ed9e554342a (diff)
downloadgitlab-ce-c0faf91ff23815404a95cf4510b43dcf5e331c4f.tar.gz
Add `to_reference` for models that support references
Now there is a single source of information for which attribute a model uses to be referenced, and its special character.
Diffstat (limited to 'spec')
-rw-r--r--spec/models/commit_range_spec.rb23
-rw-r--r--spec/models/commit_spec.rb24
-rw-r--r--spec/models/external_issue_spec.rb24
-rw-r--r--spec/models/group_spec.rb26
-rw-r--r--spec/models/issue_spec.rb21
-rw-r--r--spec/models/label_spec.rb58
-rw-r--r--spec/models/merge_request_spec.rb32
-rw-r--r--spec/models/project_spec.rb21
-rw-r--r--spec/models/snippet_spec.rb26
-rw-r--r--spec/models/user_spec.rb20
10 files changed, 239 insertions, 36 deletions
diff --git a/spec/models/commit_range_spec.rb b/spec/models/commit_range_spec.rb
index 31ee3e99cad..2d347a335a1 100644
--- a/spec/models/commit_range_spec.rb
+++ b/spec/models/commit_range_spec.rb
@@ -11,6 +11,29 @@ describe CommitRange do
expect { described_class.new("Foo") }.to raise_error
end
+ describe 'modules' do
+ subject { described_class }
+
+ it { is_expected.to include_module(Referable) }
+ end
+
+ describe '#to_reference' do
+ let(:project) { double('project', to_reference: 'namespace1/project') }
+
+ before do
+ range.project = project
+ end
+
+ it 'returns a String reference to the object' do
+ expect(range.to_reference).to eq range.to_s
+ end
+
+ it 'supports a cross-project reference' do
+ cross = double('project')
+ expect(range.to_reference(cross)).to eq "#{project.to_reference}@#{range.to_s}"
+ end
+ end
+
describe '#to_s' do
it 'is correct for three-dot syntax' do
expect(range.to_s).to eq "#{sha_from[0..7]}...#{sha_to[0..7]}"
diff --git a/spec/models/commit_spec.rb b/spec/models/commit_spec.rb
index ad2ac143d97..27eb02a870b 100644
--- a/spec/models/commit_spec.rb
+++ b/spec/models/commit_spec.rb
@@ -1,8 +1,28 @@
require 'spec_helper'
describe Commit do
- let(:project) { create :project }
- let(:commit) { project.commit }
+ let(:project) { create(:project) }
+ let(:commit) { project.commit }
+
+ describe 'modules' do
+ subject { described_class }
+
+ it { is_expected.to include_module(Mentionable) }
+ it { is_expected.to include_module(Participable) }
+ it { is_expected.to include_module(Referable) }
+ it { is_expected.to include_module(StaticModel) }
+ end
+
+ describe '#to_reference' do
+ it 'returns a String reference to the object' do
+ expect(commit.to_reference).to eq commit.id
+ end
+
+ it 'supports a cross-project reference' do
+ cross = double('project')
+ expect(commit.to_reference(cross)).to eq "#{project.to_reference}@#{commit.id}"
+ end
+ end
describe '#title' do
it "returns no_commit_message when safe_message is blank" do
diff --git a/spec/models/external_issue_spec.rb b/spec/models/external_issue_spec.rb
new file mode 100644
index 00000000000..7744610db78
--- /dev/null
+++ b/spec/models/external_issue_spec.rb
@@ -0,0 +1,24 @@
+require 'spec_helper'
+
+describe ExternalIssue do
+ let(:project) { double('project', to_reference: 'namespace1/project1') }
+ let(:issue) { described_class.new('EXT-1234', project) }
+
+ describe 'modules' do
+ subject { described_class }
+
+ it { is_expected.to include_module(Referable) }
+ end
+
+ describe '#to_reference' do
+ it 'returns a String reference to the object' do
+ expect(issue.to_reference).to eq issue.id
+ end
+ end
+
+ describe '#title' do
+ it 'returns a title' do
+ expect(issue.title).to eq "External Issue #{issue}"
+ end
+ end
+end
diff --git a/spec/models/group_spec.rb b/spec/models/group_spec.rb
index 9428224a64f..80638fc8db2 100644
--- a/spec/models/group_spec.rb
+++ b/spec/models/group_spec.rb
@@ -18,16 +18,30 @@ require 'spec_helper'
describe Group do
let!(:group) { create(:group) }
- describe "Associations" do
+ describe 'associations' do
it { is_expected.to have_many :projects }
it { is_expected.to have_many :group_members }
end
- it { is_expected.to validate_presence_of :name }
- it { is_expected.to validate_uniqueness_of(:name) }
- it { is_expected.to validate_presence_of :path }
- it { is_expected.to validate_uniqueness_of(:path) }
- it { is_expected.not_to validate_presence_of :owner }
+ describe 'modules' do
+ subject { described_class }
+
+ it { is_expected.to include_module(Referable) }
+ end
+
+ describe 'validations' do
+ it { is_expected.to validate_presence_of :name }
+ it { is_expected.to validate_uniqueness_of(:name) }
+ it { is_expected.to validate_presence_of :path }
+ it { is_expected.to validate_uniqueness_of(:path) }
+ it { is_expected.not_to validate_presence_of :owner }
+ end
+
+ describe '#to_reference' do
+ it 'returns a String reference to the object' do
+ expect(group.to_reference).to eq "@#{group.name}"
+ end
+ end
describe :users do
it { expect(group.users).to eq(group.owners) }
diff --git a/spec/models/issue_spec.rb b/spec/models/issue_spec.rb
index 20d823b40e5..4e4f816a26b 100644
--- a/spec/models/issue_spec.rb
+++ b/spec/models/issue_spec.rb
@@ -24,15 +24,30 @@ describe Issue do
it { is_expected.to belong_to(:milestone) }
end
- describe "Mass assignment" do
- end
-
describe 'modules' do
+ subject { described_class }
+
+ it { is_expected.to include_module(InternalId) }
it { is_expected.to include_module(Issuable) }
+ it { is_expected.to include_module(Referable) }
+ it { is_expected.to include_module(Sortable) }
+ it { is_expected.to include_module(Taskable) }
end
subject { create(:issue) }
+ describe '#to_reference' do
+ it 'returns a String reference to the object' do
+ expect(subject.to_reference).to eq "##{subject.iid}"
+ end
+
+ it 'supports a cross-project reference' do
+ cross = double('project')
+ expect(subject.to_reference(cross)).
+ to eq "#{subject.project.to_reference}##{subject.iid}"
+ end
+ end
+
describe '#is_being_reassigned?' do
it 'returns true if the issue assignee has changed' do
subject.assignee = create(:user)
diff --git a/spec/models/label_spec.rb b/spec/models/label_spec.rb
index 8644ac46605..a13f9ac926c 100644
--- a/spec/models/label_spec.rb
+++ b/spec/models/label_spec.rb
@@ -14,30 +14,54 @@ require 'spec_helper'
describe Label do
let(:label) { create(:label) }
- it { expect(label).to be_valid }
- it { is_expected.to belong_to(:project) }
+ describe 'associations' do
+ it { is_expected.to belong_to(:project) }
+ it { is_expected.to have_many(:label_links).dependent(:destroy) }
+ it { is_expected.to have_many(:issues).through(:label_links).source(:target) }
+ end
+
+ describe 'modules' do
+ subject { described_class }
+
+ it { is_expected.to include_module(Referable) }
+ end
+
+ describe 'validation' do
+ it { is_expected.to validate_presence_of(:project) }
- describe 'Validation' do
it 'should validate color code' do
- expect(build(:label, color: 'G-ITLAB')).not_to be_valid
- expect(build(:label, color: 'AABBCC')).not_to be_valid
- expect(build(:label, color: '#AABBCCEE')).not_to be_valid
- expect(build(:label, color: '#GGHHII')).not_to be_valid
- expect(build(:label, color: '#')).not_to be_valid
- expect(build(:label, color: '')).not_to be_valid
-
- expect(build(:label, color: '#AABBCC')).to be_valid
+ expect(label).not_to allow_value('G-ITLAB').for(:color)
+ expect(label).not_to allow_value('AABBCC').for(:color)
+ expect(label).not_to allow_value('#AABBCCEE').for(:color)
+ expect(label).not_to allow_value('GGHHII').for(:color)
+ expect(label).not_to allow_value('#').for(:color)
+ expect(label).not_to allow_value('').for(:color)
+
+ expect(label).to allow_value('#AABBCC').for(:color)
+ expect(label).to allow_value('#abcdef').for(:color)
end
it 'should validate title' do
- expect(build(:label, title: 'G,ITLAB')).not_to be_valid
- expect(build(:label, title: 'G?ITLAB')).not_to be_valid
- expect(build(:label, title: 'G&ITLAB')).not_to be_valid
- expect(build(:label, title: '')).not_to be_valid
+ expect(label).not_to allow_value('G,ITLAB').for(:title)
+ expect(label).not_to allow_value('G?ITLAB').for(:title)
+ expect(label).not_to allow_value('G&ITLAB').for(:title)
+ expect(label).not_to allow_value('').for(:title)
+
+ expect(label).to allow_value('GITLAB').for(:title)
+ expect(label).to allow_value('gitlab').for(:title)
+ expect(label).to allow_value("customer's request").for(:title)
+ end
+ end
+
+ describe '#to_reference' do
+ it 'returns a String reference to the object' do
+ expect(label.to_reference).to eq "~#{label.id}"
+ expect(label.to_reference(double)).to eq "~#{label.id}"
+ end
- expect(build(:label, title: 'GITLAB')).to be_valid
- expect(build(:label, title: 'gitlab')).to be_valid
+ it 'returns a String reference to the object using its name' do
+ expect(label.to_reference(:name)).to eq %(~"#{label.name}")
end
end
end
diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb
index 97b8abc49dd..757d8bdfae2 100644
--- a/spec/models/merge_request_spec.rb
+++ b/spec/models/merge_request_spec.rb
@@ -24,7 +24,26 @@
require 'spec_helper'
describe MergeRequest do
- describe "Validation" do
+ subject { create(:merge_request) }
+
+ describe 'modules' do
+ subject { described_class }
+
+ it { is_expected.to include_module(InternalId) }
+ it { is_expected.to include_module(Issuable) }
+ it { is_expected.to include_module(Referable) }
+ it { is_expected.to include_module(Sortable) }
+ it { is_expected.to include_module(Taskable) }
+ end
+
+ describe 'associations' do
+ it { is_expected.to belong_to(:target_project).with_foreign_key(:target_project_id).class_name('Project') }
+ it { is_expected.to belong_to(:source_project).with_foreign_key(:source_project_id).class_name('Project') }
+
+ it { is_expected.to have_one(:merge_request_diff).dependent(:destroy) }
+ end
+
+ describe 'validation' do
it { is_expected.to validate_presence_of(:target_branch) }
it { is_expected.to validate_presence_of(:source_branch) }
end
@@ -38,8 +57,15 @@ describe MergeRequest do
it { is_expected.to respond_to(:cannot_be_merged?) }
end
- describe 'modules' do
- it { is_expected.to include_module(Issuable) }
+ describe '#to_reference' do
+ it 'returns a String reference to the object' do
+ expect(subject.to_reference).to eq "!#{subject.iid}"
+ end
+
+ it 'supports a cross-project reference' do
+ cross = double('project')
+ expect(subject.to_reference(cross)).to eq "#{subject.source_project.to_reference}!#{subject.iid}"
+ end
end
describe "#mr_and_commit_notes" do
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index 37e21a90818..48568e2a3ff 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -32,7 +32,7 @@
require 'spec_helper'
describe Project do
- describe 'Associations' do
+ describe 'associations' do
it { is_expected.to belong_to(:group) }
it { is_expected.to belong_to(:namespace) }
it { is_expected.to belong_to(:creator).class_name('User') }
@@ -54,10 +54,17 @@ describe Project do
it { is_expected.to have_one(:asana_service).dependent(:destroy) }
end
- describe 'Mass assignment' do
+ describe 'modules' do
+ subject { described_class }
+
+ it { is_expected.to include_module(Gitlab::ConfigHelper) }
+ it { is_expected.to include_module(Gitlab::ShellAdapter) }
+ it { is_expected.to include_module(Gitlab::VisibilityLevel) }
+ it { is_expected.to include_module(Referable) }
+ it { is_expected.to include_module(Sortable) }
end
- describe 'Validation' do
+ describe 'validation' do
let!(:project) { create(:project) }
it { is_expected.to validate_presence_of(:name) }
@@ -91,6 +98,14 @@ describe Project do
it { is_expected.to respond_to(:path_with_namespace) }
end
+ describe '#to_reference' do
+ let(:project) { create(:empty_project) }
+
+ it 'returns a String reference to the object' do
+ expect(project.to_reference).to eq project.path_with_namespace
+ end
+ end
+
it 'should return valid url to repo' do
project = Project.new(path: 'somewhere')
expect(project.url_to_repo).to eq(Gitlab.config.gitlab_shell.ssh_path_prefix + 'somewhere.git')
diff --git a/spec/models/snippet_spec.rb b/spec/models/snippet_spec.rb
index e37dcc75230..252320b798e 100644
--- a/spec/models/snippet_spec.rb
+++ b/spec/models/snippet_spec.rb
@@ -18,7 +18,17 @@
require 'spec_helper'
describe Snippet do
- describe "Associations" do
+ describe 'modules' do
+ subject { described_class }
+
+ it { is_expected.to include_module(Gitlab::VisibilityLevel) }
+ it { is_expected.to include_module(Linguist::BlobHelper) }
+ it { is_expected.to include_module(Participable) }
+ it { is_expected.to include_module(Referable) }
+ it { is_expected.to include_module(Sortable) }
+ end
+
+ describe 'associations' do
it { is_expected.to belong_to(:author).class_name('User') }
it { is_expected.to have_many(:notes).dependent(:destroy) }
end
@@ -37,4 +47,18 @@ describe Snippet do
it { is_expected.to validate_presence_of(:content) }
end
+
+ describe '#to_reference' do
+ let(:project) { create(:empty_project) }
+ let(:snippet) { create(:snippet, project: project) }
+
+ it 'returns a String reference to the object' do
+ expect(snippet.to_reference).to eq "$#{snippet.id}"
+ end
+
+ it 'supports a cross-project reference' do
+ cross = double('project')
+ expect(snippet.to_reference(cross)).to eq "#{project.to_reference}$#{snippet.id}"
+ end
+ end
end
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index 0dddcd5bda2..87f95f9af87 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -63,7 +63,17 @@ require 'spec_helper'
describe User do
include Gitlab::CurrentSettings
- describe "Associations" do
+ describe 'modules' do
+ subject { described_class }
+
+ it { is_expected.to include_module(Gitlab::ConfigHelper) }
+ it { is_expected.to include_module(Gitlab::CurrentSettings) }
+ it { is_expected.to include_module(Referable) }
+ it { is_expected.to include_module(Sortable) }
+ it { is_expected.to include_module(TokenAuthenticatable) }
+ end
+
+ describe 'associations' do
it { is_expected.to have_one(:namespace) }
it { is_expected.to have_many(:snippets).class_name('Snippet').dependent(:destroy) }
it { is_expected.to have_many(:project_members).dependent(:destroy) }
@@ -175,6 +185,14 @@ describe User do
it { is_expected.to respond_to(:private_token) }
end
+ describe '#to_reference' do
+ let(:user) { create(:user) }
+
+ it 'returns a String reference to the object' do
+ expect(user.to_reference).to eq "@#{user.username}"
+ end
+ end
+
describe '#generate_password' do
it "should execute callback when force_random_password specified" do
user = build(:user, force_random_password: true)