Skip to content

Commit

Permalink
Merge pull request #80 from datacite/bug_claims_pending
Browse files Browse the repository at this point in the history
Bug claims pending
  • Loading branch information
kjgarza authored Oct 15, 2019
2 parents 17ce4b9 + 00445af commit f3c263c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
8 changes: 5 additions & 3 deletions app/models/claim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@ def process_data(options={})
logger = Logger.new(STDOUT)

self.start
result = collect_data

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

if result.body["skip"]
claimed_at.present? ? self.finish : self.skip
Expand All @@ -200,7 +202,7 @@ 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)
Expand All @@ -223,7 +225,7 @@ def process_data(options={})
logger.warn "[Deleted] #{self.uid}#{self.doi}] with Put Code #{result.body["put_code"]}"
end

self.finish
self.finish!
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/factories/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

factory :valid_user do
uid { '0000-0001-6528-2027' }
orcid_token { ENV['ACCESS_TOKEN'] }
orcid_token { ENV['ORCID_TOKEN'] }
end

factory :invalid_user do
Expand Down
8 changes: 8 additions & 0 deletions spec/models/claim_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@
expect(subject.claimed_at).not_to be_blank
expect(subject.state).to eq("done")
end

it 'no errors with dependency injection' do
options = {collect_data: OpenStruct.new(body: { "put_code" => "1069294"})}
expect(subject.process_data(options)).to be true
expect(subject.put_code).to eq(put_code)
expect(subject.claimed_at).not_to be_blank
expect(subject.state).to eq("done")
end

it 'already exists' do
FactoryBot.create(:claim, user: user, orcid: "0000-0001-6528-2027", doi: "10.14454/j6gr-cf48", claim_action: "create", claimed_at: Time.zone.now, put_code: put_code)
Expand Down

0 comments on commit f3c263c

Please sign in to comment.