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

New === in matches? method inside testing.rb fails to test class equality #99

Closed
ptsavdar opened this issue Dec 13, 2019 · 2 comments
Closed

Comments

@ptsavdar
Copy link

Tell us about your environment

Ruby Version:
2.6.1
Framework Version (Rails, whatever):
Rails 5.2
Action Policy Version:
0.40.0

What did you do?

Upgraded from 0.31.1 to 0.40.0

What did you expect to happen?

Spec be_authorized_to to pass as usual.

What actually happened?

Spec failed with following error:

expected Finance::ChargeTypes::ChargeType(id: uuid, name: string, mode_of_transport: string, charge_basis: string, created_at: datetime, updated_at: datetime, vat_applicable: boolean, twenty_ft_dv: boolean, forty_ft_dv: boolean, forty_ft_hc: boolean, forty_five_ft_hc: boolean, hazardous: boolean, overweight: boolean, reefer: boolean, deleted_at: datetime) to be authorized with ChargeTypePolicy#index?, but the following calls were encountered:
       - Finance::ChargeTypes::ChargeType(id: uuid, name: string, mode_of_transport: string, charge_basis: string, created_at: datetime, updated_at: datetime, vat_applicable: boolean, twenty_ft_dv: boolean, forty_ft_dv: boolean, forty_ft_hc: boolean, forty_five_ft_hc: boolean, hazardous: boolean, overweight: boolean, reefer: boolean, deleted_at: datetime) was authorized with ChargeTypePolicy#index?

Here's the spec code:

it 'is authorized' do
    expect { subject }.to be_authorized_to(:index?, ::Finance::ChargeTypes::ChargeType).with(ChargeTypePolicy)
end

And here's the code that runs in subject:

def call(**_any)
    authorize!(::Finance::ChargeTypes::ChargeType, to: :index?, with: ::ChargeTypePolicy)
    # .... rest of code
end

I understand the need to check for an_instance_of(Post) for which === makes sense, however I would suggest to change the matches? method in testing.rb code to:

def matches?(policy_class, actual_rule, target)
    policy_class == policy.class &&
      (target === policy.record || target == policy.record) &&
      rule == actual_rule
end

or something similar.

Thank you in advance

@palkan
Copy link
Owner

palkan commented Dec 14, 2019

Yeah, sorry for that. Has been fixed today and released in 0.4.2.

@palkan palkan closed this as completed Dec 14, 2019
@ptsavdar
Copy link
Author

Thank you very much!

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

2 participants