faceter 0.0.1

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.
Files changed (125) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +2 -0
  3. data/.gitignore +9 -0
  4. data/.metrics +9 -0
  5. data/.rspec +2 -0
  6. data/.rubocop.yml +2 -0
  7. data/.travis.yml +18 -0
  8. data/.yardopts +3 -0
  9. data/CHANGELOG.md +3 -0
  10. data/Gemfile +9 -0
  11. data/Guardfile +10 -0
  12. data/LICENSE +21 -0
  13. data/README.md +295 -0
  14. data/Rakefile +37 -0
  15. data/benchmark/data.json +1 -0
  16. data/benchmark/faceter.rb +73 -0
  17. data/benchmark/rom.rb +85 -0
  18. data/benchmark/run.rb +54 -0
  19. data/config/metrics/STYLEGUIDE +230 -0
  20. data/config/metrics/cane.yml +5 -0
  21. data/config/metrics/churn.yml +6 -0
  22. data/config/metrics/flay.yml +2 -0
  23. data/config/metrics/metric_fu.yml +14 -0
  24. data/config/metrics/reek.yml +1 -0
  25. data/config/metrics/roodi.yml +24 -0
  26. data/config/metrics/rubocop.yml +75 -0
  27. data/config/metrics/saikuro.yml +3 -0
  28. data/config/metrics/simplecov.yml +6 -0
  29. data/config/metrics/yardstick.yml +37 -0
  30. data/faceter.gemspec +29 -0
  31. data/lib/faceter.rb +54 -0
  32. data/lib/faceter/coercers.rb +68 -0
  33. data/lib/faceter/functions.rb +30 -0
  34. data/lib/faceter/functions/add_prefix.rb +25 -0
  35. data/lib/faceter/functions/claster.rb +27 -0
  36. data/lib/faceter/functions/clean.rb +27 -0
  37. data/lib/faceter/functions/drop_prefix.rb +29 -0
  38. data/lib/faceter/functions/exclude.rb +27 -0
  39. data/lib/faceter/functions/group.rb +41 -0
  40. data/lib/faceter/functions/keep_symbol.rb +27 -0
  41. data/lib/faceter/functions/split.rb +28 -0
  42. data/lib/faceter/functions/ungroup.rb +31 -0
  43. data/lib/faceter/functions/unwrap.rb +32 -0
  44. data/lib/faceter/functions/wrap.rb +32 -0
  45. data/lib/faceter/mapper.rb +38 -0
  46. data/lib/faceter/nodes/add_prefix.rb +21 -0
  47. data/lib/faceter/nodes/change_prefix.rb +51 -0
  48. data/lib/faceter/nodes/create.rb +43 -0
  49. data/lib/faceter/nodes/exclude.rb +25 -0
  50. data/lib/faceter/nodes/field.rb +25 -0
  51. data/lib/faceter/nodes/fold.rb +25 -0
  52. data/lib/faceter/nodes/group.rb +26 -0
  53. data/lib/faceter/nodes/list.rb +25 -0
  54. data/lib/faceter/nodes/remove_prefix.rb +21 -0
  55. data/lib/faceter/nodes/rename.rb +25 -0
  56. data/lib/faceter/nodes/stringify_keys.rb +26 -0
  57. data/lib/faceter/nodes/symbolize_keys.rb +26 -0
  58. data/lib/faceter/nodes/unfold.rb +25 -0
  59. data/lib/faceter/nodes/ungroup.rb +26 -0
  60. data/lib/faceter/nodes/unwrap.rb +26 -0
  61. data/lib/faceter/nodes/wrap.rb +26 -0
  62. data/lib/faceter/rules/append_nested.rb +28 -0
  63. data/lib/faceter/rules/merge_branches.rb +41 -0
  64. data/lib/faceter/rules/merge_excludes.rb +29 -0
  65. data/lib/faceter/rules/merge_renames.rb +27 -0
  66. data/lib/faceter/rules/order_fields.rb +27 -0
  67. data/lib/faceter/rules/prepend_nested.rb +51 -0
  68. data/lib/faceter/version.rb +11 -0
  69. data/spec/integration/commands/add_prefix_spec.rb +37 -0
  70. data/spec/integration/commands/create_spec.rb +33 -0
  71. data/spec/integration/commands/exclude_spec.rb +55 -0
  72. data/spec/integration/commands/fold_spec.rb +41 -0
  73. data/spec/integration/commands/group_spec.rb +64 -0
  74. data/spec/integration/commands/remove_prefix_spec.rb +63 -0
  75. data/spec/integration/commands/rename_spec.rb +45 -0
  76. data/spec/integration/commands/stringify_keys_spec.rb +65 -0
  77. data/spec/integration/commands/symbolize_keys_spec.rb +49 -0
  78. data/spec/integration/commands/unfold_spec.rb +41 -0
  79. data/spec/integration/commands/ungroup_spec.rb +64 -0
  80. data/spec/integration/commands/unwrap_spec.rb +51 -0
  81. data/spec/integration/commands/wrap_spec.rb +51 -0
  82. data/spec/integration/rom_spec.rb +39 -0
  83. data/spec/spec_helper.rb +25 -0
  84. data/spec/unit/coercers/create_spec.rb +16 -0
  85. data/spec/unit/coercers/exclude_spec.rb +31 -0
  86. data/spec/unit/coercers/field_spec.rb +11 -0
  87. data/spec/unit/coercers/fold_spec.rb +11 -0
  88. data/spec/unit/coercers/prefix_spec.rb +38 -0
  89. data/spec/unit/coercers/rename_spec.rb +11 -0
  90. data/spec/unit/coercers/unfold_spec.rb +11 -0
  91. data/spec/unit/coercers/unwrap_spec.rb +35 -0
  92. data/spec/unit/coercers/wrap_spec.rb +35 -0
  93. data/spec/unit/functions/add_prefix_spec.rb +12 -0
  94. data/spec/unit/functions/claster_spec.rb +12 -0
  95. data/spec/unit/functions/clean_spec.rb +18 -0
  96. data/spec/unit/functions/drop_prefix_spec.rb +33 -0
  97. data/spec/unit/functions/exclude_spec.rb +64 -0
  98. data/spec/unit/functions/group_spec.rb +176 -0
  99. data/spec/unit/functions/keep_symbol_spec.rb +21 -0
  100. data/spec/unit/functions/split_spec.rb +64 -0
  101. data/spec/unit/functions/ungroup_spec.rb +87 -0
  102. data/spec/unit/functions/unwrap_spec.rb +54 -0
  103. data/spec/unit/functions/wrap_spec.rb +67 -0
  104. data/spec/unit/nodes/add_prefix_spec.rb +62 -0
  105. data/spec/unit/nodes/create_spec.rb +53 -0
  106. data/spec/unit/nodes/exclude_spec.rb +18 -0
  107. data/spec/unit/nodes/field_spec.rb +30 -0
  108. data/spec/unit/nodes/fold_spec.rb +19 -0
  109. data/spec/unit/nodes/group_spec.rb +163 -0
  110. data/spec/unit/nodes/list_spec.rb +27 -0
  111. data/spec/unit/nodes/remove_prefix_spec.rb +62 -0
  112. data/spec/unit/nodes/rename_spec.rb +16 -0
  113. data/spec/unit/nodes/stringify_keys_spec.rb +21 -0
  114. data/spec/unit/nodes/symbolize_keys_spec.rb +21 -0
  115. data/spec/unit/nodes/unfold_spec.rb +19 -0
  116. data/spec/unit/nodes/ungroup_spec.rb +92 -0
  117. data/spec/unit/nodes/unwrap_spec.rb +47 -0
  118. data/spec/unit/nodes/wrap_spec.rb +33 -0
  119. data/spec/unit/rules/append_nested_spec.rb +41 -0
  120. data/spec/unit/rules/merge_branches_spec.rb +58 -0
  121. data/spec/unit/rules/merge_excludes_spec.rb +31 -0
  122. data/spec/unit/rules/merge_renames_spec.rb +29 -0
  123. data/spec/unit/rules/order_fields_spec.rb +31 -0
  124. data/spec/unit/rules/prepend_nested_spec.rb +41 -0
  125. metadata +315 -0
@@ -0,0 +1,87 @@
1
+ # encoding: utf-8
2
+
3
+ describe Faceter::Functions, ".ungroup" do
4
+
5
+ let(:arguments) { [:ungroup, :baz, Selector.new(options)] }
6
+
7
+ it_behaves_like :transforming_immutable_data do
8
+ let(:options) { {} }
9
+
10
+ let(:input) do
11
+ [{ qux: :QUX, baz: [{ foo: :FOO, bar: :FOO }, { foo: :BAR, bar: :BAR }] }]
12
+ end
13
+
14
+ let(:output) do
15
+ [{ qux: :QUX, foo: :FOO, bar: :FOO }, { qux: :QUX, foo: :BAR, bar: :BAR }]
16
+ end
17
+ end
18
+
19
+ it_behaves_like :transforming_immutable_data do
20
+ let(:options) { { only: [:foo, :bar] } }
21
+
22
+ let(:input) do
23
+ [{ qux: :QUX, baz: [{ foo: :FOO, bar: :FOO }, { foo: :BAR, bar: :BAR }] }]
24
+ end
25
+
26
+ let(:output) do
27
+ [{ qux: :QUX, foo: :FOO, bar: :FOO }, { qux: :QUX, foo: :BAR, bar: :BAR }]
28
+ end
29
+ end
30
+
31
+ it_behaves_like :transforming_immutable_data do
32
+ let(:options) { { only: :foo } }
33
+
34
+ let(:input) do
35
+ [{ qux: :QUX, baz: [{ foo: :FOO, bar: :FOO }, { foo: :BAR, bar: :BAR }] }]
36
+ end
37
+
38
+ let(:output) do
39
+ [
40
+ { qux: :QUX, foo: :FOO, baz: [{ bar: :FOO }] },
41
+ { qux: :QUX, foo: :BAR, baz: [{ bar: :BAR }] }
42
+ ]
43
+ end
44
+ end
45
+
46
+ it_behaves_like :transforming_immutable_data do
47
+ let(:options) { { only: :foo } }
48
+
49
+ let(:input) do
50
+ [{ qux: :QUX, baz: [{ foo: :FOO, bar: :FOO }, { foo: :FOO, bar: :BAR }] }]
51
+ end
52
+
53
+ let(:output) do
54
+ [{ qux: :QUX, foo: :FOO, baz: [{ bar: :FOO }, { bar: :BAR }] }]
55
+ end
56
+ end
57
+
58
+ it_behaves_like :transforming_immutable_data do
59
+ let(:options) { { only: [:foo, :bar] } }
60
+
61
+ let(:input) do
62
+ [
63
+ {
64
+ qux: :QUX, foo: :QUX,
65
+ baz: [{ foo: :FOO, bar: :FOO }, { foo: :BAR, bar: :BAR }]
66
+ }
67
+ ]
68
+ end
69
+
70
+ let(:output) do
71
+ [{ qux: :QUX, foo: :FOO, bar: :FOO }, { qux: :QUX, foo: :BAR, bar: :BAR }]
72
+ end
73
+ end
74
+
75
+ it_behaves_like :transforming_immutable_data do
76
+ let(:options) { {} }
77
+
78
+ let(:input) do
79
+ [{ qux: :QUX, baz: [] }]
80
+ end
81
+
82
+ let(:output) do
83
+ [{ qux: :QUX }]
84
+ end
85
+ end
86
+
87
+ end # describe Faceter::Functions.ungroup
@@ -0,0 +1,54 @@
1
+ # encoding: utf-8
2
+
3
+ describe Faceter::Functions, ".unwrap" do
4
+
5
+ let(:arguments) { [:unwrap, :foo, Selector.new(options)] }
6
+ let(:input) { { foo: { foo: :FOO, bar: :BAR, baz: :BAZ }, qux: {} } }
7
+
8
+ it_behaves_like :transforming_immutable_data do
9
+ let(:options) { {} }
10
+ let(:output) { { foo: :FOO, bar: :BAR, baz: :BAZ, qux: {} } }
11
+ end
12
+
13
+ it_behaves_like :transforming_immutable_data do
14
+ let(:options) { { except: :foo } }
15
+ let(:output) { { foo: { foo: :FOO }, bar: :BAR, baz: :BAZ, qux: {} } }
16
+ end
17
+
18
+ it_behaves_like :transforming_immutable_data do
19
+ let(:options) { { except: :bar } }
20
+ let(:output) { { foo: :FOO, baz: :BAZ, qux: {} } }
21
+ end
22
+
23
+ it_behaves_like :transforming_immutable_data do
24
+ let(:options) { { except: [:foo, :bar] } }
25
+ let(:output) { { foo: { foo: :FOO, bar: :BAR }, baz: :BAZ, qux: {} } }
26
+ end
27
+
28
+ it_behaves_like :transforming_immutable_data do
29
+ let(:options) { { only: [] } }
30
+ let(:output) { { foo: { foo: :FOO, bar: :BAR, baz: :BAZ }, qux: {} } }
31
+ end
32
+
33
+ it_behaves_like :transforming_immutable_data do
34
+ let(:options) { { only: :foo } }
35
+ let(:output) { { foo: :FOO, qux: {} } }
36
+ end
37
+
38
+ it_behaves_like :transforming_immutable_data do
39
+ let(:options) { {} }
40
+ let(:input) { { foo: { bar: :BAR }, qux: {} } }
41
+ let(:output) { { bar: :BAR, qux: {} } }
42
+ end
43
+
44
+ it_behaves_like :transforming_immutable_data do
45
+ let(:options) { { only: :bar } }
46
+ let(:output) { { foo: { foo: :FOO, baz: :BAZ }, bar: :BAR, qux: {} } }
47
+ end
48
+
49
+ it_behaves_like :transforming_immutable_data do
50
+ let(:options) { { only: [:foo, :bar] } }
51
+ let(:output) { { foo: :FOO, bar: :BAR, qux: {} } }
52
+ end
53
+
54
+ end # describe Faceter::Functions.unwrap
@@ -0,0 +1,67 @@
1
+ # encoding: utf-8
2
+
3
+ describe Faceter::Functions, ".wrap" do
4
+
5
+ let(:arguments) { [:wrap, :foo, Selector.new(options)] }
6
+ let(:input) { { foo: :FOO, bar: :BAR, baz: :BAZ, qux: :QUX } }
7
+
8
+ it_behaves_like :transforming_immutable_data do
9
+ let(:options) { {} }
10
+ let(:output) { { foo: { foo: :FOO, bar: :BAR, baz: :BAZ, qux: :QUX } } }
11
+ end
12
+
13
+ it_behaves_like :transforming_immutable_data do
14
+ let(:options) { { except: [] } }
15
+ let(:output) { { foo: { foo: :FOO, bar: :BAR, baz: :BAZ, qux: :QUX } } }
16
+ end
17
+
18
+ it_behaves_like :transforming_immutable_data do
19
+ let(:options) { { except: :foo } }
20
+ let(:output) { { foo: { bar: :BAR, baz: :BAZ, qux: :QUX } } }
21
+ end
22
+
23
+ it_behaves_like :transforming_immutable_data do
24
+ let(:options) { { except: :bar } }
25
+ let(:output) { { bar: :BAR, foo: { foo: :FOO, baz: :BAZ, qux: :QUX } } }
26
+ end
27
+
28
+ it_behaves_like :transforming_immutable_data do
29
+ let(:options) { { except: [:foo, :bar] } }
30
+ let(:output) { { bar: :BAR, foo: { baz: :BAZ, qux: :QUX } } }
31
+ end
32
+
33
+ it_behaves_like :transforming_immutable_data do
34
+ let(:options) { { only: [] } }
35
+ let(:output) { { foo: {}, bar: :BAR, baz: :BAZ, qux: :QUX } }
36
+ end
37
+
38
+ it_behaves_like :transforming_immutable_data do
39
+ let(:options) { { only: :foo } }
40
+ let(:output) { { foo: { foo: :FOO }, bar: :BAR, baz: :BAZ, qux: :QUX } }
41
+ end
42
+
43
+ it_behaves_like :transforming_immutable_data do
44
+ let(:options) { { only: :bar } }
45
+ let(:output) { { foo: { bar: :BAR }, baz: :BAZ, qux: :QUX } }
46
+ end
47
+
48
+ it_behaves_like :transforming_immutable_data do
49
+ let(:options) { { only: [:foo, :bar] } }
50
+ let(:output) { { foo: { foo: :FOO, bar: :BAR }, baz: :BAZ, qux: :QUX } }
51
+ end
52
+
53
+ it_behaves_like :transforming_immutable_data do
54
+ let(:options) { { only: [:bar] } }
55
+
56
+ let(:input) { { foo: { foo: :FOO, bar: :FOO }, bar: :BAR, baz: :BAZ } }
57
+ let(:output) { { foo: { foo: :FOO, bar: :BAR }, baz: :BAZ } }
58
+ end
59
+
60
+ it_behaves_like :transforming_immutable_data do
61
+ let(:options) { { except: :foo } }
62
+
63
+ let(:input) { { foo: { foo: :FOO, bar: :FOO }, bar: :BAR, baz: :BAZ } }
64
+ let(:output) { { foo: { foo: :FOO, bar: :BAR, baz: :BAZ } } }
65
+ end
66
+
67
+ end # describe Faceter::Functions.wrap
@@ -0,0 +1,62 @@
1
+ # encoding: utf-8
2
+
3
+ describe Faceter::Nodes::AddPrefix do
4
+
5
+ it_behaves_like :creating_immutable_node do
6
+ let(:attributes) { { prefix: "foo" } }
7
+ end
8
+
9
+ it_behaves_like :mapping_immutable_input do
10
+ let(:attributes) { { prefix: "foo" } }
11
+
12
+ let(:input) { { bar: "BAR", "baz" => { qux: :QUX } } }
13
+ let(:output) { { foo_bar: "BAR", "foo_baz" => { qux: :QUX } } }
14
+ end
15
+
16
+ it_behaves_like :mapping_immutable_input do
17
+ let(:attributes) { { prefix: "foo", separator: "." } }
18
+
19
+ let(:input) { { bar: "BAR", "baz" => { qux: :QUX } } }
20
+ let(:output) { { :"foo.bar" => "BAR", "foo.baz" => { qux: :QUX } } }
21
+ end
22
+
23
+ it_behaves_like :mapping_immutable_input do
24
+ let(:selector) { Selector.new(only: /bar/) }
25
+ let(:attributes) { { prefix: "foo", selector: selector } }
26
+
27
+ let(:input) { { bar: "BAR", "baz" => { qux: :QUX } } }
28
+ let(:output) { { foo_bar: "BAR", "baz" => { qux: :QUX } } }
29
+ end
30
+
31
+ it_behaves_like :mapping_immutable_input do
32
+ let(:selector) { Selector.new(except: "baz") }
33
+ let(:attributes) { { prefix: "foo", selector: selector } }
34
+
35
+ let(:input) { { bar: "BAR", "baz" => { qux: :QUX } } }
36
+ let(:output) { { foo_bar: "BAR", "baz" => { qux: :QUX } } }
37
+ end
38
+
39
+ it_behaves_like :mapping_immutable_input do
40
+ let(:attributes) { { prefix: "foo", nested: true } }
41
+
42
+ let(:input) { { bar: "BAR", "baz" => { qux: :QUX } } }
43
+ let(:output) { { foo_bar: "BAR", "foo_baz" => { foo_qux: :QUX } } }
44
+ end
45
+
46
+ it_behaves_like :mapping_immutable_input do
47
+ let(:selector) { Selector.new(except: /b/) }
48
+ let(:attributes) { { prefix: "foo", nested: true, selector: selector } }
49
+
50
+ let(:input) { { bar: "BAR", "baz" => { qux: :QUX } } }
51
+ let(:output) { { bar: "BAR", "baz" => { foo_qux: :QUX } } }
52
+ end
53
+
54
+ it_behaves_like :mapping_immutable_input do
55
+ let(:selector) { Selector.new(only: /q/) }
56
+ let(:attributes) { { prefix: "foo", nested: true, selector: selector } }
57
+
58
+ let(:input) { { bar: "BAR", "baz" => { qux: :QUX } } }
59
+ let(:output) { { bar: "BAR", "baz" => { foo_qux: :QUX } } }
60
+ end
61
+
62
+ end # describe Faceter::Nodes::AddPrefix
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+
3
+ describe Faceter::Nodes::Create do
4
+
5
+ it_behaves_like :creating_immutable_node do
6
+ let(:attributes) { { keys: [] } }
7
+ end
8
+
9
+ it_behaves_like :mapping_immutable_input do
10
+ let(:attributes) { { keys: :bar } }
11
+
12
+ let(:input) { { bar: :BAR, baz: :BAZ } }
13
+ let(:output) { :BAR }
14
+ end
15
+
16
+ it_behaves_like :mapping_immutable_input do
17
+ let(:attributes) { { keys: [:bar] } }
18
+
19
+ let(:input) { { bar: :BAR, baz: :BAZ } }
20
+ let(:output) { [:BAR] }
21
+ end
22
+
23
+ it_behaves_like :mapping_immutable_input do
24
+ let(:attributes) { { name: :foo, keys: :bar } }
25
+
26
+ let(:input) { { bar: :BAR, baz: :BAZ } }
27
+ let(:output) { { bar: :BAR, baz: :BAZ, foo: :BAR } }
28
+ end
29
+
30
+ it_behaves_like :mapping_immutable_input do
31
+ let(:attributes) { { name: :foo, keys: [:bar, :baz] } }
32
+
33
+ let(:input) { { bar: :BAR, baz: :BAZ } }
34
+ let(:output) { { bar: :BAR, baz: :BAZ, foo: [:BAR, :BAZ] } }
35
+ end
36
+
37
+ it_behaves_like :mapping_immutable_input do
38
+ let(:block) { proc { |bar| bar.to_s } }
39
+ let(:attributes) { { name: :foo, keys: :bar } }
40
+
41
+ let(:input) { { bar: :BAR, baz: :BAZ } }
42
+ let(:output) { { bar: :BAR, baz: :BAZ, foo: "BAR" } }
43
+ end
44
+
45
+ it_behaves_like :mapping_immutable_input do
46
+ let(:block) { proc { |*args| args.map(&:to_s) } }
47
+ let(:attributes) { { name: :foo, keys: [:bar, :baz] } }
48
+
49
+ let(:input) { { bar: :BAR, baz: :BAZ } }
50
+ let(:output) { { bar: :BAR, baz: :BAZ, foo: %w(BAR BAZ) } }
51
+ end
52
+
53
+ end # describe Faceter::Nodes::Create
@@ -0,0 +1,18 @@
1
+ # encoding: utf-8
2
+
3
+ describe Faceter::Nodes::Exclude do
4
+
5
+ let(:attributes) { { selector: Selector.new(options) } }
6
+
7
+ it_behaves_like :creating_immutable_node do
8
+ let(:options) { {} }
9
+ end
10
+
11
+ it_behaves_like :mapping_immutable_input do
12
+ let(:options) { { only: [:foo, :bar] } }
13
+
14
+ let(:input) { { foo: :FOO, bar: :BAR, baz: :BAZ } }
15
+ let(:output) { { baz: :BAZ } }
16
+ end
17
+
18
+ end # describe Faceter::Nodes::Exclude
@@ -0,0 +1,30 @@
1
+ # encoding: utf-8
2
+
3
+ describe Faceter::Nodes::Field do
4
+
5
+ before do
6
+ class Faceter::Test::Foo < AbstractMapper::Node
7
+ define_method(:transproc) { Faceter::Functions[:rename_keys, foo: :baz] }
8
+ end
9
+
10
+ class Faceter::Test::Bar < AbstractMapper::Node
11
+ define_method(:transproc) { Faceter::Functions[:rename_keys, bar: :qux] }
12
+ end
13
+ end
14
+
15
+ let(:foo) { Faceter::Test::Foo.new }
16
+ let(:bar) { Faceter::Test::Bar.new }
17
+
18
+ it_behaves_like :creating_immutable_branch do
19
+ let(:attributes) { { key: :foo } }
20
+ end
21
+
22
+ it_behaves_like :mapping_immutable_input do
23
+ let(:attributes) { { key: :baz } }
24
+ let(:block) { proc { [foo, bar] } }
25
+
26
+ let(:input) { { baz: { foo: :FOO, bar: :BAR } } }
27
+ let(:output) { { baz: { baz: :FOO, qux: :BAR } } }
28
+ end
29
+
30
+ end # describe Faceter::Nodes::Field
@@ -0,0 +1,19 @@
1
+ # encoding: utf-8
2
+
3
+ describe Faceter::Nodes::Fold do
4
+
5
+ let(:attributes) { { key: :foo } }
6
+
7
+ it_behaves_like :creating_immutable_node
8
+
9
+ it_behaves_like :mapping_immutable_input do
10
+ let(:input) { :FOO }
11
+ let(:output) { { foo: :FOO } }
12
+ end
13
+
14
+ it_behaves_like :mapping_immutable_input do
15
+ let(:input) { nil }
16
+ let(:output) { { foo: nil } }
17
+ end
18
+
19
+ end # describe Faceter::Nodes::Fold
@@ -0,0 +1,163 @@
1
+ # encoding: utf-8
2
+
3
+ describe Faceter::Nodes::Group do
4
+
5
+ let(:attributes) { { key: :baz, selector: selector } }
6
+ let(:selector) { Selector.new(options) }
7
+
8
+ it_behaves_like :creating_immutable_node do
9
+ let(:options) { {} }
10
+ end
11
+
12
+ it_behaves_like :mapping_immutable_input do
13
+ let(:options) { { only: [:foo, :bar] } }
14
+
15
+ let(:input) do
16
+ [
17
+ { foo: :FOO, bar: :FOO, qux: :QUX },
18
+ { foo: :BAR, bar: :BAR, qux: :QUX }
19
+ ]
20
+ end
21
+
22
+ let(:output) do
23
+ [
24
+ {
25
+ qux: :QUX,
26
+ baz: [{ foo: :FOO, bar: :FOO }, { foo: :BAR, bar: :BAR }]
27
+ }
28
+ ]
29
+ end
30
+ end
31
+
32
+ it_behaves_like :mapping_immutable_input do
33
+ let(:options) { { only: [:foo, :bar] } }
34
+
35
+ let(:input) do
36
+ [
37
+ { foo: :FOO, bar: :FOO, baz: :BAZ, qux: :QUX },
38
+ { foo: :BAR, bar: :BAR, baz: :BAZ, qux: :QUX }
39
+ ]
40
+ end
41
+
42
+ let(:output) do
43
+ [
44
+ {
45
+ qux: :QUX,
46
+ baz: [{ foo: :FOO, bar: :FOO }, { foo: :BAR, bar: :BAR }]
47
+ }
48
+ ]
49
+ end
50
+ end
51
+
52
+ it_behaves_like :mapping_immutable_input do
53
+ let(:options) { { only: [:foo, :bar] } }
54
+
55
+ let(:input) do
56
+ [
57
+ { foo: :FOO, bar: :FOO, baz: { bar: :BAZ }, qux: :QUX },
58
+ { foo: :BAR, bar: :BAR, baz: { bar: :BAZ }, qux: :QUX }
59
+ ]
60
+ end
61
+
62
+ let(:output) do
63
+ [
64
+ {
65
+ qux: :QUX,
66
+ baz: [{ foo: :FOO, bar: :FOO }, { foo: :BAR, bar: :BAR }]
67
+ }
68
+ ]
69
+ end
70
+ end
71
+
72
+ it_behaves_like :mapping_immutable_input do
73
+ let(:options) { { only: [:foo, :bar] } }
74
+
75
+ let(:input) do
76
+ [
77
+ { foo: :FOO, bar: :FOO, baz: [{ baz: :BAZ }], qux: :QUX },
78
+ { foo: :BAR, bar: :BAR, baz: [{ baz: :BAZZ }], qux: :QUX }
79
+ ]
80
+ end
81
+
82
+ let(:output) do
83
+ [
84
+ {
85
+ qux: :QUX,
86
+ baz: [
87
+ { foo: :FOO, bar: :FOO, baz: :BAZ },
88
+ { foo: :BAR, bar: :BAR, baz: :BAZZ }
89
+ ]
90
+ }
91
+ ]
92
+ end
93
+ end
94
+
95
+ it_behaves_like :mapping_immutable_input do
96
+ let(:options) { { only: :foo } }
97
+
98
+ let(:input) do
99
+ [
100
+ { foo: :FOO, baz: [{ baz: :FOO }, { baz: :BAR }], qux: :QUX },
101
+ { foo: :BAR, baz: [{ baz: :BAZ }, { baz: :QUX }], qux: :QUX }
102
+ ]
103
+ end
104
+
105
+ let(:output) do
106
+ [
107
+ {
108
+ qux: :QUX,
109
+ baz: [
110
+ { baz: :FOO, foo: :FOO },
111
+ { baz: :BAR, foo: :FOO },
112
+ { baz: :BAZ, foo: :BAR },
113
+ { baz: :QUX, foo: :BAR }
114
+ ]
115
+ }
116
+ ]
117
+ end
118
+ end
119
+
120
+ it_behaves_like :mapping_immutable_input do
121
+ let(:options) { { only: [:foo, :baz] } }
122
+
123
+ let(:input) do
124
+ [
125
+ { foo: :FOO, baz: :FOO, qux: :QUX },
126
+ { foo: :BAR, baz: :BAR, qux: :QUX }
127
+ ]
128
+ end
129
+
130
+ let(:output) do
131
+ [
132
+ {
133
+ qux: :QUX,
134
+ baz: [{ foo: :FOO, baz: :FOO }, { foo: :BAR, baz: :BAR }]
135
+ }
136
+ ]
137
+ end
138
+ end
139
+
140
+ it_behaves_like :mapping_immutable_input do
141
+ let(:options) { { only: :baz } }
142
+
143
+ let(:input) do
144
+ [
145
+ { baz: [{ bar: :FOO }, { baz: :FOO }], qux: :QUX },
146
+ { baz: [{ bar: :BAR }, { baz: :BAR }], qux: :QUX }
147
+ ]
148
+ end
149
+
150
+ let(:output) do
151
+ [
152
+ {
153
+ qux: :QUX,
154
+ baz: [
155
+ { baz: [{ bar: :FOO }, { baz: :FOO }] },
156
+ { baz: [{ bar: :BAR }, { baz: :BAR }] }
157
+ ]
158
+ }
159
+ ]
160
+ end
161
+ end
162
+
163
+ end # describe Faceter::Nodes::Group