diff options
author | Robert Speicher <rspeicher@gmail.com> | 2015-01-30 23:40:04 +0300 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2015-01-30 23:51:10 +0300 |
commit | ab6f7164e03139889c09a6a207e9df3481e57b3b (patch) | |
tree | c1c107612a9db89bbdc4f10c222bfcb4f5b44119 /spec/models/members | |
parent | c47328948b5fff218c68279260a57ab6b03e7423 (diff) |
Make the structure of spec/models match app/models
Diffstat (limited to 'spec/models/members')
-rw-r--r-- | spec/models/members/group_member_spec.rb | 46 | ||||
-rw-r--r-- | spec/models/members/project_member_spec.rb | 92 |
2 files changed, 138 insertions, 0 deletions
diff --git a/spec/models/members/group_member_spec.rb b/spec/models/members/group_member_spec.rb new file mode 100644 index 00000000000..38657de6793 --- /dev/null +++ b/spec/models/members/group_member_spec.rb @@ -0,0 +1,46 @@ +# == Schema Information +# +# Table name: members +# +# id :integer not null, primary key +# access_level :integer not null +# source_id :integer not null +# source_type :string(255) not null +# user_id :integer not null +# notification_level :integer not null +# type :string(255) +# created_at :datetime +# updated_at :datetime +# + +require 'spec_helper' + +describe GroupMember do + context 'notification' do + describe "#after_create" do + it "should send email to user" do + membership = build(:group_member) + membership.stub(notification_service: double('NotificationService').as_null_object) + membership.should_receive(:notification_service) + membership.save + end + end + + describe "#after_update" do + before do + @membership = create :group_member + @membership.stub(notification_service: double('NotificationService').as_null_object) + end + + it "should send email to user" do + @membership.should_receive(:notification_service) + @membership.update_attribute(:access_level, GroupMember::MASTER) + end + + it "does not send an email when the access level has not changed" do + @membership.should_not_receive(:notification_service) + @membership.update_attribute(:access_level, GroupMember::OWNER) + end + end + end +end diff --git a/spec/models/members/project_member_spec.rb b/spec/models/members/project_member_spec.rb new file mode 100644 index 00000000000..9b5f89b6d7d --- /dev/null +++ b/spec/models/members/project_member_spec.rb @@ -0,0 +1,92 @@ +# == Schema Information +# +# Table name: members +# +# id :integer not null, primary key +# access_level :integer not null +# source_id :integer not null +# source_type :string(255) not null +# user_id :integer not null +# notification_level :integer not null +# type :string(255) +# created_at :datetime +# updated_at :datetime +# + +require 'spec_helper' + +describe ProjectMember do + 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 + + @project_1.team << [ @user_1, :developer ] + @project_2.team << [ @user_2, :reporter ] + + @status = @project_2.team.import(@project_1) + 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 + + describe :add_users_into_projects do + before do + @project_1 = create :project + @project_2 = create :project + + @user_1 = create :user + @user_2 = create :user + + ProjectMember.add_users_into_projects( + [@project_1.id, @project_2.id], + [@user_1.id, @user_2.id], + ProjectMember::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 + + @project_1.team << [ @user_1, :developer] + @project_2.team << [ @user_2, :reporter] + + ProjectMember.truncate_teams([@project_1.id, @project_2.id]) + end + + it { @project_1.users.should be_empty } + it { @project_2.users.should be_empty } + end +end |