Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix undefined method config #440

Merged
merged 6 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
fail-fast: false
matrix:
rails: ["7.0", "6.1"]
rails: ["7.1", "7.0", "6.1"]
ruby: ["3.2", "3.1"]
include:
- rails: "6.1"
Expand Down
11 changes: 11 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,14 @@ appraise "rails7.0" do
gem "spring-watcher-listen", "~> 2.0.0"
gem "sqlite3", "~> 1.4"
end

appraise "rails7.1" do
gem "byebug"
gem "error_highlight", ">= 0.4.0"
gem "listen", "~> 3.2"
gem "puma", "~> 6.0"
gem "rails", "~> 7.1.0"
gem "spring", "!= 2.1.1"
gem "spring-watcher-listen", "~> 2.0.0"
gem "sqlite3", "~> 1.4"
end
15 changes: 15 additions & 0 deletions features/initializers.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Feature: properly integrate with Rails and other gems

Background:
When I create a new rails application
And I add "factory_bot_rails" from this project as a dependency
And I run `bundle install` with a clean environment

Scenario: handle already loaded ActiveRecord::Base by another gems earlier
When I run the following commands:
"""bash
cat config/application.rb
sed -i -e '/require "rails\/test_unit\/railtie"/a\'$'\n''require "active_record/base"' config/application.rb
"""
When I run `bundle exec rake test` with a clean environment
Then the output should contain "0 runs"
10 changes: 10 additions & 0 deletions features/support/rails_template
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,13 @@ if Rails.gem_version < Gem::Version.new('6')
end

gsub_file "Gemfile", /^ gem 'spring'$/, ' gem "spring", "!= 2.1.1"'

if Rails.gem_version >= Gem::Version.new('7.1')
append_to_file File.join("config", "application.rb"), <<~RUBY
class TestApp::Application
config.autoload_lib(ignore: %w(some_railtie))
end
RUBY

gsub_file "config/routes.rb", /^ get/, ' # get'
end
20 changes: 20 additions & 0 deletions gemfiles/rails7.1.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "appraisal"
gem "aruba"
gem "cucumber"
gem "error_highlight", ">= 0.4.0"
gem "rake"
gem "rspec-rails"
gem "standard"
gem "byebug"
gem "listen", "~> 3.2"
gem "puma", "~> 6.0"
gem "rails", "~> 7.1.0"
gem "spring", "!= 2.1.1"
gem "spring-watcher-listen", "~> 2.0.0"
gem "sqlite3", "~> 1.4"

gemspec name: "factory_bot_rails", path: "../"
12 changes: 7 additions & 5 deletions lib/factory_bot_rails/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ class Railtie < Rails::Railtie
FactoryBot.definition_file_paths = definition_file_paths
end

ActiveSupport.on_load :active_record do
config = Rails.configuration.factory_bot
initializer "factory_bot.reject_primary_key_attributes" do
ActiveSupport.on_load :active_record do
config = Rails.configuration.factory_bot

if config.reject_primary_key_attributes
require "factory_bot_rails/factory_validator/active_record_validator"
if config.reject_primary_key_attributes
require "factory_bot_rails/factory_validator/active_record_validator"

config.validator.add_validator FactoryValidator::ActiveRecordValidator.new
config.validator.add_validator FactoryValidator::ActiveRecordValidator.new
end
end
end

Expand Down
4 changes: 4 additions & 0 deletions spec/fake_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ module Dummy
class Application < Rails::Application
config.eager_load = false
config.root = "spec/fixtures"

if Rails.gem_version >= Gem::Version.new("7.1")
config.active_support.cache_format_version = 7
end
end
end

Expand Down
Loading