summaryrefslogtreecommitdiff
path: root/spec/models
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2012-08-28 07:01:27 -0400
committerRobert Speicher <rspeicher@gmail.com>2012-08-28 21:22:49 -0400
commit77d06454ededc3beef09db709829ccb687ccc045 (patch)
treed051a03c8753fb8947fe94638120ede631b8041c /spec/models
parent0bc909405852135d7f98440193830eba664ea122 (diff)
downloadgitlab-ce-77d06454ededc3beef09db709829ccb687ccc045.tar.gz
Simple model spec changes made possible by new factories
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/issue_spec.rb37
-rw-r--r--spec/models/key_spec.rb17
-rw-r--r--spec/models/merge_request_spec.rb24
-rw-r--r--spec/models/milestone_spec.rb7
-rw-r--r--spec/models/note_spec.rb21
-rw-r--r--spec/models/user_spec.rb26
6 files changed, 37 insertions, 95 deletions
diff --git a/spec/models/issue_spec.rb b/spec/models/issue_spec.rb
index e9cbd72589a..133f073451f 100644
--- a/spec/models/issue_spec.rb
+++ b/spec/models/issue_spec.rb
@@ -19,11 +19,7 @@ describe Issue do
it { Issue.should respond_to :opened }
end
- subject { Factory.create(:issue,
- author: Factory(:user),
- assignee: Factory(:user),
- project: Factory.create(:project)) }
- it { should be_valid }
+ subject { Factory.create(:issue) }
describe '#is_being_reassigned?' do
it 'returns true if the issue assignee has changed' do
@@ -41,11 +37,7 @@ describe Issue do
subject.is_being_closed?.should be_true
end
it 'returns false if the closed attribute has changed and is now false' do
- issue = Factory.create(:issue,
- closed: true,
- author: Factory(:user),
- assignee: Factory(:user),
- project: Factory.create(:project))
+ issue = Factory.create(:closed_issue)
issue.closed = false
issue.is_being_closed?.should be_false
end
@@ -57,11 +49,7 @@ describe Issue do
describe '#is_being_reopened?' do
it 'returns true if the closed attribute has changed and is now false' do
- issue = Factory.create(:issue,
- closed: true,
- author: Factory(:user),
- assignee: Factory(:user),
- project: Factory.create(:project))
+ issue = Factory.create(:closed_issue)
issue.closed = false
issue.is_being_reopened?.should be_true
end
@@ -75,40 +63,33 @@ describe Issue do
end
describe "plus 1" do
- let(:project) { Factory(:project) }
- subject {
- Factory.create(:issue,
- author: Factory(:user),
- assignee: Factory(:user),
- project: project)
- }
+ 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", project: Factory(:project, path: 'plusone', code: 'plusone'))
+ 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", project: Factory(:project, path: 'plusone', code: 'plusone'))
+ 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", project: Factory(:project, path: 'plusone', code: 'plusone'))
- subject.notes << Factory(:note, note: "+1 I want this", project: Factory(:project, path: 'plustwo', code: 'plustwo'))
+ 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",
- project: Factory.create(:project)) }
+ let!(:issue) { Factory.create(:issue, title: "Searchable issue") }
it "matches by title" do
Issue.search('able').all.should == [issue]
diff --git a/spec/models/key_spec.rb b/spec/models/key_spec.rb
index 0f9b31778df..ea58fbd291e 100644
--- a/spec/models/key_spec.rb
+++ b/spec/models/key_spec.rb
@@ -17,20 +17,15 @@ describe Key do
context "validation of uniqueness" do
context "as a deploy key" do
- let(:project) { Factory.create(:project, path: 'alpha', code: 'alpha') }
- let(:another_project) { Factory.create(:project, path: 'beta', code: 'beta') }
-
- before do
- deploy_key = Factory.create(:key, project: project)
- end
+ let!(:deploy_key) { create(:deploy_key) }
it "does not accept the same key twice for a project" do
- key = Factory.new(:key, project: project)
+ key = build(:key, project: deploy_key.project)
key.should_not be_valid
end
it "does accept the same key for another project" do
- key = Factory.new(:key, project: another_project)
+ key = build(:key, project_id: 0)
key.should be_valid
end
end
@@ -39,12 +34,12 @@ describe Key do
let(:user) { Factory.create(:user) }
it "accepts the key once" do
- Factory.new(:key, user: user).should be_valid
+ build(:key, user: user).should be_valid
end
it "does not accepts the key twice" do
- Factory.create(:key, user: user)
- Factory.new(:key, user: user).should_not be_valid
+ create(:key, user: user)
+ build(:key, user: user).should_not be_valid
end
end
end
diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb
index c7ad08a1e06..f4b93eea966 100644
--- a/spec/models/merge_request_spec.rb
+++ b/spec/models/merge_request_spec.rb
@@ -20,46 +20,34 @@ describe MergeRequest do
it { MergeRequest.should respond_to :opened }
end
- it { Factory.create(:merge_request,
- author: Factory(:user),
- assignee: Factory(:user),
- project: Factory.create(:project)).should be_valid }
-
describe "plus 1" do
- let(:project) { Factory(:project) }
- subject {
- Factory.create(:merge_request,
- author: Factory(:user),
- assignee: Factory(:user),
- project: project)
- }
+ 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", project: Factory(:project, path: 'plusone', code: 'plusone'))
+ 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", project: Factory(:project, path: 'plusone', code: 'plusone'))
+ 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", project: Factory(:project, path: 'plusone', code: 'plusone'))
- subject.notes << Factory(:note, note: "+1 I want this", project: Factory(:project, path: 'plustwo', code: 'plustwo'))
+ 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",
- project: Factory.create(:project)) }
+ let!(:issue) { Factory.create(:issue, title: "Searchable issue") }
it "matches by title" do
Issue.search('able').all.should == [issue]
diff --git a/spec/models/milestone_spec.rb b/spec/models/milestone_spec.rb
index e9acc4e2815..ed805a243b5 100644
--- a/spec/models/milestone_spec.rb
+++ b/spec/models/milestone_spec.rb
@@ -25,11 +25,8 @@ describe Milestone do
it { should validate_presence_of(:project_id) }
end
- let(:project) { Factory :project }
- let(:milestone) { Factory :milestone, project: project }
- let(:issue) { Factory :issue, project: project }
-
- it { milestone.should be_valid }
+ let(:milestone) { Factory :milestone }
+ let(:issue) { Factory :issue }
describe "#percent_complete" do
it "should not count open issues" do
diff --git a/spec/models/note_spec.rb b/spec/models/note_spec.rb
index c97b23cb4fa..89e50479762 100644
--- a/spec/models/note_spec.rb
+++ b/spec/models/note_spec.rb
@@ -1,9 +1,6 @@
require 'spec_helper'
describe Note do
- let(:project) { Factory :project }
- let!(:commit) { project.commit }
-
describe "Associations" do
it { should belong_to(:project) }
end
@@ -13,8 +10,6 @@ describe Note do
it { should validate_presence_of(:project) }
end
- it { Factory.create(:note,
- project: project).should be_valid }
describe "Scopes" do
it "should have a today named scope that returns ..." do
Note.today.where_values.should == ["created_at >= '#{Date.today}'"]
@@ -25,26 +20,27 @@ describe Note do
let(:project) { Factory(:project) }
it "recognizes a neutral note" do
- note = Factory(:note, project: project, note: "This is not a +1 note")
+ note = Factory(:note, note: "This is not a +1 note")
note.should_not be_upvote
end
it "recognizes a +1 note" do
- note = Factory(:note, project: project, note: "+1 for this")
+ note = Factory(:note, note: "+1 for this")
note.should be_upvote
end
it "recognizes a -1 note as no vote" do
- note = Factory(:note, project: project, note: "-1 for this")
+ note = Factory(:note, note: "-1 for this")
note.should_not be_upvote
end
end
- describe "Commit notes" do
+ let(:project) { create(:project) }
+ let(:commit) { project.commit }
+ describe "Commit notes" do
before do
@note = Factory :note,
- project: project,
noteable_id: commit.id,
noteable_type: "Commit"
end
@@ -58,7 +54,6 @@ describe Note do
describe "Pre-line commit notes" do
before do
@note = Factory :note,
- project: project,
noteable_id: commit.id,
noteable_type: "Commit",
line_code: "0_16_1"
@@ -91,8 +86,8 @@ describe Note do
describe :authorization do
before do
- @p1 = project
- @p2 = Factory :project, code: "alien", path: "gitlabhq_1"
+ @p1 = create(:project)
+ @p2 = Factory :project
@u1 = Factory :user
@u2 = Factory :user
@u3 = Factory :user
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index 265dcef1e77..ebc45fa4710 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -3,11 +3,12 @@ require 'spec_helper'
describe User do
describe "Associations" do
it { should have_many(:projects) }
- it { should have_many(:users_projects) }
- it { should have_many(:issues) }
- it { should have_many(:assigned_issues) }
- it { should have_many(:merge_requests) }
- it { should have_many(:assigned_merge_requests) }
+ it { should have_many(:users_projects).dependent(:destroy) }
+ it { should have_many(:issues).dependent(:destroy) }
+ it { should have_many(:assigned_issues).dependent(:destroy) }
+ it { should have_many(:merge_requests).dependent(:destroy) }
+ it { should have_many(:assigned_merge_requests).dependent(:destroy) }
+ it { should have_many(:notes).dependent(:destroy) }
end
describe "Respond to" do
@@ -49,21 +50,6 @@ describe User do
user = Factory(:user)
user.authentication_token.should_not == ""
end
-
- describe "dependent" do
- before do
- @user = Factory :user
- @note = Factory :note,
- author: @user,
- project: Factory(:project)
- end
-
- it "should destroy all notes with user" do
- Note.find_by_id(@note.id).should_not be_nil
- @user.destroy
- Note.find_by_id(@note.id).should be_nil
- end
- end
end
# == Schema Information
#