Sha256: 6441711ad5533e487a9f480a17f6727123dcccd27198b0ddb438dd3f447c4770
Contents?: true
Size: 1.94 KB
Versions: 3
Compression:
Stored size: 1.94 KB
Contents
require 'spec_helper' use_roles_strategy :role_string class User include DataMapper::Resource include Roles::DataMapper strategy :role_string, :default property :id, Serial property :name, String end DataMapper.finalize DataMapper.auto_migrate! User.valid_roles_are :admin, :guest describe "Roles for Mongoid" do context "default setup" do before :each do @user = User.create(:name => 'Kristian') @user.role = :guest @user.save @admin_user = User.create(:name => 'Admin user') @admin_user.roles = :admin @admin_user.save end describe '#in_role' do it "should return first user matching role" do User.in_role(:guest).first.name.should == 'Kristian' User.in_role(:admin).first.name.should == 'Admin user' end end describe "Role API" do it "should have admin user role to :admin" do @admin_user.roles_list.first.should == :admin @admin_user.admin?.should be_true @admin_user.has_role?(:guest).should be_false @admin_user.has_role?(:admin).should be_true @admin_user.is?(:admin).should be_true @admin_user.has_roles?(:admin).should be_true @admin_user.has?(:admin).should be_true end it "should have user role to :guest" do @user.roles_list.first.should == :guest @user.admin?.should be_false @user.has_role?(:guest).should be_true @user.has_role?(:admin).should be_false @user.is?(:admin).should be_false @user.has_roles?(:admin).should be_false @user.has?(:admin).should be_false end it "should set user role to :admin using roles=" do @user.roles = :admin @user.roles_list.first.should == :admin @user.has_role?(:admin).should be_true end end end end
Version data entries
3 entries across 3 versions & 1 rubygems