diff --git a/app/models/platform.rb b/app/models/platform.rb index 6d14ff1e5..a3b69ca62 100644 --- a/app/models/platform.rb +++ b/app/models/platform.rb @@ -27,6 +27,11 @@ class Platform < ActiveRecord::Base errors.add(:released, I18n.t('flash.platform.released_status_can_not_be_changed')) 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_destroy :detele_directory diff --git a/config/locales/models/platform.en.yml b/config/locales/models/platform.en.yml index b834312d1..dfc0c9a4a 100644 --- a/config/locales/models/platform.en.yml +++ b/config/locales/models/platform.en.yml @@ -50,6 +50,7 @@ en: flash: platform: 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 created: Platform created save_error: Platform save error diff --git a/config/locales/models/platform.ru.yml b/config/locales/models/platform.ru.yml index a59233458..cfac8681b 100644 --- a/config/locales/models/platform.ru.yml +++ b/config/locales/models/platform.ru.yml @@ -50,6 +50,7 @@ ru: flash: platform: released_status_can_not_be_changed: Released статус платформы не может быть изменен, если платформа уже выпущена + owner_can_not_be_changed: Владелец персональной платформы не может быть изменен saved: Платформа успешно сохранена created: Платформа успешно добавлена save_error: Не удалось сохранить платформу diff --git a/spec/models/platform_spec.rb b/spec/models/platform_spec.rb index 13ec8a3de..355bd5df5 100644 --- a/spec/models/platform_spec.rb +++ b/spec/models/platform_spec.rb @@ -42,9 +42,30 @@ describe Platform do end 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 platform.destroy Dir.exists?(platform.path).should be_false 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