jat 0.0.3 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/jat/attribute.rb +36 -4
- data/lib/jat/plugins/_activerecord_preloads/_activerecord_preloads.rb +7 -3
- data/lib/jat/plugins/_activerecord_preloads/lib/preloader.rb +7 -13
- data/lib/jat/plugins/_lower_camel_case/_lower_camel_case.rb +32 -0
- data/lib/jat/plugins/_preloads/_preloads.rb +8 -2
- data/lib/jat/plugins/cache/cache.rb +9 -5
- data/lib/jat/plugins/json_api/json_api.rb +145 -105
- data/lib/jat/plugins/json_api/lib/fields_param_parser.rb +40 -0
- data/lib/jat/plugins/json_api/lib/include_param_parser.rb +84 -0
- data/lib/jat/plugins/json_api/lib/map.rb +92 -27
- data/lib/jat/plugins/json_api/lib/params/fields/validate.rb +8 -5
- data/lib/jat/plugins/json_api/lib/response.rb +84 -196
- data/lib/jat/plugins/json_api/lib/response_piece.rb +166 -0
- data/lib/jat/plugins/json_api_activerecord/json_api_activerecord.rb +31 -0
- data/lib/jat/plugins/{_json_api_activerecord → json_api_activerecord}/lib/preloads.rb +16 -24
- data/lib/jat/plugins/json_api_lower_camel_case/json_api_lower_camel_case.rb +30 -0
- data/lib/jat/plugins/json_api_maps_cache/json_api_maps_cache.rb +54 -0
- data/lib/jat/plugins/json_api_validate_params/json_api_validate_params.rb +57 -0
- data/lib/jat/plugins/json_api_validate_params/lib/params_error.rb +6 -0
- data/lib/jat/plugins/json_api_validate_params/lib/validate_fields_param.rb +59 -0
- data/lib/jat/plugins/json_api_validate_params/lib/validate_include_param.rb +33 -0
- data/lib/jat/plugins/simple_api/lib/fields_param_parser.rb +97 -0
- data/lib/jat/plugins/simple_api/lib/map.rb +80 -10
- data/lib/jat/plugins/simple_api/lib/response.rb +78 -89
- data/lib/jat/plugins/simple_api/lib/response_piece.rb +84 -0
- data/lib/jat/plugins/simple_api/simple_api.rb +83 -24
- data/lib/jat/plugins/simple_api_activerecord/lib/preloads.rb +55 -0
- data/lib/jat/plugins/simple_api_activerecord/simple_api_activerecord.rb +31 -0
- data/lib/jat/plugins/simple_api_lower_camel_case/simple_api_lower_camel_case.rb +30 -0
- data/lib/jat/plugins/simple_api_maps_cache/simple_api_maps_cache.rb +48 -0
- data/lib/jat/plugins/simple_api_validate_params/lib/fields_error.rb +6 -0
- data/lib/jat/plugins/simple_api_validate_params/lib/validate_fields_param.rb +45 -0
- data/lib/jat/plugins/simple_api_validate_params/simple_api_validate_params.rb +45 -0
- data/lib/jat/plugins/to_str/to_str.rb +10 -4
- data/lib/jat/plugins.rb +3 -16
- data/lib/jat.rb +28 -30
- data/test/lib/jat/attribute_test.rb +15 -5
- data/test/lib/jat/plugins/_activerecord_preloads/_activerecord_preloads_test.rb +34 -15
- data/test/lib/jat/plugins/_activerecord_preloads/lib/preloader_test.rb +10 -24
- data/test/lib/jat/plugins/_camel_lower/_camel_lower_test.rb +26 -0
- data/test/lib/jat/plugins/_preloads/lib/format_user_preloads_test.rb +1 -1
- data/test/lib/jat/plugins/_preloads/lib/preloads_with_path_test.rb +1 -1
- data/test/lib/jat/plugins/cache/cache_test.rb +11 -11
- data/test/lib/jat/plugins/json_api/json_api_test.rb +63 -47
- data/test/lib/jat/plugins/json_api/lib/{params/fields_test.rb → fields_param_parser_test.rb} +7 -6
- data/test/lib/jat/plugins/json_api/lib/{params/include_test.rb → include_param_parser_test.rb} +4 -4
- data/test/lib/jat/plugins/json_api/lib/map_test.rb +150 -79
- data/test/lib/jat/plugins/json_api/lib/response_test.rb +32 -32
- data/test/lib/jat/plugins/{_json_api_activerecord/_json_api_activerecord_test.rb → json_api_activerecord/json_api_activerecord_test.rb} +14 -5
- data/test/lib/jat/plugins/{_json_api_activerecord → json_api_activerecord}/lib/preloads_test.rb +11 -10
- data/test/lib/jat/plugins/json_api_camel_lower/json_api_camel_lower_test.rb +79 -0
- data/test/lib/jat/plugins/json_api_maps_cache/json_api_maps_cache_test.rb +107 -0
- data/test/lib/jat/plugins/json_api_validate_params/json_api_validate_params_test.rb +84 -0
- data/test/lib/jat/plugins/simple_api/lib/{params/parse_test.rb → fields_param_parser_test.rb} +10 -4
- data/test/lib/jat/plugins/simple_api/lib/map_test.rb +111 -34
- data/test/lib/jat/plugins/simple_api/lib/response_test.rb +80 -74
- data/test/lib/jat/plugins/simple_api/simple_api_test.rb +91 -25
- data/test/lib/jat/plugins/simple_api_activerecord/lib/preloads_test.rb +135 -0
- data/test/lib/jat/plugins/simple_api_activerecord/simple_api_activerecord_test.rb +38 -0
- data/test/lib/jat/plugins/simple_api_camel_lower/simple_api_camel_lower_test.rb +48 -0
- data/test/lib/jat/plugins/simple_api_maps_cache/simple_api_maps_cache_test.rb +95 -0
- data/test/lib/jat/plugins/simple_api_validate_params/simple_api_validate_params_test.rb +89 -0
- data/test/lib/jat/plugins/to_str/to_str_test.rb +3 -3
- data/test/lib/jat_test.rb +47 -24
- data/test/lib/plugin_test.rb +3 -3
- data/test/test_helper.rb +0 -3
- data/test/test_plugin.rb +9 -12
- metadata +60 -71
- data/CHANGELOG.md +0 -7
- data/README.md +0 -21
- data/jat.gemspec +0 -37
- data/lib/jat/plugins/_json_api_activerecord/_json_api_activerecord.rb +0 -22
- data/lib/jat/plugins/camel_lower/camel_lower.rb +0 -18
- data/lib/jat/plugins/json_api/lib/construct_traversal_map.rb +0 -91
- data/lib/jat/plugins/json_api/lib/presenters/document_links_presenter.rb +0 -48
- data/lib/jat/plugins/json_api/lib/presenters/document_meta_presenter.rb +0 -48
- data/lib/jat/plugins/json_api/lib/presenters/jsonapi_presenter.rb +0 -48
- data/lib/jat/plugins/json_api/lib/presenters/links_presenter.rb +0 -48
- data/lib/jat/plugins/json_api/lib/presenters/meta_presenter.rb +0 -48
- data/lib/jat/plugins/json_api/lib/presenters/relationship_links_presenter.rb +0 -53
- data/lib/jat/plugins/json_api/lib/presenters/relationship_meta_presenter.rb +0 -53
- data/lib/jat/plugins/json_api/lib/traversal_map.rb +0 -34
- data/lib/jat/plugins/simple_api/lib/construct_traversal_map.rb +0 -45
- data/lib/jat/plugins/simple_api/lib/params/parse.rb +0 -68
- data/lib/jat/presenter.rb +0 -51
- data/test/lib/jat/plugins/camel_lower/camel_lower_test.rb +0 -78
- data/test/lib/jat/plugins/json_api/lib/construct_traversal_map_test.rb +0 -119
- data/test/lib/jat/plugins/json_api/lib/params/fields/parse_test.rb +0 -24
- data/test/lib/jat/plugins/json_api/lib/params/fields/validate_test.rb +0 -47
- data/test/lib/jat/plugins/json_api/lib/params/include/parse_test.rb +0 -46
- data/test/lib/jat/plugins/json_api/lib/params/include/validate_test.rb +0 -51
- data/test/lib/jat/plugins/json_api/lib/presenters/document_links_presenter_test.rb +0 -69
- data/test/lib/jat/plugins/json_api/lib/presenters/document_meta_presenter_test.rb +0 -69
- data/test/lib/jat/plugins/json_api/lib/presenters/jsonapi_presenter_test.rb +0 -69
- data/test/lib/jat/plugins/json_api/lib/presenters/links_presenter_test.rb +0 -69
- data/test/lib/jat/plugins/json_api/lib/presenters/meta_presenter_test.rb +0 -69
- data/test/lib/jat/plugins/json_api/lib/presenters/relationship_links_presenter_test.rb +0 -75
- data/test/lib/jat/plugins/json_api/lib/presenters/relationship_meta_presenter_test.rb +0 -75
- data/test/lib/jat/plugins/json_api/lib/traversal_map_test.rb +0 -58
- data/test/lib/jat/plugins/simple_api/lib/construct_traversal_map_test.rb +0 -100
- data/test/lib/jat/presenter_test.rb +0 -61
@@ -1,51 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "test_helper"
|
4
|
-
|
5
|
-
describe "Jat::Plugins::JsonApi::Params::Include::Validate" do
|
6
|
-
before { Jat::Plugins.load_plugin(:json_api) }
|
7
|
-
|
8
|
-
let(:described_class) { Jat::Plugins::JsonApi::Params::Include::Validate }
|
9
|
-
|
10
|
-
let(:base_class) { Class.new(Jat) { plugin :json_api } }
|
11
|
-
let(:a_serializer) { Class.new(base_class) }
|
12
|
-
let(:b_serializer) { Class.new(base_class) }
|
13
|
-
|
14
|
-
before do
|
15
|
-
ser = a_serializer
|
16
|
-
ser.type :a
|
17
|
-
ser.attribute :a1
|
18
|
-
ser.relationship :a2, serializer: b_serializer
|
19
|
-
ser.relationship :a3, serializer: b_serializer
|
20
|
-
|
21
|
-
ser = b_serializer
|
22
|
-
ser.type :b
|
23
|
-
ser.attribute :b1
|
24
|
-
ser.relationship :b2, serializer: a_serializer
|
25
|
-
end
|
26
|
-
|
27
|
-
it "does not raises error when all `include` values are valid" do
|
28
|
-
include_param = {a2: {b2: {a2: {b2: {a2: {}}}}}, a3: {b2: {a2: {b2: {a2: {}}}}}}
|
29
|
-
assert described_class.call(a_serializer, include_param)
|
30
|
-
end
|
31
|
-
|
32
|
-
it "raises error when some key is invalid" do
|
33
|
-
error = assert_raises(Jat::Error) { described_class.call(a_serializer, foo: {}) }
|
34
|
-
assert_equal "#{a_serializer} has no `foo` relationship", error.message
|
35
|
-
end
|
36
|
-
|
37
|
-
it "raises error when some children key is invalid" do
|
38
|
-
error = assert_raises(Jat::Error) { described_class.call(a_serializer, a2: {foo: {}}) }
|
39
|
-
assert_equal "#{b_serializer} has no `foo` relationship", error.message
|
40
|
-
end
|
41
|
-
|
42
|
-
it "raises error when trying to include attribute, not relationship" do
|
43
|
-
error = assert_raises(Jat::Error) { described_class.call(a_serializer, a1: {}) }
|
44
|
-
assert_equal "#{a_serializer} has no `a1` relationship", error.message
|
45
|
-
end
|
46
|
-
|
47
|
-
it "raises error when trying to include not existing nested attribute" do
|
48
|
-
error = assert_raises(Jat::Error) { described_class.call(a_serializer, a2: {b1: {}}) }
|
49
|
-
assert_equal "#{b_serializer} has no `b1` relationship", error.message
|
50
|
-
end
|
51
|
-
end
|
@@ -1,69 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "test_helper"
|
4
|
-
|
5
|
-
describe "Jat::Presenters::DocumentLinksPresenter" do
|
6
|
-
before { Jat::Plugins.load_plugin(:json_api) }
|
7
|
-
|
8
|
-
let(:jat_class) { Class.new(Jat) { plugin :json_api } }
|
9
|
-
let(:presenter_class) { jat_class::DocumentLinksPresenter }
|
10
|
-
|
11
|
-
describe ".jat_class=" do
|
12
|
-
it "assigns @jat_class" do
|
13
|
-
presenter_class.jat_class = :foo
|
14
|
-
assert_equal :foo, presenter_class.instance_variable_get(:@jat_class)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
describe ".jat_class" do
|
19
|
-
it "returns self @jat_class" do
|
20
|
-
assert_same jat_class, presenter_class.instance_variable_get(:@jat_class)
|
21
|
-
assert_same jat_class, presenter_class.jat_class
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
describe ".inspect" do
|
26
|
-
it "returns self name" do
|
27
|
-
assert_equal "#{jat_class}::Presenters::DocumentLinksPresenter", presenter_class.inspect
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe ".add_method" do
|
32
|
-
let(:presenter) { presenter_class.new("OBJECT", "CONTEXT") }
|
33
|
-
|
34
|
-
it "adds method by providing block without variables" do
|
35
|
-
presenter_class.add_method(:foo, proc { [object, context] })
|
36
|
-
assert_equal %w[OBJECT CONTEXT], presenter.foo
|
37
|
-
end
|
38
|
-
|
39
|
-
it "adds method by providing block with one variables" do
|
40
|
-
presenter_class.add_method(:foo, proc { |obj| [obj, object, context] })
|
41
|
-
assert_equal %w[OBJECT OBJECT CONTEXT], presenter.foo
|
42
|
-
end
|
43
|
-
|
44
|
-
it "adds method by providing block with two variables" do
|
45
|
-
presenter_class.add_method(:foo, proc { |obj, ctx| [obj, ctx, object, context] })
|
46
|
-
assert_equal %w[OBJECT CONTEXT OBJECT CONTEXT], presenter.foo
|
47
|
-
end
|
48
|
-
|
49
|
-
it "raises error when block has more than two variables" do
|
50
|
-
error = assert_raises(Jat::Error) { presenter_class.add_method(:foo, proc { |_a, _b, _c| }) }
|
51
|
-
assert_equal "Invalid block arguments count", error.message
|
52
|
-
end
|
53
|
-
|
54
|
-
it "redefines_method" do
|
55
|
-
presenter_class.add_method(:foo, proc { "OLD" })
|
56
|
-
presenter_class.add_method(:foo, proc { "NEW" })
|
57
|
-
assert_equal "NEW", presenter.foo
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
describe "#initialize" do
|
62
|
-
it "initializes object presenter with provided object and context" do
|
63
|
-
presenter = presenter_class.new("OBJ", "CTX")
|
64
|
-
|
65
|
-
assert_equal "OBJ", presenter.object
|
66
|
-
assert_equal "CTX", presenter.context
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
@@ -1,69 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "test_helper"
|
4
|
-
|
5
|
-
describe "Jat::Presenters::DocumentMetaPresenter" do
|
6
|
-
before { Jat::Plugins.load_plugin(:json_api) }
|
7
|
-
|
8
|
-
let(:jat_class) { Class.new(Jat) { plugin :json_api } }
|
9
|
-
let(:presenter_class) { jat_class::DocumentMetaPresenter }
|
10
|
-
|
11
|
-
describe ".jat_class=" do
|
12
|
-
it "assigns @jat_class" do
|
13
|
-
presenter_class.jat_class = :foo
|
14
|
-
assert_equal :foo, presenter_class.instance_variable_get(:@jat_class)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
describe ".jat_class" do
|
19
|
-
it "returns self @jat_class" do
|
20
|
-
assert_same jat_class, presenter_class.instance_variable_get(:@jat_class)
|
21
|
-
assert_same jat_class, presenter_class.jat_class
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
describe ".inspect" do
|
26
|
-
it "returns self name" do
|
27
|
-
assert_equal "#{jat_class}::Presenters::DocumentMetaPresenter", presenter_class.inspect
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe ".add_method" do
|
32
|
-
let(:presenter) { presenter_class.new("OBJECT", "CONTEXT") }
|
33
|
-
|
34
|
-
it "adds method by providing block without variables" do
|
35
|
-
presenter_class.add_method(:foo, proc { [object, context] })
|
36
|
-
assert_equal %w[OBJECT CONTEXT], presenter.foo
|
37
|
-
end
|
38
|
-
|
39
|
-
it "adds method by providing block with one variables" do
|
40
|
-
presenter_class.add_method(:foo, proc { |obj| [obj, object, context] })
|
41
|
-
assert_equal %w[OBJECT OBJECT CONTEXT], presenter.foo
|
42
|
-
end
|
43
|
-
|
44
|
-
it "adds method by providing block with two variables" do
|
45
|
-
presenter_class.add_method(:foo, proc { |obj, ctx| [obj, ctx, object, context] })
|
46
|
-
assert_equal %w[OBJECT CONTEXT OBJECT CONTEXT], presenter.foo
|
47
|
-
end
|
48
|
-
|
49
|
-
it "raises error when block has more than two variables" do
|
50
|
-
error = assert_raises(Jat::Error) { presenter_class.add_method(:foo, proc { |_a, _b, _c| }) }
|
51
|
-
assert_equal "Invalid block arguments count", error.message
|
52
|
-
end
|
53
|
-
|
54
|
-
it "redefines_method" do
|
55
|
-
presenter_class.add_method(:foo, proc { "OLD" })
|
56
|
-
presenter_class.add_method(:foo, proc { "NEW" })
|
57
|
-
assert_equal "NEW", presenter.foo
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
describe "#initialize" do
|
62
|
-
it "initializes object presenter with provided object and context" do
|
63
|
-
presenter = presenter_class.new("OBJ", "CTX")
|
64
|
-
|
65
|
-
assert_equal "OBJ", presenter.object
|
66
|
-
assert_equal "CTX", presenter.context
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
@@ -1,69 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "test_helper"
|
4
|
-
|
5
|
-
describe "Jat::Presenters::JsonapiPresenter" do
|
6
|
-
before { Jat::Plugins.load_plugin(:json_api) }
|
7
|
-
|
8
|
-
let(:jat_class) { Class.new(Jat) { plugin :json_api } }
|
9
|
-
let(:presenter_class) { jat_class::JsonapiPresenter }
|
10
|
-
|
11
|
-
describe ".jat_class=" do
|
12
|
-
it "assigns @jat_class" do
|
13
|
-
presenter_class.jat_class = :foo
|
14
|
-
assert_equal :foo, presenter_class.instance_variable_get(:@jat_class)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
describe ".jat_class" do
|
19
|
-
it "returns self @jat_class" do
|
20
|
-
assert_same jat_class, presenter_class.instance_variable_get(:@jat_class)
|
21
|
-
assert_same jat_class, presenter_class.jat_class
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
describe ".inspect" do
|
26
|
-
it "returns self name" do
|
27
|
-
assert_equal "#{jat_class}::Presenters::JsonapiPresenter", presenter_class.inspect
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe ".add_method" do
|
32
|
-
let(:presenter) { presenter_class.new("OBJECT", "CONTEXT") }
|
33
|
-
|
34
|
-
it "adds method by providing block without variables" do
|
35
|
-
presenter_class.add_method(:foo, proc { [object, context] })
|
36
|
-
assert_equal %w[OBJECT CONTEXT], presenter.foo
|
37
|
-
end
|
38
|
-
|
39
|
-
it "adds method by providing block with one variables" do
|
40
|
-
presenter_class.add_method(:foo, proc { |obj| [obj, object, context] })
|
41
|
-
assert_equal %w[OBJECT OBJECT CONTEXT], presenter.foo
|
42
|
-
end
|
43
|
-
|
44
|
-
it "adds method by providing block with two variables" do
|
45
|
-
presenter_class.add_method(:foo, proc { |obj, ctx| [obj, ctx, object, context] })
|
46
|
-
assert_equal %w[OBJECT CONTEXT OBJECT CONTEXT], presenter.foo
|
47
|
-
end
|
48
|
-
|
49
|
-
it "raises error when block has more than two variables" do
|
50
|
-
error = assert_raises(Jat::Error) { presenter_class.add_method(:foo, proc { |_a, _b, _c| }) }
|
51
|
-
assert_equal "Invalid block arguments count", error.message
|
52
|
-
end
|
53
|
-
|
54
|
-
it "redefines_method" do
|
55
|
-
presenter_class.add_method(:foo, proc { "OLD" })
|
56
|
-
presenter_class.add_method(:foo, proc { "NEW" })
|
57
|
-
assert_equal "NEW", presenter.foo
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
describe "#initialize" do
|
62
|
-
it "initializes object presenter with provided object and context" do
|
63
|
-
presenter = presenter_class.new("OBJ", "CTX")
|
64
|
-
|
65
|
-
assert_equal "OBJ", presenter.object
|
66
|
-
assert_equal "CTX", presenter.context
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
@@ -1,69 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "test_helper"
|
4
|
-
|
5
|
-
describe "Jat::Presenters::LinksPresenter" do
|
6
|
-
before { Jat::Plugins.load_plugin(:json_api) }
|
7
|
-
|
8
|
-
let(:jat_class) { Class.new(Jat) { plugin :json_api } }
|
9
|
-
let(:presenter_class) { jat_class::LinksPresenter }
|
10
|
-
|
11
|
-
describe ".jat_class=" do
|
12
|
-
it "assigns @jat_class" do
|
13
|
-
presenter_class.jat_class = :foo
|
14
|
-
assert_equal :foo, presenter_class.instance_variable_get(:@jat_class)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
describe ".jat_class" do
|
19
|
-
it "returns self @jat_class" do
|
20
|
-
assert_same jat_class, presenter_class.instance_variable_get(:@jat_class)
|
21
|
-
assert_same jat_class, presenter_class.jat_class
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
describe ".inspect" do
|
26
|
-
it "returns self name" do
|
27
|
-
assert_equal "#{jat_class}::Presenters::LinksPresenter", presenter_class.inspect
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe ".add_method" do
|
32
|
-
let(:presenter) { presenter_class.new("OBJECT", "CONTEXT") }
|
33
|
-
|
34
|
-
it "adds method by providing block without variables" do
|
35
|
-
presenter_class.add_method(:foo, proc { [object, context] })
|
36
|
-
assert_equal %w[OBJECT CONTEXT], presenter.foo
|
37
|
-
end
|
38
|
-
|
39
|
-
it "adds method by providing block with one variables" do
|
40
|
-
presenter_class.add_method(:foo, proc { |obj| [obj, object, context] })
|
41
|
-
assert_equal %w[OBJECT OBJECT CONTEXT], presenter.foo
|
42
|
-
end
|
43
|
-
|
44
|
-
it "adds method by providing block with two variables" do
|
45
|
-
presenter_class.add_method(:foo, proc { |obj, ctx| [obj, ctx, object, context] })
|
46
|
-
assert_equal %w[OBJECT CONTEXT OBJECT CONTEXT], presenter.foo
|
47
|
-
end
|
48
|
-
|
49
|
-
it "raises error when block has more than two variables" do
|
50
|
-
error = assert_raises(Jat::Error) { presenter_class.add_method(:foo, proc { |_a, _b, _c| }) }
|
51
|
-
assert_equal "Invalid block arguments count", error.message
|
52
|
-
end
|
53
|
-
|
54
|
-
it "redefines_method" do
|
55
|
-
presenter_class.add_method(:foo, proc { "OLD" })
|
56
|
-
presenter_class.add_method(:foo, proc { "NEW" })
|
57
|
-
assert_equal "NEW", presenter.foo
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
describe "#initialize" do
|
62
|
-
it "initializes object presenter with provided object and context" do
|
63
|
-
presenter = presenter_class.new("OBJ", "CTX")
|
64
|
-
|
65
|
-
assert_equal "OBJ", presenter.object
|
66
|
-
assert_equal "CTX", presenter.context
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
@@ -1,69 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "test_helper"
|
4
|
-
|
5
|
-
describe "Jat::Presenters::MetaPresenter" do
|
6
|
-
before { Jat::Plugins.load_plugin(:json_api) }
|
7
|
-
|
8
|
-
let(:jat_class) { Class.new(Jat) { plugin :json_api } }
|
9
|
-
let(:presenter_class) { jat_class::MetaPresenter }
|
10
|
-
|
11
|
-
describe ".jat_class=" do
|
12
|
-
it "assigns @jat_class" do
|
13
|
-
presenter_class.jat_class = :foo
|
14
|
-
assert_equal :foo, presenter_class.instance_variable_get(:@jat_class)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
describe ".jat_class" do
|
19
|
-
it "returns self @jat_class" do
|
20
|
-
assert_same jat_class, presenter_class.instance_variable_get(:@jat_class)
|
21
|
-
assert_same jat_class, presenter_class.jat_class
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
describe ".inspect" do
|
26
|
-
it "returns self name" do
|
27
|
-
assert_equal "#{jat_class}::Presenters::MetaPresenter", presenter_class.inspect
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe ".add_method" do
|
32
|
-
let(:presenter) { presenter_class.new("OBJECT", "CONTEXT") }
|
33
|
-
|
34
|
-
it "adds method by providing block without variables" do
|
35
|
-
presenter_class.add_method(:foo, proc { [object, context] })
|
36
|
-
assert_equal %w[OBJECT CONTEXT], presenter.foo
|
37
|
-
end
|
38
|
-
|
39
|
-
it "adds method by providing block with one variables" do
|
40
|
-
presenter_class.add_method(:foo, proc { |obj| [obj, object, context] })
|
41
|
-
assert_equal %w[OBJECT OBJECT CONTEXT], presenter.foo
|
42
|
-
end
|
43
|
-
|
44
|
-
it "adds method by providing block with two variables" do
|
45
|
-
presenter_class.add_method(:foo, proc { |obj, ctx| [obj, ctx, object, context] })
|
46
|
-
assert_equal %w[OBJECT CONTEXT OBJECT CONTEXT], presenter.foo
|
47
|
-
end
|
48
|
-
|
49
|
-
it "raises error when block has more than two variables" do
|
50
|
-
error = assert_raises(Jat::Error) { presenter_class.add_method(:foo, proc { |_a, _b, _c| }) }
|
51
|
-
assert_equal "Invalid block arguments count", error.message
|
52
|
-
end
|
53
|
-
|
54
|
-
it "redefines_method" do
|
55
|
-
presenter_class.add_method(:foo, proc { "OLD" })
|
56
|
-
presenter_class.add_method(:foo, proc { "NEW" })
|
57
|
-
assert_equal "NEW", presenter.foo
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
describe "#initialize" do
|
62
|
-
it "initializes object presenter with provided object and context" do
|
63
|
-
presenter = presenter_class.new("OBJ", "CTX")
|
64
|
-
|
65
|
-
assert_equal "OBJ", presenter.object
|
66
|
-
assert_equal "CTX", presenter.context
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
@@ -1,75 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "test_helper"
|
4
|
-
|
5
|
-
describe "Jat::Presenters::RelationshipLinksPresenter" do
|
6
|
-
before { Jat::Plugins.load_plugin(:json_api) }
|
7
|
-
|
8
|
-
let(:jat_class) { Class.new(Jat) { plugin :json_api } }
|
9
|
-
let(:presenter_class) { jat_class::RelationshipLinksPresenter }
|
10
|
-
|
11
|
-
describe ".jat_class=" do
|
12
|
-
it "assigns @jat_class" do
|
13
|
-
presenter_class.jat_class = :foo
|
14
|
-
assert_equal :foo, presenter_class.instance_variable_get(:@jat_class)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
describe ".jat_class" do
|
19
|
-
it "returns self @jat_class" do
|
20
|
-
assert_same jat_class, presenter_class.instance_variable_get(:@jat_class)
|
21
|
-
assert_same jat_class, presenter_class.jat_class
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
describe ".inspect" do
|
26
|
-
it "returns self name" do
|
27
|
-
assert_equal "#{jat_class}::Presenters::RelationshipLinksPresenter", presenter_class.inspect
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe ".add_method" do
|
32
|
-
let(:presenter) { presenter_class.new("PARENT_OBJECT", "OBJECT", "CONTEXT") }
|
33
|
-
|
34
|
-
it "adds method by providing block without variables" do
|
35
|
-
presenter_class.add_method(:foo, proc { [parent_object, object, context] })
|
36
|
-
assert_equal %w[PARENT_OBJECT OBJECT CONTEXT], presenter.foo
|
37
|
-
end
|
38
|
-
|
39
|
-
it "adds method by providing block with one variables" do
|
40
|
-
presenter_class.add_method(:foo, proc { |parent_obj| [parent_obj, parent_object, object, context] })
|
41
|
-
assert_equal %w[PARENT_OBJECT PARENT_OBJECT OBJECT CONTEXT], presenter.foo
|
42
|
-
end
|
43
|
-
|
44
|
-
it "adds method by providing block with two variables" do
|
45
|
-
presenter_class.add_method(:foo, proc { |parent_obj, obj| [parent_obj, parent_object, obj, object, context] })
|
46
|
-
assert_equal %w[PARENT_OBJECT PARENT_OBJECT OBJECT OBJECT CONTEXT], presenter.foo
|
47
|
-
end
|
48
|
-
|
49
|
-
it "adds method by providing block with three variables" do
|
50
|
-
presenter_class.add_method(:foo, proc { |parent_obj, obj, ctx| [parent_obj, parent_object, obj, object, ctx, context] })
|
51
|
-
assert_equal %w[PARENT_OBJECT PARENT_OBJECT OBJECT OBJECT CONTEXT CONTEXT], presenter.foo
|
52
|
-
end
|
53
|
-
|
54
|
-
it "raises error when block has more than three variables" do
|
55
|
-
error = assert_raises(Jat::Error) { presenter_class.add_method(:foo, proc { |_a, _b, _c, _d| }) }
|
56
|
-
assert_equal "Invalid block arguments count", error.message
|
57
|
-
end
|
58
|
-
|
59
|
-
it "redefines_method" do
|
60
|
-
presenter_class.add_method(:foo, proc { "OLD" })
|
61
|
-
presenter_class.add_method(:foo, proc { "NEW" })
|
62
|
-
assert_equal "NEW", presenter.foo
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
describe "#initialize" do
|
67
|
-
it "initializes object presenter with provided object and context" do
|
68
|
-
presenter = presenter_class.new("PARENT", "OBJ", "CTX")
|
69
|
-
|
70
|
-
assert_equal "PARENT", presenter.parent_object
|
71
|
-
assert_equal "OBJ", presenter.object
|
72
|
-
assert_equal "CTX", presenter.context
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
@@ -1,75 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "test_helper"
|
4
|
-
|
5
|
-
describe "Jat::Presenters::RelationshipMetaPresenter" do
|
6
|
-
before { Jat::Plugins.load_plugin(:json_api) }
|
7
|
-
|
8
|
-
let(:jat_class) { Class.new(Jat) { plugin :json_api } }
|
9
|
-
let(:presenter_class) { jat_class::RelationshipMetaPresenter }
|
10
|
-
|
11
|
-
describe ".jat_class=" do
|
12
|
-
it "assigns @jat_class" do
|
13
|
-
presenter_class.jat_class = :foo
|
14
|
-
assert_equal :foo, presenter_class.instance_variable_get(:@jat_class)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
describe ".jat_class" do
|
19
|
-
it "returns self @jat_class" do
|
20
|
-
assert_same jat_class, presenter_class.instance_variable_get(:@jat_class)
|
21
|
-
assert_same jat_class, presenter_class.jat_class
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
describe ".inspect" do
|
26
|
-
it "returns self name" do
|
27
|
-
assert_equal "#{jat_class}::Presenters::RelationshipMetaPresenter", presenter_class.inspect
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe ".add_method" do
|
32
|
-
let(:presenter) { presenter_class.new("PARENT_OBJECT", "OBJECT", "CONTEXT") }
|
33
|
-
|
34
|
-
it "adds method by providing block without variables" do
|
35
|
-
presenter_class.add_method(:foo, proc { [parent_object, object, context] })
|
36
|
-
assert_equal %w[PARENT_OBJECT OBJECT CONTEXT], presenter.foo
|
37
|
-
end
|
38
|
-
|
39
|
-
it "adds method by providing block with one variables" do
|
40
|
-
presenter_class.add_method(:foo, proc { |parent_obj| [parent_obj, parent_object, object, context] })
|
41
|
-
assert_equal %w[PARENT_OBJECT PARENT_OBJECT OBJECT CONTEXT], presenter.foo
|
42
|
-
end
|
43
|
-
|
44
|
-
it "adds method by providing block with two variables" do
|
45
|
-
presenter_class.add_method(:foo, proc { |parent_obj, obj| [parent_obj, parent_object, obj, object, context] })
|
46
|
-
assert_equal %w[PARENT_OBJECT PARENT_OBJECT OBJECT OBJECT CONTEXT], presenter.foo
|
47
|
-
end
|
48
|
-
|
49
|
-
it "adds method by providing block with three variables" do
|
50
|
-
presenter_class.add_method(:foo, proc { |parent_obj, obj, ctx| [parent_obj, parent_object, obj, object, ctx, context] })
|
51
|
-
assert_equal %w[PARENT_OBJECT PARENT_OBJECT OBJECT OBJECT CONTEXT CONTEXT], presenter.foo
|
52
|
-
end
|
53
|
-
|
54
|
-
it "raises error when block has more than three variables" do
|
55
|
-
error = assert_raises(Jat::Error) { presenter_class.add_method(:foo, proc { |_a, _b, _c, _d| }) }
|
56
|
-
assert_equal "Invalid block arguments count", error.message
|
57
|
-
end
|
58
|
-
|
59
|
-
it "redefines_method" do
|
60
|
-
presenter_class.add_method(:foo, proc { "OLD" })
|
61
|
-
presenter_class.add_method(:foo, proc { "NEW" })
|
62
|
-
assert_equal "NEW", presenter.foo
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
describe "#initialize" do
|
67
|
-
it "initializes object presenter with provided object and context" do
|
68
|
-
presenter = presenter_class.new("PARENT", "OBJ", "CTX")
|
69
|
-
|
70
|
-
assert_equal "PARENT", presenter.parent_object
|
71
|
-
assert_equal "OBJ", presenter.object
|
72
|
-
assert_equal "CTX", presenter.context
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
@@ -1,58 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "test_helper"
|
4
|
-
|
5
|
-
describe "Jat::Plugins::JsonApi::TraversalMap" do
|
6
|
-
let(:jat_class) do
|
7
|
-
new_class = Class.new(Jat)
|
8
|
-
new_class.attribute :foo, exposed: true
|
9
|
-
new_class.attribute :bar, exposed: false
|
10
|
-
new_class
|
11
|
-
end
|
12
|
-
|
13
|
-
let(:jat) do
|
14
|
-
jat_class.new("JAT", params: {fields: {jat: "bar"}})
|
15
|
-
end
|
16
|
-
|
17
|
-
before do
|
18
|
-
jat_class.plugin :json_api
|
19
|
-
jat_class.type :jat
|
20
|
-
end
|
21
|
-
|
22
|
-
describe "#jat" do
|
23
|
-
it "returns initialization value" do
|
24
|
-
map = Jat::Plugins::JsonApi::TraversalMap.new(jat)
|
25
|
-
assert_same jat, map.jat
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
describe "#exposed" do
|
30
|
-
it "returns memorized exposed map" do
|
31
|
-
map = Jat::Plugins::JsonApi::TraversalMap.new(jat)
|
32
|
-
expected_map_hash = Jat::Plugins::JsonApi::ConstructTraversalMap.new(jat_class, :exposed).to_h
|
33
|
-
|
34
|
-
assert_equal expected_map_hash, map.exposed
|
35
|
-
assert_same map.exposed, map.exposed
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
describe "#full" do
|
40
|
-
it "returns memorized full map" do
|
41
|
-
map = Jat::Plugins::JsonApi::TraversalMap.new(jat)
|
42
|
-
expected_map_hash = Jat::Plugins::JsonApi::ConstructTraversalMap.new(jat_class, :all).to_h
|
43
|
-
|
44
|
-
assert_equal expected_map_hash, map.full
|
45
|
-
assert_same map.full, map.full
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
describe "#current" do
|
50
|
-
it "returns memorized current map" do
|
51
|
-
map = Jat::Plugins::JsonApi::TraversalMap.new(jat)
|
52
|
-
expected_map_hash = Jat::Plugins::JsonApi::Map.call(jat)
|
53
|
-
|
54
|
-
assert_equal expected_map_hash, map.current
|
55
|
-
assert_same map.current, map.current
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|