Sha256: 42d87d6cd0cc2b850aac6aa59248a83c1cf27f8001b97d172597e226be62ee81

Contents?: true

Size: 1.08 KB

Versions: 3

Compression:

Stored size: 1.08 KB

Contents

require "active_record/strategy_helper"
require 'active_record/models/ref_many'

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

def migrate_down
  CreateRefMany.down
end      

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

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 :ref_many' 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/ref_many_spec.rb
troles-0.6.0 spec/active_record/strategies/many/ref_many_spec.rb
troles-0.5.2 spec/active_record/strategies/many/ref_many_spec.rb