Commit 9d4d40deed5ea649511f3aadd45b3da68c7c3217
1 parent
14daf2e2
Exists in
master
and in
4 other branches
Move IssueCommonality and Upvote specs out of models and into their own specs
Showing
4 changed files
with
104 additions
and
66 deletions
Show diff stats
spec/models/issue_spec.rb
@@ -19,6 +19,11 @@ describe Issue do | @@ -19,6 +19,11 @@ describe Issue do | ||
19 | it { Issue.should respond_to :opened } | 19 | it { Issue.should respond_to :opened } |
20 | end | 20 | end |
21 | 21 | ||
22 | + describe 'modules' do | ||
23 | + it { should include_module(IssueCommonality) } | ||
24 | + it { should include_module(Upvote) } | ||
25 | + end | ||
26 | + | ||
22 | subject { Factory.create(:issue) } | 27 | subject { Factory.create(:issue) } |
23 | 28 | ||
24 | describe '#is_being_reassigned?' do | 29 | describe '#is_being_reassigned?' do |
@@ -61,40 +66,6 @@ describe Issue do | @@ -61,40 +66,6 @@ describe Issue do | ||
61 | subject.is_being_reopened?.should be_false | 66 | subject.is_being_reopened?.should be_false |
62 | end | 67 | end |
63 | end | 68 | end |
64 | - | ||
65 | - describe "plus 1" do | ||
66 | - subject { Factory.create(:issue) } | ||
67 | - | ||
68 | - it "with no notes has a 0/0 score" do | ||
69 | - subject.upvotes.should == 0 | ||
70 | - end | ||
71 | - | ||
72 | - it "should recognize non-+1 notes" do | ||
73 | - subject.notes << Factory(:note, note: "No +1 here") | ||
74 | - subject.should have(1).note | ||
75 | - subject.notes.first.upvote?.should be_false | ||
76 | - subject.upvotes.should == 0 | ||
77 | - end | ||
78 | - | ||
79 | - it "should recognize a single +1 note" do | ||
80 | - subject.notes << Factory(:note, note: "+1 This is awesome") | ||
81 | - subject.upvotes.should == 1 | ||
82 | - end | ||
83 | - | ||
84 | - it "should recognize a multiple +1 notes" do | ||
85 | - subject.notes << Factory(:note, note: "+1 This is awesome") | ||
86 | - subject.notes << Factory(:note, note: "+1 I want this") | ||
87 | - subject.upvotes.should == 2 | ||
88 | - end | ||
89 | - end | ||
90 | - | ||
91 | - describe ".search" do | ||
92 | - let!(:issue) { Factory.create(:issue, title: "Searchable issue") } | ||
93 | - | ||
94 | - it "matches by title" do | ||
95 | - Issue.search('able').all.should == [issue] | ||
96 | - end | ||
97 | - end | ||
98 | end | 69 | end |
99 | # == Schema Information | 70 | # == Schema Information |
100 | # | 71 | # |
spec/models/merge_request_spec.rb
@@ -20,38 +20,9 @@ describe MergeRequest do | @@ -20,38 +20,9 @@ describe MergeRequest do | ||
20 | it { MergeRequest.should respond_to :opened } | 20 | it { MergeRequest.should respond_to :opened } |
21 | end | 21 | end |
22 | 22 | ||
23 | - describe "plus 1" do | ||
24 | - subject { Factory.create(:merge_request) } | ||
25 | - | ||
26 | - it "with no notes has a 0/0 score" do | ||
27 | - subject.upvotes.should == 0 | ||
28 | - end | ||
29 | - | ||
30 | - it "should recognize non-+1 notes" do | ||
31 | - subject.notes << Factory(:note, note: "No +1 here") | ||
32 | - subject.should have(1).note | ||
33 | - subject.notes.first.upvote?.should be_false | ||
34 | - subject.upvotes.should == 0 | ||
35 | - end | ||
36 | - | ||
37 | - it "should recognize a single +1 note" do | ||
38 | - subject.notes << Factory(:note, note: "+1 This is awesome") | ||
39 | - subject.upvotes.should == 1 | ||
40 | - end | ||
41 | - | ||
42 | - it "should recognize a multiple +1 notes" do | ||
43 | - subject.notes << Factory(:note, note: "+1 This is awesome") | ||
44 | - subject.notes << Factory(:note, note: "+1 I want this") | ||
45 | - subject.upvotes.should == 2 | ||
46 | - end | ||
47 | - end | ||
48 | - | ||
49 | - describe ".search" do | ||
50 | - let!(:issue) { Factory.create(:issue, title: "Searchable issue") } | ||
51 | - | ||
52 | - it "matches by title" do | ||
53 | - Issue.search('able').all.should == [issue] | ||
54 | - end | 23 | + describe 'modules' do |
24 | + it { should include_module(IssueCommonality) } | ||
25 | + it { should include_module(Upvote) } | ||
55 | end | 26 | end |
56 | end | 27 | end |
57 | # == Schema Information | 28 | # == Schema Information |
@@ -0,0 +1,69 @@ | @@ -0,0 +1,69 @@ | ||
1 | +require 'spec_helper' | ||
2 | + | ||
3 | +describe Issue, "IssueCommonality" do | ||
4 | + let(:issue) { create(:issue) } | ||
5 | + | ||
6 | + describe "Associations" do | ||
7 | + it { should belong_to(:project) } | ||
8 | + it { should belong_to(:author) } | ||
9 | + it { should belong_to(:assignee) } | ||
10 | + it { should have_many(:notes).dependent(:destroy) } | ||
11 | + end | ||
12 | + | ||
13 | + describe "Validation" do | ||
14 | + it { should validate_presence_of(:project_id) } | ||
15 | + it { should validate_presence_of(:author_id) } | ||
16 | + it { should validate_presence_of(:title) } | ||
17 | + it { should ensure_length_of(:title).is_at_least(0).is_at_most(255) } | ||
18 | + end | ||
19 | + | ||
20 | + describe "Scope" do | ||
21 | + it { described_class.should respond_to(:opened) } | ||
22 | + it { described_class.should respond_to(:closed) } | ||
23 | + it { described_class.should respond_to(:assigned) } | ||
24 | + end | ||
25 | + | ||
26 | + it "has an :author_id_of_changes accessor" do | ||
27 | + issue.should respond_to(:author_id_of_changes) | ||
28 | + issue.should respond_to(:author_id_of_changes=) | ||
29 | + end | ||
30 | + | ||
31 | + describe ".search" do | ||
32 | + let!(:searchable_issue) { create(:issue, title: "Searchable issue") } | ||
33 | + | ||
34 | + it "matches by title" do | ||
35 | + described_class.search('able').all.should == [searchable_issue] | ||
36 | + end | ||
37 | + end | ||
38 | + | ||
39 | + describe "#today?" do | ||
40 | + it "returns true when created today" do | ||
41 | + # Avoid timezone differences and just return exactly what we want | ||
42 | + Date.stub(:today).and_return(issue.created_at.to_date) | ||
43 | + issue.today?.should be_true | ||
44 | + end | ||
45 | + | ||
46 | + it "returns false when not created today" do | ||
47 | + Date.stub(:today).and_return(Date.yesterday) | ||
48 | + issue.today?.should be_false | ||
49 | + end | ||
50 | + end | ||
51 | + | ||
52 | + describe "#new?" do | ||
53 | + it "returns true when created today and record hasn't been updated" do | ||
54 | + issue.stub(:today?).and_return(true) | ||
55 | + issue.new?.should be_true | ||
56 | + end | ||
57 | + | ||
58 | + it "returns false when not created today" do | ||
59 | + issue.stub(:today?).and_return(false) | ||
60 | + issue.new?.should be_false | ||
61 | + end | ||
62 | + | ||
63 | + it "returns false when record has been updated" do | ||
64 | + issue.stub(:today?).and_return(true) | ||
65 | + issue.touch | ||
66 | + issue.new?.should be_false | ||
67 | + end | ||
68 | + end | ||
69 | +end |
@@ -0,0 +1,27 @@ | @@ -0,0 +1,27 @@ | ||
1 | +require 'spec_helper' | ||
2 | + | ||
3 | +describe Issue, "Upvote" do | ||
4 | + let(:issue) { create(:issue) } | ||
5 | + | ||
6 | + it "with no notes has a 0/0 score" do | ||
7 | + issue.upvotes.should == 0 | ||
8 | + end | ||
9 | + | ||
10 | + it "should recognize non-+1 notes" do | ||
11 | + issue.notes << create(:note, note: "No +1 here") | ||
12 | + issue.should have(1).note | ||
13 | + issue.notes.first.upvote?.should be_false | ||
14 | + issue.upvotes.should == 0 | ||
15 | + end | ||
16 | + | ||
17 | + it "should recognize a single +1 note" do | ||
18 | + issue.notes << create(:note, note: "+1 This is awesome") | ||
19 | + issue.upvotes.should == 1 | ||
20 | + end | ||
21 | + | ||
22 | + it "should recognize multiple +1 notes" do | ||
23 | + issue.notes << create(:note, note: "+1 This is awesome") | ||
24 | + issue.notes << create(:note, note: "+1 I want this") | ||
25 | + issue.upvotes.should == 2 | ||
26 | + end | ||
27 | +end |