Permalink
Browse files

Add rspec and documentation for UUID natural keys.

  • Loading branch information...
1 parent e78a4e0 commit 2348f3a4c0dea6f1825ecd990870d209c13388ce @schuyler schuyler committed Mar 25, 2013
View
@@ -41,6 +41,15 @@ class Email < ActiveRecord::Base
end
```
+### specify a natural key for generating the UUID from a SHA1 sum
+```ruby
+class Email < ActiveRecord::Base
+ include ActiveUUID::UUID
+ natural_key :sender_id, :received_at
+ belongs_to :sender
+end
+```
+
### use it:
Here are some example specs:
@@ -0,0 +1,4 @@
+Fabricator(:uuid_article_with_natural_key) do
+ title { Forgery::LoremIpsum.word }
+ body { Forgery::LoremIpsum.sentence }
+end
@@ -184,4 +184,15 @@
end
end
end
-end
+end
+
+describe UuidArticleWithNaturalKey do
+ let!(:article) { Fabricate :uuid_article_with_natural_key }
+ let!(:id) { article.id }
+ let!(:uuid) { UUIDTools::UUID.sha1_create(UUIDTools::UUID_OID_NAMESPACE, article.title) }
+ subject { article }
+ context 'natural_key' do
+ its(:id) { should == uuid }
+ end
+end
+
@@ -0,0 +1,5 @@
+class UuidArticleWithNaturalKey < ActiveRecord::Base
+ include ActiveUUID::UUID
+ self.table_name = 'uuid_articles'
+ natural_key :title
+end

0 comments on commit 2348f3a

Please sign in to comment.