feature "comment" do
given(:user) do
build(:user)
end
background do
user1=create(:user)
user1.id=1
login_as(user1)
end
scenario "can create comment" do
@undertake=create(:undertake)
visit undertake_path(@undertake)
within("form#undertake-form-test") do
fill_in "content" , with: "heyheyhey"
end
click_button 'send-btn'
expect(page).to have_content 'heyheyhey'
end
end
Это спецификация/features/comment_spec.rb. и это ниже - контроллеры/предпринять_controller.rb.rspec, undefined method `id 'for nil: NilClass
class UndertakesController < ApplicationController
def show
@undertake=Undertake.find_by(id: params[:id])
@comment=current_user.comments.new
end
и нижеприведенные виды недвижимости/show.html.erb.
<p><%= @undertake.id %></p>
и spec/заводы/предприниматели.rb.
FactoryGirl.define do
factory :undertake do
association :ask
association :user
id 1
user_id 2
ask_id 1
title "MyString"
content "MyText"
result false
end
end
routes.rb
resources :asks , except:[:edit, :update] do
resources :undertakes , only:[:create , :show , :destroy] , shallow: true do
resources :comments , only:[:create]
end
end
Теперь, почему у меня ошибка ActionView::Template::Error:undefined method id for nil:NilClass
. Пожалуйста, помогите мне.
, пожалуйста, отобразите файл 'routes.rb'. –
Здесь можно найти маршруты.рб. Пожалуйста. –
ресурсов: запрашивает, кроме: [: изменить,: обновить] сделать ресурсов: обязывает, только: [: создать,: показать,: уничтожить], неглубоко: true do ресурсов: только комментарии: [: create] end end –