Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How test the action text? how to add the action text in yml?

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

like image 292
Praveen Raj005 Avatar asked Sep 13 '25 11:09

Praveen Raj005


1 Answers

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.

like image 72
MibraDev Avatar answered Sep 15 '25 00:09

MibraDev