From 1766c821e03ed0fb9ffa6bb8c134ed9bb9de440b Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Wed, 24 Apr 2013 14:41:43 +0400 Subject: [PATCH] #111: added specs for repository and platform models --- spec/models/platform_spec.rb | 83 +++++++++++++++++----------------- spec/models/repository_spec.rb | 82 ++++++++++++++++++++------------- spec/spec_helper.rb | 4 +- 3 files changed, 94 insertions(+), 75 deletions(-) diff --git a/spec/models/platform_spec.rb b/spec/models/platform_spec.rb index 20b1c9d2e..13ec8a3de 100644 --- a/spec/models/platform_spec.rb +++ b/spec/models/platform_spec.rb @@ -2,48 +2,49 @@ require 'spec_helper' describe Platform do - before(:all) do - stub_symlink_methods - Platform.delete_all - User.delete_all - init_test_root - # Need for validate_uniqueness_of check - FactoryGirl.create(:platform) + before { stub_symlink_methods } + + context 'ensures that validations and associations exist' do + before do + # Need for validate_uniqueness_of check + FactoryGirl.create(:platform) + end + + it { should belong_to(:owner) } + it { should have_many(:members)} + it { should have_many(:repositories)} + it { should have_many(:products)} + + it { should validate_presence_of(:name)} + it { should validate_uniqueness_of(:name).case_insensitive } + 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) } + + Platform::VISIBILITIES.each do |value| + it {should allow_value(value).for(:visibility)} + end + it {should_not allow_value('custom_status').for(:visibility)} + + it { should have_readonly_attribute(:name) } + it { should have_readonly_attribute(:distrib_type) } + it { should have_readonly_attribute(:parent_platform_id) } + it { should have_readonly_attribute(:platform_type) } + + it { should_not allow_mass_assignment_of(:repositories) } + it { should_not allow_mass_assignment_of(:products) } + it { should_not allow_mass_assignment_of(:members) } + it { should_not allow_mass_assignment_of(:parent) } + + it {should_not allow_value("How do you do...\nmy_platform").for(:name)} end - it { should belong_to(:owner) } - it { should have_many(:members)} - it { should have_many(:repositories)} - it { should have_many(:products)} - - 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 validate_presence_of(:description) } - it { should validate_presence_of(:distrib_type) } - it { should validate_presence_of(:visibility) } - - Platform::VISIBILITIES.each do |value| - it {should allow_value(value).for(:visibility)} - end - it {should_not allow_value('custom_status').for(:visibility)} - - it { should have_readonly_attribute(:name) } - it { should have_readonly_attribute(:distrib_type) } - it { should have_readonly_attribute(:parent_platform_id) } - it { should have_readonly_attribute(:platform_type) } - - it { should_not allow_mass_assignment_of(:repositories) } - it { should_not allow_mass_assignment_of(:products) } - it { should_not allow_mass_assignment_of(:members) } - it { should_not allow_mass_assignment_of(:parent) } - - it {should_not allow_value("How do you do...\nmy_platform").for(:name)} - - 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 diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index 98f1f1052..35ea72a33 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -2,10 +2,36 @@ require 'spec_helper' describe Repository do + before { stub_symlink_methods } + + context 'ensures that validations and associations exist' do + before do + # Need for validate_uniqueness_of check + FactoryGirl.create(:repository) + end + + it { should belong_to(:platform) } + it { should have_many(:project_to_repositories).validate(true) } + it { should have_many(:projects).through(:project_to_repositories) } + + it { should validate_presence_of(:name) } + it { should validate_uniqueness_of(:name).case_insensitive.scoped_to(:platform_id) } + 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) } + it { should have_readonly_attribute(:platform_id) } + + it { should_not allow_mass_assignment_of(:platform) } + it { should_not allow_mass_assignment_of(:platform_id) } + + end context 'when create with same owner that platform' do - before (:each) do - stub_symlink_methods + before do @platform = FactoryGirl.create(:platform) @params = {:name => 'tst_platform', :description => 'test platform'} end @@ -16,39 +42,31 @@ describe Repository do end end - before(:all) do - stub_symlink_methods - Platform.delete_all - User.delete_all - Repository.delete_all - init_test_root - # Need for validate_uniqueness_of check - FactoryGirl.create(:repository) - end + context 'ensures that folder of repository will be removed after destroy' do + let(:arch) { FactoryGirl.create(:arch) } + let(:types) { ['SRPM', arch.name] } - it { should belong_to(:platform) } - it { should have_many(:project_to_repositories).validate(true) } - it { should have_many(:projects).through(:project_to_repositories) } + 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 { 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 validate_presence_of(:description) } + 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 - it { should have_readonly_attribute(:name) } - it { should have_readonly_attribute(:platform_id) } - - 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 end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 6fe491877..c233dd750 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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