#194: added validation to Platform, new specs
This commit is contained in:
parent
a62118a11f
commit
2a2009873d
|
@ -27,6 +27,11 @@ class Platform < ActiveRecord::Base
|
||||||
errors.add(:released, I18n.t('flash.platform.released_status_can_not_be_changed'))
|
errors.add(:released, I18n.t('flash.platform.released_status_can_not_be_changed'))
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
validate lambda {
|
||||||
|
if personal? && (owner_id_changed? || owner_type_changed?)
|
||||||
|
errors.add :owner, I18n.t('flash.platform.owner_can_not_be_changed')
|
||||||
|
end
|
||||||
|
}, :on => :update
|
||||||
|
|
||||||
before_create :create_directory
|
before_create :create_directory
|
||||||
before_destroy :detele_directory
|
before_destroy :detele_directory
|
||||||
|
|
|
@ -50,6 +50,7 @@ en:
|
||||||
flash:
|
flash:
|
||||||
platform:
|
platform:
|
||||||
released_status_can_not_be_changed: Released status can't be changed if platform has been released
|
released_status_can_not_be_changed: Released status can't be changed if platform has been released
|
||||||
|
owner_can_not_be_changed: Owner of personal platform can't be changed
|
||||||
saved: Platform saved
|
saved: Platform saved
|
||||||
created: Platform created
|
created: Platform created
|
||||||
save_error: Platform save error
|
save_error: Platform save error
|
||||||
|
|
|
@ -50,6 +50,7 @@ ru:
|
||||||
flash:
|
flash:
|
||||||
platform:
|
platform:
|
||||||
released_status_can_not_be_changed: Released статус платформы не может быть изменен, если платформа уже выпущена
|
released_status_can_not_be_changed: Released статус платформы не может быть изменен, если платформа уже выпущена
|
||||||
|
owner_can_not_be_changed: Владелец персональной платформы не может быть изменен
|
||||||
saved: Платформа успешно сохранена
|
saved: Платформа успешно сохранена
|
||||||
created: Платформа успешно добавлена
|
created: Платформа успешно добавлена
|
||||||
save_error: Не удалось сохранить платформу
|
save_error: Не удалось сохранить платформу
|
||||||
|
|
|
@ -42,9 +42,30 @@ describe Platform do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'ensures that folder of platform will be removed after destroy' do
|
it 'ensures that folder of platform will be removed after destroy' do
|
||||||
platform = FactoryGirl.create(:platform)
|
platform = FactoryGirl.create :platform
|
||||||
FileUtils.mkdir_p platform.path
|
FileUtils.mkdir_p platform.path
|
||||||
platform.destroy
|
platform.destroy
|
||||||
Dir.exists?(platform.path).should be_false
|
Dir.exists?(platform.path).should be_false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'ensures that owner of personal platform can not be changed' do
|
||||||
|
platform = FactoryGirl.create :personal_platform
|
||||||
|
owner = platform.owner
|
||||||
|
platform.owner = FactoryGirl.create :user
|
||||||
|
platform.save.should be_false
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'ensures that owner of platform of group can not be changed' do
|
||||||
|
group = FactoryGirl.create :group
|
||||||
|
platform = FactoryGirl.create :personal_platform, :owner => group
|
||||||
|
platform.owner = FactoryGirl.create :user
|
||||||
|
platform.save.should be_false
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'ensures that owner of main platform can be changed' do
|
||||||
|
platform = FactoryGirl.create :platform
|
||||||
|
platform.owner = FactoryGirl.create :user
|
||||||
|
platform.save.should be_true
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue