axle_attributes 1.13.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/.travis.yml +16 -0
- data/Gemfile +15 -0
- data/README.md +10 -0
- data/Rakefile +18 -0
- data/app/models/attribute_customization.rb +7 -0
- data/app/models/attribute_customization/local_cache.rb +28 -0
- data/app/models/attribute_mapping.rb +15 -0
- data/app/models/attribute_mapping/local_cache.rb +40 -0
- data/axle_attributes.gemspec +22 -0
- data/bin/rails +8 -0
- data/db/migrate/20131118042651_create_attribute_customizations.rb +16 -0
- data/db/migrate/20131121013237_create_attribute_mappings.rb +17 -0
- data/db/migrate/20151120160522_add_editable_to_attribute_customizations.rb +7 -0
- data/lib/axle_attributes.rb +30 -0
- data/lib/axle_attributes/child_definition.rb +42 -0
- data/lib/axle_attributes/conversions.rb +36 -0
- data/lib/axle_attributes/definition.rb +118 -0
- data/lib/axle_attributes/definition/callbacks.rb +34 -0
- data/lib/axle_attributes/definition/customization.rb +51 -0
- data/lib/axle_attributes/definition/formatted.rb +57 -0
- data/lib/axle_attributes/definition/indexed.rb +41 -0
- data/lib/axle_attributes/definition/mappings.rb +48 -0
- data/lib/axle_attributes/dumper.rb +54 -0
- data/lib/axle_attributes/engine.rb +4 -0
- data/lib/axle_attributes/format.rb +74 -0
- data/lib/axle_attributes/has_attributes.rb +104 -0
- data/lib/axle_attributes/has_attributes/json_reader.rb +87 -0
- data/lib/axle_attributes/model.rb +34 -0
- data/lib/axle_attributes/null_definition.rb +11 -0
- data/lib/axle_attributes/parent_definition.rb +37 -0
- data/lib/axle_attributes/provided.rb +67 -0
- data/lib/axle_attributes/regex.rb +4 -0
- data/lib/axle_attributes/segmented.rb +30 -0
- data/lib/axle_attributes/serializations.rb +147 -0
- data/lib/axle_attributes/serializations/builder/serialization.rb +83 -0
- data/lib/axle_attributes/serializations/builder/serialize_many.rb +17 -0
- data/lib/axle_attributes/serializations/builder/serialize_one.rb +7 -0
- data/lib/axle_attributes/serializations/reflection.rb +40 -0
- data/lib/axle_attributes/serializations/serialization.rb +88 -0
- data/lib/axle_attributes/serializations/serialize_many.rb +88 -0
- data/lib/axle_attributes/serializations/serialize_one.rb +34 -0
- data/lib/axle_attributes/serialized_child.rb +58 -0
- data/lib/axle_attributes/validations.rb +29 -0
- data/lib/axle_attributes/versioned.rb +21 -0
- data/test/dummy/README.rdoc +6 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/images/.keep +0 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/controllers/concerns/.keep +0 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/mailers/.keep +0 -0
- data/test/dummy/app/models/.keep +0 -0
- data/test/dummy/app/models/concerns/.keep +0 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +12 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +13 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +29 -0
- data/test/dummy/config/environments/production.rb +80 -0
- data/test/dummy/config/environments/test.rb +38 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +12 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +56 -0
- data/test/dummy/db/schema.rb +50 -0
- data/test/dummy/lib/assets/.keep +0 -0
- data/test/dummy/log/.keep +0 -0
- data/test/dummy/public/404.html +58 -0
- data/test/dummy/public/422.html +58 -0
- data/test/dummy/public/500.html +57 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/factories/all.rb +14 -0
- data/test/helper.rb +25 -0
- data/test/lib/child_definition_test.rb +43 -0
- data/test/lib/conversions_test.rb +39 -0
- data/test/lib/definition/customization_test.rb +36 -0
- data/test/lib/definition/formatted_test.rb +75 -0
- data/test/lib/definition/indexed_test.rb +57 -0
- data/test/lib/definition/mappings_test.rb +26 -0
- data/test/lib/definition_test.rb +84 -0
- data/test/lib/dumper_test.rb +38 -0
- data/test/lib/format_test.rb +64 -0
- data/test/lib/has_attributes/json_reader_test.rb +46 -0
- data/test/lib/has_attributes_test.rb +69 -0
- data/test/lib/model_test.rb +44 -0
- data/test/lib/null_definition_test.rb +27 -0
- data/test/lib/parent_definition_test.rb +75 -0
- data/test/lib/provided_test.rb +46 -0
- data/test/lib/segmented_test.rb +27 -0
- data/test/lib/serializations/reflection_test.rb +24 -0
- data/test/lib/serializations/serialize_many_test.rb +194 -0
- data/test/lib/serializations/serialize_one_test.rb +122 -0
- data/test/lib/serializations_test.rb +24 -0
- data/test/lib/serialized_child_test.rb +91 -0
- data/test/lib/timestamp_attributes_test.rb +14 -0
- data/test/lib/validations_test.rb +8 -0
- data/test/lib/versioned_test.rb +35 -0
- data/test/models/attribute_customization/local_cache_test.rb +16 -0
- data/test/models/attribute_customization_test.rb +8 -0
- data/test/models/attribute_mapping/local_cache_test.rb +31 -0
- data/test/models/attribute_mapping_test.rb +20 -0
- data/test/support/business.rb +22 -0
- data/test/support/pg.rb +9 -0
- data/test/support/vegetable.rb +8 -0
- metadata +215 -0
File without changes
|
File without changes
|
@@ -0,0 +1,58 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The page you were looking for doesn't exist (404)</title>
|
5
|
+
<style>
|
6
|
+
body {
|
7
|
+
background-color: #EFEFEF;
|
8
|
+
color: #2E2F30;
|
9
|
+
text-align: center;
|
10
|
+
font-family: arial, sans-serif;
|
11
|
+
}
|
12
|
+
|
13
|
+
div.dialog {
|
14
|
+
width: 25em;
|
15
|
+
margin: 4em auto 0 auto;
|
16
|
+
border: 1px solid #CCC;
|
17
|
+
border-right-color: #999;
|
18
|
+
border-left-color: #999;
|
19
|
+
border-bottom-color: #BBB;
|
20
|
+
border-top: #B00100 solid 4px;
|
21
|
+
border-top-left-radius: 9px;
|
22
|
+
border-top-right-radius: 9px;
|
23
|
+
background-color: white;
|
24
|
+
padding: 7px 4em 0 4em;
|
25
|
+
}
|
26
|
+
|
27
|
+
h1 {
|
28
|
+
font-size: 100%;
|
29
|
+
color: #730E15;
|
30
|
+
line-height: 1.5em;
|
31
|
+
}
|
32
|
+
|
33
|
+
body > p {
|
34
|
+
width: 33em;
|
35
|
+
margin: 0 auto 1em;
|
36
|
+
padding: 1em 0;
|
37
|
+
background-color: #F7F7F7;
|
38
|
+
border: 1px solid #CCC;
|
39
|
+
border-right-color: #999;
|
40
|
+
border-bottom-color: #999;
|
41
|
+
border-bottom-left-radius: 4px;
|
42
|
+
border-bottom-right-radius: 4px;
|
43
|
+
border-top-color: #DADADA;
|
44
|
+
color: #666;
|
45
|
+
box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
|
46
|
+
}
|
47
|
+
</style>
|
48
|
+
</head>
|
49
|
+
|
50
|
+
<body>
|
51
|
+
<!-- This file lives in public/404.html -->
|
52
|
+
<div class="dialog">
|
53
|
+
<h1>The page you were looking for doesn't exist.</h1>
|
54
|
+
<p>You may have mistyped the address or the page may have moved.</p>
|
55
|
+
</div>
|
56
|
+
<p>If you are the application owner check the logs for more information.</p>
|
57
|
+
</body>
|
58
|
+
</html>
|
@@ -0,0 +1,58 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The change you wanted was rejected (422)</title>
|
5
|
+
<style>
|
6
|
+
body {
|
7
|
+
background-color: #EFEFEF;
|
8
|
+
color: #2E2F30;
|
9
|
+
text-align: center;
|
10
|
+
font-family: arial, sans-serif;
|
11
|
+
}
|
12
|
+
|
13
|
+
div.dialog {
|
14
|
+
width: 25em;
|
15
|
+
margin: 4em auto 0 auto;
|
16
|
+
border: 1px solid #CCC;
|
17
|
+
border-right-color: #999;
|
18
|
+
border-left-color: #999;
|
19
|
+
border-bottom-color: #BBB;
|
20
|
+
border-top: #B00100 solid 4px;
|
21
|
+
border-top-left-radius: 9px;
|
22
|
+
border-top-right-radius: 9px;
|
23
|
+
background-color: white;
|
24
|
+
padding: 7px 4em 0 4em;
|
25
|
+
}
|
26
|
+
|
27
|
+
h1 {
|
28
|
+
font-size: 100%;
|
29
|
+
color: #730E15;
|
30
|
+
line-height: 1.5em;
|
31
|
+
}
|
32
|
+
|
33
|
+
body > p {
|
34
|
+
width: 33em;
|
35
|
+
margin: 0 auto 1em;
|
36
|
+
padding: 1em 0;
|
37
|
+
background-color: #F7F7F7;
|
38
|
+
border: 1px solid #CCC;
|
39
|
+
border-right-color: #999;
|
40
|
+
border-bottom-color: #999;
|
41
|
+
border-bottom-left-radius: 4px;
|
42
|
+
border-bottom-right-radius: 4px;
|
43
|
+
border-top-color: #DADADA;
|
44
|
+
color: #666;
|
45
|
+
box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
|
46
|
+
}
|
47
|
+
</style>
|
48
|
+
</head>
|
49
|
+
|
50
|
+
<body>
|
51
|
+
<!-- This file lives in public/422.html -->
|
52
|
+
<div class="dialog">
|
53
|
+
<h1>The change you wanted was rejected.</h1>
|
54
|
+
<p>Maybe you tried to change something you didn't have access to.</p>
|
55
|
+
</div>
|
56
|
+
<p>If you are the application owner check the logs for more information.</p>
|
57
|
+
</body>
|
58
|
+
</html>
|
@@ -0,0 +1,57 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>We're sorry, but something went wrong (500)</title>
|
5
|
+
<style>
|
6
|
+
body {
|
7
|
+
background-color: #EFEFEF;
|
8
|
+
color: #2E2F30;
|
9
|
+
text-align: center;
|
10
|
+
font-family: arial, sans-serif;
|
11
|
+
}
|
12
|
+
|
13
|
+
div.dialog {
|
14
|
+
width: 25em;
|
15
|
+
margin: 4em auto 0 auto;
|
16
|
+
border: 1px solid #CCC;
|
17
|
+
border-right-color: #999;
|
18
|
+
border-left-color: #999;
|
19
|
+
border-bottom-color: #BBB;
|
20
|
+
border-top: #B00100 solid 4px;
|
21
|
+
border-top-left-radius: 9px;
|
22
|
+
border-top-right-radius: 9px;
|
23
|
+
background-color: white;
|
24
|
+
padding: 7px 4em 0 4em;
|
25
|
+
}
|
26
|
+
|
27
|
+
h1 {
|
28
|
+
font-size: 100%;
|
29
|
+
color: #730E15;
|
30
|
+
line-height: 1.5em;
|
31
|
+
}
|
32
|
+
|
33
|
+
body > p {
|
34
|
+
width: 33em;
|
35
|
+
margin: 0 auto 1em;
|
36
|
+
padding: 1em 0;
|
37
|
+
background-color: #F7F7F7;
|
38
|
+
border: 1px solid #CCC;
|
39
|
+
border-right-color: #999;
|
40
|
+
border-bottom-color: #999;
|
41
|
+
border-bottom-left-radius: 4px;
|
42
|
+
border-bottom-right-radius: 4px;
|
43
|
+
border-top-color: #DADADA;
|
44
|
+
color: #666;
|
45
|
+
box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
|
46
|
+
}
|
47
|
+
</style>
|
48
|
+
</head>
|
49
|
+
|
50
|
+
<body>
|
51
|
+
<!-- This file lives in public/500.html -->
|
52
|
+
<div class="dialog">
|
53
|
+
<h1>We're sorry, but something went wrong.</h1>
|
54
|
+
</div>
|
55
|
+
<p>If you are the application owner check the logs for more information.</p>
|
56
|
+
</body>
|
57
|
+
</html>
|
File without changes
|
@@ -0,0 +1,14 @@
|
|
1
|
+
FactoryGirl.define do
|
2
|
+
factory :attribute_customization do
|
3
|
+
namespace 'Business'
|
4
|
+
name 'street'
|
5
|
+
display_name 'Street'
|
6
|
+
end
|
7
|
+
|
8
|
+
factory :attribute_mapping do
|
9
|
+
namespace 'Business'
|
10
|
+
attribute_name 'status'
|
11
|
+
label 'Active'
|
12
|
+
value 'active'
|
13
|
+
end
|
14
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
ENV["RAILS_ENV"] = "test"
|
2
|
+
|
3
|
+
require File.expand_path("../dummy/config/environment.rb", __FILE__)
|
4
|
+
require "rails/test_help"
|
5
|
+
|
6
|
+
Rails.backtrace_cleaner.remove_silencers!
|
7
|
+
ActiveSupport.parse_json_times = true
|
8
|
+
|
9
|
+
FactoryGirl.definition_file_paths << File.expand_path("../factories", __FILE__)
|
10
|
+
FactoryGirl.find_definitions
|
11
|
+
|
12
|
+
require 'support/pg'
|
13
|
+
require 'support/business'
|
14
|
+
require 'support/vegetable'
|
15
|
+
|
16
|
+
module ActiveSupport
|
17
|
+
class TestCase
|
18
|
+
include FactoryGirl::Syntax::Methods
|
19
|
+
|
20
|
+
setup do
|
21
|
+
AxleAttributes::Definition.reset_caches
|
22
|
+
Rails.cache.clear
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class AxleAttributes::ChildDefinitionTest < ActiveSupport::TestCase
|
4
|
+
class TestModel < Superstore::Base
|
5
|
+
include AxleAttributes::SerializedChild
|
6
|
+
end
|
7
|
+
|
8
|
+
test 'display_name' do
|
9
|
+
assert_equal 'Test model: Foo', AxleAttributes::ChildDefinition.new(TestModel, :foo, type: :integer).display_name
|
10
|
+
assert_equal 'Test model: Foo', AxleAttributes::ChildDefinition.new(TestModel, :foo, type: :integer).display_name
|
11
|
+
end
|
12
|
+
|
13
|
+
test 'canonical_name' do
|
14
|
+
assert_equal 'axle_attributes_child_definition_test_test_model.foo', AxleAttributes::ChildDefinition.new(TestModel, :foo).canonical_name
|
15
|
+
end
|
16
|
+
|
17
|
+
test 'setup types' do
|
18
|
+
AxleAttributes::ChildDefinition.new(TestModel, :foo, type: :integer).setup!
|
19
|
+
assert_kind_of Superstore::Types::IntegerType, TestModel.attribute_definitions['foo'].type
|
20
|
+
|
21
|
+
AxleAttributes::ChildDefinition.new(TestModel, :foo, type: :boolean).setup!
|
22
|
+
assert_kind_of Superstore::Types::BooleanType, TestModel.attribute_definitions['foo'].type
|
23
|
+
|
24
|
+
AxleAttributes::ChildDefinition.new(TestModel, :foo, type: :string).setup!
|
25
|
+
assert_kind_of Superstore::Types::StringType, TestModel.attribute_definitions['foo'].type
|
26
|
+
|
27
|
+
AxleAttributes::ChildDefinition.new(TestModel, :foo, type: :text).setup!
|
28
|
+
assert_kind_of Superstore::Types::StringType, TestModel.attribute_definitions['foo'].type
|
29
|
+
|
30
|
+
AxleAttributes::ChildDefinition.new(TestModel, :foo, type: :json).setup!
|
31
|
+
assert_kind_of Superstore::Types::JsonType, TestModel.attribute_definitions['foo'].type
|
32
|
+
end
|
33
|
+
|
34
|
+
test 'setup versioned' do
|
35
|
+
TestModel.versioned_attributes.clear
|
36
|
+
AxleAttributes::ChildDefinition.new(TestModel, :foo, type: :boolean, version: true).setup!
|
37
|
+
assert_equal ['foo'].to_set, TestModel.versioned_attributes
|
38
|
+
|
39
|
+
TestModel.versioned_attributes.clear
|
40
|
+
AxleAttributes::ChildDefinition.new(TestModel, :foo, type: :boolean).setup!
|
41
|
+
assert_equal [].to_set, TestModel.versioned_attributes
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class AxleAttributes::ConversionsTest < ActiveSupport::TestCase
|
4
|
+
class TestModel
|
5
|
+
include AxleAttributes::HasAttributes
|
6
|
+
|
7
|
+
has_attribute :color, type: :string
|
8
|
+
end
|
9
|
+
|
10
|
+
include AxleAttributes::Conversions
|
11
|
+
|
12
|
+
use_target_class TestModel
|
13
|
+
|
14
|
+
test 'definitions' do
|
15
|
+
expected = TestModel.attributes['color']
|
16
|
+
assert_equal expected, to_definition(expected)
|
17
|
+
end
|
18
|
+
|
19
|
+
test 'string converted to definition' do
|
20
|
+
expected = TestModel.attributes['color']
|
21
|
+
assert_equal expected, to_definition('color')
|
22
|
+
end
|
23
|
+
|
24
|
+
test 'null definitions' do
|
25
|
+
expected = AxleAttributes::NullDefinition.new(TestModel, 'abc')
|
26
|
+
assert_equal expected, to_definition(expected)
|
27
|
+
end
|
28
|
+
|
29
|
+
test 'string converted to null definition' do
|
30
|
+
expected = AxleAttributes::NullDefinition.new(TestModel, 'contacts')
|
31
|
+
assert_equal expected, to_definition('contacts')
|
32
|
+
end
|
33
|
+
|
34
|
+
test 'unknown conversion' do
|
35
|
+
assert_raises ConversionError do
|
36
|
+
to_definition(123)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class AxleAttributes::Definition::CustomizationTest < ActiveSupport::TestCase
|
4
|
+
test 'customization' do
|
5
|
+
attribute_customization = create :attribute_customization, name: 'foo', namespace: 'Business'
|
6
|
+
foo = AxleAttributes::Definition.new Business, :foo
|
7
|
+
|
8
|
+
assert_equal attribute_customization, foo.customization
|
9
|
+
end
|
10
|
+
|
11
|
+
test 'display_name' do
|
12
|
+
foo = AxleAttributes::Definition.new Business, :foo
|
13
|
+
assert_equal 'Foo', foo.display_name
|
14
|
+
|
15
|
+
foo_bar = AxleAttributes::Definition.new Business, 'foo.bar'
|
16
|
+
assert_equal 'Foo Bar', foo_bar.display_name
|
17
|
+
end
|
18
|
+
|
19
|
+
test 'readers' do
|
20
|
+
attribute_customization = create :attribute_customization, name: 'foo', namespace: 'Business', description: 'A cool attribute', editable: false, notes: 'We need to remove this', deprecated_on: Date.new(2004, 12, 24)
|
21
|
+
foo = AxleAttributes::Definition.new Business, :foo
|
22
|
+
bar = AxleAttributes::Definition.new Business, :bar
|
23
|
+
|
24
|
+
assert_equal 'A cool attribute', foo.description
|
25
|
+
assert_equal false, foo.editable_customization
|
26
|
+
assert_equal 'We need to remove this', foo.notes
|
27
|
+
assert_equal Date.new(2004, 12, 24), foo.deprecated_on
|
28
|
+
assert foo.deprecated?
|
29
|
+
|
30
|
+
assert_nil bar.description
|
31
|
+
assert_equal true, bar.editable_customization
|
32
|
+
assert_nil bar.notes
|
33
|
+
assert_nil bar.deprecated_on
|
34
|
+
refute bar.deprecated?
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class AxleAttributes::Definition::FormattedTest < ActiveSupport::TestCase
|
4
|
+
class PriceFormatter
|
5
|
+
# ui_regex: /\$\d+\.\d+/.inspect,
|
6
|
+
# ui_regex_error: "Please enter a price. eg. $4.99",
|
7
|
+
def setup!(definition)
|
8
|
+
end
|
9
|
+
|
10
|
+
def standardize(definition, value)
|
11
|
+
if value.start_with?('$')
|
12
|
+
value
|
13
|
+
else
|
14
|
+
"$#{value}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def validate(definition, value)
|
19
|
+
unless value =~ /\$\d+\.\d{2}/
|
20
|
+
'must be in format $31.42'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def instructions(definition)
|
25
|
+
"ex. $4.99"
|
26
|
+
end
|
27
|
+
|
28
|
+
def analyzer_mapping
|
29
|
+
{"lol" => "bar"}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class DumbFormatter
|
34
|
+
end
|
35
|
+
|
36
|
+
class TestDefinition < AxleAttributes::Definition
|
37
|
+
self.formatters = formatters.update(price: PriceFormatter.new, dumb: DumbFormatter.new)
|
38
|
+
end
|
39
|
+
|
40
|
+
test 'formatter setup with method override' do
|
41
|
+
assert_equal 'LLC', Business.new(structure: 'llc').structure
|
42
|
+
end
|
43
|
+
|
44
|
+
test 'instructions without customization' do
|
45
|
+
assert_equal "ex. $4.99", TestDefinition.new(Business, :foo, type: :integer, format: :price).instructions
|
46
|
+
assert_nil TestDefinition.new(Business, :foo, type: :integer, format: :dumb).instructions
|
47
|
+
end
|
48
|
+
|
49
|
+
test 'instructions with customization' do
|
50
|
+
create :attribute_customization, namespace: 'Business', name: 'bar', instructions: "Do it good"
|
51
|
+
|
52
|
+
assert_equal "Do it good", TestDefinition.new(Business, :bar, type: :integer, format: :price).instructions
|
53
|
+
end
|
54
|
+
|
55
|
+
test 'analyzer_mapping' do
|
56
|
+
assert_nil TestDefinition.new(Business, :foo, type: :integer, format: :dumb).analyzer_mapping
|
57
|
+
assert_equal({type: "string", analyzer: :snowball}, TestDefinition.new(Business, :foo, type: :integer, format: :dumb, index: :snowball).analyzer_mapping)
|
58
|
+
|
59
|
+
assert_equal({"lol" => "bar"}, TestDefinition.new(Business, :foo, type: :integer, format: :price).analyzer_mapping)
|
60
|
+
end
|
61
|
+
|
62
|
+
test 'standardize' do
|
63
|
+
assert_equal 'lol', TestDefinition.new(Business, :foo, type: :integer, format: :dumb).standardize('lol')
|
64
|
+
|
65
|
+
assert_equal '$5.43', TestDefinition.new(Business, :foo, type: :integer, format: :price).standardize('5.43')
|
66
|
+
assert_equal '$5.43', TestDefinition.new(Business, :foo, type: :integer, format: :price).standardize('$5.43')
|
67
|
+
end
|
68
|
+
|
69
|
+
test 'validate' do
|
70
|
+
assert_nil TestDefinition.new(Business, :foo, type: :integer, format: :dumb).validate('lol')
|
71
|
+
|
72
|
+
assert_nil TestDefinition.new(Business, :foo, type: :integer, format: :price).validate('$5.43')
|
73
|
+
assert_equal 'must be in format $31.42', TestDefinition.new(Business, :foo, type: :integer, format: :price).validate('ab12')
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class AxleAttributes::Definition::IndexedTest < ActiveSupport::TestCase
|
4
|
+
class TestModel
|
5
|
+
class << self
|
6
|
+
def name
|
7
|
+
'TestModel'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
test 'analyzer_mapping' do
|
13
|
+
assert_equal({type: "string", analyzer: :snowball}, AxleAttributes::Definition.new(TestModel, :name, index: :snowball).analyzer_mapping)
|
14
|
+
assert_equal({type: "string", analyzer: :simple}, AxleAttributes::Definition.new(TestModel, :name, index: :simple).analyzer_mapping)
|
15
|
+
assert_nil AxleAttributes::Definition.new(TestModel, :foo).analyzer_mapping
|
16
|
+
end
|
17
|
+
|
18
|
+
test 'index_mapping' do
|
19
|
+
assert_nil build_mapping(type: :string, index: false)
|
20
|
+
|
21
|
+
assert_equal(
|
22
|
+
{type: "geo_point", lat_lon: true},
|
23
|
+
build_mapping(type: false, index: {type: "geo_point", lat_lon: true})
|
24
|
+
)
|
25
|
+
|
26
|
+
assert_equal(
|
27
|
+
{type: "boolean", doc_values: true},
|
28
|
+
build_mapping(type: :boolean, index: true)
|
29
|
+
)
|
30
|
+
|
31
|
+
assert_equal(
|
32
|
+
{type: "date", format: "date", doc_values: true},
|
33
|
+
build_mapping(type: :date, index: true)
|
34
|
+
)
|
35
|
+
|
36
|
+
assert_equal(
|
37
|
+
{type: "string", index_analyzer: "keyword", search_analyzer: "standard"},
|
38
|
+
build_mapping(type: :string, index: true)
|
39
|
+
)
|
40
|
+
|
41
|
+
assert_equal(
|
42
|
+
{type: "multi_field", fields: {'foo'=> {type: "string", index: "not_analyzed", doc_values: true}, analyzed: {type: "string", analyzer: :snowball}}},
|
43
|
+
build_mapping(type: :string, index: :snowball)
|
44
|
+
)
|
45
|
+
|
46
|
+
assert_equal(
|
47
|
+
{type: "multi_field", fields: {'foo' => {type: "string", index: "not_analyzed", doc_values: true}, analyzed: {type: "string", analyzer: :simple}}},
|
48
|
+
build_mapping(type: :string, index: :simple)
|
49
|
+
)
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def build_mapping(options)
|
55
|
+
AxleAttributes::Definition.new(TestModel, :foo, options).index_mapping
|
56
|
+
end
|
57
|
+
end
|