Skip to content

Commit

Permalink
switch to readable_random for code generation
Browse files Browse the repository at this point in the history
  • Loading branch information
grosser committed Nov 10, 2009
1 parent b5eba91 commit 005755f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lib/acts_as_redeemable.rb
@@ -1,4 +1,5 @@
require 'activerecord'
require 'readable_random'

module ActsAsRedeemable
def self.included(base)
Expand Down Expand Up @@ -40,7 +41,7 @@ def acts_as_redeemable(options = {})
# Generates an alphanumeric code using an MD5 hash
# * +code_length+ - number of characters to return
def generate_code(code_length=6)
ActiveSupport::SecureRandom.base64(code_length).first(code_length).downcase
ReadableRandom.get(code_length)
end

# Generates unique code based on +generate_code+ method
Expand Down
6 changes: 3 additions & 3 deletions spec/acts_as_redeemable_spec.rb
Expand Up @@ -36,11 +36,11 @@
end

it "generates a unique code" do
ActiveSupport::SecureRandom.should_receive(:base64).and_return 'a'
ReadableRandom.should_receive(:get).and_return 'a'
FreeTodayCoupon.create!(:user_id => 1).code.should == 'a'

ActiveSupport::SecureRandom.should_receive(:base64).and_return 'a'
ActiveSupport::SecureRandom.should_receive(:base64).and_return 'b'
ReadableRandom.should_receive(:get).and_return 'a'
ReadableRandom.should_receive(:get).and_return 'b'
FreeTodayCoupon.create!(:user_id => 1).code.should == 'b'
end
end
Expand Down

0 comments on commit 005755f

Please sign in to comment.