Skip to content

Options hash passed to setter has incorrect value for collection properties #231

@conradchan

Description

@conradchan

Problem

options[:fragment] seems to correspond to the wrong property when referenced inside a setter block for a collection property.

Manufactured example:

class DemoRepresenter < Representable::Decorator
  include Representable::Hash

  property :foo
  collection :bars, setter: ->(options) do
    p "Input in setter for bars is value #{options[:input]}"
    p "Fragment in setter for bars is value #{options[:fragment]}"
  end
end

DemoRepresenter.new(OpenStruct.new).from_hash(
  {"foo"=>"fooValue", "bars"=>["barValue1", "barValue2"]}
).to_h

Actual:

The above code prints the following:

"Input in setter for bars is value [\"barValue1\", \"barValue2\"]"
"Fragment in setter for bars is value fooValue"

Expected:

The expected behavior would be for the fragment to correspond to ["barValue1", "barValue2"] since it's in the scope of the bars property.

Version:

3.0.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions