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