[Refs #263] Refactoring platforms, add platform tests and software license, showing warning for errors in update project action

This commit is contained in:
Vladimir Sharshov 2012-04-01 19:19:54 +04:00
parent 0c2850b455
commit fef3affc07
20 changed files with 120 additions and 267 deletions

9
LICENSE.txt Normal file
View File

@ -0,0 +1,9 @@
ROSA ABF is Copyright 2010-2012 ROSA CJSC.
ROSA CJSC ("ROSA") distributes the ABF source code under the GNU General Public License (GPL), version 2.0 or later.
The image and icon files in ABF are copyright ROSA CJSC ("ROSA"), but unlike the source code they are not licensed under the GPL version 2.0 or later. ROSA grants you the right to use them for testing and development purposes only, but not to use them in production (commercially or non-commercially).
Third-party copyright in this distribution is noted where applicable.
All rights not expressly granted are reserved.

View File

@ -22,8 +22,6 @@ class GroupsController < ApplicationController
end end
def show def show
@platforms = @group.platforms.paginate(:page => params[:platform_page], :per_page => 10)
# @repositories = @group.repositories.paginate(:page => params[:repository_page], :per_page => 10)
@projects = @group.projects.paginate(:page => params[:project_page], :per_page => 10) @projects = @group.projects.paginate(:page => params[:project_page], :per_page => 10)
end end

View File

@ -1,10 +1,9 @@
# -*- encoding : utf-8 -*- # -*- encoding : utf-8 -*-
class PlatformsController < ApplicationController class PlatformsController < ApplicationController
before_filter :authenticate_user!
before_filter :find_platform, :only => [:clone, :edit, :destroy, :members]
before_filter :get_paths, :only => [:new, :create, :clone]
before_filter :authenticate_user!
load_and_authorize_resource load_and_authorize_resource
autocomplete :user, :uname autocomplete :user, :uname
def build_all def build_all
@ -18,13 +17,10 @@ class PlatformsController < ApplicationController
end end
def show def show
@platform = Platform.find params[:id], :include => :repositories
#@repositories = @platform.repositories
#@members = @platform.members.uniq
end end
def new def new
@platform = Platform.new
@admin_uname = current_user.uname @admin_uname = current_user.uname
@admin_id = current_user.id @admin_id = current_user.id
end end
@ -35,9 +31,9 @@ class PlatformsController < ApplicationController
end end
def create def create
@platform = Platform.new params[:platform]
@admin_id = params[:admin_id] @admin_id = params[:admin_id]
@admin_uname = params[:admin_uname] @admin_uname = params[:admin_uname]
# FIXME: do not allow manipulate owner model, only platforms onwer_id and onwer_type
@platform.owner = @admin_id.blank? ? get_owner : User.find(@admin_id) @platform.owner = @admin_id.blank? ? get_owner : User.find(@admin_id)
if @platform.save if @platform.save
@ -45,6 +41,7 @@ class PlatformsController < ApplicationController
redirect_to @platform redirect_to @platform
else else
flash[:error] = I18n.t("flash.platform.create_error") flash[:error] = I18n.t("flash.platform.create_error")
flash[:warning] = @platform.errors.full_messages.join('. ')
render :action => :new render :action => :new
end end
end end
@ -62,7 +59,8 @@ class PlatformsController < ApplicationController
redirect_to @platform redirect_to @platform
else else
flash[:error] = I18n.t("flash.platform.save_error") flash[:error] = I18n.t("flash.platform.save_error")
render :action => :new flash[:warning] = @platform.errors.full_messages.join('. ')
render :action => :edit
end end
end end
@ -127,23 +125,4 @@ class PlatformsController < ApplicationController
redirect_to members_platform_url(@platform) redirect_to members_platform_url(@platform)
end end
protected
def get_paths
if params[:user_id]
@user = User.find params[:user_id]
@platforms_path = user_platforms_path @user
@new_platform_path = new_user_platform_path @user
elsif params[:group_id]
@group = Group.find params[:group_id]
@platforms_path = group_platforms_path @group
@new_platform_path = new_group_platform_path @group
else
@platforms_path = platforms_path
@new_platform_path = new_platform_path
end
end
def find_platform
@platform = Platform.find params[:id]
end
end end

View File

@ -44,6 +44,7 @@ class ProjectsController < ApplicationController
else else
@project.save @project.save
flash[:error] = t('flash.project.save_error') flash[:error] = t('flash.project.save_error')
flash[:warning] = @project.errors.full_messages.join('. ')
render :action => :edit render :action => :edit
end end
end end

View File

@ -11,11 +11,7 @@ class RepositoriesController < ApplicationController
load_and_authorize_resource :repository, :through => :platform, :shallow => true load_and_authorize_resource :repository, :through => :platform, :shallow => true
def index def index
if params[:platform_id] @repositories = @repositories.paginate(:page => params[:page])
@repositories = Platform.find(params[:platform_id]).repositories.paginate(:page => params[:page])
else
@repositories = Repository.paginate(:page => params[:page])
end
end end
def show def show
@ -44,6 +40,7 @@ class RepositoriesController < ApplicationController
redirect_to @repositories_path redirect_to @repositories_path
else else
flash[:error] = t('flash.repository.save_error') flash[:error] = t('flash.repository.save_error')
flash[:warning] = @repository.errors.full_messages.join('. ')
render :action => :new render :action => :new
end end
end end

View File

@ -4,4 +4,10 @@ module PlatformsHelper
return "" unless platform return "" unless platform
return platform.released ? '/update' : '/release' return platform.released ? '/update' : '/release'
end end
def platfrom_printed_name(platform)
return "" unless platform
platform.released? ? "#{platform.name} #{I18n.t("layout.platforms.released_suffix")}" : platform.name
end
end end

View File

@ -8,7 +8,6 @@ class Group < ActiveRecord::Base
has_many :members, :through => :objects, :source => :object, :source_type => 'User', :autosave => true has_many :members, :through => :objects, :source => :object, :source_type => 'User', :autosave => true
has_many :projects, :through => :targets, :source => :target, :source_type => 'Project', :autosave => true has_many :projects, :through => :targets, :source => :target, :source_type => 'Project', :autosave => true
has_many :platforms, :through => :targets, :source => :target, :source_type => 'Platform', :autosave => true
has_many :own_projects, :as => :owner, :class_name => 'Project', :dependent => :destroy has_many :own_projects, :as => :owner, :class_name => 'Project', :dependent => :destroy
has_many :own_platforms, :as => :owner, :class_name => 'Platform', :dependent => :destroy has_many :own_platforms, :as => :owner, :class_name => 'Platform', :dependent => :destroy

View File

@ -12,16 +12,18 @@ class Platform < ActiveRecord::Base
has_many :relations, :as => :target, :dependent => :destroy has_many :relations, :as => :target, :dependent => :destroy
has_many :objects, :as => :target, :class_name => 'Relation', :dependent => :destroy has_many :objects, :as => :target, :class_name => 'Relation', :dependent => :destroy
has_many :members, :through => :objects, :source => :object, :source_type => 'User' has_many :members, :through => :objects, :source => :object, :source_type => 'User'
has_many :groups, :through => :objects, :source => :object, :source_type => 'Group'
validates :description, :presence => true validates :description, :presence => true
validates :visibility, :presence => true, :inclusion => {:in => VISIBILITIES}
validates :name, :uniqueness => {:case_sensitive => false}, :presence => true, :format => { :with => /^[a-zA-Z0-9_\-]+$/ } validates :name, :uniqueness => {:case_sensitive => false}, :presence => true, :format => { :with => /^[a-zA-Z0-9_\-]+$/ }
validates :distrib_type, :presence => true, :inclusion => {:in => APP_CONFIG['distr_types']} validates :distrib_type, :presence => true, :inclusion => {:in => APP_CONFIG['distr_types']}
before_create :create_directory, :if => lambda {Thread.current[:skip]} # TODO remove this when core will be ready before_create :create_directory, :if => lambda {Thread.current[:skip]} # TODO remove this when core will be ready
before_create :xml_rpc_create, :unless => lambda {Thread.current[:skip]} before_create :xml_rpc_create, :unless => lambda {Thread.current[:skip]}
before_destroy :xml_rpc_destroy before_destroy :xml_rpc_destroy
# before_update :check_freezing
after_update :freeze_platform
after_create lambda { mount_directory_for_rsync unless hidden? } after_create lambda { mount_directory_for_rsync unless hidden? }
after_destroy lambda { umount_directory_for_rsync unless hidden? } after_destroy lambda { umount_directory_for_rsync unless hidden? }
after_update :update_owner_relation after_update :update_owner_relation
@ -34,7 +36,10 @@ class Platform < ActiveRecord::Base
scope :main, where(:platform_type => 'main') scope :main, where(:platform_type => 'main')
scope :personal, where(:platform_type => 'personal') scope :personal, where(:platform_type => 'personal')
#attr_accessible :visibility attr_accessible :owner, :visibility, :description, :released #, :owner_id, :owner_type
attr_accessible :name, :distrib_type, :parent_platform_id, :platform_type
attr_readonly :name, :distrib_type, :parent_platform_id, :platform_type
include Modules::Models::Owner include Modules::Models::Owner
@ -112,10 +117,6 @@ class Platform < ActiveRecord::Base
end end
end end
def name
released? ? "#{self[:name]} #{I18n.t("layout.platforms.released_suffix")}" : self[:name]
end
def change_visibility def change_visibility
if !self.hidden? if !self.hidden?
self.update_attribute(:visibility, 'hidden') self.update_attribute(:visibility, 'hidden')
@ -204,9 +205,10 @@ class Platform < ActiveRecord::Base
end end
end end
def check_freezing def freeze_platform
if released_changed? if released_changed? && released == true
BuildServer.freeze_platform self.name result = BuildServer.freeze(name)
raise "Failed freeze platform #{name} with code #{result}" if result != BuildServer::SUCCESS
end end
end end
end end

View File

@ -7,22 +7,6 @@
- @platforms.each do |platform| - @platforms.each do |platform|
%tr{:class => cycle("odd", "even")} %tr{:class => cycle("odd", "even")}
%td %td
= link_to platform.name, platform_path(platform) = link_to platfrom_printed_name(platform), platform_path(platform)
%td %td
= platform.distrib_type = platform.distrib_type
-#%table.table
%tr
%th.first= t("activerecord.attributes.platform.name")
%th.first= t("activerecord.attributes.platform.distrib_type")
%th.last &nbsp;
- @platforms.each do |platform|
%tr{:class => cycle("odd", "even")}
%td
= link_to platform.name, platform_path(platform)
%td
= platform.distrib_type
%td.last
= link_to t("layout.show"), platform_path(platform)
|
= link_to t("layout.delete"), platform_path(platform), :method => :delete, :confirm => t("layout.platforms.confirm_delete") if can? :destroy, platform

View File

@ -1,5 +1,5 @@
- content_for :submenu do - content_for :submenu do
- act = action_name.to_sym; contr = controller_name.to_sym - act = action_name.to_sym; contr = controller_name.to_sym
.left= @platform.name .left= platfrom_printed_name(@platform)
%nav %nav
%ul %ul

View File

@ -13,33 +13,5 @@
.button_block .button_block
= submit_tag t("layout.clone") = submit_tag t("layout.clone")
-#%input.button{:type => "submit", :class => "button"}
-#= image_tag("choose.png", :alt => t("layout.save"))
-#= t("layout.clone")
%span.text_button_padding= t("layout.or") %span.text_button_padding= t("layout.or")
= link_to t("layout.cancel"), @platforms_path, :class => "button" = link_to t("layout.cancel"), platform_path(@platform), :class => "button"
-#.block
.secondary-navigation
%ul.wat-cf
%li.first= link_to "#{t("layout.platforms.list")}", @platforms_path
%li= link_to "#{t("layout.platforms.new")}", @new_platform_path
%li.active= link_to "#{t("layout.platforms.clone")}", clone_platform_path(@platfrom)
.content
%h2.title
= t("layout.platforms.clone_header")
.inner
= form_for @cloned, :url => make_clone_platform_path(@platform), :html => { :class => :form } do |f|
.group
= f.label :name, :class => :label
= f.text_field :name, :class => 'text_field'
.group
= f.label :description, :class => :label
= f.text_field :description, :class => 'text_field'
.group.navform.wat-cf
%button.button{:type => "submit"}
= image_tag("choose.png", :alt => t("layout.save"))
= t("layout.clone")
%span.text_button_padding= t("layout.or")
= link_to t("layout.cancel"), @platforms_path, :class => "text_button_padding link_button"

View File

@ -11,18 +11,3 @@
= t("layout.platforms.delete_warning") = t("layout.platforms.delete_warning")
.rightside .rightside
= link_to t("layout.delete"), platform_path(@platform), :method => :delete, :confirm => t("layout.platforms.confirm_delete"), :class => 'button' = link_to t("layout.delete"), platform_path(@platform), :method => :delete, :confirm => t("layout.platforms.confirm_delete"), :class => 'button'
.both
-#.block
.secondary-navigation
%ul.wat-cf
%li.first= link_to t("layout.platforms.list"), platforms_path
%li= link_to t("layout.platforms.new"), new_platform_path
%li.active= link_to t("layout.platforms.edit"), edit_platform_path
.content
%h2.title
= t("layout.platforms.edit_header")
.inner
= form_for @platform, :url => platform_path(@platform), :html => { :class => :form } do |f|
= render :partial => "form", :locals => {:f => f}
-# content_for :sidebar, render(:partial => 'sidebar')

View File

@ -1,3 +1,4 @@
= link_to title(t "layout.platforms.new"), new_platform_path, :class => 'button' if can? :create, Platform -set_meta_tags :title => t('layout.platforms.list_header')
= link_to t("layout.platforms.new"), new_platform_path, :class => 'button' if can? :create, Platform
= render :partial => 'platforms/list', :object => @platforms = render :partial => 'platforms/list', :object => @platforms
= will_paginate @platforms = will_paginate @platforms

View File

@ -6,11 +6,11 @@
-#.block -#.block
.secondary-navigation .secondary-navigation
%ul.wat-cf %ul.wat-cf
%li.first= link_to "#{t("layout.platforms.list")}", @platforms_path %li.first= link_to "#{t("layout.platforms.list")}", platforms_path
%li.active= link_to "#{t("layout.platforms.new")}", @new_platform_path %li.active= link_to "#{t("layout.platforms.new")}", new_platform_path
.content .content
%h2.title %h2.title
= t("layout.platforms.new_header") = t("layout.platforms.new_header")
.inner .inner
= form_for :platform, :url => @platforms_path, :html => { :class => :form } do |f| = form_for :platform, :url => platforms_path, :html => { :class => :form } do |f|
= render :partial => "form", :locals => {:f => f} = render :partial => "form", :locals => {:f => f}

View File

@ -32,127 +32,7 @@
.buttons_block .buttons_block
- if can? :build_all, @platform - if can? :build_all, @platform
= link_to t("layout.platforms.build_all"), build_all_platform_path(@platform), :confirm => I18n.t("layout.confirm"), :method => :post, :class => "button left_floated" = link_to t("layout.platforms.build_all"), build_all_platform_path(@platform), :confirm => I18n.t("layout.confirm"), :method => :post, :class => "button left_floated"
= link_to "Клонировать", clone_platform_path(@platform), :class => "button left_floated" if can? :clone, @platform = link_to I18n.t("layout.platforms.clone"), clone_platform_path(@platform), :class => "button left_floated" if can? :clone, @platform
.both
- if @platform.platform_type == 'personal' and @platform.visibility == 'open' - if @platform.platform_type == 'personal' and @platform.visibility == 'open'
= render :partial => 'connection_info' = render :partial => 'connection_info'
-#.block
.secondary-navigation
%ul.wat-cf
%li.first= link_to t("layout.platforms.list"), platforms_path
%li= link_to t("layout.platforms.new"), new_platform_path if can? :create, Platform
%li.active= link_to t("layout.platforms.show"), platform_path
%li= link_to t("layout.platforms.private_users"), platform_private_users_path(@platform)
.content
.inner
%p
%b
= t("activerecord.attributes.platform.name")
\:
= @platform.name
%p
%b
= t("activerecord.attributes.platform.description")
\:
= @platform.description
- if @platform.parent
%p
%b
= t("activerecord.attributes.platform.parent")
\:
- if @platform.parent
= link_to @platform.parent.description, platform_path(@platform.parent)
%p
%b
= t('layout.platforms.location')
\:
= @platform.path
%p
%b
= t('layout.platforms.owner')
\:
= link_to @platform.owner.try(:name), url_for(@platform.owner)
%p
%b
= t('layout.platforms.visibility')
\:
= @platform.visibility
%p
%b
= t('layout.platforms.platform_type')
\:
= @platform.platform_type
%p
%b
= t('layout.platforms.distrib_type')
\:
= @platform.distrib_type
.wat-cf
-#= link_to image_tag("code.png", :alt => t("layout.edit")) + " " + t("layout.edit"), edit_platform_path(@platform), :class => "button"
= link_to image_tag("x.png", :alt => t("layout.delete")) + " " + t("layout.delete"), platform_path(@platform), :method => "delete", :class => "button", :confirm => t("layout.platforms.confirm_delete") if can? :delete, @platform
- if @platform.released?
= link_to t("layout.platforms.unfreeze"), unfreeze_platform_path(@platform), :confirm => I18n.t("layout.platforms.confirm_unfreeze"), :method => :post, :class => "button" if can? :unfreeze, @platform
- else
= link_to t("layout.platforms.freeze"), freeze_platform_path(@platform), :confirm => I18n.t("layout.platforms.confirm_freeze"), :method => :post, :class => "button" if can? :freeze, @platform
= link_to "Клонировать", clone_platform_path(@platform), :class => "button" if can? :clone, @platform
= link_to t("layout.platforms.build_all"), build_all_platform_path(@platform), :confirm => I18n.t("layout.confirm"), :method => :post, :class => "button" if can? :build_all, @platform
= link_to t("layout.platforms.edit"), edit_platform_path(@platform), :class => "button" if can? :edit, @platform
-#%a{ :name => "repositories" }
-#.block
.secondary-navigation
%ul.wat-cf
%li.first.active= link_to t("layout.repositories.list"), platform_path(@platform) + "#repositories"
%li= link_to t("layout.repositories.new"), new_platform_repository_path(@platform) if can? :create, Repository.build_stub(@platform)
.content
%h2.title
= t("layout.repositories.list_header")
.inner
%table.table
%tr
%th.first= t("activerecord.attributes.repository.description")
%th.last &nbsp;
- @platform.repositories.recent.each do |repository|
%tr{:class => cycle("odd", "even")}
%td
= link_to repository.description, platform_repository_path(@platform, repository)
%td.last
= link_to t("layout.show"), platform_repository_path(@platform, repository)
|
= link_to t("layout.delete"), platform_repository_path(@platform, repository), :method => :delete, :confirm => t("layout.repositories.confirm_delete") if can? :destroy, @platform
.actions-bar.wat-cf
.actions
-#%a{ :name => "producs" }
-#.block
.secondary-navigation
%ul.wat-cf
%li.first.active= link_to t("layout.products.list"), platform_path(@platform) + "#products"
%li= link_to t("layout.products.new"), new_platform_product_path(@platform) if can? :create, Product.new(:platform_id => @platform.id)
.content
%h2.title
= t("layout.products.list_header")
.inner
%table.table
%tr
%th.first= t("activerecord.attributes.product.name")
%th.last &nbsp;
- @platform.products.recent.each do |product|
%tr{:class => cycle("odd", "even")}
%td
= link_to product.name, [@platform, product]
%td.last
= link_to t("layout.edit"), edit_platform_product_path(@platform, product) if can? :update, product
|
= link_to t("layout.delete"), platform_product_path(@platform, product), :method => :delete, :confirm => t("layout.products.confirm_delete") if can? :destroy, product
=# (product.can_clone? ? "| #{link_to t("layout.products.clone"), clone_platform_product_path(@platform, product)}" : "").html_safe
.actions-bar.wat-cf
.actions
-# content_for :sidebar, render(:partial => 'sidebar')

View File

@ -0,0 +1,19 @@
class CustomizePlatform < ActiveRecord::Migration
def self.up
change_column_null :platforms, :name, false
change_column_null :platforms, :distrib_type, false
change_column_null :platforms, :platform_type, false
change_column_null :platforms, :released, false
change_column_null :platforms, :visibility, false
add_index "platforms", ["name"], :unique => true, :case_sensitive => false
end
def self.down
change_column_null :platforms, :name, true
change_column_null :platforms, :distrib_type, true
change_column_null :platforms, :platform_type, true
change_column_null :platforms, :released, true
change_column_null :platforms, :visibility, true
remove_index "platforms", ["name"]
end
end

View File

@ -11,14 +11,14 @@
# #
# 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 => 20120330201229) do ActiveRecord::Schema.define(:version => 20120331180541) do
create_table "activity_feeds", :force => true do |t| create_table "activity_feeds", :force => true do |t|
t.integer "user_id", :null => false t.integer "user_id", :null => false
t.string "kind" t.string "kind"
t.text "data" t.text "data"
t.datetime "created_at", :null => false t.datetime "created_at"
t.datetime "updated_at", :null => false t.datetime "updated_at"
end end
create_table "arches", :force => true do |t| create_table "arches", :force => true do |t|
@ -179,18 +179,20 @@ ActiveRecord::Schema.define(:version => 20120330201229) do
create_table "platforms", :force => true do |t| create_table "platforms", :force => true do |t|
t.string "description" t.string "description"
t.string "name" t.string "name", :null => false
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 t.boolean "released", :default => false, :null => false
t.integer "owner_id" t.integer "owner_id"
t.string "owner_type" t.string "owner_type"
t.string "visibility", :default => "open" t.string "visibility", :default => "open", :null => false
t.string "platform_type", :default => "main" t.string "platform_type", :default => "main", :null => false
t.string "distrib_type" t.string "distrib_type", :null => false
end end
add_index "platforms", ["name"], :name => "index_platforms_on_name", :unique => true, :case_sensitive => false
create_table "private_users", :force => true do |t| create_table "private_users", :force => true do |t|
t.integer "platform_id" t.integer "platform_id"
t.string "login" t.string "login"
@ -332,16 +334,16 @@ ActiveRecord::Schema.define(:version => 20120330201229) do
t.string "name" t.string "name"
t.string "email", :default => "", :null => false t.string "email", :default => "", :null => false
t.string "encrypted_password", :limit => 128, :default => "", :null => false t.string "encrypted_password", :limit => 128, :default => "", :null => false
t.string "password_salt", :default => "", :null => false
t.string "reset_password_token" t.string "reset_password_token"
t.datetime "remember_created_at" t.datetime "remember_created_at"
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.text "ssh_key"
t.string "uname" t.string "uname"
t.string "role" t.string "role"
t.string "language", :default => "en" t.string "language", :default => "en"
t.datetime "reset_password_sent_at"
t.integer "own_projects_count", :default => 0, :null => false t.integer "own_projects_count", :default => 0, :null => false
t.datetime "reset_password_sent_at"
t.text "professional_experience" t.text "professional_experience"
t.string "site" t.string "site"
t.string "company" t.string "company"

View File

@ -9,7 +9,7 @@ module Modules
end end
def create_personal_repository def create_personal_repository
pl = platforms.build pl = own_platforms.build
pl.owner = self pl.owner = self
pl.name = "#{self.uname}_personal" pl.name = "#{self.uname}_personal"
pl.description = "#{self.uname}_personal" pl.description = "#{self.uname}_personal"

View File

@ -88,7 +88,6 @@ describe PlatformsController do
it_should_behave_like 'platform owner' it_should_behave_like 'platform owner'
it 'should create platform with mentioned owner if owner id present' do it 'should create platform with mentioned owner if owner id present' do
post :create, @create_params.merge({:admin_id => @user.id, :admin_uname => @user.uname}) post :create, @create_params.merge({:admin_id => @user.id, :admin_uname => @user.uname})
Platform.last.owner.id.should eql(@user.id) Platform.last.owner.id.should eql(@user.id)

View File

@ -2,26 +2,46 @@
require 'spec_helper' require 'spec_helper'
describe Platform do describe Platform do
before(:each) do before(:all) do
stub_rsync_methods stub_rsync_methods
Platform.delete_all Platform.delete_all
User.delete_all
FileUtils.rm_rf(APP_CONFIG['root_path'])
# Need for validate_uniqueness_of check
FactoryGirl.create(:platform)
end
it { should belong_to(:owner) }
it { should have_many(:members)}
it { should have_many(:repositories)}
it { should have_many(:products)}
it { should validate_presence_of(:name)}
it { should validate_uniqueness_of(:name).case_insensitive }
it { should validate_format_of(:name).with('Basic_platfrom-name-1234') }
it { should validate_format_of(:name).not_with('.!') }
it { should validate_presence_of(:description) }
it { should validate_presence_of(:distrib_type) }
it { should validate_presence_of(:visibility) }
Platform::VISIBILITIES.each do |value|
it {should allow_value(value).for(:visibility)}
end
it {should_not allow_value('custom_status').for(:visibility)}
it { should have_readonly_attribute(:name) }
it { should have_readonly_attribute(:distrib_type) }
it { should have_readonly_attribute(:parent_platform_id) }
it { should have_readonly_attribute(:platform_type) }
it { should_not allow_mass_assignment_of(:repositories) }
it { should_not allow_mass_assignment_of(:products) }
it { should_not allow_mass_assignment_of(:members) }
it { should_not allow_mass_assignment_of(:parent) }
after(:all) do
Platform.delete_all
User.delete_all
FileUtils.rm_rf(APP_CONFIG['root_path']) FileUtils.rm_rf(APP_CONFIG['root_path'])
end end
context 'released' do
it 'should add suffix to name when released' do
@platform = FactoryGirl.create(: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 = FactoryGirl.create(:platform, :name => 'name')
@platform.name.should == 'name'
end
end
end end