Created
July 6, 2009 23:39
-
-
Save mtodd/141766 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| class Account < ActiveRecord::Base | |
| has_many :users | |
| has_many :account_admin_permissions | |
| has_many :admins, :through => :account_admin_permissions, :class_name => 'User' | |
| end |
This file contains hidden or 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
| class AccountAdminPermission < ActiveRecord::Base | |
| belongs_to :account | |
| belongs_to :user | |
| end |
This file contains hidden or 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
| Factory.define :account do |a| | |
| a.name { Factory.next(:name) } | |
| end | |
| Factory.define :user do |u| | |
| u.name { "%s User" % Factory.next(:name) } | |
| u.login { |u| u.name.downcase.gsub(/\s/, '.') } | |
| u.email { |u| "%s@example.com" % u.login } | |
| u.password "secret" | |
| u.password_confirmation { |u| u.password } | |
| u.account { |u| u.association(:account) } | |
| # TRIED THIS: | |
| u.account_admin_permission { |u| u.association(:account_admin_permission, :account => u.account) } | |
| end | |
| Factory.define :account_admin_permission do |p| | |
| p.association(:user) | |
| p.association(:account) | |
| # BOTH VERSIONS result in infinite loops | |
| # p.user { |u| u.association(:user) } | |
| # p.account { |u| u.association(:account) } | |
| end |
This file contains hidden or 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
| class User < ActiveRecord::Base | |
| belongs_to :account | |
| has_one :account_admin_permission | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment