1) Ich habe dieses Modell Job und das Modell InstitutionWie Integrationstest schafft durch anderes Modell
class Job < ApplicationRecord
belongs_to :institution
# others attibutes
end
2) Dies ist meine Aktion erstellen, die auf JobsController zu tun - ich brauche eine Institution, einen Job zu erstellen. es ist in Ordnung.
def create
build_job
save_job || render(:new, status: :unprocessable_entity)
end
3) Dies ist der Integrationstest, die ich erstellt Ich bin nicht den Erfolg Test
In params -I also tried institution: @institution -and also tried institution_id: @institution.id
require 'test_helper'
class JobActionsTest < ActionDispatch::IntegrationTest
setup do
@user = users(:standard)
sign_in @user
@institution = institutions(:standard)
end
test "can create a job through institution" do
get new_institution_job_path(@institution)
assert_response :success
assert_difference('Job.count') do
post jobs_path,
params: {job: {title: "Desenvolvedor", description: "Ruby",
requirements: "rspec and capybara",
start_date: Date.today,
end_date: Date.today + 5.days,
institution: @institution.id}}
end
assert_response :redirect
follow_redirect!
assert_response :success
end
end
4) Und das ist meine Konsole Fehler bekommen
#Running:
E
Error:
JobActionsTest#test_can_create_a_job_through_institution:
ActiveRecord::RecordNotFound: Couldn't find Institution with 'id'=
app/controllers/jobs_controller.rb:74:in `job_scope'
app/controllers/jobs_controller.rb:52:in `build_job'
app/controllers/jobs_controller.rb:18:in `create'
test/integration/job_actions_test.rb:22:in `block (2 levels) in <class:JobActionsTest>'
test/integration/job_actions_test.rb:21:in `block in <class:JobActionsTest>'
bin/rails test test/integration/job_actions_test.rb:17
Vielen Dank. Das hat für mich funktioniert. Ihre Tipps, wie man den richtigen Weg einstellt und wie man den Job für die richtige Institution schafft, haben mir geholfen zu verstehen. –