From 3d6069bdb31e3f747ecccba58e76496de5f086a5 Mon Sep 17 00:00:00 2001 From: Seth Call Date: Fri, 31 Jan 2014 09:32:18 -0600 Subject: [PATCH] * fix broken tests --- ruby/lib/jam_ruby/models/claimed_recording.rb | 8 +++++++- ruby/spec/jam_ruby/models/claimed_recording_spec.rb | 13 +++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/ruby/lib/jam_ruby/models/claimed_recording.rb b/ruby/lib/jam_ruby/models/claimed_recording.rb index 89fb5fa3f..7396b9a6a 100644 --- a/ruby/lib/jam_ruby/models/claimed_recording.rb +++ b/ruby/lib/jam_ruby/models/claimed_recording.rb @@ -47,11 +47,17 @@ module JamRuby end end + def remove_non_alpha_num(token) + token.gsub(/[^0-9A-Za-z]/, '') + end + private + def generate_share_token self.share_token = loop do token = SecureRandom.urlsafe_base64(SHARE_TOKEN_LENGTH, false) - token.gsub!(/[^0-9A-Za-z]/, '').upcase! + token = remove_non_alpha_num(token) + token.upcase! break token unless MusicSessionHistory.exists?(share_token: token) end end diff --git a/ruby/spec/jam_ruby/models/claimed_recording_spec.rb b/ruby/spec/jam_ruby/models/claimed_recording_spec.rb index bca0b4b0e..9b0026c6e 100644 --- a/ruby/spec/jam_ruby/models/claimed_recording_spec.rb +++ b/ruby/spec/jam_ruby/models/claimed_recording_spec.rb @@ -112,4 +112,17 @@ describe ClaimedRecording do duplicate.errors[:recording_id].should == ['has already been taken'] end end + + describe "remove_non_alpha_num" do + + let(:instance) { ClaimedRecording.new } + + it "removes hyphen" do + instance.remove_non_alpha_num("abc-").should == 'abc' + end + + it "leaves good alone" do + instance.remove_non_alpha_num("JDnfHsimMQ").should == 'JDnfHsimMQ' + end + end end \ No newline at end of file