Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: bbb29f1d4c
Fetching contributors…

Cannot retrieve contributors at this time

file 93 lines (74 sloc) 2.191 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
require 'pp'
require 'pathname'
require 'rubygems'
require 'spec'
require 'fileutils'

# for __DIR__
require Pathname(__FILE__).dirname.expand_path.parent + 'lib/data_mapper/support/kernel'

ROOT_DIR = __DIR__.parent
INTEGRATION_DB_PATH = __DIR__ + 'integration/integration_test.db'
FileUtils.touch INTEGRATION_DB_PATH

ENV['LOG_NAME'] = 'spec'
require ROOT_DIR + 'environment'
require __DIR__ + 'lib/mock_adapter'


class Article
  include DataMapper::Resource

  property :id, Fixnum, :serial => true
  property :blog_id, Fixnum
  property :created_at, DateTime
  property :author, String
  property :title, String

  class << self
    def property_by_name(name)
      properties(repository.name)[name]
    end
  end
end

class Comment
  include DataMapper::Resource
end

class NormalClass
  # should not include DataMapper::Resource
end

# ==========================
# Used for Association specs
class Vehicle
  include DataMapper::Resource

  property :id, Fixnum, :serial => true
  property :name, String
end

class Manufacturer
  include DataMapper::Resource

  property :id, Fixnum, :serial => true
  property :name, String
end

class Supplier
  include DataMapper::Resource

  property :id, Fixnum, :serial => true
  property :name, String
end

class Class
  def publicize_methods
    klass = class << self; self; end

    saved_private_class_methods = klass.private_instance_methods
    saved_protected_class_methods = klass.protected_instance_methods
    saved_private_instance_methods = self.private_instance_methods
    saved_protected_instance_methods = self.protected_instance_methods

    self.class_eval do
      klass.send(:public, *saved_private_class_methods)
      klass.send(:public, *saved_protected_class_methods)
      public(*saved_private_instance_methods)
      public(*saved_protected_instance_methods)
    end

    begin
      yield
    ensure
      self.class_eval do
        klass.send(:private, *saved_private_class_methods)
        klass.send(:protected, *saved_protected_class_methods)
        private(*saved_private_instance_methods)
        protected(*saved_protected_instance_methods)
      end
    end
  end
end
Something went wrong with that request. Please try again.