Я получаю это сообщение об ошибке при запуске моих тестов, соответствующие функции работают при тестировании в браузере.
Error:
ProductsControllerTest#test_should_create_product:
StandardError: No fixture named 'three' found for fixture set
'products'
test/controllers/products_controller_test.rb:5:in `block in
<class:ProductsControllerTest>'
bin/rails test test/controllers/products_controller_test.rb:24
Error:
ProductsControllerTest#test_should_get_index:
StandardError: No fixture named 'three' found for fixture set
'products'
test/controllers/products_controller_test.rb:5:in `block in
<class:ProductsControllerTest>'
bin/rails test test/controllers/products_controller_test.rb:14
Вот мои тесты, которые я тщательно проверил.
require 'test_helper'
class ProductsControllerTest < ActionDispatch::IntegrationTest
setup do
@product = products(:three)
@update = {
tite: 'lorxem Ipsum',
description: 'Wibbles are fun!',
image_url: 'lorem.jpg',
price: 19.95
}
end
test "should get index" do
get products_url
assert_response :success
end
test "should get new" do
get new_product_url
assert_response :success
end
test "should create product" do
assert_difference('Product.count') do
post products_url, params: { product: @update }
end
assert_redirected_to product_url(Product.last)
end
test "should show product" do
get product_url(@product)
assert_response :success
end
test "should get edit" do
get edit_product_url(@product)
assert_response :success
end
test "should update product" do
patch product_url(@product), params: { product: @update }
assert_redirected_to product_url(@product)
end
test "should destroy product" do
assert_difference('Product.count', -1) do
delete product_url(@product)
end
assert_redirected_to products_url
end
конец
А вот мои светильники
one:
title: MyString
description: MyText
image_url: test.jpg
price: 9.99
two:
title: MyString
description: MyText
image_url: test.jpg
price: 9.99
Вот мой код добавления продукта, который работает в браузере:
def create
@product = Product.new(product_params)
respond_to do |format|
if @product.save
format.html { redirect_to @product, notice: 'Product was
successfully created.' }
format.json { render :show, status: :created, location:
@product }
else
format.html { render :new }
format.json { render json: @product.errors, status:
:unprocessable_entity }
end
end
end
А вот мой код контроллера обновлений, который снова работает в браузере:
def update
respond_to do |format|
if @product.update(product_params)
format.html { redirect_to @product, notice: 'Product was
successfully updated.' }
format.json { render :show, status: :ok, location: @product }
else
format.html { render :edit }
format.json { render json: @product.errors, status:
:unprocessable_entity }
end
end
end
Любая помощь или руководство приветствуется.
EDIT:
Вот протоколы испытаний:
ProductsControllerTest: test_should_create_product
--------------------------------------------------
Product Load (0.2ms) SELECT "products".* FROM "products" WHERE "products"."id" = ? LIMIT ? [["id", 980190962], ["LIMIT", 1]]
(0.1ms) SELECT COUNT(*) FROM "products"
Started POST "/products" for 127.0.0.1 at 2019-05-08 08:35:35 +0100
Processing by ProductsController#create as HTML
Parameters: {"product"=>{"tite"=>"lorxem Ipsum", "description"=>"Wibbles are fun!", "image_url"=>"lorem.jpg", "price"=>"19.95"}}
Unpermitted parameter: :tite
(0.1ms) SAVEPOINT active_record_1
Product Exists (0.3ms) SELECT 1 AS one FROM "products" WHERE "products"."title" IS NULL LIMIT ? [["LIMIT", 1]]
(0.1ms) ROLLBACK TO SAVEPOINT active_record_1
Rendering products/new.html.erb within layouts/application
Rendered products/_form.html.erb (4.3ms)
Rendered products/new.html.erb within layouts/application (4.9ms)
Completed 200 OK in 13ms (Views: 7.1ms | ActiveRecord: 0.5ms)
(0.1ms) SELECT COUNT(*) FROM "products"
(0.1ms) rollback transaction
(0.1ms) begin transaction
Один из тестов теперь проходит - обновление - у продуктов в приборах было то же самое название, и название подтверждает свою уникальность, следовательно провал.
Будет полезна любая помощь с тестом создания продукта.
Спасибо