#465: Update specs for Platforms::ProductsController
This commit is contained in:
parent
c3108cc3eb
commit
9ba535a5e5
|
@ -11,7 +11,6 @@ class Api::V1::ProductBuildListsController < Api::V1::BaseController
|
||||||
@product.product_build_lists
|
@product.product_build_lists
|
||||||
else
|
else
|
||||||
PlatformPolicy::Scope.new(current_user, ProductBuildList.joins(product: :platform)).show
|
PlatformPolicy::Scope.new(current_user, ProductBuildList.joins(product: :platform)).show
|
||||||
# ProductBuildList.accessible_by current_ability, :read
|
|
||||||
end
|
end
|
||||||
@product_build_lists = @product_build_lists.joins(:product, :project, :arch)
|
@product_build_lists = @product_build_lists.joins(:product, :project, :arch)
|
||||||
@product_build_lists = @product_build_lists.recent.paginate(paginate_params)
|
@product_build_lists = @product_build_lists.recent.paginate(paginate_params)
|
||||||
|
|
|
@ -4,11 +4,10 @@ class Platforms::ProductsController < Platforms::BaseController
|
||||||
before_action :authenticate_user!
|
before_action :authenticate_user!
|
||||||
skip_before_action :authenticate_user!, only: [:index, :show] if APP_CONFIG['anonymous_access']
|
skip_before_action :authenticate_user!, only: [:index, :show] if APP_CONFIG['anonymous_access']
|
||||||
|
|
||||||
load_and_authorize_resource :platform
|
before_action :load_product, except: [:create, :autocomplete_project]
|
||||||
load_and_authorize_resource :product, through: :platform, except: :autocomplete_project
|
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@products = @products.paginate(page: params[:page])
|
@products = @platform.products.paginate(page: params[:page])
|
||||||
end
|
end
|
||||||
|
|
||||||
def new
|
def new
|
||||||
|
@ -20,6 +19,7 @@ class Platforms::ProductsController < Platforms::BaseController
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
authorize @product = @platform.products.build(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)
|
||||||
|
@ -53,9 +53,17 @@ class Platforms::ProductsController < Platforms::BaseController
|
||||||
end
|
end
|
||||||
|
|
||||||
def autocomplete_project
|
def autocomplete_project
|
||||||
|
authorize :project
|
||||||
@items = ProjectPolicy::Scope.new(current_user, Project).membered.
|
@items = ProjectPolicy::Scope.new(current_user, Project).membered.
|
||||||
by_owner_and_name(params[:query]).limit(20)
|
by_owner_and_name(params[:query]).limit(20)
|
||||||
#items.select! {|e| e.repo.branches.count > 0}
|
#items.select! {|e| e.repo.branches.count > 0}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
# Private: before_action hook which loads Product.
|
||||||
|
def load_product
|
||||||
|
authorize @product = Product.find(params[:id])
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,6 +3,7 @@ class ProjectPolicy < ApplicationPolicy
|
||||||
def index?
|
def index?
|
||||||
!user.guest?
|
!user.guest?
|
||||||
end
|
end
|
||||||
|
alias_method :autocomplete_project?, :index?
|
||||||
alias_method :remove_user?, :index?
|
alias_method :remove_user?, :index?
|
||||||
alias_method :preview?, :index?
|
alias_method :preview?, :index?
|
||||||
|
|
||||||
|
|
|
@ -3,20 +3,23 @@ require 'spec_helper'
|
||||||
shared_examples_for 'admin user' do
|
shared_examples_for 'admin user' do
|
||||||
|
|
||||||
it 'should be able to create product' do
|
it 'should be able to create product' do
|
||||||
lambda { post :create, @create_params }.should change{ Product.count }.by(1)
|
expect do
|
||||||
response.should redirect_to(platform_product_path( Product.last.platform, Product.last ))
|
post :create, @create_params
|
||||||
|
end.to change(Product, :count).by(1)
|
||||||
|
expect(response).to redirect_to(platform_product_path( Product.last.platform, Product.last ))
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should be able to update product' do
|
it 'should be able to update product' do
|
||||||
put :update, {id: @product.id}.merge(@update_params)
|
put :update, {id: @product.id}.merge(@update_params)
|
||||||
response.should redirect_to platform_product_path(@platform, @product)
|
expect(response).to redirect_to platform_product_path(@platform, @product)
|
||||||
@product.reload
|
expect(@product.reload.name).to eq 'pro2'
|
||||||
@product.name.should eql('pro2')
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should be able to destroy product' do
|
it 'should be able to destroy product' do
|
||||||
lambda { delete :destroy, id: @product.id, platform_id: @platform }.should change{ Product.count }.by(-1)
|
expect do
|
||||||
response.should redirect_to(platform_products_path(@platform))
|
delete :destroy, id: @product.id, platform_id: @platform
|
||||||
|
end.to change(Product, :count).by(-1)
|
||||||
|
expect(response).to redirect_to(platform_products_path(@platform))
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -46,29 +49,29 @@ describe Platforms::ProductsController, type: :controller do
|
||||||
[:create].each do |action|
|
[:create].each do |action|
|
||||||
it "should not be able to perform #{ action } action" do
|
it "should not be able to perform #{ action } action" do
|
||||||
get action, platform_id: @platform.id
|
get action, platform_id: @platform.id
|
||||||
response.should redirect_to(new_user_session_path)
|
expect(response).to redirect_to(new_user_session_path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
[:new, :edit, :update, :destroy].each do |action|
|
[:new, :edit, :update, :destroy].each do |action|
|
||||||
it "should not be able to perform #{ action } action" do
|
it "should not be able to perform #{ action } action" do
|
||||||
get action, id: @product.id, platform_id: @platform.id
|
get action, id: @product.id, platform_id: @platform.id
|
||||||
response.should redirect_to(new_user_session_path)
|
expect(response).to redirect_to(new_user_session_path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
[:show, :index].each do |action|
|
[:show, :index].each do |action|
|
||||||
it "should not be able to perform #{ action } action", anonymous_access: false do
|
it "should not be able to perform #{ action } action", anonymous_access: false do
|
||||||
get action, id: @product.id, platform_id: @platform.id
|
get action, id: @product.id, platform_id: @platform.id
|
||||||
response.should redirect_to(new_user_session_path)
|
expect(response).to redirect_to(new_user_session_path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
[:show, :index].each do |action|
|
[:show, :index].each do |action|
|
||||||
it "should be able to perform #{ action } action", anonymous_access: true do
|
it "should be able to perform #{ action } action", anonymous_access: true do
|
||||||
get action, id: @product.id, platform_id: @platform.id
|
get action, id: @product.id, platform_id: @platform.id
|
||||||
response.should render_template(action)
|
expect(response).to render_template(action)
|
||||||
response.should be_success
|
expect(response).to be_success
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -102,18 +105,22 @@ describe Platforms::ProductsController, type: :controller do
|
||||||
context 'for no relation user' do
|
context 'for no relation user' do
|
||||||
|
|
||||||
it 'should not be able to create product' do
|
it 'should not be able to create product' do
|
||||||
lambda { post :create, @create_params }.should change{ Product.count }.by(0)
|
expect do
|
||||||
response.should redirect_to(forbidden_path)
|
post :create, @create_params
|
||||||
|
end.to_not change(Product, :count)
|
||||||
|
expect(response).to 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
|
||||||
put :update, {id: @product.id}.merge(@update_params)
|
put :update, {id: @product.id}.merge(@update_params)
|
||||||
response.should redirect_to(forbidden_path)
|
expect(response).to redirect_to(forbidden_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not be able to destroy product' 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)
|
expect do
|
||||||
response.should redirect_to(forbidden_path)
|
delete :destroy, id: @product.id, platform_id: @platform
|
||||||
|
end.to_not change(Product, :count)
|
||||||
|
expect(response).to redirect_to(forbidden_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue