summaryrefslogtreecommitdiff
path: root/spec/lib
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-02-27 13:01:57 -0800
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-02-27 13:01:57 -0800
commit0d22b75b03496ced3d783f8fee9584098602ea1c (patch)
treec7ddec6072c716fd63a8703f2dfeb0e4234a633f /spec/lib
parent5f682094d9b7c985ad62ebe29664bb6fe87b54be (diff)
parentd4aab6528cb80b0f41bdac2240dd9cc32543481d (diff)
downloadgitlab-ce-0d22b75b03496ced3d783f8fee9584098602ea1c.tar.gz
Merge branch 'master' into mmonaco/gitlab-ce-api-user-noconfirm
Conflicts: lib/api/users.rb
Diffstat (limited to 'spec/lib')
-rw-r--r--spec/lib/disable_email_interceptor_spec.rb2
-rw-r--r--spec/lib/extracts_path_spec.rb20
-rw-r--r--spec/lib/git_ref_validator_spec.rb32
-rw-r--r--spec/lib/gitlab/auth_spec.rb10
-rw-r--r--spec/lib/gitlab/backend/shell_spec.rb12
-rw-r--r--spec/lib/gitlab/bitbucket_import/project_creator_spec.rb22
-rw-r--r--spec/lib/gitlab/closing_issue_extractor_spec.rb174
-rw-r--r--spec/lib/gitlab/diff/file_spec.rb6
-rw-r--r--spec/lib/gitlab/diff/parser_spec.rb34
-rw-r--r--spec/lib/gitlab/git_access_spec.rb136
-rw-r--r--spec/lib/gitlab/git_access_wiki_spec.rb4
-rw-r--r--spec/lib/gitlab/github_import/project_creator_spec.rb24
-rw-r--r--spec/lib/gitlab/gitlab_import/project_creator_spec.rb24
-rw-r--r--spec/lib/gitlab/gitlab_markdown_helper_spec.rb8
-rw-r--r--spec/lib/gitlab/gitorious_import/project_creator.rb23
-rw-r--r--spec/lib/gitlab/ldap/access_spec.rb10
-rw-r--r--spec/lib/gitlab/ldap/adapter_spec.rb6
-rw-r--r--spec/lib/gitlab/ldap/authentication_spec.rb14
-rw-r--r--spec/lib/gitlab/ldap/config_spec.rb2
-rw-r--r--spec/lib/gitlab/ldap/user_spec.rb25
-rw-r--r--spec/lib/gitlab/oauth/user_spec.rb29
-rw-r--r--spec/lib/gitlab/popen_spec.rb12
-rw-r--r--spec/lib/gitlab/push_data_builder_spec.rb39
-rw-r--r--spec/lib/gitlab/reference_extractor_spec.rb35
-rw-r--r--spec/lib/gitlab/regex_spec.rb24
-rw-r--r--spec/lib/gitlab/satellite/action_spec.rb44
-rw-r--r--spec/lib/gitlab/satellite/merge_action_spec.rb32
-rw-r--r--spec/lib/gitlab/upgrader_spec.rb6
-rw-r--r--spec/lib/gitlab/url_builder_spec.rb2
-rw-r--r--spec/lib/gitlab/version_info_spec.rb52
-rw-r--r--spec/lib/repository_cache_spec.rb34
-rw-r--r--spec/lib/votes_spec.rb153
32 files changed, 786 insertions, 264 deletions
diff --git a/spec/lib/disable_email_interceptor_spec.rb b/spec/lib/disable_email_interceptor_spec.rb
index 8bf6ee2ed50..06d5450688b 100644
--- a/spec/lib/disable_email_interceptor_spec.rb
+++ b/spec/lib/disable_email_interceptor_spec.rb
@@ -6,7 +6,7 @@ describe DisableEmailInterceptor do
end
it 'should not send emails' do
- Gitlab.config.gitlab.stub(:email_enabled).and_return(false)
+ allow(Gitlab.config.gitlab).to receive(:email_enabled).and_return(false)
expect {
deliver_mail
}.not_to change(ActionMailer::Base.deliveries, :count)
diff --git a/spec/lib/extracts_path_spec.rb b/spec/lib/extracts_path_spec.rb
index 7b3818ea5c8..ac602eac154 100644
--- a/spec/lib/extracts_path_spec.rb
+++ b/spec/lib/extracts_path_spec.rb
@@ -14,44 +14,46 @@ describe ExtractsPath do
describe '#extract_ref' do
it "returns an empty pair when no @project is set" do
@project = nil
- extract_ref('master/CHANGELOG').should == ['', '']
+ expect(extract_ref('master/CHANGELOG')).to eq(['', ''])
end
context "without a path" do
it "extracts a valid branch" do
- extract_ref('master').should == ['master', '']
+ expect(extract_ref('master')).to eq(['master', ''])
end
it "extracts a valid tag" do
- extract_ref('v2.0.0').should == ['v2.0.0', '']
+ expect(extract_ref('v2.0.0')).to eq(['v2.0.0', ''])
end
it "extracts a valid commit ref without a path" do
- extract_ref('f4b14494ef6abf3d144c28e4af0c20143383e062').should ==
+ expect(extract_ref('f4b14494ef6abf3d144c28e4af0c20143383e062')).to eq(
['f4b14494ef6abf3d144c28e4af0c20143383e062', '']
+ )
end
it "falls back to a primitive split for an invalid ref" do
- extract_ref('stable').should == ['stable', '']
+ expect(extract_ref('stable')).to eq(['stable', ''])
end
end
context "with a path" do
it "extracts a valid branch" do
- extract_ref('foo/bar/baz/CHANGELOG').should == ['foo/bar/baz', 'CHANGELOG']
+ expect(extract_ref('foo/bar/baz/CHANGELOG')).to eq(['foo/bar/baz', 'CHANGELOG'])
end
it "extracts a valid tag" do
- extract_ref('v2.0.0/CHANGELOG').should == ['v2.0.0', 'CHANGELOG']
+ expect(extract_ref('v2.0.0/CHANGELOG')).to eq(['v2.0.0', 'CHANGELOG'])
end
it "extracts a valid commit SHA" do
- extract_ref('f4b14494ef6abf3d144c28e4af0c20143383e062/CHANGELOG').should ==
+ expect(extract_ref('f4b14494ef6abf3d144c28e4af0c20143383e062/CHANGELOG')).to eq(
['f4b14494ef6abf3d144c28e4af0c20143383e062', 'CHANGELOG']
+ )
end
it "falls back to a primitive split for an invalid ref" do
- extract_ref('stable/CHANGELOG').should == ['stable', 'CHANGELOG']
+ expect(extract_ref('stable/CHANGELOG')).to eq(['stable', 'CHANGELOG'])
end
end
end
diff --git a/spec/lib/git_ref_validator_spec.rb b/spec/lib/git_ref_validator_spec.rb
index b2469c18395..4633b6f3934 100644
--- a/spec/lib/git_ref_validator_spec.rb
+++ b/spec/lib/git_ref_validator_spec.rb
@@ -1,20 +1,20 @@
require 'spec_helper'
describe Gitlab::GitRefValidator do
- it { Gitlab::GitRefValidator.validate('feature/new').should be_true }
- it { Gitlab::GitRefValidator.validate('implement_@all').should be_true }
- it { Gitlab::GitRefValidator.validate('my_new_feature').should be_true }
- it { Gitlab::GitRefValidator.validate('#1').should be_true }
- it { Gitlab::GitRefValidator.validate('feature/~new/').should be_false }
- it { Gitlab::GitRefValidator.validate('feature/^new/').should be_false }
- it { Gitlab::GitRefValidator.validate('feature/:new/').should be_false }
- it { Gitlab::GitRefValidator.validate('feature/?new/').should be_false }
- it { Gitlab::GitRefValidator.validate('feature/*new/').should be_false }
- it { Gitlab::GitRefValidator.validate('feature/[new/').should be_false }
- it { Gitlab::GitRefValidator.validate('feature/new/').should be_false }
- it { Gitlab::GitRefValidator.validate('feature/new.').should be_false }
- it { Gitlab::GitRefValidator.validate('feature\@{').should be_false }
- it { Gitlab::GitRefValidator.validate('feature\new').should be_false }
- it { Gitlab::GitRefValidator.validate('feature//new').should be_false }
- it { Gitlab::GitRefValidator.validate('feature new').should be_false }
+ it { expect(Gitlab::GitRefValidator.validate('feature/new')).to be_truthy }
+ it { expect(Gitlab::GitRefValidator.validate('implement_@all')).to be_truthy }
+ it { expect(Gitlab::GitRefValidator.validate('my_new_feature')).to be_truthy }
+ it { expect(Gitlab::GitRefValidator.validate('#1')).to be_truthy }
+ it { expect(Gitlab::GitRefValidator.validate('feature/~new/')).to be_falsey }
+ it { expect(Gitlab::GitRefValidator.validate('feature/^new/')).to be_falsey }
+ it { expect(Gitlab::GitRefValidator.validate('feature/:new/')).to be_falsey }
+ it { expect(Gitlab::GitRefValidator.validate('feature/?new/')).to be_falsey }
+ it { expect(Gitlab::GitRefValidator.validate('feature/*new/')).to be_falsey }
+ it { expect(Gitlab::GitRefValidator.validate('feature/[new/')).to be_falsey }
+ it { expect(Gitlab::GitRefValidator.validate('feature/new/')).to be_falsey }
+ it { expect(Gitlab::GitRefValidator.validate('feature/new.')).to be_falsey }
+ it { expect(Gitlab::GitRefValidator.validate('feature\@{')).to be_falsey }
+ it { expect(Gitlab::GitRefValidator.validate('feature\new')).to be_falsey }
+ it { expect(Gitlab::GitRefValidator.validate('feature//new')).to be_falsey }
+ it { expect(Gitlab::GitRefValidator.validate('feature new')).to be_falsey }
end
diff --git a/spec/lib/gitlab/auth_spec.rb b/spec/lib/gitlab/auth_spec.rb
index 1f3e1a4a3c1..95fc7e16a11 100644
--- a/spec/lib/gitlab/auth_spec.rb
+++ b/spec/lib/gitlab/auth_spec.rb
@@ -10,13 +10,21 @@ describe Gitlab::Auth do
password: password,
password_confirmation: password)
end
- let(:username) { 'john' }
+ let(:username) { 'John' } # username isn't lowercase, test this
let(:password) { 'my-secret' }
it "should find user by valid login/password" do
expect( gl_auth.find(username, password) ).to eql user
end
+ it 'should find user by valid email/password with case-insensitive email' do
+ expect(gl_auth.find(user.email.upcase, password)).to eql user
+ end
+
+ it 'should find user by valid username/password with case-insensitive username' do
+ expect(gl_auth.find(username.upcase, password)).to eql user
+ end
+
it "should not find user with invalid password" do
password = 'wrong'
expect( gl_auth.find(username, password) ).to_not eql user
diff --git a/spec/lib/gitlab/backend/shell_spec.rb b/spec/lib/gitlab/backend/shell_spec.rb
index f00ec0fa401..27279465c1a 100644
--- a/spec/lib/gitlab/backend/shell_spec.rb
+++ b/spec/lib/gitlab/backend/shell_spec.rb
@@ -8,11 +8,11 @@ describe Gitlab::Shell do
Project.stub(find: project)
end
- it { should respond_to :add_key }
- it { should respond_to :remove_key }
- it { should respond_to :add_repository }
- it { should respond_to :remove_repository }
- it { should respond_to :fork_repository }
+ it { is_expected.to respond_to :add_key }
+ it { is_expected.to respond_to :remove_key }
+ it { is_expected.to respond_to :add_repository }
+ it { is_expected.to respond_to :remove_repository }
+ it { is_expected.to respond_to :fork_repository }
- it { gitlab_shell.url_to_repo('diaspora').should == Gitlab.config.gitlab_shell.ssh_path_prefix + "diaspora.git" }
+ it { expect(gitlab_shell.url_to_repo('diaspora')).to eq(Gitlab.config.gitlab_shell.ssh_path_prefix + "diaspora.git") }
end
diff --git a/spec/lib/gitlab/bitbucket_import/project_creator_spec.rb b/spec/lib/gitlab/bitbucket_import/project_creator_spec.rb
new file mode 100644
index 00000000000..f5523105848
--- /dev/null
+++ b/spec/lib/gitlab/bitbucket_import/project_creator_spec.rb
@@ -0,0 +1,22 @@
+require 'spec_helper'
+
+describe Gitlab::BitbucketImport::ProjectCreator do
+ let(:user) { create(:user, bitbucket_access_token: "asdffg", bitbucket_access_token_secret: "sekret") }
+ let(:repo) { {
+ name: 'Vim',
+ slug: 'vim',
+ is_private: true,
+ owner: "asd"}.with_indifferent_access
+ }
+ let(:namespace){ create(:namespace) }
+
+ it 'creates project' do
+ allow_any_instance_of(Project).to receive(:add_import_job)
+
+ project_creator = Gitlab::BitbucketImport::ProjectCreator.new(repo, namespace, user)
+ project = project_creator.execute
+
+ expect(project.import_url).to eq("ssh://git@bitbucket.org/asd/vim.git")
+ expect(project.visibility_level).to eq(Gitlab::VisibilityLevel::PRIVATE)
+ end
+end
diff --git a/spec/lib/gitlab/closing_issue_extractor_spec.rb b/spec/lib/gitlab/closing_issue_extractor_spec.rb
new file mode 100644
index 00000000000..c96ee78e5fd
--- /dev/null
+++ b/spec/lib/gitlab/closing_issue_extractor_spec.rb
@@ -0,0 +1,174 @@
+require 'spec_helper'
+
+describe Gitlab::ClosingIssueExtractor do
+ let(:project) { create(:project) }
+ let(:issue) { create(:issue, project: project) }
+ let(:iid1) { issue.iid }
+
+ describe :closed_by_message_in_project do
+ context 'with a single reference' do
+ it do
+ message = "Awesome commit (Closes ##{iid1})"
+ expect(subject.closed_by_message_in_project(message, project)).to eq([issue])
+ end
+
+ it do
+ message = "Awesome commit (closes ##{iid1})"
+ expect(subject.closed_by_message_in_project(message, project)).to eq([issue])
+ end
+
+ it do
+ message = "Closed ##{iid1}"
+ expect(subject.closed_by_message_in_project(message, project)).to eq([issue])
+ end
+
+ it do
+ message = "closed ##{iid1}"
+ expect(subject.closed_by_message_in_project(message, project)).to eq([issue])
+ end
+
+ it do
+ message = "Closing ##{iid1}"
+ expect(subject.closed_by_message_in_project(message, project)).to eq([issue])
+ end
+
+ it do
+ message = "closing ##{iid1}"
+ expect(subject.closed_by_message_in_project(message, project)).to eq([issue])
+ end
+
+ it do
+ message = "Close ##{iid1}"
+ expect(subject.closed_by_message_in_project(message, project)).to eq([issue])
+ end
+
+ it do
+ message = "close ##{iid1}"
+ expect(subject.closed_by_message_in_project(message, project)).to eq([issue])
+ end
+
+ it do
+ message = "Awesome commit (Fixes ##{iid1})"
+ expect(subject.closed_by_message_in_project(message, project)).to eq([issue])
+ end
+
+ it do
+ message = "Awesome commit (fixes ##{iid1})"
+ expect(subject.closed_by_message_in_project(message, project)).to eq([issue])
+ end
+
+ it do
+ message = "Fixed ##{iid1}"
+ expect(subject.closed_by_message_in_project(message, project)).to eq([issue])
+ end
+
+ it do
+ message = "fixed ##{iid1}"
+ expect(subject.closed_by_message_in_project(message, project)).to eq([issue])
+ end
+
+ it do
+ message = "Fixing ##{iid1}"
+ expect(subject.closed_by_message_in_project(message, project)).to eq([issue])
+ end
+
+ it do
+ message = "fixing ##{iid1}"
+ expect(subject.closed_by_message_in_project(message, project)).to eq([issue])
+ end
+
+ it do
+ message = "Fix ##{iid1}"
+ expect(subject.closed_by_message_in_project(message, project)).to eq([issue])
+ end
+
+ it do
+ message = "fix ##{iid1}"
+ expect(subject.closed_by_message_in_project(message, project)).to eq([issue])
+ end
+
+ it do
+ message = "Awesome commit (Resolves ##{iid1})"
+ expect(subject.closed_by_message_in_project(message, project)).to eq([issue])
+ end
+
+ it do
+ message = "Awesome commit (resolves ##{iid1})"
+ expect(subject.closed_by_message_in_project(message, project)).to eq([issue])
+ end
+
+ it do
+ message = "Resolved ##{iid1}"
+ expect(subject.closed_by_message_in_project(message, project)).to eq([issue])
+ end
+
+ it do
+ message = "resolved ##{iid1}"
+ expect(subject.closed_by_message_in_project(message, project)).to eq([issue])
+ end
+
+ it do
+ message = "Resolving ##{iid1}"
+ expect(subject.closed_by_message_in_project(message, project)).to eq([issue])
+ end
+
+ it do
+ message = "resolving ##{iid1}"
+ expect(subject.closed_by_message_in_project(message, project)).to eq([issue])
+ end
+
+ it do
+ message = "Resolve ##{iid1}"
+ expect(subject.closed_by_message_in_project(message, project)).to eq([issue])
+ end
+
+ it do
+ message = "resolve ##{iid1}"
+ expect(subject.closed_by_message_in_project(message, project)).to eq([issue])
+ end
+ end
+
+ context 'with multiple references' do
+ let(:other_issue) { create(:issue, project: project) }
+ let(:third_issue) { create(:issue, project: project) }
+ let(:iid2) { other_issue.iid }
+ let(:iid3) { third_issue.iid }
+
+ it 'fetches issues in single line message' do
+ message = "Closes ##{iid1} and fix ##{iid2}"
+
+ expect(subject.closed_by_message_in_project(message, project)).
+ to eq([issue, other_issue])
+ end
+
+ it 'fetches comma-separated issues references in single line message' do
+ message = "Closes ##{iid1}, closes ##{iid2}"
+
+ expect(subject.closed_by_message_in_project(message, project)).
+ to eq([issue, other_issue])
+ end
+
+ it 'fetches comma-separated issues numbers in single line message' do
+ message = "Closes ##{iid1}, ##{iid2} and ##{iid3}"
+
+ expect(subject.closed_by_message_in_project(message, project)).
+ to eq([issue, other_issue, third_issue])
+ end
+
+ it 'fetches issues in multi-line message' do
+ message = "Awesome commit (closes ##{iid1})\nAlso fixes ##{iid2}"
+
+ expect(subject.closed_by_message_in_project(message, project)).
+ to eq([issue, other_issue])
+ end
+
+ it 'fetches issues in hybrid message' do
+ message = "Awesome commit (closes ##{iid1})\n"\
+ "Also fixing issues ##{iid2}, ##{iid3} and #4"
+
+ expect(subject.closed_by_message_in_project(message, project)).
+ to eq([issue, other_issue, third_issue])
+ end
+ end
+ end
+end
diff --git a/spec/lib/gitlab/diff/file_spec.rb b/spec/lib/gitlab/diff/file_spec.rb
index cf0b5c282c1..40eb45e37ca 100644
--- a/spec/lib/gitlab/diff/file_spec.rb
+++ b/spec/lib/gitlab/diff/file_spec.rb
@@ -11,11 +11,11 @@ describe Gitlab::Diff::File do
describe :diff_lines do
let(:diff_lines) { diff_file.diff_lines }
- it { diff_lines.size.should == 30 }
- it { diff_lines.first.should be_kind_of(Gitlab::Diff::Line) }
+ it { expect(diff_lines.size).to eq(30) }
+ it { expect(diff_lines.first).to be_kind_of(Gitlab::Diff::Line) }
end
describe :mode_changed? do
- it { diff_file.mode_changed?.should be_false }
+ it { expect(diff_file.mode_changed?).to be_falsey }
end
end
diff --git a/spec/lib/gitlab/diff/parser_spec.rb b/spec/lib/gitlab/diff/parser_spec.rb
index 35b78260acd..918f6d0ead4 100644
--- a/spec/lib/gitlab/diff/parser_spec.rb
+++ b/spec/lib/gitlab/diff/parser_spec.rb
@@ -50,43 +50,43 @@ eos
@lines = parser.parse(diff.lines)
end
- it { @lines.size.should == 30 }
+ it { expect(@lines.size).to eq(30) }
describe 'lines' do
describe 'first line' do
let(:line) { @lines.first }
- it { line.type.should == 'match' }
- it { line.old_pos.should == 6 }
- it { line.new_pos.should == 6 }
- it { line.text.should == '@@ -6,12 +6,18 @@ module Popen' }
+ it { expect(line.type).to eq('match') }
+ it { expect(line.old_pos).to eq(6) }
+ it { expect(line.new_pos).to eq(6) }
+ it { expect(line.text).to eq('@@ -6,12 +6,18 @@ module Popen') }
end
describe 'removal line' do
let(:line) { @lines[10] }
- it { line.type.should == 'old' }
- it { line.old_pos.should == 14 }
- it { line.new_pos.should == 13 }
- it { line.text.should == '- options = { chdir: path }' }
+ it { expect(line.type).to eq('old') }
+ it { expect(line.old_pos).to eq(14) }
+ it { expect(line.new_pos).to eq(13) }
+ it { expect(line.text).to eq('- options = { chdir: path }') }
end
describe 'addition line' do
let(:line) { @lines[16] }
- it { line.type.should == 'new' }
- it { line.old_pos.should == 15 }
- it { line.new_pos.should == 18 }
- it { line.text.should == '+ options = {' }
+ it { expect(line.type).to eq('new') }
+ it { expect(line.old_pos).to eq(15) }
+ it { expect(line.new_pos).to eq(18) }
+ it { expect(line.text).to eq('+ options = {') }
end
describe 'unchanged line' do
let(:line) { @lines.last }
- it { line.type.should == nil }
- it { line.old_pos.should == 24 }
- it { line.new_pos.should == 31 }
- it { line.text.should == ' @cmd_output &lt;&lt; stderr.read' }
+ it { expect(line.type).to eq(nil) }
+ it { expect(line.old_pos).to eq(24) }
+ it { expect(line.new_pos).to eq(31) }
+ it { expect(line.text).to eq(' @cmd_output &lt;&lt; stderr.read') }
end
end
end
diff --git a/spec/lib/gitlab/git_access_spec.rb b/spec/lib/gitlab/git_access_spec.rb
index 570b03827a8..666398eedd4 100644
--- a/spec/lib/gitlab/git_access_spec.rb
+++ b/spec/lib/gitlab/git_access_spec.rb
@@ -5,14 +5,76 @@ describe Gitlab::GitAccess do
let(:project) { create(:project) }
let(:user) { create(:user) }
- describe 'download_allowed?' do
+ describe 'can_push_to_branch?' do
+ describe 'push to none protected branch' do
+ it "returns true if user is a master" do
+ project.team << [user, :master]
+ expect(Gitlab::GitAccess.can_push_to_branch?(user, project, "random_branch")).to be_truthy
+ end
+
+ it "returns true if user is a developer" do
+ project.team << [user, :developer]
+ expect(Gitlab::GitAccess.can_push_to_branch?(user, project, "random_branch")).to be_truthy
+ end
+
+ it "returns false if user is a reporter" do
+ project.team << [user, :reporter]
+ expect(Gitlab::GitAccess.can_push_to_branch?(user, project, "random_branch")).to be_falsey
+ end
+ end
+
+ describe 'push to protected branch' do
+ before do
+ @branch = create :protected_branch, project: project
+ end
+
+ it "returns true if user is a master" do
+ project.team << [user, :master]
+ expect(Gitlab::GitAccess.can_push_to_branch?(user, project, @branch.name)).to be_truthy
+ end
+
+ it "returns false if user is a developer" do
+ project.team << [user, :developer]
+ expect(Gitlab::GitAccess.can_push_to_branch?(user, project, @branch.name)).to be_falsey
+ end
+
+ it "returns false if user is a reporter" do
+ project.team << [user, :reporter]
+ expect(Gitlab::GitAccess.can_push_to_branch?(user, project, @branch.name)).to be_falsey
+ end
+ end
+
+ describe 'push to protected branch if allowed for developers' do
+ before do
+ @branch = create :protected_branch, project: project, developers_can_push: true
+ end
+
+ it "returns true if user is a master" do
+ project.team << [user, :master]
+ expect(Gitlab::GitAccess.can_push_to_branch?(user, project, @branch.name)).to be_truthy
+ end
+
+ it "returns true if user is a developer" do
+ project.team << [user, :developer]
+ expect(Gitlab::GitAccess.can_push_to_branch?(user, project, @branch.name)).to be_truthy
+ end
+
+ it "returns false if user is a reporter" do
+ project.team << [user, :reporter]
+ expect(Gitlab::GitAccess.can_push_to_branch?(user, project, @branch.name)).to be_falsey
+ end
+ end
+
+ end
+
+ describe 'download_access_check' do
describe 'master permissions' do
before { project.team << [user, :master] }
context 'pull code' do
- subject { access.download_allowed?(user, project) }
+ subject { access.download_access_check(user, project) }
- it { should be_true }
+ it { expect(subject.allowed?).to be_truthy }
end
end
@@ -20,9 +82,9 @@ describe Gitlab::GitAccess do
before { project.team << [user, :guest] }
context 'pull code' do
- subject { access.download_allowed?(user, project) }
+ subject { access.download_access_check(user, project) }
- it { should be_false }
+ it { expect(subject.allowed?).to be_falsey }
end
end
@@ -33,34 +95,54 @@ describe Gitlab::GitAccess do
end
context 'pull code' do
- subject { access.download_allowed?(user, project) }
+ subject { access.download_access_check(user, project) }
- it { should be_false }
+ it { expect(subject.allowed?).to be_falsey }
end
end
describe 'without acccess to project' do
context 'pull code' do
- subject { access.download_allowed?(user, project) }
+ subject { access.download_access_check(user, project) }
+
+ it { expect(subject.allowed?).to be_falsey }
+ end
+ end
+
+ describe 'deploy key permissions' do
+ let(:key) { create(:deploy_key) }
+
+ context 'pull code' do
+ context 'allowed' do
+ before { key.projects << project }
+ subject { access.download_access_check(key, project) }
+
+ it { expect(subject.allowed?).to be_truthy }
+ end
+
+ context 'denied' do
+ subject { access.download_access_check(key, project) }
- it { should be_false }
+ it { expect(subject.allowed?).to be_falsey }
+ end
end
end
end
- describe 'push_allowed?' do
+ describe 'push_access_check' do
def protect_feature_branch
create(:protected_branch, name: 'feature', project: project)
end
def changes
{
- push_new_branch: '000000000 570e7b2ab refs/heads/wow',
+ push_new_branch: "#{Gitlab::Git::BLANK_SHA} 570e7b2ab refs/heads/wow",
push_master: '6f6d7e7ed 570e7b2ab refs/heads/master',
push_protected_branch: '6f6d7e7ed 570e7b2ab refs/heads/feature',
- push_remove_protected_branch: '570e7b2ab 000000000 refs/heads/feature',
+ push_remove_protected_branch: "570e7b2ab #{Gitlab::Git::BLANK_SHA} "\
+ 'refs/heads/feature',
push_tag: '6f6d7e7ed 570e7b2ab refs/tags/v1.0.0',
- push_new_tag: '000000000 570e7b2ab refs/tags/v7.8.9',
+ push_new_tag: "#{Gitlab::Git::BLANK_SHA} 570e7b2ab refs/tags/v7.8.9",
push_all: ['6f6d7e7ed 570e7b2ab refs/heads/master', '6f6d7e7ed 570e7b2ab refs/heads/feature']
}
end
@@ -109,6 +191,13 @@ describe Gitlab::GitAccess do
}
end
+ def self.updated_permissions_matrix
+ updated_permissions_matrix = permissions_matrix.dup
+ updated_permissions_matrix[:developer][:push_protected_branch] = true
+ updated_permissions_matrix[:developer][:push_all] = true
+ updated_permissions_matrix
+ end
+
permissions_matrix.keys.each do |role|
describe "#{role} access" do
before { protect_feature_branch }
@@ -116,9 +205,26 @@ describe Gitlab::GitAccess do
permissions_matrix[role].each do |action, allowed|
context action do
- subject { access.push_allowed?(user, project, changes[action]) }
+ subject { access.push_access_check(user, project, changes[action]) }
+
+ it { expect(subject.allowed?).to allowed ? be_truthy : be_falsey }
+ end
+ end
+ end
+ end
+
+ context "with enabled developers push to protected branches " do
+ updated_permissions_matrix.keys.each do |role|
+ describe "#{role} access" do
+ before { create(:protected_branch, name: 'feature', developers_can_push: true, project: project) }
+ before { project.team << [user, role] }
+
+ updated_permissions_matrix[role].each do |action, allowed|
+ context action do
+ subject { access.push_access_check(user, project, changes[action]) }
- it { should allowed ? be_true : be_false }
+ it { expect(subject.allowed?).to allowed ? be_truthy : be_falsey }
+ end
end
end
end
diff --git a/spec/lib/gitlab/git_access_wiki_spec.rb b/spec/lib/gitlab/git_access_wiki_spec.rb
index ed5785b31e6..c31c6764091 100644
--- a/spec/lib/gitlab/git_access_wiki_spec.rb
+++ b/spec/lib/gitlab/git_access_wiki_spec.rb
@@ -11,9 +11,9 @@ describe Gitlab::GitAccessWiki do
project.team << [user, :developer]
end
- subject { access.push_allowed?(user, project, changes) }
+ subject { access.push_access_check(user, project, changes) }
- it { should be_true }
+ it { expect(subject.allowed?).to be_truthy }
end
def changes
diff --git a/spec/lib/gitlab/github_import/project_creator_spec.rb b/spec/lib/gitlab/github_import/project_creator_spec.rb
new file mode 100644
index 00000000000..8d594a112d4
--- /dev/null
+++ b/spec/lib/gitlab/github_import/project_creator_spec.rb
@@ -0,0 +1,24 @@
+require 'spec_helper'
+
+describe Gitlab::GithubImport::ProjectCreator do
+ let(:user) { create(:user, github_access_token: "asdffg") }
+ let(:repo) { OpenStruct.new(
+ login: 'vim',
+ name: 'vim',
+ private: true,
+ full_name: 'asd/vim',
+ clone_url: "https://gitlab.com/asd/vim.git",
+ owner: OpenStruct.new(login: "john"))
+ }
+ let(:namespace){ create(:namespace) }
+
+ it 'creates project' do
+ allow_any_instance_of(Project).to receive(:add_import_job)
+
+ project_creator = Gitlab::GithubImport::ProjectCreator.new(repo, namespace, user)
+ project = project_creator.execute
+
+ expect(project.import_url).to eq("https://asdffg@gitlab.com/asd/vim.git")
+ expect(project.visibility_level).to eq(Gitlab::VisibilityLevel::PRIVATE)
+ end
+end
diff --git a/spec/lib/gitlab/gitlab_import/project_creator_spec.rb b/spec/lib/gitlab/gitlab_import/project_creator_spec.rb
new file mode 100644
index 00000000000..4c0d64ed138
--- /dev/null
+++ b/spec/lib/gitlab/gitlab_import/project_creator_spec.rb
@@ -0,0 +1,24 @@
+require 'spec_helper'
+
+describe Gitlab::GitlabImport::ProjectCreator do
+ let(:user) { create(:user, gitlab_access_token: "asdffg") }
+ let(:repo) { {
+ name: 'vim',
+ path: 'vim',
+ visibility_level: Gitlab::VisibilityLevel::PRIVATE,
+ path_with_namespace: 'asd/vim',
+ http_url_to_repo: "https://gitlab.com/asd/vim.git",
+ owner: {name: "john"}}.with_indifferent_access
+ }
+ let(:namespace){ create(:namespace) }
+
+ it 'creates project' do
+ allow_any_instance_of(Project).to receive(:add_import_job)
+
+ project_creator = Gitlab::GitlabImport::ProjectCreator.new(repo, namespace, user)
+ project = project_creator.execute
+
+ expect(project.import_url).to eq("https://oauth2:asdffg@gitlab.com/asd/vim.git")
+ expect(project.visibility_level).to eq(Gitlab::VisibilityLevel::PRIVATE)
+ end
+end
diff --git a/spec/lib/gitlab/gitlab_markdown_helper_spec.rb b/spec/lib/gitlab/gitlab_markdown_helper_spec.rb
index 540618a5603..ab613193f41 100644
--- a/spec/lib/gitlab/gitlab_markdown_helper_spec.rb
+++ b/spec/lib/gitlab/gitlab_markdown_helper_spec.rb
@@ -5,24 +5,24 @@ describe Gitlab::MarkdownHelper do
%w(textile rdoc org creole wiki
mediawiki rst adoc asciidoc asc).each do |type|
it "returns true for #{type} files" do
- Gitlab::MarkdownHelper.markup?("README.#{type}").should be_true
+ expect(Gitlab::MarkdownHelper.markup?("README.#{type}")).to be_truthy
end
end
it 'returns false when given a non-markup filename' do
- Gitlab::MarkdownHelper.markup?('README.rb').should_not be_true
+ expect(Gitlab::MarkdownHelper.markup?('README.rb')).not_to be_truthy
end
end
describe '#gitlab_markdown?' do
%w(mdown md markdown).each do |type|
it "returns true for #{type} files" do
- Gitlab::MarkdownHelper.gitlab_markdown?("README.#{type}").should be_true
+ expect(Gitlab::MarkdownHelper.gitlab_markdown?("README.#{type}")).to be_truthy
end
end
it 'returns false when given a non-markdown filename' do
- Gitlab::MarkdownHelper.gitlab_markdown?('README.rb').should_not be_true
+ expect(Gitlab::MarkdownHelper.gitlab_markdown?('README.rb')).not_to be_truthy
end
end
end
diff --git a/spec/lib/gitlab/gitorious_import/project_creator.rb b/spec/lib/gitlab/gitorious_import/project_creator.rb
new file mode 100644
index 00000000000..cf2318bb3a2
--- /dev/null
+++ b/spec/lib/gitlab/gitorious_import/project_creator.rb
@@ -0,0 +1,23 @@
+require 'spec_helper'
+
+describe Gitlab::GitoriousImport::ProjectCreator do
+ let(:user) { create(:user) }
+ let(:repo) { Gitlab::GitoriousImport::Repository.new('foo/bar-baz-qux') }
+ let(:namespace){ create(:namespace) }
+
+ it 'creates project' do
+ allow_any_instance_of(Project).to receive(:add_import_job)
+
+ project_creator = Gitlab::GitoriousImport::ProjectCreator.new(repo, namespace, user)
+ project_creator.execute
+ project = Project.last
+
+ expect(project.name).to eq("Bar Baz Qux")
+ expect(project.path).to eq("bar-baz-qux")
+ expect(project.namespace).to eq(namespace)
+ expect(project.visibility_level).to eq(Gitlab::VisibilityLevel::PUBLIC)
+ expect(project.import_type).to eq("gitorious")
+ expect(project.import_source).to eq("foo/bar-baz-qux")
+ expect(project.import_url).to eq("https://gitorious.org/foo/bar-baz-qux.git")
+ end
+end
diff --git a/spec/lib/gitlab/ldap/access_spec.rb b/spec/lib/gitlab/ldap/access_spec.rb
index f4d5a927396..a2b05249147 100644
--- a/spec/lib/gitlab/ldap/access_spec.rb
+++ b/spec/lib/gitlab/ldap/access_spec.rb
@@ -2,7 +2,7 @@ require 'spec_helper'
describe Gitlab::LDAP::Access do
let(:access) { Gitlab::LDAP::Access.new user }
- let(:user) { create(:user, :ldap) }
+ let(:user) { create(:omniauth_user) }
describe :allowed? do
subject { access.allowed? }
@@ -10,7 +10,7 @@ describe Gitlab::LDAP::Access do
context 'when the user cannot be found' do
before { Gitlab::LDAP::Person.stub(find_by_dn: nil) }
- it { should be_false }
+ it { is_expected.to be_falsey }
end
context 'when the user is found' do
@@ -19,13 +19,13 @@ describe Gitlab::LDAP::Access do
context 'and the user is diabled via active directory' do
before { Gitlab::LDAP::Person.stub(disabled_via_active_directory?: true) }
- it { should be_false }
+ it { is_expected.to be_falsey }
end
context 'and has no disabled flag in active diretory' do
before { Gitlab::LDAP::Person.stub(disabled_via_active_directory?: false) }
- it { should be_true }
+ it { is_expected.to be_truthy }
end
context 'without ActiveDirectory enabled' do
@@ -34,7 +34,7 @@ describe Gitlab::LDAP::Access do
Gitlab::LDAP::Config.any_instance.stub(active_directory: false)
end
- it { should be_true }
+ it { is_expected.to be_truthy }
end
end
end
diff --git a/spec/lib/gitlab/ldap/adapter_spec.rb b/spec/lib/gitlab/ldap/adapter_spec.rb
index 19347e47378..b609e4b38f2 100644
--- a/spec/lib/gitlab/ldap/adapter_spec.rb
+++ b/spec/lib/gitlab/ldap/adapter_spec.rb
@@ -12,20 +12,20 @@ describe Gitlab::LDAP::Adapter do
context "and the result is non-empty" do
before { ldap.stub(search: [:foo]) }
- it { should be_true }
+ it { is_expected.to be_truthy }
end
context "and the result is empty" do
before { ldap.stub(search: []) }
- it { should be_false }
+ it { is_expected.to be_falsey }
end
end
context "when the search encounters an error" do
before { ldap.stub(search: nil, get_operation_result: double(code: 1, message: 'some error')) }
- it { should be_false }
+ it { is_expected.to be_falsey }
end
end
end
diff --git a/spec/lib/gitlab/ldap/authentication_spec.rb b/spec/lib/gitlab/ldap/authentication_spec.rb
index 0eb7c443b8b..8afc2b21f46 100644
--- a/spec/lib/gitlab/ldap/authentication_spec.rb
+++ b/spec/lib/gitlab/ldap/authentication_spec.rb
@@ -2,7 +2,7 @@ require 'spec_helper'
describe Gitlab::LDAP::Authentication do
let(:klass) { Gitlab::LDAP::Authentication }
- let(:user) { create(:user, :ldap, extern_uid: dn) }
+ let(:user) { create(:omniauth_user, extern_uid: dn) }
let(:dn) { 'uid=john,ou=people,dc=example,dc=com' }
let(:login) { 'john' }
let(:password) { 'password' }
@@ -19,7 +19,7 @@ describe Gitlab::LDAP::Authentication do
klass.any_instance.stub(adapter: double(:adapter,
bind_as: double(:ldap_user, dn: dn)
))
- expect(klass.login(login, password)).to be_true
+ expect(klass.login(login, password)).to be_truthy
end
it "is false if the user does not exist" do
@@ -27,27 +27,27 @@ describe Gitlab::LDAP::Authentication do
klass.any_instance.stub(adapter: double(:adapter,
bind_as: double(:ldap_user, dn: dn)
))
- expect(klass.login(login, password)).to be_false
+ expect(klass.login(login, password)).to be_falsey
end
it "is false if authentication fails" do
user
# try only to fake the LDAP call
klass.any_instance.stub(adapter: double(:adapter, bind_as: nil))
- expect(klass.login(login, password)).to be_false
+ expect(klass.login(login, password)).to be_falsey
end
it "fails if ldap is disabled" do
Gitlab::LDAP::Config.stub(enabled?: false)
- expect(klass.login(login, password)).to be_false
+ expect(klass.login(login, password)).to be_falsey
end
it "fails if no login is supplied" do
- expect(klass.login('', password)).to be_false
+ expect(klass.login('', password)).to be_falsey
end
it "fails if no password is supplied" do
- expect(klass.login(login, '')).to be_false
+ expect(klass.login(login, '')).to be_falsey
end
end
end \ No newline at end of file
diff --git a/spec/lib/gitlab/ldap/config_spec.rb b/spec/lib/gitlab/ldap/config_spec.rb
index 3ebb8aae243..2df2beca7a6 100644
--- a/spec/lib/gitlab/ldap/config_spec.rb
+++ b/spec/lib/gitlab/ldap/config_spec.rb
@@ -4,7 +4,7 @@ describe Gitlab::LDAP::Config do
let(:config) { Gitlab::LDAP::Config.new provider }
let(:provider) { 'ldapmain' }
- describe :initalize do
+ describe '#initalize' do
it 'requires a provider' do
expect{ Gitlab::LDAP::Config.new }.to raise_error ArgumentError
end
diff --git a/spec/lib/gitlab/ldap/user_spec.rb b/spec/lib/gitlab/ldap/user_spec.rb
index 726c9764e3d..4f93545feb6 100644
--- a/spec/lib/gitlab/ldap/user_spec.rb
+++ b/spec/lib/gitlab/ldap/user_spec.rb
@@ -13,20 +13,37 @@ describe Gitlab::LDAP::User do
double(uid: 'my-uid', provider: 'ldapmain', info: double(info))
end
+ describe :changed? do
+ it "marks existing ldap user as changed" do
+ existing_user = create(:omniauth_user, extern_uid: 'my-uid', provider: 'ldapmain')
+ expect(gl_user.changed?).to be_truthy
+ end
+
+ it "marks existing non-ldap user if the email matches as changed" do
+ existing_user = create(:user, email: 'john@example.com')
+ expect(gl_user.changed?).to be_truthy
+ end
+
+ it "dont marks existing ldap user as changed" do
+ existing_user = create(:omniauth_user, email: 'john@example.com', extern_uid: 'my-uid', provider: 'ldapmain')
+ expect(gl_user.changed?).to be_falsey
+ end
+ end
+
describe :find_or_create do
it "finds the user if already existing" do
- existing_user = create(:user, extern_uid: 'my-uid', provider: 'ldapmain')
+ existing_user = create(:omniauth_user, extern_uid: 'my-uid', provider: 'ldapmain')
expect{ gl_user.save }.to_not change{ User.count }
end
it "connects to existing non-ldap user if the email matches" do
- existing_user = create(:user, email: 'john@example.com')
+ existing_user = create(:omniauth_user, email: 'john@example.com', provider: "twitter")
expect{ gl_user.save }.to_not change{ User.count }
existing_user.reload
- expect(existing_user.extern_uid).to eql 'my-uid'
- expect(existing_user.provider).to eql 'ldapmain'
+ expect(existing_user.ldap_identity.extern_uid).to eql 'my-uid'
+ expect(existing_user.ldap_identity.provider).to eql 'ldapmain'
end
it "creates a new user if not found" do
diff --git a/spec/lib/gitlab/oauth/user_spec.rb b/spec/lib/gitlab/oauth/user_spec.rb
index 8a83a1b2588..44cdd1e4fab 100644
--- a/spec/lib/gitlab/oauth/user_spec.rb
+++ b/spec/lib/gitlab/oauth/user_spec.rb
@@ -8,23 +8,23 @@ describe Gitlab::OAuth::User do
let(:auth_hash) { double(uid: uid, provider: provider, info: double(info_hash)) }
let(:info_hash) do
{
- nickname: 'john',
+ nickname: '-john+gitlab-ETC%.git@gmail.com',
name: 'John',
email: 'john@mail.com'
}
end
describe :persisted? do
- let!(:existing_user) { create(:user, extern_uid: 'my-uid', provider: 'my-provider') }
+ let!(:existing_user) { create(:omniauth_user, extern_uid: 'my-uid', provider: 'my-provider') }
it "finds an existing user based on uid and provider (facebook)" do
auth = double(info: double(name: 'John'), uid: 'my-uid', provider: 'my-provider')
- expect( oauth_user.persisted? ).to be_true
+ expect( oauth_user.persisted? ).to be_truthy
end
it "returns false if use is not found in database" do
auth_hash.stub(uid: 'non-existing')
- expect( oauth_user.persisted? ).to be_false
+ expect( oauth_user.persisted? ).to be_falsey
end
end
@@ -39,8 +39,9 @@ describe Gitlab::OAuth::User do
oauth_user.save
expect(gl_user).to be_valid
- expect(gl_user.extern_uid).to eql uid
- expect(gl_user.provider).to eql 'twitter'
+ identity = gl_user.identities.first
+ expect(identity.extern_uid).to eql uid
+ expect(identity.provider).to eql 'twitter'
end
end
@@ -61,8 +62,8 @@ describe Gitlab::OAuth::User do
it do
oauth_user.save
- gl_user.should be_valid
- gl_user.should_not be_blocked
+ expect(gl_user).to be_valid
+ expect(gl_user).not_to be_blocked
end
end
@@ -71,8 +72,8 @@ describe Gitlab::OAuth::User do
it do
oauth_user.save
- gl_user.should be_valid
- gl_user.should be_blocked
+ expect(gl_user).to be_valid
+ expect(gl_user).to be_blocked
end
end
end
@@ -88,8 +89,8 @@ describe Gitlab::OAuth::User do
it do
oauth_user.save
- gl_user.should be_valid
- gl_user.should_not be_blocked
+ expect(gl_user).to be_valid
+ expect(gl_user).not_to be_blocked
end
end
@@ -98,8 +99,8 @@ describe Gitlab::OAuth::User do
it do
oauth_user.save
- gl_user.should be_valid
- gl_user.should_not be_blocked
+ expect(gl_user).to be_valid
+ expect(gl_user).not_to be_blocked
end
end
end
diff --git a/spec/lib/gitlab/popen_spec.rb b/spec/lib/gitlab/popen_spec.rb
index 76d506eb3c0..cd9d0456b25 100644
--- a/spec/lib/gitlab/popen_spec.rb
+++ b/spec/lib/gitlab/popen_spec.rb
@@ -13,8 +13,8 @@ describe 'Gitlab::Popen', no_db: true do
@output, @status = @klass.new.popen(%W(ls), path)
end
- it { @status.should be_zero }
- it { @output.should include('cache') }
+ it { expect(@status).to be_zero }
+ it { expect(@output).to include('cache') }
end
context 'non-zero status' do
@@ -22,8 +22,8 @@ describe 'Gitlab::Popen', no_db: true do
@output, @status = @klass.new.popen(%W(cat NOTHING), path)
end
- it { @status.should == 1 }
- it { @output.should include('No such file or directory') }
+ it { expect(@status).to eq(1) }
+ it { expect(@output).to include('No such file or directory') }
end
context 'unsafe string command' do
@@ -37,8 +37,8 @@ describe 'Gitlab::Popen', no_db: true do
@output, @status = @klass.new.popen(%W(ls))
end
- it { @status.should be_zero }
- it { @output.should include('spec') }
+ it { expect(@status).to be_zero }
+ it { expect(@output).to include('spec') }
end
end
diff --git a/spec/lib/gitlab/push_data_builder_spec.rb b/spec/lib/gitlab/push_data_builder_spec.rb
new file mode 100644
index 00000000000..1b8ba7b4d43
--- /dev/null
+++ b/spec/lib/gitlab/push_data_builder_spec.rb
@@ -0,0 +1,39 @@
+require 'spec_helper'
+
+describe 'Gitlab::PushDataBuilder' do
+ let(:project) { create(:project) }
+ let(:user) { create(:user) }
+
+
+ describe :build_sample do
+ let(:data) { Gitlab::PushDataBuilder.build_sample(project, user) }
+
+ it { expect(data).to be_a(Hash) }
+ it { expect(data[:before]).to eq('6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9') }
+ it { expect(data[:after]).to eq('5937ac0a7beb003549fc5fd26fc247adbce4a52e') }
+ it { expect(data[:ref]).to eq('refs/heads/master') }
+ it { expect(data[:commits].size).to eq(3) }
+ it { expect(data[:repository][:git_http_url]).to eq(project.http_url_to_repo) }
+ it { expect(data[:repository][:git_ssh_url]).to eq(project.ssh_url_to_repo) }
+ it { expect(data[:repository][:visibility_level]).to eq(project.visibility_level) }
+ it { expect(data[:total_commits_count]).to eq(3) }
+ end
+
+ describe :build do
+ let(:data) do
+ Gitlab::PushDataBuilder.build(project,
+ user,
+ Gitlab::Git::BLANK_SHA,
+ '8a2a6eb295bb170b34c24c76c49ed0e9b2eaf34b',
+ 'refs/tags/v1.1.0')
+ end
+
+ it { expect(data).to be_a(Hash) }
+ it { expect(data[:before]).to eq(Gitlab::Git::BLANK_SHA) }
+ it { expect(data[:checkout_sha]).to eq('5937ac0a7beb003549fc5fd26fc247adbce4a52e') }
+ it { expect(data[:after]).to eq('8a2a6eb295bb170b34c24c76c49ed0e9b2eaf34b') }
+ it { expect(data[:ref]).to eq('refs/tags/v1.1.0') }
+ it { expect(data[:commits]).to be_empty }
+ it { expect(data[:total_commits_count]).to be_zero }
+ end
+end
diff --git a/spec/lib/gitlab/reference_extractor_spec.rb b/spec/lib/gitlab/reference_extractor_spec.rb
index 23867df39dd..0847c31258c 100644
--- a/spec/lib/gitlab/reference_extractor_spec.rb
+++ b/spec/lib/gitlab/reference_extractor_spec.rb
@@ -3,52 +3,51 @@ require 'spec_helper'
describe Gitlab::ReferenceExtractor do
it 'extracts username references' do
subject.analyze('this contains a @user reference', nil)
- subject.users.should == [{ project: nil, id: 'user' }]
+ expect(subject.users).to eq([{ project: nil, id: 'user' }])
end
it 'extracts issue references' do
subject.analyze('this one talks about issue #1234', nil)
- subject.issues.should == [{ project: nil, id: '1234' }]
+ expect(subject.issues).to eq([{ project: nil, id: '1234' }])
end
it 'extracts JIRA issue references' do
- Gitlab.config.gitlab.stub(:issues_tracker).and_return('jira')
subject.analyze('this one talks about issue JIRA-1234', nil)
- subject.issues.should == [{ project: nil, id: 'JIRA-1234' }]
+ expect(subject.issues).to eq([{ project: nil, id: 'JIRA-1234' }])
end
it 'extracts merge request references' do
subject.analyze("and here's !43, a merge request", nil)
- subject.merge_requests.should == [{ project: nil, id: '43' }]
+ expect(subject.merge_requests).to eq([{ project: nil, id: '43' }])
end
it 'extracts snippet ids' do
subject.analyze('snippets like $12 get extracted as well', nil)
- subject.snippets.should == [{ project: nil, id: '12' }]
+ expect(subject.snippets).to eq([{ project: nil, id: '12' }])
end
it 'extracts commit shas' do
subject.analyze('commit shas 98cf0ae3 are pulled out as Strings', nil)
- subject.commits.should == [{ project: nil, id: '98cf0ae3' }]
+ expect(subject.commits).to eq([{ project: nil, id: '98cf0ae3' }])
end
it 'extracts multiple references and preserves their order' do
subject.analyze('@me and @you both care about this', nil)
- subject.users.should == [
+ expect(subject.users).to eq([
{ project: nil, id: 'me' },
{ project: nil, id: 'you' }
- ]
+ ])
end
it 'leaves the original note unmodified' do
text = 'issue #123 is just the worst, @user'
subject.analyze(text, nil)
- text.should == 'issue #123 is just the worst, @user'
+ expect(text).to eq('issue #123 is just the worst, @user')
end
it 'handles all possible kinds of references' do
accessors = Gitlab::Markdown::TYPES.map { |t| "#{t}s".to_sym }
- subject.should respond_to(*accessors)
+ expect(subject).to respond_to(*accessors)
end
context 'with a project' do
@@ -63,7 +62,7 @@ describe Gitlab::ReferenceExtractor do
project.team << [@u_bar, :guest]
subject.analyze('@foo, @baduser, @bar, and @offteam', project)
- subject.users_for(project).should == [@u_foo, @u_bar]
+ expect(subject.users_for(project)).to eq([@u_foo, @u_bar])
end
it 'accesses valid issue objects' do
@@ -71,7 +70,7 @@ describe Gitlab::ReferenceExtractor do
@i1 = create(:issue, project: project)
subject.analyze("##{@i0.iid}, ##{@i1.iid}, and #999.", project)
- subject.issues_for(project).should == [@i0, @i1]
+ expect(subject.issues_for(project)).to eq([@i0, @i1])
end
it 'accesses valid merge requests' do
@@ -79,7 +78,7 @@ describe Gitlab::ReferenceExtractor do
@m1 = create(:merge_request, source_project: project, target_project: project, source_branch: 'bbb')
subject.analyze("!999, !#{@m1.iid}, and !#{@m0.iid}.", project)
- subject.merge_requests_for(project).should == [@m1, @m0]
+ expect(subject.merge_requests_for(project)).to eq([@m1, @m0])
end
it 'accesses valid snippets' do
@@ -88,7 +87,7 @@ describe Gitlab::ReferenceExtractor do
@s2 = create(:project_snippet)
subject.analyze("$#{@s0.id}, $999, $#{@s2.id}, $#{@s1.id}", project)
- subject.snippets_for(project).should == [@s0, @s1]
+ expect(subject.snippets_for(project)).to eq([@s0, @s1])
end
it 'accesses valid commits' do
@@ -97,9 +96,9 @@ describe Gitlab::ReferenceExtractor do
subject.analyze("this references commits #{commit.sha[0..6]} and 012345",
project)
extracted = subject.commits_for(project)
- extracted.should have(1).item
- extracted[0].sha.should == commit.sha
- extracted[0].message.should == commit.message
+ expect(extracted.size).to eq(1)
+ expect(extracted[0].sha).to eq(commit.sha)
+ expect(extracted[0].message).to eq(commit.message)
end
end
end
diff --git a/spec/lib/gitlab/regex_spec.rb b/spec/lib/gitlab/regex_spec.rb
index a3aae7771bd..1db9f15b790 100644
--- a/spec/lib/gitlab/regex_spec.rb
+++ b/spec/lib/gitlab/regex_spec.rb
@@ -2,20 +2,20 @@ require 'spec_helper'
describe Gitlab::Regex do
describe 'path regex' do
- it { 'gitlab-ce'.should match(Gitlab::Regex.path_regex) }
- it { 'gitlab_git'.should match(Gitlab::Regex.path_regex) }
- it { '_underscore.js'.should match(Gitlab::Regex.path_regex) }
- it { '100px.com'.should match(Gitlab::Regex.path_regex) }
- it { '?gitlab'.should_not match(Gitlab::Regex.path_regex) }
- it { 'git lab'.should_not match(Gitlab::Regex.path_regex) }
- it { 'gitlab.git'.should_not match(Gitlab::Regex.path_regex) }
+ it { expect('gitlab-ce').to match(Gitlab::Regex.path_regex) }
+ it { expect('gitlab_git').to match(Gitlab::Regex.path_regex) }
+ it { expect('_underscore.js').to match(Gitlab::Regex.path_regex) }
+ it { expect('100px.com').to match(Gitlab::Regex.path_regex) }
+ it { expect('?gitlab').not_to match(Gitlab::Regex.path_regex) }
+ it { expect('git lab').not_to match(Gitlab::Regex.path_regex) }
+ it { expect('gitlab.git').not_to match(Gitlab::Regex.path_regex) }
end
describe 'project name regex' do
- it { 'gitlab-ce'.should match(Gitlab::Regex.project_name_regex) }
- it { 'GitLab CE'.should match(Gitlab::Regex.project_name_regex) }
- it { '100 lines'.should match(Gitlab::Regex.project_name_regex) }
- it { 'gitlab.git'.should match(Gitlab::Regex.project_name_regex) }
- it { '?gitlab'.should_not match(Gitlab::Regex.project_name_regex) }
+ it { expect('gitlab-ce').to match(Gitlab::Regex.project_name_regex) }
+ it { expect('GitLab CE').to match(Gitlab::Regex.project_name_regex) }
+ it { expect('100 lines').to match(Gitlab::Regex.project_name_regex) }
+ it { expect('gitlab.git').to match(Gitlab::Regex.project_name_regex) }
+ it { expect('?gitlab').not_to match(Gitlab::Regex.project_name_regex) }
end
end
diff --git a/spec/lib/gitlab/satellite/action_spec.rb b/spec/lib/gitlab/satellite/action_spec.rb
index 3eb1258d67e..28e3d64ee2b 100644
--- a/spec/lib/gitlab/satellite/action_spec.rb
+++ b/spec/lib/gitlab/satellite/action_spec.rb
@@ -6,7 +6,7 @@ describe 'Gitlab::Satellite::Action' do
describe '#prepare_satellite!' do
it 'should be able to fetch timeout from conf' do
- Gitlab::Satellite::Action::DEFAULT_OPTIONS[:git_timeout].should == 30.seconds
+ expect(Gitlab::Satellite::Action::DEFAULT_OPTIONS[:git_timeout]).to eq(30.seconds)
end
it 'create a repository with a parking branch and one remote: origin' do
@@ -15,22 +15,22 @@ describe 'Gitlab::Satellite::Action' do
#now lets dirty it up
starting_remote_count = repo.git.list_remotes.size
- starting_remote_count.should >= 1
+ expect(starting_remote_count).to be >= 1
#kind of hookey way to add a second remote
origin_uri = repo.git.remote({v: true}).split(" ")[1]
begin
repo.git.remote({raise: true}, 'add', 'another-remote', origin_uri)
repo.git.branch({raise: true}, 'a-new-branch')
- repo.heads.size.should > (starting_remote_count)
- repo.git.remote().split(" ").size.should > (starting_remote_count)
+ expect(repo.heads.size).to be > (starting_remote_count)
+ expect(repo.git.remote().split(" ").size).to be > (starting_remote_count)
rescue
end
repo.git.config({}, "user.name", "#{user.name} -- foo")
repo.git.config({}, "user.email", "#{user.email} -- foo")
- repo.config['user.name'].should =="#{user.name} -- foo"
- repo.config['user.email'].should =="#{user.email} -- foo"
+ expect(repo.config['user.name']).to eq("#{user.name} -- foo")
+ expect(repo.config['user.email']).to eq("#{user.email} -- foo")
#These must happen in the context of the satellite directory...
@@ -42,13 +42,13 @@ describe 'Gitlab::Satellite::Action' do
#verify it's clean
heads = repo.heads.map(&:name)
- heads.size.should == 1
- heads.include?(Gitlab::Satellite::Satellite::PARKING_BRANCH).should == true
+ expect(heads.size).to eq(1)
+ expect(heads.include?(Gitlab::Satellite::Satellite::PARKING_BRANCH)).to eq(true)
remotes = repo.git.remote().split(' ')
- remotes.size.should == 1
- remotes.include?('origin').should == true
- repo.config['user.name'].should ==user.name
- repo.config['user.email'].should ==user.email
+ expect(remotes.size).to eq(1)
+ expect(remotes.include?('origin')).to eq(true)
+ expect(repo.config['user.name']).to eq(user.name)
+ expect(repo.config['user.email']).to eq(user.email)
end
end
@@ -61,16 +61,16 @@ describe 'Gitlab::Satellite::Action' do
#set assumptions
FileUtils.rm_f(project.satellite.lock_file)
- File.exists?(project.satellite.lock_file).should be_false
+ expect(File.exists?(project.satellite.lock_file)).to be_falsey
satellite_action = Gitlab::Satellite::Action.new(user, project)
satellite_action.send(:in_locked_and_timed_satellite) do |sat_repo|
- repo.should == sat_repo
- (File.exists? project.satellite.lock_file).should be_true
+ expect(repo).to eq(sat_repo)
+ expect(File.exists? project.satellite.lock_file).to be_truthy
called = true
end
- called.should be_true
+ expect(called).to be_truthy
end
@@ -80,19 +80,19 @@ describe 'Gitlab::Satellite::Action' do
# Set base assumptions
if File.exists? project.satellite.lock_file
- FileLockStatusChecker.new(project.satellite.lock_file).flocked?.should be_false
+ expect(FileLockStatusChecker.new(project.satellite.lock_file).flocked?).to be_falsey
end
satellite_action = Gitlab::Satellite::Action.new(user, project)
satellite_action.send(:in_locked_and_timed_satellite) do |sat_repo|
called = true
- repo.should == sat_repo
- (File.exists? project.satellite.lock_file).should be_true
- FileLockStatusChecker.new(project.satellite.lock_file).flocked?.should be_true
+ expect(repo).to eq(sat_repo)
+ expect(File.exists? project.satellite.lock_file).to be_truthy
+ expect(FileLockStatusChecker.new(project.satellite.lock_file).flocked?).to be_truthy
end
- called.should be_true
- FileLockStatusChecker.new(project.satellite.lock_file).flocked?.should be_false
+ expect(called).to be_truthy
+ expect(FileLockStatusChecker.new(project.satellite.lock_file).flocked?).to be_falsey
end
diff --git a/spec/lib/gitlab/satellite/merge_action_spec.rb b/spec/lib/gitlab/satellite/merge_action_spec.rb
index 479a73a1081..915e3ff0e51 100644
--- a/spec/lib/gitlab/satellite/merge_action_spec.rb
+++ b/spec/lib/gitlab/satellite/merge_action_spec.rb
@@ -13,9 +13,9 @@ describe 'Gitlab::Satellite::MergeAction' do
describe '#commits_between' do
def verify_commits(commits, first_commit_sha, last_commit_sha)
- commits.each { |commit| commit.class.should == Gitlab::Git::Commit }
- commits.first.id.should == first_commit_sha
- commits.last.id.should == last_commit_sha
+ commits.each { |commit| expect(commit.class).to eq(Gitlab::Git::Commit) }
+ expect(commits.first.id).to eq(first_commit_sha)
+ expect(commits.last.id).to eq(last_commit_sha)
end
context 'on fork' do
@@ -35,7 +35,7 @@ describe 'Gitlab::Satellite::MergeAction' do
describe '#format_patch' do
def verify_content(patch)
sample_compare.commits.each do |commit|
- patch.include?(commit).should be_true
+ expect(patch.include?(commit)).to be_truthy
end
end
@@ -57,11 +57,11 @@ describe 'Gitlab::Satellite::MergeAction' do
describe '#diffs_between_satellite tested against diff_in_satellite' do
def is_a_matching_diff(diff, diffs)
diff_count = diff.scan('diff --git').size
- diff_count.should >= 1
- diffs.size.should == diff_count
+ expect(diff_count).to be >= 1
+ expect(diffs.size).to eq(diff_count)
diffs.each do |a_diff|
- a_diff.class.should == Gitlab::Git::Diff
- (diff.include? a_diff.diff).should be_true
+ expect(a_diff.class).to eq(Gitlab::Git::Diff)
+ expect(diff.include? a_diff.diff).to be_truthy
end
end
@@ -82,23 +82,23 @@ describe 'Gitlab::Satellite::MergeAction' do
describe '#can_be_merged?' do
context 'on fork' do
- it { Gitlab::Satellite::MergeAction.new(
+ it { expect(Gitlab::Satellite::MergeAction.new(
merge_request_fork.author,
- merge_request_fork).can_be_merged?.should be_true }
+ merge_request_fork).can_be_merged?).to be_truthy }
- it { Gitlab::Satellite::MergeAction.new(
+ it { expect(Gitlab::Satellite::MergeAction.new(
merge_request_fork_with_conflict.author,
- merge_request_fork_with_conflict).can_be_merged?.should be_false }
+ merge_request_fork_with_conflict).can_be_merged?).to be_falsey }
end
context 'between branches' do
- it { Gitlab::Satellite::MergeAction.new(
+ it { expect(Gitlab::Satellite::MergeAction.new(
merge_request.author,
- merge_request).can_be_merged?.should be_true }
+ merge_request).can_be_merged?).to be_truthy }
- it { Gitlab::Satellite::MergeAction.new(
+ it { expect(Gitlab::Satellite::MergeAction.new(
merge_request_with_conflict.author,
- merge_request_with_conflict).can_be_merged?.should be_false }
+ merge_request_with_conflict).can_be_merged?).to be_falsey }
end
end
end
diff --git a/spec/lib/gitlab/upgrader_spec.rb b/spec/lib/gitlab/upgrader_spec.rb
index 2b254d6b3a6..ce3ea6c260a 100644
--- a/spec/lib/gitlab/upgrader_spec.rb
+++ b/spec/lib/gitlab/upgrader_spec.rb
@@ -5,20 +5,20 @@ describe Gitlab::Upgrader do
let(:current_version) { Gitlab::VERSION }
describe 'current_version_raw' do
- it { upgrader.current_version_raw.should == current_version }
+ it { expect(upgrader.current_version_raw).to eq(current_version) }
end
describe 'latest_version?' do
it 'should be true if newest version' do
upgrader.stub(latest_version_raw: current_version)
- upgrader.latest_version?.should be_true
+ expect(upgrader.latest_version?).to be_truthy
end
end
describe 'latest_version_raw' do
it 'should be latest version for GitLab 5' do
upgrader.stub(current_version_raw: "5.3.0")
- upgrader.latest_version_raw.should == "v5.4.2"
+ expect(upgrader.latest_version_raw).to eq("v5.4.2")
end
end
end
diff --git a/spec/lib/gitlab/url_builder_spec.rb b/spec/lib/gitlab/url_builder_spec.rb
index eb47bee8336..716430340b6 100644
--- a/spec/lib/gitlab/url_builder_spec.rb
+++ b/spec/lib/gitlab/url_builder_spec.rb
@@ -5,7 +5,7 @@ describe Gitlab::UrlBuilder do
it 'returns the issue url' do
issue = create(:issue)
url = Gitlab::UrlBuilder.new(:issue).build(issue.id)
- expect(url).to eq "#{Settings.gitlab['url']}/#{issue.project.to_param}/issues/#{issue.iid}"
+ expect(url).to eq "#{Settings.gitlab['url']}/#{issue.project.path_with_namespace}/issues/#{issue.iid}"
end
end
end
diff --git a/spec/lib/gitlab/version_info_spec.rb b/spec/lib/gitlab/version_info_spec.rb
index 94dccf7a4e5..5afeb1c1ec3 100644
--- a/spec/lib/gitlab/version_info_spec.rb
+++ b/spec/lib/gitlab/version_info_spec.rb
@@ -12,58 +12,58 @@ describe 'Gitlab::VersionInfo', no_db: true do
end
context '>' do
- it { @v2_0_0.should > @v1_1_0 }
- it { @v1_1_0.should > @v1_0_1 }
- it { @v1_0_1.should > @v1_0_0 }
- it { @v1_0_0.should > @v0_1_0 }
- it { @v0_1_0.should > @v0_0_1 }
+ it { expect(@v2_0_0).to be > @v1_1_0 }
+ it { expect(@v1_1_0).to be > @v1_0_1 }
+ it { expect(@v1_0_1).to be > @v1_0_0 }
+ it { expect(@v1_0_0).to be > @v0_1_0 }
+ it { expect(@v0_1_0).to be > @v0_0_1 }
end
context '>=' do
- it { @v2_0_0.should >= Gitlab::VersionInfo.new(2, 0, 0) }
- it { @v2_0_0.should >= @v1_1_0 }
+ it { expect(@v2_0_0).to be >= Gitlab::VersionInfo.new(2, 0, 0) }
+ it { expect(@v2_0_0).to be >= @v1_1_0 }
end
context '<' do
- it { @v0_0_1.should < @v0_1_0 }
- it { @v0_1_0.should < @v1_0_0 }
- it { @v1_0_0.should < @v1_0_1 }
- it { @v1_0_1.should < @v1_1_0 }
- it { @v1_1_0.should < @v2_0_0 }
+ it { expect(@v0_0_1).to be < @v0_1_0 }
+ it { expect(@v0_1_0).to be < @v1_0_0 }
+ it { expect(@v1_0_0).to be < @v1_0_1 }
+ it { expect(@v1_0_1).to be < @v1_1_0 }
+ it { expect(@v1_1_0).to be < @v2_0_0 }
end
context '<=' do
- it { @v0_0_1.should <= Gitlab::VersionInfo.new(0, 0, 1) }
- it { @v0_0_1.should <= @v0_1_0 }
+ it { expect(@v0_0_1).to be <= Gitlab::VersionInfo.new(0, 0, 1) }
+ it { expect(@v0_0_1).to be <= @v0_1_0 }
end
context '==' do
- it { @v0_0_1.should == Gitlab::VersionInfo.new(0, 0, 1) }
- it { @v0_1_0.should == Gitlab::VersionInfo.new(0, 1, 0) }
- it { @v1_0_0.should == Gitlab::VersionInfo.new(1, 0, 0) }
+ it { expect(@v0_0_1).to eq(Gitlab::VersionInfo.new(0, 0, 1)) }
+ it { expect(@v0_1_0).to eq(Gitlab::VersionInfo.new(0, 1, 0)) }
+ it { expect(@v1_0_0).to eq(Gitlab::VersionInfo.new(1, 0, 0)) }
end
context '!=' do
- it { @v0_0_1.should_not == @v0_1_0 }
+ it { expect(@v0_0_1).not_to eq(@v0_1_0) }
end
context 'unknown' do
- it { @unknown.should_not be @v0_0_1 }
- it { @unknown.should_not be Gitlab::VersionInfo.new }
+ it { expect(@unknown).not_to be @v0_0_1 }
+ it { expect(@unknown).not_to be Gitlab::VersionInfo.new }
it { expect{@unknown > @v0_0_1}.to raise_error(ArgumentError) }
it { expect{@unknown < @v0_0_1}.to raise_error(ArgumentError) }
end
context 'parse' do
- it { Gitlab::VersionInfo.parse("1.0.0").should == @v1_0_0 }
- it { Gitlab::VersionInfo.parse("1.0.0.1").should == @v1_0_0 }
- it { Gitlab::VersionInfo.parse("git 1.0.0b1").should == @v1_0_0 }
- it { Gitlab::VersionInfo.parse("git 1.0b1").should_not be_valid }
+ it { expect(Gitlab::VersionInfo.parse("1.0.0")).to eq(@v1_0_0) }
+ it { expect(Gitlab::VersionInfo.parse("1.0.0.1")).to eq(@v1_0_0) }
+ it { expect(Gitlab::VersionInfo.parse("git 1.0.0b1")).to eq(@v1_0_0) }
+ it { expect(Gitlab::VersionInfo.parse("git 1.0b1")).not_to be_valid }
end
context 'to_s' do
- it { @v1_0_0.to_s.should == "1.0.0" }
- it { @unknown.to_s.should == "Unknown" }
+ it { expect(@v1_0_0.to_s).to eq("1.0.0") }
+ it { expect(@unknown.to_s).to eq("Unknown") }
end
end
diff --git a/spec/lib/repository_cache_spec.rb b/spec/lib/repository_cache_spec.rb
new file mode 100644
index 00000000000..af399f3a731
--- /dev/null
+++ b/spec/lib/repository_cache_spec.rb
@@ -0,0 +1,34 @@
+require 'rspec'
+require_relative '../../lib/repository_cache'
+
+describe RepositoryCache do
+ let(:backend) { double('backend').as_null_object }
+ let(:cache) { RepositoryCache.new('example', backend) }
+
+ describe '#cache_key' do
+ it 'includes the namespace' do
+ expect(cache.cache_key(:foo)).to eq 'foo:example'
+ end
+ end
+
+ describe '#expire' do
+ it 'expires the given key from the cache' do
+ cache.expire(:foo)
+ expect(backend).to have_received(:delete).with('foo:example')
+ end
+ end
+
+ describe '#fetch' do
+ it 'fetches the given key from the cache' do
+ cache.fetch(:bar)
+ expect(backend).to have_received(:fetch).with('bar:example')
+ end
+
+ it 'accepts a block' do
+ p = -> {}
+
+ cache.fetch(:baz, &p)
+ expect(backend).to have_received(:fetch).with('baz:example', &p)
+ end
+ end
+end
diff --git a/spec/lib/votes_spec.rb b/spec/lib/votes_spec.rb
index a3c353d5eab..df243a26008 100644
--- a/spec/lib/votes_spec.rb
+++ b/spec/lib/votes_spec.rb
@@ -5,132 +5,181 @@ describe Issue, 'Votes' do
describe "#upvotes" do
it "with no notes has a 0/0 score" do
- issue.upvotes.should == 0
+ expect(issue.upvotes).to eq(0)
end
it "should recognize non-+1 notes" do
add_note "No +1 here"
- issue.should have(1).note
- issue.notes.first.upvote?.should be_false
- issue.upvotes.should == 0
+ expect(issue.notes.size).to eq(1)
+ expect(issue.notes.first.upvote?).to be_falsey
+ expect(issue.upvotes).to eq(0)
end
it "should recognize a single +1 note" do
add_note "+1 This is awesome"
- issue.upvotes.should == 1
+ expect(issue.upvotes).to eq(1)
end
- it "should recognize multiple +1 notes" do
- add_note "+1 This is awesome"
- add_note "+1 I want this"
- issue.upvotes.should == 2
+ it 'should recognize multiple +1 notes' do
+ add_note '+1 This is awesome', create(:user)
+ add_note '+1 I want this', create(:user)
+ expect(issue.upvotes).to eq(2)
+ end
+
+ it 'should not count 2 +1 votes from the same user' do
+ add_note '+1 This is awesome'
+ add_note '+1 I want this'
+ expect(issue.upvotes).to eq(1)
end
end
describe "#downvotes" do
it "with no notes has a 0/0 score" do
- issue.downvotes.should == 0
+ expect(issue.downvotes).to eq(0)
end
it "should recognize non--1 notes" do
add_note "Almost got a -1"
- issue.should have(1).note
- issue.notes.first.downvote?.should be_false
- issue.downvotes.should == 0
+ expect(issue.notes.size).to eq(1)
+ expect(issue.notes.first.downvote?).to be_falsey
+ expect(issue.downvotes).to eq(0)
end
it "should recognize a single -1 note" do
add_note "-1 This is bad"
- issue.downvotes.should == 1
+ expect(issue.downvotes).to eq(1)
end
it "should recognize multiple -1 notes" do
- add_note "-1 This is bad"
- add_note "-1 Away with this"
- issue.downvotes.should == 2
+ add_note('-1 This is bad', create(:user))
+ add_note('-1 Away with this', create(:user))
+ expect(issue.downvotes).to eq(2)
end
end
describe "#votes_count" do
it "with no notes has a 0/0 score" do
- issue.votes_count.should == 0
+ expect(issue.votes_count).to eq(0)
end
it "should recognize non notes" do
add_note "No +1 here"
- issue.should have(1).note
- issue.votes_count.should == 0
+ expect(issue.notes.size).to eq(1)
+ expect(issue.votes_count).to eq(0)
end
it "should recognize a single +1 note" do
add_note "+1 This is awesome"
- issue.votes_count.should == 1
+ expect(issue.votes_count).to eq(1)
end
it "should recognize a single -1 note" do
add_note "-1 This is bad"
- issue.votes_count.should == 1
+ expect(issue.votes_count).to eq(1)
end
it "should recognize multiple notes" do
- add_note "+1 This is awesome"
- add_note "-1 This is bad"
- add_note "+1 I want this"
- issue.votes_count.should == 3
+ add_note('+1 This is awesome', create(:user))
+ add_note('-1 This is bad', create(:user))
+ add_note('+1 I want this', create(:user))
+ expect(issue.votes_count).to eq(3)
+ end
+
+ it 'should not count 2 -1 votes from the same user' do
+ add_note '-1 This is suspicious'
+ add_note '-1 This is bad'
+ expect(issue.votes_count).to eq(1)
end
end
describe "#upvotes_in_percent" do
it "with no notes has a 0% score" do
- issue.upvotes_in_percent.should == 0
+ expect(issue.upvotes_in_percent).to eq(0)
end
it "should count a single 1 note as 100%" do
add_note "+1 This is awesome"
- issue.upvotes_in_percent.should == 100
+ expect(issue.upvotes_in_percent).to eq(100)
end
- it "should count multiple +1 notes as 100%" do
- add_note "+1 This is awesome"
- add_note "+1 I want this"
- issue.upvotes_in_percent.should == 100
+ it 'should count multiple +1 notes as 100%' do
+ add_note('+1 This is awesome', create(:user))
+ add_note('+1 I want this', create(:user))
+ expect(issue.upvotes_in_percent).to eq(100)
end
- it "should count fractions for multiple +1 and -1 notes correctly" do
- add_note "+1 This is awesome"
- add_note "+1 I want this"
- add_note "-1 This is bad"
- add_note "+1 me too"
- issue.upvotes_in_percent.should == 75
+ it 'should count fractions for multiple +1 and -1 notes correctly' do
+ add_note('+1 This is awesome', create(:user))
+ add_note('+1 I want this', create(:user))
+ add_note('-1 This is bad', create(:user))
+ add_note('+1 me too', create(:user))
+ expect(issue.upvotes_in_percent).to eq(75)
end
end
describe "#downvotes_in_percent" do
it "with no notes has a 0% score" do
- issue.downvotes_in_percent.should == 0
+ expect(issue.downvotes_in_percent).to eq(0)
end
it "should count a single -1 note as 100%" do
add_note "-1 This is bad"
- issue.downvotes_in_percent.should == 100
+ expect(issue.downvotes_in_percent).to eq(100)
end
- it "should count multiple -1 notes as 100%" do
- add_note "-1 This is bad"
- add_note "-1 Away with this"
- issue.downvotes_in_percent.should == 100
+ it 'should count multiple -1 notes as 100%' do
+ add_note('-1 This is bad', create(:user))
+ add_note('-1 Away with this', create(:user))
+ expect(issue.downvotes_in_percent).to eq(100)
end
- it "should count fractions for multiple +1 and -1 notes correctly" do
- add_note "+1 This is awesome"
- add_note "+1 I want this"
- add_note "-1 This is bad"
- add_note "+1 me too"
- issue.downvotes_in_percent.should == 25
+ it 'should count fractions for multiple +1 and -1 notes correctly' do
+ add_note('+1 This is awesome', create(:user))
+ add_note('+1 I want this', create(:user))
+ add_note('-1 This is bad', create(:user))
+ add_note('+1 me too', create(:user))
+ expect(issue.downvotes_in_percent).to eq(25)
+ end
+ end
+
+ describe '#filter_superceded_votes' do
+
+ it 'should count a users vote only once amongst multiple votes' do
+ add_note('-1 This needs work before I will accept it')
+ add_note('+1 I want this', create(:user))
+ add_note('+1 This is is awesome', create(:user))
+ add_note('+1 this looks good now')
+ add_note('+1 This is awesome', create(:user))
+ add_note('+1 me too', create(:user))
+ expect(issue.downvotes).to eq(0)
+ expect(issue.upvotes).to eq(5)
end
+
+ it 'should count each users vote only once' do
+ add_note '-1 This needs work before it will be accepted'
+ add_note '+1 I like this'
+ add_note '+1 I still like this'
+ add_note '+1 I really like this'
+ add_note '+1 Give me this now!!!!'
+ expect(issue.downvotes).to eq(0)
+ expect(issue.upvotes).to eq(1)
+ end
+
+ it 'should count a users vote only once without caring about comments' do
+ add_note '-1 This needs work before it will be accepted'
+ add_note 'Comment 1'
+ add_note 'Another comment'
+ add_note '+1 vote'
+ add_note 'final comment'
+ expect(issue.downvotes).to eq(0)
+ expect(issue.upvotes).to eq(1)
+ end
+
end
- def add_note(text)
- issue.notes << create(:note, note: text, project: issue.project)
+ def add_note(text, author = issue.author)
+ created_at = Time.now - 1.hour + Note.count.seconds
+ issue.notes << create(:note, note: text, project: issue.project,
+ author_id: author.id, created_at: created_at)
end
end