#111: added specs for repository and platform models

This commit is contained in:
Vokhmin Alexey V 2013-04-24 14:41:43 +04:00
parent ca02f0706f
commit 1766c821e0
3 changed files with 94 additions and 75 deletions

View File

@ -2,11 +2,10 @@
require 'spec_helper'
describe Platform do
before(:all) do
stub_symlink_methods
Platform.delete_all
User.delete_all
init_test_root
before { stub_symlink_methods }
context 'ensures that validations and associations exist' do
before do
# Need for validate_uniqueness_of check
FactoryGirl.create(:platform)
end
@ -18,8 +17,8 @@ describe Platform do
it { should validate_presence_of(:name)}
it { should validate_uniqueness_of(:name).case_insensitive }
it { should validate_format_of(:name).with('Basic_platform-name-1234') }
it { should validate_format_of(:name).not_with('.!') }
it { should allow_value('Basic_platform-name-1234').for(:name) }
it { should_not allow_value('.!').for(:name) }
it { should validate_presence_of(:description) }
it { should validate_presence_of(:distrib_type) }
it { should validate_presence_of(:visibility) }
@ -40,10 +39,12 @@ describe Platform do
it { should_not allow_mass_assignment_of(:parent) }
it {should_not allow_value("How do you do...\nmy_platform").for(:name)}
end
after(:all) do
Platform.delete_all
User.delete_all
clear_test_root
it 'ensures that folder of platform will be removed after destroy' do
platform = FactoryGirl.create(:platform)
FileUtils.mkdir_p platform.path
platform.destroy
Dir.exists?(platform.path).should be_false
end
end

View File

@ -2,26 +2,10 @@
require 'spec_helper'
describe Repository do
before { stub_symlink_methods }
context 'when create with same owner that platform' do
before (:each) do
stub_symlink_methods
@platform = FactoryGirl.create(:platform)
@params = {:name => 'tst_platform', :description => 'test platform'}
end
it 'it should increase Repository.count by 1' do
rep = Repository.create(@params) {|r| r.platform = @platform}
@platform.repositories.count.should eql(1)
end
end
before(:all) do
stub_symlink_methods
Platform.delete_all
User.delete_all
Repository.delete_all
init_test_root
context 'ensures that validations and associations exist' do
before do
# Need for validate_uniqueness_of check
FactoryGirl.create(:repository)
end
@ -32,10 +16,10 @@ describe Repository do
it { should validate_presence_of(:name) }
it { should validate_uniqueness_of(:name).case_insensitive.scoped_to(:platform_id) }
it { should validate_format_of(:name).with('basic_repository-name-1234') }
it { should validate_format_of(:name).not_with('.!') }
it { should validate_format_of(:name).not_with('Main') }
it { should validate_format_of(:name).not_with("!!\nbang_bang\n!!") }
it { should allow_value('basic_repository-name-1234').for(:name) }
it { should_not allow_value('.!').for(:name) }
it { should_not allow_value('Main').for(:name) }
it { should_not allow_value("!!\nbang_bang\n!!").for(:name) }
it { should validate_presence_of(:description) }
it { should have_readonly_attribute(:name) }
@ -44,11 +28,45 @@ describe Repository do
it { should_not allow_mass_assignment_of(:platform) }
it { should_not allow_mass_assignment_of(:platform_id) }
after(:all) do
Platform.delete_all
User.delete_all
Repository.delete_all
clear_test_root
end
context 'when create with same owner that platform' do
before do
@platform = FactoryGirl.create(:platform)
@params = {:name => 'tst_platform', :description => 'test platform'}
end
it 'it should increase Repository.count by 1' do
rep = Repository.create(@params) {|r| r.platform = @platform}
@platform.repositories.count.should eql(1)
end
end
context 'ensures that folder of repository will be removed after destroy' do
let(:arch) { FactoryGirl.create(:arch) }
let(:types) { ['SRPM', arch.name] }
it "repository of main platform" do
FactoryGirl.create(:arch)
r = FactoryGirl.create(:repository)
paths = types.
map{ |type| "#{r.platform.path}/repository/#{type}/#{r.name}" }.
each{ |path| FileUtils.mkdir_p path }
r.destroy
paths.each{ |path| Dir.exists?(path).should be_false }
end
it "repository of personal platform" do
FactoryGirl.create(:arch)
main_platform = FactoryGirl.create(:platform)
r = FactoryGirl.create(:personal_repository)
paths = types.
map{ |type| "#{r.platform.path}/repository/#{main_platform.name}/#{type}/#{r.name}" }.
each{ |path| FileUtils.mkdir_p path }
r.destroy
paths.each{ |path| Dir.exists?(path).should be_false }
end
end
end

View File

@ -28,6 +28,8 @@ RSpec.configure do |config|
config.filter_run_excluding :anonymous_access => !(APP_CONFIG['anonymous_access'])
config.before(:all) { init_test_root }
config.after(:all) { clear_test_root }
end
def set_session_for(user=nil)
@ -65,8 +67,6 @@ def stub_redis
stub(Resque).redis { @redis_instance }
end
init_test_root
def fill_project project
%x(mkdir -p #{project.path} && cp -Rf #{Rails.root}/spec/tests.git/* #{project.path}) # maybe FIXME ?
end