-
Notifications
You must be signed in to change notification settings - Fork 684
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
RSpec controller tests fail with v11 of the shopify app #879
Comments
Thanks @Jay-Plumb this is a duplicate; please follow along here: #874 |
@Jay-Plumb Thank you for sharing your workaround. It does seem like this is not a duplicate (As I told tiffany it might be, it was my fault she closed it! Sorry) I just want to clarify. Your tests stubbing changed to add versioning? Is that what change? Or do you know exactly why you need to change it this way? I think I will reopen this because it would be a good idea to add test helpers for this gem to make it easier for people to test their code. This way these sort of issues need to be opened |
Hey @tanema, I attempted the solution within #874 but I can confirm that the approach did not work for me. I believe the reason for the change was in relation to switching from: # config/initializers/shopify_app.rb
ShopifyApp.configure do |config|
...
config.session_repository = Shop
end to: # config/initializers/shopify_app.rb
ShopifyApp.configure do |config|
...
config.session_repository = 'ShopifyApp::InMemorySessionStore'
end but I am not 100% sure if that is the cause. However, I can definitely confirm that on v10 the old approach worked but I hit into issues from
Thanks! |
I'm stuck on this, however the proposed workaround isn't working for me :( |
I also encountered this issue with def login_shop(shop)
stubbed_session = ShopifyAPI::Session.new(domain: shop.shopify_domain, token: shop.shopify_token, api_version: shop.api_version)
expect(ShopifyApp::SessionRepository).to receive(:retrieve_shop_session).and_return(stubbed_session)
@request.session[:shop_id] = shop.id
end |
This issue is stale because it has been open for 2 years. It will be closed if no further action occurs in 14 days. |
We are closing this issue because it has been inactive for a few months. If you still encounter this issue with the latest stable version, please reopen using the issue template. You can also contribute directly by submitting a pull request– see the CONTRIBUTING.md file for guidelines Thank you! |
Hey team,
Until v10 of the shopify app, it was possible to stub out the sessions controller within our RSpec tests such as:
From there, we could define a before action within our controller tests which would prevent our test from redirecting due to not having an activated session:
However, since v11 of the shopify app gem, I found the above no longer worked and after looking at how
/lib/shopify_app/controller_concerns/login_protection.rb
operated, I fixed the test suite by doing the following:All I am doing is stubbing out the retrieve call to ShopifyApp::SessionRepository and returning a stubbed version and allows the session to be activated.
Now, the reason why I wanted to open an issue is to help share my solution with others. I have had comments in the past with how to still test controllers when inheriting from
ShopifyApp::AuthenticatedController
. I think it could be really useful to have the above added to the README.md to help others that use RSpec for their testsuite. I am more than happy to make the change but I will wait for feedback from the team first. Equally, if anyone has a better solution to the above then do share and we can take it from there!The text was updated successfully, but these errors were encountered: