2011-10-27 14:04:03 +01:00
|
|
|
require 'spec_helper'
|
2011-12-15 09:38:40 +00:00
|
|
|
|
|
|
|
shared_examples_for 'personal repository viewer' do
|
|
|
|
it 'should be able to show personal repository' do
|
|
|
|
get :show, :id => @repository.id
|
|
|
|
response.should render_template(:show)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for 'personal repository owner' do
|
|
|
|
it_should_behave_like 'personal repository viewer'
|
|
|
|
|
|
|
|
it 'should be able to perform add_project action' do
|
|
|
|
get :add_project, :id => @repository.id
|
|
|
|
response.should render_template(:projects_list)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be able to add project personal repository with project_id param' do
|
|
|
|
get :add_project, :id => @repository.id, :project_id => @project.id
|
|
|
|
response.should redirect_to(personal_repository_path(@repository))
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be able to perform remove_project action' do
|
|
|
|
get :remove_project, :id => @repository.id, :project_id => @project.id
|
|
|
|
response.should redirect_to(personal_repository_path(@repository))
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
it 'should be able to perform change_visibility action' do
|
|
|
|
get :change_visibility, :id => @repository.id
|
|
|
|
response.should redirect_to(settings_personal_repository_path(@repository))
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be able to change visibility of repository' do
|
|
|
|
get :change_visibility, :id => @repository.id
|
|
|
|
@repository.platform.reload.visibility.should == 'open'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be able to perform settings action' do
|
|
|
|
get :settings, :id => @repository.id
|
|
|
|
response.should render_template(:settings)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-10-27 14:04:03 +01:00
|
|
|
|
|
|
|
describe PersonalRepositoriesController do
|
2011-11-30 09:53:53 +00:00
|
|
|
before(:each) do
|
2011-12-12 07:51:39 +00:00
|
|
|
stub_rsync_methods
|
|
|
|
|
2011-11-30 09:53:53 +00:00
|
|
|
@repository = Factory(:personal_repository)
|
|
|
|
@platform = Factory(:platform)
|
|
|
|
@project = Factory(:project)
|
|
|
|
@another_user = Factory(:user)
|
|
|
|
@create_params = {:repository => {:name => 'pro', :description => 'pro2'}, :platform_id => @platform.id}
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for guest' do
|
|
|
|
[:show, :add_project, :remove_project, :settings, :change_visibility].each do |action|
|
|
|
|
it "should not be able to perform #{ action } action" do
|
|
|
|
get action, :id => @repository.id
|
|
|
|
response.should redirect_to(new_user_session_path)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for admin' do
|
|
|
|
before(:each) do
|
|
|
|
@admin = Factory(:admin)
|
|
|
|
set_session_for(@admin)
|
2011-12-15 21:52:45 +00:00
|
|
|
|
|
|
|
@project.update_attribute(:owner, @admin)
|
2011-11-30 09:53:53 +00:00
|
|
|
end
|
|
|
|
|
2011-12-15 09:38:40 +00:00
|
|
|
it_should_behave_like 'personal repository owner'
|
|
|
|
it_should_behave_like 'repository user with add project rights'
|
|
|
|
it_should_behave_like 'repository user with remove project rights'
|
2011-11-30 09:53:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'for anyone except admin' do
|
|
|
|
before(:each) do
|
|
|
|
@user = Factory(:user)
|
|
|
|
set_session_for(@user)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for owner user' do
|
|
|
|
before(:each) do
|
|
|
|
@user = Factory(:user)
|
|
|
|
set_session_for(@user)
|
|
|
|
|
2011-12-15 21:52:45 +00:00
|
|
|
@project.update_attribute(:owner, @user)
|
|
|
|
|
2011-11-30 09:53:53 +00:00
|
|
|
@repository.update_attribute(:owner, @user)
|
2011-12-06 15:24:04 +00:00
|
|
|
@repository.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')
|
2011-11-30 09:53:53 +00:00
|
|
|
|
|
|
|
@repository.platform.update_attribute(:owner, @user)
|
2011-12-06 15:24:04 +00:00
|
|
|
@repository.platform.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')
|
2011-11-30 09:53:53 +00:00
|
|
|
end
|
|
|
|
|
2011-12-15 09:38:40 +00:00
|
|
|
it_should_behave_like 'personal repository owner'
|
|
|
|
it_should_behave_like 'repository user with add project rights'
|
|
|
|
it_should_behave_like 'repository user with remove project rights'
|
2011-11-30 09:53:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'for reader user' do
|
|
|
|
before(:each) do
|
|
|
|
@user = Factory(:user)
|
|
|
|
set_session_for(@user)
|
2011-12-06 15:24:04 +00:00
|
|
|
@repository.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'reader')
|
2011-11-30 09:53:53 +00:00
|
|
|
end
|
|
|
|
|
2011-12-15 09:38:40 +00:00
|
|
|
it_should_behave_like 'personal repository viewer'
|
2011-11-30 09:53:53 +00:00
|
|
|
|
|
|
|
it 'should not be able to perform add_project action' do
|
|
|
|
get :add_project, :id => @repository.id
|
|
|
|
response.should redirect_to(forbidden_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not be able to perform add_project action with project_id param' do
|
|
|
|
get :add_project, :id => @repository.id, :project_id => @project.id
|
|
|
|
response.should redirect_to(forbidden_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not be able to perform settings action' do
|
|
|
|
get :settings, :id => @repository.id
|
|
|
|
response.should redirect_to(forbidden_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not be able to perform change_visibility action' do
|
|
|
|
get :change_visibility, :id => @repository.id
|
|
|
|
response.should redirect_to(forbidden_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not change visibility of repository' do
|
|
|
|
get :change_visibility, :id => @repository.id
|
|
|
|
@repository.platform.reload.visibility.should == 'hidden'
|
|
|
|
end
|
|
|
|
end
|
2011-10-27 14:04:03 +01:00
|
|
|
|
|
|
|
end
|