Module: DataMapper::Spec::Adapters::Helpers

Defined in:
lib/dm-core/spec/lib/adapter_helpers.rb

Instance Method Summary collapse

Instance Method Details

#describe_adapter(kind, &block) ⇒ Object


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
# File 'lib/dm-core/spec/lib/adapter_helpers.rb', line 19

def describe_adapter(kind, &block)
  describe("with #{kind} adapter") do
    let(:adapter)    { @adapter    }
    let(:repository) { @repository }

    before :all do
      # store these in instance vars for the shared adapter specs
      @adapter    = DataMapper::Spec.adapter(kind)
      @repository = DataMapper.repository(@adapter.name)

      @repository.scope { DataMapper.finalize }

      # create all tables and constraints before each spec
      DataMapper::Model.descendants.each do |model|
        next unless model.respond_to?(:auto_migrate!)
        begin
          model.auto_migrate!(@repository.name)
        rescue IncompleteModelError
          # skip incomplete models
        end
      end
    end

    after :all do
      # remove all tables and constraints after each spec
      DataMapper::Model.descendants.each do |model|
        next unless model.respond_to?(:auto_migrate_down!)
        begin
          model.auto_migrate_down!(@repository.name)
        rescue IncompleteModelError
          # skip incomplete models
        end
      end
      # TODO consider proper automigrate functionality
      if @adapter.respond_to?(:reset)
        @adapter.reset
      end
    end

    instance_eval(&block)
  end
end

#supported_by(*adapters, &block) ⇒ Object


7
8
9
10
11
12
13
# File 'lib/dm-core/spec/lib/adapter_helpers.rb', line 7

def supported_by(*adapters, &block)
  adapters = adapters.map { |adapter| adapter.to_sym }
  adapter  = DataMapper::Spec.adapter_name.to_sym
  if adapters.include?(:all) || adapters.include?(adapter)
    describe_adapter(:default, &block)
  end
end

#with_alternate_adapter(&block) ⇒ Object


15
16
17
# File 'lib/dm-core/spec/lib/adapter_helpers.rb', line 15

def with_alternate_adapter(&block)
  describe_adapter(:alternate, &block)
end