From b9c0f1e3d9482645ee3a906fc1b0b07b9e8746c0 Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Sun, 11 Dec 2011 20:00:50 +0400 Subject: [PATCH 1/3] [fixed #16] Changed owner fetching in PlatformsController#create --- app/controllers/platforms_controller.rb | 3 ++- spec/controllers/platforms_controller_spec.rb | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/controllers/platforms_controller.rb b/app/controllers/platforms_controller.rb index 97cf7a97f..b485c6cfe 100644 --- a/app/controllers/platforms_controller.rb +++ b/app/controllers/platforms_controller.rb @@ -52,7 +52,8 @@ class PlatformsController < ApplicationController def create @platform = Platform.new params[:platform] - @platform.owner = get_owner + @platform.owner = (params[:admin_id]) ? User.find_by_uname(params[:admin_id]) : nil + @platform.owner ||= get_owner if @platform.save! @platform.make_admin_relation(params[:admin_id]) diff --git a/spec/controllers/platforms_controller_spec.rb b/spec/controllers/platforms_controller_spec.rb index 935f0298a..8b4b9f06e 100644 --- a/spec/controllers/platforms_controller_spec.rb +++ b/spec/controllers/platforms_controller_spec.rb @@ -38,7 +38,13 @@ describe PlatformsController do context 'for global admin' do before(:each) do @admin = Factory(:admin) + @user = Factory(:user) 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 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 'change_objects_count_on_destroy_success' 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_id => @user.uname}) + Platform.last.owner.id.should eql(@user.id) + end + + end + end context 'for owner user' do From c3f4c8dd8797ced759088b0051a90c9bb35aaced Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Sun, 11 Dec 2011 21:43:42 +0400 Subject: [PATCH 2/3] [updated #16] admin_id renamed to admin_uname. --- app/controllers/platforms_controller.rb | 4 ++-- app/views/platforms/_form.html.haml | 4 ++-- spec/controllers/platforms_controller_spec.rb | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/platforms_controller.rb b/app/controllers/platforms_controller.rb index b485c6cfe..dc9fe0bbb 100644 --- a/app/controllers/platforms_controller.rb +++ b/app/controllers/platforms_controller.rb @@ -52,11 +52,11 @@ class PlatformsController < ApplicationController def create @platform = Platform.new params[:platform] - @platform.owner = (params[:admin_id]) ? User.find_by_uname(params[:admin_id]) : nil + @platform.owner = (params[:admin_uname]) ? User.find_by_uname(params[:admin_uname]) : nil @platform.owner ||= get_owner if @platform.save! - @platform.make_admin_relation(params[:admin_id]) +# @platform.make_admin_relation(@platform.owner.id) flash[:notice] = I18n.t("flash.platform.saved") redirect_to @platform else diff --git a/app/views/platforms/_form.html.haml b/app/views/platforms/_form.html.haml index d1684ee25..2665b658f 100644 --- a/app/views/platforms/_form.html.haml +++ b/app/views/platforms/_form.html.haml @@ -21,8 +21,8 @@ = f.check_box :released, :class => 'check_box' .group - = label_tag "", t("layout.platforms.admin_id"), :class => :label - = autocomplete_field_tag 'admin_id', params[:admin_id], autocomplete_user_uname_platforms_path + = label_tag "admin_uname", t("layout.platforms.admin_id"), :class => :label + = autocomplete_field_tag 'admin_uname', params[:admin_uname], autocomplete_user_uname_platforms_path =# text_field_tag 'admin_id', '', :id => 'admin_id_field' .group.navform.wat-cf diff --git a/spec/controllers/platforms_controller_spec.rb b/spec/controllers/platforms_controller_spec.rb index 8b4b9f06e..c0ac1fb15 100644 --- a/spec/controllers/platforms_controller_spec.rb +++ b/spec/controllers/platforms_controller_spec.rb @@ -70,7 +70,7 @@ describe PlatformsController do context 'when owner uname present' do it 'should create platform with mentioned owner' do - post :create, @create_params.merge({:admin_id => @user.uname}) + post :create, @create_params.merge({:admin_uname => @user.uname}) Platform.last.owner.id.should eql(@user.id) end From 5c07046dac015a251bb66c3d5204f4c21b6dd620 Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Sun, 11 Dec 2011 22:50:55 +0400 Subject: [PATCH 3/3] [updated #16] Fixed localization fauldnames. --- app/views/platforms/_form.html.haml | 2 +- config/locales/ru.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/platforms/_form.html.haml b/app/views/platforms/_form.html.haml index 2665b658f..00b9e65a1 100644 --- a/app/views/platforms/_form.html.haml +++ b/app/views/platforms/_form.html.haml @@ -21,7 +21,7 @@ = f.check_box :released, :class => 'check_box' .group - = label_tag "admin_uname", t("layout.platforms.admin_id"), :class => :label + = label_tag "admin_uname", t("layout.platforms.admin_uname"), :class => :label = autocomplete_field_tag 'admin_uname', params[:admin_uname], autocomplete_user_uname_platforms_path =# text_field_tag 'admin_id', '', :id => 'admin_id_field' diff --git a/config/locales/ru.yml b/config/locales/ru.yml index 943cfb82a..41e02c199 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -94,7 +94,7 @@ ru: confirm_delete: Вы уверены, что хотите удалить эту категорию? platforms: - admin_id: Владелец + admin_uname: Владелец build_all: Собрать все list: Список new: Создать