LoginSignup
0
0

More than 5 years have passed since last update.

rspecで、let, beforeのコードの順番で紐付いたモデルが取れたり取れなかったりする

Posted at
api_spec.rb
let!(:user1) { create(:user, id: 1, finc_user_id: 1) }
let(:user2) { create(:user, id: 2, finc_user_id: 2) }
let(:partner_organization) { create(:partner_organization, id: 1) }
let(:partner_organization_branch) { create(:partner_organization_branch, partner_organization: partner_organization) }
let!(:partner_organization_branches_user) { create(:partner_organization_branches_user, partner_organization_branch: partner_organization_branch, user: user1) }

let(:url) { "/internal/v1/users/partner_organizations/" }
let(:params) { { finc_user_ids: finc_user_ids, application_token: Settings.wellness_survey.api.access_grant } }
before { get url, params }

だとok. ちゃんと
{"users"=>[{"id"=>1, "partner_organization_branches"=>[中身あり]}], "non_exist_users"=>[]}

api_spec.rb
let(:url) { "/internal/v1/users/partner_organizations/" }
let(:params) { { finc_user_ids: finc_user_ids, application_token: Settings.wellness_survey.api.access_grant } }
before { get url, params }

let!(:user1) { create(:user, id: 1, finc_user_id: 1) }
let(:user2) { create(:user, id: 2, finc_user_id: 2) }
let(:partner_organization) { create(:partner_organization, id: 1) }
let(:partner_organization_branch) { create(:partner_organization_branch, partner_organization: partner_organization) }
let!(:partner_organization_branches_user) { create(:partner_organization_branches_user, partner_organization_branch: partner_organization_branch, user: user1) }

{"users"=>[{"id"=>1, "partner_organization_branches"=>[中身なしblank]}], "non_exist_users"=>[]}
で紐付いたユーザが取れない

原因ググり中。

0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0