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

Convert controller specs to requests #90

Merged
merged 15 commits into from
Mar 22, 2021
Merged

Conversation

SamuelMartini
Copy link
Contributor

@SamuelMartini SamuelMartini commented Sep 4, 2020

Description

Ref #18

In converting the controller in request specs I have tried to not stubbing any method. The purpose of this PR is to port every test that was written in the controller and for this reason, it was not possible to avoid stubs in every example.

CheckoutController and OrderController are the more sensitive tests. CheckoutController has many before_action filters that make it cumbersome to ensure the example was testing the right filter (when the expectation is the same). Those tests probably make sense in a Controller test where you can stub messages to be received but in a request spec we are only interested in the response so we may want to revisit those tests. Also, It would be really cool to refactor the controller and
make it lean.

@SamuelMartini SamuelMartini self-assigned this Sep 4, 2020
@SamuelMartini SamuelMartini linked an issue Sep 4, 2020 that may be closed by this pull request
@SamuelMartini SamuelMartini changed the title Samuel martini/request specs Convert controller specs to requests Sep 4, 2020
@SamuelMartini SamuelMartini force-pushed the SamuelMartini/request_specs branch 2 times, most recently from 2ba1580 to 1062a7c Compare October 23, 2020 13:55
@SamuelMartini SamuelMartini force-pushed the SamuelMartini/request_specs branch 2 times, most recently from 2b2aafb to ab31c3f Compare December 18, 2020 10:39
@kennyadsl
Copy link
Member

@SamuelMartini I've opened solidusio/solidus#3873 to track what we need to do in core to remove the hack we did to test system specs without forgery protection.

@kennyadsl
Copy link
Member

kennyadsl commented Feb 16, 2021

@SamuelMartini forgery protection is now false on the dummy app in core!

@SamuelMartini SamuelMartini force-pushed the SamuelMartini/request_specs branch 2 times, most recently from 99de74d to 8263594 Compare March 12, 2021 13:12
@SamuelMartini SamuelMartini marked this pull request as ready for review March 12, 2021 13:16
@kennyadsl
Copy link
Member

@SamuelMartini can you please rebase now that specs are green on master? Also, I'd love to take advantage of this PR to get rid of the _controller part in the filename of specs. Now that they are requests specs it doesn't make a lot of sense anymore.

Usually, the authentication in solidus applications is provided by
`solidus_auth_devise`[1]. The solidus controllers in fact expect the devise
`current_spree_user` or custom `spree_current_user` methods to be
implemented and called inside the proxy `try_spree_current-user`[2]

When testing controllers through requests specs, examples should have no
dependency and knowledge of `solidus_auth_devise`. However, solidus
controllers need one of the above methods to fetch the current user.

This commit adds an helper method to the tested controllers to behave
like an extension implementing `spree_current_user`.

[1]: https://github.com/solidusio/solidus_auth_devise
[2]: https://github.com/solidusio/solidus/blob/fa7aa92d1b1c174d1a2489a0e20a3f99201820b8/core/lib/spree/core/controller_helpers/auth.rb#L71
This commit remove two examples:
- This test[1] as it is not possible to test without simulating an user
login during a checkout. However, this is tested in this system spec[2]
which is a more proper place for this kind of spec.

- This test[3] as it is testing the case the user does not respond to a
  method defined in solidus_core[4]. This method is part of the users
methods[5] which is a rails concern that must be included in any user
defined class.
[1]: https://github.com/nebulab/solidus_starter_frontend/blob/v0.1.0/spec/controllers/spree/checkout_controller_spec.rb#L59
[2]: https://github.com/nebulab/solidus_starter_frontend/blob/v0.1.0/spec/system/checkout_spec.rb#L162
[3]: https://github.com/nebulab/solidus_starter_frontend/blob/v0.1.0/spec/controllers/spree/checkout_controller_spec.rb#L127
[4]: https://github.com/solidusio/solidus/blob/v2.11.7/core/app/models/spree/order.rb#L787
[5]: https://github.com/solidusio/solidus/blob/v2.11.7/core/app/models/concerns/spree/user_methods.rb
Copy link
Member

@kennyadsl kennyadsl left a comment

Choose a reason for hiding this comment

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

Thanks @SamuelMartini for never give up on this huge task!

@kennyadsl kennyadsl merged commit 62a67a2 into master Mar 22, 2021
@kennyadsl kennyadsl deleted the SamuelMartini/request_specs branch March 22, 2021 14:33
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

Successfully merging this pull request may close these issues.

[Specs] Convert controller specs into requests specs
2 participants