Sha256: 399809fee2a264794f7dd1d8737f3dd3ffff6dcfc52aa76588d77b31df4a7413

Contents?: true

Size: 978 Bytes

Versions: 11

Compression:

Stored size: 978 Bytes

Contents

class Factory 
  class Proxy
    class Stub < Proxy #:nodoc:
      @@next_id = 1000

      def initialize(klass)
        @stub = klass.new
        @stub.id = next_id
        @stub.instance_eval do
          def new_record?
            id.nil?
          end

          def connection
            raise "stubbed models are not allowed to access the database"
          end

          def reload
            raise "stubbed models are not allowed to access the database"
          end
        end
      end

      def next_id
        @@next_id += 1
      end

      def get(attribute)
        @stub.send(attribute)
      end

      def set(attribute, value)
        @stub.send(:"#{attribute}=", value)
      end

      def associate(name, factory, attributes)
        set(name, Factory.stub(factory, attributes))
      end

      def association(factory, overrides = {})
        Factory.stub(factory, overrides)
      end

      def result
        @stub
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 8 rubygems

Version Path
BrettRasmussen-factory_girl-1.2.2 lib/factory_girl/proxy/stub.rb
BrettRasmussen-factory_girl-1.2.3 lib/factory_girl/proxy/stub.rb
agibralter-factory_girl-1.2.1 lib/factory_girl/proxy/stub.rb
lacomartincik-factory_girl-1.2.1.1 lib/factory_girl/proxy/stub.rb
masa-iwasaki-factory_girl-1.2.1.1 lib/factory_girl/proxy/stub.rb
qrush-factory_girl-1.2.1.1 lib/factory_girl/proxy/stub.rb
thoughtbot-factory_girl-1.2.2 lib/factory_girl/proxy/stub.rb
freegenie-factory_girl-1.2.4 lib/factory_girl/proxy/stub.rb
freegenie-factory_girl-1.2.3 lib/factory_girl/proxy/stub.rb
freegenie-factory_girl-1.2.2 lib/factory_girl/proxy/stub.rb
factory_girl-1.2.2 lib/factory_girl/proxy/stub.rb