fixes composed_of for delegated attributes and methods #3807

Closed
wants to merge 1 commit into
from

Projects

None yet

7 participants

@pnegri

composed_of wasnt working for delegated attributes and methods again.

this is my first contribution, can any1 check if its valid?

thanks

@lest

It will be good to have test for it

@josevalim
Ruby on Rails member

I am fine with this change but we do need to have a test for it, as @lest said.

@pnegri

did the tests, but (dont know why), the other tests are getting errors like "stack too deep", maybe i did forgot to do something prior to test preparation. but was not my fault, cant execute the aggregation tests on HEAD/rails too.

anyway, the tests for the delegate and methods are working.

@josevalim
Ruby on Rails member

Ah, the stack too deep makes total sense. As the overridden method will probably invoked the composed_of bit.

@pnegri
@pnegri

Any tip on how to improve those tests?

@roshats

I made commit and now old and new tests pass. Can I attach code to this pull request without creating new?

@pnegri

roshats. Submit a Pull request to my Branch and i will update this pull.
Regards
Patrick

@isaacsanders

Is this still an issue?

@pnegri

dont know maybe we need to remerge again and pull

@rafaelfranca
Ruby on Rails member

@pnegri @roshats any news about this one?

@edtsech edtsech added a commit to edtsech/rails that referenced this pull request May 26, 2012
@edtsech edtsech Fix stack level to deep issue in #3807. 0448f6c
@pnegri pnegri closed this May 26, 2012
@pnegri pnegri reopened this May 26, 2012
@rafaelfranca
Ruby on Rails member

@pnegri could you squash your commits?

@rafaelfranca
Ruby on Rails member
@pnegri

hey guys, any update on that?

@steveklabnik
Ruby on Rails member

If #6743 gets merged, this feature won't be useful.

@pnegri pnegri referenced this pull request Jun 16, 2012
Merged

Removing composed_of #6743

@steveklabnik steveklabnik added a commit that closed this pull request Jun 18, 2012
@steveklabnik steveklabnik Removing composed_of from ActiveRecord.
This feature adds a lot of complication to ActiveRecord for dubious
value. Let's talk about what it does currently:

class Customer < ActiveRecord::Base
  composed_of :balance, :class_name => "Money", :mapping => %w(balance amount)
end

Instead, you can do something like this:

    def balance
      @balance ||= Money.new(value, currency)
    end

    def balance=(balance)
      self[:value] = balance.value
      self[:currency] = balance.currency
      @balance = balance
    end

Since that's fairly easy code to write, and doesn't need anything
extra from the framework, if you use composed_of today, you'll
have to add accessors/mutators like that.

Closes #1436
Closes #2084
Closes #3807
14fc8b3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment