Sha256: 4fc8b42e26a7cc90336531949b701af18b4b44b97d3d90ff8b170179905bddfb

Contents?: true

Size: 1.48 KB

Versions: 16

Compression:

Stored size: 1.48 KB

Contents

require "rolify/shared_contexts"

shared_examples_for "Role.scopes" do
  before do
    role_class.destroy_all
  end
  
  subject { user_class.first }
  
  describe ".global" do 
    let!(:admin_role) { subject.add_role :admin }
    let!(:staff_role) { subject.add_role :staff }
     
    it { subject.roles.global.should == [ admin_role, staff_role ] }
  end
  
  describe ".class_scoped" do
    let!(:manager_role) { subject.add_role :manager, Group }
    let!(:moderator_role) { subject.add_role :moderator, Forum }
    
    it { subject.roles.class_scoped.should =~ [ manager_role, moderator_role ] }
    it { subject.roles.class_scoped(Group).should =~ [ manager_role ] }
    it { subject.roles.class_scoped(Forum).should =~ [ moderator_role ] }
  end
  
  describe ".instance_scoped" do
    let!(:visitor_role) { subject.add_role :visitor, Forum.first }
    let!(:zombie_role) { subject.add_role :visitor, Forum.last }
    let!(:anonymous_role) { subject.add_role :anonymous, Group.last }
    
    it { subject.roles.instance_scoped.to_a.entries.should =~ [ visitor_role, zombie_role, anonymous_role ] }
    it { subject.roles.instance_scoped(Forum).should =~ [ visitor_role, zombie_role ] }
    it { subject.roles.instance_scoped(Forum.first).should =~ [ visitor_role ] }
    it { subject.roles.instance_scoped(Forum.last).should =~ [ zombie_role ] }
    it { subject.roles.instance_scoped(Group.last).should =~ [ anonymous_role ] }
    it { subject.roles.instance_scoped(Group.first).should be_empty }
  end
end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
rolify-6.0.1 spec/rolify/shared_examples/shared_examples_for_scopes.rb
rolify-6.0.0 spec/rolify/shared_examples/shared_examples_for_scopes.rb
rolify-5.3.0 spec/rolify/shared_examples/shared_examples_for_scopes.rb
rolify-5.2.0 spec/rolify/shared_examples/shared_examples_for_scopes.rb
rolify-5.1.0 spec/rolify/shared_examples/shared_examples_for_scopes.rb
rolify-5.0.0 spec/rolify/shared_examples/shared_examples_for_scopes.rb
rolify-4.1.1 spec/rolify/shared_examples/shared_examples_for_scopes.rb
rolify-4.1.0 spec/rolify/shared_examples/shared_examples_for_scopes.rb
rolify-4.0.0 spec/rolify/shared_examples/shared_examples_for_scopes.rb
rolify-3.5.2 spec/rolify/shared_examples/shared_examples_for_scopes.rb
rolify-3.5.1 spec/rolify/shared_examples/shared_examples_for_scopes.rb
rolify-3.5.0 spec/rolify/shared_examples/shared_examples_for_scopes.rb
rolify-3.4.1 spec/rolify/shared_examples/shared_examples_for_scopes.rb
rolify-3.4.0 spec/rolify/shared_examples/shared_examples_for_scopes.rb
rolify-3.3.0 spec/rolify/shared_examples/shared_examples_for_scopes.rb
third-prestige-rolify-3.3.0.rc5 spec/rolify/shared_examples/shared_examples_for_scopes.rb