From 3b51d532253c268637b3b05637f1bdbab126f92c Mon Sep 17 00:00:00 2001 From: "Timothy N. Tsvetkov" Date: Thu, 17 Mar 2011 17:47:16 +0300 Subject: [PATCH] freeze + spec --- app/controllers/platforms_controller.rb | 27 +++++++++++++++++++ app/models/platform.rb | 4 +++ app/views/platforms/show.html.haml | 7 +++++ config/locales/ru.yml | 9 +++++++ config/routes.rb | 5 ++++ ...0110317130503_add_released_to_platforms.rb | 9 +++++++ db/schema.rb | 3 ++- spec/controllers/git_controller_spec.rb | 6 ++--- spec/factories/platform_factory.rb | 4 +++ spec/helpers/git_helper_spec.rb | 6 ++--- spec/models/arch_spec.rb | 6 ++--- spec/models/containter_spec.rb | 6 ++--- spec/models/platform_spec.rb | 22 ++++++++++++++- spec/models/project_spec.rb | 6 ++--- spec/models/rpm_spec.rb | 6 ++--- spec/models/user_spec.rb | 6 ++--- 16 files changed, 109 insertions(+), 23 deletions(-) create mode 100644 db/migrate/20110317130503_add_released_to_platforms.rb create mode 100644 spec/factories/platform_factory.rb diff --git a/app/controllers/platforms_controller.rb b/app/controllers/platforms_controller.rb index 2882ad887..b533350d4 100644 --- a/app/controllers/platforms_controller.rb +++ b/app/controllers/platforms_controller.rb @@ -1,6 +1,8 @@ class PlatformsController < ApplicationController before_filter :authenticate_user! + before_filter :find_platform, :only => [:freeze, :unfreeze] + def index @platforms = Platform.all end @@ -26,10 +28,35 @@ class PlatformsController < ApplicationController end end + def freeze + @platform.released = true + if @platform.save + flash[:notice] = I18n.t("flash.platform.freezed") + else + flash[:notice] = I18n.t("flash.platform.freeze_error") + end + redirect_to @platform + end + + def unfreeze + @platform.released = false + if @platform.save + flash[:notice] = I18n.t("flash.platform.unfreezed") + else + flash[:notice] = I18n.t("flash.platform.unfreeze_error") + end + + redirect_to @platform + end def destroy Platform.destroy params[:id] redirect_to root_path end + + protected + def find_platform + @platform = Platform.find params[:id] + end end diff --git a/app/models/platform.rb b/app/models/platform.rb index 6b3326295..53e8dc828 100644 --- a/app/models/platform.rb +++ b/app/models/platform.rb @@ -21,6 +21,10 @@ class Platform < ActiveRecord::Base return p end + def name + released? ? "#{self[:name]} #{I18n.t("layout.platforms.released_suffix")}" : self[:name] + end + protected def build_path(dir) diff --git a/app/views/platforms/show.html.haml b/app/views/platforms/show.html.haml index fa70e4649..ea0b1523e 100644 --- a/app/views/platforms/show.html.haml +++ b/app/views/platforms/show.html.haml @@ -2,6 +2,13 @@ = t('layout.platforms.show') = @platform.name = link_to t('layout.platforms.back_to_the_list'), platforms_path + +.freeze + - if @platform.released? + = link_to I18n.t("layout.platforms.unfreeze"), unfreeze_platform_path(@platform), :confirm => I18n.t("layout.platforms.confirm_unfreeze") + - else + = link_to I18n.t("layout.platforms.freeze"), freeze_platform_path(@platform), :confirm => I18n.t("layout.platforms.confirm_freeze") + .location = t('layout.platforms.location') = @platform.path diff --git a/config/locales/ru.yml b/config/locales/ru.yml index fe9f85fa5..7a7eecf58 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -19,6 +19,11 @@ ru: location: Расположение repositories: Репозитории back_to_the_list: ⇐ К списку платформ + freeze: Заморозить + unfreeze: Разморозить + confirm_freeze: Вы уверены, что хотите заморозить эту платформу? + confirm_unfreeze: Вы уверены, что хотите разморозить эту платформу? + released_suffix: (выпущена) repositories: new: Новый репозиторий show: Репозиторий @@ -51,6 +56,10 @@ ru: platform: saved: Платформа успешно добавлена saved_error: Не удалось создать платформу + freezed: Платформа успешно заморожена + freeze_error: Не удалось заморозить платформу, попробуйте еще раз + unfreezed: Платформа успешно разморожена + unfreeze_error: Не удалось разморозить платформу, попробуйте еще раз attributes: password: Пароль diff --git a/config/routes.rb b/config/routes.rb index 22a932744..38c6abee9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,6 +2,11 @@ Rosa::Application.routes.draw do devise_for :users resources :platforms do + member do + get 'freeze' + get 'unfreeze' + end + resources :repositories do resources :projects do resource :repo, :controller => "git/repositories", :only => [:show] diff --git a/db/migrate/20110317130503_add_released_to_platforms.rb b/db/migrate/20110317130503_add_released_to_platforms.rb new file mode 100644 index 000000000..bc8346d7e --- /dev/null +++ b/db/migrate/20110317130503_add_released_to_platforms.rb @@ -0,0 +1,9 @@ +class AddReleasedToPlatforms < ActiveRecord::Migration + def self.up + add_column :platforms, :released, :boolean, :default => false + end + + def self.down + remove_column :platforms, :released + end +end diff --git a/db/schema.rb b/db/schema.rb index 85cdd3353..5682f8a97 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20110312133948) do +ActiveRecord::Schema.define(:version => 20110317130503) do create_table "arches", :force => true do |t| t.string "name", :null => false @@ -34,6 +34,7 @@ ActiveRecord::Schema.define(:version => 20110312133948) do t.integer "parent_platform_id" t.datetime "created_at" t.datetime "updated_at" + t.boolean "released", :default => false end create_table "projects", :force => true do |t| diff --git a/spec/controllers/git_controller_spec.rb b/spec/controllers/git_controller_spec.rb index 8d014fed2..d4f08fdc9 100644 --- a/spec/controllers/git_controller_spec.rb +++ b/spec/controllers/git_controller_spec.rb @@ -1,5 +1,5 @@ require 'spec_helper' -describe GitController do - -end +#describe GitController do +# +#end diff --git a/spec/factories/platform_factory.rb b/spec/factories/platform_factory.rb new file mode 100644 index 000000000..d5485013e --- /dev/null +++ b/spec/factories/platform_factory.rb @@ -0,0 +1,4 @@ +Factory.define(:platform) do |p| + p.name { Factory.next(:string) } + p.unixname { Factory.next(:string) } +end \ No newline at end of file diff --git a/spec/helpers/git_helper_spec.rb b/spec/helpers/git_helper_spec.rb index eb2e92e20..8e9bd35ee 100644 --- a/spec/helpers/git_helper_spec.rb +++ b/spec/helpers/git_helper_spec.rb @@ -10,6 +10,6 @@ require 'spec_helper' # end # end # end -describe GitHelper do - pending "add some examples to (or delete) #{__FILE__}" -end +#describe GitHelper do +# pending "add some examples to (or delete) #{__FILE__}" +#end diff --git a/spec/models/arch_spec.rb b/spec/models/arch_spec.rb index 3493766cd..9cafdfa93 100644 --- a/spec/models/arch_spec.rb +++ b/spec/models/arch_spec.rb @@ -1,5 +1,5 @@ require 'spec_helper' -describe Arch do - pending "add some examples to (or delete) #{__FILE__}" -end +#describe Arch do +# pending "add some examples to (or delete) #{__FILE__}" +#end diff --git a/spec/models/containter_spec.rb b/spec/models/containter_spec.rb index d43ba585e..a49f2d5a4 100644 --- a/spec/models/containter_spec.rb +++ b/spec/models/containter_spec.rb @@ -1,5 +1,5 @@ require 'spec_helper' -describe Containter do - pending "add some examples to (or delete) #{__FILE__}" -end +#describe Containter do +# pending "add some examples to (or delete) #{__FILE__}" +#end diff --git a/spec/models/platform_spec.rb b/spec/models/platform_spec.rb index 52468b7ae..ac691f491 100644 --- a/spec/models/platform_spec.rb +++ b/spec/models/platform_spec.rb @@ -1,5 +1,25 @@ require 'spec_helper' describe Platform do - pending "add some examples to (or delete) #{__FILE__}" + before(:each) do + Platform.delete_all + FileUtils.rm_rf(APP_CONFIG['root_path']) + end + + context 'released' do + it 'should add suffix to name when released' do + @platform = Factory(:platform) + old_name = @platform.name + + @platform.released = true + @platform.save + + @platform.name.should == "#{old_name} #{I18n.t("layout.platforms.released_suffix")}" + end + + it 'should not add suffix to name when not released' do + @platform = Factory(:platform, :name => 'name') + @platform.name.should == 'name' + end + end end diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 9bda4d927..b8b2fd9a1 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -1,5 +1,5 @@ require 'spec_helper' -describe Project do - pending "add some examples to (or delete) #{__FILE__}" -end +#describe Project do +# pending "add some examples to (or delete) #{__FILE__}" +#end diff --git a/spec/models/rpm_spec.rb b/spec/models/rpm_spec.rb index 078804244..956151566 100644 --- a/spec/models/rpm_spec.rb +++ b/spec/models/rpm_spec.rb @@ -1,5 +1,5 @@ require 'spec_helper' -describe Rpm do - pending "add some examples to (or delete) #{__FILE__}" -end +#describe Rpm do +# pending "add some examples to (or delete) #{__FILE__}" +#end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 44032b484..adb8d8920 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -1,5 +1,5 @@ require 'spec_helper' -describe User do - pending "add some examples to (or delete) #{__FILE__}" -end +#describe User do +# pending "add some examples to (or delete) #{__FILE__}" +#end