Sha256: 477cabf94deb03d4bc0b014fb398d5af9f827d1c576f702ecdfb53d1b52b2abf

Contents?: true

Size: 778 Bytes

Versions: 41

Compression:

Stored size: 778 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

41 entries across 37 versions & 1 rubygems

Version Path
representable-3.0.3 test/decorator_scope_test.rb
representable-3.0.2 test/decorator_scope_test.rb
representable-3.0.1 test/decorator_scope_test.rb
representable-3.0.0 test/decorator_scope_test.rb
representable-2.4.1 test-with-deprecations/decorator_scope_test.rb
representable-2.4.1 test/decorator_scope_test.rb
representable-2.4.0 test-with-deprecations/decorator_scope_test.rb
representable-2.4.0 test/decorator_scope_test.rb
representable-2.4.0.rc5 test-with-deprecations/decorator_scope_test.rb
representable-2.4.0.rc5 test/decorator_scope_test.rb
representable-2.4.0.rc4 test/decorator_scope_test.rb
representable-2.4.0.rc4 test-with-deprecations/decorator_scope_test.rb
representable-2.4.0.rc3 test/decorator_scope_test.rb
representable-2.4.0.rc2 test/decorator_scope_test.rb
representable-2.4.0.rc1 test/decorator_scope_test.rb
representable-2.3.0 test/decorator_scope_test.rb
representable-2.2.3 test/decorator_scope_test.rb
representable-2.2.2 test/decorator_scope_test.rb
representable-2.2.1 test/decorator_scope_test.rb
representable-2.2.0 test/decorator_scope_test.rb