Add more coverage for model validations and associations
This commit is contained in:
parent
2bdea8651f
commit
97423a0bed
12 changed files with 96 additions and 50 deletions
|
@ -2,23 +2,52 @@ require 'spec_helper'
|
|||
|
||||
describe Project do
|
||||
describe "Associations" do
|
||||
it { should belong_to(:owner).class_name('User') }
|
||||
it { should have_many(:users) }
|
||||
it { should have_many(:protected_branches).dependent(:destroy) }
|
||||
it { should have_many(:events).dependent(:destroy) }
|
||||
it { should have_many(:wikis).dependent(:destroy) }
|
||||
it { should have_many(:merge_requests).dependent(:destroy) }
|
||||
it { should have_many(:users_projects).dependent(:destroy) }
|
||||
it { should have_many(:issues).dependent(:destroy) }
|
||||
it { should have_many(:milestones).dependent(:destroy) }
|
||||
it { should have_many(:users_projects).dependent(:destroy) }
|
||||
it { should have_many(:notes).dependent(:destroy) }
|
||||
it { should have_many(:snippets).dependent(:destroy) }
|
||||
it { should have_many(:hooks).dependent(:destroy) }
|
||||
it { should have_many(:deploy_keys).dependent(:destroy) }
|
||||
it { should have_many(:hooks).dependent(:destroy) }
|
||||
it { should have_many(:wikis).dependent(:destroy) }
|
||||
it { should have_many(:protected_branches).dependent(:destroy) }
|
||||
end
|
||||
|
||||
describe "Validation" do
|
||||
let!(:project) { create(:project) }
|
||||
|
||||
it { should validate_presence_of(:name) }
|
||||
it { should validate_uniqueness_of(:name) }
|
||||
it { should ensure_length_of(:name).is_within(0..255) }
|
||||
|
||||
it { should validate_presence_of(:path) }
|
||||
it { should validate_uniqueness_of(:path) }
|
||||
it { should ensure_length_of(:path).is_within(0..255) }
|
||||
# TODO: Formats
|
||||
|
||||
it { should ensure_length_of(:description).is_within(0..2000) }
|
||||
|
||||
it { should validate_presence_of(:code) }
|
||||
it { should validate_uniqueness_of(:code) }
|
||||
it { should ensure_length_of(:code).is_within(1..255) }
|
||||
# TODO: Formats
|
||||
|
||||
it { should validate_presence_of(:owner) }
|
||||
|
||||
it "should not allow new projects beyond user limits" do
|
||||
project.stub(:owner).and_return(double(can_create_project?: false, projects_limit: 1))
|
||||
project.should_not be_valid
|
||||
project.errors[:base].first.should match(/Your own projects limit is 1/)
|
||||
end
|
||||
|
||||
it "should not allow 'gitolite-admin' as repo name" do
|
||||
should allow_value("blah").for(:path)
|
||||
should_not allow_value("gitolite-admin").for(:path)
|
||||
end
|
||||
end
|
||||
|
||||
describe "Respond to" do
|
||||
|
@ -73,9 +102,11 @@ describe Project do
|
|||
it { should respond_to(:trigger_post_receive) }
|
||||
end
|
||||
|
||||
it "should not allow 'gitolite-admin' as repo name" do
|
||||
should allow_value("blah").for(:path)
|
||||
should_not allow_value("gitolite-admin").for(:path)
|
||||
describe 'modules' do
|
||||
it { should include_module(Repository) }
|
||||
it { should include_module(PushObserver) }
|
||||
it { should include_module(Authority) }
|
||||
it { should include_module(Team) }
|
||||
end
|
||||
|
||||
it "should return valid url to repo" do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue