Skip to content

Overriding attributes doesn't affect dependent attributes #67

@Morozzzko

Description

@Morozzzko

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="john@example.com">

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions