jat 0.0.5 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jat/attribute.rb +5 -16
- data/lib/jat/config.rb +4 -7
- data/lib/jat/plugins/activerecord/activerecord.rb +23 -0
- data/lib/jat/plugins/{_activerecord_preloads/_activerecord_preloads.rb → base/base_activerecord_preloads/base_activerecord_preloads.rb} +7 -2
- data/lib/jat/plugins/{_activerecord_preloads → base/base_activerecord_preloads}/lib/preloader.rb +16 -4
- data/lib/jat/plugins/{_lower_camel_case/_lower_camel_case.rb → base/base_lower_camel_case/base_lower_camel_case.rb} +6 -2
- data/lib/jat/plugins/{_preloads/_preloads.rb → base/base_preloads/base_preloads.rb} +6 -2
- data/lib/jat/plugins/{_preloads → base/base_preloads}/lib/format_user_preloads.rb +1 -1
- data/lib/jat/plugins/{_preloads → base/base_preloads}/lib/preloads_with_path.rb +1 -1
- data/lib/jat/plugins/cache/cache.rb +5 -1
- data/lib/jat/plugins/json_api/json_api.rb +7 -3
- data/lib/jat/plugins/json_api/lib/map.rb +4 -5
- data/lib/jat/plugins/json_api/lib/response.rb +1 -5
- data/lib/jat/plugins/json_api/lib/response_piece.rb +19 -10
- data/lib/jat/plugins/json_api/plugins/json_api_activerecord/json_api_activerecord.rb +23 -0
- data/lib/jat/plugins/{json_api_lower_camel_case → json_api/plugins/json_api_lower_camel_case}/json_api_lower_camel_case.rb +6 -2
- data/lib/jat/plugins/{json_api_maps_cache → json_api/plugins/json_api_maps_cache}/json_api_maps_cache.rb +5 -1
- data/lib/jat/plugins/json_api/plugins/json_api_preloads/json_api_preloads.rb +38 -0
- data/lib/jat/plugins/{json_api_activerecord → json_api/plugins/json_api_preloads}/lib/preloads.rb +1 -1
- data/lib/jat/plugins/{json_api_validate_params → json_api/plugins/json_api_validate_params}/json_api_validate_params.rb +5 -1
- data/lib/jat/plugins/{json_api_validate_params → json_api/plugins/json_api_validate_params}/lib/params_error.rb +0 -0
- data/lib/jat/plugins/{json_api_validate_params → json_api/plugins/json_api_validate_params}/lib/validate_fields_param.rb +0 -0
- data/lib/jat/plugins/{json_api_validate_params → json_api/plugins/json_api_validate_params}/lib/validate_include_param.rb +1 -3
- data/lib/jat/plugins/lower_camel_case/lower_camel_case.rb +23 -0
- data/lib/jat/plugins/maps_cache/maps_cache.rb +23 -0
- data/lib/jat/plugins/preloads/preloads.rb +23 -0
- data/lib/jat/plugins/simple_api/lib/fields_param_parser.rb +20 -36
- data/lib/jat/plugins/simple_api/lib/map.rb +4 -5
- data/lib/jat/plugins/simple_api/lib/response.rb +1 -5
- data/lib/jat/plugins/simple_api/lib/response_piece.rb +1 -5
- data/lib/jat/plugins/simple_api/plugins/simple_api_activerecord/simple_api_activerecord.rb +23 -0
- data/lib/jat/plugins/{simple_api_lower_camel_case → simple_api/plugins/simple_api_lower_camel_case}/simple_api_lower_camel_case.rb +6 -2
- data/lib/jat/plugins/{simple_api_maps_cache → simple_api/plugins/simple_api_maps_cache}/simple_api_maps_cache.rb +6 -4
- data/lib/jat/plugins/{simple_api_activerecord → simple_api/plugins/simple_api_preloads}/lib/preloads.rb +1 -1
- data/lib/jat/plugins/simple_api/plugins/simple_api_preloads/simple_api_preloads.rb +38 -0
- data/lib/jat/plugins/{simple_api_validate_params → simple_api/plugins/simple_api_validate_params}/lib/fields_error.rb +0 -0
- data/lib/jat/plugins/{simple_api_validate_params → simple_api/plugins/simple_api_validate_params}/lib/validate_fields_param.rb +0 -0
- data/lib/jat/plugins/{simple_api_validate_params → simple_api/plugins/simple_api_validate_params}/simple_api_validate_params.rb +6 -2
- data/lib/jat/plugins/simple_api/simple_api.rb +8 -7
- data/lib/jat/plugins/to_str/to_str.rb +5 -1
- data/lib/jat/plugins/types/types.rb +55 -0
- data/lib/jat/plugins/validate_params/validate_params.rb +23 -0
- data/lib/jat/plugins.rb +41 -15
- data/lib/jat.rb +24 -17
- data/test/lib/jat/attribute_test.rb +8 -0
- data/test/lib/jat/plugins/activerecord/activerecord_test.rb +27 -0
- data/test/lib/jat/plugins/{_activerecord_preloads/_activerecord_preloads_test.rb → base_activerecord_preloads/base_activerecord_preloads_test.rb} +3 -3
- data/test/lib/jat/plugins/{_activerecord_preloads → base_activerecord_preloads}/lib/preloader_test.rb +2 -2
- data/test/lib/jat/plugins/{_camel_lower/_camel_lower_test.rb → base_lower_camel_case/base_lower_camel_case_test.rb} +2 -2
- data/test/lib/jat/plugins/{_preloads/_preloads_test.rb → base_preloads/base_preloads_test.rb} +2 -2
- data/test/lib/jat/plugins/{_preloads → base_preloads}/lib/format_user_preloads_test.rb +3 -3
- data/test/lib/jat/plugins/{_preloads → base_preloads}/lib/preloads_with_path_test.rb +2 -2
- data/test/lib/jat/plugins/json_api/json_api_test.rb +1 -9
- data/test/lib/jat/plugins/json_api/lib/fields_param_parser_test.rb +20 -12
- data/test/lib/jat/plugins/json_api/lib/include_param_parser_test.rb +25 -11
- data/test/lib/jat/plugins/json_api/lib/map_test.rb +132 -124
- data/test/lib/jat/plugins/json_api/lib/response_piece_test.rb +13 -0
- data/test/lib/jat/plugins/json_api/lib/response_test.rb +6 -1
- data/test/lib/jat/plugins/json_api_activerecord/json_api_activerecord_test.rb +4 -18
- data/test/lib/jat/plugins/{json_api_camel_lower/json_api_camel_lower_test.rb → json_api_lower_camel_case/json_api_lower_camel_case_test.rb} +6 -0
- data/test/lib/jat/plugins/json_api_preloads/json_api_preloads_test.rb +51 -0
- data/test/lib/jat/plugins/{json_api_activerecord → json_api_preloads}/lib/preloads_test.rb +8 -6
- data/test/lib/jat/plugins/json_api_validate_params/json_api_validate_params_test.rb +30 -6
- data/test/lib/jat/plugins/lower_camel_case/lower_camel_case_test.rb +27 -0
- data/test/lib/jat/plugins/maps_cache/maps_cache_test.rb +27 -0
- data/test/lib/jat/plugins/preloads/preloads_test.rb +27 -0
- data/test/lib/jat/plugins/simple_api/lib/fields_param_parser_test.rb +57 -43
- data/test/lib/jat/plugins/simple_api/lib/map_test.rb +90 -82
- data/test/lib/jat/plugins/simple_api/lib/response_piece_test.rb +13 -0
- data/test/lib/jat/plugins/simple_api/lib/response_test.rb +18 -12
- data/test/lib/jat/plugins/simple_api/simple_api_test.rb +33 -6
- data/test/lib/jat/plugins/simple_api_activerecord/simple_api_activerecord_test.rb +4 -18
- data/test/lib/jat/plugins/{simple_api_camel_lower/simple_api_camel_lower_test.rb → simple_api_lower_camel_case/simple_api_lower_camel_case_test.rb} +7 -1
- data/test/lib/jat/plugins/{simple_api_activerecord → simple_api_preloads}/lib/preloads_test.rb +8 -8
- data/test/lib/jat/plugins/simple_api_preloads/simple_api_preloads_test.rb +51 -0
- data/test/lib/jat/plugins/simple_api_validate_params/simple_api_validate_params_test.rb +12 -0
- data/test/lib/jat/plugins/types/types_test.rb +83 -0
- data/test/lib/jat/plugins/validate_params/validate_params_test.rb +27 -0
- data/test/lib/jat/plugins_test.rb +88 -0
- data/test/test_helper.rb +8 -4
- metadata +98 -82
- data/lib/jat/plugins/json_api_activerecord/json_api_activerecord.rb +0 -31
- data/lib/jat/plugins/simple_api_activerecord/simple_api_activerecord.rb +0 -31
data/test/lib/jat/plugins/{simple_api_activerecord → simple_api_preloads}/lib/preloads_test.rb
RENAMED
@@ -2,18 +2,18 @@
|
|
2
2
|
|
3
3
|
require "test_helper"
|
4
4
|
|
5
|
-
describe "Jat::Plugins::
|
6
|
-
let(:base)
|
5
|
+
describe "Jat::Plugins::SimpleApiPreloads::Preloads" do
|
6
|
+
let(:base) do
|
7
|
+
Class.new(Jat) do
|
8
|
+
plugin :simple_api
|
9
|
+
plugin :simple_api_preloads
|
10
|
+
end
|
11
|
+
end
|
7
12
|
|
13
|
+
let(:described_class) { Jat::Plugins::SimpleApiPreloads::Preloads }
|
8
14
|
let(:user_serializer) { Class.new(base) }
|
9
15
|
let(:profile_serializer) { Class.new(base) }
|
10
|
-
let(:email_serializer) { Class.new(base) }
|
11
|
-
|
12
16
|
let(:jat_user) { user_serializer.new }
|
13
|
-
let(:jat_profile) { profile_serializer.new }
|
14
|
-
let(:jat_email) { email_serializer.new }
|
15
|
-
|
16
|
-
let(:described_class) { Jat::Plugins::SimpleApiActiverecord::Preloads }
|
17
17
|
|
18
18
|
def define_map(map)
|
19
19
|
user_serializer::Map.expects(:call).returns(map)
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "test_helper"
|
4
|
+
|
5
|
+
describe "Jat::Plugins::SimpleApiPreloads" do
|
6
|
+
before do
|
7
|
+
@plugin = Jat::Plugins.find_plugin(:simple_api_preloads)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "checks simple_api plugin loaded before" do
|
11
|
+
jat_class = Class.new(Jat)
|
12
|
+
error = assert_raises(Jat::Error) { jat_class.plugin @plugin }
|
13
|
+
assert_match(/simple_api/, error.message)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "loads other plugins in before_load" do
|
17
|
+
jat_class = Class.new(Jat)
|
18
|
+
jat_class.plugin :simple_api
|
19
|
+
|
20
|
+
jat_class.expects(:plugin).with(:base_preloads, foo: :bar)
|
21
|
+
|
22
|
+
@plugin.before_load(jat_class, foo: :bar)
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "InstanceMethods" do
|
26
|
+
it "adds #preloads method as a delegator to #{@plugin}::Preloads" do
|
27
|
+
jat_class = Class.new(Jat)
|
28
|
+
jat_class.plugin :simple_api
|
29
|
+
jat_class.plugin @plugin
|
30
|
+
jat = jat_class.allocate
|
31
|
+
|
32
|
+
@plugin::Preloads.expects(:call).with(jat).returns("RES")
|
33
|
+
|
34
|
+
assert_equal "RES", jat.preloads
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "ClassMethods" do
|
39
|
+
it "adds .preloads method as a delegator to #{@plugin}::Preloads" do
|
40
|
+
jat_class = Class.new(Jat)
|
41
|
+
jat_class.plugin :simple_api
|
42
|
+
jat_class.plugin @plugin
|
43
|
+
|
44
|
+
jat = jat_class.allocate
|
45
|
+
jat_class.expects(:new).with("CONTEXT").returns(jat)
|
46
|
+
@plugin::Preloads.expects(:call).with(jat).returns("RES")
|
47
|
+
|
48
|
+
assert_equal "RES", jat_class.preloads("CONTEXT")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -36,6 +36,11 @@ describe "Jat::Plugins::SimpleApiValidateParams" do
|
|
36
36
|
jat_class
|
37
37
|
end
|
38
38
|
|
39
|
+
it "returns true when provided fields present" do
|
40
|
+
jat = serializer.new(fields: "foo_bar,foo_bazz(foo_bar)")
|
41
|
+
assert jat.validate
|
42
|
+
end
|
43
|
+
|
39
44
|
it "validates fields" do
|
40
45
|
jat = serializer.new(fields: "foo_bar,extra")
|
41
46
|
error = assert_raises(Jat::SimpleApiFieldsError) { jat.validate }
|
@@ -43,6 +48,13 @@ describe "Jat::Plugins::SimpleApiValidateParams" do
|
|
43
48
|
assert_equal(expected_message, error.message)
|
44
49
|
end
|
45
50
|
|
51
|
+
it "validates fields when using lower_camel_case plugin" do
|
52
|
+
jat = serializer_lower_camel_case.new(fields: "fooBar,extra")
|
53
|
+
error = assert_raises(Jat::SimpleApiFieldsError) { jat.validate }
|
54
|
+
expected_message = "Field 'extra' not exists"
|
55
|
+
assert_equal(expected_message, error.message)
|
56
|
+
end
|
57
|
+
|
46
58
|
it "validates deeply nested fields" do
|
47
59
|
c = Class.new(base_serializer)
|
48
60
|
c.attribute :c1
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "test_helper"
|
4
|
+
|
5
|
+
describe "Jat::Plugins::Types" do
|
6
|
+
let(:struct) { Struct.new(:attr) }
|
7
|
+
|
8
|
+
let(:jat_class) do
|
9
|
+
new_class = Class.new(Jat)
|
10
|
+
new_class.plugin(:types)
|
11
|
+
new_class
|
12
|
+
end
|
13
|
+
|
14
|
+
def attr_value(original_value)
|
15
|
+
obj = struct.new(original_value)
|
16
|
+
jat_class.attributes[:attr].value(obj, nil)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "has predefined :int type" do
|
20
|
+
jat_class.attribute(:attr, type: :int)
|
21
|
+
|
22
|
+
assert_equal(0, attr_value("0"))
|
23
|
+
assert_equal(8, attr_value("010")) # octal system
|
24
|
+
assert_equal(10, attr_value("0xa")) # hexadecimal system
|
25
|
+
end
|
26
|
+
|
27
|
+
it "has predefined :bool type" do
|
28
|
+
jat_class.attribute(:attr, type: :bool)
|
29
|
+
|
30
|
+
assert_equal(false, attr_value(nil))
|
31
|
+
assert_equal(false, attr_value(false))
|
32
|
+
assert_equal(true, attr_value(1))
|
33
|
+
end
|
34
|
+
|
35
|
+
it "has predefined :float type" do
|
36
|
+
jat_class.attribute(:attr, type: :float)
|
37
|
+
|
38
|
+
assert_same(0.0, attr_value("0"))
|
39
|
+
assert_same(0.001, attr_value("1e-3"))
|
40
|
+
assert_same(1.234, attr_value("1.234"))
|
41
|
+
end
|
42
|
+
|
43
|
+
it "has predefined :array type" do
|
44
|
+
jat_class.attribute(:attr, type: :array)
|
45
|
+
|
46
|
+
assert_equal([1], attr_value(1))
|
47
|
+
assert_equal([1], attr_value([1]))
|
48
|
+
end
|
49
|
+
|
50
|
+
it "has predefined :hash type" do
|
51
|
+
jat_class.attribute(:attr, type: :hash)
|
52
|
+
|
53
|
+
assert_equal({}, attr_value([]))
|
54
|
+
assert_equal({}, attr_value({}))
|
55
|
+
assert_equal({key: :value}, attr_value(key: :value))
|
56
|
+
end
|
57
|
+
|
58
|
+
it "has predefined :str type" do
|
59
|
+
jat_class.attribute(:attr, type: :str)
|
60
|
+
|
61
|
+
assert_equal("", attr_value(nil))
|
62
|
+
assert_equal("123", attr_value(123))
|
63
|
+
end
|
64
|
+
|
65
|
+
it "allows to use callable method as type" do
|
66
|
+
jat_class.attribute(:attr, type: ->(obj) { obj ? :yes : :no })
|
67
|
+
|
68
|
+
assert_equal(:no, attr_value(nil))
|
69
|
+
assert_equal(:yes, attr_value(1))
|
70
|
+
end
|
71
|
+
|
72
|
+
it "allows to configure custom type" do
|
73
|
+
jat_class.config[:types][:year] = ->(obj) { obj.strftime("%Y") }
|
74
|
+
jat_class.attribute(:attr, type: :year)
|
75
|
+
|
76
|
+
assert_equal("2020", attr_value(Time.new(2020, 10, 10)))
|
77
|
+
end
|
78
|
+
|
79
|
+
it "allows to skip type" do
|
80
|
+
jat_class.attribute(:attr)
|
81
|
+
assert_equal(333, attr_value(333))
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "test_helper"
|
4
|
+
|
5
|
+
describe "Jat::Plugins::ValidateParams" do
|
6
|
+
it "raises error if no response plugin is loaded" do
|
7
|
+
new_class = Class.new(Jat)
|
8
|
+
err = assert_raises(Jat::Error) { new_class.plugin :validate_params }
|
9
|
+
assert_equal "Please load :json_api or :simple_api plugin first", err.message
|
10
|
+
end
|
11
|
+
|
12
|
+
it "loads simple_api compatible plugin" do
|
13
|
+
new_class = Class.new(Jat)
|
14
|
+
new_class.plugin :simple_api
|
15
|
+
new_class.plugin :validate_params
|
16
|
+
|
17
|
+
assert new_class.plugin_used?(:simple_api_validate_params)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "loads json_api compatible plugin" do
|
21
|
+
new_class = Class.new(Jat)
|
22
|
+
new_class.plugin :json_api
|
23
|
+
new_class.plugin :validate_params
|
24
|
+
|
25
|
+
assert new_class.plugin_used?(:json_api_validate_params)
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "test_helper"
|
4
|
+
|
5
|
+
describe Jat::Plugins do
|
6
|
+
let(:described_module) { Jat::Plugins }
|
7
|
+
|
8
|
+
describe ".register_plugin" do
|
9
|
+
it "adds plugin to the @plugins list" do
|
10
|
+
plugin = Module.new
|
11
|
+
plugin_name = :new_plugin
|
12
|
+
described_module.register_plugin(plugin_name, plugin)
|
13
|
+
|
14
|
+
assert_equal plugin, described_module.instance_variable_get(:@plugins).fetch(plugin_name)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe ".find_plugin" do
|
19
|
+
it "returns module if module provided" do
|
20
|
+
plugin = Module.new
|
21
|
+
assert_equal plugin, described_module.find_plugin(plugin)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "returns already registered plugin found by name" do
|
25
|
+
plugin = Module.new
|
26
|
+
plugin_name = :new_plugin
|
27
|
+
described_module.register_plugin(plugin_name, plugin)
|
28
|
+
|
29
|
+
assert_equal plugin, described_module.find_plugin(plugin_name)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "returns global plugins found by name" do
|
33
|
+
assert_equal "Jat::Plugins::Activerecord", described_module.find_plugin(:activerecord).name
|
34
|
+
assert_equal "Jat::Plugins::Cache", described_module.find_plugin(:cache).name
|
35
|
+
assert_equal "Jat::Plugins::JsonApi", described_module.find_plugin(:json_api).name
|
36
|
+
assert_equal "Jat::Plugins::LowerCamelCase", described_module.find_plugin(:lower_camel_case).name
|
37
|
+
assert_equal "Jat::Plugins::MapsCache", described_module.find_plugin(:maps_cache).name
|
38
|
+
assert_equal "Jat::Plugins::Preloads", described_module.find_plugin(:preloads).name
|
39
|
+
assert_equal "Jat::Plugins::SimpleApi", described_module.find_plugin(:simple_api).name
|
40
|
+
assert_equal "Jat::Plugins::ToStr", described_module.find_plugin(:to_str).name
|
41
|
+
assert_equal "Jat::Plugins::Types", described_module.find_plugin(:types).name
|
42
|
+
assert_equal "Jat::Plugins::ValidateParams", described_module.find_plugin(:validate_params).name
|
43
|
+
end
|
44
|
+
|
45
|
+
it "returns json_api only plugins found by name (name has `json_api_` prefix)" do
|
46
|
+
assert_equal "Jat::Plugins::JsonApiActiverecord", described_module.find_plugin(:json_api_activerecord).name
|
47
|
+
assert_equal "Jat::Plugins::JsonApiLowerCamelCase", described_module.find_plugin(:json_api_lower_camel_case).name
|
48
|
+
assert_equal "Jat::Plugins::JsonApiMapsCache", described_module.find_plugin(:json_api_maps_cache).name
|
49
|
+
assert_equal "Jat::Plugins::JsonApiPreloads", described_module.find_plugin(:json_api_preloads).name
|
50
|
+
assert_equal "Jat::Plugins::JsonApiValidateParams", described_module.find_plugin(:json_api_validate_params).name
|
51
|
+
end
|
52
|
+
|
53
|
+
it "returns simple_api only plugins found by name (name has `simple_api_` prefix)" do
|
54
|
+
assert_equal "Jat::Plugins::SimpleApiActiverecord", described_module.find_plugin(:simple_api_activerecord).name
|
55
|
+
assert_equal "Jat::Plugins::SimpleApiLowerCamelCase", described_module.find_plugin(:simple_api_lower_camel_case).name
|
56
|
+
assert_equal "Jat::Plugins::SimpleApiMapsCache", described_module.find_plugin(:simple_api_maps_cache).name
|
57
|
+
assert_equal "Jat::Plugins::SimpleApiPreloads", described_module.find_plugin(:simple_api_preloads).name
|
58
|
+
assert_equal "Jat::Plugins::SimpleApiValidateParams", described_module.find_plugin(:simple_api_validate_params).name
|
59
|
+
end
|
60
|
+
|
61
|
+
it "returns base plugins found by name (name has `base_` prefix)" do
|
62
|
+
assert_equal "Jat::Plugins::BaseActiverecordPreloads", described_module.find_plugin(:base_activerecord_preloads).name
|
63
|
+
assert_equal "Jat::Plugins::BaseLowerCamelCase", described_module.find_plugin(:base_lower_camel_case).name
|
64
|
+
assert_equal "Jat::Plugins::BasePreloads", described_module.find_plugin(:base_preloads).name
|
65
|
+
end
|
66
|
+
|
67
|
+
it "raises specific error if plugin not found" do
|
68
|
+
err = assert_raises(Jat::PluginLoadError) { described_module.find_plugin(:foo) }
|
69
|
+
assert_equal "Plugin 'foo' does not exist", err.message
|
70
|
+
end
|
71
|
+
|
72
|
+
it "raises specific error if plugin was found by name but was not registered" do
|
73
|
+
plugin_name = "test_foo"
|
74
|
+
|
75
|
+
# Add plugin folder and file in plugins directory
|
76
|
+
plugin_dir = File.join(__dir__, "../../../lib/jat/plugins", plugin_name)
|
77
|
+
plugin_path = File.join(plugin_dir, "#{plugin_name}.rb")
|
78
|
+
Dir.mkdir(plugin_dir)
|
79
|
+
File.new(plugin_path, File::CREAT)
|
80
|
+
|
81
|
+
err = assert_raises(Jat::PluginLoadError) { described_module.find_plugin(plugin_name) }
|
82
|
+
assert_equal "Plugin '#{plugin_name}' did not register itself correctly", err.message
|
83
|
+
ensure
|
84
|
+
File.unlink(plugin_path)
|
85
|
+
Dir.unlink(plugin_dir)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -1,13 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
# ARGV is populated with all test file names when running `rake`
|
4
|
+
# ARGV is not populated when running `ruby -Itest {file}`
|
5
|
+
# ARGV is not populated when running test by `m` gem - `m {file}`
|
6
|
+
# ARGV is not populated when running tests by `m` gem with line number - `m {file}:{line_number}`
|
7
|
+
# jruby and truffleruby have bad simplecov support
|
8
|
+
if RUBY_ENGINE == "ruby" && ARGV.any?
|
9
|
+
require "simplecov"
|
10
|
+
SimpleCov.start
|
6
11
|
end
|
7
12
|
|
8
13
|
require "bundler/setup"
|
9
14
|
require "minitest/autorun"
|
10
15
|
require "mocha/minitest"
|
11
|
-
require "pry-byebug"
|
12
16
|
|
13
17
|
require_relative "../lib/jat"
|
metadata
CHANGED
@@ -1,113 +1,99 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrey Glushkov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: mocha
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: simplecov
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0
|
61
|
+
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '0
|
68
|
+
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: standard
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: activerecord
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - "
|
87
|
+
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
89
|
+
version: '0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - "
|
94
|
+
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: sqlite3
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - "~>"
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '1.4'
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - "~>"
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '1.4'
|
96
|
+
version: '0'
|
111
97
|
description: |
|
112
98
|
JAT serializer allows you to generate a JSON response based on the fields requested by the client.
|
113
99
|
Besides, it helps to preload relations to avoid N+1 when used with activerecord.
|
@@ -120,12 +106,13 @@ files:
|
|
120
106
|
- lib/jat/attribute.rb
|
121
107
|
- lib/jat/config.rb
|
122
108
|
- lib/jat/plugins.rb
|
123
|
-
- lib/jat/plugins/
|
124
|
-
- lib/jat/plugins/
|
125
|
-
- lib/jat/plugins/
|
126
|
-
- lib/jat/plugins/
|
127
|
-
- lib/jat/plugins/
|
128
|
-
- lib/jat/plugins/
|
109
|
+
- lib/jat/plugins/activerecord/activerecord.rb
|
110
|
+
- lib/jat/plugins/base/base_activerecord_preloads/base_activerecord_preloads.rb
|
111
|
+
- lib/jat/plugins/base/base_activerecord_preloads/lib/preloader.rb
|
112
|
+
- lib/jat/plugins/base/base_lower_camel_case/base_lower_camel_case.rb
|
113
|
+
- lib/jat/plugins/base/base_preloads/base_preloads.rb
|
114
|
+
- lib/jat/plugins/base/base_preloads/lib/format_user_preloads.rb
|
115
|
+
- lib/jat/plugins/base/base_preloads/lib/preloads_with_path.rb
|
129
116
|
- lib/jat/plugins/cache/cache.rb
|
130
117
|
- lib/jat/plugins/json_api/json_api.rb
|
131
118
|
- lib/jat/plugins/json_api/lib/fields_param_parser.rb
|
@@ -139,58 +126,76 @@ files:
|
|
139
126
|
- lib/jat/plugins/json_api/lib/params/include/validate.rb
|
140
127
|
- lib/jat/plugins/json_api/lib/response.rb
|
141
128
|
- lib/jat/plugins/json_api/lib/response_piece.rb
|
142
|
-
- lib/jat/plugins/json_api_activerecord/json_api_activerecord.rb
|
143
|
-
- lib/jat/plugins/
|
144
|
-
- lib/jat/plugins/
|
145
|
-
- lib/jat/plugins/
|
146
|
-
- lib/jat/plugins/
|
147
|
-
- lib/jat/plugins/json_api_validate_params/
|
148
|
-
- lib/jat/plugins/json_api_validate_params/lib/
|
149
|
-
- lib/jat/plugins/json_api_validate_params/lib/
|
129
|
+
- lib/jat/plugins/json_api/plugins/json_api_activerecord/json_api_activerecord.rb
|
130
|
+
- lib/jat/plugins/json_api/plugins/json_api_lower_camel_case/json_api_lower_camel_case.rb
|
131
|
+
- lib/jat/plugins/json_api/plugins/json_api_maps_cache/json_api_maps_cache.rb
|
132
|
+
- lib/jat/plugins/json_api/plugins/json_api_preloads/json_api_preloads.rb
|
133
|
+
- lib/jat/plugins/json_api/plugins/json_api_preloads/lib/preloads.rb
|
134
|
+
- lib/jat/plugins/json_api/plugins/json_api_validate_params/json_api_validate_params.rb
|
135
|
+
- lib/jat/plugins/json_api/plugins/json_api_validate_params/lib/params_error.rb
|
136
|
+
- lib/jat/plugins/json_api/plugins/json_api_validate_params/lib/validate_fields_param.rb
|
137
|
+
- lib/jat/plugins/json_api/plugins/json_api_validate_params/lib/validate_include_param.rb
|
138
|
+
- lib/jat/plugins/lower_camel_case/lower_camel_case.rb
|
139
|
+
- lib/jat/plugins/maps_cache/maps_cache.rb
|
140
|
+
- lib/jat/plugins/preloads/preloads.rb
|
150
141
|
- lib/jat/plugins/simple_api/lib/fields_param_parser.rb
|
151
142
|
- lib/jat/plugins/simple_api/lib/map.rb
|
152
143
|
- lib/jat/plugins/simple_api/lib/response.rb
|
153
144
|
- lib/jat/plugins/simple_api/lib/response_piece.rb
|
145
|
+
- lib/jat/plugins/simple_api/plugins/simple_api_activerecord/simple_api_activerecord.rb
|
146
|
+
- lib/jat/plugins/simple_api/plugins/simple_api_lower_camel_case/simple_api_lower_camel_case.rb
|
147
|
+
- lib/jat/plugins/simple_api/plugins/simple_api_maps_cache/simple_api_maps_cache.rb
|
148
|
+
- lib/jat/plugins/simple_api/plugins/simple_api_preloads/lib/preloads.rb
|
149
|
+
- lib/jat/plugins/simple_api/plugins/simple_api_preloads/simple_api_preloads.rb
|
150
|
+
- lib/jat/plugins/simple_api/plugins/simple_api_validate_params/lib/fields_error.rb
|
151
|
+
- lib/jat/plugins/simple_api/plugins/simple_api_validate_params/lib/validate_fields_param.rb
|
152
|
+
- lib/jat/plugins/simple_api/plugins/simple_api_validate_params/simple_api_validate_params.rb
|
154
153
|
- lib/jat/plugins/simple_api/simple_api.rb
|
155
|
-
- lib/jat/plugins/simple_api_activerecord/lib/preloads.rb
|
156
|
-
- lib/jat/plugins/simple_api_activerecord/simple_api_activerecord.rb
|
157
|
-
- lib/jat/plugins/simple_api_lower_camel_case/simple_api_lower_camel_case.rb
|
158
|
-
- lib/jat/plugins/simple_api_maps_cache/simple_api_maps_cache.rb
|
159
|
-
- lib/jat/plugins/simple_api_validate_params/lib/fields_error.rb
|
160
|
-
- lib/jat/plugins/simple_api_validate_params/lib/validate_fields_param.rb
|
161
|
-
- lib/jat/plugins/simple_api_validate_params/simple_api_validate_params.rb
|
162
154
|
- lib/jat/plugins/to_str/to_str.rb
|
155
|
+
- lib/jat/plugins/types/types.rb
|
156
|
+
- lib/jat/plugins/validate_params/validate_params.rb
|
163
157
|
- lib/jat/utils/enum_deep_dup.rb
|
164
158
|
- lib/jat/utils/enum_deep_freeze.rb
|
165
159
|
- test/lib/jat/attribute_test.rb
|
166
160
|
- test/lib/jat/config_test.rb
|
167
|
-
- test/lib/jat/plugins/
|
168
|
-
- test/lib/jat/plugins/
|
169
|
-
- test/lib/jat/plugins/
|
170
|
-
- test/lib/jat/plugins/
|
171
|
-
- test/lib/jat/plugins/
|
172
|
-
- test/lib/jat/plugins/
|
161
|
+
- test/lib/jat/plugins/activerecord/activerecord_test.rb
|
162
|
+
- test/lib/jat/plugins/base_activerecord_preloads/base_activerecord_preloads_test.rb
|
163
|
+
- test/lib/jat/plugins/base_activerecord_preloads/lib/preloader_test.rb
|
164
|
+
- test/lib/jat/plugins/base_lower_camel_case/base_lower_camel_case_test.rb
|
165
|
+
- test/lib/jat/plugins/base_preloads/base_preloads_test.rb
|
166
|
+
- test/lib/jat/plugins/base_preloads/lib/format_user_preloads_test.rb
|
167
|
+
- test/lib/jat/plugins/base_preloads/lib/preloads_with_path_test.rb
|
173
168
|
- test/lib/jat/plugins/cache/cache_test.rb
|
174
169
|
- test/lib/jat/plugins/json_api/json_api_test.rb
|
175
170
|
- test/lib/jat/plugins/json_api/lib/fields_param_parser_test.rb
|
176
171
|
- test/lib/jat/plugins/json_api/lib/include_param_parser_test.rb
|
177
172
|
- test/lib/jat/plugins/json_api/lib/map_test.rb
|
173
|
+
- test/lib/jat/plugins/json_api/lib/response_piece_test.rb
|
178
174
|
- test/lib/jat/plugins/json_api/lib/response_test.rb
|
179
175
|
- test/lib/jat/plugins/json_api_activerecord/json_api_activerecord_test.rb
|
180
|
-
- test/lib/jat/plugins/
|
181
|
-
- test/lib/jat/plugins/json_api_camel_lower/json_api_camel_lower_test.rb
|
176
|
+
- test/lib/jat/plugins/json_api_lower_camel_case/json_api_lower_camel_case_test.rb
|
182
177
|
- test/lib/jat/plugins/json_api_maps_cache/json_api_maps_cache_test.rb
|
178
|
+
- test/lib/jat/plugins/json_api_preloads/json_api_preloads_test.rb
|
179
|
+
- test/lib/jat/plugins/json_api_preloads/lib/preloads_test.rb
|
183
180
|
- test/lib/jat/plugins/json_api_validate_params/json_api_validate_params_test.rb
|
181
|
+
- test/lib/jat/plugins/lower_camel_case/lower_camel_case_test.rb
|
182
|
+
- test/lib/jat/plugins/maps_cache/maps_cache_test.rb
|
183
|
+
- test/lib/jat/plugins/preloads/preloads_test.rb
|
184
184
|
- test/lib/jat/plugins/simple_api/lib/fields_param_parser_test.rb
|
185
185
|
- test/lib/jat/plugins/simple_api/lib/map_test.rb
|
186
|
+
- test/lib/jat/plugins/simple_api/lib/response_piece_test.rb
|
186
187
|
- test/lib/jat/plugins/simple_api/lib/response_test.rb
|
187
188
|
- test/lib/jat/plugins/simple_api/simple_api_test.rb
|
188
|
-
- test/lib/jat/plugins/simple_api_activerecord/lib/preloads_test.rb
|
189
189
|
- test/lib/jat/plugins/simple_api_activerecord/simple_api_activerecord_test.rb
|
190
|
-
- test/lib/jat/plugins/
|
190
|
+
- test/lib/jat/plugins/simple_api_lower_camel_case/simple_api_lower_camel_case_test.rb
|
191
191
|
- test/lib/jat/plugins/simple_api_maps_cache/simple_api_maps_cache_test.rb
|
192
|
+
- test/lib/jat/plugins/simple_api_preloads/lib/preloads_test.rb
|
193
|
+
- test/lib/jat/plugins/simple_api_preloads/simple_api_preloads_test.rb
|
192
194
|
- test/lib/jat/plugins/simple_api_validate_params/simple_api_validate_params_test.rb
|
193
195
|
- test/lib/jat/plugins/to_str/to_str_test.rb
|
196
|
+
- test/lib/jat/plugins/types/types_test.rb
|
197
|
+
- test/lib/jat/plugins/validate_params/validate_params_test.rb
|
198
|
+
- test/lib/jat/plugins_test.rb
|
194
199
|
- test/lib/jat/utils/enum_deep_dup_test.rb
|
195
200
|
- test/lib/jat/utils/enum_deep_freeze_test.rb
|
196
201
|
- test/lib/jat_test.rb
|
@@ -220,40 +225,51 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
220
225
|
- !ruby/object:Gem::Version
|
221
226
|
version: '0'
|
222
227
|
requirements: []
|
223
|
-
rubygems_version: 3.
|
228
|
+
rubygems_version: 3.3.3
|
224
229
|
signing_key:
|
225
230
|
specification_version: 4
|
226
231
|
summary: JSON API TOOLKIT
|
227
232
|
test_files:
|
228
233
|
- test/lib/jat/attribute_test.rb
|
229
234
|
- test/lib/jat/config_test.rb
|
230
|
-
- test/lib/jat/plugins/
|
231
|
-
- test/lib/jat/plugins/
|
232
|
-
- test/lib/jat/plugins/
|
233
|
-
- test/lib/jat/plugins/
|
234
|
-
- test/lib/jat/plugins/
|
235
|
-
- test/lib/jat/plugins/
|
235
|
+
- test/lib/jat/plugins/activerecord/activerecord_test.rb
|
236
|
+
- test/lib/jat/plugins/base_activerecord_preloads/base_activerecord_preloads_test.rb
|
237
|
+
- test/lib/jat/plugins/base_activerecord_preloads/lib/preloader_test.rb
|
238
|
+
- test/lib/jat/plugins/base_lower_camel_case/base_lower_camel_case_test.rb
|
239
|
+
- test/lib/jat/plugins/base_preloads/base_preloads_test.rb
|
240
|
+
- test/lib/jat/plugins/base_preloads/lib/format_user_preloads_test.rb
|
241
|
+
- test/lib/jat/plugins/base_preloads/lib/preloads_with_path_test.rb
|
236
242
|
- test/lib/jat/plugins/cache/cache_test.rb
|
237
243
|
- test/lib/jat/plugins/json_api/json_api_test.rb
|
238
244
|
- test/lib/jat/plugins/json_api/lib/fields_param_parser_test.rb
|
239
245
|
- test/lib/jat/plugins/json_api/lib/include_param_parser_test.rb
|
240
246
|
- test/lib/jat/plugins/json_api/lib/map_test.rb
|
247
|
+
- test/lib/jat/plugins/json_api/lib/response_piece_test.rb
|
241
248
|
- test/lib/jat/plugins/json_api/lib/response_test.rb
|
242
249
|
- test/lib/jat/plugins/json_api_activerecord/json_api_activerecord_test.rb
|
243
|
-
- test/lib/jat/plugins/
|
244
|
-
- test/lib/jat/plugins/json_api_camel_lower/json_api_camel_lower_test.rb
|
250
|
+
- test/lib/jat/plugins/json_api_lower_camel_case/json_api_lower_camel_case_test.rb
|
245
251
|
- test/lib/jat/plugins/json_api_maps_cache/json_api_maps_cache_test.rb
|
252
|
+
- test/lib/jat/plugins/json_api_preloads/json_api_preloads_test.rb
|
253
|
+
- test/lib/jat/plugins/json_api_preloads/lib/preloads_test.rb
|
246
254
|
- test/lib/jat/plugins/json_api_validate_params/json_api_validate_params_test.rb
|
255
|
+
- test/lib/jat/plugins/lower_camel_case/lower_camel_case_test.rb
|
256
|
+
- test/lib/jat/plugins/maps_cache/maps_cache_test.rb
|
257
|
+
- test/lib/jat/plugins/preloads/preloads_test.rb
|
247
258
|
- test/lib/jat/plugins/simple_api/lib/fields_param_parser_test.rb
|
248
259
|
- test/lib/jat/plugins/simple_api/lib/map_test.rb
|
260
|
+
- test/lib/jat/plugins/simple_api/lib/response_piece_test.rb
|
249
261
|
- test/lib/jat/plugins/simple_api/lib/response_test.rb
|
250
262
|
- test/lib/jat/plugins/simple_api/simple_api_test.rb
|
251
|
-
- test/lib/jat/plugins/simple_api_activerecord/lib/preloads_test.rb
|
252
263
|
- test/lib/jat/plugins/simple_api_activerecord/simple_api_activerecord_test.rb
|
253
|
-
- test/lib/jat/plugins/
|
264
|
+
- test/lib/jat/plugins/simple_api_lower_camel_case/simple_api_lower_camel_case_test.rb
|
254
265
|
- test/lib/jat/plugins/simple_api_maps_cache/simple_api_maps_cache_test.rb
|
266
|
+
- test/lib/jat/plugins/simple_api_preloads/lib/preloads_test.rb
|
267
|
+
- test/lib/jat/plugins/simple_api_preloads/simple_api_preloads_test.rb
|
255
268
|
- test/lib/jat/plugins/simple_api_validate_params/simple_api_validate_params_test.rb
|
256
269
|
- test/lib/jat/plugins/to_str/to_str_test.rb
|
270
|
+
- test/lib/jat/plugins/types/types_test.rb
|
271
|
+
- test/lib/jat/plugins/validate_params/validate_params_test.rb
|
272
|
+
- test/lib/jat/plugins_test.rb
|
257
273
|
- test/lib/jat/utils/enum_deep_dup_test.rb
|
258
274
|
- test/lib/jat/utils/enum_deep_freeze_test.rb
|
259
275
|
- test/lib/jat_test.rb
|