Sha256: ee9855f0ba1e576bc32de6ab92c86e914654bb083ec75900969e74a741faf2d8

Contents?: true

Size: 1.72 KB

Versions: 8

Compression:

Stored size: 1.72 KB

Contents

require 'rails_helper'

RSpec.describe Role, type: :model do
  before :all do
  end
  let(:user) { User.make! } 
  let(:company) { Company.make! } 
  let(:project) { Project.make! } 
  
  it "allows user assignment to super user" do
    ur = Role.new(user: user, ownable: SuperUser.new )
    ur.valid?.should be_truthy
  end

  it "allows user assignment to company admin" do
    ur = Role.create(user:user, ownable: company)
    ur.valid?.should be_truthy
  end

  it "invalidates a user role with an invalid ownable like 'Role'" do
    ur = Role.create(user:user, ownable: Role.new)
    ur.valid?.should be_falsey
  end

  context "User helper methods" do 
    it "should register a user as a super user" do
      user.superuser?.should == false
      Role.create!(user:user, ownable: SuperUser.new)
      user.reload
      user.superuser?.should == true
    end

    it "should register a company admin" do
      user.admin?(company).should == false
      Role.create!(user:user, ownable: company)
      user.reload
      user.admin?(company).should == true
    end

    it "should register a project administrator" do 
      user.admin?(project).should == false
      Role.create!(user:user, ownable: project)
      user.reload
      user.admin?(project).should == true
    end

    it "should register a user a company admin if admin of any company" do
      user.company_admin?.should == false
      Role.create!(user:user, ownable: company)
      user.reload
      user.company_admin?.should == true
    end

    it "should register a user as a project admin if admin of any project" do
      user.project_admin?.should == false
      Role.create!(user:user, ownable: project)
      user.reload
      user.project_admin?.should == true
    end

  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
introspective_grape-0.2.7 spec/models/role_spec.rb
introspective_grape-0.2.6 spec/models/role_spec.rb
introspective_grape-0.2.5 spec/models/role_spec.rb
introspective_grape-0.2.4 spec/models/role_spec.rb
introspective_grape-0.2.3 spec/models/role_spec.rb
introspective_grape-0.2.2 spec/models/role_spec.rb
introspective_grape-0.2.0 spec/models/role_spec.rb
introspective_grape-0.1.9 spec/models/role_spec.rb