Use new ShortId class to generate short id
This commit is contained in:
parent
0a48959cda
commit
08a8165fa9
|
@ -22,17 +22,7 @@ class Message < ActiveRecord::Base
|
|||
after_save :update_unread_counts
|
||||
|
||||
def assign_short_id
|
||||
10.times do |try|
|
||||
if try == 10
|
||||
raise "too many hash collisions"
|
||||
end
|
||||
|
||||
self.short_id = Utils.random_str(6)
|
||||
|
||||
if !Message.find_by_short_id(self.short_id)
|
||||
break
|
||||
end
|
||||
end
|
||||
self.short_id = ShortId.new(self.class).generate
|
||||
end
|
||||
|
||||
def check_for_both_deleted
|
||||
|
|
8
spec/models/message_spec.rb
Normal file
8
spec/models/message_spec.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
require "spec_helper"
|
||||
|
||||
describe Message do
|
||||
it "should get a short id" do
|
||||
m = Message.make!
|
||||
m.short_id.should match(/^\A[a-zA-Z0-9]{1,10}\z/)
|
||||
end
|
||||
end
|
|
@ -28,3 +28,10 @@ Comment.blueprint do
|
|||
story_id { Story.make!.id }
|
||||
comment { "comment text #{sn}" }
|
||||
end
|
||||
|
||||
Message.blueprint do
|
||||
recipient_user_id { User.make!.id }
|
||||
author_user_id { User.make!.id }
|
||||
subject { "message subject #{sn}" }
|
||||
body { "message body #{sn}" }
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue