Sha256: 9fe89080abbc5be9d22951e63a551a8085488d5a337a9454590f61d55a2124be

Contents?: true

Size: 755 Bytes

Versions: 7

Compression:

Stored size: 755 Bytes

Contents

require 'test_helper'

class GetterSetterTest < BaseTest
  representer! do
    property :name, # key under :name.
      :getter => lambda { |args| "#{args[:welcome]} #{song_name}" },
      :setter => lambda { |val, args| self.song_name = "#{args[:welcome]} #{val}" }
  end

  subject { Struct.new(:song_name).new("Mony Mony").extend(representer) }

  it "uses :getter when rendering" do
    subject.instance_eval { def name; raise; end }
    subject.to_hash(:welcome => "Hi").must_equal({"name" => "Hi Mony Mony"})
  end

  it "uses :setter when parsing" do
    subject.instance_eval { def name=(*); raise; end; self }
    subject.from_hash({"name" => "Eyes Without A Face"}, :welcome => "Hello").song_name.must_equal "Hello Eyes Without A Face"
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
representable-2.4.1 test-with-deprecations/getter_setter_test.rb
representable-2.4.0 test-with-deprecations/getter_setter_test.rb
representable-2.4.0.rc5 test-with-deprecations/getter_setter_test.rb
representable-2.4.0.rc4 test-with-deprecations/getter_setter_test.rb
representable-2.4.0.rc3 test/getter_setter_test.rb
representable-2.4.0.rc2 test/getter_setter_test.rb
representable-2.4.0.rc1 test/getter_setter_test.rb