<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,27 +1,48 @@
 class Factory 
   class Proxy
     class Stub &lt; Proxy #:nodoc:
+      @@next_id = 1000
+
       def initialize(klass)
-        @mock = Object.new
+        @stub = klass.new
+        @stub.id = next_id
+        @stub.instance_eval do
+          def new_record?
+            id.nil?
+          end
+
+          def connection
+            raise &quot;stubbed models are not allowed to access the database&quot;
+          end
+
+          def reload
+            raise &quot;stubbed models are not allowed to access the database&quot;
+          end
+        end
+      end
+
+      def next_id
+        @@next_id += 1
       end
-      
+
       def get(attribute)
-        @mock.send(attribute)
+        @stub.send(attribute)
       end
-      
+
       def set(attribute, value)
-        unless @mock.respond_to?(&quot;#{attribute}=&quot;)
-          class &lt;&lt; @mock; self end.send(:attr_accessor, attribute)
-        end
-        @mock.send(&quot;#{attribute}=&quot;, value)
+        @stub.send(:&quot;#{attribute}=&quot;, value)
       end
-      
+
       def associate(name, factory, attributes)
-        set(name, nil)
+        set(name, Factory.stub(factory, attributes))
+      end
+
+      def association(factory, overrides = {})
+        Factory.stub(factory, overrides)
       end
-      
+
       def result
-        @mock      
+        @stub
       end
     end
   end</diff>
      <filename>lib/factory_girl/proxy/stub.rb</filename>
    </modified>
    <modified>
      <diff>@@ -2,54 +2,68 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_hel
 
 describe Factory::Proxy::Stub do
   before do
-    @proxy = Factory::Proxy::Stub.new(@class)
+    @class = &quot;class&quot;
+    @instance = &quot;instance&quot;
+    stub(@class).new { @instance }
+    stub(@instance, :id=)
+    stub(@instance).id { 42 }
+    stub(@instance).reload { @instance.connection.reload }
+
+    @stub = Factory::Proxy::Stub.new(@class)
+  end
+
+  it &quot;should not be a new record&quot; do
+    @stub.result.should_not be_new_record
+  end
+
+  it &quot;should not be able to connect to the database&quot; do
+    lambda { @stub.result.reload }.should raise_error(RuntimeError)
   end
 
-  describe &quot;when asked to associate with another factory&quot; do
+  describe &quot;when a user factory exists&quot; do
     before do
-      stub(Factory).create
-      @proxy.associate(:owner, :user, {})
+      @user = &quot;user&quot;
+      stub(Factory).stub(:user, {}) { @user }
     end
 
-    it &quot;should not set a value for the association&quot; do
-      @proxy.result.owner.should be_nil
-    end
-  end
+    describe &quot;when asked to associate with another factory&quot; do
+      before do
+        stub(@instance).owner { @user }
+        mock(Factory).stub(:user, {}) { @user }
+        mock(@stub).set(:owner, @user)
 
-  it &quot;should return nil when building an association&quot; do
-    @proxy.association(:user).should be_nil
-  end
+        @stub.associate(:owner, :user, {})
+      end
 
-  it &quot;should not call Factory.create when building an association&quot; do
-    mock(Factory).create.never
-    @proxy.association(:user).should be_nil
-  end
+      it &quot;should set a value for the association&quot; do
+        @stub.result.owner.should == @user
+      end
+    end
 
-  it &quot;should always return nil when building an association&quot; do
-    @proxy.set(:association, 'x')
-    @proxy.association(:user).should be_nil
-  end
+    it &quot;should return the association when building one&quot; do
+      mock(Factory).create.never
+      @stub.association(:user).should == @user
+    end
 
-  it &quot;should return a mock object when asked for the result&quot; do
-    @proxy.result.should be_kind_of(Object)
+    it &quot;should return the actual instance when asked for the result&quot; do
+      @stub.result.should == @instance
+    end
   end
 
-  describe &quot;after setting an attribute&quot; do
+  describe &quot;with an existing attribute&quot; do
     before do
-      @proxy.set(:attribute, 'value')
+      @value = &quot;value&quot;
+      mock(@instance).send(:attribute) { @value }
+      mock(@instance).send(:attribute=, @value)
+      @stub.set(:attribute, @value)
     end
 
-    it &quot;should add a stub to the resulting object&quot; do
-      @proxy.attribute.should == 'value'
+    it &quot;should to the resulting object&quot; do
+      @stub.attribute.should == 'value'
     end
 
     it &quot;should return that value when asked for that attribute&quot; do
-      @proxy.get(:attribute).should == 'value'
+      @stub.get(:attribute).should == @value
     end
   end
-
-  it &quot;should define a setter even if attribute= is defined&quot; do
-    @proxy.set('attribute', nil)
-    lambda { @proxy.set('age', 18) }.should_not raise_error
-  end
 end</diff>
      <filename>spec/factory_girl/proxy/stub_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -110,7 +110,7 @@ describe &quot;integration&quot; do
 
   end
 
-  describe &quot;a generated mock instance&quot; do
+  describe &quot;a generated stub instance&quot; do
 
     before do
       @stub = Factory.stub(:user, :first_name =&gt; 'Bill')
@@ -122,18 +122,39 @@ describe &quot;integration&quot; do
       end
     end
 
-    it &quot;should correctly assign lazy, dependent attributes&quot; do
+    it &quot;should correctly assign attributes&quot; do
       @stub.email.should == &quot;bill.hendrix@example.com&quot;
     end
 
-    it &quot;should override attrbutes&quot; do
+    it &quot;should override attributes&quot; do
       @stub.first_name.should == 'Bill'
     end
 
-    it &quot;should not assign associations&quot; do
-      Factory.stub(:post).author.should be_nil
+    it &quot;should assign associations&quot; do
+      Factory.stub(:post).author.should_not be_nil
+    end
+
+    it &quot;should have an id&quot; do
+      @stub.id.should &gt; 0
     end
 
+    it &quot;should have unique IDs&quot; do
+      @other_stub = Factory.stub(:user)
+      @stub.id.should_not == @other_stub.id
+    end
+
+    it &quot;should not be considered a new record&quot; do
+      @stub.should_not be_new_record
+    end
+
+    it &quot;should raise exception if connection to the database is attempted&quot; do
+      lambda { @stub.connection }.should raise_error(RuntimeError)
+      lambda { @stub.update_attribute(:first_name, &quot;Nick&quot;) }.should raise_error(RuntimeError)
+      lambda { @stub.reload }.should raise_error(RuntimeError)
+      lambda { @stub.destroy }.should raise_error(RuntimeError)
+      lambda { @stub.save }.should raise_error(RuntimeError)
+      lambda { @stub.increment!(:age) }.should raise_error(RuntimeError)
+    end
   end
 
   describe &quot;an instance generated by a factory with a custom class name&quot; do</diff>
      <filename>spec/integration_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>263e7be9da43e830b1e0d61be5f5508397af0308</id>
    </parent>
  </parents>
  <author>
    <name>Nick Quaranto</name>
    <email>nick@quaran.to</email>
  </author>
  <url>http://github.com/thoughtbot/factory_girl/commit/4ecd2f11785543c0bfdab199a40d24ee75a4c62d</url>
  <id>4ecd2f11785543c0bfdab199a40d24ee75a4c62d</id>
  <committed-date>2009-04-28T12:08:27-07:00</committed-date>
  <authored-date>2009-04-28T07:39:32-07:00</authored-date>
  <message>Refactored Factory#stub so it uses a real instance and throws exceptions when connections to the database are triggered.</message>
  <tree>932811530bc9d8cc58ccc939c21d7558b2e5f511</tree>
  <committer>
    <name>Nick Quaranto</name>
    <email>nick@quaran.to</email>
  </committer>
</commit>
