yaks 0.9.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +158 -56
  3. data/Rakefile +1 -3
  4. data/ataru_setup.rb +72 -0
  5. data/find_missing_tests.rb +34 -0
  6. data/lib/yaks.rb +8 -10
  7. data/lib/yaks/breaking_changes.rb +4 -6
  8. data/lib/yaks/builder.rb +1 -1
  9. data/lib/yaks/changelog.rb +1 -1
  10. data/lib/yaks/collection_mapper.rb +8 -5
  11. data/lib/yaks/collection_resource.rb +0 -1
  12. data/lib/yaks/config.rb +17 -7
  13. data/lib/yaks/configurable.rb +20 -14
  14. data/lib/yaks/default_policy.rb +82 -33
  15. data/lib/yaks/format.rb +7 -3
  16. data/lib/yaks/format/collection_json.rb +4 -4
  17. data/lib/yaks/format/hal.rb +1 -2
  18. data/lib/yaks/format/halo.rb +2 -4
  19. data/lib/yaks/format/json_api.rb +46 -27
  20. data/lib/yaks/html5_forms.rb +0 -2
  21. data/lib/yaks/mapper.rb +5 -5
  22. data/lib/yaks/mapper/association.rb +7 -7
  23. data/lib/yaks/mapper/association_mapper.rb +2 -0
  24. data/lib/yaks/mapper/attribute.rb +10 -4
  25. data/lib/yaks/mapper/config.rb +2 -2
  26. data/lib/yaks/mapper/form.rb +4 -10
  27. data/lib/yaks/mapper/form/config.rb +16 -17
  28. data/lib/yaks/mapper/form/dynamic_field.rb +1 -1
  29. data/lib/yaks/mapper/form/field.rb +16 -7
  30. data/lib/yaks/mapper/form/field/option.rb +5 -4
  31. data/lib/yaks/mapper/form/fieldset.rb +1 -1
  32. data/lib/yaks/mapper/form/legend.rb +18 -0
  33. data/lib/yaks/mapper/has_many.rb +1 -0
  34. data/lib/yaks/mapper/link.rb +7 -4
  35. data/lib/yaks/null_resource.rb +4 -5
  36. data/lib/yaks/pipeline.rb +2 -2
  37. data/lib/yaks/primitivize.rb +3 -2
  38. data/lib/yaks/reader/hal.rb +12 -13
  39. data/lib/yaks/reader/json_api.rb +50 -33
  40. data/lib/yaks/resource.rb +6 -7
  41. data/lib/yaks/resource/form.rb +2 -12
  42. data/lib/yaks/resource/form/field.rb +4 -3
  43. data/lib/yaks/resource/form/field/option.rb +1 -1
  44. data/lib/yaks/resource/form/fieldset.rb +1 -1
  45. data/lib/yaks/resource/form/legend.rb +18 -0
  46. data/lib/yaks/resource/has_fields.rb +13 -7
  47. data/lib/yaks/resource/link.rb +1 -1
  48. data/lib/yaks/runner.rb +5 -2
  49. data/lib/yaks/serializer.rb +2 -3
  50. data/lib/yaks/util.rb +7 -8
  51. data/lib/yaks/version.rb +1 -1
  52. data/spec/acceptance/acceptance_spec.rb +53 -38
  53. data/spec/acceptance/json_shared_examples.rb +45 -12
  54. data/spec/acceptance/models.rb +1 -1
  55. data/spec/integration/dynamic_form_fields_spec.rb +0 -1
  56. data/spec/integration/fieldset_spec.rb +18 -20
  57. data/spec/integration/map_to_resource_spec.rb +6 -6
  58. data/spec/json/{confucius.collection.json → confucius.collection_json.json} +0 -0
  59. data/spec/json/confucius.json_api.json +43 -27
  60. data/spec/json/list_of_quotes.collection_json.json +43 -0
  61. data/spec/json/list_of_quotes.hal.json +18 -0
  62. data/spec/json/list_of_quotes.json_api.json +25 -0
  63. data/spec/json/youtypeitwepostit.collection_json.json +45 -0
  64. data/spec/spec_helper.rb +4 -3
  65. data/spec/support/classes_for_policy_testing.rb +38 -14
  66. data/spec/support/deep_eql.rb +21 -18
  67. data/spec/support/pet_mapper.rb +2 -0
  68. data/spec/support/shared_contexts.rb +9 -9
  69. data/spec/unit/yaks/builder_spec.rb +41 -18
  70. data/spec/unit/yaks/collection_mapper_spec.rb +22 -19
  71. data/spec/unit/yaks/collection_resource_spec.rb +16 -8
  72. data/spec/unit/yaks/config_spec.rb +215 -19
  73. data/spec/unit/yaks/configurable_spec.rb +66 -7
  74. data/spec/unit/yaks/default_policy/derive_mapper_from_collection_spec.rb +47 -0
  75. data/spec/unit/yaks/default_policy/derive_mapper_from_item_spec.rb +114 -0
  76. data/spec/unit/yaks/default_policy/derive_mapper_from_object_spec.rb +29 -71
  77. data/spec/unit/yaks/default_policy_spec.rb +4 -5
  78. data/spec/unit/yaks/format/collection_json_spec.rb +35 -36
  79. data/spec/unit/yaks/format/hal_spec.rb +3 -3
  80. data/spec/unit/yaks/format/json_api_spec.rb +109 -68
  81. data/spec/unit/yaks/format_spec.rb +34 -0
  82. data/spec/unit/yaks/fp/callable_spec.rb +5 -3
  83. data/spec/unit/yaks/mapper/association_mapper_spec.rb +22 -4
  84. data/spec/unit/yaks/mapper/association_spec.rb +23 -11
  85. data/spec/unit/yaks/mapper/attribute_spec.rb +46 -7
  86. data/spec/unit/yaks/mapper/config_spec.rb +2 -3
  87. data/spec/unit/yaks/mapper/form/config_spec.rb +95 -0
  88. data/spec/unit/yaks/mapper/form/dynamic_field_spec.rb +30 -0
  89. data/spec/unit/yaks/mapper/form/field/option_spec.rb +48 -4
  90. data/spec/unit/yaks/mapper/form/field_spec.rb +43 -2
  91. data/spec/unit/yaks/mapper/form/fieldset_spec.rb +67 -8
  92. data/spec/unit/yaks/mapper/form/legend_spec.rb +52 -0
  93. data/spec/unit/yaks/mapper/form_spec.rb +84 -23
  94. data/spec/unit/yaks/mapper/has_many_spec.rb +39 -36
  95. data/spec/unit/yaks/mapper/has_one_spec.rb +28 -20
  96. data/spec/unit/yaks/mapper/link_spec.rb +68 -16
  97. data/spec/unit/yaks/mapper_spec.rb +118 -30
  98. data/spec/unit/yaks/null_resource_spec.rb +83 -52
  99. data/spec/unit/yaks/pipeline_spec.rb +101 -74
  100. data/spec/unit/yaks/primitivize_spec.rb +25 -6
  101. data/spec/unit/yaks/resource/form/field_spec.rb +5 -5
  102. data/spec/unit/yaks/resource/form/fieldset_spec.rb +7 -0
  103. data/spec/unit/yaks/resource/form/legend_spec.rb +8 -0
  104. data/spec/unit/yaks/resource/form_spec.rb +17 -37
  105. data/spec/unit/yaks/resource/has_fields_spec.rb +44 -3
  106. data/spec/unit/yaks/resource/link_spec.rb +11 -6
  107. data/spec/unit/yaks/resource_spec.rb +87 -98
  108. data/spec/unit/yaks/runner_spec.rb +112 -28
  109. data/spec/unit/yaks/serializer_spec.rb +1 -1
  110. data/spec/unit/yaks/util_spec.rb +30 -10
  111. data/spec/yaml/list_of_quotes.yaml +13 -0
  112. data/yaks.gemspec +21 -13
  113. metadata +129 -41
  114. data/lib/yaks/attributes.rb +0 -86
  115. data/lib/yaks/fp.rb +0 -26
  116. data/lib/yaks/identifier/link_relation.rb +0 -17
  117. data/resources/iana-link-relations.csv +0 -152
  118. data/spec/json/youtypeitwepostit.collection.json +0 -45
  119. data/spec/unit/yaks/attributes_spec.rb +0 -178
  120. data/spec/unit/yaks/fp_spec.rb +0 -29
@@ -1,5 +1,5 @@
1
1
  class Kitten
2
- include Yaks::Attributes.new(:furriness)
2
+ include Attribs.new(:furriness)
3
3
 
4
4
  def self.create(opts, &block)
5
5
  level = opts[:fur_level]
@@ -9,7 +9,7 @@ class Kitten
9
9
  end
10
10
 
11
11
  class Hanky
12
- include Yaks::Attributes.new(:stickyness, :size, :color)
12
+ include Attribs.new(:stickyness, :size, :color)
13
13
 
14
14
  def self.create(sticky, opts = {})
15
15
  new(stickyness: sticky, size: opts[:size], color: opts[:color])
@@ -19,13 +19,29 @@ end
19
19
  RSpec.describe Yaks::Configurable do
20
20
  let(:suffix) { SecureRandom.hex(16) }
21
21
  subject do
22
- eval %Q<
22
+ # rubocop:disable Lint/Eval
23
+ eval %<
23
24
  class TestConfigurable#{suffix}
24
25
  class Config
25
- include Yaks::Attributes.new(color: 'blue', taste: 'sour', contents: [])
26
+ include Attribs.new(color: 'blue', taste: 'sour', contents: [])
27
+
28
+ def turn_into_orange
29
+ with(color: 'orange', taste: 'like an orange')
30
+ end
31
+
32
+ def turn_into_apple
33
+ with(color: 'green', taste: 'like an apple')
34
+ end
35
+
36
+ def with_color_and_contents(color)
37
+ with(color: color, contents: yield(contents))
38
+ end
26
39
  end
27
40
  extend Yaks::Configurable
28
41
 
42
+ def_set :color, :taste
43
+ def_forward :turn_into_apple, :turn_into_orange, :with_color_and_contents
44
+ def_forward appleize: :turn_into_apple
29
45
  def_add :kitten, create: Kitten, append_to: :contents, defaults: {fur_level: 7}
30
46
  def_add :cat, create: Kitten, append_to: :contents
31
47
  def_add :hanky, create: Hanky, append_to: :contents, defaults: {size: 12, color: :red}
@@ -57,7 +73,7 @@ end
57
73
  end
58
74
 
59
75
  it 'should pass on a block' do
60
- subject.cat(fur_level: 3) {|l| l+3}
76
+ subject.cat(fur_level: 3) {|l| l + 3}
61
77
  expect(subject.config.contents).to eql [Kitten.new(furriness: 6)]
62
78
  end
63
79
 
@@ -72,13 +88,56 @@ end
72
88
  end
73
89
  end
74
90
 
75
-
76
91
  describe '#def_set' do
77
92
  it 'should set' do
93
+ subject.color 'red'
94
+ expect(subject.config.color).to eql 'red'
95
+ end
96
+
97
+ it 'should capture blocks as closures' do
98
+ subject.color {|x| "#{x} blue"}
99
+ expect(subject.config.color.call("dark")).to eql 'dark blue'
100
+ end
101
+
102
+ it 'should signal when called without arguments' do
103
+ expect { subject.color }.to raise_error(ArgumentError, "setting color: no value and no block given")
104
+ end
105
+
106
+ it 'is an error when both a value and a block are passed in' do
107
+ expect { subject.color('red') {'blue'} }.to raise_error(ArgumentError, "ambiguous invocation setting color: give either a value or a block, not both.")
78
108
  end
79
109
  end
110
+
80
111
  describe '#def_forward' do
81
- it 'should forward' do
112
+ it 'should generate a method that delegates to the config instance - first position' do
113
+ subject.turn_into_orange
114
+ expect(subject.config.color).to eql 'orange'
115
+ end
116
+
117
+ it 'should generate a method that delegates to the config instance - last position' do
118
+ subject.turn_into_apple
119
+ expect(subject.config.color).to eql 'green'
120
+ end
121
+
122
+ it 'should work with a hash for mappings' do
123
+ subject.appleize
124
+ expect(subject.config.color).to eql 'green'
125
+ end
126
+
127
+ it 'should forward arguments and block' do
128
+ subject.with_color_and_contents('brown') do |contents|
129
+ contents + [1, 2, 3]
130
+ end
131
+
132
+ expect(subject.config.color).to eql 'brown'
133
+ expect(subject.config.contents).to eql [1, 2, 3]
134
+ end
135
+ end
136
+
137
+ describe '#inherited' do
138
+ it 'should propagate the config state' do
139
+ subject.appleize
140
+ expect(Class.new(subject).config.color).to eql 'green'
82
141
  end
83
142
  end
84
143
  end
@@ -0,0 +1,47 @@
1
+ RSpec.describe Yaks::DefaultPolicy, '#derive_mapper_from_collection' do
2
+ subject(:policy) { described_class.new(options) }
3
+
4
+ let(:options) { {} }
5
+
6
+ context 'given an empty array' do
7
+ it 'should return the vanilla CollectionMapper' do
8
+ expect(policy.derive_mapper_from_collection([])).to be Yaks::CollectionMapper
9
+ end
10
+ end
11
+
12
+ it 'should find the mapper based on naming' do
13
+ expect(policy.derive_mapper_from_collection([Soy.new])).to be SoyCollectionMapper
14
+ end
15
+
16
+ it 'should not care about the object module' do
17
+ expect(policy.derive_mapper_from_collection([Grain::Soy.new])).to be SoyCollectionMapper
18
+ end
19
+
20
+ context 'if no collection mapper with a similar name is defined' do
21
+ let(:options) { {namespace: Namespace} }
22
+
23
+ it 'should look for a CollectionMapper in the namespace' do
24
+ expect(policy.derive_mapper_from_collection([WildSoy.new])).to be(Namespace::CollectionMapper)
25
+ end
26
+
27
+ context 'when trying to lookup CollectionMapper results in something other than an NameError' do
28
+ let(:options) { {namespace: DislikesCollectionMapper} }
29
+
30
+ it 'should propagate the error' do
31
+ expect {
32
+ policy.derive_mapper_from_object([])
33
+ }.to raise_error
34
+ end
35
+ end
36
+
37
+ context 'when trying to lookup a specific collection mapper results in something other than an NameError' do
38
+ let(:options) { {namespace: DislikesOtherMappers} }
39
+
40
+ it 'should propagate the error' do
41
+ expect do
42
+ policy.derive_mapper_from_object([Namespace::Nested::Rye.new])
43
+ end.to raise_error
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,114 @@
1
+ RSpec.describe Yaks::DefaultPolicy, '#derive_mapper_from_item' do
2
+ subject(:policy) { described_class.new(options) }
3
+
4
+ let(:options) { {} }
5
+
6
+ it 'should use const_get with second argument set to false' do
7
+ stub(Object).const_get(any_args) { SoyMapper }
8
+ policy.derive_mapper_from_item(Soy.new)
9
+ expect(Object).to have_received.const_get("SoyMapper", false)
10
+ end
11
+
12
+ context 'at top level' do
13
+ it 'should derive it by name' do
14
+ expect(policy.derive_mapper_from_item(Soy.new)).to be SoyMapper
15
+ end
16
+
17
+ it 'should look for parent class if not found' do
18
+ expect(policy.derive_mapper_from_item(WildSoy.new)).to be SoyMapper
19
+ end
20
+
21
+ context 'with namespace option set' do
22
+ let(:options) { {namespace: MyMappers} }
23
+
24
+ it 'should look inside the namespace' do
25
+ expect(policy.derive_mapper_from_item(Soy.new)).to be MyMappers::SoyMapper
26
+ end
27
+
28
+ it 'should look for its parent class mapper in the namespace if not found' do
29
+ expect(policy.derive_mapper_from_item(WildSoy.new)).to be MyMappers::SoyMapper
30
+ end
31
+ end
32
+ end
33
+
34
+ context 'inside a module' do
35
+ it 'should look inside the module' do
36
+ expect(policy.derive_mapper_from_item(Grain::Soy.new)).to be Grain::SoyMapper
37
+ end
38
+
39
+ it 'should look for its parent class mapper in the module if not found' do
40
+ expect(policy.derive_mapper_from_item(Grain::WildSoy.new)).to be Grain::SoyMapper
41
+ end
42
+
43
+ context 'no mapper defined in module' do
44
+ it 'should look for mapper outside module' do
45
+ expect(policy.derive_mapper_from_item(Grain::Wheat.new)).to be WheatMapper
46
+ end
47
+
48
+ it 'should look for its parent class mapper outside module' do
49
+ expect(policy.derive_mapper_from_item(Grain::Durum.new)).to be WheatMapper
50
+ end
51
+ end
52
+
53
+ context 'with namespace option set' do
54
+ let(:options) { {namespace: MyMappers} }
55
+
56
+ it 'should look inside the module' do
57
+ expect(policy.derive_mapper_from_item(Grain::Soy.new)).to be MyMappers::Grain::SoyMapper
58
+ end
59
+
60
+ it 'should look for its parent class mapper if not found' do
61
+ expect(policy.derive_mapper_from_item(Grain::WildSoy.new)).to be MyMappers::Grain::SoyMapper
62
+ end
63
+
64
+ context 'no mapper defined in module' do
65
+ it 'should look for mapper in namespace top level' do
66
+ expect(policy.derive_mapper_from_item(Grain::Wheat.new)).to be MyMappers::WheatMapper
67
+ end
68
+
69
+ it 'should look for its parent mapper in namespace top level' do
70
+ expect(policy.derive_mapper_from_item(Grain::Durum.new)).to be MyMappers::WheatMapper
71
+ end
72
+ end
73
+ end
74
+
75
+ context 'deeply nested module' do
76
+ it 'should look inside the module' do
77
+ expect(policy.derive_mapper_from_item(Grain::Dry::Soy.new)).to be Grain::Dry::SoyMapper
78
+ end
79
+ end
80
+ end
81
+
82
+ context 'when no mapper is found' do
83
+ it 'should give a nice message' do
84
+ expect do
85
+ policy.derive_mapper_from_item(Namespace::Nested::Mung.new)
86
+ end.to raise_error /Failed to find a mapper for #<Namespace::Nested::Mung:0x\h+>. Did you mean to implement Namespace::Nested::MungMapper\?/
87
+ end
88
+
89
+ context 'with namespace option specified' do
90
+ let(:options) { {namespace: MyMappers} }
91
+
92
+ it 'should give a nice message' do
93
+ expect do
94
+ policy.derive_mapper_from_item(Namespace::Nested::Rye.new)
95
+ end.to raise_error /Failed to find a mapper for #<Namespace::Nested::Rye:0x\h+>. Did you mean to implement MyMappers::Namespace::Nested::RyeMapper\?/
96
+ end
97
+ end
98
+ end
99
+
100
+ context 'Object instance' do
101
+ it 'return ObjectMapper' do
102
+ expect(policy.derive_mapper_from_item(Object.new)).to be ObjectMapper
103
+ end
104
+
105
+ context 'no mapper available' do
106
+ before { Object.send(:remove_const, "ObjectMapper") }
107
+ after { Object::ObjectMapper = Class.new }
108
+
109
+ it 'raise error' do
110
+ expect { policy.derive_mapper_from_item(Object.new) }.to raise_error RuntimeError
111
+ end
112
+ end
113
+ end
114
+ end
@@ -1,94 +1,52 @@
1
1
  RSpec.describe Yaks::DefaultPolicy, '#derive_mapper_from_object' do
2
- subject(:policy) { described_class.new(options) }
3
-
4
- let(:options) { {} }
2
+ subject(:policy) { described_class.new }
5
3
 
6
4
  context 'for a single instance' do
7
- it 'should derive it by name' do
8
- expect(policy.derive_mapper_from_object(Soy.new)).to be SoyMapper
9
- end
10
-
11
- context 'given a namespace' do
12
- let(:options) { {namespace: MyMappers} }
5
+ let(:object) { Soy.new }
13
6
 
14
- it 'should look inside the namespace' do
15
- expect(policy.derive_mapper_from_object(Soy.new)).to be MyMappers::SoyMapper
16
- end
7
+ it 'should call derive_mapper_for_item' do
8
+ stub(policy).derive_mapper_from_item(object) { SoyMapper }
9
+ policy.derive_mapper_from_object(object)
10
+ expect(policy).to have_received.derive_mapper_from_item(object)
17
11
  end
18
12
  end
19
13
 
20
14
  context 'for array-like objects' do
21
- context 'given an empty array' do
22
- it 'should return the vanilla CollectionMapper' do
23
- expect(policy.derive_mapper_from_object([])).to be Yaks::CollectionMapper
24
- end
25
- end
15
+ let(:object) { [Soy.new] }
26
16
 
27
- it 'should find the mapper based on naming' do
28
- expect(policy.derive_mapper_from_object([Soy.new])).to be SoyCollectionMapper
29
- end
30
-
31
- context 'if no collection mapper with a similar name is defined' do
32
- let(:options) { {namespace: Namespace} }
33
-
34
- it 'should look for a CollectionMapper in the namespace' do
35
- expect(policy.derive_mapper_from_object([Wheat.new])).to be(
36
- Namespace::CollectionMapper
37
- )
38
- end
17
+ it 'should call derive_mapper_for_item' do
18
+ stub(policy).derive_mapper_from_collection(object) { SoyCollectionMapper }
19
+ policy.derive_mapper_from_object(object)
20
+ expect(policy).to have_received.derive_mapper_from_collection(object)
39
21
  end
40
22
  end
41
23
 
42
- context 'for a model class inside a module' do
43
- let(:options) { {namespace: Namespace} }
44
-
45
- it 'should take the non-qualified classname, and search the mapper namespace with that' do
46
- expect(policy.derive_mapper_from_object(Namespace::Nested::Rye.new)).to be(
47
- Namespace::RyeMapper
48
- )
49
- end
50
-
51
- it 'should take the non-qualified classname when looking for a collection mapper' do
52
- expect(policy.derive_mapper_from_object([Namespace::Nested::Rye.new])).to be(
53
- Namespace::RyeCollectionMapper
54
- )
55
- end
56
- end
24
+ context 'mapper_for options set' do
25
+ subject(:policy) { described_class.new(options) }
57
26
 
58
- context 'when trying to lookup CollectionMapper results in something other than an NameError' do
59
- let(:options) { { namespace: DislikesCollectionMapper } }
27
+ context 'when mapping a class' do
28
+ let(:options) { {mapper_rules: {home: HomeMapper, Soy => MyMappers::WheatMapper}} }
60
29
 
61
- it 'should propagate the error' do
62
- expect {
63
- policy.derive_mapper_from_object([])
64
- }.to raise_error
30
+ it 'should use the mapping' do
31
+ expect(policy.derive_mapper_from_object(Soy.new)).to be MyMappers::WheatMapper
32
+ end
65
33
  end
66
- end
67
34
 
68
- context 'when trying to lookup a specific collection mapper results in something other than an NameError' do
69
- let(:options) { { namespace: DislikesOtherMappers } }
35
+ context 'when mapping a symbol' do
36
+ let(:options) { {mapper_rules: {soy: SoyMapper}} }
70
37
 
71
- it 'should propagate the error' do
72
- expect {
73
- policy.derive_mapper_from_object([Namespace::Nested::Rye.new])
74
- }.to raise_error
38
+ it 'should use the mapping' do
39
+ expect(policy.derive_mapper_from_object(:soy)).to be SoyMapper
40
+ end
75
41
  end
76
- end
77
-
78
- context 'when a mapper exists for a superclass' do
79
- let(:options) { {namespace: MyMappers} }
80
42
 
81
- it 'should use the superclass mapper' do
82
- expect(policy.derive_mapper_from_object(Namespace::Nested::Mung.new)).to be(MyMappers::BeanMapper)
83
- end
84
- end
43
+ context 'when mapping a lambda' do
44
+ let(:user) { fake(logged_in?: true) }
45
+ let(:options) { {mapper_rules: {->(user){ user.logged_in? } => SoyMapper}} }
85
46
 
86
- context 'when no mapper is found' do
87
- it 'should give a nice message' do
88
- expect {
89
- policy.derive_mapper_from_object(Namespace::Nested::Mung.new)
90
- }.to raise_error /Failed to find a mapper for #<Namespace::Nested::Mung:0x\h+>. Did you mean to implement MungMapper\?/
47
+ it 'should use the mapping' do
48
+ expect(policy.derive_mapper_from_object(user)).to be SoyMapper
49
+ end
91
50
  end
92
51
  end
93
-
94
52
  end
@@ -1,5 +1,5 @@
1
1
  RSpec.describe Yaks::DefaultPolicy do
2
- subject(:policy) { described_class.new( options ) }
2
+ subject(:policy) { described_class.new(options) }
3
3
 
4
4
  let(:options) { {} }
5
5
  let(:association) { Yaks::Mapper::HasMany.create('shoes') }
@@ -12,7 +12,7 @@ RSpec.describe Yaks::DefaultPolicy do
12
12
  let(:options) { {foo: :bar} }
13
13
 
14
14
  it 'should merge default and given options' do
15
- expect(policy.options.values_at(:namespace, :foo)).to eql [Kernel, :bar]
15
+ expect(policy.options.values_at(:namespace, :foo)).to eql [Object, :bar]
16
16
  end
17
17
  end
18
18
 
@@ -39,7 +39,7 @@ RSpec.describe Yaks::DefaultPolicy do
39
39
  end
40
40
 
41
41
  describe '#derive_mapper_from_association' do
42
- let(:options) { { namespace: Namespace } }
42
+ let(:options) { {namespace: Namespace} }
43
43
 
44
44
  it 'should derive using the singular association name, and look inside the namespace' do
45
45
  expect(policy.derive_mapper_from_association(association)).to be Namespace::ShoeMapper
@@ -53,10 +53,9 @@ RSpec.describe Yaks::DefaultPolicy do
53
53
  end
54
54
 
55
55
  describe '#expand_rel' do
56
- let(:options) { { rel_template: 'http://foo/{?rel}' } }
56
+ let(:options) { {rel_template: 'http://foo/{?rel}'} }
57
57
  it 'should expand the given template' do
58
58
  expect(policy.expand_rel('rockets')).to eql 'http://foo/?rel=rockets'
59
59
  end
60
60
  end
61
-
62
61
  end
@@ -7,7 +7,7 @@ RSpec.describe Yaks::Format::CollectionJson do
7
7
  it { should deep_eql(load_json_fixture('plant_collection.collection')) }
8
8
  end
9
9
 
10
- context '#links?' do
10
+ describe '#links?' do
11
11
  context 'when resource is not a collection' do
12
12
  let(:resource) {
13
13
  Yaks::Resource.new(
@@ -52,7 +52,7 @@ RSpec.describe Yaks::Format::CollectionJson do
52
52
  end
53
53
  end
54
54
 
55
- context '#queries?' do
55
+ describe '#queries?' do
56
56
  let(:resource) {
57
57
  Yaks::Resource.new(
58
58
  attributes: {foo: 'fooval', bar: 'barval'},
@@ -124,7 +124,7 @@ RSpec.describe Yaks::Format::CollectionJson do
124
124
  end
125
125
  end
126
126
 
127
- context '#template?' do
127
+ describe '#template?' do
128
128
  context 'when no template form has been specified' do
129
129
  let(:format) {
130
130
  described_class.new
@@ -144,14 +144,14 @@ RSpec.describe Yaks::Format::CollectionJson do
144
144
 
145
145
  context 'when a template form has been specified' do
146
146
  let(:format) {
147
- described_class.new(:template => :template_form_name)
147
+ described_class.new(template: :template_form_name)
148
148
  }
149
149
 
150
150
  context 'and the form is not present' do
151
151
  let(:resource) {
152
152
  Yaks::Resource.new(
153
- attributes: {foo: 'fooval', bar: 'barval'},
154
- forms: [Yaks::Resource::Form.new(name: :not_the_form_name)]
153
+ attributes: {foo: 'fooval', bar: 'barval'},
154
+ forms: [Yaks::Resource::Form.new(name: :not_the_form_name)]
155
155
  )
156
156
  }
157
157
 
@@ -167,8 +167,8 @@ RSpec.describe Yaks::Format::CollectionJson do
167
167
  context 'and the form is present' do
168
168
  let(:resource) {
169
169
  Yaks::Resource.new(
170
- attributes: {foo: 'fooval', bar: 'barval'},
171
- forms: [Yaks::Resource::Form.new(name: :template_form_name)]
170
+ attributes: {foo: 'fooval', bar: 'barval'},
171
+ forms: [Yaks::Resource::Form.new(name: :template_form_name)]
172
172
  )
173
173
  }
174
174
 
@@ -183,7 +183,7 @@ RSpec.describe Yaks::Format::CollectionJson do
183
183
  end
184
184
  end
185
185
 
186
- context 'serialize_links' do
186
+ describe '#serialize_links' do
187
187
  context 'without title' do
188
188
  let(:resource) {
189
189
  Yaks::Resource.new(
@@ -203,10 +203,10 @@ RSpec.describe Yaks::Format::CollectionJson do
203
203
  "items" => [
204
204
  {
205
205
  "data" => [
206
- { "name"=>"foo", "value"=>"fooval" },
207
- { "name"=>"bar", "value"=>"barval" }
206
+ {"name" => "foo", "value" => "fooval"},
207
+ {"name" => "bar", "value" => "barval"}
208
208
  ],
209
- "links" => [{"rel"=>"the_rel", "href"=>"the_uri"}]
209
+ "links" => [{"rel" => "the_rel", "href" => "the_uri"}]
210
210
  }
211
211
  ]
212
212
  }
@@ -233,10 +233,10 @@ RSpec.describe Yaks::Format::CollectionJson do
233
233
  "items" => [
234
234
  {
235
235
  "data" => [
236
- { "name"=>"foo", "value"=>"fooval" },
237
- { "name"=>"bar", "value"=>"barval" }
236
+ {"name" => "foo", "value" => "fooval"},
237
+ {"name" => "bar", "value" => "barval"}
238
238
  ],
239
- "links" => [{"name"=>"the_name", "rel"=>"the_rel", "href"=>"the_uri"}]
239
+ "links" => [{"name" => "the_name", "rel" => "the_rel", "href" => "the_uri"}]
240
240
  }
241
241
  ]
242
242
  }
@@ -245,7 +245,7 @@ RSpec.describe Yaks::Format::CollectionJson do
245
245
  end
246
246
  end
247
247
 
248
- context 'serialize_queries' do
248
+ describe '#serialize_queries' do
249
249
  let(:resource) {
250
250
  Yaks::Resource.new(
251
251
  attributes: {foo: 'fooval', bar: 'barval'},
@@ -277,13 +277,13 @@ RSpec.describe Yaks::Format::CollectionJson do
277
277
  "items" => [
278
278
  {
279
279
  "data" => [
280
- { "name"=>"foo", "value"=>"fooval" },
281
- { "name"=>"bar", "value"=>"barval" }
280
+ {"name" => "foo", "value" => "fooval"},
281
+ {"name" => "bar", "value" => "barval"}
282
282
  ]
283
283
  }
284
284
  ],
285
285
  "queries" => [
286
- { "href"=>"/foo", "rel"=>"search" }
286
+ {"href" => "/foo", "rel" => "search"}
287
287
  ]
288
288
  }
289
289
  )
@@ -315,17 +315,16 @@ RSpec.describe Yaks::Format::CollectionJson do
315
315
  "items" => [
316
316
  {
317
317
  "data" => [
318
- { "name"=>"foo", "value"=>"fooval" },
319
- { "name"=>"bar", "value"=>"barval" }
318
+ {"name" => "foo", "value" => "fooval"},
319
+ {"name" => "bar", "value" => "barval"}
320
320
  ]
321
321
  }
322
322
  ],
323
323
  "queries" => [
324
- { "href"=>"/foo", "rel"=>"search", "prompt"=>"My query prompt",
325
- "data"=>
326
- [
327
- { "name"=>"foo", "value"=>"" },
328
- { "name"=>"bar", "value"=>"", "prompt"=>"My Bar Field" }
324
+ {"href" => "/foo", "rel" => "search", "prompt" => "My query prompt",
325
+ "data" => [
326
+ {"name" => "foo", "value" => ""},
327
+ {"name" => "bar", "value" => "", "prompt" => "My Bar Field"}
329
328
  ]
330
329
  }
331
330
  ]
@@ -336,9 +335,9 @@ RSpec.describe Yaks::Format::CollectionJson do
336
335
  end
337
336
  end
338
337
 
339
- context 'serialize_template' do
338
+ describe '#serialize_template' do
340
339
  let(:format) {
341
- described_class.new(:template => :form_for_new)
340
+ described_class.new(template: :form_for_new)
342
341
  }
343
342
 
344
343
  let(:resource) {
@@ -367,15 +366,15 @@ RSpec.describe Yaks::Format::CollectionJson do
367
366
  "items" => [
368
367
  {
369
368
  "data" => [
370
- { "name"=>"foo", "value"=>"fooval" },
371
- { "name"=>"bar", "value"=>"barval" }
369
+ {"name" => "foo", "value" => "fooval"},
370
+ {"name" => "bar", "value" => "barval"}
372
371
  ]
373
372
  }
374
373
  ],
375
374
  "template" => {
376
375
  "data" => [
377
- { "name"=>"foo", "value"=>"", "prompt"=>"My Foo Field" },
378
- { "name"=>"bar", "value"=>"", "prompt"=>"My Bar Field" }
376
+ {"name" => "foo", "value" => "", "prompt" => "My Foo Field"},
377
+ {"name" => "bar", "value" => "", "prompt" => "My Bar Field"}
379
378
  ]
380
379
  }
381
380
  }
@@ -398,15 +397,15 @@ RSpec.describe Yaks::Format::CollectionJson do
398
397
  "items" => [
399
398
  {
400
399
  "data" => [
401
- { "name"=>"foo", "value"=>"fooval" },
402
- { "name"=>"bar", "value"=>"barval" }
400
+ {"name" => "foo", "value" => "fooval"},
401
+ {"name" => "bar", "value" => "barval"}
403
402
  ]
404
403
  }
405
404
  ],
406
405
  "template" => {
407
406
  "data" => [
408
- { "name"=>"foo", "value"=>"" },
409
- { "name"=>"bar", "value"=>"" }
407
+ {"name" => "foo", "value" => ""},
408
+ {"name" => "bar", "value" => ""}
410
409
  ]
411
410
  }
412
411
  }