[#345] fix relations create; refactoring specs; remove unneded files

This commit is contained in:
Alexander Machehin 2014-03-18 15:31:01 +06:00
parent 1a97bfb67c
commit 4cf3e931bd
41 changed files with 165 additions and 269 deletions

View File

@ -4,7 +4,7 @@ module Owner
included do
validates :owner, presence: true
after_create do
relations.create({ actor_id: owner.id, actor_type: owner.class.to_s, role: 'admin' }, without_protection: true)
relations.create(actor: owner, role: 'admin')
end
end
end

View File

@ -9,7 +9,7 @@ class Relation < ActiveRecord::Base
# validate { errors.add(:actor, :taken) if Relation.where(actor_type: self.actor_type, actor_id: self.actor_id).present? }
before_validation :add_default_role
attr_accessible :actor_id, :actor_type, :target_id, :target_type, :role
attr_accessible :actor_id, :actor_type, :target_id, :target_type, :actor, :target, :role
scope :by_user_through_groups, ->(u) {
where("actor_type = 'User' AND actor_id = ? OR actor_type = 'Group' AND actor_id IN (?)", u.id, u.group_ids)

View File

@ -132,7 +132,7 @@ describe Api::V1::AdvisoriesController do
context 'for user who has access to update build_list' do
before do
@user = FactoryGirl.create(:user)
@build_list.save_to_platform.relations.create(role: 'admin', actor: @user)
create_relation @build_list.save_to_platform, @user, 'admin'
http_login(@user)
end

View File

@ -110,8 +110,8 @@ describe Api::V1::BuildListsController do
@user = FactoryGirl.create(:user)
@owner_user = @project.owner
@member_user = FactoryGirl.create(:user)
@project.relations.create(role: 'reader', actor: @member_user)
@build_list.save_to_platform.relations.create(role: 'admin', actor: @owner_user) # Why it's really need it??
create_relation(@project, @member_user, 'reader')
create_relation @build_list.save_to_platform, @owner_user, 'admin' # Why it's really need it??
# Create and show params:
@create_params = {build_list: @build_list.attributes.symbolize_keys.merge(:qwerty=>'!')} # wrong parameter
@ -541,7 +541,7 @@ describe Api::V1::BuildListsController do
@another_user = FactoryGirl.create(:user)
@build_list.update_column(:status, BuildList::SUCCESS)
@build_list.save_to_repository.update_column(:publish_without_qa, true)
@build_list.project.relations.create!(actor_type: 'User', actor_id: @another_user.id, role: 'writer')
create_relation(@build_list.project, @another_user, 'writer')
http_login(@another_user)
do_reject_publish
end
@ -631,11 +631,11 @@ describe Api::V1::BuildListsController do
# Groups:
@owner_group = FactoryGirl.create(:group, owner: @owner_user)
@member_group = FactoryGirl.create(:group)
@member_group.actors.create role: 'reader', actor_id: @member_user.id, actor_type: 'User'
create_actor_relation(@member_group, @member_user, 'reader')
@group = FactoryGirl.create(:group)
@user = FactoryGirl.create(:user)
@group.actors.create role: 'reader', actor_id: @user.id, actor_type: 'User'
create_actor_relation(@group, @user, 'reader')
old_path = @project.path
@project.owner = @owner_group
@ -643,10 +643,10 @@ describe Api::V1::BuildListsController do
# Move GIT repo into new folder
system "mkdir -p #{@project.path} && mv -f #{old_path}/* #{@project.path}/"
@project.relations.create role: 'reader', actor_id: @member_group.id, actor_type: 'Group'
@project.relations.create role: 'admin', actor_id: @owner_group.id, actor_type: 'Group'
@build_list.save_to_platform.relations.create(role: 'admin', actor: @owner_group) # Why it's really need it??
@build_list.save_to_platform.relations.create(role: 'reader', actor: @member_group) # Why it's really need it??
create_relation(@project, @member_group, 'reader')
create_relation(@project, @owner_group, 'admin')
create_relation(@build_list.save_to_platform, @owner_group, 'admin') # Why it's really need it??
create_relation(@build_list.save_to_platform, @member_group, 'reader') # Why it's really need it??
http_login(@user)
end
@ -704,7 +704,7 @@ describe Api::V1::BuildListsController do
@build_list4 = FactoryGirl.create(:build_list)
@build_list4.project.update_column(:visibility, 'hidden')
@build_list4.project.relations.create! role: 'reader', actor_id: @user.id, actor_type: 'User'
create_relation(@build_list4, @user, 'reader')
@filter_build_list1 = FactoryGirl.create(:build_list)
@filter_build_list2 = FactoryGirl.create(:build_list)
@ -787,8 +787,8 @@ describe Api::V1::BuildListsController do
stub_symlink_methods
@owner_user = @project.owner
@member_user = FactoryGirl.create(:user)
@project.relations.create(role: 'reader', actor: @member_user)
@build_list.save_to_platform.relations.create(role: 'admin', actor: @owner_user) # Why it's really need it??
create_relation(@project, @member_user, 'reader')
create_relation(@build_list.save_to_platform, @owner_user, 'admin') # Why it's really need it??
# Show params:
@show_params = {id: @build_list.id, format: :json}
@ -843,7 +843,6 @@ describe Api::V1::BuildListsController do
stub_symlink_methods
@owner_user = @project.owner#FactoryGirl.create(:user)
@member_user = FactoryGirl.create(:user)
#@project.relations.create(role: 'reader', actor: @member_user)
# Show params:
@show_params = {id: @build_list.id, format: :json}
@ -851,17 +850,10 @@ describe Api::V1::BuildListsController do
# Groups:
@owner_group = FactoryGirl.create(:group, owner: @owner_user)
@member_group = FactoryGirl.create(:group)
@member_group.actors.create role: 'reader', actor_id: @member_user.id, actor_type: 'User'
create_actor_relation(@member_group, @member_user, 'reader')
@group = FactoryGirl.create(:group)
@group.actors.create role: 'reader', actor_id: @user.id, actor_type: 'User'
#@project = FactoryGirl.create(:project, owner: @owner_group, repositories: @platform.repositories)
#@project.owner = @owner_group
#@project.save
@project.relations.create role: 'reader', actor_id: @member_group.id, actor_type: 'Group'
#@build_list.save_to_platform.relations.create(role: 'reader', actor: @member_group) # Why it's really need it??
#@build_list.save_to_platform.relations.create(role: 'admin', actor: @owner_group) # Why it's really need it??
create_actor_relation(@group, @user, 'reader')
create_relation(@project, @member_group, 'reader')
end
context 'for open project' do

View File

@ -11,7 +11,7 @@ describe Api::V1::IssuesController do
@membered_issue = FactoryGirl.create(:issue)
@membered_project = @membered_issue.project
@membered_project.relations.create(role: 'reader', actor: @issue.user)
create_relation(@membered_project, @issue.user, 'reader')
@open_issue = FactoryGirl.create(:issue)
@open_project = @open_issue.project

View File

@ -365,7 +365,7 @@ describe Api::V1::PlatformsController do
before do
http_login(@user)
@platform.owner = @user; @platform.save
@platform.relations.create!(actor_type: 'User', actor_id: @user.id, role: 'admin')
create_relation(@platform, @user, 'admin')
end
it_should_behave_like 'api platform user with reader rights'

View File

@ -57,7 +57,7 @@ end
shared_examples_for 'api user with admin rights' do
before(:each) do
@product_build_list.product.platform.relations.create!(actor_type: 'User', actor_id: @another_user.id, role: 'admin')
create_relation(@product_build_list.product.platform, @another_user, 'admin')
http_login(@another_user)
commit_hash = @product_build_list.project.repo.commits.first.id
params = {product_id: @product_build_list.product_id, arch_id: Arch.last.id,

View File

@ -57,7 +57,7 @@ end
shared_examples_for 'api user with admin rights' do
before(:each) do
@product.platform.relations.create!(actor_type: 'User', actor_id: @another_user.id, role: 'admin')
create_relation(@product.platform, @another_user, 'admin')
http_login(@another_user)
params = {platform_id: @product.platform.id, project_id: @product.project.id}
@create_params = {product:{name: 'pro', time_living: 150}.merge(params)}

View File

@ -326,13 +326,13 @@ describe Api::V1::ProjectsController do
it 'writer group 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: 'writer')
create_actor_relation(group, @muser, 'writer')
lambda { post :create, params.deep_merge({project: {owner_type: 'Group', owner_id: group.id}})}.should change{ Project.count }.by(1)
end
it 'reader group should not be able to create project for their group' do
group = FactoryGirl.create(:group)
group.actors.create(actor_type: 'User', actor_id: @user.id, role: 'reader')
create_actor_relation(@group, @user, 'reader')
lambda { post :create, params.deep_merge({project: {owner_type: 'Group', owner_id: group.id}})}.should change{ Project.count }.by(0)
end
end
@ -347,13 +347,13 @@ describe Api::V1::ProjectsController do
context 'group writer' do
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: 'writer')
create_actor_relation(group, @user, 'writer')
lambda {post :fork, id: @project.id, group_id: group.id}.should change{ Project.count }.by(1)
end
it 'should be able to fork project with different name to their group' do
group = FactoryGirl.create(:group)
group.actors.create(actor_type: 'User', actor_id: @user.id, role: 'writer')
create_actor_relation(group, @user, 'writer')
new_name = @project.name + '_forked'
lambda { post :fork, id: @project.id, group_id: group.id, fork_name: new_name }.should
change { Project.where(name: new_name).count }.by(1)
@ -363,14 +363,14 @@ describe Api::V1::ProjectsController do
context 'group reader' do
it 'should not be able to fork project to their group' do
group = FactoryGirl.create(:group)
group.actors.create(actor_type: 'User', actor_id: @user.id, role: 'reader')
create_actor_relation(group, @user, 'reader')
lambda {post :fork, id: @project.id, group_id: group.id}.should change{ Project.count }.by(0)
end
it 'should not be able to fork project with different name to their group' do
group = FactoryGirl.create(:group)
new_name = @project.name + '_forked'
group.actors.create(actor_type: 'User', actor_id: @user.id, role: 'reader')
create_actor_relation(group, @user, 'reader')
lambda { post :fork, id: @project.id, group_id: group.id, fork_name: new_name }.should
change{ Project.where(name: new_name.count) }.by(0)
end
@ -410,7 +410,7 @@ describe Api::V1::ProjectsController do
before(:each) do
@user = FactoryGirl.create(:user)
http_login(@user)
@project.relations.create!(actor_type: 'User', actor_id: @user.id, role: 'reader')
create_relation(@project, @user, 'reader')
end
it_should_behave_like 'api projects user with reader rights'
@ -425,7 +425,7 @@ describe Api::V1::ProjectsController do
before(:each) do
@user = FactoryGirl.create(:user)
http_login(@user)
@project.relations.create!(actor_type: 'User', actor_id: @user.id, role: 'writer')
create_relation(@project, @user, 'writer')
end
it_should_behave_like 'api projects user with reader rights'
@ -459,9 +459,7 @@ describe Api::V1::ProjectsController do
end
context 'reader user' do
before(:each) do
@group.actors.create(actor_id: @group_user.id, actor_type: 'User', role: 'reader')
end
before(:each) { create_actor_relation(@group, @group_user, 'reader') }
it_should_behave_like 'api projects user with reader rights'
it_should_behave_like 'api projects user with reader rights for hidden project'
@ -472,9 +470,7 @@ describe Api::V1::ProjectsController do
end
context 'admin user' do
before(:each) do
@group.actors.create(actor_id: @group_user.id, actor_type: 'User', role: 'admin')
end
before(:each) { create_actor_relation(@group, @group_user, 'admin') }
it_should_behave_like 'api projects user with reader rights'
it_should_behave_like 'api projects user with reader rights for hidden project'
@ -488,13 +484,11 @@ describe Api::V1::ProjectsController do
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'
create_relation(@project, @group, 'admin')
end
context 'reader user' do
before(:each) do
@group.actors.create(actor_id: @group_user.id, actor_type: 'User', role: 'reader')
end
before(:each) { create_actor_relation(@group, @group_user, 'reader') }
it_should_behave_like 'api projects user with reader rights'
it_should_behave_like 'api projects user with reader rights for hidden project'
@ -505,9 +499,7 @@ describe Api::V1::ProjectsController do
end
context 'admin user' do
before(:each) do
@group.actors.create(actor_id: @group_user.id, actor_type: 'User', role: 'admin')
end
before(:each) { create_actor_relation(@group, @group_user, 'admin') }
it_should_behave_like 'api projects user with reader rights'
it_should_behave_like 'api projects user with reader rights for hidden project'
@ -519,14 +511,10 @@ describe Api::V1::ProjectsController do
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
before(:each) { create_relation(@project, @group, 'reader') }
context 'reader user' do
before(:each) do
@group.actors.create(actor_id: @group_user.id, actor_type: 'User', role: 'reader')
end
before(:each) { create_actor_relation(@group, @group_user, 'reader') }
it_should_behave_like 'api projects user with reader rights'
it_should_behave_like 'api projects user with reader rights for hidden project'
@ -536,9 +524,8 @@ describe Api::V1::ProjectsController do
it_should_behave_like 'api projects user without owner 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
before(:each) { create_relation(@project, @group_user, 'admin') }
it_should_behave_like 'api projects user with reader rights'
it_should_behave_like 'api projects user with fork rights'
it_should_behave_like 'api projects user with fork rights for hidden project'
@ -548,9 +535,7 @@ describe Api::V1::ProjectsController do
end
context 'admin user' do
before(:each) do
@group.actors.create(actor_id: @group_user.id, actor_type: 'User', role: 'admin')
end
before(:each) { create_actor_relation(@group, @group_user, 'admin') }
it_should_behave_like 'api projects user with reader rights'
it_should_behave_like 'api projects user with reader rights for hidden project'

View File

@ -29,7 +29,7 @@ describe Api::V1::PullRequestsController do
@membered_project = FactoryGirl.create(:project_with_commit)
@membered_pull = create_pull 'master', 'non_conflicts', @membered_project.owner, @membered_project
@membered_project.relations.create(role: 'reader', actor: @pull.user)
create_relation(@membered_project, @pull.user, 'reader')
@create_params = {pull_request: {title: 'title', body: 'body',
from_ref: 'conflicts', to_ref: 'master'},
@ -276,11 +276,11 @@ describe Api::V1::PullRequestsController do
context 'send email messages' do
before(:each) do
@project_reader = FactoryGirl.create :user
@project.relations.create!(actor_type: 'User', actor_id: @project_reader.id, role: 'reader')
create_relation(@project, @project_reader, 'reader')
@project_admin = FactoryGirl.create :user
@project.relations.create!(actor_type: 'User', actor_id: @project_admin.id, role: 'admin')
create_relation(@project, @project_admin, 'admin')
@project_writer = FactoryGirl.create :user
@project.relations.create!(actor_type: 'User', actor_id: @project_writer.id, role: 'writer')
create_relation(@project, @project_writer, 'writer')
http_login(@project_writer)
ActionMailer::Base.deliveries = []

View File

@ -351,7 +351,7 @@ describe Api::V1::RepositoriesController do
[@repository, @personal_repository].each do |repository|
platform = repository.platform
platform.owner = @user; platform.save
repository.platform.relations.create!(actor_type: 'User', actor_id: @user.id, role: 'admin')
create_relation(repository.platform, @user, 'admin')
end
end

View File

@ -35,7 +35,7 @@ describe Groups::MembersController do
context 'for admin user' do
before(:each) do
@admin_user = FactoryGirl.create(:user)
@group.actors.create(actor_id: @admin_user.id, actor_type: 'User', role: 'admin')
create_actor_relation(@group, @admin_user, 'admin')
set_session_for @admin_user
end
@ -68,7 +68,7 @@ describe Groups::MembersController do
context 'for writer user' do
before(:each) do
@writer_user = FactoryGirl.create(:user)
@group.actors.create(actor_id: @writer_user.id, actor_type: 'User', role: 'writer')
create_actor_relation(@group, @writer_user, 'writer')
set_session_for @writer_user
end

View File

@ -129,7 +129,7 @@ describe Groups::ProfileController do
before(:each) do
@user = FactoryGirl.create(:user)
set_session_for(@user)
@group.actors.create(actor_type: 'User', actor_id: @user.id, role: 'admin')
create_actor_relation(@group, @user, 'admin')
end
it_should_behave_like 'group user with project show rights'
@ -144,7 +144,7 @@ describe Groups::ProfileController do
set_session_for(@user)
@group.owner = @user
@group.save
@group.actors.create(actor_type: 'User', actor_id: @user.id, role: 'admin')
create_actor_relation(@group, @user, 'admin')
end
it_should_behave_like 'group user with project show rights'
@ -156,7 +156,7 @@ describe Groups::ProfileController do
before(:each) do
@user = FactoryGirl.create(:user)
set_session_for(@user)
@group.actors.create(actor_type: 'User', actor_id: @user.id, role: 'reader')
create_actor_relation(@group, @user, 'reader')
end
it "should remove user from groups" do

View File

@ -67,7 +67,7 @@ describe Platforms::ContentsController do
before do
http_login(@user)
@platform.owner = @user; @platform.save
@platform.relations.create!(actor_type: 'User', actor_id: @user.id, role: 'admin')
create_relation(@platform, @user, 'admin')
end
it_should_behave_like 'content platform user with show rights'

View File

@ -139,7 +139,7 @@ describe Platforms::KeyPairsController do
before(:each) do
@user = FactoryGirl.create(:user)
set_session_for(@user)
@platform.relations.create!(actor_type: 'User', actor_id: @user.id, role: 'admin')
create_relation(@platform, @user, 'admin')
end
it_should_behave_like 'key_pair platform owner'
@ -149,7 +149,7 @@ describe Platforms::KeyPairsController do
before(:each) do
@user = FactoryGirl.create(:user)
set_session_for(@user)
@platform.relations.create!(actor_type: 'User', actor_id: @user.id, role: 'reader')
create_relation(@platform, @user, 'reader')
end
it_should_behave_like 'key_pair platform reader'

View File

@ -57,12 +57,10 @@ describe Platforms::MaintainersController do
context 'for platform member' do
before(:each) do
@platform.relations.create!(actor_type: 'User', actor_id: @user.id, role: 'admin')
create_relation(@platform, @user, 'admin')
end
it_should_behave_like 'guest user'
end
end

View File

@ -213,7 +213,7 @@ describe Platforms::MassBuildsController do
before(:each) do
@user = FactoryGirl.create(:user)
set_session_for(@user)
@platform.relations.create!(actor_type: 'User', actor_id: @user.id, role: 'admin')
create_relation(@platform, @user, 'admin')
end
it_should_behave_like 'mass_build platform owner'
@ -224,7 +224,7 @@ describe Platforms::MassBuildsController do
before(:each) do
@user = FactoryGirl.create(:user)
set_session_for(@user)
@platform.relations.create!(actor_type: 'User', actor_id: @user.id, role: 'reader')
create_relation(@platform, @user, 'reader')
end
it_should_behave_like 'mass_build platform reader'

View File

@ -353,7 +353,7 @@ describe Platforms::PlatformsController do
before do
http_login(@user)
@platform.owner = @user; @platform.save
@platform.relations.create!(actor_type: 'User', actor_id: @user.id, role: 'admin')
create_relation(@platform, @user, 'admin')
end
it_should_behave_like 'platform user with reader rights'

View File

@ -145,7 +145,7 @@ describe Platforms::ProductBuildListsController do
before(:each) do
@user = FactoryGirl.create(:user)
set_session_for(@user)
@product.platform.relations.create!(actor_type: 'User', actor_id: @user.id, role: 'admin')
create_relation(@product.platform, @user, 'admin')
end
it_should_behave_like 'product build list admin'

View File

@ -93,7 +93,7 @@ describe Platforms::ProductsController do
context 'for admin relation user' do
before(:each) do
@platform.relations.create!(actor_type: 'User', actor_id: @user.id, role: 'admin')
create_relation(@platform, @user, 'admin')
end
it_should_behave_like 'admin user'

View File

@ -96,7 +96,7 @@ shared_examples_for 'registered user or guest' do
end
it 'should not be able to remove member from repository' do
@repository.relations.create(role: 'admin', actor: @another_user)
create_relation(@repository, @another_user, 'admin')
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)
@ -104,8 +104,8 @@ shared_examples_for 'registered user or guest' do
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)
create_relation(@repository, @another_user, 'admin')
create_relation(@repository, @another_user2, 'admin')
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)
@ -195,7 +195,7 @@ shared_examples_for 'platform admin user' do
end
it 'should be able to remove member from repository' do
@repository.relations.create(role: 'admin', actor: @another_user)
create_relation(@repository, @another_user, 'admin')
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)
@ -203,8 +203,8 @@ shared_examples_for 'platform admin user' do
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)
create_relation(@repository, @another_user, 'admin')
create_relation(@repository, @another_user2, 'admin')
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))
@ -309,7 +309,7 @@ describe Platforms::RepositoriesController do
context 'for platform member user' do
before(:each) do
[@repository, @personal_repository].each do |repo|
repo.platform.relations.create!(actor_type: 'User', actor_id: @user.id, role: 'admin')
create_relation(repo.platform, @user, 'admin')
end
end

View File

@ -95,7 +95,7 @@ describe Platforms::TokensController do
before(:each) do
@user = FactoryGirl.create(:user)
set_session_for(@user)
@platform.relations.create!(actor_type: 'User', actor_id: @user.id, role: 'admin')
create_relation(@platform, @user, 'admin')
end
it_should_behave_like 'token of platform for owner'
@ -105,7 +105,7 @@ describe Platforms::TokensController do
before do
@user = FactoryGirl.create(:user)
set_session_for(@user)
@platform.relations.create!(actor_type: 'User', actor_id: @user.id, role: 'reader')
create_relation(@platform, @user, 'reader')
end
it_should_behave_like 'token of platform for simple user or guest' do

View File

@ -116,9 +116,8 @@ describe Projects::BuildListsController do
@project = @build_list.project
@owner_user = @project.owner
@member_user = FactoryGirl.create(:user)
rel = @project.relations.build(role: 'reader')
rel.actor = @member_user
rel.save
create_relation(@project, @member_user, 'reader')
@user = FactoryGirl.create(:user)
set_session_for(@user)
@show_params = {owner_name: @project.owner.uname, project_name: @project.name, id: @build_list.id}
@ -205,7 +204,7 @@ describe Projects::BuildListsController do
@writer_user = FactoryGirl.create(:user)
@build_list.update_column(:status, BuildList::SUCCESS)
@build_list.save_to_repository.update_column(:publish_without_qa, true)
@build_list.project.relations.create!(actor_type: 'User', actor_id: @writer_user.id, role: 'writer')
create_relation(@build_list.project, @writer_user, 'writer')
set_session_for(@writer_user)
do_reject_publish
end
@ -232,7 +231,7 @@ describe Projects::BuildListsController do
@build_list4 = FactoryGirl.create(:build_list)
@build_list4.project.update_column(:visibility, 'hidden')
@build_list4.project.relations.create! role: 'reader', actor_id: @user.id, actor_type: 'User'
create_relation(@build_list4.project, @user, 'reader')
end
it 'should be able to perform index action' do
@ -314,8 +313,8 @@ describe Projects::BuildListsController do
@member_group = FactoryGirl.create(:group)
@member_user = FactoryGirl.create(:user)
@member_group.actors.create role: 'reader', actor_id: @member_user.id, actor_type: 'User'
@project.relations.create role: 'reader', actor_id: @member_group.id, actor_type: 'Group'
create_actor_relation(@member_group, @member_user, 'reader')
create_relation(@project, @member_group, 'reader')
@show_params = {owner_name: @project.owner.uname, project_name: @project.name, id: @build_list.id}
end
@ -332,7 +331,7 @@ describe Projects::BuildListsController do
@build_list4 = FactoryGirl.create(:build_list)
@build_list4.project.update_column(:visibility, 'hidden')
@build_list4.project.relations.create! role: 'reader', actor_id: @user.id, actor_type: 'User'
create_relation(@build_list4.project, @user, 'reader')
end
it 'should be able to perform index action' do

View File

@ -104,7 +104,7 @@ describe Projects::CollaboratorsController do
context 'for admin user' do
before(:each) do
@project.relations.create!(actor_type: 'User', actor_id: @user.id, role: 'admin')
create_relation(@project, @user, 'admin')
end
it_should_behave_like 'project admin user'
@ -121,7 +121,7 @@ describe Projects::CollaboratorsController do
context 'for reader user' do
before(:each) do
@project.relations.create!(actor_type: 'User', actor_id: @user.id, role: 'reader')
create_relation(@project, @user, 'reader')
end
it_should_behave_like 'user with no rights for this project'
@ -129,7 +129,7 @@ describe Projects::CollaboratorsController do
context 'for writer user' do
before(:each) do
@project.relations.create!(actor_type: 'User', actor_id: @user.id, role: 'writer')
create_relation(@project, @user, 'writer')
end
it_should_behave_like 'user with no rights for this project'

View File

@ -20,7 +20,7 @@ describe Projects::CommentsController do
context 'for project admin user' do
before(:each) do
@project.relations.create!(actor_type: 'User', actor_id: @user.id, role: 'admin')
create_relation(@project, @user, 'admin')
end
it_should_behave_like 'user with create comment ability'
@ -43,7 +43,7 @@ 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')
create_relation(@project, @user, 'reader')
end
it_should_behave_like 'user with create comment ability'
@ -54,7 +54,7 @@ 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')
create_relation(@project, @user, 'writer')
end
it_should_behave_like 'user with create comment ability'

View File

@ -38,7 +38,7 @@ describe Projects::CommentsController do
context 'for project admin user' do
before(:each) do
@project.relations.create!(actor_type: 'User', actor_id: @user.id, role: 'admin')
create_relation(@project, @user, 'admin')
end
it_should_behave_like 'user with create comment ability'
@ -60,7 +60,7 @@ 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')
create_relation(@project, @user, 'reader')
end
it_should_behave_like 'user with create comment ability'
@ -71,7 +71,7 @@ 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')
create_relation(@project, @user, 'writer')
end
it_should_behave_like 'user with create comment ability'

View File

@ -100,7 +100,7 @@ describe Projects::Git::TreesController do
context 'for writer user' do
before(:each) do
user = FactoryGirl.create(:user)
@project.relations.create!(actor_type: 'User', actor_id: user.id, role: 'writer')
create_relation(@project, @user, 'writer')
set_session_for user
end

View File

@ -94,14 +94,14 @@ describe Projects::HooksController do
context 'for reader user' do
before do
@project.relations.create!(actor_type: 'User', actor_id: @user.id, role: 'reader')
create_relation(@project, @user, 'reader')
end
it_should_behave_like 'hooks user without project admin rights'
end
context 'for writer user' do
before do
@project.relations.create!(actor_type: 'User', actor_id: @user.id, role: 'writer')
create_relation(@project, @user, 'writer')
end
it_should_behave_like 'hooks user without project admin rights'
end
@ -120,82 +120,59 @@ describe Projects::HooksController do
end
context 'group member user with reader role' do
before do
@group.actors.create(actor_id: @user.id, actor_type: 'User', role: 'reader')
end
before do { create_actor_relation(@group, @auser, 'reader') }
it_should_behave_like 'hooks user without project admin rights'
context 'user should has best role' do
before do
@project.relations.create actor_id: @user.id, actor_type: @user.class.to_s, role: 'admin'
end
before { create_relation(@project, @user, 'admin') }
it_should_behave_like 'hooks user with project admin rights'
end
end
context 'group member user with admin role' do
before do
@group.actors.create(actor_id: @user.id, actor_type: 'User', role: 'admin')
end
before do { create_actor_relation(@group, @user, 'admin') }
it_should_behave_like 'hooks user with project admin rights'
end
end
context 'group is member of the project' do
context 'with admin rights' do
before do
@project.relations.create actor_id: @group.id, actor_type: @group.class.to_s, role: 'admin'
end
before { create_relation(@project, @group, 'admin') }
context 'group member user with reader role' do
before do
@group.actors.create(actor_id: @user.id, actor_type: 'User', role: 'reader')
end
before { create_actor_relation(@group, @user, 'reader') }
it_should_behave_like 'hooks user with project admin rights'
context 'user should has best role' do
before do
@project.relations.create actor_id: @user.id, actor_type: @user.class.to_s, role: 'reader'
end
before { create_relation(@project, @user, 'reader') }
it_should_behave_like 'hooks user with project admin rights'
end
end
context 'group member user with admin role' do
before do
@group.actors.create(actor_id: @user.id, actor_type: 'User', role: 'admin')
end
before { create_actor_relation(@group, @user, 'admin') }
it_should_behave_like 'hooks user with project admin rights'
end
end
context 'with reader rights' do
before do
@project.relations.create actor_id: @group.id, actor_type: @group.class.to_s, role: 'reader'
end
before { create_relation(@project, @group, 'reader') }
context 'group member user with reader role' do
before do
@group.actors.create(actor_id: @user.id, actor_type: 'User', role: 'reader')
end
before { create_actor_relation(@group, @user, 'reader') }
it_should_behave_like 'hooks user without project admin rights'
context 'user should has best role' do
before do
@project.relations.create actor_id: @user.id, actor_type: @user.class.to_s, role: 'admin'
end
before { create_relation(@project, @user, 'admin') }
it_should_behave_like 'hooks user with project admin rights'
end
end
context 'group member user with admin role' do
before do
@group.actors.create(actor_id: @user.id, actor_type: 'User', role: 'admin')
end
before { create_actor_relation(@group, @user, 'admin') }
it_should_behave_like 'hooks user without project admin rights'
end
end

View File

@ -162,7 +162,7 @@ describe Projects::IssuesController do
context 'for project admin user' do
before(:each) do
@project.relations.create!(actor_type: 'User', actor_id: @user.id, role: 'admin')
create_relation(@project, @user, 'admin')
end
it_should_behave_like 'issue user with project guest rights'
@ -189,7 +189,7 @@ describe Projects::IssuesController do
context 'for project reader user' do
before(:each) do
@project.relations.create!(actor_type: 'User', actor_id: @user.id, role: 'reader')
create_relation(@project, @user, 'reader')
end
it_should_behave_like 'issue user with project guest rights'
@ -232,7 +232,7 @@ describe Projects::IssuesController do
context 'for project writer user' do
before(:each) do
@project.relations.create!(actor_type: 'User', actor_id: @user.id, role: 'writer')
create_relation(@project, @user, 'writer')
end
it_should_behave_like 'issue user with project guest rights'

View File

@ -9,7 +9,7 @@ shared_examples_for 'projects user with reader rights' do
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')
create_actor_relation(group, @user, 'admin')
lambda {post :fork, owner_name: @project.owner.uname, project_name: @project.name,
group: group.id}.should change{ Project.count }.by(1)
end
@ -71,27 +71,27 @@ shared_examples_for 'projects user without project admin rights' do
it 'writer group 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: 'writer')
create_actor_relation(group, @user, 'writer')
lambda {post :fork, owner_name: @project.owner.uname, project_name: @project.name,
group: group.id}.should change{ Project.count }.by(1)
end
it 'reader group should not be able to fork project to their group' do
group = FactoryGirl.create(:group)
group.actors.create(actor_type: 'User', actor_id: @user.id, role: 'reader')
create_actor_relation(group, @user, 'reader')
lambda {post :fork, owner_name: @project.owner.uname, project_name: @project.name,
group: group.id}.should change{ Project.count }.by(0)
end
it 'writer group should be able to create project to their group' do
group = FactoryGirl.create(:group)
group.actors.create(actor_type: 'User', actor_id: @user.id, role: 'writer')
create_actor_relation(group, @user, 'wrtier')
lambda {post :create, @create_params.merge(who_owns: 'group', owner_id: group.id)}.should change{ Project.count }.by(1)
end
it 'reader group should not be able to create project to their group' do
group = FactoryGirl.create(:group)
group.actors.create(actor_type: 'User', actor_id: @user.id, role: 'reader')
create_actor_relation(group, @user, 'reader')
lambda {post :create, @create_params.merge(who_owns: 'group', owner_id: group.id)}.should change{ Project.count }.by(0)
end
end
@ -168,7 +168,7 @@ describe Projects::ProjectsController do
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')
create_actor_relation(group, @user, 'admin')
lambda { post :create, @create_params.merge({who_owns: 'group', owner_id: group.id})}.should change{ Project.count }.by(1)
end
@ -215,7 +215,7 @@ describe Projects::ProjectsController do
context 'for reader user' do
before(:each) do
@project.relations.create!(actor_type: 'User', actor_id: @user.id, role: 'reader')
create_relation(@project, @user, 'reader')
end
it_should_behave_like 'projects user with reader rights'
@ -224,7 +224,7 @@ describe Projects::ProjectsController do
context 'for writer user' do
before(:each) do
@project.relations.create!(actor_type: 'User', actor_id: @user.id, role: 'writer')
create_relation(@project, @user, 'writer')
end
it_should_behave_like 'projects user with reader rights'
@ -257,9 +257,7 @@ describe Projects::ProjectsController do
end
context 'group member user with reader role' do
before(:each) do
@group.actors.create(actor_id: @user.id, actor_type: 'User', role: 'reader')
end
before(:each) { create_actor_relation(@group, @user, 'reader') }
it_should_behave_like 'projects user with reader rights'
it_should_behave_like 'projects user without project admin rights'
@ -269,17 +267,13 @@ describe Projects::ProjectsController do
end
context 'user should has best role' do
before(:each) do
@project.relations.create actor_id: @user.id, actor_type: @user.class.to_s, role: 'admin'
end
before(:each) { create_relation(@project, @user, 'admin') }
it_should_behave_like 'projects user with project admin rights'
end
end
context 'group member user with admin role' do
before(:each) do
@group.actors.create(actor_id: @user.id, actor_type: 'User', role: 'admin')
end
before(:each) { create_actor_relation(@group, @user, 'admin') }
it_should_behave_like 'projects user with project admin rights'
it_should_behave_like 'projects user with reader rights'
@ -288,30 +282,22 @@ describe Projects::ProjectsController 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
before(:each) { create_relation(@project, @group, 'admin') }
context 'group member user with reader role' do
before(:each) do
@group.actors.create(actor_id: @user.id, actor_type: 'User', role: 'reader')
end
before(:each) { create_actor_relation(@group, @user, 'reader') }
it_should_behave_like 'projects user with reader 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: @user.id, actor_type: @user.class.to_s, role: 'reader'
end
before(:each) { create_relation(@project, @user, 'reader') }
it_should_behave_like 'projects user with project admin rights'
end
end
context 'group member user with admin role' do
before(:each) do
@group.actors.create(actor_id: @user.id, actor_type: 'User', role: 'admin')
end
before(:each) { create_actor_relation(@group, @user, 'admin') }
it_should_behave_like 'projects user with project admin rights'
it_should_behave_like 'projects user with reader rights'
@ -319,30 +305,22 @@ describe Projects::ProjectsController do
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
before(:each) { create_relation(@project, @group, 'reader') }
context 'group member user with reader role' do
before(:each) do
@group.actors.create(actor_id: @user.id, actor_type: 'User', role: 'reader')
end
before(:each) { create_actor_relation(@group, @user, 'reader') }
it_should_behave_like 'projects user with reader 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: @user.id, actor_type: @user.class.to_s, role: 'admin'
end
before(:each) { create_relation(@project, @user, 'admin') }
it_should_behave_like 'projects user with project admin rights'
end
end
context 'group member user with admin role' do
before(:each) do
@group.actors.create(actor_id: @user.id, actor_type: 'User', role: 'admin')
end
before(:each) { create_actor_relation(@group, @user, 'admin') }
it_should_behave_like 'projects user with reader rights'
it_should_behave_like 'projects user without project admin rights'

View File

@ -191,7 +191,7 @@ describe Projects::PullRequestsController do
context 'for project admin user' do
before do
@project.relations.create!(actor_type: 'User', actor_id: @user.id, role: 'admin')
create_relation(@project, @user, 'admin')
end
it_should_behave_like 'pull request user with project guest rights'
@ -214,7 +214,7 @@ describe Projects::PullRequestsController do
context 'for project reader user' do
before do
@project.relations.create!(actor_type: 'User', actor_id: @user.id, role: 'reader')
create_relation(@project, @user, 'reader')
end
it_should_behave_like 'pull request user with project guest rights'
@ -235,7 +235,7 @@ describe Projects::PullRequestsController do
context 'for project writer user' do
before do
@project.relations.create!(actor_type: 'User', actor_id: @user.id, role: 'writer')
create_relation(@project, @user, 'writer')
end
it_should_behave_like 'pull request user with project guest rights'
@ -300,11 +300,11 @@ describe Projects::PullRequestsController do
context 'send email messages' do
before(:each) do
@project_reader = FactoryGirl.create :user
@project.relations.create!(actor_type: 'User', actor_id: @project_reader.id, role: 'reader')
create_relation(@project, @project_reader, 'reader')
@project_admin = FactoryGirl.create :user
@project.relations.create!(actor_type: 'User', actor_id: @project_admin.id, role: 'admin')
create_relation(@project, @project_admin, 'admin')
@project_writer = FactoryGirl.create :user
@project.relations.create!(actor_type: 'User', actor_id: @project_writer.id, role: 'writer')
create_relation(@project, @project_writer, 'writer')
set_session_for(@project_writer)
ActionMailer::Base.deliveries = []

View File

@ -65,7 +65,7 @@ describe Projects::SubscribesController do
before(:each) do
@user = FactoryGirl.create(:admin)
set_session_for(@user)
@project.relations.create!(actor_type: 'User', actor_id: @user.id, role: 'admin')
create_relation(@project, @user, 'admin')
@destroy_params = @destroy_params.merge({id: @user.id})
end

View File

@ -1,15 +0,0 @@
require 'spec_helper'
# Specs in this file have access to a helper object that includes
# the BuildListsHelper. For example:
#
# describe BuildListsHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# helper.concat_strings("this","that").should == "this that"
# end
# end
# end
describe BuildListsHelper do
pending "add some examples to (or delete) #{__FILE__}"
end

View File

@ -1,15 +0,0 @@
require 'spec_helper'
# Specs in this file have access to a helper object that includes
# the WikiHelper. For example:
#
# describe WikiHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# helper.concat_strings("this","that").should == "this that"
# end
# end
# end
describe WikiHelper do
pending "add some examples to (or delete) #{__FILE__}"
end

View File

@ -138,7 +138,7 @@ describe CanCan do
context 'with read rights' do
before(:each) do
@project.relations.create!(actor_id: @user.id, actor_type: 'User', role: 'reader')
create_relation(@project, @user, 'reader')
end
it 'should be able to read project' do
@ -152,7 +152,7 @@ describe CanCan do
context 'with writer rights' do
before(:each) do
@project.relations.create!(actor_id: @user.id, actor_type: 'User', role: 'writer')
create_relation(@project, @user, 'writer')
end
[:read, :create, :new].each do |action|
@ -171,7 +171,7 @@ describe CanCan do
context 'with admin rights' do
before(:each) do
@project.relations.create!(actor_id: @user.id, actor_type: 'User', role: 'admin')
create_relation(@project, @user, 'admin')
end
[:read, :update].each do |action|
@ -227,7 +227,7 @@ describe CanCan do
context 'through group-member' do
before(:each) do
@group_member = FactoryGirl.create(:group)
@project.relations.create!(actor_id: @group_member.id, actor_type: 'Group', role: 'reader')
create_relation(@project, @group_member, 'reader')
@group_member_ability = Ability.new(@group_member.owner)
end
@ -274,7 +274,7 @@ describe CanCan do
context 'with read rights' do
before(:each) do
@platform.relations.create!(actor_id: @user.id, actor_type: 'User', role: 'reader')
create_relation(@platform, @user, 'reader')
@ability = Ability.new(@user)
end
@ -310,7 +310,7 @@ describe CanCan do
context 'with read rights' do
before(:each) do
@repository.platform.relations.create!(actor_id: @user.id, actor_type: 'User', role: 'reader')
create_relation(@repository.platform, @user, 'reader')
end
it "should be able to read repository" do

View File

@ -62,7 +62,7 @@ describe Comment do
set_comments_data_for_commit
@admin = FactoryGirl.create(:user)
@ability = Ability.new(@admin)
@project.relations.create!({actor_type: 'User', actor_id: @admin.id, role: 'admin'}, without_protection: true)
create_relation(@project, @admin, 'admin')
end
it_should_behave_like 'user with create comment ability (for model)'

View File

@ -40,8 +40,7 @@ describe Comment do
@stranger = FactoryGirl.create(:user)
set_commentable_data
@project.relations.create!(actor_type: 'User', actor_id: @user.id, role: 'admin')
create_relation(@project, @user, 'admin')
end
it_should_behave_like 'user with create comment ability (for model)'
@ -64,7 +63,7 @@ describe Comment do
@project.owner = @user
@project.save
@project.relations.create!(actor_type: 'User', actor_id: @user.id, role: 'admin')
create_relation(@project, @user, 'admin')
end
it_should_behave_like 'user with create comment ability (for model)'

View File

@ -33,7 +33,7 @@ describe Group do
before(:each) do
@user = FactoryGirl.create(:user)
@another_user = FactoryGirl.create(:user)
@group.actors.create(actor_type: 'User', actor_id: @user.id, role: 'admin')
create_actor_relation(@group, @user, 'admin')
@ability = Ability.new(@user)
end
@ -65,7 +65,7 @@ describe Group do
@group.owner = @user
@group.save
@group.actors.create(actor_type: 'User', actor_id: @user.id, role: 'admin')
create_actor_relation(@group, @user, 'admin')
@ability = Ability.new(@user)
end
@ -79,7 +79,7 @@ describe Group do
context 'for group reader and writer user' do
before(:each) do
@user = FactoryGirl.create(:user)
@group.actors.create(actor_type: 'User', actor_id: @user.id, role: 'reader')
create_actor_relation(@group, @user, 'reader')
@ability = Ability.new(@user)
end

View File

@ -66,32 +66,32 @@ describe Issue do
@group = FactoryGirl.create(:group)
@reader = FactoryGirl.create :user
@group.actors.create(actor_type: 'User', actor_id: @reader.id, role: 'reader')
create_actor_relation(@group, @reader, 'reader')
end
it 'should send an e-mail to all members of the admin group' do
@project.relations.create!(actor_type: 'Group', actor_id: @group.id, role: 'admin')
create_relation(@project, @group, 'admin')
create_issue(@stranger)
ActionMailer::Base.deliveries.count.should == 3 # 1 owner + 2 group member. enough?
end
it 'should send an e-mail to all members of the admin group except creator' do
@project.relations.create!(actor_type: 'Group', actor_id: @group.id, role: 'admin')
create_relation(@project, @group, 'admin')
create_issue(@group.owner)
ActionMailer::Base.deliveries.count.should == 2 # 1 owner + 1 group member. enough?
end
it 'should not send an e-mail to members of the reader group' do
@project.relations.create!(actor_type: 'Group', actor_id: @group.id, role: 'reader')
create_relation(@project, @group, 'reader')
create_issue(@stranger)
ActionMailer::Base.deliveries.count.should == 1 # 1 project owner
end
it 'should reset issue assignee after remove him from group' do
@project.relations.create!(actor_type: 'Group', actor_id: @group.id, role: 'reader')
create_relation(@project, @group, 'reader')
create_issue(@group.owner)
@issue.update_column :assignee_id, @reader.id
@group.remove_member @reader
@ -99,8 +99,8 @@ describe Issue do
end
it 'should not reset issue assignee' do
@project.relations.create!(actor_type: 'Group', actor_id: @group.id, role: 'reader')
@project.relations.create!(actor_type: 'User', actor_id: @reader.id, role: 'reader')
create_relation(@project, @group, 'reader')
create_relation(@project, @reader, 'reader')
create_issue(@group.owner)
@issue.update_column :assignee_id, @reader.id
@group.remove_member @reader
@ -108,7 +108,7 @@ describe Issue do
end
it 'should reset issue assignee after remove him from project' do
@project.relations.create!(actor_type: 'User', actor_id: @reader.id, role: 'reader')
create_relation(@project, @reader, 'reader')
create_issue(@reader)
@issue.update_column :assignee_id, @reader.id
@project.remove_member @reader # via api
@ -140,7 +140,7 @@ describe Issue do
context 'for reader of the group' do
it 'should not send an e-mail' do
reader = FactoryGirl.create :user
@group.actors.create(actor_type: 'User', actor_id: reader.id, role: 'reader')
create_actor_relation(@group, reader, 'reader')
create_issue(@stranger)
ActionMailer::Base.deliveries.count.should == 1

View File

@ -1,4 +1,3 @@
require 'spec_helper'
describe User do
@ -24,15 +23,11 @@ describe User do
%w(reader writer admin).each do |group_role|
context "for group with #{group_role} role in project" do
before(:each) do
@project.relations.create actor_id: @group.id, actor_type: @group.class.to_s, role: group_role
end
before(:each) { create_relation(@project, @group, group_role) }
%w(reader writer admin).each do |role|
context "for user with #{role} role in group" do
before(:each) do
@group.actors.create(actor_id: @user.id, actor_type: 'User', role: role)
end
before(:each) { create_actor_relation(@group, @user, role) }
it "should have #{group_role} role to project" do
@user.best_role(@project).should == group_role
@ -48,14 +43,12 @@ describe User do
@project.owner = @group
@project.save
@project.relations.create actor_id: @project.owner.id, actor_type: @project.owner.class.to_s, role: 'admin'
create_relation(@project, @project.owner, 'admin')
end
%w(reader writer admin).each do |role|
context "for user with #{role} role in group" do
before(:each) do
@group.actors.create(actor_id: @user.id, actor_type: 'User', role: role)
end
before(:each) { create_actor_relation(@group, @user, role) }
it "should have #{role} role to project" do
@user.best_role(@project).should == role
@ -65,9 +58,7 @@ describe User do
%w(reader writer admin).each do |role|
context "for user with #{role} role in project" do
before(:each) do
@project.relations.create(actor_id: @user.id, actor_type: 'User', role: role)
end
before(:each) { create_relation(@project, @user, role) }
it "should have #{role} role to project" do
@user.best_role(@project).should == role
@ -77,16 +68,16 @@ describe User do
context "for user with reader role in group and writer role in project" do
it "should have writer best role to project" do
@group.actors.create(actor_id: @user.id, actor_type: 'User', role: 'reader')
@project.relations.create(actor_id: @user.id, actor_type: 'User', role: 'writer')
create_actor_relation(@group, @user, 'reader')
create_relation(@project, @user, 'writer')
@user.best_role(@project).should == 'writer'
end
end
context "for user with admin role in group and reader role in project" do
it "should have admin best role to project" do
@group.actors.create(actor_id: @user.id, actor_type: 'User', role: 'admin')
@project.relations.create(actor_id: @user.id, actor_type: 'User', role: 'reader')
create_actor_relation(@group, @user, 'admin')
create_relation(@project, @user, 'reader')
@user.best_role(@project).should == 'admin'
end
end

7
spec/support/relation.rb Normal file
View File

@ -0,0 +1,7 @@
def create_relation(target, actor, role)
target.relations.create!(actor: actor, role: role)
end
def create_actor_relation(target, actor, role)
target.actors.create!(actor: actor, role: role)
end