Skip to content

Commit

Permalink
Added tests to check subclassing
Browse files Browse the repository at this point in the history
  • Loading branch information
joelvh committed May 19, 2017
1 parent 68b6140 commit d180018
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions spec/active_record_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
class User < ActiveRecord::Base
groupify :group_member
groupify :named_group_member

has_group :organizations, class_name: "Organization"
end

class Manager < User
Expand Down Expand Up @@ -213,6 +215,29 @@ class ProjectMember < ActiveRecord::Base
parent_org.add(child_org)
expect(parent_org.organizations).to include(child_org)
end

it "can have subclassed associations for groups of a specific kind" do
org = Organization.create!

user.groups << group
user.groups << org

expect(user.groups).to include(group)
expect(user.groups).to include(org)

expect(user.organizations).to_not include(group)
expect(user.organizations).to include(org)

expect(org.members).to include(user)
expect(group.members).to include(user)

expect(user.organizations.count).to eq(1)
expect(user.organizations.first).to be_a(Organization)

expect(user.groups.count).to eq(2)
expect(user.groups.first).to be_a(Organization)
expect(user.groups.second).to be_a(Group)
end
end

it "lists which member classes can belong to this group" do
Expand Down

0 comments on commit d180018

Please sign in to comment.