2012-01-30 20:39:34 +00:00
|
|
|
# -*- encoding : utf-8 -*-
|
2011-03-10 11:35:46 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2012-05-02 10:18:07 +01:00
|
|
|
describe Projects::ProjectsController do
|
2012-04-10 10:40:38 +01:00
|
|
|
|
|
|
|
before(:each) do
|
2012-05-16 16:29:28 +01:00
|
|
|
stub_symlink_methods
|
2011-12-12 07:51:39 +00:00
|
|
|
|
2012-03-29 21:34:22 +01:00
|
|
|
@project = FactoryGirl.create(:project)
|
|
|
|
@another_user = FactoryGirl.create(:user)
|
2011-11-29 23:41:12 +00:00
|
|
|
@create_params = {:project => {:name => 'pro'}}
|
2012-04-19 20:45:50 +01:00
|
|
|
@update_params = {:project => {:description => 'pro2'}}
|
2012-04-10 10:40:38 +01:00
|
|
|
end
|
2011-03-10 11:35:46 +00:00
|
|
|
|
2012-04-10 10:40:38 +01:00
|
|
|
context 'for guest' do
|
2011-11-24 19:22:37 +00:00
|
|
|
it 'should not be able to perform index action' do
|
2011-11-26 00:54:40 +00:00
|
|
|
get :index
|
|
|
|
response.should redirect_to(new_user_session_path)
|
2011-11-24 19:22:37 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not be able to perform update action' do
|
2012-04-19 20:45:50 +01:00
|
|
|
put :update, {:owner_name => @project.owner.uname, :project_name => @project.name}.merge(@update_params)
|
2011-11-26 00:54:40 +00:00
|
|
|
response.should redirect_to(new_user_session_path)
|
2011-11-24 19:22:37 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for admin' do
|
2012-04-10 10:40:38 +01:00
|
|
|
before(:each) do
|
|
|
|
@admin = FactoryGirl.create(:admin)
|
|
|
|
set_session_for(@admin)
|
|
|
|
end
|
2011-11-24 19:22:37 +00:00
|
|
|
|
2011-12-28 02:57:42 +00:00
|
|
|
it_should_behave_like 'projects user with admin rights'
|
2011-12-15 09:38:40 +00:00
|
|
|
it_should_behave_like 'projects user with reader rights'
|
2011-11-24 19:22:37 +00:00
|
|
|
|
|
|
|
it 'should be able to perform create action' do
|
|
|
|
post :create, @create_params
|
2012-04-19 20:45:50 +01:00
|
|
|
response.should redirect_to(project_path( Project.last ))
|
2011-11-24 19:22:37 +00:00
|
|
|
end
|
|
|
|
|
2011-11-29 14:36:51 +00:00
|
|
|
it 'should change objects count on create' do
|
|
|
|
lambda { post :create, @create_params }.should change{ Project.count }.by(1)
|
2011-11-24 19:22:37 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for owner user' do
|
2012-04-10 10:40:38 +01:00
|
|
|
before(:each) do
|
|
|
|
@user = FactoryGirl.create(:user)
|
|
|
|
set_session_for(@user)
|
|
|
|
@project.update_attribute(:owner, @user)
|
2012-04-26 02:38:33 +01:00
|
|
|
@project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'admin')
|
2012-04-10 10:40:38 +01:00
|
|
|
end
|
2011-11-24 19:22:37 +00:00
|
|
|
|
2011-12-28 02:57:42 +00:00
|
|
|
it_should_behave_like 'projects user with admin rights'
|
2011-12-15 09:38:40 +00:00
|
|
|
it_should_behave_like 'user with rights to view projects'
|
2011-11-25 16:23:10 +00:00
|
|
|
|
|
|
|
it 'should be able to perform destroy action' do
|
2012-04-19 20:45:50 +01:00
|
|
|
delete :destroy, {:owner_name => @project.owner.uname, :project_name => @project.name}
|
2011-11-25 16:23:10 +00:00
|
|
|
response.should redirect_to(@project.owner)
|
|
|
|
end
|
|
|
|
|
2011-11-29 14:36:51 +00:00
|
|
|
it 'should change objects count on destroy' do
|
2012-04-19 20:45:50 +01:00
|
|
|
lambda { delete :destroy, :owner_name => @project.owner.uname, :project_name => @project.name }.should change{ Project.count }.by(-1)
|
2011-11-29 14:36:51 +00:00
|
|
|
end
|
|
|
|
|
2011-11-25 16:23:10 +00:00
|
|
|
it 'should not be able to fork project' do
|
2012-04-19 20:45:50 +01:00
|
|
|
post :fork, :owner_name => @project.owner.uname, :project_name => @project.name
|
|
|
|
# @project.errors.count.should == 1
|
|
|
|
response.should redirect_to(@project)
|
2011-11-25 16:23:10 +00:00
|
|
|
end
|
2012-04-10 10:40:38 +01:00
|
|
|
|
2011-11-24 19:22:37 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'for reader user' do
|
2012-04-10 10:40:38 +01:00
|
|
|
before(:each) do
|
|
|
|
@user = FactoryGirl.create(:user)
|
|
|
|
set_session_for(@user)
|
2012-04-26 02:38:33 +01:00
|
|
|
@project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'reader')
|
2012-04-10 10:40:38 +01:00
|
|
|
end
|
2011-11-24 19:22:37 +00:00
|
|
|
|
2011-12-15 09:38:40 +00:00
|
|
|
it_should_behave_like 'projects user with reader rights'
|
2012-06-19 19:24:35 +01:00
|
|
|
it_should_behave_like 'user without update rights'
|
2011-11-24 19:22:37 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'for writer user' do
|
2012-04-10 10:40:38 +01:00
|
|
|
before(:each) do
|
|
|
|
@user = FactoryGirl.create(:user)
|
|
|
|
set_session_for(@user)
|
2012-04-26 02:38:33 +01:00
|
|
|
@project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'writer')
|
2012-04-10 10:40:38 +01:00
|
|
|
end
|
2011-11-24 19:22:37 +00:00
|
|
|
|
2011-12-15 09:38:40 +00:00
|
|
|
it_should_behave_like 'projects user with reader rights'
|
2012-04-09 18:56:03 +01:00
|
|
|
|
2012-04-10 10:40:38 +01:00
|
|
|
it 'should not be able to create project to other group' do
|
|
|
|
group = FactoryGirl.create(:group)
|
|
|
|
post :create, @create_params.merge({:who_owns => 'group', :owner_id => group.id})
|
|
|
|
response.should redirect_to(forbidden_path)
|
|
|
|
end
|
|
|
|
|
2012-04-09 18:56:03 +01:00
|
|
|
it 'should not be able to fork project to other group' do
|
|
|
|
group = FactoryGirl.create(:group)
|
2012-04-19 20:45:50 +01:00
|
|
|
post :fork, :owner_name => @project.owner.uname, :project_name => @project.name, :group => group.id
|
2012-04-09 18:56:03 +01:00
|
|
|
response.should redirect_to(forbidden_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be able to fork project to group' do
|
|
|
|
group = FactoryGirl.create(:group)
|
2012-04-26 02:38:33 +01:00
|
|
|
group.actors.create(:actor_type => 'User', :actor_id => @user.id, :role => 'admin')
|
2012-04-19 20:45:50 +01:00
|
|
|
post :fork, :owner_name => @project.owner.uname, :project_name => @project.name, :group => group.id
|
2012-05-02 10:18:07 +01:00
|
|
|
response.should redirect_to(project_path(group.projects.first))
|
2012-04-09 18:56:03 +01:00
|
|
|
end
|
2011-11-24 19:22:37 +00:00
|
|
|
end
|
2011-12-16 00:33:44 +00:00
|
|
|
|
|
|
|
context 'search projects' do
|
|
|
|
before(:each) do
|
2012-03-29 21:34:22 +01:00
|
|
|
@admin = FactoryGirl.create(:admin)
|
|
|
|
@project1 = FactoryGirl.create(:project, :name => 'perl-debug')
|
|
|
|
@project2 = FactoryGirl.create(:project, :name => 'perl')
|
2011-12-16 00:33:44 +00:00
|
|
|
set_session_for(@admin)
|
|
|
|
end
|
|
|
|
|
2012-03-07 21:34:49 +00:00
|
|
|
pending 'should return projects in right order' do
|
2011-12-16 00:33:44 +00:00
|
|
|
get :index, :query => 'per'
|
|
|
|
assigns(:projects).should eq([@project2, @project1])
|
|
|
|
end
|
|
|
|
end
|
2012-04-10 10:40:38 +01:00
|
|
|
|
|
|
|
context 'for other user' do
|
2012-05-15 11:36:36 +01:00
|
|
|
before(:each) do
|
2012-04-10 10:40:38 +01:00
|
|
|
@user = FactoryGirl.create(:user)
|
|
|
|
set_session_for(@user)
|
2012-05-15 11:36:36 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not be able to fork hidden project' do
|
2012-04-10 10:40:38 +01:00
|
|
|
@project.update_attribute(:visibility, 'hidden')
|
2012-04-19 20:45:50 +01:00
|
|
|
post :fork, :owner_name => @project.owner.uname, :project_name => @project.name
|
2012-04-23 21:55:42 +01:00
|
|
|
response.should redirect_to(forbidden_path)
|
2012-04-10 10:40:38 +01:00
|
|
|
end
|
2012-05-15 11:36:36 +01:00
|
|
|
|
2012-06-19 19:24:35 +01:00
|
|
|
it_should_behave_like 'user without update rights'
|
|
|
|
end
|
2012-05-15 11:36:36 +01:00
|
|
|
|
2012-06-19 19:24:35 +01:00
|
|
|
context 'for group' do
|
|
|
|
before(:each) do
|
|
|
|
@group = FactoryGirl.create(:group)
|
|
|
|
@group_user = FactoryGirl.create(:user)
|
|
|
|
@project.relations.destroy_all
|
|
|
|
set_session_for(@group_user)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'owner of the project' do
|
|
|
|
before(:each) do
|
|
|
|
@project.update_attribute :owner, @group
|
|
|
|
@project.relations.create :actor_id => @project.owner.id, :actor_type => @project.owner.class.to_s, :role => 'admin'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'reader user' do
|
|
|
|
before(:each) do
|
|
|
|
@group.actors.create(:actor_id => @group_user.id, :actor_type => 'User', :role => 'reader')
|
|
|
|
end
|
|
|
|
|
|
|
|
it_should_behave_like 'projects user with reader rights'
|
|
|
|
it_should_behave_like 'user without update rights'
|
|
|
|
|
|
|
|
it 'should has reader role to group project' do
|
|
|
|
@group_user.best_role(@project).should eql('reader') # Need this?
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'user should has best role' do
|
|
|
|
before(:each) do
|
|
|
|
@project.relations.create :actor_id => @group_user.id, :actor_type => @group_user.class.to_s, :role => 'admin'
|
|
|
|
end
|
|
|
|
it_should_behave_like 'projects user with admin rights'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'admin user' do
|
|
|
|
before(:each) do
|
|
|
|
@group.actors.create(:actor_id => @group_user.id, :actor_type => 'User', :role => 'admin')
|
|
|
|
end
|
|
|
|
|
|
|
|
it_should_behave_like 'projects user with admin rights'
|
|
|
|
it_should_behave_like 'projects user with reader rights'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'member of the project' do
|
|
|
|
context 'with admin rights' do
|
|
|
|
before(:each) do
|
|
|
|
@project.relations.create :actor_id => @group.id, :actor_type => @group.class.to_s, :role => 'admin'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'reader user' do
|
|
|
|
before(:each) do
|
|
|
|
@group.actors.create(:actor_id => @group_user.id, :actor_type => 'User', :role => 'reader')
|
|
|
|
end
|
|
|
|
|
|
|
|
it_should_behave_like 'projects user with reader rights'
|
|
|
|
it_should_behave_like 'projects user with admin rights'
|
|
|
|
|
|
|
|
context 'user should has best role' do
|
|
|
|
before(:each) do
|
|
|
|
@project.relations.create :actor_id => @group_user.id, :actor_type => @group_user.class.to_s, :role => 'reader'
|
|
|
|
end
|
|
|
|
it_should_behave_like 'projects user with admin rights'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'admin user' do
|
|
|
|
before(:each) do
|
|
|
|
@group.actors.create(:actor_id => @group_user.id, :actor_type => 'User', :role => 'admin')
|
|
|
|
end
|
|
|
|
|
|
|
|
it_should_behave_like 'projects user with admin rights'
|
|
|
|
it_should_behave_like 'projects user with reader rights'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with reader rights' do
|
|
|
|
before(:each) do
|
|
|
|
@project.relations.create :actor_id => @group.id, :actor_type => @group.class.to_s, :role => 'reader'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'reader user' do
|
|
|
|
before(:each) do
|
|
|
|
@group.actors.create(:actor_id => @group_user.id, :actor_type => 'User', :role => 'reader')
|
|
|
|
end
|
|
|
|
|
|
|
|
it_should_behave_like 'projects user with reader rights'
|
|
|
|
it_should_behave_like 'user without update rights'
|
|
|
|
|
|
|
|
context 'user should has best role' do
|
|
|
|
before(:each) do
|
|
|
|
@project.relations.create :actor_id => @group_user.id, :actor_type => @group_user.class.to_s, :role => 'admin'
|
|
|
|
end
|
|
|
|
it_should_behave_like 'projects user with admin rights'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'admin user' do
|
|
|
|
before(:each) do
|
|
|
|
@group.actors.create(:actor_id => @group_user.id, :actor_type => 'User', :role => 'admin')
|
|
|
|
end
|
|
|
|
|
|
|
|
it_should_behave_like 'projects user with reader rights'
|
|
|
|
it_should_behave_like 'user without update rights'
|
|
|
|
end
|
|
|
|
end
|
2012-05-15 11:36:36 +01:00
|
|
|
end
|
2012-04-10 10:40:38 +01:00
|
|
|
end
|
2011-03-10 11:35:46 +00:00
|
|
|
end
|