【发布时间】:2017-09-27 12:49:31
【问题描述】:
1) 我有这个模范职位和模范机构
class Job < ApplicationRecord
belongs_to :institution
# others attibutes
end
2) 这是我在 JobsController 上创建的操作 - 我需要一个机构来创建工作。没关系。
def create
build_job
save_job || render(:new, status: :unprocessable_entity)
end
3) 这是我创建的集成测试 我没有通过成功测试
在参数中
-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) 这是我的控制台错误
#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
【问题讨论】:
标签: ruby-on-rails ruby integration-testing