Permalink
Browse files

Resolved conflicts in token spec

  • Loading branch information...
2 parents 1542c3d + 82bd6a4 commit 3723f3ddab3bdfe8fd0571aaec2875172ed50a93 @thetron committed Feb 17, 2013
Showing with 18 additions and 0 deletions.
  1. +1 −0 README.md
  2. +2 −0 lib/mongoid_token.rb
  3. +15 −0 spec/mongoid/token_spec.rb
View
@@ -71,6 +71,7 @@ The options for `contains` are as follows:
* `:alphanumeric` - letters (upper and lowercase) and numbers
* `:alpha` - letters (upper and lowercase) only
+* `:alpha_lower` - letters (lowercase) only
* `:numeric` - numbers only, anything from 1 character long, up to and
`length`
* `:fixed_numeric` - numbers only, but with the number of characters always the same as `length`
View
@@ -106,6 +106,8 @@ def generate_token(length, characters = :alphanumeric)
(rand(10**length - 10**(length-1)) + 10**(length-1)).to_s
when :alpha
Array.new(length).map{['A'..'Z','a'..'z'].map{|r|r.to_a}.flatten[rand(52)]}.join
+ when :alpha_lower
+ Array.new(length).map{['a'..'z'].map{|r|r.to_a}.flatten[rand(26)]}.join
end
end
end
View
@@ -47,6 +47,14 @@ class Image
token :length => 8, :contains => :fixed_numeric_no_leading_zeros
end
+class Event
+ include Mongoid::Document
+ include Mongoid::Token
+
+ field :name
+ token :length => 8, :contains => :alpha_lower
+end
+
class Node
include Mongoid::Document
include Mongoid::Token
@@ -71,12 +79,14 @@ class Cluster
@link = Link.create(:url => "http://involved.com.au")
@video = Video.create(:name => "Nyan nyan")
@image = Image.create(:url => "http://involved.com.au/image.png")
+ @event = Event.create(:name => "Super cool party!")
Account.create_indexes
Link.create_indexes
FailLink.create_indexes
Video.create_indexes
Image.create_indexes
+ Event.create_indexes
Node.create_indexes
end
@@ -119,6 +129,11 @@ class Cluster
@video = Video.create(:name => "A test video")
@video.vid.gsub(/[A-Za-z]/, "").length.should == 0
end
+
+ 50.times do |index|
+ @event = Event.create(:name => "Super cool party!2")
+ @event.token.gsub(/[a-z]/, "").length.should == 0
+ end
end
it "should create the only after the first save" do

0 comments on commit 3723f3d

Please sign in to comment.