fixture_farm 0.2.3 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2c38b9ab62c74bb939508d55c18a39a6ba64a879531a8c2784ed5ad7b67f5945
4
- data.tar.gz: 2a0984353f13d7601f7aa51bb00bcdb7260a773ff5e96aa944d6f5627182ad50
3
+ metadata.gz: bc500dbe7c8e382796e3882a382384a82c9dcde5dcbad901f8bcffdc785f211c
4
+ data.tar.gz: c67a9e29f7fe8bd8f1b7e526489b188258230a4b784d0ed4603c09e72d59d2ff
5
5
  SHA512:
6
- metadata.gz: e6bf3e7eddd7aa146c9eb536888f085ec77e63f976f09eae9cf353ded3f6345cc44471d74e00f425398efd16cee2147e99e9799c0e176dd0562474df2288eef3
7
- data.tar.gz: 8db0f16307c09a07c669980cfa3156d765945ba201a658deb3744c8dc5163555129658e1ed83b6ef2f76fff616fef0432649ad19ca87fb794988a6699161b338
6
+ metadata.gz: ba1426b1998c8b40872a3a8bf0a8f994f9727a9ac7bdf1619f1fc6310c241ffba1b07e05b7325fc81099b46107936264402b390dba3f9cb885235777cc633b67
7
+ data.tar.gz: 30c3b9fffafe22018481d677d1669c102271ccfda188750d9c0f6ccc88cca3696cf02ad2a1568ff48f791d152698f006b6ba01ffa4d9db825753c5ef001b1d11
data/README.md CHANGED
@@ -11,6 +11,7 @@ Generated fixture that `belongs_to` a record from an existing fixture, will refe
11
11
 
12
12
  - doesn't update fixtures
13
13
  - doesn't delete fixtures
14
+ - assumes that all serialized attributes are json (so that at least ActiveStorage::Blob metadata is correctly represented; it really should be Rails serializing attributes according to their respective coders when inserting fixtures into the database, but, alas, this isn't happening)
14
15
 
15
16
  ## Installation
16
17
 
@@ -126,5 +127,15 @@ end
126
127
 
127
128
  Running this test with `RECORD_FIXTURES=1` will generate missing fixture entries in `test/fixtures/posts.yml`. Now re-run the test again and it's passing.
128
129
 
130
+ ### Automatic fixture naming
131
+
132
+ 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`.
133
+
134
+ 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:
135
+
136
+ ```ruby
137
+ FixtureFarm.low_priority_parent_model_for_naming = -> { _1.is_a?(TenantModel) }
138
+ ```
139
+
129
140
  ## License
130
141
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FixtureFarm
4
- mattr_accessor :parent_models_to_ignore_when_naming_fixtures, default: []
4
+ mattr_accessor :low_priority_parent_model_for_naming, default: -> { false }
5
5
 
6
6
  class FixtureRecorder
7
7
  STORE_PATH = Rails.root.join('tmp', 'fixture_farm_store.json')
@@ -117,19 +117,23 @@ module FixtureFarm
117
117
  end
118
118
 
119
119
  def first_belongs_to_fixture_name(model_instance)
120
+ low_priority_name = nil
121
+
120
122
  model_instance.class.reflect_on_all_associations.filter(&:belongs_to?).each do |association|
121
123
  associated_model_instance = find_associated_model_instance(model_instance, association)
122
124
 
123
125
  next unless associated_model_instance
124
126
 
125
- next if FixtureFarm.parent_models_to_ignore_when_naming_fixtures.any? { _1.call(associated_model_instance) }
126
-
127
127
  if (associated_model_instance_fixture_name = fixture_name(associated_model_instance))
128
- return associated_model_instance_fixture_name
128
+ if FixtureFarm.low_priority_parent_model_for_naming.call(associated_model_instance)
129
+ low_priority_name = associated_model_instance_fixture_name
130
+ else
131
+ return associated_model_instance_fixture_name
132
+ end
129
133
  end
130
134
  end
131
135
 
132
- nil
136
+ low_priority_name
133
137
  end
134
138
 
135
139
  def update_fixture_files(named_new_fixtures)
@@ -201,6 +205,8 @@ module FixtureFarm
201
205
  value.iso8601
202
206
  when BigDecimal
203
207
  value.to_f
208
+ when Hash
209
+ value.to_json
204
210
  else
205
211
  value
206
212
  end
@@ -1,3 +1,3 @@
1
1
  module FixtureFarm
2
- VERSION = '0.2.3'
2
+ VERSION = '0.3.0'
3
3
  end
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: 0.2.3
4
+ version: 0.3.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-03-24 00:00:00.000000000 Z
11
+ date: 2025-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails