我正在使用Rails 5和minitest。在我的测试文件中,我如何知道fixtures文件中某个项目的ID是什么?我有以下模式
create_table "lines", force: :cascade do |t|
t.string "route_long_name"
t.string "name"
t.integer "system_type"
t.string "color"
t.string "onestop_id"
t.string "vehicle_type"
t.string "wheelchair_accessible"
t.string "bikes_allowed"
t.index ["onestop_id"], name: "index_lines_on_onestop_id"
t.index ["route_long_name"], name: "index_lines_on_route_long_name"
end
然后在我的测试/夹具/生产线中。yml,我创建了这个装置
one:
id: "1"
name: "line1"
color: "green"
So in my minitest test, I try this
test "get show page with valid line id" do
test_line_id = "1"
line = Line.find_by_id(test_line_id)
puts "inspect1: #{line.inspect}"
assert_not_nil line
get line_url(line)
line = assigns(:line)
puts "inspect2 #{line.inspect}"
assert_equal test_line_id, line.id
assert_response :success
end
但是那条线
assert_equal test_line_id, line.id
模具有错误
Expected: "1"
Actual: "980190962"
那么,如何在fixtures文件中计算出项目的ID呢?