Merge pull request #19 from warpc/platform_owner_fix

[fixed #16] Changed owner fetching in PlatformsController#create
This commit is contained in:
Vladimir Sharshov 2011-12-12 01:14:00 -08:00
commit a7a1639df7
4 changed files with 22 additions and 5 deletions

View File

@ -52,10 +52,11 @@ class PlatformsController < ApplicationController
def create def create
@platform = Platform.new params[:platform] @platform = Platform.new params[:platform]
@platform.owner = get_owner @platform.owner = (params[:admin_uname]) ? User.find_by_uname(params[:admin_uname]) : nil
@platform.owner ||= get_owner
if @platform.save! if @platform.save!
@platform.make_admin_relation(params[:admin_id]) # @platform.make_admin_relation(@platform.owner.id)
flash[:notice] = I18n.t("flash.platform.saved") flash[:notice] = I18n.t("flash.platform.saved")
redirect_to @platform redirect_to @platform
else else

View File

@ -21,8 +21,8 @@
= f.check_box :released, :class => 'check_box' = f.check_box :released, :class => 'check_box'
.group .group
= label_tag "", t("layout.platforms.admin_id"), :class => :label = label_tag "admin_uname", t("layout.platforms.admin_uname"), :class => :label
= autocomplete_field_tag 'admin_id', params[:admin_id], autocomplete_user_uname_platforms_path = autocomplete_field_tag 'admin_uname', params[:admin_uname], autocomplete_user_uname_platforms_path
=# text_field_tag 'admin_id', '', :id => 'admin_id_field' =# text_field_tag 'admin_id', '', :id => 'admin_id_field'
.group.navform.wat-cf .group.navform.wat-cf

View File

@ -94,7 +94,7 @@ ru:
confirm_delete: Вы уверены, что хотите удалить эту категорию? confirm_delete: Вы уверены, что хотите удалить эту категорию?
platforms: platforms:
admin_id: Владелец admin_uname: Владелец
build_all: Собрать все build_all: Собрать все
list: Список list: Список
new: Создать new: Создать

View File

@ -38,7 +38,13 @@ describe PlatformsController do
context 'for global admin' do context 'for global admin' do
before(:each) do before(:each) do
@admin = Factory(:admin) @admin = Factory(:admin)
@user = Factory(:user)
set_session_for(@admin) set_session_for(@admin)
any_instance_of(Platform) do |plat|
stub(plat).mount_directory_for_rsync {|args| true}
stub(plat).umount_directory_for_rsync {|args| true}
end
# any_instance_of(Platform).umount_directory_for_rsync{true}
end end
it_should_behave_like 'able_to_perform_index#platforms' it_should_behave_like 'able_to_perform_index#platforms'
@ -60,6 +66,16 @@ describe PlatformsController do
it_should_behave_like 'be_able_to_perform_destroy#platforms' it_should_behave_like 'be_able_to_perform_destroy#platforms'
it_should_behave_like 'change_objects_count_on_destroy_success' it_should_behave_like 'change_objects_count_on_destroy_success'
it_should_behave_like 'not_be_able_to_destroy_personal_platform' it_should_behave_like 'not_be_able_to_destroy_personal_platform'
context 'when owner uname present' do
it 'should create platform with mentioned owner' do
post :create, @create_params.merge({:admin_uname => @user.uname})
Platform.last.owner.id.should eql(@user.id)
end
end
end end
context 'for owner user' do context 'for owner user' do