File: option_test.rb

package info (click to toggle)
ruby-representable 3.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 952 kB
  • sloc: ruby: 6,495; makefile: 4
file content (36 lines) | stat: -rw-r--r-- 883 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# frozen_string_literal: true

require 'test_helper'

class OptionTest < Minitest::Spec
  class Callable
    include Uber::Callable
    def call(*); "callable" end
  end

  class MyRepresenter < Representable::Decorator
    include Representable::JSON

    property :static,   getter: "static"
    property :symbol,   getter: :symbol
    property :proc,     getter: ->(*) { "proc" }
    property :callable, getter: Callable.new
  end

  Album = Struct.new(:static) do
    def symbol(*); "symbol" end
  end

  let(:album_representer) { MyRepresenter.new(Album.new) }

  describe ::Representable::Option do
    it "supports all types of callables (method, proc, static etc)" do
      _(album_representer.to_hash).must_equal({
        "static"    => "static",
        "symbol"    => "symbol",
        "proc"      => "proc",
        "callable"  => "callable",
      })
    end
  end
end