2011-11-29 17:45:03 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2012-04-02 16:43:59 +01:00
|
|
|
shared_examples_for 'user with change projects in repository rights' do
|
2012-09-12 12:47:53 +01:00
|
|
|
|
2012-04-02 16:43:59 +01:00
|
|
|
it 'should be able to see add_project page' do
|
|
|
|
get :add_project, :id => @repository.id, :platform_id => @platform.id
|
|
|
|
response.should render_template(:projects_list)
|
|
|
|
end
|
2012-09-12 12:47:53 +01:00
|
|
|
|
2012-04-02 16:43:59 +01:00
|
|
|
it 'should be able to add project to repository' do
|
|
|
|
get :add_project, :id => @repository.id, :platform_id => @platform.id, :project_id => @project.id
|
|
|
|
response.should redirect_to(platform_repository_path(@repository.platform, @repository))
|
2012-08-31 23:00:39 +01:00
|
|
|
@repository.projects.should include(@project)
|
2012-04-02 16:43:59 +01:00
|
|
|
end
|
2012-09-12 12:47:53 +01:00
|
|
|
|
2012-04-02 16:43:59 +01:00
|
|
|
it 'should be able to remove project from repository' do
|
|
|
|
get :remove_project, :id => @repository.id, :platform_id => @platform.id, :project_id => @project.id
|
|
|
|
response.should redirect_to(platform_repository_path(@repository.platform, @repository))
|
2012-08-31 23:00:39 +01:00
|
|
|
@repository.projects.should_not include(@project)
|
2012-04-02 16:43:59 +01:00
|
|
|
end
|
2012-09-12 12:47:53 +01:00
|
|
|
|
|
|
|
end
|
|
|
|
|
2013-07-29 13:24:41 +01:00
|
|
|
shared_examples_for 'user with rights of add/remove sync_lock_file to repository' do
|
|
|
|
it 'should be able to perform sync_lock_file action' do
|
|
|
|
put :sync_lock_file, :id => @repository.id, :platform_id => @platform.id
|
|
|
|
response.should redirect_to(edit_platform_repository_path(@platform, @repository))
|
2013-07-29 10:50:45 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-07-29 13:24:41 +01:00
|
|
|
shared_examples_for 'user without rights of add/remove sync_lock_file to repository' do
|
|
|
|
it 'should not be able to perform #{action} action' do
|
|
|
|
put :sync_lock_file, :id => @repository.id, :platform_id => @platform.id
|
|
|
|
response.should redirect_to(redirect_path)
|
2013-07-29 10:50:45 +01:00
|
|
|
end
|
2012-09-12 12:47:53 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for 'user without change projects in repository rights' do
|
|
|
|
it 'should not be able to add project to repository' do
|
|
|
|
get :add_project, :id => @repository.id, :platform_id => @platform.id, :project_id => @project.id
|
|
|
|
response.should redirect_to(redirect_path)
|
|
|
|
@repository.projects.should_not include(@project)
|
|
|
|
end
|
|
|
|
|
2013-06-14 00:03:02 +01:00
|
|
|
it 'should not be able to perform regenerate_metadata action' do
|
|
|
|
put :regenerate_metadata, :id => @repository.id, :platform_id => @platform.id
|
|
|
|
response.should redirect_to(redirect_path)
|
2013-08-26 19:33:23 +01:00
|
|
|
@repository.repository_statuses.should have(:no).items
|
2013-06-14 00:03:02 +01:00
|
|
|
end
|
|
|
|
|
2012-09-12 12:47:53 +01:00
|
|
|
it 'should not be able to remove project from repository' do
|
|
|
|
delete :remove_project, :id => @repository.id, :platform_id => @platform.id, :project_id => @project.id
|
|
|
|
response.should redirect_to(redirect_path)
|
|
|
|
@repository.projects.should_not include(@project)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-09-12 12:49:42 +01:00
|
|
|
shared_examples_for 'registered user or guest' do
|
2012-09-12 12:47:53 +01:00
|
|
|
it 'should not be able to perform new action' do
|
|
|
|
get :new, :platform_id => @platform.id
|
|
|
|
response.should redirect_to(redirect_path)
|
|
|
|
end
|
|
|
|
|
2013-06-14 00:03:02 +01:00
|
|
|
it 'should not be able to perform regenerate_metadata action' do
|
|
|
|
put :regenerate_metadata, :id => @repository.id, :platform_id => @platform.id
|
|
|
|
response.should redirect_to(redirect_path)
|
2013-08-26 19:33:23 +01:00
|
|
|
@repository.repository_statuses.should have(:no).items
|
2013-06-14 09:29:12 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not be able to perform regenerate_metadata action of personal repository' do
|
|
|
|
put :regenerate_metadata, :id => @personal_repository.id, :platform_id => @personal_repository.platform.id
|
|
|
|
response.should redirect_to(redirect_path)
|
2013-08-26 19:33:23 +01:00
|
|
|
@personal_repository.repository_statuses.should have(:no).items
|
2013-06-14 00:03:02 +01:00
|
|
|
end
|
|
|
|
|
2012-09-12 12:47:53 +01:00
|
|
|
it 'should not be able to perform create action' do
|
|
|
|
post :create, @create_params
|
|
|
|
lambda { post :create, @create_params }.should change{ Repository.count }.by(0)
|
|
|
|
response.should redirect_to(redirect_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not be able to perform edit action' do
|
|
|
|
get :edit, :id => @repository.id, :platform_id => @platform.id
|
|
|
|
response.should redirect_to(redirect_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not be able to perform update action' do
|
|
|
|
put :update, :id => @repository.id, :platform_id => @platform.id
|
|
|
|
response.should redirect_to(redirect_path)
|
|
|
|
end
|
|
|
|
|
2012-09-12 13:40:57 +01:00
|
|
|
it 'should not be able to add new member to repository' do
|
|
|
|
post :add_member, :id => @repository.id, :platform_id => @platform.id, :member_id => @another_user.id
|
|
|
|
response.should redirect_to(redirect_path)
|
|
|
|
@repository.members.should_not include(@another_user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not be able to remove member from repository' do
|
|
|
|
@repository.relations.create(:role => 'admin', :actor => @another_user)
|
|
|
|
delete :remove_member, :id => @repository.id, :platform_id => @platform.id, :member_id => @another_user.id
|
|
|
|
response.should redirect_to(redirect_path)
|
|
|
|
@repository.members.should include(@another_user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not be able to remove members from repository' do
|
|
|
|
another_user2 = FactoryGirl.create(:user)
|
|
|
|
@repository.relations.create(:role => 'admin', :actor => @another_user)
|
|
|
|
@repository.relations.create(:role => 'admin', :actor => another_user2)
|
|
|
|
post :remove_members, :id => @repository.id, :platform_id => @platform.id,
|
|
|
|
:user_remove => {@another_user.id => [1], another_user2.id => [1]}
|
|
|
|
response.should redirect_to(redirect_path)
|
|
|
|
@repository.members.should include(@another_user, another_user2)
|
|
|
|
end
|
|
|
|
|
2012-09-12 12:47:53 +01:00
|
|
|
it 'should not be able to destroy repository in main platform' do
|
2013-04-08 22:43:18 +01:00
|
|
|
delete :destroy, :id => @repository.id, :platform_id => @platform.id
|
2012-09-12 12:47:53 +01:00
|
|
|
response.should redirect_to(redirect_path)
|
|
|
|
lambda { delete :destroy, :id => @repository.id }.should_not change{ Repository.count }.by(-1)
|
|
|
|
end
|
|
|
|
|
2013-04-08 22:43:18 +01:00
|
|
|
it 'should not be able to destroy personal repository' do
|
2013-06-14 09:29:12 +01:00
|
|
|
lambda { delete :destroy, :id => @personal_repository.id, :platform_id => @personal_repository.platform.id}
|
|
|
|
.should change{ Repository.count }.by(0)
|
2013-04-08 22:43:18 +01:00
|
|
|
response.should redirect_to(redirect_path)
|
|
|
|
end
|
2012-04-02 16:43:59 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for 'registered user' do
|
|
|
|
it 'should be able to perform index action' do
|
2012-07-17 09:02:56 +01:00
|
|
|
get :index, :platform_id => @platform.id
|
2012-04-02 16:43:59 +01:00
|
|
|
response.should render_template(:index)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be able to perform show action' do
|
|
|
|
get :show, :id => @repository.id
|
|
|
|
response.should render_template(:show)
|
|
|
|
end
|
2012-09-07 10:41:49 +01:00
|
|
|
|
|
|
|
it 'should be able to perform projects_list action' do
|
|
|
|
get :projects_list, :id => @repository.id, :platform_id => @platform.id, :format => :json
|
|
|
|
response.should be_success
|
|
|
|
end
|
|
|
|
|
2012-04-02 16:43:59 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for 'platform admin user' do
|
|
|
|
|
|
|
|
it_should_behave_like 'registered user'
|
2013-07-29 13:24:41 +01:00
|
|
|
it_should_behave_like 'user with rights of add/remove sync_lock_file to repository'
|
2012-04-02 16:43:59 +01:00
|
|
|
|
|
|
|
it 'should be able to perform new action' do
|
|
|
|
get :new, :platform_id => @platform.id
|
|
|
|
response.should render_template(:new)
|
|
|
|
end
|
|
|
|
|
2013-06-14 00:03:02 +01:00
|
|
|
it 'should be able to perform regenerate_metadata action' do
|
|
|
|
put :regenerate_metadata, :id => @repository.id, :platform_id => @platform.id
|
|
|
|
response.should redirect_to(platform_repository_path(@platform, @repository))
|
2013-08-26 19:33:23 +01:00
|
|
|
@repository.repository_statuses.find_by_platform_id(@platform.id).
|
|
|
|
waiting_for_regeneration?.should be_true
|
2013-06-14 09:29:12 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be able to perform regenerate_metadata action of personal repository' do
|
|
|
|
put :regenerate_metadata, :id => @personal_repository.id, :platform_id => @personal_repository.platform.id, :build_for_platform_id => @platform.id
|
|
|
|
response.should redirect_to(platform_repository_path(@personal_repository.platform, @personal_repository))
|
2013-08-26 19:33:23 +01:00
|
|
|
@personal_repository.repository_statuses.find_by_platform_id(@platform.id).
|
|
|
|
waiting_for_regeneration?.should be_true
|
2013-06-14 09:29:12 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not be able to perform regenerate_metadata action of personal repository when build_for_platform does not exist' do
|
|
|
|
put :regenerate_metadata, :id => @personal_repository.id, :platform_id => @personal_repository.platform.id
|
|
|
|
response.should render_template(:file => "#{Rails.root}/public/404.html")
|
2013-08-26 19:33:23 +01:00
|
|
|
@personal_repository.repository_statuses.should have(:no).items
|
2013-06-14 00:03:02 +01:00
|
|
|
end
|
|
|
|
|
2012-04-02 16:43:59 +01:00
|
|
|
it 'should be able to create repository' do
|
|
|
|
lambda { post :create, @create_params }.should change{ Repository.count }.by(1)
|
|
|
|
response.should redirect_to(platform_repository_path(@platform, Repository.last))
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be able to destroy repository in main platform' do
|
2013-04-08 22:43:18 +01:00
|
|
|
lambda { delete :destroy, :id => @repository.id, :platform_id => @platform.id }.should change{ Repository.count }.by(-1)
|
2012-04-02 16:43:59 +01:00
|
|
|
response.should redirect_to(platform_repositories_path(@repository.platform))
|
|
|
|
end
|
|
|
|
|
2012-09-12 12:47:53 +01:00
|
|
|
it 'should be able to perform edit action' do
|
|
|
|
get :edit, :id => @repository.id, :platform_id => @platform.id
|
|
|
|
response.should render_template(:edit)
|
|
|
|
end
|
|
|
|
|
2012-09-12 13:17:51 +01:00
|
|
|
it 'should be able to add new member to repository' do
|
|
|
|
post :add_member, :id => @repository.id, :platform_id => @platform.id, :member_id => @another_user.id
|
|
|
|
response.should redirect_to(edit_platform_repository_path(@repository.platform, @repository))
|
|
|
|
@repository.members.should include(@another_user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be able to remove member from repository' do
|
|
|
|
@repository.relations.create(:role => 'admin', :actor => @another_user)
|
|
|
|
delete :remove_member, :id => @repository.id, :platform_id => @platform.id, :member_id => @another_user.id
|
|
|
|
response.should redirect_to(edit_platform_repository_path(@repository.platform, @repository))
|
|
|
|
@repository.members.should_not include(@another_user)
|
|
|
|
end
|
|
|
|
|
2012-09-12 13:40:57 +01:00
|
|
|
it 'should be able to remove members from repository' do
|
|
|
|
another_user2 = FactoryGirl.create(:user)
|
|
|
|
@repository.relations.create(:role => 'admin', :actor => @another_user)
|
|
|
|
@repository.relations.create(:role => 'admin', :actor => another_user2)
|
|
|
|
post :remove_members, :id => @repository.id, :platform_id => @platform.id,
|
|
|
|
:user_remove => {@another_user.id => [1], another_user2.id => [1]}
|
|
|
|
response.should redirect_to(edit_platform_repository_path(@repository.platform, @repository))
|
|
|
|
@repository.members.should_not include(@another_user, another_user2)
|
|
|
|
end
|
|
|
|
|
2013-04-08 22:43:18 +01:00
|
|
|
it 'should not be able to destroy personal repository with name "main"' do
|
2013-04-08 22:50:53 +01:00
|
|
|
# hook for "ActiveRecord::ActiveRecordError: name is marked as readonly"
|
2013-04-08 22:43:18 +01:00
|
|
|
Repository.where(:id => @personal_repository.id).update_all("name = 'main'")
|
2013-06-14 09:29:12 +01:00
|
|
|
lambda { delete :destroy, :id => @personal_repository.id, :platform_id => @personal_repository.platform.id}
|
|
|
|
.should change{ Repository.count }.by(0)
|
2013-04-08 22:43:18 +01:00
|
|
|
response.should redirect_to(forbidden_path)
|
2012-09-12 12:47:53 +01:00
|
|
|
end
|
2013-04-08 22:43:18 +01:00
|
|
|
|
|
|
|
it 'should be able to destroy personal repository with name not "main"' do
|
2013-06-14 09:29:12 +01:00
|
|
|
lambda { delete :destroy, :id => @personal_repository.id, :platform_id => @personal_repository.platform.id}
|
|
|
|
.should change{ Repository.count }.by(-1)
|
2013-04-08 22:43:18 +01:00
|
|
|
response.should redirect_to(platform_repositories_path(@personal_repository.platform))
|
2012-09-12 12:47:53 +01:00
|
|
|
end
|
2013-04-08 22:43:18 +01:00
|
|
|
|
|
|
|
it_should_behave_like 'user with change projects in repository rights'
|
2012-04-02 16:43:59 +01:00
|
|
|
end
|
|
|
|
|
2012-05-02 10:18:07 +01:00
|
|
|
describe Platforms::RepositoriesController do
|
2012-04-02 16:43:59 +01:00
|
|
|
before(:each) do
|
2012-05-16 16:29:28 +01:00
|
|
|
stub_symlink_methods
|
2013-06-14 00:03:02 +01:00
|
|
|
stub_redis
|
2011-12-12 07:51:39 +00:00
|
|
|
|
2012-03-29 21:34:22 +01:00
|
|
|
@platform = FactoryGirl.create(:platform)
|
2012-04-02 16:43:59 +01:00
|
|
|
@repository = FactoryGirl.create(:repository, :platform => @platform)
|
|
|
|
@personal_repository = FactoryGirl.create(:personal_repository)
|
2012-03-29 21:34:22 +01:00
|
|
|
@project = FactoryGirl.create(:project)
|
|
|
|
@another_user = FactoryGirl.create(:user)
|
2011-11-29 17:45:03 +00:00
|
|
|
@create_params = {:repository => {:name => 'pro', :description => 'pro2'}, :platform_id => @platform.id}
|
2012-09-07 10:41:49 +01:00
|
|
|
|
|
|
|
@user = FactoryGirl.create(:user)
|
|
|
|
set_session_for(@user)
|
2012-04-02 16:43:59 +01:00
|
|
|
end
|
2011-11-29 17:45:03 +00:00
|
|
|
|
2012-04-02 16:43:59 +01:00
|
|
|
context 'for guest' do
|
2012-09-07 10:41:49 +01:00
|
|
|
|
|
|
|
before(:each) do
|
|
|
|
set_session_for(User.new)
|
2011-11-29 17:45:03 +00:00
|
|
|
end
|
|
|
|
|
2012-09-07 10:41:49 +01:00
|
|
|
it_should_behave_like 'registered user' if APP_CONFIG['anonymous_access']
|
2012-09-12 12:47:53 +01:00
|
|
|
|
|
|
|
let(:redirect_path) { new_user_session_path }
|
2012-09-12 12:49:42 +01:00
|
|
|
it_should_behave_like 'registered user or guest'
|
2012-09-12 12:47:53 +01:00
|
|
|
it_should_behave_like 'user without change projects in repository rights'
|
2013-07-29 13:24:41 +01:00
|
|
|
it_should_behave_like 'user without rights of add/remove sync_lock_file to repository'
|
2012-09-07 10:41:49 +01:00
|
|
|
|
|
|
|
it "should not be able to perform show action", :anonymous_access => false do
|
|
|
|
get :show, :id => @repository
|
|
|
|
response.should redirect_to(new_user_session_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should not be able to perform index action", :anonymous_access => false do
|
|
|
|
get :index, :platform_id => @platform
|
|
|
|
response.should redirect_to(new_user_session_path)
|
2012-08-31 23:00:39 +01:00
|
|
|
end
|
2012-09-07 10:41:49 +01:00
|
|
|
|
|
|
|
it 'should not be able to perform projects_list action', :anonymous_access => false do
|
|
|
|
get :projects_list, :id => @repository.id, :platform_id => @platform.id, :format => :json
|
|
|
|
response.response_code.should == 401
|
|
|
|
end
|
|
|
|
|
2011-11-29 17:45:03 +00:00
|
|
|
end
|
|
|
|
|
2012-09-12 12:47:53 +01:00
|
|
|
context 'for user' do
|
|
|
|
it_should_behave_like 'registered user'
|
|
|
|
|
|
|
|
let(:redirect_path) { forbidden_path }
|
2012-09-12 12:49:42 +01:00
|
|
|
it_should_behave_like 'registered user or guest'
|
2012-09-12 12:47:53 +01:00
|
|
|
it_should_behave_like 'user without change projects in repository rights'
|
2013-07-29 13:24:41 +01:00
|
|
|
it_should_behave_like 'user without rights of add/remove sync_lock_file to repository'
|
2012-09-12 12:47:53 +01:00
|
|
|
end
|
|
|
|
|
2011-11-29 17:45:03 +00:00
|
|
|
context 'for admin' do
|
2012-04-02 16:43:59 +01:00
|
|
|
before(:each) do
|
2012-09-07 10:41:49 +01:00
|
|
|
@user.role = "admin"
|
|
|
|
@user.save
|
2011-11-29 17:45:03 +00:00
|
|
|
end
|
|
|
|
|
2012-04-02 16:43:59 +01:00
|
|
|
it_should_behave_like 'platform admin user'
|
|
|
|
|
|
|
|
end
|
2012-08-31 23:00:39 +01:00
|
|
|
|
2012-04-02 16:43:59 +01:00
|
|
|
context 'for platform owner user' do
|
|
|
|
before(:each) do
|
2012-09-07 10:41:49 +01:00
|
|
|
@user = @repository.platform.owner
|
2013-04-08 22:58:50 +01:00
|
|
|
platform = @personal_repository.platform
|
2013-06-21 13:43:39 +01:00
|
|
|
platform.owner = @user
|
|
|
|
# Owner of personal platform can't be changed
|
|
|
|
platform.save(:validate => false)
|
2012-04-02 16:43:59 +01:00
|
|
|
set_session_for(@user)
|
2011-11-29 17:45:03 +00:00
|
|
|
end
|
|
|
|
|
2012-04-02 16:43:59 +01:00
|
|
|
it_should_behave_like 'platform admin user'
|
2011-11-29 17:45:03 +00:00
|
|
|
end
|
|
|
|
|
2012-09-07 10:41:49 +01:00
|
|
|
context 'for platform member user' do
|
2012-04-02 16:43:59 +01:00
|
|
|
before(:each) do
|
2013-04-08 22:58:50 +01:00
|
|
|
[@repository, @personal_repository].each do |repo|
|
|
|
|
repo.platform.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'admin')
|
|
|
|
end
|
2012-04-02 16:43:59 +01:00
|
|
|
end
|
2012-08-31 23:00:39 +01:00
|
|
|
|
2012-09-07 10:41:49 +01:00
|
|
|
it_should_behave_like 'platform admin user'
|
|
|
|
end
|
|
|
|
|
2012-09-12 12:47:53 +01:00
|
|
|
context 'for repository member user' do
|
|
|
|
before(:each) do
|
2013-04-08 22:58:50 +01:00
|
|
|
[@repository, @personal_repository].each do |repo|
|
2013-07-17 16:33:58 +01:00
|
|
|
repo.add_member @user
|
2013-04-08 22:58:50 +01:00
|
|
|
end
|
2011-11-29 17:45:03 +00:00
|
|
|
end
|
|
|
|
|
2012-09-12 12:47:53 +01:00
|
|
|
it_should_behave_like 'registered user'
|
2012-04-02 16:43:59 +01:00
|
|
|
|
2012-09-12 12:47:53 +01:00
|
|
|
let(:redirect_path) { forbidden_path }
|
2012-09-12 12:49:42 +01:00
|
|
|
it_should_behave_like 'registered user or guest'
|
2012-09-12 12:47:53 +01:00
|
|
|
it_should_behave_like 'user with change projects in repository rights'
|
2013-07-29 13:24:41 +01:00
|
|
|
it_should_behave_like 'user without rights of add/remove sync_lock_file to repository'
|
2013-07-17 16:33:58 +01:00
|
|
|
|
|
|
|
context 'for hidden platform' do
|
|
|
|
before do
|
|
|
|
@platform.update_column(:visibility, 'hidden')
|
|
|
|
@personal_repository.platform.update_column(:visibility, 'hidden')
|
|
|
|
end
|
|
|
|
it_should_behave_like 'registered user'
|
|
|
|
|
|
|
|
let(:redirect_path) { forbidden_path }
|
|
|
|
it_should_behave_like 'registered user or guest'
|
|
|
|
it_should_behave_like 'user with change projects in repository rights'
|
2013-07-29 13:24:41 +01:00
|
|
|
it_should_behave_like 'user without rights of add/remove sync_lock_file to repository'
|
2013-07-17 16:33:58 +01:00
|
|
|
end
|
|
|
|
|
2011-11-29 17:45:03 +00:00
|
|
|
end
|
2012-04-02 16:43:59 +01:00
|
|
|
|
2011-11-29 17:45:03 +00:00
|
|
|
end
|