rom-factory
rom-factory copied to clipboard
Overriding attributes doesn't affect dependent attributes
Describe the bug
Whenever I have an attribute which depends on another one, overriding the dependency (i.e. with a trait) doesn't affect the calculated attribute.
Seems similar to #63, but a bit different
To Reproduce
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'rom'
gem 'rom-sql'
gem 'sqlite3'
gem 'rom-factory', '~> 0.10.2'
end
require 'rom'
require 'rom-factory'
ROM_CONTAINER = ROM.container(:sql, 'sqlite::memory') do |conf|
conf.default.create_table(:users) do
primary_key :id
column :name, String, null: false
column :email, String, null: false
end
class Users < ROM::Relation[:sql]
schema(infer: true)
end
conf.register_relation(Users)
end
Factory = ROM::Factory.configure do |config|
config.rom = ROM_CONTAINER
end
Factory.define(:user) do |f|
f.name 'John'
f.email { |name| name.downcase + '@example.com' }
f.trait :jane do |t|
t.name 'Jane'
end
end
pp Factory[:user, :jane] # #<ROM::Struct::User id=1 name="Jane" email="[email protected]">
Expected behavior
I expect calculated field to change its value depending on name
, even if I override name
in a trait.
My environment
- Affects my production application: YES (kind of? )
- Ruby version: 3.0.1
- OS: macOS Big Sur 11.2.2
Thanks for reporting this. I'll be revisiting this gem in general just before rom 6.0 / hanami 2.0 so hopefully I'll address all the known issues. In the meantime....help-wanted 🙂