Sha256: 45555f220f13cdc7c85510b2d4942242756ccd917a78f951162c71aefaa39bfa

Contents?: true

Size: 1.36 KB

Versions: 1

Compression:

Stored size: 1.36 KB

Contents

require 'helper'

class AxleAttributes::HasAttributes::JsonReaderTest < ActiveSupport::TestCase
  class Pet < Superstore::Base
    include AxleAttributes::SerializedChild
  end

  class TestModel < Superstore::Base
    include AxleAttributes::Model

    class << self
      def name
        'TestModel'
      end
    end

    json = {
      'location' => {
        'street'    => {'type' => 'string', 'format' => 'phone'}
      },
      'pets' => {
        'class_name'  => 'AxleAttributes::HasAttributes::JsonReaderTest::Pet',
        'type'        => 'serialize_many',
        'attributes'  => {
          'name'        => {'type' => 'string'},
          'disposition' => {'type' => 'string'}
        }
      }
    }

    AxleAttributes::HasAttributes::JsonReader.read_definitions(TestModel, json, defaults: {index: true, version: false})
  end

  test 'simple definition' do
    refute_nil TestModel.attributes['street']
    assert_equal :string, TestModel.attributes['street'].options[:type]
    assert_equal :phone, TestModel.attributes['street'].options[:format]
    assert_equal true, TestModel.attributes['street'].options[:index]
    assert_equal false, TestModel.attributes['street'].options[:version]
  end

  test 'serialization definition' do
    refute_nil TestModel.serialization_reflections[:pets]
    assert_equal :string, Pet.attributes['disposition'].options[:type]
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
axle_attributes-1.13.2 test/lib/has_attributes/json_reader_test.rb