Skip to content

Commit 515980b

Browse files
committed
Only call save if model implements save
Eliminates the need to create a stub save method on a model that doesn’t use ActiveRecord.
1 parent e81389e commit 515980b

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

lib/jsonapi/resource.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ def change(callback)
5151
if @save_needed || is_new?
5252
deferred = true if save == :deferred
5353
end
54-
5554
end
5655
end
5756

@@ -123,7 +122,12 @@ def _save
123122
raise JSONAPI::Exceptions::ValidationErrors.new(@model.errors.messages)
124123
end
125124

126-
saved = @model.save
125+
if defined? @model.save
126+
saved = @model.save
127+
else
128+
saved = true
129+
end
130+
127131
@save_needed = !saved
128132

129133
return :completed

test/fixtures/active_record.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,10 +262,6 @@ def destroy
262262
$breed_data.remove(@id)
263263
end
264264

265-
def save
266-
true
267-
end
268-
269265
def valid?
270266
@errors.clear
271267
if name.is_a?(String) && name.length > 0

0 commit comments

Comments
 (0)