-
Notifications
You must be signed in to change notification settings - Fork 442
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
Add a spec for the project policy #5878
Conversation
end | ||
|
||
permissions :local_project_and_allowed_to_create_package_in? do | ||
it { expect(subject).to permit(user, project) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this test is repeated! 🙈 it is one case for line 13. Instead of disabling Rubocop, listen to the smart Rubocop and remove this line 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
they are repeated or rubocop cannot understand the permissions block? For me looking the documentation https://www.rubydoc.info/gems/pundit/Pundit%2FRSpec%2FDSL:permissions - and looking the source code, look like we are testing different method, with the same parameters, which results in different tests, therefore not repeated, no @Ana06 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, as I said, rubocop doesn't understand the permission block. Not so smart ;)
d383aca
to
d1e597e
Compare
it was repeated, but you are right there is also a Rubocop bug. When having a Rubocop bug instead of disabling it in the file, where it will keep for ever even if it gets fixed upstream, you should report it upstream and regenerate the todo file. This way if it is solved upstream, we don't have to do anything else. Reporting it upstream is IMO part of the culture/philosophy of working in open source, we should contribute with the upstream project we are using as it is good for us as well and because we want our users to do the same and it takes 1 minute to add a comment to the issue. Anyway, as you said you don't want to report it, I have done already: rubocop/rubocop-rspec#333 (comment) |
end | ||
|
||
permissions :local_project_and_allowed_to_create_package_in? do | ||
it { expect(subject).not_to permit(user, '') } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should test this also for other kind of users 🤔 I mean the case with an empty string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not necessary. There is no different behavior if it's a remote project and user is normal or user is admin. Unless you spot some specific use case. Otherwise I would ask you to approve it,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ping @Ana06 could you please tell me if you see a different use case or please accept it? thank you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As @mdeniz mentioned, this is private and shouldn't now be tested, for any user
sure, please go ahead. Even better if you submit a PR to them. Thank you for making the open source community better 💓 💓 💓 💓 |
@Ana06? 2 Days hanging now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that you need to cover update?
and destroy?
. I would cover also index?
and show?
to ensure that always return true.
it { expect(subject).to permit(admin_user, project) } | ||
end | ||
|
||
permissions :local_project_and_allowed_to_create_package_in? do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a private method in the policy, no need to test it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it wasn't private, and show?
and index?
didn't exist @mdeniz
let(:project) { user.home_project } | ||
subject { ProjectPolicy } | ||
|
||
permissions :create?, :can_create_package_in?, :unlock?, :local_project_and_allowed_to_create_package_in? do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
local_project_and_allowed_to_create_package_in? is private, no need to test it
There has been some recent changes (some methods are now private) that affect this PR, I need to review this again. @mdeniz has just commented about that. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @mdeniz that the untested method should be tested, specially update
because it does include a lot of logic.
end | ||
|
||
permissions :local_project_and_allowed_to_create_package_in? do | ||
it { expect(subject).not_to permit(user, '') } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As @mdeniz mentioned, this is private and shouldn't now be tested, for any user
|
||
permissions :create?, :can_create_package_in?, :unlock?, :local_project_and_allowed_to_create_package_in? do | ||
it { expect(subject).to permit(user, project) } | ||
it { expect(subject).not_to permit(anonymous_user, project) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think in the test here we should test the code in project_policy.rb
, but not the code in can_create_project?
and can_modify?
which should be tested in the User model. So basically I would have just 2 test, one with a user and another one without user. The rest is in IMO responsibility of the model test.
@vpereira why have you closed this? 😕 |
@Ana06 this was a simple PR, that should be merged before 3e22695, but then it got stuck in the review. if it was approved and merged before the 3e22695, then tests for However looks like there were more important issues "to be resolved" here before it get merged.. just sad 💔 |
Add rspec for the pundit project policy