Sha256: 79d1b6e04eebadf3d729779d6f487c736154b0cf594aca76e11dfb37c1ff1d54

Contents?: true

Size: 1.64 KB

Versions: 5

Compression:

Stored size: 1.64 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 'spec'
require 'rspec_spinner'
require 'activesupport'

$:.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

XMLPreamble='<?xml version="1.0" encoding="UTF-8"?>'

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
amee-3.2.1 spec/spec_helper.rb
amee-3.2.0 spec/spec_helper.rb
amee-3.1.2 spec/spec_helper.rb
amee-3.1.1 spec/spec_helper.rb
amee-3.0.1 spec/spec_helper.rb