Skip to content

Commit 0bd6e88

Browse files
Merge pull request #29 from datacite/add-event-model-specs
Add event model specs
2 parents 31ba1c2 + 131eb60 commit 0bd6e88

File tree

6 files changed

+414
-4
lines changed

6 files changed

+414
-4
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,5 @@ end
4646

4747
group :test do
4848
gem "simplecov", require: false
49+
gem "shoulda-matchers"
4950
end

Gemfile.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,8 @@ GEM
337337
aws-sdk-core (>= 2)
338338
concurrent-ruby
339339
thor
340+
shoulda-matchers (6.5.0)
341+
activesupport (>= 5.2.0)
340342
simplecov (0.22.0)
341343
docile (~> 1.1)
342344
simplecov-html (~> 0.11)
@@ -400,6 +402,7 @@ DEPENDENCIES
400402
sentry-rails
401403
sentry-ruby
402404
shoryuken (~> 4.0)
405+
shoulda-matchers
403406
simplecov
404407
uuid (~> 2.3, >= 2.3.9)
405408

app/models/event.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,21 @@ class Event < ApplicationRecord
4242

4343
# Getters
4444
def subj_hash
45-
@subj_hash ||= JSON.parse(subj)
45+
return {} if subj.blank?
46+
47+
JSON.parse(subj)
48+
rescue => e
49+
Rails.logger.error("JSON parsing failed for event.subj: #{e.message}")
50+
{}
4651
end
4752

4853
def obj_hash
49-
@obj_hash ||= JSON.parse(obj)
54+
return {} if obj.blank?
55+
56+
JSON.parse(obj)
57+
rescue => e
58+
Rails.logger.error("JSON parsing failed for event.obj: #{e.message}")
59+
{}
5060
end
5161

5262
# Callback Hooks

0 commit comments

Comments
 (0)