thoughtbot / thoughtbot/factory_bot

build_stubbed broke when i upgrade to Rails 7.1.3

Open
#1,634 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Ruby
Stars
8.2k
Forks
2.6k
PR merge metrics
No merged PRs in 30d

Description

Description

When i try to upgrade to Rails 7.1 from Rails 6.0, i get some errors in my specs, i found for some reason when i use build_stubbed in validations, it don't work properly.

Reproduction Steps

I just runned my specs and for some reason this broke:

  context "validations" do
    it { is_expected.to(validate_presence_of(:product_id)) }

    it "validate uniqueness of product_id" do
      valid_seasonality_item = create(:seasonality_item)
      invalid_seasonality_item = build_stubbed(:seasonality_item,
        product: valid_seasonality_item.product,
        seasonality: valid_seasonality_item.seasonality,
      )
      invalid_seasonality_item.valid?
      expect(invalid_seasonality_item.errors&.first&.attribute).to(eq(:product_id))
    end
  end

idk, for some reason this dont work, is expected to the invalid_seasonality_item to be invalid, but, its valid in this tests, so, i just changed the build_stubbed for build and thats works

Expected behavior

I want some response about what happened with build_stubbed and a solution for that

Actual behavior

At the moment, my specs with build_stubbed are broke.

System configuration

factory_bot version: "factory_bot_rails", "~> 6.4.0"
rails version: "rails", "~> 7.1.3"
ruby version: ruby 3.3.0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the provided validation spec and reproduce it using build_stubbed with Rails 7.1.3, Ruby 3.3.0, and factory_bot_rails 6.4. Compare the resulting validation behavior with build, then consider the issue done when the cause is documented and the affected behavior has a verified regression test or confirmed project-level resolution.

Written by the indexing model from the issue text.

Assessment

Tech stack
rails, ruby
Domain
testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.