Commit 77d06454ededc3beef09db709829ccb687ccc045

Authored by Robert Speicher
1 parent 0bc90940

Simple model spec changes made possible by new factories

spec/models/issue_spec.rb
@@ -19,11 +19,7 @@ describe Issue do @@ -19,11 +19,7 @@ describe Issue do
19 it { Issue.should respond_to :opened } 19 it { Issue.should respond_to :opened }
20 end 20 end
21 21
22 - subject { Factory.create(:issue,  
23 - author: Factory(:user),  
24 - assignee: Factory(:user),  
25 - project: Factory.create(:project)) }  
26 - it { should be_valid } 22 + subject { Factory.create(:issue) }
27 23
28 describe '#is_being_reassigned?' do 24 describe '#is_being_reassigned?' do
29 it 'returns true if the issue assignee has changed' do 25 it 'returns true if the issue assignee has changed' do
@@ -41,11 +37,7 @@ describe Issue do @@ -41,11 +37,7 @@ describe Issue do
41 subject.is_being_closed?.should be_true 37 subject.is_being_closed?.should be_true
42 end 38 end
43 it 'returns false if the closed attribute has changed and is now false' do 39 it 'returns false if the closed attribute has changed and is now false' do
44 - issue = Factory.create(:issue,  
45 - closed: true,  
46 - author: Factory(:user),  
47 - assignee: Factory(:user),  
48 - project: Factory.create(:project)) 40 + issue = Factory.create(:closed_issue)
49 issue.closed = false 41 issue.closed = false
50 issue.is_being_closed?.should be_false 42 issue.is_being_closed?.should be_false
51 end 43 end
@@ -57,11 +49,7 @@ describe Issue do @@ -57,11 +49,7 @@ describe Issue do
57 49
58 describe '#is_being_reopened?' do 50 describe '#is_being_reopened?' do
59 it 'returns true if the closed attribute has changed and is now false' do 51 it 'returns true if the closed attribute has changed and is now false' do
60 - issue = Factory.create(:issue,  
61 - closed: true,  
62 - author: Factory(:user),  
63 - assignee: Factory(:user),  
64 - project: Factory.create(:project)) 52 + issue = Factory.create(:closed_issue)
65 issue.closed = false 53 issue.closed = false
66 issue.is_being_reopened?.should be_true 54 issue.is_being_reopened?.should be_true
67 end 55 end
@@ -75,40 +63,33 @@ describe Issue do @@ -75,40 +63,33 @@ describe Issue do
75 end 63 end
76 64
77 describe "plus 1" do 65 describe "plus 1" do
78 - let(:project) { Factory(:project) }  
79 - subject {  
80 - Factory.create(:issue,  
81 - author: Factory(:user),  
82 - assignee: Factory(:user),  
83 - project: project)  
84 - } 66 + subject { Factory.create(:issue) }
85 67
86 it "with no notes has a 0/0 score" do 68 it "with no notes has a 0/0 score" do
87 subject.upvotes.should == 0 69 subject.upvotes.should == 0
88 end 70 end
89 71
90 it "should recognize non-+1 notes" do 72 it "should recognize non-+1 notes" do
91 - subject.notes << Factory(:note, note: "No +1 here", project: Factory(:project, path: 'plusone', code: 'plusone')) 73 + subject.notes << Factory(:note, note: "No +1 here")
92 subject.should have(1).note 74 subject.should have(1).note
93 subject.notes.first.upvote?.should be_false 75 subject.notes.first.upvote?.should be_false
94 subject.upvotes.should == 0 76 subject.upvotes.should == 0
95 end 77 end
96 78
97 it "should recognize a single +1 note" do 79 it "should recognize a single +1 note" do
98 - subject.notes << Factory(:note, note: "+1 This is awesome", project: Factory(:project, path: 'plusone', code: 'plusone')) 80 + subject.notes << Factory(:note, note: "+1 This is awesome")
99 subject.upvotes.should == 1 81 subject.upvotes.should == 1
100 end 82 end
101 83
102 it "should recognize a multiple +1 notes" do 84 it "should recognize a multiple +1 notes" do
103 - subject.notes << Factory(:note, note: "+1 This is awesome", project: Factory(:project, path: 'plusone', code: 'plusone'))  
104 - subject.notes << Factory(:note, note: "+1 I want this", project: Factory(:project, path: 'plustwo', code: 'plustwo')) 85 + subject.notes << Factory(:note, note: "+1 This is awesome")
  86 + subject.notes << Factory(:note, note: "+1 I want this")
105 subject.upvotes.should == 2 87 subject.upvotes.should == 2
106 end 88 end
107 end 89 end
108 90
109 describe ".search" do 91 describe ".search" do
110 - let!(:issue) { Factory.create(:issue, title: "Searchable issue",  
111 - project: Factory.create(:project)) } 92 + let!(:issue) { Factory.create(:issue, title: "Searchable issue") }
112 93
113 it "matches by title" do 94 it "matches by title" do
114 Issue.search('able').all.should == [issue] 95 Issue.search('able').all.should == [issue]
spec/models/key_spec.rb
@@ -17,20 +17,15 @@ describe Key do @@ -17,20 +17,15 @@ describe Key do
17 context "validation of uniqueness" do 17 context "validation of uniqueness" do
18 18
19 context "as a deploy key" do 19 context "as a deploy key" do
20 - let(:project) { Factory.create(:project, path: 'alpha', code: 'alpha') }  
21 - let(:another_project) { Factory.create(:project, path: 'beta', code: 'beta') }  
22 -  
23 - before do  
24 - deploy_key = Factory.create(:key, project: project)  
25 - end 20 + let!(:deploy_key) { create(:deploy_key) }
26 21
27 it "does not accept the same key twice for a project" do 22 it "does not accept the same key twice for a project" do
28 - key = Factory.new(:key, project: project) 23 + key = build(:key, project: deploy_key.project)
29 key.should_not be_valid 24 key.should_not be_valid
30 end 25 end
31 26
32 it "does accept the same key for another project" do 27 it "does accept the same key for another project" do
33 - key = Factory.new(:key, project: another_project) 28 + key = build(:key, project_id: 0)
34 key.should be_valid 29 key.should be_valid
35 end 30 end
36 end 31 end
@@ -39,12 +34,12 @@ describe Key do @@ -39,12 +34,12 @@ describe Key do
39 let(:user) { Factory.create(:user) } 34 let(:user) { Factory.create(:user) }
40 35
41 it "accepts the key once" do 36 it "accepts the key once" do
42 - Factory.new(:key, user: user).should be_valid 37 + build(:key, user: user).should be_valid
43 end 38 end
44 39
45 it "does not accepts the key twice" do 40 it "does not accepts the key twice" do
46 - Factory.create(:key, user: user)  
47 - Factory.new(:key, user: user).should_not be_valid 41 + create(:key, user: user)
  42 + build(:key, user: user).should_not be_valid
48 end 43 end
49 end 44 end
50 end 45 end
spec/models/merge_request_spec.rb
@@ -20,46 +20,34 @@ describe MergeRequest do @@ -20,46 +20,34 @@ describe MergeRequest do
20 it { MergeRequest.should respond_to :opened } 20 it { MergeRequest.should respond_to :opened }
21 end 21 end
22 22
23 - it { Factory.create(:merge_request,  
24 - author: Factory(:user),  
25 - assignee: Factory(:user),  
26 - project: Factory.create(:project)).should be_valid }  
27 -  
28 describe "plus 1" do 23 describe "plus 1" do
29 - let(:project) { Factory(:project) }  
30 - subject {  
31 - Factory.create(:merge_request,  
32 - author: Factory(:user),  
33 - assignee: Factory(:user),  
34 - project: project)  
35 - } 24 + subject { Factory.create(:merge_request) }
36 25
37 it "with no notes has a 0/0 score" do 26 it "with no notes has a 0/0 score" do
38 subject.upvotes.should == 0 27 subject.upvotes.should == 0
39 end 28 end
40 29
41 it "should recognize non-+1 notes" do 30 it "should recognize non-+1 notes" do
42 - subject.notes << Factory(:note, note: "No +1 here", project: Factory(:project, path: 'plusone', code: 'plusone')) 31 + subject.notes << Factory(:note, note: "No +1 here")
43 subject.should have(1).note 32 subject.should have(1).note
44 subject.notes.first.upvote?.should be_false 33 subject.notes.first.upvote?.should be_false
45 subject.upvotes.should == 0 34 subject.upvotes.should == 0
46 end 35 end
47 36
48 it "should recognize a single +1 note" do 37 it "should recognize a single +1 note" do
49 - subject.notes << Factory(:note, note: "+1 This is awesome", project: Factory(:project, path: 'plusone', code: 'plusone')) 38 + subject.notes << Factory(:note, note: "+1 This is awesome")
50 subject.upvotes.should == 1 39 subject.upvotes.should == 1
51 end 40 end
52 41
53 it "should recognize a multiple +1 notes" do 42 it "should recognize a multiple +1 notes" do
54 - subject.notes << Factory(:note, note: "+1 This is awesome", project: Factory(:project, path: 'plusone', code: 'plusone'))  
55 - subject.notes << Factory(:note, note: "+1 I want this", project: Factory(:project, path: 'plustwo', code: 'plustwo')) 43 + subject.notes << Factory(:note, note: "+1 This is awesome")
  44 + subject.notes << Factory(:note, note: "+1 I want this")
56 subject.upvotes.should == 2 45 subject.upvotes.should == 2
57 end 46 end
58 end 47 end
59 48
60 describe ".search" do 49 describe ".search" do
61 - let!(:issue) { Factory.create(:issue, title: "Searchable issue",  
62 - project: Factory.create(:project)) } 50 + let!(:issue) { Factory.create(:issue, title: "Searchable issue") }
63 51
64 it "matches by title" do 52 it "matches by title" do
65 Issue.search('able').all.should == [issue] 53 Issue.search('able').all.should == [issue]
spec/models/milestone_spec.rb
@@ -25,11 +25,8 @@ describe Milestone do @@ -25,11 +25,8 @@ describe Milestone do
25 it { should validate_presence_of(:project_id) } 25 it { should validate_presence_of(:project_id) }
26 end 26 end
27 27
28 - let(:project) { Factory :project }  
29 - let(:milestone) { Factory :milestone, project: project }  
30 - let(:issue) { Factory :issue, project: project }  
31 -  
32 - it { milestone.should be_valid } 28 + let(:milestone) { Factory :milestone }
  29 + let(:issue) { Factory :issue }
33 30
34 describe "#percent_complete" do 31 describe "#percent_complete" do
35 it "should not count open issues" do 32 it "should not count open issues" do
spec/models/note_spec.rb
1 require 'spec_helper' 1 require 'spec_helper'
2 2
3 describe Note do 3 describe Note do
4 - let(:project) { Factory :project }  
5 - let!(:commit) { project.commit }  
6 -  
7 describe "Associations" do 4 describe "Associations" do
8 it { should belong_to(:project) } 5 it { should belong_to(:project) }
9 end 6 end
@@ -13,8 +10,6 @@ describe Note do @@ -13,8 +10,6 @@ describe Note do
13 it { should validate_presence_of(:project) } 10 it { should validate_presence_of(:project) }
14 end 11 end
15 12
16 - it { Factory.create(:note,  
17 - project: project).should be_valid }  
18 describe "Scopes" do 13 describe "Scopes" do
19 it "should have a today named scope that returns ..." do 14 it "should have a today named scope that returns ..." do
20 Note.today.where_values.should == ["created_at >= '#{Date.today}'"] 15 Note.today.where_values.should == ["created_at >= '#{Date.today}'"]
@@ -25,26 +20,27 @@ describe Note do @@ -25,26 +20,27 @@ describe Note do
25 let(:project) { Factory(:project) } 20 let(:project) { Factory(:project) }
26 21
27 it "recognizes a neutral note" do 22 it "recognizes a neutral note" do
28 - note = Factory(:note, project: project, note: "This is not a +1 note") 23 + note = Factory(:note, note: "This is not a +1 note")
29 note.should_not be_upvote 24 note.should_not be_upvote
30 end 25 end
31 26
32 it "recognizes a +1 note" do 27 it "recognizes a +1 note" do
33 - note = Factory(:note, project: project, note: "+1 for this") 28 + note = Factory(:note, note: "+1 for this")
34 note.should be_upvote 29 note.should be_upvote
35 end 30 end
36 31
37 it "recognizes a -1 note as no vote" do 32 it "recognizes a -1 note as no vote" do
38 - note = Factory(:note, project: project, note: "-1 for this") 33 + note = Factory(:note, note: "-1 for this")
39 note.should_not be_upvote 34 note.should_not be_upvote
40 end 35 end
41 end 36 end
42 37
43 - describe "Commit notes" do 38 + let(:project) { create(:project) }
  39 + let(:commit) { project.commit }
44 40
  41 + describe "Commit notes" do
45 before do 42 before do
46 @note = Factory :note, 43 @note = Factory :note,
47 - project: project,  
48 noteable_id: commit.id, 44 noteable_id: commit.id,
49 noteable_type: "Commit" 45 noteable_type: "Commit"
50 end 46 end
@@ -58,7 +54,6 @@ describe Note do @@ -58,7 +54,6 @@ describe Note do
58 describe "Pre-line commit notes" do 54 describe "Pre-line commit notes" do
59 before do 55 before do
60 @note = Factory :note, 56 @note = Factory :note,
61 - project: project,  
62 noteable_id: commit.id, 57 noteable_id: commit.id,
63 noteable_type: "Commit", 58 noteable_type: "Commit",
64 line_code: "0_16_1" 59 line_code: "0_16_1"
@@ -91,8 +86,8 @@ describe Note do @@ -91,8 +86,8 @@ describe Note do
91 86
92 describe :authorization do 87 describe :authorization do
93 before do 88 before do
94 - @p1 = project  
95 - @p2 = Factory :project, code: "alien", path: "gitlabhq_1" 89 + @p1 = create(:project)
  90 + @p2 = Factory :project
96 @u1 = Factory :user 91 @u1 = Factory :user
97 @u2 = Factory :user 92 @u2 = Factory :user
98 @u3 = Factory :user 93 @u3 = Factory :user
spec/models/user_spec.rb
@@ -3,11 +3,12 @@ require &#39;spec_helper&#39; @@ -3,11 +3,12 @@ require &#39;spec_helper&#39;
3 describe User do 3 describe User do
4 describe "Associations" do 4 describe "Associations" do
5 it { should have_many(:projects) } 5 it { should have_many(:projects) }
6 - it { should have_many(:users_projects) }  
7 - it { should have_many(:issues) }  
8 - it { should have_many(:assigned_issues) }  
9 - it { should have_many(:merge_requests) }  
10 - it { should have_many(:assigned_merge_requests) } 6 + it { should have_many(:users_projects).dependent(:destroy) }
  7 + it { should have_many(:issues).dependent(:destroy) }
  8 + it { should have_many(:assigned_issues).dependent(:destroy) }
  9 + it { should have_many(:merge_requests).dependent(:destroy) }
  10 + it { should have_many(:assigned_merge_requests).dependent(:destroy) }
  11 + it { should have_many(:notes).dependent(:destroy) }
11 end 12 end
12 13
13 describe "Respond to" do 14 describe "Respond to" do
@@ -49,21 +50,6 @@ describe User do @@ -49,21 +50,6 @@ describe User do
49 user = Factory(:user) 50 user = Factory(:user)
50 user.authentication_token.should_not == "" 51 user.authentication_token.should_not == ""
51 end 52 end
52 -  
53 - describe "dependent" do  
54 - before do  
55 - @user = Factory :user  
56 - @note = Factory :note,  
57 - author: @user,  
58 - project: Factory(:project)  
59 - end  
60 -  
61 - it "should destroy all notes with user" do  
62 - Note.find_by_id(@note.id).should_not be_nil  
63 - @user.destroy  
64 - Note.find_by_id(@note.id).should be_nil  
65 - end  
66 - end  
67 end 53 end
68 # == Schema Information 54 # == Schema Information
69 # 55 #