#211: added specs for BuildList API controller

This commit is contained in:
Vokhmin Alexey V 2013-07-04 23:39:02 +04:00
parent 61509312a0
commit 2dee10a23f
3 changed files with 23 additions and 4 deletions

View File

@ -26,7 +26,7 @@ class Api::V1::PlatformsController < Api::V1::BaseController
user = User.find_by_authentication_token token
@current_ability, @current_user = nil, user
if user && can?(:read, platform)
if user && can?(:show, platform)
render :nothing => true
else
render :nothing => true, :status => 403

View File

@ -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 => '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(: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|
if build_list.build_published?

View File

@ -116,7 +116,7 @@ describe Api::V1::BuildListsController do
# Create and show params:
@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'])
http_login(@user)
@ -466,10 +466,25 @@ describe Api::V1::BuildListsController do
context 'if user is project owner' do
before(:each) {http_login(@owner_user)}
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
context 'if user is project read member' do
before(:each) {http_login(@member_user)}
it_should_behave_like 'not create build list via api'
end
end
@ -510,7 +525,7 @@ describe Api::V1::BuildListsController do
# Create and show params:
@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'])
# Groups: