freeze + spec

This commit is contained in:
Timothy N. Tsvetkov 2011-03-17 17:47:16 +03:00
parent a655d0eb6b
commit 3b51d53225
16 changed files with 109 additions and 23 deletions

View File

@ -1,6 +1,8 @@
class PlatformsController < ApplicationController class PlatformsController < ApplicationController
before_filter :authenticate_user! before_filter :authenticate_user!
before_filter :find_platform, :only => [:freeze, :unfreeze]
def index def index
@platforms = Platform.all @platforms = Platform.all
end end
@ -26,10 +28,35 @@ class PlatformsController < ApplicationController
end end
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 def destroy
Platform.destroy params[:id] Platform.destroy params[:id]
redirect_to root_path redirect_to root_path
end end
protected
def find_platform
@platform = Platform.find params[:id]
end
end end

View File

@ -21,6 +21,10 @@ class Platform < ActiveRecord::Base
return p return p
end end
def name
released? ? "#{self[:name]} #{I18n.t("layout.platforms.released_suffix")}" : self[:name]
end
protected protected
def build_path(dir) def build_path(dir)

View File

@ -2,6 +2,13 @@
= t('layout.platforms.show') = t('layout.platforms.show')
= @platform.name = @platform.name
= link_to t('layout.platforms.back_to_the_list'), platforms_path = 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 .location
= t('layout.platforms.location') = t('layout.platforms.location')
= @platform.path = @platform.path

View File

@ -19,6 +19,11 @@ ru:
location: Расположение location: Расположение
repositories: Репозитории repositories: Репозитории
back_to_the_list: К списку платформ back_to_the_list: К списку платформ
freeze: Заморозить
unfreeze: Разморозить
confirm_freeze: Вы уверены, что хотите заморозить эту платформу?
confirm_unfreeze: Вы уверены, что хотите разморозить эту платформу?
released_suffix: (выпущена)
repositories: repositories:
new: Новый репозиторий new: Новый репозиторий
show: Репозиторий show: Репозиторий
@ -51,6 +56,10 @@ ru:
platform: platform:
saved: Платформа успешно добавлена saved: Платформа успешно добавлена
saved_error: Не удалось создать платформу saved_error: Не удалось создать платформу
freezed: Платформа успешно заморожена
freeze_error: Не удалось заморозить платформу, попробуйте еще раз
unfreezed: Платформа успешно разморожена
unfreeze_error: Не удалось разморозить платформу, попробуйте еще раз
attributes: attributes:
password: Пароль password: Пароль

View File

@ -2,6 +2,11 @@ Rosa::Application.routes.draw do
devise_for :users devise_for :users
resources :platforms do resources :platforms do
member do
get 'freeze'
get 'unfreeze'
end
resources :repositories do resources :repositories do
resources :projects do resources :projects do
resource :repo, :controller => "git/repositories", :only => [:show] resource :repo, :controller => "git/repositories", :only => [:show]

View File

@ -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

View File

@ -10,7 +10,7 @@
# #
# It's strongly recommended to check this file into your version control system. # 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| create_table "arches", :force => true do |t|
t.string "name", :null => false t.string "name", :null => false
@ -34,6 +34,7 @@ ActiveRecord::Schema.define(:version => 20110312133948) do
t.integer "parent_platform_id" t.integer "parent_platform_id"
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.boolean "released", :default => false
end end
create_table "projects", :force => true do |t| create_table "projects", :force => true do |t|

View File

@ -1,5 +1,5 @@
require 'spec_helper' require 'spec_helper'
describe GitController do #describe GitController do
#
end #end

View File

@ -0,0 +1,4 @@
Factory.define(:platform) do |p|
p.name { Factory.next(:string) }
p.unixname { Factory.next(:string) }
end

View File

@ -10,6 +10,6 @@ require 'spec_helper'
# end # end
# end # end
# end # end
describe GitHelper do #describe GitHelper do
pending "add some examples to (or delete) #{__FILE__}" # pending "add some examples to (or delete) #{__FILE__}"
end #end

View File

@ -1,5 +1,5 @@
require 'spec_helper' require 'spec_helper'
describe Arch do #describe Arch do
pending "add some examples to (or delete) #{__FILE__}" # pending "add some examples to (or delete) #{__FILE__}"
end #end

View File

@ -1,5 +1,5 @@
require 'spec_helper' require 'spec_helper'
describe Containter do #describe Containter do
pending "add some examples to (or delete) #{__FILE__}" # pending "add some examples to (or delete) #{__FILE__}"
end #end

View File

@ -1,5 +1,25 @@
require 'spec_helper' require 'spec_helper'
describe Platform do 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 end

View File

@ -1,5 +1,5 @@
require 'spec_helper' require 'spec_helper'
describe Project do #describe Project do
pending "add some examples to (or delete) #{__FILE__}" # pending "add some examples to (or delete) #{__FILE__}"
end #end

View File

@ -1,5 +1,5 @@
require 'spec_helper' require 'spec_helper'
describe Rpm do #describe Rpm do
pending "add some examples to (or delete) #{__FILE__}" # pending "add some examples to (or delete) #{__FILE__}"
end #end

View File

@ -1,5 +1,5 @@
require 'spec_helper' require 'spec_helper'
describe User do #describe User do
pending "add some examples to (or delete) #{__FILE__}" # pending "add some examples to (or delete) #{__FILE__}"
end #end