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

Add a spec for the project policy #5878

Closed
wants to merge 1 commit into from

Conversation

vpereira
Copy link
Contributor

Add rspec for the pundit project policy

end

permissions :local_project_and_allowed_to_create_package_in? do
it { expect(subject).to permit(user, project) }
Copy link
Member

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 😉

Copy link
Contributor Author

@vpereira vpereira Sep 19, 2018

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 ?

Copy link
Contributor Author

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 ;)

@Ana06
Copy link
Member

Ana06 commented Sep 19, 2018

@vpereira

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 ?

no, as I said, rubocop doesn't understand the permission block. Not so smart ;)

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, '') }
Copy link
Member

@Ana06 Ana06 Sep 19, 2018

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.

Copy link
Contributor Author

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,

Copy link
Contributor Author

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.

Copy link
Member

@Ana06 Ana06 Sep 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vpereira

Otherwise I would ask you to approve it,

@Ana06 could you please tell me if you see a different use case or please accept it? thank you.

We don't need to hurry to approve it. I have some more concerns. I'll add them in a moment

Copy link
Member

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

@vpereira
Copy link
Contributor Author

vpereira commented Sep 19, 2018

Reporting it upstream is IMO part of the culture/philosophy of working in open source,

sure, please go ahead. Even better if you submit a PR to them. Thank you for making the open source community better 💓 💓 💓 💓

@DavidKang DavidKang added Frontend Things related to the OBS RoR app Test Suite / CI 💉 Things related to our tests/CI labels Sep 20, 2018
@hennevogel
Copy link
Member

@Ana06? 2 Days hanging now.

Copy link
Contributor

@mdeniz mdeniz left a 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
Copy link
Contributor

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

Copy link
Member

@Ana06 Ana06 Sep 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was probably not private when @vpereira wrote the test, as this was introduced in 3e22695

It makes now no sense to test it.

Copy link
Contributor Author

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
Copy link
Contributor

@mdeniz mdeniz Sep 21, 2018

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

@Ana06
Copy link
Member

Ana06 commented Sep 21, 2018

@hennevogel

@Ana06? 2 Days hanging now.

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.

Copy link
Member

@Ana06 Ana06 left a 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, '') }
Copy link
Member

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) }
Copy link
Member

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 vpereira closed this Sep 22, 2018
@Ana06
Copy link
Member

Ana06 commented Sep 24, 2018

@vpereira why have you closed this? 😕

@vpereira
Copy link
Contributor Author

@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 local_project_and_allowed_to_create_package_in? would fail, @hennevogel would have to adapt it, extend it to cover the new permissions added by him. It would be a quick win.

However looks like there were more important issues "to be resolved" here before it get merged.. just sad 💔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Frontend Things related to the OBS RoR app Test Suite / CI 💉 Things related to our tests/CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants