vial 0.2026.1.15.0 → 0.2026.8.6.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: 680dac32bdbceb116ecfec2b9619833bb45f18caed07aa499b1fc47e2a80c02e
4
- data.tar.gz: b08b502390918d7ee4f91abb33573c2528fa2b6b1d65b9b70896c077b5269420
3
+ metadata.gz: a7c47154ae0355e8591c6a673f3d3be7ec35157f5c283fe0e19a5d7e16de8264
4
+ data.tar.gz: f91144b61b12600d6c5d5b8d59eba6e8a83c28a99e212e702bc4a253f6d6b76b
5
5
  SHA512:
6
- metadata.gz: '08d206381eafcff51a9b7b678388c2200d270999d8002f18769b18cd226abd7cc3dca77d49024ebb0f63637bbc46668fecf38fe4fbca7cb8c0e66a0f4b1b8212'
7
- data.tar.gz: 4f06a9a9ff59325f4506b5485d587f69cc2b2ec12f53543abda96e3bca414c03ebde7e7d80dd0070660f057a8083378dd9a0c7cd9d1a51002c9638d4685e972c
6
+ metadata.gz: 41a2fe162d2082ccfcc1a972f9d1bd45ddb8359a9ba4b171d2a5549709f286bfadc0b4d67150cfcc836be62921d3ff3fb40f4b13574c3b5557fc266adaea4a6c
7
+ data.tar.gz: 75e803f3ac0a2d8c94a598960b320a20e85d33c034837d14d43cb3a6a141b997585d541b8a0cffb3edf78a27a71da6444052e103922d8711126224192b813449
data/README.md CHANGED
@@ -67,7 +67,10 @@ Example `test/vials/users.vial.rb`:
67
67
 
68
68
  ```ruby
69
69
  vial :users do
70
+ sequence(:email) { |i| "user#{i}@test.local" }
71
+
70
72
  base do
73
+ email sequence(:email)
71
74
  active true
72
75
  country "MA"
73
76
  end
@@ -81,8 +84,6 @@ vial :users do
81
84
  active false
82
85
  end
83
86
 
84
- sequence(:email) { |i| "user#{i}@test.local" }
85
-
86
87
  generate 10, :admin
87
88
  generate 50, :guest
88
89
  end
@@ -90,10 +91,18 @@ end
90
91
 
91
92
  Output: `test/fixtures/users.yml` with deterministic IDs and explicit records.
92
93
 
94
+ Note: `sequence(:name) { ... }` only defines a sequence. It applies to records
95
+ when an attribute references it — `email sequence(:email)` inside `base` or a
96
+ variant. The compiler warns about sequences that are defined but never referenced.
97
+
93
98
  ### Global Validation
94
99
 
95
100
  `vial:compile` validates the entire dataset before writing any fixtures. Any collision or duplicate label fails the compile with a precise error.
96
101
 
102
+ IDs are namespaced per `record_type` (one namespace per table): fixtures for
103
+ different tables may share numeric IDs, and collisions are only errors within
104
+ the same record type.
105
+
97
106
  ### Composition
98
107
 
99
108
  ```ruby
@@ -149,6 +158,10 @@ vial :users do
149
158
  end
150
159
  ```
151
160
 
161
+ Explicit and derived IDs share one namespace per `record_type`, so two vials
162
+ targeting the same table cannot collide, while vials for different tables can
163
+ reuse the same numbers freely.
164
+
152
165
  Explain a derived ID:
153
166
 
154
167
  ```bash
data/lib/vial/compiler.rb CHANGED
@@ -29,6 +29,8 @@ module Vial
29
29
  return CompileResult.new(status: :no_definitions, files: [], output_path: @output_path.to_s)
30
30
  end
31
31
 
32
+ warn_about_unused_sequences(definitions)
33
+
32
34
  records_by_definition = definitions.each_with_object([]) do |definition, entries|
33
35
  next if definition.abstract?
34
36
  entries << { definition: definition, records: definition.build_records }
@@ -91,6 +93,15 @@ module Vial
91
93
 
92
94
  private
93
95
 
96
+ def warn_about_unused_sequences(definitions)
97
+ definitions.each do |definition|
98
+ definition.unused_sequence_names.each do |name|
99
+ warn "Vial: sequence :#{name} in vial :#{definition.name} is defined but never referenced " \
100
+ "(use `#{name} sequence(:#{name})` inside base or a variant)"
101
+ end
102
+ end
103
+ end
104
+
94
105
  def write_fixture(definition, records)
95
106
  file_path = File.join(@output_path.to_s, "#{definition.name}.yml")
96
107
  FileUtils.mkdir_p(File.dirname(file_path))
data/lib/vial/config.rb CHANGED
@@ -20,14 +20,22 @@ module Vial
20
20
  private
21
21
 
22
22
  def default_source_paths
23
- [Rails.root.join('test/vials')]
23
+ [app_root.join('test/vials')]
24
24
  end
25
25
 
26
26
  def default_output_path
27
27
  fixture_paths = Array(ActiveSupport::TestCase.fixture_paths).compact
28
28
  return fixture_paths.first if fixture_paths.any?
29
29
 
30
- Rails.root.join('test/fixtures')
30
+ app_root.join('test/fixtures')
31
+ end
32
+
33
+ # Rails is optional for the core compiler; fall back to the working
34
+ # directory in plain Ruby projects.
35
+ def app_root
36
+ return Rails.root if defined?(Rails) && Rails.respond_to?(:root) && Rails.root
37
+
38
+ Pathname.new(Dir.pwd)
31
39
  end
32
40
  end
33
41
  end
@@ -140,8 +140,25 @@ module Vial
140
140
  @sequence_defs
141
141
  end
142
142
 
143
+ # Sequences defined with a block but never consumed via
144
+ # `attr sequence(:name)` in base or a variant. Defining one without
145
+ # referencing it is a silent no-op, so the compiler warns about these.
146
+ def unused_sequence_names
147
+ return [] if abstract?
148
+
149
+ referenced = sequence_refs_in(resolved_base_attributes)
150
+ @variant_attributes.each_value do |attrs|
151
+ referenced |= sequence_refs_in(attrs)
152
+ end
153
+ @sequence_defs.keys - referenced
154
+ end
155
+
143
156
  private
144
157
 
158
+ def sequence_refs_in(attributes)
159
+ attributes.values.filter_map { |value| value.name if value.is_a?(SequenceRef) }
160
+ end
161
+
145
162
  def parse_generation_args(*args, **kwargs)
146
163
  if args.length == 0
147
164
  raise ArgumentError, 'generate requires a count or variant'
@@ -67,17 +67,21 @@ module Vial
67
67
  end
68
68
 
69
69
  def assign_and_validate_ids!
70
+ # IDs are namespaced per record_type: fixtures for different tables can
71
+ # share numeric IDs, collisions only matter within one record type.
70
72
  used_ids = {}
71
73
  all_records.each do |record|
72
74
  explicit = explicit_id_for(record)
73
75
  next unless explicit
74
76
 
75
77
  id_value = explicit[:value]
76
- if (existing = used_ids[id_value])
78
+ id_key = id_key_for(record, id_value)
79
+ if (existing = used_ids[id_key])
77
80
  raise ValidationError.new(
78
81
  'ExplicitIDCollision',
79
82
  [
80
83
  "ID: #{id_value.inspect}",
84
+ "record_type: #{record.definition.record_type}",
81
85
  record_descriptor(existing[:record], existing[:source_file], existing[:source_line]),
82
86
  record_descriptor(record, explicit[:source_file], explicit[:source_line])
83
87
  ]
@@ -85,7 +89,7 @@ module Vial
85
89
  end
86
90
 
87
91
  record.attributes[record.definition.primary_key] = id_value
88
- used_ids[id_value] = { explicit: true, record: record, source_file: explicit[:source_file], source_line: explicit[:source_line] }
92
+ used_ids[id_key] = { explicit: true, record: record, source_file: explicit[:source_file], source_line: explicit[:source_line] }
89
93
  end
90
94
 
91
95
  derived_records = all_records.reject { |record| record.attributes.key?(record.definition.primary_key) }
@@ -106,10 +110,11 @@ module Vial
106
110
  salt: attempts
107
111
  )
108
112
 
109
- existing = used_ids[id_value]
113
+ id_key = id_key_for(record, id_value)
114
+ existing = used_ids[id_key]
110
115
  if existing.nil?
111
116
  record.attributes[record.definition.primary_key] = id_value
112
- used_ids[id_value] = { explicit: false, record: record }
117
+ used_ids[id_key] = { explicit: false, record: record }
113
118
  return
114
119
  end
115
120
 
@@ -141,6 +146,10 @@ module Vial
141
146
  )
142
147
  end
143
148
 
149
+ def id_key_for(record, id_value)
150
+ [record.definition.record_type, id_value]
151
+ end
152
+
144
153
  def explicit_id_for(record)
145
154
  primary_key = record.definition.primary_key
146
155
  return nil unless record.attributes.key?(primary_key)
data/lib/vial/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Vial
4
- VERSION = "0.2026.1.15.0"
4
+ VERSION = "0.2026.8.6.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vial
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2026.1.15.0
4
+ version: 0.2026.8.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Abdelkader Boudih
@@ -104,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
104
  - !ruby/object:Gem::Version
105
105
  version: '0'
106
106
  requirements: []
107
- rubygems_version: 4.0.3
107
+ rubygems_version: 4.0.10
108
108
  specification_version: 4
109
109
  summary: 'Vial: Fixtures, Reinvented'
110
110
  test_files: []