2
require 'dm-migrations'
3
require 'dm-validations'
5
# Reload adapters to make sure ActsAsUrl sees the ORM
6
Stringex::ActsAsUrl::Adapter.load_available
8
puts "-------------------------------------------------"
9
puts "Running ActsAsUrl tests with DataMapper adapter"
10
puts "-------------------------------------------------"
12
DataMapper.setup :default, 'sqlite::memory:'
14
# What the tests do in constant redefining the same classes doesn't quite work with DataMapper.
15
# This proc allows us to reset the class definitions on each test. This might be more expensive
16
# but it definitely allows the class definitions to be correct. If someone more familiar with
17
# DataMapper than I am wants to refactor this, I'd be more than happy to take a look.
18
DefineTestClasses = proc do
20
include DataMapper::Resource
22
property :title, String
23
property :other, String
24
property :another, String
25
property :url, String, :lazy => false
31
include DataMapper::Resource
33
property :title, String
34
property :other, String
35
property :another, String
36
property :url, String, :lazy => false
37
property :type, String
39
# This gets redefined in the only test that uses it but I want to be uniform
40
# in setting configuration details in the tests themselves
44
class STIChildDocument < STIBaseDocument
47
class AnotherSTIChildDocument < STIBaseDocument
51
Document.auto_migrate!
52
STIBaseDocument.auto_migrate!
55
module AdapterSpecificTestBehaviors
57
DefineTestClasses.call
61
[Document, STIBaseDocument, STIChildDocument, AnotherSTIChildDocument].each do |klass|
63
Object.send :remove_const, klass.name.intern
67
def add_validation_on_document_title
68
Document.class_eval do
69
validates_presence_of :title
73
def remove_validation_on_document_title
74
# Do nothing. The class is going to be reloaded on the next test.
77
def adapter_specific_update(instance, hash)
78
response = instance.send :update, hash