grape-roar 0.4.1 → 0.5.0

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 (46) hide show
  1. checksums.yaml +5 -5
  2. data/.github/FUNDING.yml +2 -0
  3. data/.github/dependabot.yml +6 -0
  4. data/.github/workflows/danger.yml +22 -0
  5. data/.github/workflows/lint.yml +15 -0
  6. data/.github/workflows/test-activerecord.yml +34 -0
  7. data/.github/workflows/test-mongodb.yml +33 -0
  8. data/.github/workflows/test.yml +19 -0
  9. data/.rubocop.yml +7 -6
  10. data/.rubocop_todo.yml +163 -21
  11. data/CHANGELOG.md +13 -11
  12. data/Dangerfile +4 -0
  13. data/Gemfile +16 -8
  14. data/Gemfile.danger +6 -0
  15. data/README.md +41 -22
  16. data/grape-roar.gemspec +2 -3
  17. data/lib/grape/roar/extensions/relations/adapters/base.rb +1 -1
  18. data/lib/grape/roar/extensions/relations/adapters/mongoid.rb +1 -1
  19. data/lib/grape/roar/extensions/relations/adapters.rb +2 -2
  20. data/lib/grape/roar/extensions/relations/mapper.rb +7 -2
  21. data/lib/grape/roar/extensions/relations/validations/active_record.rb +11 -38
  22. data/lib/grape/roar/extensions/relations/validations/mongoid/6.rb +48 -0
  23. data/lib/grape/roar/extensions/relations/validations/mongoid/7.rb +75 -0
  24. data/lib/grape/roar/extensions/relations/validations/mongoid.rb +5 -84
  25. data/lib/grape/roar/representer.rb +4 -1
  26. data/lib/grape/roar/version.rb +1 -1
  27. data/spec/decorator_spec.rb +0 -2
  28. data/spec/extensions/relations/adapters/active_record_spec.rb +21 -17
  29. data/spec/extensions/relations/adapters/adapters_module_spec.rb +3 -2
  30. data/spec/extensions/relations/adapters/mongoid_spec.rb +21 -17
  31. data/spec/extensions/relations/dsl_methods_spec.rb +14 -14
  32. data/spec/extensions/relations/mapper_spec.rb +10 -10
  33. data/spec/extensions/relations/validations/active_record_spec.rb +35 -32
  34. data/spec/extensions/relations/validations/mongoid_spec.rb +64 -61
  35. data/spec/nested_representer_spec.rb +0 -2
  36. data/spec/present_with_spec.rb +0 -2
  37. data/spec/relations_spec.rb +6 -5
  38. data/spec/representer_spec.rb +34 -8
  39. data/spec/spec_helper.rb +6 -2
  40. data/spec/support/all/article_representer.rb +1 -0
  41. data/spec/support/all/grape_app_context.rb +0 -2
  42. metadata +19 -12
  43. data/.travis.yml +0 -36
  44. data/Appraisals +0 -9
  45. data/gemfiles/with_activerecord.gemfile +0 -22
  46. data/gemfiles/with_mongoid.gemfile +0 -22
@@ -34,6 +34,7 @@ module Grape
34
34
  def find_representer(base, target_name, const)
35
35
  const = base.const_get(const)
36
36
  return false if const.nil? || !const.is_a?(Module)
37
+
37
38
  (const < ::Roar::JSON::HAL) && const.name
38
39
  .downcase
39
40
  .include?(target_name.singularize)
@@ -41,6 +42,7 @@ module Grape
41
42
 
42
43
  def map_collection(relation, opts)
43
44
  return entity.link_relation(relation, true) unless opts.fetch(:embedded, false)
45
+
44
46
  entity.collection(relation, opts)
45
47
  end
46
48
 
@@ -50,8 +52,9 @@ module Grape
50
52
  elsif adapter.single_entity_methods
51
53
  .include?(opts[:relation_kind]) || opts[:relation_kind] == :self
52
54
  :map_single_entity
53
- else raise Exceptions::UnsupportedRelationError,
54
- 'No such relation supported'
55
+ else
56
+ raise Exceptions::UnsupportedRelationError,
57
+ 'No such relation supported'
55
58
  end
56
59
 
57
60
  send(map, relation, opts)
@@ -61,6 +64,7 @@ module Grape
61
64
  def map_single_entity(relation, opts)
62
65
  return entity.map_self_url if opts[:relation_kind] == :self
63
66
  return entity.link_relation(relation) unless opts.fetch(:embedded, false)
67
+
64
68
  entity.property(relation, opts)
65
69
  end
66
70
 
@@ -80,6 +84,7 @@ module Grape
80
84
  def validate_relation(relation, kind)
81
85
  validator_method = "#{kind}_valid?"
82
86
  return true unless adapter.respond_to?(validator_method)
87
+
83
88
  adapter.send(validator_method, relation.to_s)
84
89
  end
85
90
  end
@@ -9,55 +9,28 @@ module Grape
9
9
  include Validations::Misc
10
10
 
11
11
  def belongs_to_valid?(relation)
12
- relation = klass.reflections[relation]
13
-
14
- return true if relation.is_a?(
15
- ::ActiveRecord::Reflection::BelongsToReflection
16
- )
17
-
18
- invalid_relation(
19
- ::ActiveRecord::Reflection::BelongsToReflection,
20
- relation.class
21
- )
12
+ _valid_relation? relation, ::ActiveRecord::Reflection::BelongsToReflection
22
13
  end
23
14
 
24
15
  def has_many_valid?(relation)
25
- relation = klass.reflections[relation]
26
-
27
- return true if relation.is_a?(
28
- ::ActiveRecord::Reflection::HasManyReflection
29
- )
30
-
31
- invalid_relation(
32
- ::ActiveRecord::Reflection::HasManyReflection,
33
- relation.class
34
- )
16
+ _valid_relation? relation, ::ActiveRecord::Reflection::HasManyReflection
35
17
  end
36
18
 
37
19
  def has_and_belongs_to_many_valid?(relation)
38
- relation = klass.reflections[relation]
39
-
40
- return true if relation.is_a?(
41
- ::ActiveRecord::Reflection::HasAndBelongsToManyReflection
42
- )
43
-
44
- invalid_relation(
45
- ::ActiveRecord::Reflection::HasAndBelongsToManyReflection,
46
- relation.class
47
- )
20
+ _valid_relation? relation, ::ActiveRecord::Reflection::HasAndBelongsToManyReflection
48
21
  end
49
22
 
50
23
  def has_one_valid?(relation)
51
- relation = klass.reflections[relation]
24
+ _valid_relation? relation, ::ActiveRecord::Reflection::HasOneReflection
25
+ end
26
+
27
+ private
52
28
 
53
- return true if relation.is_a?(
54
- ::ActiveRecord::Reflection::HasOneReflection
55
- )
29
+ def _valid_relation?(relation, relation_klass)
30
+ relation = klass.reflections[relation]
31
+ return true if relation.is_a?(relation_klass)
56
32
 
57
- invalid_relation(
58
- ::ActiveRecord::Reflection::HasOneReflection,
59
- relation.class
60
- )
33
+ invalid_relation(relation_klass, relation.class)
61
34
  end
62
35
  end
63
36
  end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Grape
4
+ module Roar
5
+ module Extensions
6
+ module Relations
7
+ module Validations
8
+ module Mongoid
9
+ include Validations::Misc
10
+
11
+ def belongs_to_valid?(relation)
12
+ _valid_relation? relation, ::Mongoid::Relations::Referenced::In
13
+ end
14
+
15
+ def embeds_many_valid?(relation)
16
+ _valid_relation? relation, ::Mongoid::Relations::Embedded::Many
17
+ end
18
+
19
+ def embeds_one_valid?(relation)
20
+ _valid_relation? relation, ::Mongoid::Relations::Embedded::One
21
+ end
22
+
23
+ def has_many_valid?(relation)
24
+ _valid_relation? relation, ::Mongoid::Relations::Referenced::Many
25
+ end
26
+
27
+ def has_and_belongs_to_many_valid?(relation)
28
+ _valid_relation? relation, ::Mongoid::Relations::Referenced::ManyToMany
29
+ end
30
+
31
+ def has_one_valid?(relation)
32
+ _valid_relation? relation, ::Mongoid::Relations::Referenced::One
33
+ end
34
+
35
+ private
36
+
37
+ def _valid_relation?(relation, relation_klass)
38
+ relation = klass.reflect_on_association(relation)
39
+ return true if relation[:relation] == relation_klass
40
+
41
+ invalid_relation(relation_klass, relation[:relation])
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Grape
4
+ module Roar
5
+ module Extensions
6
+ module Relations
7
+ module Validations
8
+ module Mongoid
9
+ include Validations::Misc
10
+
11
+ def belongs_to_valid?(relation)
12
+ _valid_relation?(
13
+ relation,
14
+ ::Mongoid::Association::Referenced::BelongsTo,
15
+ ::Mongoid::Association::Referenced::BelongsTo::Proxy
16
+ )
17
+ end
18
+
19
+ def embeds_many_valid?(relation)
20
+ _valid_relation?(
21
+ relation,
22
+ ::Mongoid::Association::Embedded::EmbedsMany,
23
+ ::Mongoid::Association::Embedded::EmbedsMany::Proxy
24
+ )
25
+ end
26
+
27
+ def embeds_one_valid?(relation)
28
+ _valid_relation?(
29
+ relation,
30
+ ::Mongoid::Association::Embedded::EmbedsOne,
31
+ ::Mongoid::Association::Embedded::EmbedsOne::Proxy
32
+ )
33
+ end
34
+
35
+ def has_many_valid?(relation)
36
+ _valid_relation?(
37
+ relation,
38
+ ::Mongoid::Association::Referenced::HasMany,
39
+ ::Mongoid::Association::Referenced::HasMany::Proxy
40
+ )
41
+ end
42
+
43
+ def has_and_belongs_to_many_valid?(relation)
44
+ _valid_relation?(
45
+ relation,
46
+ ::Mongoid::Association::Referenced::HasAndBelongsToMany,
47
+ ::Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy
48
+ )
49
+ end
50
+
51
+ def has_one_valid?(relation)
52
+ _valid_relation?(
53
+ relation,
54
+ ::Mongoid::Association::Referenced::HasOne,
55
+ ::Mongoid::Association::Referenced::HasOne::Proxy
56
+ )
57
+ end
58
+
59
+ private
60
+
61
+ def _valid_relation?(relation, relation_klass, relation_proxy_klass)
62
+ relation = klass.reflect_on_association(relation)
63
+
64
+ related = relation.is_a?(Hash) ? relation[:relation] : relation.relation
65
+
66
+ return true if related == relation_klass || related == relation_proxy_klass
67
+
68
+ invalid_relation(relation.class, related)
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -1,88 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Grape
4
- module Roar
5
- module Extensions
6
- module Relations
7
- module Validations
8
- module Mongoid
9
- include Validations::Misc
10
-
11
- def belongs_to_valid?(relation)
12
- relation = klass.reflect_on_association(relation)
13
-
14
- return true if relation[:relation] ==
15
- ::Mongoid::Relations::Referenced::In
16
-
17
- invalid_relation(
18
- ::Mongoid::Relations::Referenced::In, relation[:relation]
19
- )
20
- end
21
-
22
- def embeds_many_valid?(relation)
23
- relation = klass.reflect_on_association(relation)
24
-
25
- return true if relation[:relation] ==
26
- ::Mongoid::Relations::Embedded::Many
27
-
28
- invalid_relation(
29
- ::Mongoid::Relations::Embedded::Many, relation[:relation]
30
- )
31
- end
32
-
33
- def embeds_one_valid?(relation)
34
- relation = klass.reflect_on_association(relation)
35
-
36
- return true if relation[:relation] ==
37
- ::Mongoid::Relations::Embedded::One
38
-
39
- invalid_relation(
40
- ::Mongoid::Relations::Embedded::One, relation[:relation]
41
- )
42
- end
43
-
44
- # rubocop:disable Style/PredicateName
45
- def has_many_valid?(relation)
46
- relation = klass.reflect_on_association(relation)
47
-
48
- return true if relation[:relation] ==
49
- ::Mongoid::Relations::Referenced::Many
50
-
51
- invalid_relation(
52
- ::Mongoid::Relations::Referenced::Many, relation[:relation]
53
- )
54
- end
55
- # rubocop:enable Style/PredicateName
56
-
57
- # rubocop:disable Style/PredicateName
58
- def has_and_belongs_to_many_valid?(relation)
59
- relation = klass.reflect_on_association(relation)
60
-
61
- return true if relation[:relation] ==
62
- ::Mongoid::Relations::Referenced::ManyToMany
63
-
64
- invalid_relation(
65
- ::Mongoid::Relations::Referenced::ManyToMany,
66
- relation[:relation]
67
- )
68
- end
69
- # rubocop:enable Style/PredicateName
70
-
71
- # rubocop:disable Style/PredicateName
72
- def has_one_valid?(relation)
73
- relation = klass.reflect_on_association(relation)
74
-
75
- return true if relation[:relation] ==
76
- ::Mongoid::Relations::Referenced::One
77
-
78
- invalid_relation(
79
- ::Mongoid::Relations::Referenced::One, relation[:relation]
80
- )
81
- end
82
- # rubocop:enable Style/PredicateName
83
- end
84
- end
85
- end
86
- end
3
+ if defined?(Mongoid)
4
+ if Gem::Version.new(Mongoid::VERSION) < Gem::Version.new('7')
5
+ require_relative 'mongoid/6'
6
+ else
7
+ require_relative 'mongoid/7'
87
8
  end
88
9
  end
@@ -9,7 +9,10 @@ module Grape
9
9
 
10
10
  module ClassMethods
11
11
  def represent(object, _options = {})
12
- object.extend self
12
+ # See https://github.com/ruby-grape/grape-roar/issues/16
13
+ raise TypeError if object.singleton_class == object.class
14
+
15
+ object.extend(self)
13
16
  object
14
17
  end
15
18
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Grape
4
4
  module Roar
5
- VERSION = '0.4.1'
5
+ VERSION = '0.5.0'
6
6
  end
7
7
  end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
-
4
-
5
3
  describe Grape::Roar::Decorator do
6
4
  subject do
7
5
  Class.new(Grape::API)
@@ -1,26 +1,30 @@
1
1
  # frozen_string_literal: true
2
- describe Grape::Roar::Extensions::Relations::Adapters::ActiveRecord, active_record: true do
3
- let(:model) { Class.new(ActiveRecord::Base) }
4
- subject { described_class.new(model) }
5
2
 
6
- context '.valid_for?' do
7
- it 'is only valid for ActiveRecord::Base descendants' do
8
- expect(described_class.valid_for?(model)).to eql(true)
9
- expect(described_class.valid_for?('foo')).to eql(false)
3
+ if defined?(ActiveRecord)
4
+ describe Grape::Roar::Extensions::Relations::Adapters::ActiveRecord, :activerecord do
5
+ let(:model) { Class.new(ActiveRecord::Base) }
6
+
7
+ subject { described_class.new(model) }
8
+
9
+ describe '.valid_for?' do
10
+ it 'is only valid for ActiveRecord::Base descendants' do
11
+ expect(described_class.valid_for?(model)).to eql(true)
12
+ expect(described_class.valid_for?('foo')).to eql(false)
13
+ end
10
14
  end
11
- end
12
15
 
13
- context '#collection_methods' do
14
- it 'should return all collection methods' do
15
- expect(subject.collection_methods)
16
- .to match_array(%i[has_many has_and_belongs_to_many])
16
+ describe '#collection_methods' do
17
+ it 'returns all collection methods' do
18
+ expect(subject.collection_methods)
19
+ .to match_array(%i[has_many has_and_belongs_to_many])
20
+ end
17
21
  end
18
- end
19
22
 
20
- context '#single_entity_methods' do
21
- it 'should return all single entity methods' do
22
- expect(subject.single_entity_methods)
23
- .to match_array(%i[has_one belongs_to])
23
+ describe '#single_entity_methods' do
24
+ it 'returns all single entity methods' do
25
+ expect(subject.single_entity_methods)
26
+ .to match_array(%i[has_one belongs_to])
27
+ end
24
28
  end
25
29
  end
26
30
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
- describe Grape::Roar::Extensions::Relations::Adapters, active_record: true do
3
- context '.for' do
2
+
3
+ describe Grape::Roar::Extensions::Relations::Adapters, :activerecord do
4
+ describe '.for' do
4
5
  let(:model) { Class.new(ActiveRecord::Base) }
5
6
 
6
7
  it 'looks up the correct adapter for a given class' do
@@ -1,26 +1,30 @@
1
1
  # frozen_string_literal: true
2
- describe Grape::Roar::Extensions::Relations::Adapters::Mongoid, mongoid: true do
3
- let(:model) { Class.new.tap { |c| c.include(::Mongoid::Document) } }
4
- subject { described_class.new(model) }
5
2
 
6
- context '.valid_for?' do
7
- it 'is only valid for classes that mixed in Mongoid::Document' do
8
- expect(described_class.valid_for?(model)).to eql(true)
9
- expect(described_class.valid_for?('foo')).to eql(false)
3
+ if defined?(Mongoid)
4
+ describe Grape::Roar::Extensions::Relations::Adapters::Mongoid, :mongoid do
5
+ let(:model) { Class.new.tap { |c| c.include(Mongoid::Document) } }
6
+
7
+ subject { described_class.new(model) }
8
+
9
+ describe '.valid_for?' do
10
+ it 'is only valid for classes that mixed in Mongoid::Document' do
11
+ expect(described_class.valid_for?(model)).to eql(true)
12
+ expect(described_class.valid_for?('foo')).to eql(false)
13
+ end
10
14
  end
11
- end
12
15
 
13
- context '#collection_methods' do
14
- it 'should return all collection methods' do
15
- expect(subject.collection_methods)
16
- .to match_array(%i[embeds_many has_many has_and_belongs_to_many])
16
+ describe '#collection_methods' do
17
+ it 'returns all collection methods' do
18
+ expect(subject.collection_methods)
19
+ .to match_array(%i[embeds_many has_many has_and_belongs_to_many])
20
+ end
17
21
  end
18
- end
19
22
 
20
- context '#single_entity_methods' do
21
- it 'should return all single entity methods' do
22
- expect(subject.single_entity_methods)
23
- .to match_array(%i[has_one belongs_to embeds_one])
23
+ describe '#single_entity_methods' do
24
+ it 'returns all single entity methods' do
25
+ expect(subject.single_entity_methods)
26
+ .to match_array(%i[has_one belongs_to embeds_one])
27
+ end
24
28
  end
25
29
  end
26
30
  end
@@ -5,7 +5,7 @@ describe Grape::Roar::Extensions::Relations::DSLMethods do
5
5
  Class.new.tap { |c| c.singleton_class.include(described_class) }
6
6
  end
7
7
 
8
- context '#link_relation' do
8
+ describe '#link_relation' do
9
9
  let(:relation) { double }
10
10
  let(:collection) { false }
11
11
 
@@ -29,7 +29,7 @@ describe Grape::Roar::Extensions::Relations::DSLMethods do
29
29
  end
30
30
  end
31
31
 
32
- context '#name_for_represented' do
32
+ describe '#name_for_represented' do
33
33
  let(:represented) { double }
34
34
 
35
35
  after { subject.name_for_represented(represented) }
@@ -49,7 +49,7 @@ describe Grape::Roar::Extensions::Relations::DSLMethods do
49
49
  .and_return(relational_mapper)
50
50
  end
51
51
 
52
- context '#relation' do
52
+ describe '#relation' do
53
53
  let(:relation_name) { double }
54
54
  let(:relation_kind) { :has_many }
55
55
  let(:opts) { {} }
@@ -63,18 +63,18 @@ describe Grape::Roar::Extensions::Relations::DSLMethods do
63
63
  end
64
64
  end
65
65
 
66
- context '#link_self' do
66
+ describe '#link_self' do
67
67
  after { subject.link_self }
68
68
 
69
69
  it 'calls the method correctly' do
70
70
  expect(relational_mapper).to receive(:[]=).with(
71
- :self, relation_kind: :self
71
+ :self, { relation_kind: :self }
72
72
  )
73
73
  end
74
74
  end
75
75
  end
76
76
 
77
- context '#map_base_url' do
77
+ describe '#map_base_url' do
78
78
  let(:grape_request) do
79
79
  OpenStruct.new(base_url: 'foo/', script_name: 'v1')
80
80
  end
@@ -93,14 +93,14 @@ describe Grape::Roar::Extensions::Relations::DSLMethods do
93
93
  context 'with user provided block' do
94
94
  let(:block) { proc {} }
95
95
 
96
- it 'should return the user block' do
96
+ it 'returns the user block' do
97
97
  subject.map_base_url(&block)
98
98
  expect(subject.map_base_url).to eql(block)
99
99
  end
100
100
  end
101
101
  end
102
102
 
103
- context '#map_self_url' do
103
+ describe '#map_self_url' do
104
104
  after { subject.map_self_url }
105
105
 
106
106
  it 'calls the correct method' do
@@ -108,7 +108,7 @@ describe Grape::Roar::Extensions::Relations::DSLMethods do
108
108
  end
109
109
  end
110
110
 
111
- context '#map_resource_path' do
111
+ describe '#map_resource_path' do
112
112
  let(:object) { OpenStruct.new(id: 4) }
113
113
  let(:opts) { double }
114
114
  let(:relation) { 'baz' }
@@ -122,14 +122,14 @@ describe Grape::Roar::Extensions::Relations::DSLMethods do
122
122
  context 'with user provided block' do
123
123
  let(:block) { proc {} }
124
124
 
125
- it 'should return the user block' do
125
+ it 'returns the user block' do
126
126
  subject.map_resource_path(&block)
127
127
  expect(subject.map_resource_path).to eql(block)
128
128
  end
129
129
  end
130
130
  end
131
131
 
132
- context '#represent' do
132
+ describe '#represent' do
133
133
  let(:object) { double }
134
134
  let(:options) { double }
135
135
 
@@ -142,7 +142,7 @@ describe Grape::Roar::Extensions::Relations::DSLMethods do
142
142
 
143
143
  after { subject.represent(object, options) }
144
144
 
145
- it 'should map relations and invoke super' do
145
+ it 'maps relations and invoke super' do
146
146
  expect(subject).to receive(:map_relations).with(object)
147
147
  expect(subject.superclass).to receive(:represent).with(object, options)
148
148
  end
@@ -150,8 +150,8 @@ describe Grape::Roar::Extensions::Relations::DSLMethods do
150
150
  context 'with relations mapped' do
151
151
  let(:relations_mapped) { true }
152
152
 
153
- it 'should not map relations and invoke super' do
154
- expect(subject).to_not receive(:map_relations).with(object)
153
+ it 'does not map relations and invoke super' do
154
+ expect(subject).not_to receive(:map_relations).with(object)
155
155
  expect(subject.superclass).to receive(:represent).with(object, options)
156
156
  end
157
157
  end
@@ -1,12 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  describe Grape::Roar::Extensions::Relations::Mapper do
4
+ subject { described_class.new(entity) }
5
+
4
6
  let(:entity) { double }
5
7
  let(:klass) { double }
6
8
 
7
- subject { described_class.new(entity) }
8
-
9
- context '#initialize' do
9
+ describe '#initialize' do
10
10
  it 'assigns the correct variables' do
11
11
  expect(subject.instance_variable_get(:@entity)).to eql(entity)
12
12
  expect(subject.instance_variable_get(:@config)).to eql({})
@@ -14,7 +14,7 @@ describe Grape::Roar::Extensions::Relations::Mapper do
14
14
  end
15
15
  end
16
16
 
17
- context '#adapter' do
17
+ describe '#adapter' do
18
18
  let(:klass) { class_double('ActiveRecord::Base') }
19
19
 
20
20
  before do
@@ -23,18 +23,18 @@ describe Grape::Roar::Extensions::Relations::Mapper do
23
23
 
24
24
  after { subject.adapter }
25
25
 
26
- it 'should call the correct method' do
26
+ it 'calls the correct method' do
27
27
  expect(Grape::Roar::Extensions::Relations::Adapters)
28
28
  .to receive(:for).with(klass)
29
29
  end
30
30
  end
31
31
 
32
- context '#decorate' do
32
+ describe '#decorate' do
33
33
  let(:adapter) { double }
34
34
  let(:config) do
35
35
  { test_single: {
36
- relation_kind: :belongs_to, embedded: true, misc_opt: 'foo'
37
- },
36
+ relation_kind: :belongs_to, embedded: true, misc_opt: 'foo'
37
+ },
38
38
  test_collection: {
39
39
  relation_kind: :has_many, embedded: true, misc_opt: 'baz'
40
40
  } }
@@ -52,7 +52,7 @@ describe Grape::Roar::Extensions::Relations::Mapper do
52
52
  subject.instance_variable_set(:@config, config)
53
53
  end
54
54
 
55
- it 'should correctly decorate the entity' do
55
+ it 'correctlies decorate the entity' do
56
56
  expect(adapter).to receive(:belongs_to_valid?).with(
57
57
  'test_single'
58
58
  ).and_return(true)
@@ -78,7 +78,7 @@ describe Grape::Roar::Extensions::Relations::Mapper do
78
78
  { test_single: { relation_kind: :has_baz, misc_opt: 'foo' } }
79
79
  end
80
80
 
81
- it 'will raise the correct exception' do
81
+ it 'raises the correct exception' do
82
82
  expect { subject.decorate(klass) }.to raise_error(
83
83
  Grape::Roar::Extensions::Relations::Exceptions::UnsupportedRelationError
84
84
  )