Skip to content

Commit 3f624b3

Browse files
authored
Merge pull request #205 from solidusio/kennyadsl/remove-support-old-factories
2 parents 5ec5b6a + 38d0f9d commit 3f624b3

File tree

7 files changed

+18
-85
lines changed

7 files changed

+18
-85
lines changed

.circleci/config.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ jobs:
3636
ruby_version: '2.7'
3737
steps: ['setup', 'solidusio_extensions/run-tests-solidus-older']
3838
lint-code:
39-
executor: solidusio_extensions/sqlite
39+
executor:
40+
name: solidusio_extensions/sqlite
41+
ruby_version: '3.0'
4042
steps: ['setup', 'solidusio_extensions/lint-code']
4143

4244
workflows:

.rubocop.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
inherit_from:
22
- https://relaxed.ruby.style/rubocop.yml
33

4+
Gemspec/RequiredRubyVersion:
5+
Enabled: false
46
Layout/EmptyLinesAroundAttributeAccessor:
57
Enabled: true
68
Layout/SpaceAroundMethodCallOperator:
@@ -42,7 +44,7 @@ Gemspec/DeprecatedAttributeAssignment:
4244
Enabled: false
4345

4446
AllCops:
45-
TargetRubyVersion: 2.5
47+
TargetRubyVersion: 3.0
4648
Exclude:
4749
- tmp/**/*
4850
- "vendor/**/*"
@@ -55,4 +57,3 @@ Style/FrozenStringLiteralComment:
5557
- "**/bin/*"
5658
- "**/exe/*"
5759
- "spec/**/*"
58-

lib/solidus_dev_support/rubocop.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
module SolidusDevSupport
44
module RuboCop
5-
CONFIG_PATH = "#{__dir__}/rubocop/config.yml"
5+
CONFIG_PATH = "#{__dir__}/rubocop/config.yml".freeze
66

77
def self.inject_defaults!
88
config = ::RuboCop::ConfigLoader.load_file(CONFIG_PATH)

lib/solidus_dev_support/templates/extension/README.md

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,7 @@ bundle exec rubocop
4242
```
4343

4444
When testing your application's integration with this extension you may use its factories.
45-
Simply add this require statement to your `spec/spec_helper.rb`:
46-
47-
```ruby
48-
require '<%= file_name %>/testing_support/factories'
49-
```
50-
51-
Or, if you are using `FactoryBot.definition_file_paths`, you can load Solidus core
52-
factories along with this extension's factories using this statement:
45+
You can load Solidus core factories along with this extension's factories using this statement:
5346

5447
```ruby
5548
SolidusDevSupport::TestingSupport::Factories.load_for(<%= class_name %>::Engine)

lib/solidus_dev_support/templates/extension/spec/spec_helper.rb.tt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ require 'solidus_dev_support/rspec/feature_helper'
1818
# in spec/support/ and its subdirectories.
1919
Dir["#{__dir__}/support/**/*.rb"].sort.each { |f| require f }
2020

21-
# Requires factories defined in lib/<%= file_name %>/testing_support/factories.rb
21+
# Requires factories defined in Solidus core and this extension.
22+
# See: lib/<%= file_name %>/testing_support/factories.rb
2223
SolidusDevSupport::TestingSupport::Factories.load_for(<%= class_name %>::Engine)
2324

2425
RSpec.configure do |config|

lib/solidus_dev_support/testing_support/factories.rb

Lines changed: 7 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,22 @@
11
# frozen_string_literal: true
22

33
require 'factory_bot'
4-
5-
Spree::Deprecation.silence do
6-
require 'spree/testing_support/factories'
7-
puts <<~MSG
8-
We are transitioning to a new way of loading factories for extensions.
9-
Be sure this extension does not load factories using require but uses
10-
the load_for() method in its spec_helper.rb, eg:
11-
12-
SolidusDevSupport::TestingSupport::Factories.load_for(ExtensionName1::Engine, ExtensionName2::Engine)
13-
14-
This will load Solidus Core factories right before the ones defined in
15-
lib/extension_name/testing_support/factories/*_factory.rb or
16-
lib/extension_name/testing_support/factories.rb
17-
18-
This message will be removed when all extensions are updated.
19-
MSG
20-
end
21-
22-
begin
23-
require 'spree/testing_support/factory_bot'
24-
rescue LoadError
25-
# Do nothing, we are testing the extension against an old version of Solidus
26-
end
4+
require 'spree/testing_support/factory_bot'
275

286
module SolidusDevSupport
297
module TestingSupport
308
module Factories
319
def self.load_for(*engines)
3210
paths = engines.flat_map do |engine|
33-
# Check if the extension has a lib/*/factories.rb. If it does, we emit a
34-
# deprecation warning and just use it.
35-
obsolete_factories_file = engine.root.glob('lib/*/factories.rb').first # 'lib/*/factories/*_factory.rb'
36-
if obsolete_factories_file.present?
37-
ActiveSupport::Deprecation.warn <<-WARN.squish, caller(4)
38-
SolidusDevSupport::TestingSupport::Factories.load_for() is automatically loading
39-
all factories present in #{obsolete_factories_file.dirname.to_s.gsub(engine.root.to_s, '')}/testing_support/factories/.
40-
Please move the content of #{obsolete_factories_file.to_s.gsub(engine.root.to_s, '')} to that directory.
41-
WARN
42-
43-
[obsolete_factories_file]
44-
else
45-
# If there are both a lib/*/testing_support/factories.rb and a lib/*/testing_support/factories/,
46-
# we assume that the factories.rb file is only used to load all factories prensent in the directory.
47-
# That file can be removed from the extension, in fact, we ignore it and emit a message asking to
48-
# remove it.
49-
factories_file_or_folder = engine.root.glob('lib/*/testing_support/factories{,.rb}')
50-
if factories_file_or_folder.size == 2
51-
folder, file = factories_file_or_folder.partition(&:directory?).map(&:first).map { |path| path.to_s.gsub(engine.root.to_s, '') }
52-
ActiveSupport::Deprecation.warn <<-WARN.squish, caller(4)
53-
SolidusDevSupport::TestingSupport::Factories.load_for() is automatically loading
54-
all factories present into #{folder}. You should now safely remove #{file} if it
55-
is only used to load ./factories content.
56-
WARN
57-
58-
engine.root.glob('lib/*/testing_support/factories/**/*_factory.rb')
59-
elsif factories_file_or_folder.first.directory?
60-
engine.root.glob('lib/*/testing_support/factories/**/*_factory.rb')
61-
else
62-
factories_file_or_folder
63-
end
64-
end
11+
engine.root.glob('lib/*/testing_support/factories{,.rb}')
6512
end.map { |path| path.sub(/.rb\z/, '').to_s }
6613

67-
if using_factory_bot_definition_file_paths?
68-
FactoryBot.definition_file_paths = [
69-
Spree::TestingSupport::FactoryBot.definition_file_paths,
70-
paths,
71-
].flatten
72-
73-
FactoryBot.reload
74-
else
75-
FactoryBot.find_definitions
76-
77-
paths.each { |path| require path }
78-
end
79-
end
14+
FactoryBot.definition_file_paths = [
15+
Spree::TestingSupport::FactoryBot.definition_file_paths,
16+
paths,
17+
].flatten
8018

81-
def self.using_factory_bot_definition_file_paths?
82-
defined?(Spree::TestingSupport::FactoryBot) &&
83-
Spree::TestingSupport::FactoryBot.respond_to?(:definition_file_paths)
19+
FactoryBot.reload
8420
end
8521
end
8622
end

spec/features/create_extension_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def sh(*args)
162162
if $DEBUG || ENV['DEBUG']
163163
warn '~' * 80
164164
warn "$ #{command}"
165-
warn output.to_s
165+
warn output
166166
warn "$ #{command} ~~~~> EXIT STATUS: #{status.exitstatus}"
167167
end
168168

0 commit comments

Comments
 (0)