Running integration test with Selenium loses database records

10 views
Skip to first unread message

Jack Royal-Gordon

unread,
Nov 18, 2020, 10:27:54 PM11/18/20
to rs...@googlegroups.com
Testing a Rails app (4.2) with RSpec (3.99) and Capybara (2.18). The beginning of the test creates a user and attempts to login to the user's account. By the time my Rails code gets control in the "login" module, the user has disappeared from the database. Here's the code in question:

@user = FactoryGirl.create :user_fully_setup
 visit root_path
 fill_in :email,     with: @user.email
 fill_in :password,  with: @user.password
 click_button

This code executes successfully (the click_button logs in the user) unless I add “js: true” to the test example, in which case I can see the browser window and it indeed fails to login (because the user is gone).

When running with Selenium, at the point before "click_button", the user still exists. When it hits my first "before_filter" in the controller when the "click_button" is executed, the user is gone (along with records in other tables created at the same time as the user).

I know that RSpec often runs inside a db transaction, is there any way Capybara could be causing the transaction to get reset?

If you’re wondering why I’m trying to run this with Selenium when it works just fine without it, it’s really just the first step of the test, and JS is being tested downstream from this part, so I will need it, just not for this part.

Phil Pirozhkov

unread,
Nov 19, 2020, 3:34:53 AM11/19/20
to Jack Royal-Gordon
Before you got it to Rails 5.1, you'll have to share the transaction to be able to set up the database from "the client part".

--
You received this message because you are subscribed to the Google Groups "rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rspec+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rspec/2D73D42B-CC1B-41E6-BFEE-EDECADEE128F%40pobox.com.

Jack Royal-Gordon

unread,
Nov 19, 2020, 3:34:41 PM11/19/20
to rs...@googlegroups.com
Thanks for the quick response Phil. That fixed the problem. But now I have a different issue.

When login is complete, control is redirected to another page. That page submits a background job to Sidekiq and then displays a screen with a META refresh of 15 seconds. When running live, this makes the page refresh every 15 seconds. Once the report has finished, the controller recognizes this and instead of generating the holding page, generates the report.

That’s how it works in development and production. In testing, there is no background job. So instead, I added a call inline within the test to run the background job. It works just fine, but the browser display never refreshes. And if I click the Refresh button on the browser screen, it acts like it’s doing something (dot running back and forth on tab’s header) but never finishes. And if I try “page.driver.refresh” (instead of clicking the page’s refresh button), nothing happens (no refresh, no running dot, etc).

I can accept that maybe the META Refresh is being ignored, but I would have though that page.driver.refresh would have refreshed the page, and that if that didn’t, then the refresh button would.

If I change the post-login action to redirect to a different page with no META refresh, it works just fine.


Reply all
Reply to author
Forward
0 new messages