Sha256: 470d8606c80044061717f5a8c7e567796066b4fec91fc055b1ef1f773c45f957

Contents?: true

Size: 1.95 KB

Versions: 1

Compression:

Stored size: 1.95 KB

Contents

require 'helper'

class AxleAttributes::ParentDefinitionTest < ActiveSupport::TestCase
  class TestModel < Superstore::Base
    include AxleAttributes::Model

    class << self
      def reset!
        elastic_index.mapping[:properties].clear
        speshal_attributes.clear
        versioned_attributes.clear
      end

      def base_class
        TestModel
      end

      def attribute(name, options = {})
        speshal_attributes[name] = options
      end

      def speshal_attributes
        @@speshal_attributes ||= {}
      end
    end
  end

  setup do
    TestModel.reset!
  end

  test 'attribute with blank' do
    AxleAttributes::ParentDefinition.new(TestModel, :foo).setup!

    assert_equal({}, TestModel.speshal_attributes)
  end

  test 'attribute with default' do
    AxleAttributes::ParentDefinition.new(TestModel, :foo, type: :integer, default: 42).setup!

    assert_equal({'foo' => {type: :integer, default: 42}}, TestModel.speshal_attributes)
  end

  test 'attribute with type integer' do
    AxleAttributes::ParentDefinition.new(TestModel, :foo, type: :integer).setup!

    assert_equal({'foo' => {type: :integer}}, TestModel.speshal_attributes)
  end

  test 'attribute with type text' do
    AxleAttributes::ParentDefinition.new(TestModel, :foo, type: :text).setup!

    assert_equal({'foo' => {type: :string}}, TestModel.speshal_attributes)
  end

  test 'setup index' do
    definition = AxleAttributes::ParentDefinition.new(TestModel, :foo, type: :string, index: :snowball)

    definition.setup!

    assert_equal definition.index_mapping, TestModel.elastic_index.mapping[:properties]['foo']
  end

  test 'version with false' do
    AxleAttributes::ParentDefinition.new(TestModel, :foo, version: false).setup!

    assert_equal [].to_set, TestModel.versioned_attributes
  end

  test 'version with true' do
    AxleAttributes::ParentDefinition.new(TestModel, :foo, version: true).setup!

    assert_equal ['foo'].to_set, TestModel.versioned_attributes
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
axle_attributes-1.13.2 test/lib/parent_definition_test.rb