summaryrefslogtreecommitdiff
path: root/spec/lib
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-04-10 23:28:42 +0300
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-04-10 23:28:42 +0300
commit001f3bc59ef34752b98ab405fde2520b15eff51c (patch)
tree80a74c103fe12efdd374219c01fb113f4e1baede /spec/lib
parent0ae892007dac045e58cab793806f778b90ce6c2e (diff)
downloadgitlab-ce-001f3bc59ef34752b98ab405fde2520b15eff51c.tar.gz
Specs refactoring to reduce test time. Disabled observers by default for specs
Diffstat (limited to 'spec/lib')
-rw-r--r--spec/lib/votes_spec.rb116
1 files changed, 60 insertions, 56 deletions
diff --git a/spec/lib/votes_spec.rb b/spec/lib/votes_spec.rb
index b49ed15b5c3..a3c353d5eab 100644
--- a/spec/lib/votes_spec.rb
+++ b/spec/lib/votes_spec.rb
@@ -1,132 +1,136 @@
require 'spec_helper'
-describe MergeRequest do
- let(:merge_request) { FactoryGirl.create(:merge_request_with_diffs) }
+describe Issue, 'Votes' do
+ let(:issue) { create(:issue) }
describe "#upvotes" do
it "with no notes has a 0/0 score" do
- merge_request.upvotes.should == 0
+ issue.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
+ add_note "No +1 here"
+ issue.should have(1).note
+ issue.notes.first.upvote?.should be_false
+ issue.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
+ add_note "+1 This is awesome"
+ issue.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
+ add_note "+1 This is awesome"
+ add_note "+1 I want this"
+ issue.upvotes.should == 2
end
end
describe "#downvotes" do
it "with no notes has a 0/0 score" do
- merge_request.downvotes.should == 0
+ issue.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
+ add_note "Almost got a -1"
+ issue.should have(1).note
+ issue.notes.first.downvote?.should be_false
+ issue.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
+ add_note "-1 This is bad"
+ issue.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
+ add_note "-1 This is bad"
+ add_note "-1 Away with this"
+ issue.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
+ issue.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
+ add_note "No +1 here"
+ issue.should have(1).note
+ issue.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
+ add_note "+1 This is awesome"
+ issue.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
+ add_note "-1 This is bad"
+ issue.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
+ add_note "+1 This is awesome"
+ add_note "-1 This is bad"
+ add_note "+1 I want this"
+ issue.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
+ issue.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
+ add_note "+1 This is awesome"
+ issue.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
+ add_note "+1 This is awesome"
+ add_note "+1 I want this"
+ issue.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
+ 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
end
end
describe "#downvotes_in_percent" do
it "with no notes has a 0% score" do
- merge_request.downvotes_in_percent.should == 0
+ issue.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
+ add_note "-1 This is bad"
+ issue.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
+ add_note "-1 This is bad"
+ add_note "-1 Away with this"
+ issue.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
+ 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
end
end
+
+ def add_note(text)
+ issue.notes << create(:note, note: text, project: issue.project)
+ end
end