Sha256: 11b5d36529a9ca3b202229a3bdac9e02790d1f8d11946f15f182f5a2ee352433

Contents?: true

Size: 1.41 KB

Versions: 1

Compression:

Stored size: 1.41 KB

Contents

require 'rubygems'
require 'spec'
require 'rspec_spinner'

$:.unshift(File.dirname(__FILE__) + '/../lib')
require 'amee'

Spec::Runner.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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
amee-2.7.0 spec/spec_helper.rb