#465: Update specs for Platforms::ProductBuildListsController

This commit is contained in:
Vokhmin Alexey V 2015-04-04 00:06:33 +03:00
parent 2dc5bb4b97
commit c3108cc3eb
4 changed files with 44 additions and 28 deletions

View File

@ -48,6 +48,7 @@ class Api::V1::ProductBuildListsController < Api::V1::BaseController
private
# Private: before_action hook which loads ProductBuildList.
def load_product_build_list
authorize @product_build_list = ProductBuildList.find(params[:id])
end

View File

@ -89,6 +89,8 @@ class ApplicationController < ActionController::Base
if Rails.env.production? && !AIRBRAKE_IGNORE.include?(e.class)
notify_airbrake(e)
end
Rails.logger.error e.message
Rails.logger.error e.backtrace.inspect
render_error 500
end

View File

@ -4,18 +4,17 @@ class Platforms::ProductBuildListsController < Platforms::BaseController
before_action :authenticate_user!
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]
load_and_authorize_resource :platform, except: :index
load_and_authorize_resource :product, through: :platform, except: :index
load_and_authorize_resource :product_build_list, through: :product, except: :index
load_and_authorize_resource only: [:index, :show, :log, :cancel, :update]
before_action :load_product, except: :index
before_action :load_product_build_list, except: [:index, :create]
def new
product = @product_build_list.product
@product_build_list.params = product.params
@product_build_list.main_script = product.main_script
@product_build_list.time_living = product.time_living
@product_build_list.project_version = product.project_version
@product_build_list.project = product.project
@product_build_list = @product.product_build_lists.new
@product_build_list.params = @product.params
@product_build_list.main_script = @product.main_script
@product_build_list.time_living = @product.time_living
@product_build_list.project_version = @product.project_version
@product_build_list.project = @product.project
unless @product_build_list.project
flash[:error] = t('flash.product_build_list.no_project')
redirect_to edit_platform_product_path(@platform, @product)
@ -53,6 +52,7 @@ class Platforms::ProductBuildListsController < Platforms::BaseController
pbl.user = current_user
pbl.base_url = "http://#{request.host_with_port}"
authorize pbl
if pbl.save
flash[:notice] = t('flash.product.build_started')
redirect_to [@platform, @product]
@ -73,8 +73,11 @@ class Platforms::ProductBuildListsController < Platforms::BaseController
end
def index
authorize :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_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?
@product_build_lists = @product_build_lists.where(id: @product_build_list.product_id)
else
@ -98,4 +101,14 @@ class Platforms::ProductBuildListsController < Platforms::BaseController
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

View File

@ -6,7 +6,7 @@ shared_examples_for 'product build list admin' do
expect {
post :create, valid_attributes
}.to change(ProductBuildList, :count).by(1)
response.should redirect_to([@product.platform, @product])
expect(response).to redirect_to([@product.platform, @product])
end
it "should be able to perform destroy action" do
@ -14,41 +14,41 @@ shared_examples_for 'product build list admin' do
expect {
delete :destroy, valid_attributes_for_destroy
}.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
it 'should be able to perform index action' do
get :index
response.should render_template(:index)
expect(response).to render_template(:index)
end
it 'should be able to perform cancel action' do
url = platform_product_product_build_list_path(@product.platform, @product, @pbl)
@request.env['HTTP_REFERER'] = url
put :cancel, valid_attributes_for_show
response.should redirect_to(url)
expect(response).to redirect_to(url)
end
it 'should be able to perform show action' do
get :show, valid_attributes_for_show
response.should render_template(:show)
expect(response).to render_template(:show)
end
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})
response.should be_success
expect(response).to be_success
end
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})
time_living = @pbl.time_living
@pbl.reload.time_living.should == time_living
@pbl.not_delete.should be_truthy
expect(@pbl.reload.time_living).to eq time_living
expect(@pbl.not_delete).to be_truthy
end
it 'should be able to perform log action' do
get :log, valid_attributes_for_show
response.should be_success
expect(response).to be_success
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
expect {
post :create, valid_attributes
}.to change(ProductBuildList, :count).by(0)
response.should_not be_success
}.to_not change(ProductBuildList, :count)
expect(response).to_not be_success
end
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 {
delete :destroy, valid_attributes_for_destroy
}.to change(ProductBuildList, :count).by(0)
response.should_not be_success
expect(response).to_not be_success
end
it 'should not be able to perform cancel action' do
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
it 'should not be able to perform update action' do
put :update, valid_attributes_for_show
response.should_not be_success
expect(response).to_not be_success
end
end
@ -84,17 +84,17 @@ end
shared_examples_for 'product build list user' do
it 'should be able to perform index action' do
get :index
response.should render_template(:index)
expect(response).to render_template(:index)
end
it 'should be able to perform show action' do
get :show, valid_attributes_for_show
response.should render_template(:show)
expect(response).to render_template(:show)
end
it 'should be able to perform log action' do
get :log, valid_attributes_for_show
response.should be_success
expect(response).to be_success
end
end
@ -131,7 +131,7 @@ describe Platforms::ProductBuildListsController, type: :controller do
[:index, :show, :log].each do |action|
it "should not be able to perform #{action}" do
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