Skip to content

Commit

Permalink
Merge pull request #4060 from nebulab/spaghetticode/store-credit-auth…
Browse files Browse the repository at this point in the history
…orization_code

Add UUID to StoreCredit#generate_authorization_code
  • Loading branch information
kennyadsl authored May 21, 2021
2 parents 79e6748 + a4a3b57 commit a39affe
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 6 additions & 1 deletion core/app/models/spree/store_credit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,12 @@ def can_void?(payment)
end

def generate_authorization_code
"#{id}-SC-#{Time.current.utc.strftime('%Y%m%d%H%M%S%6N')}"
[
id,
'SC',
Time.current.utc.strftime('%Y%m%d%H%M%S%6N'),
SecureRandom.uuid
].join('-')
end

def editable?
Expand Down
8 changes: 8 additions & 0 deletions core/spec/models/spree/store_credit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -897,4 +897,12 @@
end
end
end

describe "#generate_authorization_code" do
it "doesn't rely on time for uniqueness" do
freeze_time do
expect(subject.generate_authorization_code).not_to eq(subject.generate_authorization_code)
end
end
end
end

0 comments on commit a39affe

Please sign in to comment.