[refs #263] Test refactoring

This commit is contained in:
Vladimir Sharshov 2012-09-06 14:53:03 +04:00
parent 0ff8f92b62
commit 698e55e3e8
16 changed files with 289 additions and 265 deletions

View File

@ -5,9 +5,7 @@ class Projects::ProjectsController < Projects::BaseController
def index
@projects = Project.accessible_by(current_ability, :membered)
# @projects = @projects.search(params[:query]).search_order if params[:query].present?
#puts prepare_list(@projects).inspect
respond_to do |format|
format.html { @projects = @projects.recent.paginate(:page => params[:page], :per_page => 25) }
format.json { @projects = prepare_list(@projects) }

View File

@ -45,7 +45,7 @@ class MassBuild < ActiveRecord::Base
end
def cancel_all
self.stop_build = true; save(:validate => false)
update_column(:stop_build, true)
build_lists.find_each(:batch_size => 100) do |bl|
bl.cancel
end

View File

@ -169,6 +169,8 @@ ActiveRecord::Schema.define(:version => 20120730214052) do
t.datetime "updated_at", :null => false
end
add_index "projects", ["owner_id"], :name => "index_projects_on_name_and_owner_id_and_owner_type", :unique => true, :case_sensitive => false
create_table "groups", :force => true do |t|
t.integer "owner_id"
t.datetime "created_at", :null => false
@ -253,7 +255,7 @@ ActiveRecord::Schema.define(:version => 20120730214052) do
t.string "owner_type"
t.string "visibility", :default => "open", :null => false
t.string "platform_type", :default => "main", :null => false
t.string "distrib_type"
t.string "distrib_type", :null => false
end
add_index "platforms", ["name"], :name => "index_platforms_on_name", :unique => true, :case_sensitive => false

View File

@ -129,7 +129,8 @@ describe Groups::ProfileController do
before(:each) do
@user = FactoryGirl.create(:user)
set_session_for(@user)
@group.owner = @user; @group.save
@group.owner = @user
@group.save
@group.actors.create(:actor_type => 'User', :actor_id => @user.id, :role => 'admin')
end

View File

@ -126,7 +126,9 @@ describe Platforms::KeyPairsController do
before(:each) do
@user = FactoryGirl.create(:user)
set_session_for(@user)
@platform.owner = @user; @platform.save
@platform.owner = @user
@platform.save
end
it_should_behave_like 'key_pair platform owner'

View File

@ -133,7 +133,9 @@ describe Platforms::MassBuildsController do
before(:each) do
@user = FactoryGirl.create(:user)
set_session_for(@user)
@platform.owner = @user; @platform.save
@platform.owner = @user
@platform.save
end
it_should_behave_like 'mass_build platform owner'

View File

@ -104,7 +104,10 @@ describe Platforms::PlatformsController do
before(:each) do
@user = FactoryGirl.create(:user)
set_session_for(@user)
@platform.owner = @user; @platform.save
@platform.owner = @user
@platform.save
@platform.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'admin')
end

View File

@ -326,7 +326,7 @@ describe Projects::BuildListsController do
describe 'publish_build' do
before {
test_git_commit(build_list.project)
build_list.update_column :commit_hash, build_list.project.repo.commits('master').last.id
build_list.update_column(:commit_hash, build_list.project.repo.commits('master').last.id)
build_list.update_column(:status, BuildList::BUILD_PUBLISH)
build_list_package
}

View File

@ -6,12 +6,14 @@ shared_context "collaborators controller" do
stub_symlink_methods
@project = FactoryGirl.create(:project)
@another_user = FactoryGirl.create(:user)
@group = FactoryGirl.create(:group)
@member_user = FactoryGirl.create(:user)
# Create relation with 'writer' rights
@collaborator = Collaborator.create(:actor => @member_user, :project => @project, :role => 'writer')
end
def set_params
@user = FactoryGirl.create(:user)
set_session_for(@user)
@user_params = {
:actor_id => @another_user.id.to_s,
:actor_type => 'user',
@ -26,11 +28,7 @@ shared_context "collaborators controller" do
:owner_name => @project.owner.uname, :project_name => @project.name,
:format => :json
}
@update_params = {
:owner_name => @project.owner.uname, :project_name => @project.name,
:collaborator => {:role => 'reader'},
:format => :json
}
@update_params = @create_params.merge(:collaborator => {:role => 'reader'})
end
end
@ -82,7 +80,9 @@ describe Projects::CollaboratorsController do
include_context "collaborators controller"
context 'for guest' do
before {set_params}
before(:each) do
set_session_for(User.new)
end
it 'should not be able to perform index action' do
get :index, :owner_name => @project.owner.uname, :project_name => @project.name
response.should redirect_to(new_user_session_path)
@ -96,10 +96,8 @@ describe Projects::CollaboratorsController do
context 'for global admin' do
before(:each) do
@admin = FactoryGirl.create(:admin)
set_session_for(@admin)
@group = FactoryGirl.create(:group)
set_params
@user.role = "admin"
@user.save
end
it_should_behave_like 'project admin user'
@ -107,11 +105,7 @@ describe Projects::CollaboratorsController do
context 'for admin user' do
before(:each) do
@user = FactoryGirl.create(:user)
set_session_for(@user)
@group = FactoryGirl.create(:group)
@project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'admin')
set_params
end
it_should_behave_like 'project admin user'
@ -119,13 +113,8 @@ describe Projects::CollaboratorsController do
context 'for owner user' do
before(:each) do
@user = FactoryGirl.create(:user)
@user = @project.owner # owner should be user
set_session_for(@user)
@group = FactoryGirl.create(:group)
@project.owner = @user; @project.save!; @project.reload
@project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'admin')
set_params
end
it_should_behave_like 'project admin user'
@ -133,10 +122,7 @@ describe Projects::CollaboratorsController do
context 'for reader user' do
before(:each) do
@user = FactoryGirl.create(:user)
set_session_for(@user)
@project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'reader')
set_params
end
it_should_behave_like 'user with no rights for this project'
@ -144,10 +130,7 @@ describe Projects::CollaboratorsController do
context 'for writer user' do
before(:each) do
@user = FactoryGirl.create(:user)
set_session_for(@user)
@project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'writer')
set_params
end
it_should_behave_like 'user with no rights for this project'

View File

@ -9,17 +9,16 @@ shared_context "comments controller" do
@issue = FactoryGirl.create(:issue, :project_id => @project.id, :user => FactoryGirl.create(:user))
@comment = FactoryGirl.create(:comment, :commentable => @issue, :project_id => @project.id)
any_instance_of(Project, :versions => ['v1.0', 'v2.0'])
@user = FactoryGirl.create(:user)
set_session_for(@user)
@own_comment = FactoryGirl.create(:comment, :commentable => @issue, :user => @user, :project_id => @project.id)
set_session_for(@user)
@address = {:owner_name => @project.owner.uname, :project_name => @project.name, :issue_id => @issue.serial_id}
@create_params = {:comment => {:body => 'I am a comment!'}}.merge(@address)
@update_params = {:comment => {:body => 'updated'}}.merge(@address)
end
def set_params
@create_params = {:comment => {:body => 'I am a comment!'}, :owner_name => @project.owner.uname, :project_name => @project.name, :issue_id => @issue.serial_id}
@update_params = {:comment => {:body => 'updated'}, :owner_name => @project.owner.uname, :project_name => @project.name, :issue_id => @issue.serial_id}
end
end
shared_examples_for 'user with create comment rights' do
@ -28,7 +27,7 @@ shared_examples_for 'user with create comment rights' do
response.should redirect_to(project_issue_path(@project, @issue))
end
it 'should create subscribe object into db' do
it 'should create comment in the database' do
lambda{ post :create, @create_params }.should change{ Comment.count }.by(1)
end
end
@ -39,7 +38,7 @@ shared_examples_for 'user with update own comment rights' do
response.should redirect_to([@project, @issue])
end
it 'should update subscribe body' do
it 'should update comment body' do
put :update, {:id => @own_comment.id}.merge(@update_params)
@own_comment.reload.body.should == 'updated'
end
@ -71,33 +70,44 @@ end
shared_examples_for 'user without destroy comment rights' do
it 'should not be able to perform destroy action' do
delete :destroy, :id => @comment.id, :issue_id => @issue.serial_id, :owner_name => @project.owner.uname, :project_name => @project.name
delete :destroy, {:id => @comment.id}.merge(@address)
response.should redirect_to(forbidden_path)
end
it 'should not reduce comments count' do
lambda{ delete :destroy, :id => @comment.id, :issue_id => @issue.serial_id, :owner_name => @project.owner.uname, :project_name => @project.name }.should change{ Issue.count }.by(0)
it 'should not delete comment from database' do
lambda{ delete :destroy, {:id => @comment.id}.merge(@address)}.should change{ Issue.count }.by(0)
end
end
#shared_examples_for 'user with destroy rights' do
# it 'should be able to perform destroy action' do
# delete :destroy, :id => @comment.id, :issue_id => @issue.id, :owner_name => @project.owner.uname, :project_name => @project.name
# response.should redirect_to([@project, @issue])
# end
#
# it 'should reduce comments count' do
# lambda{ delete :destroy, :id => @comment.id, :issue_id => @issue.id, :owner_name => @project.owner.uname, :project_name => @project.name }.should change{ Comment.count }.by(-1)
# end
#end
shared_examples_for 'user with destroy comment rights' do
it 'should be able to perform destroy action' do
delete :destroy, {:id => @comment.id}.merge(@address)
response.should redirect_to([@project, @issue])
end
it 'should delete comment from database' do
lambda{ delete :destroy, {:id => @comment.id}.merge(@address)}.should change{ Comment.count }.by(-1)
end
end
describe Projects::CommentsController do
include_context "comments controller"
context 'for global admin user' do
before(:each) do
@user.role = "admin"
@user.save
end
it_should_behave_like 'user with create comment rights'
it_should_behave_like 'user with update stranger comment rights'
it_should_behave_like 'user with update own comment rights'
it_should_behave_like 'user with destroy comment rights'
end
context 'for project admin user' do
before(:each) do
@project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'admin')
set_params
end
it_should_behave_like 'user with create comment rights'
@ -108,11 +118,7 @@ describe Projects::CommentsController do
context 'for project owner user' do
before(:each) do
@project.owner = @user; @project.save!; @project.reload; @project.owner.reload
# @project.relations.destroy_all
# @project.relations.create! :actor_id => @project.owner_id, :actor_type => @project.owner_type, :role => 'admin'
# @create_params[:owner_name] = @user.uname; @update_params[:owner_name] = @user.uname
set_params
set_session_for(@project.owner) # owner should be user
end
it_should_behave_like 'user with create comment rights'
@ -124,7 +130,6 @@ describe Projects::CommentsController do
context 'for project reader user' do
before(:each) do
@project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'reader')
set_params
end
it_should_behave_like 'user with create comment rights'
@ -136,7 +141,6 @@ describe Projects::CommentsController do
context 'for project writer user' do
before(:each) do
@project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'writer')
set_params
end
it_should_behave_like 'user with create comment rights'

View File

@ -8,8 +8,6 @@ shared_context "issues controller" do
@project = FactoryGirl.create(:project)
@issue_user = FactoryGirl.create(:user)
any_instance_of(Project, :versions => ['v1.0', 'v2.0'])
@issue = FactoryGirl.create(:issue, :project_id => @project.id, :assignee_id => @issue_user.id)
@project_with_turned_off_issues = FactoryGirl.create(:project, :has_issues => false)
@ -47,7 +45,7 @@ shared_examples_for 'issue user with project reader rights' do
end
it 'should be able to perform index action on hidden project' do
@project.update_attributes :visibility => 'hidden'
@project.update_attributes(:visibility => 'hidden')
get :index, :owner_name => @project.owner.uname, :project_name => @project.name
response.should render_template(:index)
end
@ -143,7 +141,9 @@ describe Projects::IssuesController do
before(:each) do
@user = FactoryGirl.create(:user)
set_session_for(@user)
@project.owner = @user; @project.save!; @project.reload
@project.owner = @user
@project.save!
@project.reload
@project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'admin')
set_params
end
@ -220,7 +220,7 @@ describe Projects::IssuesController do
end
it 'should not be able to perform index action on hidden project' do
@project.update_attributes :visibility => 'hidden'
@project.update_attributes(:visibility => 'hidden')
get :index, :owner_name => @project.owner.uname, :project_name => @project.name
response.should redirect_to(forbidden_path)
end
@ -236,7 +236,7 @@ describe Projects::IssuesController do
end
it 'should not be able to perform index action on hidden project' do
@project.update_attributes :visibility => 'hidden'
@project.update_attributes(:visibility => 'hidden')
get :index, :owner_name => @project.owner.uname, :project_name => @project.name
response.should redirect_to(new_user_session_path)
end

View File

@ -1,217 +1,277 @@
# -*- encoding : utf-8 -*-
require 'spec_helper'
shared_examples_for 'projects user with reader rights' do
it 'should be able to fork project' do
post :fork, :owner_name => @project.owner.uname, :project_name => @project.name
response.should redirect_to(project_path(Project.last))
end
it 'should be able to fork project to their group' do
group = FactoryGirl.create(:group)
group.actors.create(:actor_type => 'User', :actor_id => @user.id, :role => 'admin')
lambda {post :fork, :owner_name => @project.owner.uname, :project_name => @project.name,
:group => group.id}.should change{ Project.count }.by(1)
end
it 'should be able to fork project to own group' do
group = FactoryGirl.create(:group, :owner => @user)
lambda {post :fork, :owner_name => @project.owner.uname, :project_name => @project.name,
:group => group.id}.should change{ Project.count }.by(1)
end
# it 'should be able to view project' do
# get :show, :owner_name => @project.owner.uname, :project_name => @project.name
# assigns(:project).should eq @project
# end
end
shared_examples_for 'projects user with project admin rights' do
it 'should be able to perform update action' do
put :update, {:owner_name => @project.owner.uname, :project_name => @project.name}.merge(@update_params)
response.should redirect_to(project_path(@project))
end
end
shared_examples_for 'user with destroy rights' do
it 'should be able to perform destroy action' do
delete :destroy, {:owner_name => @project.owner.uname, :project_name => @project.name}
response.should redirect_to(@project.owner)
end
it 'should change objects count on destroy' do
lambda { delete :destroy, :owner_name => @project.owner.uname, :project_name => @project.name }.should change{ Project.count }.by(-1)
end
end
shared_examples_for 'projects user without project admin rights' do
it 'should not be able to edit project' do
description = @project.description
put :update, :project=>{:description =>"hack"}, :owner_name => @project.owner.uname, :project_name => @project.name
@project.reload.description.should == description
response.should redirect_to(forbidden_path)
end
it 'should not be able to edit project sections' do
has_wiki, has_issues = @project.has_wiki, @project.has_issues
post :sections, :project =>{:has_wiki => !has_wiki, :has_issues => !has_issues}, :owner_name => @project.owner.uname, :project_name => @project.name
@project.reload.has_wiki.should == has_wiki
@project.reload.has_issues.should == has_issues
response.should redirect_to(forbidden_path)
end
end
describe Projects::ProjectsController do
before(:each) do
stub_symlink_methods
@project = FactoryGirl.create(:project)
@another_user = FactoryGirl.create(:user)
@create_params = {:project => {:name => 'pro'}}
@update_params = {:project => {:description => 'pro2'}}
@user = FactoryGirl.create(:user)
set_session_for(@user)
end
context 'for guest' do
it 'should not be able to perform index action' do
get :index
response.should redirect_to(new_user_session_path)
context 'for system users' do
context 'guest' do
before(:each) do
set_session_for(User.new)
end
it 'should not be able to perform index action' do
get :index
response.should redirect_to(new_user_session_path)
end
it 'should not be able to perform update action' do
put :update, {:owner_name => @project.owner.uname, :project_name => @project.name}.merge(@update_params)
response.should redirect_to(new_user_session_path)
end
end
it 'should not be able to perform update action' do
put :update, {:owner_name => @project.owner.uname, :project_name => @project.name}.merge(@update_params)
response.should redirect_to(new_user_session_path)
end
end
context 'registered user' do
it 'should be able to perform index action' do
get :index
response.should render_template(:index)
end
context 'create project for myself' do
it 'should be able to perform create action' do
post :create, @create_params
response.should redirect_to(project_path( Project.last ))
end
it 'should create project in the database' do
lambda { post :create, @create_params }.should change{ Project.count }.by(1)
end
end
context 'create project for group' do
it 'should not be able to create project for alien 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
it 'should be able to create project for their group' do
group = FactoryGirl.create(:group)
group.actors.create(:actor_type => 'User', :actor_id => @user.id, :role => 'admin')
lambda { post :create, @create_params.merge({:who_owns => 'group', :owner_id => group.id})}.should change{ Project.count }.by(1)
end
it 'should be able to create project for own group' do
group = FactoryGirl.create(:group, :owner => @user)
lambda { post :create, @create_params.merge({:who_owns => 'group', :owner_id => group.id})}.should change{ Project.count }.by(1)
end
end
end # context 'registered user'
end # context 'for system users'
context 'for project members' do
context 'for global admin' do
before(:each) do
@user.role = "admin"
@user.save
set_session_for(@user)
end
it_should_behave_like 'projects user with project admin rights'
it_should_behave_like 'projects user with reader rights'
it_should_behave_like 'user with destroy rights'
context 'for admin' do
before(:each) do
@admin = FactoryGirl.create(:admin)
set_session_for(@admin)
end
it_should_behave_like 'projects user with admin rights'
it_should_behave_like 'projects user with reader rights'
context 'for owner user' do
before(:each) do
@user = @project.owner
set_session_for(@user) # owner should be user
end
it_should_behave_like 'projects user with project admin rights'
it_should_behave_like 'projects user with reader rights'
it_should_behave_like 'user with destroy rights'
it 'should not be able to fork own project' do
post :fork, :owner_name => @project.owner.uname, :project_name => @project.name
response.should redirect_to(@project)
end
it 'should be able to perform create action' do
post :create, @create_params
response.should redirect_to(project_path( Project.last ))
end
it 'should change objects count on create' do
lambda { post :create, @create_params }.should change{ Project.count }.by(1)
end
end
context 'for reader user' do
before(:each) do
@project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'reader')
end
context 'for owner user' do
before(:each) do
@user = FactoryGirl.create(:user)
set_session_for(@user)
@project.owner = @user; @project.save!; @project.reload
@project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'admin')
it_should_behave_like 'projects user with reader rights'
it_should_behave_like 'projects user without project admin rights'
end
it_should_behave_like 'projects user with admin rights'
it_should_behave_like 'user with rights to view projects'
context 'for writer user' do
before(:each) do
@project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'writer')
end
it_should_behave_like 'projects user with reader rights'
it_should_behave_like 'projects user without project admin rights'
it 'should be able to perform destroy action' do
delete :destroy, {:owner_name => @project.owner.uname, :project_name => @project.name}
response.should redirect_to(@project.owner)
end
it 'should change objects count on destroy' do
lambda { delete :destroy, :owner_name => @project.owner.uname, :project_name => @project.name }.should change{ Project.count }.by(-1)
context 'for other user' do
it 'should not be able to fork hidden project' do
@project.update_attributes(:visibility => 'hidden')
post :fork, :owner_name => @project.owner.uname, :project_name => @project.name
response.should redirect_to(forbidden_path)
end
it_should_behave_like 'projects user without project admin rights'
end
it 'should not be able to fork project' do
post :fork, :owner_name => @project.owner.uname, :project_name => @project.name
# @project.errors.count.should == 1
response.should redirect_to(@project)
end
end
context 'for reader user' do
before(:each) do
@user = FactoryGirl.create(:user)
set_session_for(@user)
@project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'reader')
end
it_should_behave_like 'projects user with reader rights'
it_should_behave_like 'user without update rights'
end
context 'for writer user' do
before(:each) do
@user = FactoryGirl.create(:user)
set_session_for(@user)
@project.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'writer')
end
it_should_behave_like 'projects user with reader rights'
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
it 'should not be able to fork project to other group' do
group = FactoryGirl.create(:group)
post :fork, :owner_name => @project.owner.uname, :project_name => @project.name, :group => group.id
response.should redirect_to(forbidden_path)
end
it 'should be able to fork project to group' do
group = FactoryGirl.create(:group)
group.actors.create(:actor_type => 'User', :actor_id => @user.id, :role => 'admin')
post :fork, :owner_name => @project.owner.uname, :project_name => @project.name, :group => group.id
response.should redirect_to(project_path(group.projects.first))
end
end
context 'search projects' do
before(:each) do
@admin = FactoryGirl.create(:admin)
@project1 = FactoryGirl.create(:project, :name => 'perl-debug')
@project2 = FactoryGirl.create(:project, :name => 'perl')
set_session_for(@admin)
end
pending 'should return projects in right order' do
get :index, :query => 'per'
assigns(:projects).should eq([@project2, @project1])
end
end
context 'for other user' do
before(:each) do
@user = FactoryGirl.create(:user)
set_session_for(@user)
end
it 'should not be able to fork hidden project' do
@project.update_attributes(:visibility => 'hidden')
post :fork, :owner_name => @project.owner.uname, :project_name => @project.name
response.should redirect_to(forbidden_path)
end
it_should_behave_like 'user without update rights'
end
end # context 'for project members'
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
context 'group is owner of the project' do
before(:each) do
@project.owner = @group; @project.save!; @project.reload
@project.relations.create :actor_id => @project.owner.id, :actor_type => @project.owner.class.to_s, :role => 'admin'
@project = FactoryGirl.create(:project, :owner => @group)
end
context 'reader user' do
context 'group member user with reader role' do
before(:each) do
@group.actors.create(:actor_id => @group_user.id, :actor_type => 'User', :role => 'reader')
@group.actors.create(:actor_id => @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_behave_like 'projects user without project admin rights'
it 'should has reader role to group project' do
@group_user.best_role(@project).should eql('reader') # Need this?
@user.best_role(@project).should eql('reader')
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'
@project.relations.create :actor_id => @user.id, :actor_type => @user.class.to_s, :role => 'admin'
end
it_should_behave_like 'projects user with admin rights'
it_should_behave_like 'projects user with project admin rights'
end
end
context 'admin user' do
context 'group member user with admin role' do
before(:each) do
@group.actors.create(:actor_id => @group_user.id, :actor_type => 'User', :role => 'admin')
@group.actors.create(:actor_id => @user.id, :actor_type => 'User', :role => 'admin')
end
it_should_behave_like 'projects user with admin rights'
it_should_behave_like 'projects user with project admin rights'
it_should_behave_like 'projects user with reader rights'
end
end
context 'member of the project' do
context 'group is 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
context 'group member user with reader role' do
before(:each) do
@group.actors.create(:actor_id => @group_user.id, :actor_type => 'User', :role => 'reader')
@group.actors.create(:actor_id => @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'
it_should_behave_like 'projects user with project 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'
@project.relations.create :actor_id => @user.id, :actor_type => @user.class.to_s, :role => 'reader'
end
it_should_behave_like 'projects user with admin rights'
it_should_behave_like 'projects user with project admin rights'
end
end
context 'admin user' do
context 'group member user with admin role' do
before(:each) do
@group.actors.create(:actor_id => @group_user.id, :actor_type => 'User', :role => 'admin')
@group.actors.create(:actor_id => @user.id, :actor_type => 'User', :role => 'admin')
end
it_should_behave_like 'projects user with admin rights'
it_should_behave_like 'projects user with project admin rights'
it_should_behave_like 'projects user with reader rights'
end
end
@ -221,29 +281,29 @@ describe Projects::ProjectsController do
@project.relations.create :actor_id => @group.id, :actor_type => @group.class.to_s, :role => 'reader'
end
context 'reader user' do
context 'group member user with reader role' do
before(:each) do
@group.actors.create(:actor_id => @group_user.id, :actor_type => 'User', :role => 'reader')
@group.actors.create(:actor_id => @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_behave_like 'projects user without project 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 => 'admin'
@project.relations.create :actor_id => @user.id, :actor_type => @user.class.to_s, :role => 'admin'
end
it_should_behave_like 'projects user with admin rights'
it_should_behave_like 'projects user with project admin rights'
end
end
context 'admin user' do
context 'group member user with admin role' do
before(:each) do
@group.actors.create(:actor_id => @group_user.id, :actor_type => 'User', :role => 'admin')
@group.actors.create(:actor_id => @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'
it_should_behave_like 'projects user without project admin rights'
end
end
end

View File

@ -123,7 +123,9 @@ describe CanCan do
context "private users relations" do
before(:each) do
@private_user = FactoryGirl.create(:private_user)
@private_user.platform.owner = @user; @private_user.platform.save
@private_user.platform.owner = @user
@private_user.platform.save
end
[:read, :create].each do |action|
@ -207,7 +209,9 @@ describe CanCan do
context 'with owner rights' do
before(:each) do
@project.owner = @user; @project.save
@project.owner = @user
@project.save
@project.relations.create!(:actor_id => @user.id, :actor_type => 'User', :role => 'admin')
@issue.project.reload
end
@ -241,7 +245,8 @@ describe CanCan do
context 'with owner rights' do
before(:each) do
@platform.owner = @user; @platform.save
@platform.owner = @user
@platform.save
end
[:read, :update, :destroy].each do |action|

View File

@ -148,7 +148,10 @@ describe Comment do
@user = FactoryGirl.create(:user)
@stranger = FactoryGirl.create(:user)
set_comments_data_for_commit
@project.owner = @user; @project.save
@project.owner = @user
@project.save
ActionMailer::Base.deliveries = []
end

View File

@ -61,8 +61,11 @@ describe Group do
context 'for group owner' do
before(:each) do
@user = FactoryGirl.create(:user)
@group.owner = @user; @group.save
@user = FactoryGirl.create(:user)
@group.owner = @user
@group.save
@group.actors.create(:actor_type => 'User', :actor_id => @user.id, :role => 'admin')
@ability = Ability.new(@user)
end

View File

@ -1,42 +0,0 @@
# -*- encoding : utf-8 -*-
shared_examples_for 'projects user with reader rights' do
include_examples 'user with rights to view projects' # nested shared_examples_for dont work
it 'should be able to fork project' do
post :fork, :owner_name => @project.owner.uname, :project_name => @project.name
response.should redirect_to(project_path(Project.last))
end
end
shared_examples_for 'projects user with admin rights' do
it 'should be able to perform update action' do
put :update, {:owner_name => @project.owner.uname, :project_name => @project.name}.merge(@update_params)
response.should redirect_to(project_path(@project))
end
end
shared_examples_for 'user with rights to view projects' do
it 'should be able to perform index action' do
get :index
response.should render_template(:index)
end
end
shared_examples_for 'user without update rights' do
it 'should not be able to edit project' do
description = @project.description
put :update, :project=>{:description =>"hack"}, :owner_name => @project.owner.uname, :project_name => @project.name
Project.find(@project.id).description.should == description
response.should redirect_to(forbidden_path)
end
it 'should not be able to edit project sections' do
has_wiki, has_issues = @project.has_wiki, @project.has_issues
post :sections, :project =>{:has_wiki => !has_wiki, :has_issues => !has_issues}, :owner_name => @project.owner.uname, :project_name => @project.name
project = Project.find(@project.id)
project.has_wiki.should == has_wiki
project.has_issues.should == has_issues
response.should redirect_to(forbidden_path)
end
end