Skip to content

Commit

Permalink
fix missing to save to AR
Browse files Browse the repository at this point in the history
write_attribute does not save to active record.
include dependcy injection for better testing
  • Loading branch information
kjgarza committed Oct 10, 2019
1 parent 6a08694 commit 8ec03b1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion 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 Down Expand Up @@ -224,6 +226,7 @@ def process_data(options={})
end

self.finish
save
end
end

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 8ec03b1

Please sign in to comment.