summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2012-08-29 01:52:19 -0400
committerRobert Speicher <rspeicher@gmail.com>2012-08-29 10:44:34 -0400
commit9d4d40deed5ea649511f3aadd45b3da68c7c3217 (patch)
treed885f66649ac9b5b7c892dccf11cf476133b7c8f
parent14daf2e2ba9d75527b5de07d87a9027bd53d607e (diff)
downloadgitlab-ce-9d4d40deed5ea649511f3aadd45b3da68c7c3217.tar.gz
Move IssueCommonality and Upvote specs out of models and into their own specs
-rw-r--r--spec/models/issue_spec.rb39
-rw-r--r--spec/models/merge_request_spec.rb35
-rw-r--r--spec/roles/issue_commonality_spec.rb69
-rw-r--r--spec/roles/upvote_spec.rb27
4 files changed, 104 insertions, 66 deletions
diff --git a/spec/models/issue_spec.rb b/spec/models/issue_spec.rb
index 133f073451f..a03405b5959 100644
--- a/spec/models/issue_spec.rb
+++ b/spec/models/issue_spec.rb
@@ -19,6 +19,11 @@ describe Issue do
it { Issue.should respond_to :opened }
end
+ describe 'modules' do
+ it { should include_module(IssueCommonality) }
+ it { should include_module(Upvote) }
+ end
+
subject { Factory.create(:issue) }
describe '#is_being_reassigned?' do
@@ -61,40 +66,6 @@ describe Issue do
subject.is_being_reopened?.should be_false
end
end
-
- describe "plus 1" do
- subject { Factory.create(:issue) }
-
- it "with no notes has a 0/0 score" do
- subject.upvotes.should == 0
- end
-
- it "should recognize non-+1 notes" do
- subject.notes << Factory(:note, note: "No +1 here")
- subject.should have(1).note
- subject.notes.first.upvote?.should be_false
- subject.upvotes.should == 0
- end
-
- it "should recognize a single +1 note" do
- subject.notes << Factory(:note, note: "+1 This is awesome")
- subject.upvotes.should == 1
- end
-
- it "should recognize a multiple +1 notes" do
- subject.notes << Factory(:note, note: "+1 This is awesome")
- subject.notes << Factory(:note, note: "+1 I want this")
- subject.upvotes.should == 2
- end
- end
-
- describe ".search" do
- let!(:issue) { Factory.create(:issue, title: "Searchable issue") }
-
- it "matches by title" do
- Issue.search('able').all.should == [issue]
- end
- end
end
# == Schema Information
#
diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb
index f4b93eea966..10f0a01fcda 100644
--- a/spec/models/merge_request_spec.rb
+++ b/spec/models/merge_request_spec.rb
@@ -20,38 +20,9 @@ describe MergeRequest do
it { MergeRequest.should respond_to :opened }
end
- describe "plus 1" do
- subject { Factory.create(:merge_request) }
-
- it "with no notes has a 0/0 score" do
- subject.upvotes.should == 0
- end
-
- it "should recognize non-+1 notes" do
- subject.notes << Factory(:note, note: "No +1 here")
- subject.should have(1).note
- subject.notes.first.upvote?.should be_false
- subject.upvotes.should == 0
- end
-
- it "should recognize a single +1 note" do
- subject.notes << Factory(:note, note: "+1 This is awesome")
- subject.upvotes.should == 1
- end
-
- it "should recognize a multiple +1 notes" do
- subject.notes << Factory(:note, note: "+1 This is awesome")
- subject.notes << Factory(:note, note: "+1 I want this")
- subject.upvotes.should == 2
- end
- end
-
- describe ".search" do
- let!(:issue) { Factory.create(:issue, title: "Searchable issue") }
-
- it "matches by title" do
- Issue.search('able').all.should == [issue]
- end
+ describe 'modules' do
+ it { should include_module(IssueCommonality) }
+ it { should include_module(Upvote) }
end
end
# == Schema Information
diff --git a/spec/roles/issue_commonality_spec.rb b/spec/roles/issue_commonality_spec.rb
new file mode 100644
index 00000000000..77b98b46ed9
--- /dev/null
+++ b/spec/roles/issue_commonality_spec.rb
@@ -0,0 +1,69 @@
+require 'spec_helper'
+
+describe Issue, "IssueCommonality" do
+ let(:issue) { create(:issue) }
+
+ describe "Associations" do
+ it { should belong_to(:project) }
+ it { should belong_to(:author) }
+ it { should belong_to(:assignee) }
+ it { should have_many(:notes).dependent(:destroy) }
+ end
+
+ describe "Validation" do
+ it { should validate_presence_of(:project_id) }
+ it { should validate_presence_of(:author_id) }
+ it { should validate_presence_of(:title) }
+ it { should ensure_length_of(:title).is_at_least(0).is_at_most(255) }
+ end
+
+ describe "Scope" do
+ it { described_class.should respond_to(:opened) }
+ it { described_class.should respond_to(:closed) }
+ it { described_class.should respond_to(:assigned) }
+ end
+
+ it "has an :author_id_of_changes accessor" do
+ issue.should respond_to(:author_id_of_changes)
+ issue.should respond_to(:author_id_of_changes=)
+ end
+
+ describe ".search" do
+ let!(:searchable_issue) { create(:issue, title: "Searchable issue") }
+
+ it "matches by title" do
+ described_class.search('able').all.should == [searchable_issue]
+ end
+ end
+
+ describe "#today?" do
+ it "returns true when created today" do
+ # Avoid timezone differences and just return exactly what we want
+ Date.stub(:today).and_return(issue.created_at.to_date)
+ issue.today?.should be_true
+ end
+
+ it "returns false when not created today" do
+ Date.stub(:today).and_return(Date.yesterday)
+ issue.today?.should be_false
+ end
+ end
+
+ describe "#new?" do
+ it "returns true when created today and record hasn't been updated" do
+ issue.stub(:today?).and_return(true)
+ issue.new?.should be_true
+ end
+
+ it "returns false when not created today" do
+ issue.stub(:today?).and_return(false)
+ issue.new?.should be_false
+ end
+
+ it "returns false when record has been updated" do
+ issue.stub(:today?).and_return(true)
+ issue.touch
+ issue.new?.should be_false
+ end
+ end
+end
diff --git a/spec/roles/upvote_spec.rb b/spec/roles/upvote_spec.rb
new file mode 100644
index 00000000000..24288ada0fe
--- /dev/null
+++ b/spec/roles/upvote_spec.rb
@@ -0,0 +1,27 @@
+require 'spec_helper'
+
+describe Issue, "Upvote" do
+ let(:issue) { create(:issue) }
+
+ it "with no notes has a 0/0 score" do
+ issue.upvotes.should == 0
+ end
+
+ it "should recognize non-+1 notes" do
+ issue.notes << create(:note, 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
+ issue.notes << create(:note, note: "+1 This is awesome")
+ issue.upvotes.should == 1
+ end
+
+ it "should recognize multiple +1 notes" do
+ issue.notes << create(:note, note: "+1 This is awesome")
+ issue.notes << create(:note, note: "+1 I want this")
+ issue.upvotes.should == 2
+ end
+end