-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove useless functions and refactor specs
- Loading branch information
Showing
6 changed files
with
8 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,7 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe Course::Group, type: :model do | ||
it { is_expected.to belong_to(:course).class_name(Course.name) } | ||
|
||
let!(:instance) { create(:instance) } | ||
|
||
with_tenant(:instance) do | ||
let!(:course_owner) { create(:course_user, role: :owner) } | ||
let!(:course) { course_owner.course } | ||
let!(:owner) { course_owner.user } | ||
let!(:course_student) { create(:course_user, course: course, role: :student) } | ||
let!(:student) { course_student.user } | ||
let!(:group) { create(:course_group, course: course) } | ||
let!(:group2) { create(:course_group, course: course) } | ||
|
||
before do | ||
User.stamper = owner | ||
end | ||
|
||
describe '#add_user' do | ||
subject { group.add_user(owner) } | ||
|
||
context 'user is not a member of any group' do | ||
it 'creates a new group user for the user' do | ||
expect { subject }.to change(Course::GroupUser, :count).by(1) | ||
owner.reload | ||
expect(Course::GroupUser.last).to eq(owner.group_users.first) | ||
end | ||
end | ||
|
||
context 'user is a member of another group' do | ||
before do | ||
create(:course_group_user, user: owner, group: group2) | ||
end | ||
|
||
it 'removes the user from the previous group and assign him to the current one' do | ||
expect(owner.groups.last).to eq(group2) | ||
expect { subject }.not_to change(Course::GroupUser, :count) | ||
owner.reload | ||
expect(owner.groups.last).to eq(group) | ||
end | ||
end | ||
end | ||
|
||
describe '#role_for_user' do | ||
before do | ||
create(:course_group_user, group: group, user: owner, role: :manager) | ||
end | ||
context 'user is a group member' do | ||
it "returns the user's role in the group" do | ||
expect(group.role_for_user(owner)).to eq('manager') | ||
end | ||
end | ||
|
||
context 'user is a not a group member' do | ||
it 'returns nil' do | ||
expect(group.role_for_user(student)).to be(nil) | ||
end | ||
end | ||
end | ||
end | ||
it { is_expected.to belong_to(:course).inverse_of(:groups) } | ||
it { is_expected.to have_many(:group_users).inverse_of(:group).dependent(:destroy) } | ||
it { is_expected.to have_many(:users).through(:group_users) } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,6 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe Course::GroupUser, type: :model do | ||
it { is_expected.to belong_to(:user).class_name(User.name) } | ||
it { is_expected.to belong_to(:group).class_name(Course::Group.name) } | ||
|
||
let!(:instance) { create(:instance) } | ||
with_tenant(:instance) do | ||
let!(:course_student) { create(:course_user) } | ||
let!(:course) { course_student.course } | ||
let!(:group) { create(:course_group, course: course) } | ||
let!(:group_student) { create(:course_group_user, group: group, user: course_student.user) } | ||
|
||
describe '#course_user' do | ||
it 'returns the course user that belongs to the user and the course' do | ||
expect(group_student.course_user).to eq(course_student) | ||
end | ||
end | ||
end | ||
it { is_expected.to belong_to(:user).inverse_of(:group_users) } | ||
it { is_expected.to belong_to(:group).inverse_of(:group_users) } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters