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 19 it { Issue.should respond_to :opened }
20 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 24 describe '#is_being_reassigned?' do
29 25 it 'returns true if the issue assignee has changed' do
... ... @@ -41,11 +37,7 @@ describe Issue do
41 37 subject.is_being_closed?.should be_true
42 38 end
43 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 41 issue.closed = false
50 42 issue.is_being_closed?.should be_false
51 43 end
... ... @@ -57,11 +49,7 @@ describe Issue do
57 49  
58 50 describe '#is_being_reopened?' do
59 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 53 issue.closed = false
66 54 issue.is_being_reopened?.should be_true
67 55 end
... ... @@ -75,40 +63,33 @@ describe Issue do
75 63 end
76 64  
77 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 68 it "with no notes has a 0/0 score" do
87 69 subject.upvotes.should == 0
88 70 end
89 71  
90 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 74 subject.should have(1).note
93 75 subject.notes.first.upvote?.should be_false
94 76 subject.upvotes.should == 0
95 77 end
96 78  
97 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 81 subject.upvotes.should == 1
100 82 end
101 83  
102 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 87 subject.upvotes.should == 2
106 88 end
107 89 end
108 90  
109 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 94 it "matches by title" do
114 95 Issue.search('able').all.should == [issue]
... ...
spec/models/key_spec.rb
... ... @@ -17,20 +17,15 @@ describe Key do
17 17 context "validation of uniqueness" do
18 18  
19 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 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 24 key.should_not be_valid
30 25 end
31 26  
32 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 29 key.should be_valid
35 30 end
36 31 end
... ... @@ -39,12 +34,12 @@ describe Key do
39 34 let(:user) { Factory.create(:user) }
40 35  
41 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 38 end
44 39  
45 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 43 end
49 44 end
50 45 end
... ...
spec/models/merge_request_spec.rb
... ... @@ -20,46 +20,34 @@ describe MergeRequest do
20 20 it { MergeRequest.should respond_to :opened }
21 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 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 26 it "with no notes has a 0/0 score" do
38 27 subject.upvotes.should == 0
39 28 end
40 29  
41 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 32 subject.should have(1).note
44 33 subject.notes.first.upvote?.should be_false
45 34 subject.upvotes.should == 0
46 35 end
47 36  
48 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 39 subject.upvotes.should == 1
51 40 end
52 41  
53 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 45 subject.upvotes.should == 2
57 46 end
58 47 end
59 48  
60 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 52 it "matches by title" do
65 53 Issue.search('able').all.should == [issue]
... ...
spec/models/milestone_spec.rb
... ... @@ -25,11 +25,8 @@ describe Milestone do
25 25 it { should validate_presence_of(:project_id) }
26 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 31 describe "#percent_complete" do
35 32 it "should not count open issues" do
... ...
spec/models/note_spec.rb
1 1 require 'spec_helper'
2 2  
3 3 describe Note do
4   - let(:project) { Factory :project }
5   - let!(:commit) { project.commit }
6   -
7 4 describe "Associations" do
8 5 it { should belong_to(:project) }
9 6 end
... ... @@ -13,8 +10,6 @@ describe Note do
13 10 it { should validate_presence_of(:project) }
14 11 end
15 12  
16   - it { Factory.create(:note,
17   - project: project).should be_valid }
18 13 describe "Scopes" do
19 14 it "should have a today named scope that returns ..." do
20 15 Note.today.where_values.should == ["created_at >= '#{Date.today}'"]
... ... @@ -25,26 +20,27 @@ describe Note do
25 20 let(:project) { Factory(:project) }
26 21  
27 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 24 note.should_not be_upvote
30 25 end
31 26  
32 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 29 note.should be_upvote
35 30 end
36 31  
37 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 34 note.should_not be_upvote
40 35 end
41 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 42 before do
46 43 @note = Factory :note,
47   - project: project,
48 44 noteable_id: commit.id,
49 45 noteable_type: "Commit"
50 46 end
... ... @@ -58,7 +54,6 @@ describe Note do
58 54 describe "Pre-line commit notes" do
59 55 before do
60 56 @note = Factory :note,
61   - project: project,
62 57 noteable_id: commit.id,
63 58 noteable_type: "Commit",
64 59 line_code: "0_16_1"
... ... @@ -91,8 +86,8 @@ describe Note do
91 86  
92 87 describe :authorization do
93 88 before do
94   - @p1 = project
95   - @p2 = Factory :project, code: "alien", path: "gitlabhq_1"
  89 + @p1 = create(:project)
  90 + @p2 = Factory :project
96 91 @u1 = Factory :user
97 92 @u2 = Factory :user
98 93 @u3 = Factory :user
... ...
spec/models/user_spec.rb
... ... @@ -3,11 +3,12 @@ require &#39;spec_helper&#39;
3 3 describe User do
4 4 describe "Associations" do
5 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 12 end
12 13  
13 14 describe "Respond to" do
... ... @@ -49,21 +50,6 @@ describe User do
49 50 user = Factory(:user)
50 51 user.authentication_token.should_not == ""
51 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 53 end
68 54 # == Schema Information
69 55 #
... ...