~ubuntu-branches/ubuntu/vivid/ruby-stringex/vivid-proposed

« back to all changes in this revision

Viewing changes to test/unit/acts_as_url/adapter/data_mapper.rb

  • Committer: Package Import Robot
  • Author(s): Youhei SASAKI
  • Date: 2014-05-30 01:15:06 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20140530011506-gqmvsja16gwyevdv
Tags: 2.5.2-1
* Imported Upstream version 2.5.2
* Drop obsolete patches
* Update test path: follow upstream changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
require 'dm-core'
2
 
require 'dm-migrations'
3
 
require 'dm-validations'
4
 
require 'stringex'
5
 
# Reload adapters to make sure ActsAsUrl sees the ORM
6
 
Stringex::ActsAsUrl::Adapter.load_available
7
 
 
8
 
puts "-------------------------------------------------"
9
 
puts "Running ActsAsUrl tests with DataMapper adapter"
10
 
puts "-------------------------------------------------"
11
 
 
12
 
DataMapper.setup :default, 'sqlite::memory:'
13
 
 
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
19
 
  class Document
20
 
    include DataMapper::Resource
21
 
    property :id,      Serial
22
 
    property :title,   String
23
 
    property :other,   String
24
 
    property :another, String
25
 
    property :url,     String, :lazy => false
26
 
 
27
 
    acts_as_url :title
28
 
  end
29
 
 
30
 
  class STIBaseDocument
31
 
    include DataMapper::Resource
32
 
    property :id,      Serial
33
 
    property :title,   String
34
 
    property :other,   String
35
 
    property :another, String
36
 
    property :url,     String, :lazy => false
37
 
    property :type,    String
38
 
 
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
41
 
    acts_as_url :title
42
 
  end
43
 
 
44
 
  class STIChildDocument < STIBaseDocument
45
 
  end
46
 
 
47
 
  class AnotherSTIChildDocument < STIBaseDocument
48
 
  end
49
 
 
50
 
  DataMapper.finalize
51
 
  Document.auto_migrate!
52
 
  STIBaseDocument.auto_migrate!
53
 
end
54
 
 
55
 
module AdapterSpecificTestBehaviors
56
 
  def setup
57
 
    DefineTestClasses.call
58
 
  end
59
 
 
60
 
  def teardown
61
 
    [Document, STIBaseDocument, STIChildDocument, AnotherSTIChildDocument].each do |klass|
62
 
      klass.destroy
63
 
      Object.send :remove_const, klass.name.intern
64
 
    end
65
 
  end
66
 
 
67
 
  def add_validation_on_document_title
68
 
    Document.class_eval do
69
 
      validates_presence_of :title
70
 
    end
71
 
  end
72
 
 
73
 
  def remove_validation_on_document_title
74
 
    # Do nothing. The class is going to be reloaded on the next test.
75
 
  end
76
 
 
77
 
  def adapter_specific_update(instance, hash)
78
 
    response = instance.send :update, hash
79
 
  end
80
 
end