Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overriding attributes doesn't affect dependent attributes #67

Open
Morozzzko opened this issue Apr 27, 2021 · 1 comment
Open

Overriding attributes doesn't affect dependent attributes #67

Morozzzko opened this issue Apr 27, 2021 · 1 comment

Comments

@Morozzzko
Copy link

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
@Morozzzko Morozzzko changed the title Overriding attributes doesn't affect related attributes Overriding attributes doesn't affect dependent attributes Apr 27, 2021
@solnic
Copy link
Member

solnic commented Apr 28, 2021

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 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants