Sha256: 934c6d754d730e48460522ebb454ae663dfb26a073c147e11690be947d7e730a
Contents?: true
Size: 1.15 KB
Versions: 2
Compression:
Stored size: 1.15 KB
Contents
# frozen_string_literal: true require 'with_model/model' require 'with_model/model/dsl' require 'with_model/table' require 'with_model/version' module WithModel # @param name The constant name (as a symbol) to assign the model class to. # @param scope Passed to `before`/`after` in the test context. # @param options Passed to {WithModel::Model#initialize}. # @param block Yielded an instance of {WithModel::Model::DSL}. def with_model(name, scope: nil, **options, &block) model = Model.new name, options dsl = Model::DSL.new model dsl.instance_exec(&block) if block before(*scope) do model.create end after(*scope) do model.destroy end end # @param name The table name (as a symbol) to create. # @param scope Passed to `before`/`after` in the test context. # @param options Passed to {WithModel::Table#initialize}. # @param block Passed to {WithModel::Table#initialize} (like {WithModel::Model::DSL#table}). def with_table(name, scope: nil, **options, &block) table = Table.new name, options, &block before(*scope) do table.create end after(*scope) do table.destroy end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
with_model-2.1.2 | lib/with_model.rb |
with_model-2.1.1 | lib/with_model.rb |