[issue #79] Added validation to ProjectToRepository

This commit is contained in:
George Vinogradov 2011-12-23 21:06:47 +04:00
parent 96d458875e
commit 7d8d77a386
2 changed files with 27 additions and 1 deletions

View File

@ -7,4 +7,14 @@ class ProjectToRepository < ActiveRecord::Base
after_create lambda { project.xml_rpc_create(repository) }, :unless => lambda {Thread.current[:skip]}
after_destroy lambda { project.xml_rpc_destroy(repository) }
# after_rollback lambda { project.xml_rpc_destroy(repository) rescue true if new_record? }
validate :one_project_in_platform_repositories
protected
def one_project_in_platform_repositories
c = Platform.scoped.select('projects.*').joins(:repositories => :projects).where(
:projects => {:name => project.name}, :id => repository.platform_id).count
errors.add(:project, 'should be one in platform') if c > 0
end
end

View File

@ -1,5 +1,21 @@
require 'spec_helper'
describe ProjectToRepository do
pending "add some examples to (or delete) #{__FILE__}"
# pending "add some examples to (or delete) #{__FILE__}"
before(:each) do
stub_rsync_methods
@platform = Factory(:platform)
@first_repo = Factory(:repository, :platform_id => @platform.id)
@second_repo = Factory(:repository, :platform_id => @platform.id)
@project = Factory(:project)
@first_repo.projects << @project
@first_repo.save
end
it 'should not add the same project in different repositories of same platform' do
# puts Platform.scoped.select('projects.*').joins(:repositories => :projects).where(:id => @platform.id)inspect
p2r = @second_repo.project_to_repositories.build :project_id => @project.id
p2r.should_not be_valid
end
end