Sha256: 77af9cb8e540bac0067f9625ef7878b19ae044b921264b56f3e5409a2b2444e1
Contents?: true
Size: 1.37 KB
Versions: 1
Compression:
Stored size: 1.37 KB
Contents
require 'spec_helper' class User include Mongoid::Document include Mongoid::Document::Roleable field :name end describe "A Roleable model" do let(:user) { User.new(name: 'Drefined') } it "should have a add_role method" do user.should respond_to :add_role end it "should have a has_role? method" do user.should respond_to :has_role? end it "should have a remove_role method" do user.should respond_to :remove_role end it "should be able to add a role" do role = "superadmin" user.add_role(role) user.has_role?(role).should be true end it "should be able to remove a role" do role = "superadmin" user.add_role(role) user.remove_role(role) user.has_role?(role).should_not be true end end describe "A Roleable model with roles assigned" do before(:each) do @user = User.create(name: 'Drefined', with_roles: ['superadmin', 'admin', 'user']) end it "should be able to find_roles" do User.find_roles('superadmin').first.should eq(@user) User.find_roles(['superadmin', 'admin']).first.should eq(@user) end it "should be able to find_roles objects if more than one object is present" do user_2 = User.create!(name: 'Quicksorter', roles: 'admin') users_with_roles = User.find_roles('admin') users_with_roles.include?(@user).should be true users_with_roles.include?(user_2).should be true end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
mongoid-simple-roles-0.0.1 | spec/mongoid-simple-roles_spec.rb |