<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>brcpfcnpj/lib/brcpfcnpj/.cpf_cnpj_activerecord.rb.swp</filename>
    </added>
    <added>
      <filename>brcpfcnpj/spec/.spec_helper.rb.swp</filename>
    </added>
    <added>
      <filename>brcpfcnpj/spec/db/.create_testing_structure.rb.swp</filename>
    </added>
    <added>
      <filename>brcpfcnpj/spec/db/create_testing_structure.rb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -4,3 +4,5 @@
 pkg
 doc
 *~
+*swp
+*swo</diff>
      <filename>.gitignore</filename>
    </modified>
    <modified>
      <diff>@@ -6,9 +6,8 @@ module CpfCnpjActiveRecord #:nodoc:
     def usar_como_cpf(*args) #:nodoc:
       unless args.size.zero?
         args.each do |name|
-          composed_of name, :class_name =&gt; 'Cpf', :mapping =&gt; [name.to_s, &quot;numero&quot;], :allow_nil =&gt; true do
-            Cpf.new(name[:numero])
-          end
+          composed_of name, :class_name =&gt; 'Cpf', :mapping =&gt; [name.to_s, &quot;numero&quot;], :allow_nil =&gt; true,
+            :constructor =&gt; Proc.new { |numero| Cpf.new(numero) }
           name = name.to_s
           module_eval &lt;&lt;-ADICIONANDO_METODOS_PARA_CPF
           validate :#{name}_valido?
@@ -41,10 +40,8 @@ module CpfCnpjActiveRecord #:nodoc:
     def usar_como_cnpj(*args) #:nodoc:
       unless args.size.zero?
         args.each do |name|
-          composed_of name, :class_name =&gt; 'Cnpj', :mapping =&gt; [name.to_s, &quot;numero&quot;], :allow_nil =&gt; true do
-            Cnpj.new(name[:numero])
-          end
-
+          composed_of name, :class_name =&gt; 'Cnpj', :mapping =&gt; [name.to_s, &quot;numero&quot;], :allow_nil =&gt; true,
+            :constructor =&gt; Proc.new { |numero| Cnpj.new(numero) }
           name = name.to_s
           module_eval &lt;&lt;-ADICIONANDO_METODOS_PARA_CNPJ
           validate :#{name}_valido?</diff>
      <filename>brcpfcnpj/lib/brcpfcnpj/cpf_cnpj_activerecord.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,14 +1,15 @@
 require File.dirname(__FILE__) + '/spec_helper'
 require File.dirname(__FILE__) + '/active_record/base_without_table'
 
-class Person &lt; ActiveRecord::BaseWithoutTable
+class Pessoa &lt; ActiveRecord::Base
   usar_como_cpf :cpf
+  validates_uniqueness_of :cpf
 end
 
 describe &quot;Using a model attribute as Cpf&quot; do
 
   before(:each) do
-    @person = Person.new
+    @person = Pessoa.new(:nome =&gt; &quot;Fulano&quot;)
   end
   
   it &quot;should format the received number&quot; do
@@ -62,7 +63,7 @@ describe &quot;Using a model attribute as Cpf&quot; do
   end
   
   it &quot;should be able to receive parameters at initialization&quot; do
-    @person = Person.new(:cpf =&gt; &quot;111.44477735&quot;)
+    @person = Pessoa.new(:cpf =&gt; &quot;111.44477735&quot;)
     @person.cpf.numero.should == &quot;111.444.777-35&quot;  
   end
   
@@ -74,4 +75,22 @@ describe &quot;Using a model attribute as Cpf&quot; do
   end
 end
 
+describe &quot;using validations&quot; do
+  it &quot;should validate presence of cpf&quot; do
+    Pessoa.validates_presence_of :cpf
+    p = Pessoa.new(:nome =&gt; &quot;Fulano&quot;)
+    p.should_not be_valid
+    p.errors.on(:cpf).should eql(&quot;can't be blank&quot;)
+  end
 
+  it &quot;should validate uniqueness of cpf&quot; do
+    p1 = Pessoa.new(:nome =&gt; &quot;Fulano&quot;, :cpf =&gt; &quot;11144477735&quot;)
+    p1.save
+    puts p1.inspect
+    p2 = Pessoa.new(:nome =&gt; &quot;Beltrano&quot;, :cpf =&gt; &quot;11144477735&quot;)
+    p2.valid?
+    p p2.errors
+    p2.should_not be_valid
+    p2.errors.on(:cpf).should_not be_nil
+  end
+end</diff>
      <filename>brcpfcnpj/spec/cpf_active_record_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,3 +1,9 @@
 require 'rubygems'
 require 'spec'
 require File.expand_path(File.dirname(__FILE__) + &quot;/../lib/brcpfcnpj&quot;)
+require 'active_record'
+
+ActiveRecord::Base.establish_connection(:adapter=&gt;&quot;sqlite3&quot;, :database =&gt; &quot;:memory:&quot;)
+require File.dirname(__FILE__) + &quot;/db/create_testing_structure&quot;
+
+CreateTestingStructure.migrate(:up)</diff>
      <filename>brcpfcnpj/spec/spec_helper.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>664189b51df498973d99ce708fb2cac2f7aa8ddd</id>
    </parent>
  </parents>
  <author>
    <name>CassioMarques</name>
    <email>cassiommc@gmail.com</email>
  </author>
  <url>http://github.com/tapajos/brazilian-rails/commit/dfd56f32abcb35b8094e947c7c21a518dab629ae</url>
  <id>dfd56f32abcb35b8094e947c7c21a518dab629ae</id>
  <committed-date>2009-01-20T16:43:30-08:00</committed-date>
  <authored-date>2009-01-13T13:21:06-08:00</authored-date>
  <message>Alterados blocos compose_of no cpf e cnpj

Signed-off-by: Marcos Tapaj&#243;s &lt;tapajos@improveit.com.br&gt;</message>
  <tree>31725d139433bf9335ca10a6e208b109ee580e33</tree>
  <committer>
    <name>Marcos Tapaj&#243;s</name>
    <email>tapajos@improveit.com.br</email>
  </committer>
</commit>
