fixture_farm 0.2.4 → 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: 43aa39081579e57d7b594eac34c61e810e8729c607348510b96a40f4743edd38
4
- data.tar.gz: 99ec6eeaac71cb939d6b730add5b4ccbe1cc886df2b6ab1922d10efa65a2de7c
3
+ metadata.gz: bc500dbe7c8e382796e3882a382384a82c9dcde5dcbad901f8bcffdc785f211c
4
+ data.tar.gz: c67a9e29f7fe8bd8f1b7e526489b188258230a4b784d0ed4603c09e72d59d2ff
5
5
  SHA512:
6
- metadata.gz: 87815f5d50ff8ac43d89e48c04053b7559a9cfd0840179c95c28101a117fcba8fc4dba81ac674eaf4103126982a4b70b3e60abc913dbc7de7824acd6bd8b4cb6
7
- data.tar.gz: 3de064aa07aa85980be1bd28a51b8e4dc43366722515c783b8f6f69613ab67cc1cd00c6fc81040d2bdb6c20af64969b557b1848de35b9d4142d80515097e717e
6
+ metadata.gz: ba1426b1998c8b40872a3a8bf0a8f994f9727a9ac7bdf1619f1fc6310c241ffba1b07e05b7325fc81099b46107936264402b390dba3f9cb885235777cc633b67
7
+ data.tar.gz: 30c3b9fffafe22018481d677d1669c102271ccfda188750d9c0f6ccc88cca3696cf02ad2a1568ff48f791d152698f006b6ba01ffa4d9db825753c5ef001b1d11
data/README.md CHANGED
@@ -127,5 +127,15 @@ end
127
127
 
128
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.
129
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
+
130
140
  ## License
131
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)
@@ -1,3 +1,3 @@
1
1
  module FixtureFarm
2
- VERSION = '0.2.4'
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.4
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-25 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