Sha256: b80b36c0599d81f34902c83c3537b91d453876a52e35803a934f3f306fc7e40f

Contents?: true

Size: 820 Bytes

Versions: 32

Compression:

Stored size: 820 Bytes

Contents

require_relative 'helper'

class User < DTO.new(:first_name, :last_name)
end

class DTOTest < MiniTest::Unit::TestCase
  def setup
    @user = User.new(first_name: 'John', last_name: 'Doe', another: 'Yeah!')
  end

  def test_accessors
    assert_equal 'John', @user.first_name
    assert_equal 'Doe', @user.last_name
    refute @user.respond_to? :another
  end

  def test_to_json
    assert_equal({ first_name: 'John', last_name: 'Doe' }.to_json, @user.to_json)
    another = Class.new(DTO.new :first_name, :childs )
    with_childs = another.new(first_name: 'Jess', childs: [ 'Albert', 'Margo' ])
    assert_equal({ first_name: 'Jess', childs: ['Albert', 'Margo']}.to_json, with_childs.to_json)
  end

  def test_to_s
    expected = "first_name: John, last_name: Doe" 
    assert_equal expected, @user.to_s
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
mxhero-api-0.1.55 test/test_dto.rb
mxhero-api-0.1.54 test/test_dto.rb
mxhero-api-0.1.53 test/test_dto.rb
mxhero-api-0.1.52 test/test_dto.rb
mxhero-api-0.1.41 test/test_dto.rb
mxhero-api-0.1.40 test/test_dto.rb
mxhero-api-0.1.39 test/test_dto.rb
mxhero-api-0.1.38 test/test_dto.rb
mxhero-api-0.1.37 test/test_dto.rb
mxhero-api-0.1.36 test/test_dto.rb
mxhero-api-0.1.35 test/test_dto.rb
mxhero-api-0.1.34 test/test_dto.rb
mxhero-api-0.1.33 test/test_dto.rb
mxhero-api-0.1.32 test/test_dto.rb
mxhero-api-0.1.31 test/test_dto.rb
mxhero-api-0.1.30 test/test_dto.rb
mxhero-api-0.1.29 test/test_dto.rb
mxhero-api-0.1.28 test/test_dto.rb
mxhero-api-0.1.27 test/test_dto.rb
mxhero-api-0.1.26 test/test_dto.rb