Records created with FactoryGirl not available in Controller

北城余情 提交于 2019-12-12 01:57:11

问题


One of my tests has started failing. It previously worked and going through the same actions by hand in the browser show the feature to be working.

I create the records to be tested like this:

will = FactoryGirl.create(:user, profile: "security of the internet", first_name: "will")

To investigate, I added a

binding.pry 

call in my controller. The action searches Users.

If i do:

User.all

at the pry prompt, no users are shown, an empty result.

If i break into the actual test with pry, User.all shows the expected records.

What might be the cause of this?


回答1:


Usually this is because your test is tagged js: true and is using a JS capable driver but you are using transactional database testing. When using the "full browser" drivers the app and tests run. Different threads so they each have their own database connection. This means objects created in one threads transaction aren't visible in the other until committed, but when using transaction based testing nothing ever gets committed. To fix, turn off transactional testing and use truncation or deletion for that test - see database_cleaner



来源:https://stackoverflow.com/questions/37660341/records-created-with-factorygirl-not-available-in-controller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!