thoughtbot / factory_bot

A library for setting up Ruby objects as test data.

Home Page:https://thoughtbot.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

build_stubbed broke when i upgrade to Rails 7.1.3

dev-Gois opened this issue · comments

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