[Refs #263] Refactoring product. Add tests.
This commit is contained in:
parent
b769bc1783
commit
d382732e68
|
@ -1,9 +1,6 @@
|
||||||
# -*- encoding : utf-8 -*-
|
# -*- encoding : utf-8 -*-
|
||||||
class ProductsController < ApplicationController
|
class ProductsController < ApplicationController
|
||||||
before_filter :authenticate_user!
|
before_filter :authenticate_user!
|
||||||
before_filter :find_product, :only => [:show, :edit, :update, :destroy]
|
|
||||||
before_filter :find_platform
|
|
||||||
before_filter :build_product_stub, :only => [:new, :create]
|
|
||||||
|
|
||||||
load_and_authorize_resource :platform
|
load_and_authorize_resource :platform
|
||||||
load_and_authorize_resource :product, :through => :platform
|
load_and_authorize_resource :product, :through => :platform
|
||||||
|
@ -20,24 +17,17 @@ class ProductsController < ApplicationController
|
||||||
@product.build_script = DEFAULT_BUILD
|
@product.build_script = DEFAULT_BUILD
|
||||||
end
|
end
|
||||||
|
|
||||||
# def clone
|
|
||||||
# @template = @platform.products.find(params[:id])
|
|
||||||
# @product = @platform.products.new
|
|
||||||
# @product.clone_from!(@template)
|
|
||||||
#
|
|
||||||
# render :template => "products/new"
|
|
||||||
# end
|
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@product = @platform.products.new params[:product]
|
|
||||||
if @product.save
|
if @product.save
|
||||||
flash[:notice] = t('flash.product.saved')
|
flash[:notice] = t('flash.product.saved')
|
||||||
redirect_to platform_product_path(@platform, @product)
|
redirect_to platform_product_path(@platform, @product)
|
||||||
else
|
else
|
||||||
flash[:error] = t('flash.product.save_error')
|
flash[:error] = t('flash.product.save_error')
|
||||||
|
flash[:warning] = @platform.errors.full_messages.join('. ')
|
||||||
render :action => :new
|
render :action => :new
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -45,9 +35,10 @@ class ProductsController < ApplicationController
|
||||||
def update
|
def update
|
||||||
if @product.update_attributes(params[:product])
|
if @product.update_attributes(params[:product])
|
||||||
flash[:notice] = t('flash.product.saved')
|
flash[:notice] = t('flash.product.saved')
|
||||||
redirect_to @platform
|
redirect_to platform_product_path(@platform, @product)
|
||||||
else
|
else
|
||||||
flash[:error] = t('flash.product.save_error')
|
flash[:error] = t('flash.product.save_error')
|
||||||
|
flash[:warning] = @platform.errors.full_messages.join('. ')
|
||||||
render :action => "edit"
|
render :action => "edit"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -61,17 +52,4 @@ class ProductsController < ApplicationController
|
||||||
redirect_to platform_products_path(@platform)
|
redirect_to platform_products_path(@platform)
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
|
||||||
|
|
||||||
def find_product
|
|
||||||
@product = Product.find params[:id]
|
|
||||||
end
|
|
||||||
|
|
||||||
def find_platform
|
|
||||||
@platform = Platform.find params[:platform_id]
|
|
||||||
end
|
|
||||||
|
|
||||||
def build_product_stub
|
|
||||||
@product = Product.new(:platform_id => params[:platform_id])
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,6 +15,10 @@ class Product < ActiveRecord::Base
|
||||||
|
|
||||||
scope :recent, order("name ASC")
|
scope :recent, order("name ASC")
|
||||||
|
|
||||||
|
attr_accessible :name, :counter, :ks, :menu, :tar, :cron_tab, :use_cron
|
||||||
|
attr_accessible :description, :build_script, :delete_tar
|
||||||
|
attr_readonly :platform_id
|
||||||
|
|
||||||
def delete_tar
|
def delete_tar
|
||||||
@delete_tar ||= "0"
|
@delete_tar ||= "0"
|
||||||
end
|
end
|
||||||
|
|
|
@ -37,16 +37,9 @@
|
||||||
|
|
||||||
= render :partial => "products/crontab", :locals => { :form => f }
|
= render :partial => "products/crontab", :locals => { :form => f }
|
||||||
|
|
||||||
- content_for :commented do
|
|
||||||
.leftlist= f.label :system_wide, :class => :label
|
|
||||||
.rightlist= f.check_box :system_wide, :class => 'check_box'
|
|
||||||
|
|
||||||
.both
|
.both
|
||||||
.button_block
|
.button_block
|
||||||
= submit_tag t("layout.save")
|
= submit_tag t("layout.save")
|
||||||
-#%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"), @product.new_record? ? platform_path(@platform) : platform_product_path(@platform, @product), :class => "button"
|
= link_to t("layout.cancel"), @product.new_record? ? platform_path(@platform) : platform_product_path(@platform, @product), :class => "button"
|
||||||
|
|
||||||
|
|
|
@ -10,15 +10,3 @@
|
||||||
= form_for [@platform, @product], :html => { :class => :form, :multipart => true } do |f|
|
= form_for [@platform, @product], :html => { :class => :form, :multipart => true } do |f|
|
||||||
= render :partial => "form", :locals => {:f => f}
|
= render :partial => "form", :locals => {:f => f}
|
||||||
|
|
||||||
-#.block
|
|
||||||
.secondary-navigation
|
|
||||||
%ul.wat-cf
|
|
||||||
%li.first= link_to @platform.name, platform_path(@platform) + "#products"
|
|
||||||
%li.active= link_to @product.name, edit_platform_product_path(@platform, @product)
|
|
||||||
.content
|
|
||||||
%h2.title= t("layout.products.edit_header")
|
|
||||||
.inner
|
|
||||||
= form_for [@platform, @product], :html => { :class => :form, :multipart => true } do |f|
|
|
||||||
= render :partial => "form", :locals => {:f => f}
|
|
||||||
|
|
||||||
-#- content_for :sidebar, render(:partial => 'sidebar')
|
|
||||||
|
|
|
@ -5,15 +5,3 @@
|
||||||
= form_for [@platform, @product], :html => { :class => :form, :multipart => true } do |f|
|
= form_for [@platform, @product], :html => { :class => :form, :multipart => true } do |f|
|
||||||
= render :partial => "form", :locals => {:f => f}
|
= render :partial => "form", :locals => {:f => f}
|
||||||
|
|
||||||
-#.block
|
|
||||||
.secondary-navigation
|
|
||||||
%ul.wat-cf
|
|
||||||
%li.first= link_to @platform.name, platform_path(@platform) + "#products"
|
|
||||||
%li.active= link_to t("layout.products.new"), new_platform_product_path(@platform)
|
|
||||||
.content
|
|
||||||
%h2.title= t("layout.products.new_header")
|
|
||||||
.inner
|
|
||||||
= form_for [@platform, @product], :html => { :class => :form, :multipart => true } do |f|
|
|
||||||
= render :partial => "form", :locals => {:f => f}
|
|
||||||
|
|
||||||
-#- content_for :sidebar, render(:partial => 'sidebar')
|
|
||||||
|
|
|
@ -11,8 +11,6 @@
|
||||||
= link_to image_tag("code.png", :alt => t("layout.edit")) + " " + t("layout.edit"), edit_platform_product_path(@platform, @product), :class => "button"
|
= link_to image_tag("code.png", :alt => t("layout.edit")) + " " + t("layout.edit"), edit_platform_product_path(@platform, @product), :class => "button"
|
||||||
- if can? :destroy, @product
|
- if can? :destroy, @product
|
||||||
= link_to image_tag("x.png", :alt => t("layout.delete")) + " " + t("layout.delete"), platform_product_path(@platform, @product), :method => "delete", :class => "button", :confirm => t("layout.products.confirm_delete")
|
= link_to image_tag("x.png", :alt => t("layout.delete")) + " " + t("layout.delete"), platform_product_path(@platform, @product), :method => "delete", :class => "button", :confirm => t("layout.products.confirm_delete")
|
||||||
-# if @product.can_clone?
|
|
||||||
=# link_to t("layout.products.clone"), clone_platform_product_path(@platform, @product), :class => "button"
|
|
||||||
- if can?(:create, @product.product_build_lists.build)
|
- if can?(:create, @product.product_build_lists.build)
|
||||||
= link_to t("layout.products.build"), platform_product_product_build_lists_path(@platform, @product), :class => "button", :method => 'post', :confirm => t("layout.confirm")
|
= link_to t("layout.products.build"), platform_product_product_build_lists_path(@platform, @product), :class => "button", :method => 'post', :confirm => t("layout.confirm")
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
class ClearProduct < ActiveRecord::Migration
|
||||||
|
def self.up
|
||||||
|
remove_column :products, :build_status
|
||||||
|
remove_column :products, :build_path
|
||||||
|
remove_column :products, :system_wide
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.down
|
||||||
|
add_column :products, :build_status, :integer, :default => 2, :null => false
|
||||||
|
add_column :products, :build_path, :string
|
||||||
|
add_column :products, :system_wide, :boolean, :default => false
|
||||||
|
end
|
||||||
|
end
|
|
@ -11,7 +11,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 => 20120331180541) do
|
ActiveRecord::Schema.define(:version => 20120403110931) 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
|
||||||
|
@ -215,8 +215,6 @@ ActiveRecord::Schema.define(:version => 20120331180541) do
|
||||||
create_table "products", :force => true do |t|
|
create_table "products", :force => true do |t|
|
||||||
t.string "name", :null => false
|
t.string "name", :null => false
|
||||||
t.integer "platform_id", :null => false
|
t.integer "platform_id", :null => false
|
||||||
t.integer "build_status", :default => 2, :null => false
|
|
||||||
t.string "build_path"
|
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
t.text "build_script"
|
t.text "build_script"
|
||||||
|
@ -227,7 +225,6 @@ ActiveRecord::Schema.define(:version => 20120331180541) do
|
||||||
t.string "tar_content_type"
|
t.string "tar_content_type"
|
||||||
t.integer "tar_file_size"
|
t.integer "tar_file_size"
|
||||||
t.datetime "tar_updated_at"
|
t.datetime "tar_updated_at"
|
||||||
t.boolean "system_wide", :default => false
|
|
||||||
t.text "cron_tab"
|
t.text "cron_tab"
|
||||||
t.boolean "use_cron", :default => false
|
t.boolean "use_cron", :default => false
|
||||||
t.text "description"
|
t.text "description"
|
||||||
|
|
|
@ -37,7 +37,7 @@ describe BuildListsController do
|
||||||
|
|
||||||
it 'should be able to perform create action' do
|
it 'should be able to perform create action' do
|
||||||
post :create, {:project_id => @project.id}.merge(@create_params)
|
post :create, {:project_id => @project.id}.merge(@create_params)
|
||||||
response.should redirect_to(@project)
|
response.should redirect_to project_build_lists_path(@project)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should save correct commit_hash for branch based build' do
|
it 'should save correct commit_hash for branch based build' do
|
||||||
|
|
|
@ -1,6 +1,27 @@
|
||||||
# -*- encoding : utf-8 -*-
|
# -*- encoding : utf-8 -*-
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
|
shared_examples_for 'admin user' do
|
||||||
|
|
||||||
|
it 'should be able to create product' do
|
||||||
|
lambda { post :create, @create_params }.should change{ Product.count }.by(1)
|
||||||
|
response.should redirect_to(platform_product_path( Product.last.platform.id, Product.last ))
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should be able to update product' do
|
||||||
|
put :update, {:id => @product.id}.merge(@update_params)
|
||||||
|
response.should redirect_to platform_product_path(@platform, @product)
|
||||||
|
@product.reload
|
||||||
|
@product.name.should eql('pro2')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should be able to destroy product' do
|
||||||
|
lambda { delete :destroy, :id => @product.id, :platform_id => @platform }.should change{ Product.count }.by(-1)
|
||||||
|
response.should redirect_to(platform_products_path(@platform))
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
describe ProductsController do
|
describe ProductsController do
|
||||||
before(:each) do
|
before(:each) do
|
||||||
stub_rsync_methods
|
stub_rsync_methods
|
||||||
|
@ -34,30 +55,11 @@ describe ProductsController do
|
||||||
set_session_for(@admin)
|
set_session_for(@admin)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should be able to perform create action' do
|
it_should_behave_like 'admin user'
|
||||||
post :create, @create_params
|
|
||||||
response.should redirect_to(platform_product_path( Product.last.platform.id, Product.last ))
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should change objects count on create' do
|
|
||||||
lambda { post :create, @create_params }.should change{ Product.count }.by(1)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should be able to perform update action' do
|
|
||||||
put :update, {:id => @product.id}.merge(@update_params)
|
|
||||||
response.should redirect_to(platform_path(@platform))
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should change objects count on destroy success' do
|
|
||||||
lambda { delete :destroy, :id => @product.id, :platform_id => @platform }.should change{ Product.count }.by(-1)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should be able to perform destroy action' do
|
|
||||||
delete :destroy, :platform_id => @platform.id, :id => @product.id
|
|
||||||
response.should redirect_to(platform_products_path(@platform))
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
context 'for admin relation user' do
|
context 'for admin relation user' do
|
||||||
before(:each) do
|
before(:each) do
|
||||||
@user = FactoryGirl.create(:user)
|
@user = FactoryGirl.create(:user)
|
||||||
|
@ -65,28 +67,7 @@ describe ProductsController do
|
||||||
@platform.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')
|
@platform.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should be able to perform create action' do
|
it_should_behave_like 'admin user'
|
||||||
post :create, @create_params
|
|
||||||
response.should redirect_to(platform_product_path( Product.last.platform.id, Product.last ))
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should change objects count on create' do
|
|
||||||
lambda { post :create, @create_params }.should change{ Product.count }.by(1)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should be able to perform update action' do
|
|
||||||
put :update, {:id => @product.id}.merge(@update_params)
|
|
||||||
response.should redirect_to(platform_path(@platform))
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should change objects count on destroy success' do
|
|
||||||
lambda { delete :destroy, :id => @product.id, :platform_id => @platform }.should change{ Product.count }.by(-1)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should be able to perform destroy action' do
|
|
||||||
delete :destroy, :platform_id => @platform.id, :id => @product.id
|
|
||||||
response.should redirect_to(platform_products_path(@platform))
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'for no relation user' do
|
context 'for no relation user' do
|
||||||
|
@ -95,13 +76,9 @@ describe ProductsController do
|
||||||
set_session_for(@user)
|
set_session_for(@user)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not be able to perform create action' do
|
it 'should not be able to create product' do
|
||||||
post :create, @create_params
|
|
||||||
response.should redirect_to(forbidden_path)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should not change objects count on create' do
|
|
||||||
lambda { post :create, @create_params }.should change{ Product.count }.by(0)
|
lambda { post :create, @create_params }.should change{ Product.count }.by(0)
|
||||||
|
response.should redirect_to(forbidden_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not be able to perform update action' do
|
it 'should not be able to perform update action' do
|
||||||
|
@ -109,14 +86,11 @@ describe ProductsController do
|
||||||
response.should redirect_to(forbidden_path)
|
response.should redirect_to(forbidden_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not change objects count on destroy success' do
|
it 'should not be able to destroy product' do
|
||||||
lambda { delete :destroy, :id => @product.id, :platform_id => @platform }.should change{ Product.count }.by(0)
|
lambda { delete :destroy, :id => @product.id, :platform_id => @platform }.should change{ Product.count }.by(0)
|
||||||
end
|
|
||||||
|
|
||||||
it 'should not be able to perform destroy action' do
|
|
||||||
delete :destroy, :platform_id => @platform.id, :id => @product.id
|
|
||||||
response.should redirect_to(forbidden_path)
|
response.should redirect_to(forbidden_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe ProjectsController do
|
describe ProjectsController do
|
||||||
|
|
||||||
before(:each) do
|
before(:each) do
|
||||||
stub_rsync_methods
|
stub_rsync_methods
|
||||||
|
|
||||||
|
|
|
@ -2,5 +2,33 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe Product do
|
describe Product do
|
||||||
pending "add some examples to (or delete) #{__FILE__}"
|
before(:all) do
|
||||||
|
stub_rsync_methods
|
||||||
|
Platform.delete_all
|
||||||
|
User.delete_all
|
||||||
|
Product.delete_all
|
||||||
|
FileUtils.rm_rf(APP_CONFIG['root_path'])
|
||||||
|
# Need for validate_uniqueness_of check
|
||||||
|
FactoryGirl.create(:product)
|
||||||
|
end
|
||||||
|
|
||||||
|
it { should belong_to(:platform) }
|
||||||
|
it { should have_many(:product_build_lists)}
|
||||||
|
|
||||||
|
it { should validate_presence_of(:name)}
|
||||||
|
it { should validate_uniqueness_of(:name).scoped_to(:platform_id) }
|
||||||
|
|
||||||
|
it { should have_readonly_attribute(:platform_id) }
|
||||||
|
|
||||||
|
it { should_not allow_mass_assignment_of(:platform) }
|
||||||
|
it { should_not allow_mass_assignment_of(:platform_id) }
|
||||||
|
it { should_not allow_mass_assignment_of(:product_build_lists) }
|
||||||
|
|
||||||
|
after(:all) do
|
||||||
|
Platform.delete_all
|
||||||
|
User.delete_all
|
||||||
|
Product.delete_all
|
||||||
|
FileUtils.rm_rf(APP_CONFIG['root_path'])
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
Loading…
Reference in New Issue