File tree Expand file tree Collapse file tree 3 files changed +12
-9
lines changed
lib/jsonapi_errorable/serializers Expand file tree Collapse file tree 3 files changed +12
-9
lines changed Original file line number Diff line number Diff line change @@ -18,7 +18,6 @@ Gem::Specification.new do |spec|
18
18
spec . executables = spec . files . grep ( %r{^exe/} ) { |f | File . basename ( f ) }
19
19
spec . require_paths = [ "lib" ]
20
20
21
- spec . add_dependency 'rails' , [ ">= 4.1" , "< 6" ]
22
21
spec . add_dependency 'jsonapi-serializable' , '~> 0.1'
23
22
24
23
spec . add_development_dependency "bundler" , "~> 1.11"
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ module Serializers
3
3
class Validation
4
4
attr_reader :object
5
5
6
- def initialize ( object , relationship_params , relationship_message = { } )
6
+ def initialize ( object , relationship_params = { } , relationship_message = { } )
7
7
@object = object
8
8
@relationship_params = relationship_params || { }
9
9
@relationship_message = relationship_message
@@ -33,7 +33,7 @@ def errors
33
33
end
34
34
35
35
def relationship? ( name )
36
- return false unless activerecord ?
36
+ return false unless activemodel ?
37
37
38
38
relation_names = object . class . reflect_on_all_associations . map ( &:name )
39
39
relation_names . include? ( name )
@@ -56,8 +56,8 @@ def pointer_for(object, name)
56
56
end
57
57
end
58
58
59
- def activerecord ?
60
- object . is_a? ( ActiveRecord :: Base )
59
+ def activemodel ?
60
+ object . class . respond_to? ( :reflect_on_all_associations )
61
61
end
62
62
63
63
def relationship_errors ( relationship_params )
Original file line number Diff line number Diff line change 7
7
let ( :instance ) { described_class . new ( object ) }
8
8
9
9
before do
10
- allow ( instance ) . to receive ( :activerecord ? ) { true }
10
+ allow ( instance ) . to receive ( :activemodel ? ) { true }
11
11
allow ( object . class )
12
12
. to receive ( :reflect_on_all_associations )
13
13
. and_return ( [ double ( name : :pets ) ] )
18
18
subject { instance . errors }
19
19
20
20
before do
21
- allow ( object ) . to receive ( :respond_to? ) . with ( :username ) { true }
21
+ allow ( object ) . to receive ( :respond_to? ) . with ( :errors ) { true }
22
22
end
23
23
24
24
context 'when the error is on an attribute' do
25
+ before do
26
+ allow ( object ) . to receive ( :respond_to? ) . with ( :username ) { true }
27
+ end
28
+
25
29
it 'renders valid JSONAPI error format' do
26
30
expect ( subject ) . to eq (
27
31
[
61
65
62
66
context 'but the object is not activerecord' do
63
67
before do
64
- allow ( instance ) . to receive ( :activerecord ? ) { false }
68
+ allow ( instance ) . to receive ( :activemodel ? ) { false }
65
69
allow ( object ) . to receive ( :respond_to? ) . with ( :pets ) { true }
66
70
end
67
71
146
150
147
151
context 'when not activerecord' do
148
152
before do
149
- allow ( instance ) . to receive ( :activerecord ? ) { false }
153
+ allow ( instance ) . to receive ( :activemodel ? ) { false }
150
154
end
151
155
152
156
it { is_expected . to be ( false ) }
You can’t perform that action at this time.
0 commit comments