[RUBY] [Rails5] Rspec -Unit test when nesting-

・ Introduction

I will leave it as a memorandum about the unit test at the time of Routing nesting.

1. Prerequisites

** First, suppose the post table exists as below, **

create_table "posts", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
    t.string "content", null: false
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.integer "group_id"
    t.integer "user_id"
  end

** And it is in a state of being nested under the group as shown below. ** **

  resources :groups do
    resources :posts, only: %i[new create edit update]
  end

2. Conclusion

It's not that difficult, so I'll write a conclusion.

Under the above conditions

** I just passed the parameter of the parent model id to the expected behavior ** (I was really into trying to create the parent model directly)

  before do
    get :new, params: { group_id: group.id }
  end

I was able to memorize it in a hash format very simply.

Recommended Posts

[Rails5] Rspec -Unit test when nesting-
Let's unit test with [rails] Rspec!
[Rails] Test with RSpec
[Rails] Test code using Rspec
[Rails] About Rspec response test
[Rails] From test preparation to model unit testing [RSpec]
About app testing RSpec (unit test)
[RSpec] Unit test (using gem: factory_bot)
[Rails] Unit test code for User model
Introduce RSpec and write unit test code
[Ruby on Rails] View test with RSpec
[Ruby on Rails] Controller test with RSpec
[Ruby on Rails] Model test with RSpec
Rails tutorial test
Rspec Basics [Rails]
[Rails5] Rspec -validation-
About RSpec (Rails)
I rewrote the Rails tutorial test with RSpec
Introducing Rspec, a Ruby on Rails test framework
RSpec test code execution
RSpec unit test code creation procedure (login user creation Ver.)
Test run on rails
[Rails / RSpec] Write Model test (using Shoulda Matchers / FactoryBot)
Rails5 Rspec test error ArgumentError: Factory not registered: user
Java Unit Test Library-Artery-Sample
Test Nokogiri with Rspec.
Resolve ActiveRecord :: NoDatabaseError when doing rails test (Rails tutorial Chapter 3)
Rails, RSpec installation procedure
Unit test with Junit.
I tried unit testing Rails app using RSpec and FactoryBot
About method matchers used in model unit test code (RSpec)
The story when the test folder was not created in Rails
[Challenge CircleCI from 0] Build an automated test (Rails6.0, mysql8.0, Rspec)
rails test db only drop
[IntelliJ IDEA] Perform Unit Test
Test Active Strage with RSpec
Introduction to Micronaut 2 ~ Unit test ~
Unit test architecture using ArchUnit
Test GraphQL resolver with rspec
Implementation of unit test code
Error when using rails capybara
Detailed tips when using Rails
Understand code coverage with Rspec, the Ruby on Rails test framework
Breakpoint doesn't work when running Rails Minitest in Ruby Test Explorer
Password dummy data generation notes in Rails model unit test code
[Ruby On Rails] When a model unit test is performed with RSpec using FactoryBot, an error occurs because the foreign key is not entered.