thoughtbot / thoughtbot/factory_bot

Initial value for sequences having no effect

Open
#1,724 1 comment 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

Hello! I was reading the documentation on restricting the sequence to an initial starting value. Following the documentation as written has no effect.

Reproduction Steps
require "bundler/inline"

gemfile(true) do
  source "https://rubygems.org"
  git_source(:github) { |repo| "https://github.com/#{repo}.git" }
  gem "factory_bot", "6.4.6"
  gem "activerecord"
  gem "sqlite3"
end

require "active_record"
require "factory_bot"
require "minitest/autorun"
require "logger"

ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
ActiveRecord::Base.logger = Logger.new(STDOUT)

ActiveRecord::Schema.define do
  create_table :posts, force: true do |t|
    t.integer :number_of_characters
  end
end

class Post < ActiveRecord::Base
end

FactoryBot.define do
  factory :post do
    sequence(:body, 1)
  end
end

class FactoryBotTest < Minitest::Test
  def test_factory_bot_stuff
    post = FactoryBot.create(:post)

    assert_equal post.number_of_characters, 1
  end
end
Expected behavior

The sequence starts with the integer 1.

Actual behavior

The sequence starts with the integer 4.

System configuration

6.4.6:
6.1.7.7:
3.1.5:

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 initial-value section of GETTING_STARTED.md and run the reproduction shown in the issue, checking the attribute used by the sequence against the attribute asserted in the test. Then trace the sequence entry point and add a regression test covering the documented starting value. Done means the documented example starts at 1 and the test suite passes.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.