I will leave it as a memorandum about the unit test at the time of Routing nesting.
** 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
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