fixture_farm 1.1.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +18 -18
- data/bin/fixture_farm.rb +2 -2
- data/lib/fixture_farm/fixture_recorder.rb +3 -1
- data/lib/fixture_farm/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 92b468fd49d2062a518429bf20576066f827ff474c96bdf6fcab066ac5657824
|
4
|
+
data.tar.gz: '09980fce3fdb708ae0b9803a10b8c04970a9fa78dfe55cf737c2a30b6818c8a8'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2982e7c153b5747d463005253c256594b7dbbf4ca8f622a44612581b7d6571834f5b28ae50d6f85c32a188c9b62f26a77f6160816cba52d5a5ab53a08e007958
|
7
|
+
data.tar.gz: f3f4958dcf22e728df77ead1d874a43ba603c5cfb6222bc7500848d5b06d327faad20291dbc8832e7db484e03dbf42dd90129c7fd39f1ce75d5475c397a85007
|
data/README.md
CHANGED
@@ -93,14 +93,24 @@ Assuming there was a parent fixture `dave` that didn't have any children, this t
|
|
93
93
|
|
94
94
|
`record_fixtures` accepts optional name prefix, that applies to all new fixture names.
|
95
95
|
|
96
|
+
### Automatic fixture naming
|
97
|
+
|
98
|
+
Generated fixture names are based on the first `belongs_to` association of the model. E.g., if a new post fixtures belongs_to to a user fixture `bob`, the name is going to be `bob_post_1`.
|
99
|
+
|
100
|
+
It's possible to lower the priority of given parent assiciations when it comes to naming, so that certain names are only picked when there are no other suitable parent associations. This is useful, for example, to exclude `acts_as_tenant` association:
|
101
|
+
|
102
|
+
```ruby
|
103
|
+
FixtureFarm.low_priority_parent_model_for_naming = -> { _1.is_a?(TenantModel) }
|
104
|
+
```
|
105
|
+
|
96
106
|
#### Fixture Name Replacement
|
97
107
|
|
98
108
|
`record_fixtures` also supports hash arguments for advanced fixture naming control:
|
99
109
|
|
100
110
|
```ruby
|
101
|
-
# Replace 'client_1' with 'new_client' in fixture names, or use 'new_client' as prefix if not found
|
102
111
|
record_fixtures(new_client: :client_1) do
|
103
|
-
User.create!(name: 'Test User', email: 'test@example.com')
|
112
|
+
User.create!(name: 'Test User', email: 'test@example.com', client: clients(:client_1))
|
113
|
+
Star.create!
|
104
114
|
end
|
105
115
|
```
|
106
116
|
|
@@ -108,19 +118,9 @@ This works in two ways:
|
|
108
118
|
- **Replacement**: If a generated fixture name contains `client_1`, it gets replaced with `new_client`
|
109
119
|
- **Prefixing**: If a generated fixture name doesn't contain `client_1`, it gets prefixed with `new_client_`
|
110
120
|
|
111
|
-
|
112
|
-
-
|
113
|
-
-
|
114
|
-
|
115
|
-
### Automatic fixture naming
|
116
|
-
|
117
|
-
Generated fixture names are based on the first `belongs_to` association of the model. E.g., if a new post fixtures belongs_to to a user fixture `bob`, the name is going to be `bob_post_1`.
|
118
|
-
|
119
|
-
It's possible to lower the priority of given parent assiciations when it comes to naming, so that certain names are only picked when there are no other suitable parent associations. This is useful, for example, to exclude `acts_as_tenant` association:
|
120
|
-
|
121
|
-
```ruby
|
122
|
-
FixtureFarm.low_priority_parent_model_for_naming = -> { _1.is_a?(TenantModel) }
|
123
|
-
```
|
121
|
+
In the above example:
|
122
|
+
- The user fixture would be named `client_1_user_1`, but the actual name will be `new_client_user_1` (replacement)
|
123
|
+
- The star fixture would be named `star_1`, but will be named `new_client_star_1` (prefixing)
|
124
124
|
|
125
125
|
### Attachment fixtures
|
126
126
|
|
@@ -142,16 +142,16 @@ Now a test like the one below is either going to fail if some product fixtures h
|
|
142
142
|
```ruby
|
143
143
|
if ENV["GENERATE_FIXTURES"]
|
144
144
|
setup do
|
145
|
-
@original_queue_adapter =
|
145
|
+
@original_queue_adapter = ActiveJob::Base.queue_adapter
|
146
146
|
# This is so that variants get generated and blobs analyzed
|
147
|
-
|
147
|
+
ActiveJob::Base.queue_adapter = :inline
|
148
148
|
|
149
149
|
@original_storage_service = ActiveStorage::Blob.service
|
150
150
|
ActiveStorage::Blob.service = ActiveStorage::Blob.services.fetch(:test_fixtures)
|
151
151
|
end
|
152
152
|
|
153
153
|
teardown do
|
154
|
-
|
154
|
+
ActiveJob::Base.queue_adapter = @original_queue_adapter
|
155
155
|
ActiveStorage::Blob.service = @original_storage_service
|
156
156
|
end
|
157
157
|
end
|
data/bin/fixture_farm.rb
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
require_relative '../lib/fixture_farm/fixture_recorder'
|
5
5
|
|
6
6
|
def usage
|
7
|
-
puts 'Usage: bundle exec fixture_farm <record|status|stop> [name_prefix|
|
7
|
+
puts 'Usage: bundle exec fixture_farm <record|status|stop> [name_prefix|old_name:new_name]'
|
8
8
|
exit 1
|
9
9
|
end
|
10
10
|
|
@@ -12,7 +12,7 @@ case ARGV[0]
|
|
12
12
|
when 'record'
|
13
13
|
prefix_arg = ARGV[1]
|
14
14
|
|
15
|
-
# Parse hash syntax like "new_user
|
15
|
+
# Parse hash syntax like "user_1:new_user" into {user_1: :new_user}
|
16
16
|
if prefix_arg&.include?(':')
|
17
17
|
parts = prefix_arg.split(':', 2)
|
18
18
|
parsed_prefix = { parts[0].to_sym => parts[1].to_sym }
|
@@ -266,6 +266,8 @@ module FixtureFarm
|
|
266
266
|
value.to_f
|
267
267
|
when Hash
|
268
268
|
value.to_json
|
269
|
+
when IPAddr
|
270
|
+
value.to_s
|
269
271
|
else
|
270
272
|
value
|
271
273
|
end
|
@@ -380,7 +382,7 @@ module FixtureFarm
|
|
380
382
|
"#{model_instance.class.name.underscore.split('/').last}_1"
|
381
383
|
].select(&:present?).join('_')
|
382
384
|
|
383
|
-
@fixture_name_replacements.each do |
|
385
|
+
@fixture_name_replacements.each do |old_name, new_name|
|
384
386
|
# Only apply replacement if the base_name doesn't already start with new_name
|
385
387
|
# This prevents double-application of replacements
|
386
388
|
next if base_name.start_with?("#{new_name}_")
|
data/lib/fixture_farm/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fixture_farm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- artemave
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-09-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|