Sha256: 62ad837605dc5e2d7b3a2a2e26aff8d4c57b1b9c908edaa9d7be8177252e5a87

Contents?: true

Size: 783 Bytes

Versions: 5

Compression:

Stored size: 783 Bytes

Contents

require 'test_helper'

# TODO: remove in 2.0.
class DecoratorScopeTest < MiniTest::Spec
  representer! do
    property :title, :getter => lambda { |*| title_from_representer }, :decorator_scope => true
  end

  let(:representer_with_method) {
    Module.new do
      include Representable::Hash
      property :title, :decorator_scope => true
      def title; "Crystal Planet"; end
    end
   }

  it "executes lambdas in represented context" do
    _(Class.new do
      def title_from_representer
        "Sounds Of Silence"
      end
    end.new.extend(representer).to_hash).must_equal({"title"=>"Sounds Of Silence"})
  end

  it "executes method in represented context" do
    _(Object.new.extend(representer_with_method).to_hash).must_equal({"title"=>"Crystal Planet"})
  end
end

Version data entries

5 entries across 5 versions & 3 rubygems

Version Path
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/representable-3.2.0/test/decorator_scope_test.rb
fluent-plugin-google-cloud-logging-on-prem-0.1.0 vendor/ruby/3.1.0/gems/representable-3.2.0/test/decorator_scope_test.rb
representable-3.2.0 test/decorator_scope_test.rb
representable-3.1.1 test/decorator_scope_test.rb
representable-3.1.0 test/decorator_scope_test.rb