#465: Update specs for Platforms::ProductBuildListsController
This commit is contained in:
parent
2dc5bb4b97
commit
c3108cc3eb
|
@ -48,6 +48,7 @@ class Api::V1::ProductBuildListsController < Api::V1::BaseController
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
# Private: before_action hook which loads ProductBuildList.
|
||||||
def load_product_build_list
|
def load_product_build_list
|
||||||
authorize @product_build_list = ProductBuildList.find(params[:id])
|
authorize @product_build_list = ProductBuildList.find(params[:id])
|
||||||
end
|
end
|
||||||
|
|
|
@ -89,6 +89,8 @@ class ApplicationController < ActionController::Base
|
||||||
if Rails.env.production? && !AIRBRAKE_IGNORE.include?(e.class)
|
if Rails.env.production? && !AIRBRAKE_IGNORE.include?(e.class)
|
||||||
notify_airbrake(e)
|
notify_airbrake(e)
|
||||||
end
|
end
|
||||||
|
Rails.logger.error e.message
|
||||||
|
Rails.logger.error e.backtrace.inspect
|
||||||
render_error 500
|
render_error 500
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -4,18 +4,17 @@ class Platforms::ProductBuildListsController < Platforms::BaseController
|
||||||
before_action :authenticate_user!
|
before_action :authenticate_user!
|
||||||
skip_before_action :authenticate_user!, only: [:index, :show, :log] if APP_CONFIG['anonymous_access']
|
skip_before_action :authenticate_user!, only: [:index, :show, :log] if APP_CONFIG['anonymous_access']
|
||||||
before_action :redirect_to_full_path_if_short_url, only: [:show, :update]
|
before_action :redirect_to_full_path_if_short_url, only: [:show, :update]
|
||||||
load_and_authorize_resource :platform, except: :index
|
|
||||||
load_and_authorize_resource :product, through: :platform, except: :index
|
before_action :load_product, except: :index
|
||||||
load_and_authorize_resource :product_build_list, through: :product, except: :index
|
before_action :load_product_build_list, except: [:index, :create]
|
||||||
load_and_authorize_resource only: [:index, :show, :log, :cancel, :update]
|
|
||||||
|
|
||||||
def new
|
def new
|
||||||
product = @product_build_list.product
|
@product_build_list = @product.product_build_lists.new
|
||||||
@product_build_list.params = product.params
|
@product_build_list.params = @product.params
|
||||||
@product_build_list.main_script = product.main_script
|
@product_build_list.main_script = @product.main_script
|
||||||
@product_build_list.time_living = product.time_living
|
@product_build_list.time_living = @product.time_living
|
||||||
@product_build_list.project_version = product.project_version
|
@product_build_list.project_version = @product.project_version
|
||||||
@product_build_list.project = product.project
|
@product_build_list.project = @product.project
|
||||||
unless @product_build_list.project
|
unless @product_build_list.project
|
||||||
flash[:error] = t('flash.product_build_list.no_project')
|
flash[:error] = t('flash.product_build_list.no_project')
|
||||||
redirect_to edit_platform_product_path(@platform, @product)
|
redirect_to edit_platform_product_path(@platform, @product)
|
||||||
|
@ -53,6 +52,7 @@ class Platforms::ProductBuildListsController < Platforms::BaseController
|
||||||
pbl.user = current_user
|
pbl.user = current_user
|
||||||
pbl.base_url = "http://#{request.host_with_port}"
|
pbl.base_url = "http://#{request.host_with_port}"
|
||||||
|
|
||||||
|
authorize pbl
|
||||||
if pbl.save
|
if pbl.save
|
||||||
flash[:notice] = t('flash.product.build_started')
|
flash[:notice] = t('flash.product.build_started')
|
||||||
redirect_to [@platform, @product]
|
redirect_to [@platform, @product]
|
||||||
|
@ -73,8 +73,11 @@ class Platforms::ProductBuildListsController < Platforms::BaseController
|
||||||
end
|
end
|
||||||
|
|
||||||
def index
|
def index
|
||||||
|
authorize :product_build_list
|
||||||
@product_build_list = ProductBuildList.new(params[:product_build_list])
|
@product_build_list = ProductBuildList.new(params[:product_build_list])
|
||||||
@product_build_list.status = nil if params[:product_build_list].try(:[], :status).blank?
|
@product_build_list.status = nil if params[:product_build_list].try(:[], :status).blank?
|
||||||
|
@product_build_lists = @platform.product_build_lists if @platform
|
||||||
|
@product_build_lists ||= PlatformPolicy::Scope.new(current_user, ProductBuildList.joins(product: :platform)).show
|
||||||
if @product_build_list.product_id.present?
|
if @product_build_list.product_id.present?
|
||||||
@product_build_lists = @product_build_lists.where(id: @product_build_list.product_id)
|
@product_build_lists = @product_build_lists.where(id: @product_build_list.product_id)
|
||||||
else
|
else
|
||||||
|
@ -98,4 +101,14 @@ class Platforms::ProductBuildListsController < Platforms::BaseController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Private: before_action hook which loads ProductBuildList.
|
||||||
|
def load_product_build_list
|
||||||
|
authorize @product_build_list = ProductBuildList.find(params[:id])
|
||||||
|
end
|
||||||
|
|
||||||
|
# Private: before_action hook which loads Product.
|
||||||
|
def load_product
|
||||||
|
authorize @product = Product.find(params[:product_id]), :show? if params[:product_id]
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,7 +6,7 @@ shared_examples_for 'product build list admin' do
|
||||||
expect {
|
expect {
|
||||||
post :create, valid_attributes
|
post :create, valid_attributes
|
||||||
}.to change(ProductBuildList, :count).by(1)
|
}.to change(ProductBuildList, :count).by(1)
|
||||||
response.should redirect_to([@product.platform, @product])
|
expect(response).to redirect_to([@product.platform, @product])
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should be able to perform destroy action" do
|
it "should be able to perform destroy action" do
|
||||||
|
@ -14,41 +14,41 @@ shared_examples_for 'product build list admin' do
|
||||||
expect {
|
expect {
|
||||||
delete :destroy, valid_attributes_for_destroy
|
delete :destroy, valid_attributes_for_destroy
|
||||||
}.to change(ProductBuildList, :count).by(-1)
|
}.to change(ProductBuildList, :count).by(-1)
|
||||||
response.should redirect_to([@pbl.product.platform, @pbl.product])
|
expect(response).to redirect_to([@pbl.product.platform, @pbl.product])
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should be able to perform index action' do
|
it 'should be able to perform index action' do
|
||||||
get :index
|
get :index
|
||||||
response.should render_template(:index)
|
expect(response).to render_template(:index)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should be able to perform cancel action' do
|
it 'should be able to perform cancel action' do
|
||||||
url = platform_product_product_build_list_path(@product.platform, @product, @pbl)
|
url = platform_product_product_build_list_path(@product.platform, @product, @pbl)
|
||||||
@request.env['HTTP_REFERER'] = url
|
@request.env['HTTP_REFERER'] = url
|
||||||
put :cancel, valid_attributes_for_show
|
put :cancel, valid_attributes_for_show
|
||||||
response.should redirect_to(url)
|
expect(response).to redirect_to(url)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should be able to perform show action' do
|
it 'should be able to perform show action' do
|
||||||
get :show, valid_attributes_for_show
|
get :show, valid_attributes_for_show
|
||||||
response.should render_template(:show)
|
expect(response).to render_template(:show)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should be able to perform update action' do
|
it 'should be able to perform update action' do
|
||||||
put :update, valid_attributes_for_show.merge(product_build_list: {time_living: 100,not_delete: true})
|
put :update, valid_attributes_for_show.merge(product_build_list: {time_living: 100,not_delete: true})
|
||||||
response.should be_success
|
expect(response).to be_success
|
||||||
end
|
end
|
||||||
|
|
||||||
it "ensures that only not_delete field of product build list has been updated" do
|
it "ensures that only not_delete field of product build list has been updated" do
|
||||||
put :update, valid_attributes_for_show.merge(product_build_list: {time_living: 100,not_delete: true})
|
put :update, valid_attributes_for_show.merge(product_build_list: {time_living: 100,not_delete: true})
|
||||||
time_living = @pbl.time_living
|
time_living = @pbl.time_living
|
||||||
@pbl.reload.time_living.should == time_living
|
expect(@pbl.reload.time_living).to eq time_living
|
||||||
@pbl.not_delete.should be_truthy
|
expect(@pbl.not_delete).to be_truthy
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should be able to perform log action' do
|
it 'should be able to perform log action' do
|
||||||
get :log, valid_attributes_for_show
|
get :log, valid_attributes_for_show
|
||||||
response.should be_success
|
expect(response).to be_success
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -57,8 +57,8 @@ shared_examples_for 'product build list user without admin rights' do
|
||||||
it 'should not be able to perform create action' do
|
it 'should not be able to perform create action' do
|
||||||
expect {
|
expect {
|
||||||
post :create, valid_attributes
|
post :create, valid_attributes
|
||||||
}.to change(ProductBuildList, :count).by(0)
|
}.to_not change(ProductBuildList, :count)
|
||||||
response.should_not be_success
|
expect(response).to_not be_success
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not be able to perform destroy action' do
|
it 'should not be able to perform destroy action' do
|
||||||
|
@ -66,17 +66,17 @@ shared_examples_for 'product build list user without admin rights' do
|
||||||
expect {
|
expect {
|
||||||
delete :destroy, valid_attributes_for_destroy
|
delete :destroy, valid_attributes_for_destroy
|
||||||
}.to change(ProductBuildList, :count).by(0)
|
}.to change(ProductBuildList, :count).by(0)
|
||||||
response.should_not be_success
|
expect(response).to_not be_success
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not be able to perform cancel action' do
|
it 'should not be able to perform cancel action' do
|
||||||
put :cancel, valid_attributes_for_show
|
put :cancel, valid_attributes_for_show
|
||||||
response.should_not redirect_to(platform_product_product_build_list_path(@product.platform, @product, @pbl))
|
expect(response).to_not redirect_to(platform_product_product_build_list_path(@product.platform, @product, @pbl))
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not be able to perform update action' do
|
it 'should not be able to perform update action' do
|
||||||
put :update, valid_attributes_for_show
|
put :update, valid_attributes_for_show
|
||||||
response.should_not be_success
|
expect(response).to_not be_success
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -84,17 +84,17 @@ end
|
||||||
shared_examples_for 'product build list user' do
|
shared_examples_for 'product build list user' do
|
||||||
it 'should be able to perform index action' do
|
it 'should be able to perform index action' do
|
||||||
get :index
|
get :index
|
||||||
response.should render_template(:index)
|
expect(response).to render_template(:index)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should be able to perform show action' do
|
it 'should be able to perform show action' do
|
||||||
get :show, valid_attributes_for_show
|
get :show, valid_attributes_for_show
|
||||||
response.should render_template(:show)
|
expect(response).to render_template(:show)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should be able to perform log action' do
|
it 'should be able to perform log action' do
|
||||||
get :log, valid_attributes_for_show
|
get :log, valid_attributes_for_show
|
||||||
response.should be_success
|
expect(response).to be_success
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -131,7 +131,7 @@ describe Platforms::ProductBuildListsController, type: :controller do
|
||||||
[:index, :show, :log].each do |action|
|
[:index, :show, :log].each do |action|
|
||||||
it "should not be able to perform #{action}" do
|
it "should not be able to perform #{action}" do
|
||||||
get action, valid_attributes_for_show
|
get action, valid_attributes_for_show
|
||||||
response.should redirect_to(new_user_session_path)
|
expect(response).to redirect_to(new_user_session_path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue