Permalink
Browse files

Source and specs cleanup

  • Loading branch information...
1 parent b4bdc4c commit f846538c85d7220d55d491cfff7bd32d9b7f08ad @pyromaniac pyromaniac committed Nov 6, 2012
Showing with 8 additions and 15 deletions.
  1. +1 −1 lib/activeuuid/uuid.rb
  2. +7 −14 spec/lib/activerecord_spec.rb
View
2 lib/activeuuid/uuid.rb
@@ -133,7 +133,7 @@ def create_uuid
def generate_uuids_if_needed
primary_key = self.class.primary_key
- if self.class.uuid_columns.include?(primary_key)
+ if self.class.columns_hash[primary_key].uuid?
send("#{primary_key}=", create_uuid) unless send("#{primary_key}?")
end
end
View
21 spec/lib/activerecord_spec.rb
@@ -62,35 +62,28 @@
end
context 'typecasting' do
- let(:input) { "e4618518-cb9f-11e1-aa7c-14dae903e06a" }
- let(:uuid) { UUIDTools::UUID.parse input }
+ let(:uuid) { UUIDTools::UUID.random_create }
let(:string) { uuid.to_s }
context 'primary' do
- before { article.id = input }
+ before { article.id = string }
specify do
article.id.should == uuid
- article.id_before_type_cast.should == input
+ article.id_before_type_cast.should == string
end
specify do
- article.id_before_type_cast.should == input
+ article.id_before_type_cast.should == string
article.id.should == uuid
end
- # specify do
- # article.save
- # article.reload
- # article.id_before_type_cast.should == string
- # article.id.should == uuid
- # end
end
context 'non-primary' do
- before { article.another_uuid = input }
+ before { article.another_uuid = string }
specify do
article.another_uuid.should == uuid
- article.another_uuid_before_type_cast.should == input
+ article.another_uuid_before_type_cast.should == string
end
specify do
- article.another_uuid_before_type_cast.should == input
+ article.another_uuid_before_type_cast.should == string
article.another_uuid.should == uuid
end
specify do

0 comments on commit f846538

Please sign in to comment.