ruby on rails - Database not getting set up with :js => true -
with code below browser fires test. can see rendered page. items missing on page supposed in database. why isn't database getting populated?
when rid of ":js =>true" database set up.. test fails because need javascript click on table row.
require 'spec_helper' feature "[user can add analysis line]", :js => true context "[user signed in]" scenario "[user can visit home page click on line , add analysis]" puts "** add analysis feature spec not working **" jim = fabricate(:user) sign_in(jim) nfl = fabricate(:league, name: "nflxx") nba = fabricate(:league, name: "nba") nhl = fabricate(:league, name: "nhl") mlb = fabricate(:league, name: "mlb") nfl_event1 = fabricate(:event, league: nfl, home_team: "eagles") nfl_event2 = fabricate(:event, league: nfl, home_team: "jets") nba_event = fabricate(:event, league: nba, home_team: "sixers") nhl_event = fabricate(:event, league: nhl, home_team: "flyers") mlb_event = fabricate(:event, league: mlb, home_team: "phillies") visit(posts_path) find('.league-text').click_link("all") page.all('.vegas-line')[0].click click_link("add analysis") fill_in('post_title', :with => "this analysis") fill_in('post_content', :with => "this long analysis game. if should me") click_button('post') page.should have_content "post submitted sucessfully" end end end
i think problem have when tests run javascript test code , application server code running in separate threads , therefore don't share same database connection.
if have rspec-rails running default configuration using database transactions cleanup (the test wrapped in transaction rolled @ end). doesn't work across multiple threads or processes. see https://github.com/jnicklas/capybara#transactions-and-database-setup
the common way solve problem use database cleaner gem - https://github.com/bmabey/database_cleaner
Comments
Post a Comment