2012-10-09 04:14:17 -04:00
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: users_projects
|
|
|
|
#
|
2012-11-19 13:24:05 -05:00
|
|
|
# id :integer not null, primary key
|
|
|
|
# user_id :integer not null
|
|
|
|
# project_id :integer not null
|
|
|
|
# created_at :datetime not null
|
|
|
|
# updated_at :datetime not null
|
|
|
|
# project_access :integer default(0), not null
|
2012-10-09 04:14:17 -04:00
|
|
|
#
|
|
|
|
|
2011-10-08 17:36:38 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe UsersProject do
|
|
|
|
describe "Associations" do
|
|
|
|
it { should belong_to(:project) }
|
|
|
|
it { should belong_to(:user) }
|
|
|
|
end
|
|
|
|
|
2012-09-26 14:17:17 -04:00
|
|
|
describe "Mass assignment" do
|
|
|
|
it { should_not allow_mass_assignment_of(:project_id) }
|
|
|
|
end
|
|
|
|
|
2011-10-08 17:36:38 -04:00
|
|
|
describe "Validation" do
|
2012-08-29 11:36:02 -04:00
|
|
|
let!(:users_project) { create(:users_project) }
|
|
|
|
|
2012-10-08 20:10:16 -04:00
|
|
|
it { should validate_presence_of(:user) }
|
2012-09-06 17:05:23 -04:00
|
|
|
it { should validate_uniqueness_of(:user_id).scoped_to(:project_id).with_message(/already exists/) }
|
2012-08-29 11:36:02 -04:00
|
|
|
|
2012-10-08 20:10:16 -04:00
|
|
|
it { should validate_presence_of(:project) }
|
2012-12-22 12:52:28 -05:00
|
|
|
it { should ensure_inclusion_of(:project_access).in_array(UsersProject.access_roles.values) }
|
2011-10-08 17:36:38 -04:00
|
|
|
end
|
|
|
|
|
2011-10-26 09:46:25 -04:00
|
|
|
describe "Delegate methods" do
|
2011-10-08 17:36:38 -04:00
|
|
|
it { should respond_to(:user_name) }
|
|
|
|
it { should respond_to(:user_email) }
|
|
|
|
end
|
2012-10-24 07:52:17 -04:00
|
|
|
|
|
|
|
describe :import_team do
|
|
|
|
before do
|
|
|
|
@abilities = Six.new
|
|
|
|
@abilities << Ability
|
|
|
|
|
|
|
|
@project_1 = create :project
|
|
|
|
@project_2 = create :project
|
|
|
|
|
|
|
|
@user_1 = create :user
|
|
|
|
@user_2 = create :user
|
|
|
|
|
2013-01-04 01:43:25 -05:00
|
|
|
@project_1.team << [ @user_1, :developer ]
|
|
|
|
@project_2.team << [ @user_2, :reporter ]
|
2012-10-24 07:52:17 -04:00
|
|
|
|
2013-01-04 01:43:25 -05:00
|
|
|
@status = @project_2.team.import(@project_1)
|
2012-10-24 07:52:17 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it { @status.should be_true }
|
|
|
|
|
|
|
|
describe 'project 2 should get user 1 as developer. user_2 should not be changed' do
|
|
|
|
it { @project_2.users.should include(@user_1) }
|
|
|
|
it { @project_2.users.should include(@user_2) }
|
|
|
|
|
|
|
|
it { @abilities.allowed?(@user_1, :write_project, @project_2).should be_true }
|
|
|
|
it { @abilities.allowed?(@user_2, :read_project, @project_2).should be_true }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'project 1 should not be changed' do
|
|
|
|
it { @project_1.users.should include(@user_1) }
|
|
|
|
it { @project_1.users.should_not include(@user_2) }
|
|
|
|
end
|
|
|
|
end
|
2013-01-03 12:11:14 -05:00
|
|
|
|
|
|
|
describe :add_users_into_projects do
|
|
|
|
before do
|
|
|
|
@project_1 = create :project
|
|
|
|
@project_2 = create :project
|
|
|
|
|
|
|
|
@user_1 = create :user
|
|
|
|
@user_2 = create :user
|
|
|
|
|
|
|
|
UsersProject.add_users_into_projects(
|
|
|
|
[@project_1.id, @project_2.id],
|
|
|
|
[@user_1.id, @user_2.id],
|
|
|
|
UsersProject::MASTER
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { @project_1.users.should include(@user_1) }
|
|
|
|
it { @project_1.users.should include(@user_2) }
|
|
|
|
|
|
|
|
|
|
|
|
it { @project_2.users.should include(@user_1) }
|
|
|
|
it { @project_2.users.should include(@user_2) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe :truncate_teams do
|
|
|
|
before do
|
|
|
|
@project_1 = create :project
|
|
|
|
@project_2 = create :project
|
|
|
|
|
|
|
|
@user_1 = create :user
|
|
|
|
@user_2 = create :user
|
|
|
|
|
2013-01-04 01:43:25 -05:00
|
|
|
@project_1.team << [ @user_1, :developer]
|
|
|
|
@project_2.team << [ @user_2, :reporter]
|
2013-01-03 12:11:14 -05:00
|
|
|
|
|
|
|
UsersProject.truncate_teams([@project_1.id, @project_2.id])
|
|
|
|
end
|
|
|
|
|
|
|
|
it { @project_1.users.should be_empty }
|
|
|
|
it { @project_2.users.should be_empty }
|
|
|
|
end
|
2011-10-08 17:36:38 -04:00
|
|
|
end
|