[英]Rails 5 Integration Test is only using fixtures values
我正在尝试在Rails 5中编写测试。我对生成的脚手架测试做了一些修改。 但是它似乎是从固定装置的某处获取的,仅使用此源运行测试。
控制器上的“创建”方法接受一个电子邮件用户和一个URL页面列表。
我的测试课:
require 'test_helper'
class UsersControllerTest < ActionDispatch::IntegrationTest
test "test" do
assert_difference('User.count', 1) do
post users_url, params: { user: { email: 'a@a' }, pages:[{url:'a'},{url:'b'},{url:'c'}] }, as: :json
end
assert_response 201
end
end
-------------------- fixtures --------------------------
_______PAGES.YML______ __________USERS.YML__________
| one: | | one: |
| url: one.html | | email: testmail@mail.com |
| | | |
| two: | | two: |
| url: pageTwo.html | | email: two@mail.com |
|______________________| |_____________________________|
调试时,在保存页面之前,该值正确:
<Page id: nil, url: "a", user_id: 980190963, created_at: nil, updated_at: nil>
但是测试完成后,我的数据库就像:
--USERS
id |email |created_at |updated_at |
----------|------------------|--------------------|--------------------|
980190962 |testmail@mail.com |2017-03-21 17:43:50 |2017-03-21 17:43:50 |
298486374 |two@mail.com |2017-03-21 17:43:50 |2017-03-21 17:43:50 |
--PAGES
id |url |contato_id |created_at |updated_at |
----------|-------------|-----------|--------------------|--------------------|
980190962 |one.html | |2017-03-21 17:43:50 |2017-03-21 17:43:50 |
298486374 |pageTwo.html | |2017-03-21 17:43:50 |2017-03-21 17:43:50 |
为什么我的电子邮件和URL值没有保存? 还是fk?
谢谢。
它看起来不是rspec,但我尝试回答。
运行测试时,Rails可以清理数据库表,因此它可以清理数据库中的所有数据并创建保存在数据库中的新夹具数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.