Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specs fail if user itself is resourcified #590

Open
eimantas opened this issue Mar 14, 2023 · 0 comments
Open

Specs fail if user itself is resourcified #590

eimantas opened this issue Mar 14, 2023 · 0 comments

Comments

@eimantas
Copy link

eimantas commented Mar 14, 2023

I have the following setup:

class User < ApplicationRecord
  rolify
  resourcify
end

class Subject < ApplicationRecord
  resourcify
end

and the following spec:

require 'rails_helper'

RSpec.describe Subject, type: :model do
  it 'can give access to users' do 
    user = User.create!()
    subject = Subject.create!()
    user.add_role :admin, subject
    expect(subject.applied_roles).to include(user.roles.first)
  end
end

The above spec fails. It passes as soon as I remove the resourcify from User class. The failure message I get is:

% bundle exec rspec spec/models/subject_spec.rb:7
Run options: include {:locations=>{"./spec/models/subject_spec.rb"=>[7]}}
F

Failures:

  1) Subject can give access to users
     Failure/Error: expect(subject.applied_roles).to include(user.roles.first)
     
       expected [] to include #<Role id: 1, name: "admin", resource_type: "User", resource_id: 1, created_at: "2023-03-14 06:51:29.467423000 +0000", updated_at: "2023-03-14 06:51:29.482289000 +0000">
       Diff:
       @@ -1 +1 @@
       -[#<Role id: 1, name: "admin", resource_type: "User", resource_id: 1, created_at: "2023-03-14 06:51:29.467423000 +0000", updated_at: "2023-03-14 06:51:29.482289000 +0000">]
       +[]
       
     # ./spec/models/subject_spec.rb:9:in `block (2 levels) in <top (required)>'

Finished in 0.07391 seconds (files took 1.47 seconds to load)
1 example, 1 failure

Failed examples:

rspec ./spec/models/subject_spec.rb:5 # Subject can give access to users

System info:

% uname -a 
Darwin machine.lan 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:42:11 PST 2023; root:xnu-8792.81.3~2/RELEASE_X86_64 x86_64
% ruby -v
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-darwin21]
% rails --version
Rails 7.0.4.3

Rolify v6.0.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant