Sha256: 25f0b9d774f71840657e633b53838b0616dafea3460af2ae346dc5a3092d3745

Contents?: true

Size: 1.54 KB

Versions: 5

Compression:

Stored size: 1.54 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 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
      user.superuser = true
      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

5 entries across 5 versions & 1 rubygems

Version Path
introspective_grape-0.3.2 spec/models/role_spec.rb
introspective_grape-0.3.1 spec/models/role_spec.rb
introspective_grape-0.3.0 spec/models/role_spec.rb
introspective_grape-0.2.9 spec/models/role_spec.rb
introspective_grape-0.2.8 spec/models/role_spec.rb