#211: added specs for BuildList API controller
This commit is contained in:
parent
61509312a0
commit
2dee10a23f
|
@ -26,7 +26,7 @@ class Api::V1::PlatformsController < Api::V1::BaseController
|
||||||
|
|
||||||
user = User.find_by_authentication_token token
|
user = User.find_by_authentication_token token
|
||||||
@current_ability, @current_user = nil, user
|
@current_ability, @current_user = nil, user
|
||||||
if user && can?(:read, platform)
|
if user && can?(:show, platform)
|
||||||
render :nothing => true
|
render :nothing => true
|
||||||
else
|
else
|
||||||
render :nothing => true, :status => 403
|
render :nothing => true, :status => 403
|
||||||
|
|
|
@ -82,7 +82,11 @@ class Ability
|
||||||
can [:read, :log, :related, :everything], BuildList, :project => {:owner_type => 'User', :owner_id => user.id}
|
can [:read, :log, :related, :everything], BuildList, :project => {:owner_type => 'User', :owner_id => user.id}
|
||||||
can [:read, :log, :related, :everything], BuildList, :project => {:owner_type => 'Group', :owner_id => user.group_ids}
|
can [:read, :log, :related, :everything], BuildList, :project => {:owner_type => 'Group', :owner_id => user.group_ids}
|
||||||
can([:read, :log, :everything], BuildList, read_relations_for('build_lists', 'projects')) {|build_list| can? :read, build_list.project}
|
can([:read, :log, :everything], BuildList, read_relations_for('build_lists', 'projects')) {|build_list| can? :read, build_list.project}
|
||||||
can(:create, BuildList) {|build_list| build_list.project.is_package && can?(:write, build_list.project) && can?(:read, build_list.build_for_platform) }
|
can(:create, BuildList) {|build_list|
|
||||||
|
build_list.project.is_package &&
|
||||||
|
can?(:write, build_list.project) &&
|
||||||
|
can?(:show, build_list.build_for_platform)
|
||||||
|
}
|
||||||
|
|
||||||
can(:publish, BuildList) do |build_list|
|
can(:publish, BuildList) do |build_list|
|
||||||
if build_list.build_published?
|
if build_list.build_published?
|
||||||
|
|
|
@ -116,7 +116,7 @@ describe Api::V1::BuildListsController do
|
||||||
|
|
||||||
# Create and show params:
|
# Create and show params:
|
||||||
@create_params = {:build_list => @build_list.attributes.symbolize_keys.merge(:qwerty=>'!')} # wrong parameter
|
@create_params = {:build_list => @build_list.attributes.symbolize_keys.merge(:qwerty=>'!')} # wrong parameter
|
||||||
@create_params = @create_params.merge(:arches => [@params[:arch_id]], :build_for_platforms => [@params[:build_for_platform_id]], :format => :json)
|
@create_params = @create_params.merge(:arches => [@params[:arch_id]], :build_for_platform_id => @platform.id, :format => :json)
|
||||||
any_instance_of(Project, :versions => ['v1.0', 'v2.0'])
|
any_instance_of(Project, :versions => ['v1.0', 'v2.0'])
|
||||||
|
|
||||||
http_login(@user)
|
http_login(@user)
|
||||||
|
@ -466,10 +466,25 @@ describe Api::V1::BuildListsController do
|
||||||
context 'if user is project owner' do
|
context 'if user is project owner' do
|
||||||
before(:each) {http_login(@owner_user)}
|
before(:each) {http_login(@owner_user)}
|
||||||
it_should_behave_like 'create build list via api'
|
it_should_behave_like 'create build list via api'
|
||||||
|
|
||||||
|
context 'no ability to read build_for_platform' do
|
||||||
|
before do
|
||||||
|
repository = FactoryGirl.create(:repository)
|
||||||
|
repository.platform.change_visibility
|
||||||
|
Platform.where(:id => @platform.id).update_all(:platform_type => 'personal')
|
||||||
|
@create_params[:build_list].merge!({
|
||||||
|
:include_repos => [repository.id],
|
||||||
|
:build_for_platform_id => repository.platform_id
|
||||||
|
})
|
||||||
|
end
|
||||||
|
it_should_behave_like 'not create build list via api'
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'if user is project read member' do
|
context 'if user is project read member' do
|
||||||
before(:each) {http_login(@member_user)}
|
before(:each) {http_login(@member_user)}
|
||||||
|
it_should_behave_like 'not create build list via api'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -510,7 +525,7 @@ describe Api::V1::BuildListsController do
|
||||||
|
|
||||||
# Create and show params:
|
# Create and show params:
|
||||||
@create_params = {:build_list => @build_list.attributes.symbolize_keys}
|
@create_params = {:build_list => @build_list.attributes.symbolize_keys}
|
||||||
@create_params = @create_params.merge(:arches => [@params[:arch_id]], :build_for_platforms => [@params[:build_for_platform_id]], :format => :json)
|
@create_params = @create_params.merge(:arches => [@params[:arch_id]], :build_for_platform_id => @platform.id, :format => :json)
|
||||||
any_instance_of(Project, :versions => ['v1.0', 'v2.0'])
|
any_instance_of(Project, :versions => ['v1.0', 'v2.0'])
|
||||||
|
|
||||||
# Groups:
|
# Groups:
|
||||||
|
|
Loading…
Reference in New Issue