summaryrefslogtreecommitdiff
path: root/spec/lib
diff options
context:
space:
mode:
authorRiyad Preukschas <riyad@informatik.uni-bremen.de>2013-01-15 00:52:25 +0100
committerRiyad Preukschas <riyad@informatik.uni-bremen.de>2013-01-15 00:52:25 +0100
commit30227869482bbbdbfea153f2b45ef3bb9a9fd218 (patch)
treeaff64071116447092751770d2896998f62d1b44a /spec/lib
parent8ee5fce9d64b70d8981896457484fae622d142c9 (diff)
parentaca0caa8cc1a6bd481f87dd810284e69d3747050 (diff)
downloadgitlab-ce-30227869482bbbdbfea153f2b45ef3bb9a9fd218.tar.gz
Merge commit 'master' into discussions
Conflicts: app/assets/stylesheets/sections/notes.scss app/contexts/notes/load_context.rb app/models/project.rb app/observers/note_observer.rb app/roles/votes.rb app/views/commit/show.html.haml app/views/merge_requests/_show.html.haml app/views/merge_requests/diffs.js.haml app/views/merge_requests/show.js.haml app/views/notes/_note.html.haml features/steps/project/project_merge_requests.rb spec/models/note_spec.rb
Diffstat (limited to 'spec/lib')
-rw-r--r--spec/lib/extracts_path_spec.rb22
-rw-r--r--spec/lib/project_mover_spec.rb1
-rw-r--r--spec/lib/votes_spec.rb138
3 files changed, 160 insertions, 1 deletions
diff --git a/spec/lib/extracts_path_spec.rb b/spec/lib/extracts_path_spec.rb
index cf4220175a7..deb6499e008 100644
--- a/spec/lib/extracts_path_spec.rb
+++ b/spec/lib/extracts_path_spec.rb
@@ -7,7 +7,8 @@ describe ExtractsPath do
before do
@project = project
- project.stub(:ref_names).and_return(['master', 'foo/bar/baz', 'v1.0.0', 'v2.0.0'])
+ project.stub(repository: stub(ref_names: ['master', 'foo/bar/baz', 'v1.0.0', 'v2.0.0']))
+ project.stub(path_with_namespace: 'gitlab/gitlab-ci')
end
describe '#extract_ref' do
@@ -53,5 +54,24 @@ describe ExtractsPath do
extract_ref('stable/CHANGELOG').should == ['stable', 'CHANGELOG']
end
end
+
+ context "with a fullpath" do
+ it "extracts a valid branch" do
+ extract_ref('/gitlab/gitlab-ci/tree/foo/bar/baz/CHANGELOG').should == ['foo/bar/baz', 'CHANGELOG']
+ end
+
+ it "extracts a valid tag" do
+ extract_ref('/gitlab/gitlab-ci/tree/v2.0.0/CHANGELOG').should == ['v2.0.0', 'CHANGELOG']
+ end
+
+ it "extracts a valid commit SHA" do
+ extract_ref('/gitlab/gitlab-ci/tree/f4b14494ef6abf3d144c28e4af0c20143383e062/CHANGELOG').should ==
+ ['f4b14494ef6abf3d144c28e4af0c20143383e062', 'CHANGELOG']
+ end
+
+ it "extracts a timestamp" do
+ extract_ref('/gitlab/gitlab-ci/tree/v2.0.0/CHANGELOG?_=12354435').should == ['v2.0.0', 'CHANGELOG']
+ end
+ end
end
end
diff --git a/spec/lib/project_mover_spec.rb b/spec/lib/project_mover_spec.rb
index 2362bc2667b..28323b24ef6 100644
--- a/spec/lib/project_mover_spec.rb
+++ b/spec/lib/project_mover_spec.rb
@@ -5,6 +5,7 @@ describe Gitlab::ProjectMover do
before do
FileUtils.rm_rf base_path if File.exists? base_path
+ FileUtils.mkdir_p base_path
Gitlab.config.gitolite.stub(repos_path: base_path)
diff --git a/spec/lib/votes_spec.rb b/spec/lib/votes_spec.rb
new file mode 100644
index 00000000000..7e49ac781c2
--- /dev/null
+++ b/spec/lib/votes_spec.rb
@@ -0,0 +1,138 @@
+require 'spec_helper'
+
+describe Issue do
+ it { should include_module(Votes) }
+end
+
+describe MergeRequest do
+ let(:merge_request) { FactoryGirl.create(:merge_request_with_diffs) }
+
+ it { should include_module(Votes) }
+
+ describe "#upvotes" do
+ it "with no notes has a 0/0 score" do
+ merge_request.upvotes.should == 0
+ end
+
+ it "should recognize non-+1 notes" do
+ merge_request.notes << create(:note, note: "No +1 here")
+ merge_request.should have(1).note
+ merge_request.notes.first.upvote?.should be_false
+ merge_request.upvotes.should == 0
+ end
+
+ it "should recognize a single +1 note" do
+ merge_request.notes << create(:note, note: "+1 This is awesome")
+ merge_request.upvotes.should == 1
+ end
+
+ it "should recognize multiple +1 notes" do
+ merge_request.notes << create(:note, note: "+1 This is awesome")
+ merge_request.notes << create(:note, note: "+1 I want this")
+ merge_request.upvotes.should == 2
+ end
+ end
+
+ describe "#downvotes" do
+ it "with no notes has a 0/0 score" do
+ merge_request.downvotes.should == 0
+ end
+
+ it "should recognize non--1 notes" do
+ merge_request.notes << create(:note, note: "Almost got a -1")
+ merge_request.should have(1).note
+ merge_request.notes.first.downvote?.should be_false
+ merge_request.downvotes.should == 0
+ end
+
+ it "should recognize a single -1 note" do
+ merge_request.notes << create(:note, note: "-1 This is bad")
+ merge_request.downvotes.should == 1
+ end
+
+ it "should recognize multiple -1 notes" do
+ merge_request.notes << create(:note, note: "-1 This is bad")
+ merge_request.notes << create(:note, note: "-1 Away with this")
+ merge_request.downvotes.should == 2
+ end
+ end
+
+ describe "#votes_count" do
+ it "with no notes has a 0/0 score" do
+ merge_request.votes_count.should == 0
+ end
+
+ it "should recognize non notes" do
+ merge_request.notes << create(:note, note: "No +1 here")
+ merge_request.should have(1).note
+ merge_request.votes_count.should == 0
+ end
+
+ it "should recognize a single +1 note" do
+ merge_request.notes << create(:note, note: "+1 This is awesome")
+ merge_request.votes_count.should == 1
+ end
+
+ it "should recognize a single -1 note" do
+ merge_request.notes << create(:note, note: "-1 This is bad")
+ merge_request.votes_count.should == 1
+ end
+
+ it "should recognize multiple notes" do
+ merge_request.notes << create(:note, note: "+1 This is awesome")
+ merge_request.notes << create(:note, note: "-1 This is bad")
+ merge_request.notes << create(:note, note: "+1 I want this")
+ merge_request.votes_count.should == 3
+ end
+ end
+
+ describe "#upvotes_in_percent" do
+ it "with no notes has a 0% score" do
+ merge_request.upvotes_in_percent.should == 0
+ end
+
+ it "should count a single 1 note as 100%" do
+ merge_request.notes << create(:note, note: "+1 This is awesome")
+ merge_request.upvotes_in_percent.should == 100
+ end
+
+ it "should count multiple +1 notes as 100%" do
+ merge_request.notes << create(:note, note: "+1 This is awesome")
+ merge_request.notes << create(:note, note: "+1 I want this")
+ merge_request.upvotes_in_percent.should == 100
+ end
+
+ it "should count fractions for multiple +1 and -1 notes correctly" do
+ merge_request.notes << create(:note, note: "+1 This is awesome")
+ merge_request.notes << create(:note, note: "+1 I want this")
+ merge_request.notes << create(:note, note: "-1 This is bad")
+ merge_request.notes << create(:note, note: "+1 me too")
+ merge_request.upvotes_in_percent.should == 75
+ end
+ end
+
+ describe "#downvotes_in_percent" do
+ it "with no notes has a 0% score" do
+ merge_request.downvotes_in_percent.should == 0
+ end
+
+ it "should count a single -1 note as 100%" do
+ merge_request.notes << create(:note, note: "-1 This is bad")
+ merge_request.downvotes_in_percent.should == 100
+ end
+
+ it "should count multiple -1 notes as 100%" do
+ merge_request.notes << create(:note, note: "-1 This is bad")
+ merge_request.notes << create(:note, note: "-1 Away with this")
+ merge_request.downvotes_in_percent.should == 100
+ end
+
+ it "should count fractions for multiple +1 and -1 notes correctly" do
+ merge_request.notes << create(:note, note: "+1 This is awesome")
+ merge_request.notes << create(:note, note: "+1 I want this")
+ merge_request.notes << create(:note, note: "-1 This is bad")
+ merge_request.notes << create(:note, note: "+1 me too")
+ merge_request.downvotes_in_percent.should == 25
+ end
+ end
+end