[Refs #263] Refactoring ProductBuildList. Add tests
This commit is contained in:
parent
f4937559a6
commit
a6ec36086c
|
@ -16,17 +16,20 @@ class ProductBuildList < ActiveRecord::Base
|
||||||
|
|
||||||
belongs_to :product
|
belongs_to :product
|
||||||
|
|
||||||
validates :product, :status, :presence => true
|
validates :product_id, :status, :presence => true
|
||||||
validates :status, :inclusion => { :in => [BUILD_STARTED, BUILD_COMPLETED, BUILD_FAILED] }
|
validates :status, :inclusion => { :in => [BUILD_STARTED, BUILD_COMPLETED, BUILD_FAILED] }
|
||||||
|
|
||||||
|
attr_accessor :base_url
|
||||||
|
attr_accessible :status, :notified_at, :base_url
|
||||||
|
attr_readonly :product_id
|
||||||
|
|
||||||
|
|
||||||
scope :default_order, order('notified_at DESC')
|
scope :default_order, order('notified_at DESC')
|
||||||
scope :for_status, lambda {|status| where(:status => status) }
|
scope :for_status, lambda {|status| where(:status => status) }
|
||||||
scope :for_user, lambda { |user| where(:user_id => user.id) }
|
scope :for_user, lambda { |user| where(:user_id => user.id) }
|
||||||
scope :scoped_to_product_name, lambda {|product_name| joins(:product).where('products.name LIKE ?', "%#{product_name}%")}
|
scope :scoped_to_product_name, lambda {|product_name| joins(:product).where('products.name LIKE ?', "%#{product_name}%")}
|
||||||
scope :recent, order("#{table_name}.updated_at DESC")
|
scope :recent, order("#{table_name}.updated_at DESC")
|
||||||
|
|
||||||
attr_accessor :base_url
|
|
||||||
|
|
||||||
after_create :xml_rpc_create
|
after_create :xml_rpc_create
|
||||||
after_destroy :xml_delete_iso_container
|
after_destroy :xml_delete_iso_container
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
%table.tablesorter{:cellpadding => "0", :cellspacing => "0"}
|
%table.tablesorter{:cellpadding => "0", :cellspacing => "0"}
|
||||||
%thead
|
%thead
|
||||||
%tr
|
%tr
|
||||||
-#%th.lpadding16= t("activerecord.attributes.product_build_list.bs_id")
|
|
||||||
%th.lpadding16= t("activerecord.attributes.product_build_list.id")
|
%th.lpadding16= t("activerecord.attributes.product_build_list.id")
|
||||||
%th.lpadding16= t("activerecord.attributes.product_build_list.status")
|
%th.lpadding16= t("activerecord.attributes.product_build_list.status")
|
||||||
%th.lpadding16= t("activerecord.attributes.product_build_list.container_path")
|
%th.lpadding16= t("activerecord.attributes.product_build_list.container_path")
|
||||||
|
|
|
@ -1,23 +1,64 @@
|
||||||
# -*- encoding : utf-8 -*-
|
# -*- encoding : utf-8 -*-
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
|
shared_examples_for 'admin' do
|
||||||
|
|
||||||
|
it "should be able to create ProductBuildList" do
|
||||||
|
expect {
|
||||||
|
post :create, valid_attributes
|
||||||
|
}.to change(ProductBuildList, :count).by(1)
|
||||||
|
response.should redirect_to([@product.platform, @product])
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should be able to destroy ProductBuildList" do
|
||||||
|
expect {
|
||||||
|
delete :destroy, valid_attributes_for_destroy
|
||||||
|
}.to change(ProductBuildList, :count).by(-1)
|
||||||
|
response.should redirect_to([@pbl.product.platform, @pbl.product])
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should be able to view ProductBuildLists' do
|
||||||
|
get :index
|
||||||
|
response.should render_template(:index)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
describe ProductBuildListsController do
|
describe ProductBuildListsController do
|
||||||
before(:each) do
|
before(:each) do
|
||||||
stub_rsync_methods
|
stub_rsync_methods
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'crud' do
|
context 'crud' do
|
||||||
def valid_attributes
|
|
||||||
{:product_id => product.id, :platform_id => product.platform_id}
|
before(:each) do
|
||||||
|
@product = FactoryGirl.create(:product)
|
||||||
|
@pbl = FactoryGirl.create(:product_build_list, :product => @product)
|
||||||
end
|
end
|
||||||
|
|
||||||
let(:product) { FactoryGirl.create(:product) }
|
def valid_attributes
|
||||||
|
{:product_id => @product.id, :platform_id => @product.platform_id}
|
||||||
|
end
|
||||||
|
|
||||||
|
def valid_attributes_for_destroy
|
||||||
|
{:id => @pbl.id, :product_id => @pbl.product.id, :platform_id => @pbl.product.platform.id }
|
||||||
|
end
|
||||||
|
|
||||||
context 'for guest' do
|
context 'for guest' do
|
||||||
it 'should not be able to perform create action' do
|
it 'should not be able to create ProductBuildList' do
|
||||||
post :create, valid_attributes
|
post :create, valid_attributes
|
||||||
response.should redirect_to(new_user_session_path)
|
response.should redirect_to(new_user_session_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'should not be able to destroy ProductBuildList' do
|
||||||
|
delete :destroy, valid_attributes_for_destroy
|
||||||
|
response.should redirect_to(new_user_session_path)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should not be able to view ProductBuildLists' do
|
||||||
|
get :index
|
||||||
|
response.should redirect_to(new_user_session_path)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'for user' do
|
context 'for user' do
|
||||||
|
@ -27,38 +68,53 @@ describe ProductBuildListsController do
|
||||||
post :create, valid_attributes
|
post :create, valid_attributes
|
||||||
response.should redirect_to(forbidden_url)
|
response.should redirect_to(forbidden_url)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'should not be able to perform create action' do
|
||||||
|
delete :destroy, valid_attributes_for_destroy
|
||||||
|
response.should redirect_to(forbidden_url)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should be able to view ProductBuildLists' do
|
||||||
|
get :index
|
||||||
|
response.should render_template(:index)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'for admin' do
|
context 'for platform admin' do
|
||||||
before(:each) { set_session_for FactoryGirl.create(:admin) }
|
before(:each) do
|
||||||
|
@user = FactoryGirl.create(:user)
|
||||||
it "creates a new ProductBuildList" do
|
set_session_for(@user)
|
||||||
expect {
|
@pbl.product.platform.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')
|
||||||
post :create, valid_attributes
|
|
||||||
}.to change(ProductBuildList, :count).by(1)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "redirects to the product" do
|
it_should_behave_like 'admin'
|
||||||
post :create, valid_attributes
|
|
||||||
response.should redirect_to([product.platform, product])
|
end
|
||||||
end
|
|
||||||
|
context 'for global admin' do
|
||||||
|
before(:each) { set_session_for FactoryGirl.create(:admin) }
|
||||||
|
|
||||||
|
it_should_behave_like 'admin'
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'callbacks' do
|
context 'callbacks' do
|
||||||
let(:product_build_list) { FactoryGirl.create(:product_build_list) }
|
|
||||||
|
let(:pbl) { FactoryGirl.create(:product_build_list) }
|
||||||
|
|
||||||
|
before(:each) do
|
||||||
|
mock(controller).authenticate_product_builder! {true}
|
||||||
|
end
|
||||||
|
|
||||||
def do_get
|
def do_get
|
||||||
get :status_build, :id => product_build_list.id, :status => ProductBuildList::BUILD_FAILED
|
get :status_build, :id => pbl.id, :status => ProductBuildList::BUILD_FAILED
|
||||||
product_build_list.reload
|
pbl.reload
|
||||||
end
|
end
|
||||||
|
|
||||||
it do
|
it "should update ProductBuildList status" do
|
||||||
expect { do_get }.to change(product_build_list, :status).to(ProductBuildList::BUILD_FAILED)
|
expect { do_get }.to change(pbl, :status).to(ProductBuildList::BUILD_FAILED)
|
||||||
end
|
|
||||||
|
|
||||||
it do
|
|
||||||
do_get
|
|
||||||
response.should be_success
|
response.should be_success
|
||||||
response.body.should be_blank
|
response.body.should be_blank
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,5 +2,26 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe ProductBuildList do
|
describe ProductBuildList do
|
||||||
pending "add some examples to (or delete) #{__FILE__}"
|
before(:all) do
|
||||||
end
|
stub_rsync_methods
|
||||||
|
end
|
||||||
|
|
||||||
|
it { should belong_to(:product) }
|
||||||
|
|
||||||
|
it { should validate_presence_of(:product_id)}
|
||||||
|
it { should validate_presence_of(:status)}
|
||||||
|
|
||||||
|
ProductBuildList::STATUSES.each do |value|
|
||||||
|
it {should allow_value(value).for(:status)}
|
||||||
|
end
|
||||||
|
|
||||||
|
it {should_not allow_value(555).for(:status)}
|
||||||
|
|
||||||
|
it { should have_readonly_attribute(:product_id) }
|
||||||
|
it { should_not allow_mass_assignment_of(:product_id) }
|
||||||
|
|
||||||
|
it { should allow_mass_assignment_of(:status) }
|
||||||
|
it { should allow_mass_assignment_of(:notified_at) }
|
||||||
|
it { should allow_mass_assignment_of(:base_url) }
|
||||||
|
|
||||||
|
end
|
Loading…
Reference in New Issue