Sha256: 2c9b1f5cd8d2f5789c7dd37d83a345bb76d3025e7cde8c9cbeff9fa4855da4b6

Contents?: true

Size: 1.04 KB

Versions: 14

Compression:

Stored size: 1.04 KB

Contents

require 'test_helper'

class FeaturesTest < MiniTest::Spec
  module Title
    def title; "Is It A Lie"; end
  end
  module Length
    def length; "2:31"; end
  end

  definition = lambda {
    feature Title
    feature Length

    # exec_context: :decorator, so the readers are called on the Decorator instance (which gets readers from features!).
    property :title, exec_context: :decorator
    property :length, exec_context: :decorator
    property :details do
      property :title, exec_context: :decorator
    end
  }

  let (:song) { OpenStruct.new(:details => Object.new) }

  describe "Module" do
    representer! do
      instance_exec &definition
    end

    it { song.extend(representer).to_hash.must_equal({"title"=>"Is It A Lie", "length"=>"2:31", "details"=>{"title"=>"Is It A Lie"}}) }
  end


  describe "Decorator" do
    representer!(:decorator => true) do
      instance_exec &definition
    end

    it { representer.new(song).to_hash.must_equal({"title"=>"Is It A Lie", "length"=>"2:31", "details"=>{"title"=>"Is It A Lie"}}) }
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
representable-2.1.7 test/features_test.rb
representable-2.1.6 test/features_test.rb
representable-2.1.5 test/features_test.rb
representable-2.1.4 test/features_test.rb
representable-2.1.3 test/features_test.rb
representable-2.1.1 test/features_test.rb
representable-2.1.0 test/features_test.rb
representable-2.0.4 test/features_test.rb
representable-2.0.3 test/features_test.rb
representable-2.0.2 test/features_test.rb
representable-2.0.1 test/features_test.rb
representable-2.0.0 test/features_test.rb
representable-2.0.0.rc2 test/features_test.rb
representable-2.0.0.rc1 test/features_test.rb