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