On Thursday, August 27, 2015 at 7:47:05 AM UTC-7, Jon Whitcraft wrote:
>
> Hello,
>
> I have an endpoint that uses a Sequel Model with full_text_search to pull 
> the data and return.  This all works fine, but when I goto test it the test 
> always fails because the data hasn't been committed to the DB yet.
>
> I have this code in my spec_helper.rb file
>
> config.around(:each) do |example|
>   @app.database.transaction(:rollback=>:always, 
> :auto_savepoint=>true){example.run}
> end
>
>
> which means, that when I run this test
>
> it 'will return a specific record' do
>   spec_deploy = create(:deploy, user_id: user[:id], build_id: build[:id])
>   get "/rest/v1/deploy?q=#{spec_deploy[:author]}"
>   expect(last_response.status).to eq(200)
>   json = JSON.parse(last_response.body)
>   expect(json['records']).not_to be_empty
> end
>
>
> It fails because it tries to run the full_text_search count query on the 
> db and the data doesn't exist.
>
> Is there a way for me to tell this specific test to not use transactions 
> or to commit and rollback manually?
>

Yes.  RSpec provides a way to pass additional data to the it method and 
access it from example (inside your around(:each)) block, so you can decide 
whether or not to use transactions for that spec.  I'm not an RSpec user, 
so I'm not sure the exact syntax for doing so, but I'm sure RSpec 
documentation covers it.

Note that this should not be a problem if you are using rack-test to 
retrieve the data from an in-process web application.  It's only if an 
external browser simulator is used that it should be an issue.

Thanks,
Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to