2012-01-30 20:39:34 +00:00
|
|
|
# -*- encoding : utf-8 -*-
|
2011-03-09 17:38:21 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2012-07-24 17:02:02 +01:00
|
|
|
describe Project do
|
2012-09-12 16:36:00 +01:00
|
|
|
before do
|
2012-07-24 17:02:02 +01:00
|
|
|
stub_symlink_methods
|
|
|
|
@root_project = FactoryGirl.create(:project)
|
|
|
|
@child_project = @root_project.fork(FactoryGirl.create(:user))
|
|
|
|
@child_child_project = @child_project.fork(FactoryGirl.create(:user))
|
|
|
|
end
|
|
|
|
|
2012-10-15 09:28:18 +01:00
|
|
|
context 'for destroy' do
|
|
|
|
let!(:root_project) { FactoryGirl.create(:project) }
|
|
|
|
let!(:child_project) { root_project.fork(FactoryGirl.create(:user)) }
|
|
|
|
let!(:child_child_project) { child_project.fork(FactoryGirl.create(:user)) }
|
|
|
|
|
|
|
|
context 'root project' do
|
|
|
|
before { root_project.destroy }
|
|
|
|
|
|
|
|
it "should not be delete child" do
|
|
|
|
Project.where(:id => child_project).count.should == 1
|
|
|
|
end
|
2012-07-24 17:02:02 +01:00
|
|
|
|
2012-10-15 09:28:18 +01:00
|
|
|
it "should not be delete child of the child" do
|
|
|
|
Project.where(:id => child_child_project).count.should == 1
|
|
|
|
end
|
2012-07-24 17:02:02 +01:00
|
|
|
end
|
|
|
|
|
2012-10-15 09:28:18 +01:00
|
|
|
pending 'when will be available :orphan_strategy => :adopt' do
|
|
|
|
context 'middle node' do
|
|
|
|
before{ child_project.destroy }
|
|
|
|
|
|
|
|
it "should set root project as a parent for orphan child" do
|
|
|
|
Project.find(child_child_project).ancestry == root_project
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should not be delete child of the child" do
|
|
|
|
Project.where(:id => child_child_project).count.should == 1
|
|
|
|
end
|
|
|
|
end
|
2012-07-24 17:02:02 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-09-12 16:36:00 +01:00
|
|
|
context 'attach personal repository' do
|
|
|
|
let(:user) { FactoryGirl.create(:user) }
|
|
|
|
it "ensures that personal repository has been attached when project had been created as package" do
|
|
|
|
project = FactoryGirl.create(:project, :owner => user, :is_package => true)
|
|
|
|
project.repositories.should == [user.personal_repository]
|
|
|
|
end
|
|
|
|
|
|
|
|
it "ensures that personal repository has not been attached when project had been created as not package" do
|
|
|
|
project = FactoryGirl.create(:project, :owner => user, :is_package => false)
|
|
|
|
project.repositories.should have(:no).items
|
|
|
|
end
|
|
|
|
|
|
|
|
it "ensures that personal repository has been attached when project had been updated as package" do
|
|
|
|
project = FactoryGirl.create(:project, :owner => user, :is_package => false)
|
|
|
|
project.update_attribute(:is_package, true)
|
|
|
|
project.repositories.should == [user.personal_repository]
|
|
|
|
end
|
|
|
|
|
|
|
|
it "ensures that personal repository has been removed from project when project had been updated as not package" do
|
|
|
|
project = FactoryGirl.create(:project, :owner => user, :is_package => true)
|
|
|
|
project.update_attribute(:is_package, false)
|
|
|
|
project.repositories.should have(:no).items
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-10-15 09:28:18 +01:00
|
|
|
context 'truncates project name before validation' do
|
|
|
|
let!(:project) { FactoryGirl.build(:project, :name => ' test_name ') }
|
2012-07-24 17:02:02 +01:00
|
|
|
|
2012-10-15 09:28:18 +01:00
|
|
|
it 'ensures that validation passed' do
|
|
|
|
project.valid?.should be_true
|
|
|
|
end
|
2012-11-07 10:20:24 +00:00
|
|
|
|
2012-10-15 09:28:18 +01:00
|
|
|
it 'ensures that name has been truncated' do
|
|
|
|
project.valid?
|
|
|
|
project.name.should == 'test_name'
|
|
|
|
end
|
|
|
|
end
|
2012-07-24 17:02:02 +01:00
|
|
|
|
2012-11-07 10:20:24 +00:00
|
|
|
context 'Validate project name' do
|
|
|
|
let!(:project) { FactoryGirl.build(:project, :name => ' test_name ') }
|
|
|
|
|
|
|
|
it "'hacked' uname should not pass" do
|
|
|
|
lambda {FactoryGirl.create(:project, :name => "...\nbeatiful_name\n for project")}.should raise_error(ActiveRecord::RecordInvalid)
|
|
|
|
end
|
|
|
|
end
|
2012-09-12 16:36:00 +01:00
|
|
|
end
|