How to add body in action text?
Post.rb
has_rich_text :body
test/fixtures/posts.yml
one:
name: <%= Faker::Name.unique.name %>
body: "body"
posts_controller_test.rb
require 'test_helper'
class PostsControllerTest < ActionDispatch::IntegrationTest
setup do
@post = posts(:one)
end
test "should get index" do
get posts_url
assert_response :success
end
end
I run the PostsControllerTest expected success response but got
Minitest::UnexpectedError: ActiveRecord::Fixture::FixtureError: table "posts" has no columns named "body"
.
Using rails 6.0, Ruby 2.7.1
Create file:
test/fixtures/action_text/rich_texts.yml
if it does not exist, then add these lines to it:
post_one:
record: one (Post) # record: record name (in_yml) in association (ModelName)
name: body # has_rich_text :name_of_rich_text_attribute
body: <p>Lorem ipsum dolor sit amet.</p> # actual rich text content
You also should remove body: "body"
from test/fixtures/posts.yml.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With