Sha256: 04603c54d338c16c49a87386deb84d71719504e01a1391e3335e018e87cda1fb
Contents?: true
Size: 1.61 KB
Versions: 13
Compression:
Stored size: 1.61 KB
Contents
# Copyright (C) 2008-2011 AMEE UK Ltd. - http://www.amee.com # Released as Open Source Software under the BSD 3-Clause license. See LICENSE.txt for details. require 'rubygems' require 'rspec' require 'logger' $:.unshift(File.dirname(__FILE__) + '/../lib') require 'amee' RSpec.configure do |config| config.mock_with :flexmock end # Stub activerecord for rails tests # Taken from http://muness.blogspot.com/2006/12/unit-testing-rails-activerecord-classes.html class ActiveRecordUnitTestHelper attr_accessor :klass def initialize klass self.klass = klass self end def where attributes klass.stubs(:columns).returns(columns(attributes)) instance = klass.new(attributes) instance.id = attributes[:id] if attributes[:id] #the id attributes works differently on active record classes instance end protected def columns attributes attributes.keys.collect{|attribute| column attribute.to_s, attributes[attribute]} end def column column_name, value ActiveRecord::ConnectionAdapters::Column.new(column_name, nil, ActiveRecordUnitTestHelper.active_record_type(value.class), false) end def self.active_record_type klass return case klass.name when "Fixnum" then "integer" when "Float" then "float" when "Time" then "time" when "Date" then "date" when "String" then "string" when "Object" then "boolean" end end end def disconnected klass ActiveRecordUnitTestHelper.new(klass) end def fixture(filename) File.read File.dirname(__FILE__)+'/fixtures/'+filename end XMLPreamble='<?xml version="1.0" encoding="UTF-8"?>'
Version data entries
13 entries across 13 versions & 1 rubygems