Sha256: 3cbdf98edf0c3346a732d91c8ff7f9e140205cc7bd3d9381cd09699ba19e8570

Contents?: true

Size: 1.98 KB

Versions: 2

Compression:

Stored size: 1.98 KB

Contents

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

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

        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
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sbf-dm-core-1.3.0 lib/dm-core/spec/lib/adapter_helpers.rb
sbf-dm-core-1.3.0.beta lib/dm-core/spec/lib/adapter_helpers.rb