Naming the association in the model makes the relationship easier to express in the factory.
8 lines
237 B
Ruby
8 lines
237 B
Ruby
class UserRole < ActiveRecord::Base
|
|
belongs_to :user
|
|
belongs_to :granter, :class_name => "User"
|
|
|
|
ALL_ROLES = %w(administrator moderator).freeze
|
|
|
|
validates :role, :inclusion => ALL_ROLES, :uniqueness => { :scope => :user_id }
|
|
end
|