2011-03-10 11:35:46 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe ProjectsController do
|
2011-11-24 19:22:37 +00:00
|
|
|
before(:each) do
|
2011-12-12 07:51:39 +00:00
|
|
|
stub_rsync_methods
|
|
|
|
|
2011-11-24 19:22:37 +00:00
|
|
|
@project = Factory(:project)
|
|
|
|
@another_user = Factory(:user)
|
2011-11-29 23:41:12 +00:00
|
|
|
@create_params = {:project => {:name => 'pro'}}
|
|
|
|
@update_params = {:project => {:name => 'pro2'}}
|
2011-11-25 16:23:10 +00:00
|
|
|
|
|
|
|
platform = Factory(:platform)
|
|
|
|
@process_build_params = {:build => {
|
|
|
|
:arches => {Factory(:arch).id => '1'},
|
|
|
|
:project_version => 'v1.0',
|
|
|
|
:bpl => {platform.id => '1'},
|
|
|
|
:pl => platform.id,
|
|
|
|
:update_type => 'security'
|
|
|
|
}}
|
2011-12-07 09:46:48 +00:00
|
|
|
|
|
|
|
any_instance_of(Project, :versions => ['v1.0', 'v2.0'])
|
2011-11-24 19:22:37 +00:00
|
|
|
end
|
2011-03-10 11:35:46 +00:00
|
|
|
|
2011-11-24 19:22:37 +00:00
|
|
|
context 'for guest' do
|
|
|
|
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
|
2011-11-26 00:54:40 +00:00
|
|
|
put :update, {:id => @project.id}.merge(@update_params)
|
|
|
|
response.should redirect_to(new_user_session_path)
|
2011-11-24 19:22:37 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for admin' do
|
|
|
|
before(:each) do
|
|
|
|
@admin = Factory(:admin)
|
|
|
|
set_session_for(@admin)
|
|
|
|
end
|
|
|
|
|
2011-12-15 09:38:40 +00:00
|
|
|
it_should_behave_like 'projects user with writer rights'
|
|
|
|
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
|
|
|
|
response.should redirect_to(project_path( Project.last.id ))
|
|
|
|
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
|
|
|
|
before(:each) do
|
|
|
|
@user = Factory(:user)
|
|
|
|
set_session_for(@user)
|
|
|
|
@project.update_attribute(:owner, @user)
|
2011-12-06 15:24:04 +00:00
|
|
|
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin')
|
2011-11-24 19:22:37 +00:00
|
|
|
end
|
|
|
|
|
2011-12-15 09:38:40 +00:00
|
|
|
it_should_behave_like 'projects user with writer rights'
|
|
|
|
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
|
|
|
|
delete :destroy, {:id => @project.id}
|
|
|
|
response.should redirect_to(@project.owner)
|
|
|
|
end
|
|
|
|
|
2011-11-29 14:36:51 +00:00
|
|
|
it 'should change objects count on destroy' do
|
2011-12-05 09:29:17 +00:00
|
|
|
lambda { delete :destroy, :id => @project.id }.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
|
|
|
|
post :fork, :id => @project.id
|
|
|
|
response.should redirect_to(forbidden_path)
|
|
|
|
end
|
2011-11-24 19:22:37 +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
|
|
|
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'reader')
|
2011-11-24 19:22:37 +00:00
|
|
|
end
|
|
|
|
|
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
|
|
|
|
2011-11-29 14:36:51 +00:00
|
|
|
it 'should be able to perform show action' do
|
2011-11-24 19:22:37 +00:00
|
|
|
get :show, :id => @project.id
|
|
|
|
response.should render_template(:show)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for writer user' do
|
|
|
|
before(:each) do
|
|
|
|
@user = Factory(:user)
|
|
|
|
set_session_for(@user)
|
2011-12-06 15:24:04 +00:00
|
|
|
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'writer')
|
2011-11-24 19:22:37 +00:00
|
|
|
end
|
|
|
|
|
2011-12-15 09:38:40 +00:00
|
|
|
it_should_behave_like 'projects user with writer rights'
|
|
|
|
it_should_behave_like 'projects user with reader rights'
|
2011-11-24 19:22:37 +00:00
|
|
|
end
|
2011-12-16 00:33:44 +00:00
|
|
|
|
|
|
|
context 'search projects' do
|
|
|
|
|
|
|
|
before(:each) do
|
|
|
|
@admin = Factory(:admin)
|
|
|
|
@project1 = Factory(:project, :name => 'perl-debug')
|
|
|
|
@project2 = Factory(:project, :name => 'perl')
|
|
|
|
set_session_for(@admin)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should return projects in right order' do
|
|
|
|
get :index, :query => 'per'
|
|
|
|
assigns(:projects).should eq([@project2, @project1])
|
|
|
|
end
|
|
|
|
end
|
2011-03-10 11:35:46 +00:00
|
|
|
end
|