Sha256: 9adc0127605338d5d3bade3afb53252610888ddf9c0fe72a5905028e31dd5540

Contents?: true

Size: 1.22 KB

Versions: 1

Compression:

Stored size: 1.22 KB

Contents

require 'helper'

class AttributeMapping::LocalCacheTest < ActiveSupport::TestCase
  setup do
    AxleAttributes::Definition.reset_caches
  end

  test "cached_mapping_for" do
    assert_equal({}, AttributeMapping.cached_mapping_for('Foo').read)

    attribute_mapping = create :attribute_mapping, namespace: 'Foo', attribute_name: 'bar', value: 'omgz', label: 'Rofl'
    expected = {'omgz' => 'Rofl'}
    assert_equal expected, AttributeMapping.cached_mapping_for('Foo').read['bar']

    attribute_mapping.destroy
    assert_equal({}, AttributeMapping.cached_mapping_for('Foo').read)
  end

  test "alphanumeric ordering" do
    attribute_mapping = create :attribute_mapping, namespace: 'Foo', attribute_name: 'baz', value: 'b', label: '10'
    attribute_mapping = create :attribute_mapping, namespace: 'Foo', attribute_name: 'baz', value: 'c', label: '2'
    attribute_mapping = create :attribute_mapping, namespace: 'Foo', attribute_name: 'baz', value: 'a', label: 'a'

    expected = {"a" => "a", "b" => "10", "c" => "2"}.to_a
    assert_equal expected, AttributeMapping.cached_mapping_for('Foo').read['baz'].to_a
  end

  test "cache_name" do
    assert_equal 'attribute_mapping_Foo', AttributeMapping.cached_mapping_for('Foo').cache_name
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
axle_attributes-1.13.2 test/models/attribute_mapping/local_cache_test.rb