-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refs#13 Added testcases for the Model Group (#87)
Also added factorygirl for the same Factory for the Group
- Loading branch information
1 parent
72a8bc8
commit 86aa61c
Showing
2 changed files
with
97 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,17 @@ | ||
FactoryGirl.define do | ||
factory :group do | ||
factory :group do | ||
name { Faker::Lorem.word } | ||
description { Faker::Lorem.sentence } | ||
members {|a| [a.association(:user)]} | ||
|
||
factory :group_with_invitations do | ||
transient do | ||
invitations_count 1 | ||
end | ||
after(:create) do |group, evaluator| | ||
create_list(:group_invitation, evaluator.invitations_count, group: group) | ||
end | ||
end | ||
|
||
end | ||
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,11 +1,92 @@ | ||
require "test_helper" | ||
|
||
class GroupTest < ActiveSupport::TestCase | ||
def group | ||
@group ||= Group.new | ||
|
||
def test_name_must_be_present | ||
group = build(:group,:name => nil) | ||
group.valid? | ||
assert_not_empty group.errors[:name] | ||
end | ||
|
||
def test_description_must_be_present | ||
group = build(:group,:description => nil) | ||
group.valid? | ||
assert_not_empty group.errors[:description] | ||
end | ||
|
||
def test_group_owner_should_be_present | ||
group = create(:group) | ||
user = create(:user) | ||
group.owner = user | ||
assert_not_nil group.owner | ||
end | ||
|
||
def test_user_is_a_member_of_a_group | ||
group = create(:group) | ||
user = create(:user) | ||
group.members << user | ||
assert group.member?(user) | ||
end | ||
|
||
def test_user_is_not_a_member_of_a_group | ||
group = create(:group) | ||
user = create(:user) | ||
assert_not group.member?(user) | ||
end | ||
|
||
def test_group_should_not_accept_invitation_if_token_is_not_present | ||
group = create(:group) | ||
token = SecureRandom.base64(24).tr('0+/=', 'A0lk') | ||
assert_not group.accept_invitation(token) | ||
end | ||
|
||
def test_group_must_accept_invitation_having_token_with_them | ||
group = create(:group) | ||
invitation = create(:group_invitation) | ||
group.group_invitations << invitation | ||
user = create(:user) | ||
user.group_invitations << invitation | ||
assert group.accept_invitation(invitation.token) | ||
end | ||
|
||
def test_user_is_not_invited_if_group_invitation_is_not_present | ||
group = create(:group) | ||
user = create(:user) | ||
assert_not group.invited? | ||
end | ||
|
||
def test_user_is_invited_if_group_invitation_is_present | ||
group = create(:group) | ||
user = create(:user) | ||
invitation = create(:group_invitation, user: user) | ||
group.group_invitations << invitation | ||
assert group.invited?(user: user) | ||
end | ||
|
||
def test_group_member_not_removed_if_member_is_the_owner | ||
group = create(:group) | ||
member = create(:user) | ||
group.members << member | ||
group.owner = member | ||
assert_not group.can_remove_member?(member) | ||
end | ||
|
||
def test_group_member_removed_if_current_user_is_member | ||
member = create(:user) | ||
group = create(:group) | ||
group.members << member | ||
current_user = member | ||
group.owner = group.members.first | ||
assert group.can_remove_member?(member, current_user) | ||
end | ||
|
||
def test_valid | ||
assert group.valid? | ||
def test_group_member_current_user_removed_if_current_user_is_owner | ||
member = create(:user) | ||
group = create(:group) | ||
group.members << member | ||
current_user = group.members.first | ||
group.owner = current_user | ||
assert group.can_remove_member?(member, current_user) | ||
end | ||
|
||
end |