Sha256: 66018b81b7a019d8f45119d0c49afc64d9467208b532a5101813677eb350871c

Contents?: true

Size: 1.12 KB

Versions: 3

Compression:

Stored size: 1.12 KB

Contents

require "active_record/strategy_helper"
require 'active_record/models/custom_join'

def migrate_up
  CreateCustomJoin.up # run migration
  Config.add_roles [:user, :admin, :editor, :blogger]
end

def migrate_down
  CreateCustomJoin.down
end      

User.troles_strategy :ref_many do |c|
  c.valid_roles = [:user, :admin, :blogger, :editor]
  # c.auto_config[:relations] = false
end.configure! :role_join_model => 'RolesUsersJoin'

module UserSetup
  def find_role name
    Role.where(:name => name.to_sym).first
  end

  def create_no_roles_user
    Factory.create :user, :name => 'no roles', :troles => []
  end

  def create_user
    Factory.create :user, :name => 'normal', :troles => [ find_role(:user) ]
  end

  def create_admin_user
    Factory.create :user, :name => 'admin', :troles => [ find_role(:admin) ]
  end

  def create_complex_user
    Factory.create :user, :name => 'user and admin', :troles => [ find_role(:user), find_role(:admin) ]
  end
end


require 'troles/common/api_spec' # Common API examples  

describe 'Troles strategy Custom Join' do
  it_should_behave_like "Common API"
  # it_should_behave_like "Troles API"  
end    

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
troles-0.6.1 spec/active_record/strategies/many/custom_join_spec.rb
troles-0.6.0 spec/active_record/strategies/many/custom_join_spec.rb
troles-0.5.2 spec/active_record/strategies/many/custom_join_spec.rb