0
我试图在rails 5中编写测试。我修改了一些生成的脚手架测试。但它似乎是从某个地方得到的,只能用这个来源运行测试。Rails 5集成测试只使用灯具值
控制器上的'create'方法接受一个带有电子邮件的用户和一个带有url的页面列表。
我的测试类:
require 'test_helper'
class UsersControllerTest < ActionDispatch::IntegrationTest
test "test" do
assert_difference('User.count', 1) do
post users_url, params: { user: { email: '[email protected]' }, 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: [email protected] |
| | | |
| two: | | two: |
| url: pageTwo.html | | email: [email protected] |
|______________________| |_____________________________|
调试时,对之前保存的网页的值是否正确:
<Page id: nil, url: "a", user_id: 980190963, created_at: nil, updated_at: nil>
但测试compleats后,我的数据库是这样的:
--USERS
id |email |created_at |updated_at |
----------|------------------|--------------------|--------------------|
980190962 |[email protected] |2017-03-21 17:43:50 |2017-03-21 17:43:50 |
298486374 |[email protected] |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 |
为什么我的电子邮件和网址值没有保存?也不是fk?
感谢。
谢谢。很难认识到Rails默认清除了所有的测试数据。文档没有明确提到这一点。 – Aleph