update ability.rb, add new specs
This commit is contained in:
parent
57ec1e2982
commit
abbbacdf7f
|
@ -1,11 +1,11 @@
|
||||||
# -*- encoding : utf-8 -*-
|
# -*- encoding : utf-8 -*-
|
||||||
class Platforms::ProductBuildListsController < Platforms::BaseController
|
class Platforms::ProductBuildListsController < Platforms::BaseController
|
||||||
before_filter :authenticate_user!, :except => [:status_build]
|
before_filter :authenticate_user!, :except => [:status_build]
|
||||||
skip_before_filter :authenticate_user!, :only => [:index] if APP_CONFIG['anonymous_access']
|
skip_before_filter :authenticate_user!, :only => [:index, :show, :log] if APP_CONFIG['anonymous_access']
|
||||||
load_and_authorize_resource :platform, :except => [:index, :status_build]
|
load_and_authorize_resource :platform, :except => [:index, :status_build]
|
||||||
load_and_authorize_resource :product, :through => :platform, :except => [:index, :status_build]
|
load_and_authorize_resource :product, :through => :platform, :except => [:index, :status_build]
|
||||||
load_and_authorize_resource :product_build_list, :through => :product, :except => [:index, :status_build]
|
load_and_authorize_resource :product_build_list, :through => :product, :except => [:index, :status_build]
|
||||||
load_and_authorize_resource :only => [:index]
|
load_and_authorize_resource :only => [:index, :show, :log, :stop]
|
||||||
|
|
||||||
before_filter :authenticate_product_builder!, :only => [:status_build]
|
before_filter :authenticate_product_builder!, :only => [:status_build]
|
||||||
before_filter :find_product_build_list, :only => [:status_build]
|
before_filter :find_product_build_list, :only => [:status_build]
|
||||||
|
@ -32,14 +32,10 @@ class Platforms::ProductBuildListsController < Platforms::BaseController
|
||||||
end
|
end
|
||||||
|
|
||||||
def log
|
def log
|
||||||
respond_to do |format|
|
render :json => {
|
||||||
format.json {
|
:log => @product_build_list.log,
|
||||||
render :json => {
|
:building => @product_build_list.build_started?
|
||||||
:log => @product_build_list.log,
|
}
|
||||||
:building => @product_build_list.build_started?
|
|
||||||
}
|
|
||||||
}
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
|
|
@ -20,7 +20,7 @@ class Ability
|
||||||
can :read, PullRequest, :to_project => {:visibility => 'open'}
|
can :read, PullRequest, :to_project => {:visibility => 'open'}
|
||||||
can :search, BuildList
|
can :search, BuildList
|
||||||
can [:read, :log, :everything], BuildList, :project => {:visibility => 'open'}
|
can [:read, :log, :everything], BuildList, :project => {:visibility => 'open'}
|
||||||
can :read, ProductBuildList#, :product => {:platform => {:visibility => 'open'}} # double nested hash don't work
|
can [:read, :log], ProductBuildList#, :product => {:platform => {:visibility => 'open'}} # double nested hash don't work
|
||||||
can :read, Advisory
|
can :read, Advisory
|
||||||
|
|
||||||
# Core callbacks
|
# Core callbacks
|
||||||
|
@ -114,7 +114,7 @@ class Ability
|
||||||
can(:read, Product, read_relations_for('products', 'platforms')) {|product| product.platform.main?}
|
can(:read, Product, read_relations_for('products', 'platforms')) {|product| product.platform.main?}
|
||||||
can([:create, :update, :destroy, :clone], Product) {|product| local_admin? product.platform and product.platform.main?}
|
can([:create, :update, :destroy, :clone], Product) {|product| local_admin? product.platform and product.platform.main?}
|
||||||
|
|
||||||
can(:create, ProductBuildList) {|pbl| can?(:update, pbl.product)}
|
can([:create, :stop], ProductBuildList) {|pbl| can?(:update, pbl.product)}
|
||||||
can(:destroy, ProductBuildList) {|pbl| can?(:destroy, pbl.product)}
|
can(:destroy, ProductBuildList) {|pbl| can?(:destroy, pbl.product)}
|
||||||
|
|
||||||
can [:read, :create], PrivateUser, :platform => {:owner_type => 'User', :owner_id => user.id}
|
can [:read, :create], PrivateUser, :platform => {:owner_type => 'User', :owner_id => user.id}
|
||||||
|
|
|
@ -23,9 +23,10 @@
|
||||||
= render 'show_field', :key => :notified_at, :value => l(pbl.updated_at, :format => :long)
|
= render 'show_field', :key => :notified_at, :value => l(pbl.updated_at, :format => :long)
|
||||||
|
|
||||||
- if pbl.build_started?
|
- if pbl.build_started?
|
||||||
.leftlist= t("layout.product_build_lists.action")
|
- if can? :stop, pbl
|
||||||
.rightlist= link_to t("layout.product_build_lists.stop"), stop_platform_product_product_build_list_path(pbl.product.platform, pbl.product, pbl)
|
.leftlist= t("layout.product_build_lists.action")
|
||||||
.both
|
.rightlist= link_to t("layout.product_build_lists.stop"), stop_platform_product_product_build_list_path(pbl.product.platform, pbl.product, pbl)
|
||||||
|
.both
|
||||||
= render 'shared/log', { :build_started => true, :get_log_path => log_platform_product_product_build_list_path(pbl.product.platform, pbl.product, pbl) }
|
= render 'shared/log', { :build_started => true, :get_log_path => log_platform_product_product_build_list_path(pbl.product.platform, pbl.product, pbl) }
|
||||||
|
|
||||||
%h3= t("layout.product_build_lists.results")
|
%h3= t("layout.product_build_lists.results")
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
# -*- encoding : utf-8 -*-
|
# -*- encoding : utf-8 -*-
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
shared_examples_for 'admin' do
|
shared_examples_for 'product build list admin' do
|
||||||
|
|
||||||
it "should be able to create ProductBuildList" do
|
it "should be able to perform create action" 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])
|
response.should redirect_to([@product.platform, @product])
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should be able to destroy ProductBuildList" do
|
it "should be able to perform destroy action" do
|
||||||
@pbl.update_column(:project_id, nil)
|
@pbl.update_column(:project_id, nil)
|
||||||
expect {
|
expect {
|
||||||
delete :destroy, valid_attributes_for_destroy
|
delete :destroy, valid_attributes_for_destroy
|
||||||
|
@ -18,11 +18,65 @@ shared_examples_for 'admin' do
|
||||||
response.should redirect_to([@pbl.product.platform, @pbl.product])
|
response.should redirect_to([@pbl.product.platform, @pbl.product])
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should be able to view ProductBuildLists' do
|
it 'should be able to perform index action' do
|
||||||
get :index
|
get :index
|
||||||
response.should render_template(:index)
|
response.should render_template(:index)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'should be able to perform stop action' do
|
||||||
|
get :stop, valid_attributes_for_show
|
||||||
|
response.should redirect_to(platform_product_product_build_list_path(@product.platform, @product, @pbl))
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should be able to perform show action' do
|
||||||
|
get :show, valid_attributes_for_show
|
||||||
|
response.should render_template(:show)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should be able to perform log action' do
|
||||||
|
get :log, valid_attributes_for_show
|
||||||
|
response.should be_success
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
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
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should not be able to perform destroy action' do
|
||||||
|
@pbl.update_column(:project_id, nil)
|
||||||
|
expect {
|
||||||
|
delete :destroy, valid_attributes_for_destroy
|
||||||
|
}.to change(ProductBuildList, :count).by(0)
|
||||||
|
response.should_not be_success
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should not be able to perform stop action' do
|
||||||
|
get :stop, valid_attributes_for_show
|
||||||
|
response.should_not redirect_to(platform_product_product_build_list_path(@product.platform, @product, @pbl))
|
||||||
|
end
|
||||||
|
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)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should be able to perform show action' do
|
||||||
|
get :show, valid_attributes_for_show
|
||||||
|
response.should render_template(:show)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should be able to perform log action' do
|
||||||
|
get :log, valid_attributes_for_show
|
||||||
|
response.should be_success
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe Platforms::ProductBuildListsController do
|
describe Platforms::ProductBuildListsController do
|
||||||
|
@ -45,27 +99,21 @@ describe Platforms::ProductBuildListsController do
|
||||||
{:id => @pbl.id, :product_id => @pbl.product.id, :platform_id => @pbl.product.platform.id }
|
{:id => @pbl.id, :product_id => @pbl.product.id, :platform_id => @pbl.product.platform.id }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'for guest' do
|
def valid_attributes_for_show
|
||||||
it 'should not be able to create ProductBuildList' do
|
valid_attributes_for_destroy
|
||||||
post :create, valid_attributes
|
end
|
||||||
response.should redirect_to(new_user_session_path)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should not be able to destroy ProductBuildList' do
|
context 'for guest' do
|
||||||
@pbl.update_column(:project_id, nil)
|
it_should_behave_like 'product build list user without admin rights'
|
||||||
delete :destroy, valid_attributes_for_destroy
|
|
||||||
response.should redirect_to(new_user_session_path)
|
|
||||||
end
|
|
||||||
|
|
||||||
if APP_CONFIG['anonymous_access']
|
if APP_CONFIG['anonymous_access']
|
||||||
it 'should be able to view ProductBuildLists' do
|
it_should_behave_like 'product build list user'
|
||||||
get :index
|
|
||||||
response.should be_success
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
it 'should not be able to view ProductBuildLists' do
|
[:index, :show, :log].each do |action|
|
||||||
get :index
|
it "should not be able to perform #{action}" do
|
||||||
response.should redirect_to(new_user_session_path)
|
get action, valid_attributes_for_show
|
||||||
|
response.should redirect_to(new_user_session_path)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -73,21 +121,8 @@ describe Platforms::ProductBuildListsController do
|
||||||
context 'for user' do
|
context 'for user' do
|
||||||
before(:each) { set_session_for FactoryGirl.create(:user) }
|
before(:each) { set_session_for FactoryGirl.create(:user) }
|
||||||
|
|
||||||
it 'should not be able to perform create action' do
|
it_should_behave_like 'product build list user'
|
||||||
post :create, valid_attributes
|
it_should_behave_like 'product build list user without admin rights'
|
||||||
response.should redirect_to(forbidden_url)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should not be able to perform create action' do
|
|
||||||
@pbl.update_column(:project_id, nil)
|
|
||||||
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
|
||||||
|
|
||||||
|
@ -98,14 +133,15 @@ describe Platforms::ProductBuildListsController do
|
||||||
@pbl.product.platform.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'admin')
|
@pbl.product.platform.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'admin')
|
||||||
end
|
end
|
||||||
|
|
||||||
it_should_behave_like 'admin'
|
it_should_behave_like 'product build list admin'
|
||||||
|
it_should_behave_like 'product build list user'
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'for global admin' do
|
context 'for global admin' do
|
||||||
before(:each) { set_session_for FactoryGirl.create(:admin) }
|
before(:each) { set_session_for FactoryGirl.create(:admin) }
|
||||||
|
|
||||||
it_should_behave_like 'admin'
|
it_should_behave_like 'product build list admin'
|
||||||
|
it_should_behave_like 'product build list user'
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue