Skip to content

Commit

Permalink
add bang for the AASM to save changes
Browse files Browse the repository at this point in the history
You can tell AASM to auto-save the object or leave it unsaved
  • Loading branch information
kjgarza committed Oct 14, 2019
1 parent 8ec03b1 commit 4f29915
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions app/models/claim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,13 @@ def to_param # overridden, use uuid instead of id
def process_data(options={})
logger = Logger.new(STDOUT)

self.start
self.start!

### depdency Injection for testing
result = options[:collect_data] || collect_data

if result.body["skip"]
claimed_at.present? ? self.finish : self.skip
claimed_at.present? ? self.finish! : self.skip!

logger.warn "[Skipped] #{self.uid}#{self.doi}] #{result.body["reason"]}"
elsif result.body["errors"]
Expand All @@ -202,14 +202,14 @@ def process_data(options={})

logger.error "[Error] #{self.uid}#{self.doi}] " + result.body["errors"].first["title"].inspect

self.error
self.error!
elsif result.body["notification"]
write_attribute(:put_code, result.body["put_code"])
write_attribute(:error_messages, nil)

logger.warn "[Notification] #{self.uid}#{self.doi}] with Put Code #{result.body["put_code"]}"

self.notify
self.notify!
else
if to_be_created?
write_attribute(:claimed_at, Time.zone.now)
Expand All @@ -225,8 +225,7 @@ def process_data(options={})
logger.warn "[Deleted] #{self.uid}#{self.doi}] with Put Code #{result.body["put_code"]}"
end

self.finish
save
self.finish!
end
end

Expand Down

0 comments on commit 4f29915

Please sign in to comment.