#214: added specs for TreesController

This commit is contained in:
Vokhmin Alexey V 2013-07-15 17:03:34 +04:00
parent 2b423e6a6e
commit 225da758ec
2 changed files with 44 additions and 2 deletions

View File

@ -15,7 +15,6 @@ class Ability
# Shared rights between guests and registered users # Shared rights between guests and registered users
can [:show, :archive], Project, :visibility => 'open' can [:show, :archive], Project, :visibility => 'open'
can :get_id, Project, :visibility => 'open' # api can :get_id, Project, :visibility => 'open' # api
can :archive, Project, :visibility => 'open'
can(:refs_list, Project) {|project| can? :show, project} can(:refs_list, Project) {|project| can? :show, project}
can :read, Issue, :project => {:visibility => 'open'} can :read, Issue, :project => {:visibility => 'open'}
can [:read, :commits, :files], PullRequest, :to_project => {:visibility => 'open'} can [:read, :commits, :files], PullRequest, :to_project => {:visibility => 'open'}

View File

@ -7,7 +7,6 @@ describe Projects::Git::TreesController do
stub_symlink_methods stub_symlink_methods
@project = FactoryGirl.create(:project) @project = FactoryGirl.create(:project)
@another_user = FactoryGirl.create(:user)
@params = { :owner_name => @project.owner.uname, @params = { :owner_name => @project.owner.uname,
:project_name => @project.name, :project_name => @project.name,
:treeish => "#{@project.name}-master"} :treeish => "#{@project.name}-master"}
@ -37,6 +36,17 @@ describe Projects::Git::TreesController do
get :archive, @params.merge(:format => 'tar.gz') get :archive, @params.merge(:format => 'tar.gz')
response.code.should == '401' response.code.should == '401'
end end
it 'should not be able to perform destroy action' do
delete :destroy, @params.merge(:treeish => 'master')
response.should_not be_success
end
it 'should not be able to perform restore_branch action' do
put :restore_branch, @params.merge(:treeish => 'master')
response.should_not be_success
end
end end
context 'for other user' do context 'for other user' do
@ -60,6 +70,16 @@ describe Projects::Git::TreesController do
response.should be_success response.should be_success
end end
it 'should not be able to perform destroy action' do
delete :destroy, @params.merge(:treeish => 'master')
response.should_not be_success
end
it 'should not be able to perform restore_branch action' do
put :restore_branch, @params.merge(:treeish => 'master')
response.should_not be_success
end
[:tags, :branches].each do |action| [:tags, :branches].each do |action|
it "should be able to perform #{action} action" do it "should be able to perform #{action} action" do
get action, @params.merge(:treeish => 'master') get action, @params.merge(:treeish => 'master')
@ -68,5 +88,28 @@ describe Projects::Git::TreesController do
end end
end end
context 'for writer user' do
before(:each) do
user = FactoryGirl.create(:user)
@project.relations.create!(:actor_type => 'User', :actor_id => user.id, :role => 'writer')
set_session_for user
end
it 'should be able to perform destroy action' do
delete :destroy, @params.merge(:treeish => 'conflicts')
response.should be_success
end
it 'should not be able to perform destroy action for master branch' do
delete :destroy, @params.merge(:treeish => 'master')
response.should_not be_success
end
it 'should be able to perform restore_branch action' do
put :restore_branch, @params.merge(:treeish => 'conflicts')
response.should be_success
end
end
after(:all) {clean_projects_dir} after(:all) {clean_projects_dir}
end end