-
Notifications
You must be signed in to change notification settings - Fork 401
Open
Description
I have the following setup:
class User < ApplicationRecord
rolify
resourcify
end
class Subject < ApplicationRecord
resourcify
endand 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
endThe 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 usersSystem 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
j-jzk
Metadata
Metadata
Assignees
Labels
No labels