Skip to content

Commit 392b38d

Browse files
committed
made gem independent from activerecord
1 parent 7c39ac5 commit 392b38d

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

jsonapi_errorable.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
1818
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
1919
spec.require_paths = ["lib"]
2020

21-
spec.add_dependency 'rails', [">= 4.1", "< 6"]
21+
spec.add_dependency 'activemodel', [">= 4.1", "< 6"]
2222
spec.add_dependency 'jsonapi-serializable', '~> 0.1'
2323

2424
spec.add_development_dependency "bundler", "~> 1.11"

lib/jsonapi_errorable/serializers/validation.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def errors
3333
end
3434

3535
def relationship?(name)
36-
return false unless activerecord?
36+
return false unless activemodel?
3737

3838
relation_names = object.class.reflect_on_all_associations.map(&:name)
3939
relation_names.include?(name)
@@ -56,8 +56,8 @@ def pointer_for(object, name)
5656
end
5757
end
5858

59-
def activerecord?
60-
object.is_a?(ActiveRecord::Base)
59+
def activemodel?
60+
object.class.respond_to?(:reflect_on_all_associations)
6161
end
6262

6363
def relationship_errors(relationship_params)

spec/serializers/serializable_validation_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
let(:instance) { described_class.new(object) }
88

99
before do
10-
allow(instance).to receive(:activerecord?) { true }
10+
allow(instance).to receive(:activemodel?) { true }
1111
allow(object.class)
1212
.to receive(:reflect_on_all_associations)
1313
.and_return([double(name: :pets)])
@@ -65,7 +65,7 @@
6565

6666
context 'but the object is not activerecord' do
6767
before do
68-
allow(instance).to receive(:activerecord?) { false }
68+
allow(instance).to receive(:activemodel?) { false }
6969
allow(object).to receive(:respond_to?).with(:pets) { true }
7070
end
7171

@@ -150,7 +150,7 @@
150150

151151
context 'when not activerecord' do
152152
before do
153-
allow(instance).to receive(:activerecord?) { false }
153+
allow(instance).to receive(:activemodel?) { false }
154154
end
155155

156156
it { is_expected.to be(false) }

0 commit comments

Comments
 (0)