1) J'ai ce modèle d'emploi et l'institution modèleComment faire l'intégration de test créer par le biais d'autres modèle
class Job < ApplicationRecord
belongs_to :institution
# others attibutes
end
2) Ceci est mon action créer sur JobsController - je besoin d'une institution pour créer un emploi. c'est bon.
def create
build_job
save_job || render(:new, status: :unprocessable_entity)
end
3) C'est le test d'intégration que j'ai créé je ne reçois pas le test de la réussite
Dans 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) Et ceci est mon erreur de la console
#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
Merci beaucoup. Cela a fonctionné pour moi. Vos conseils sur la façon de mettre le bon chemin et comment créer le travail pour la bonne institution m'a aidé à comprendre. –