Simple model spec changes made possible by new factories
This commit is contained in:
parent
0bc9094058
commit
77d06454ed
6 changed files with 37 additions and 95 deletions
|
@ -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]
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
#
|
||||
|
|
Loading…
Add table
Reference in a new issue