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
|
# frozen_string_literal: true
require 'debug'
require 'state_machines-activemodel'
require 'minitest/autorun'
require 'minitest/reporters'
require 'active_support/all'
Minitest::Reporters.use! [Minitest::Reporters::ProgressReporter.new]
I18n.enforce_available_locales = true
class BaseTestCase < ActiveSupport::TestCase
protected
# Creates a plain model without ActiveModel features
def new_plain_model(&block)
model = Class.new do
def self.name
'Foo'
end
end
model.class_eval(&block) if block_given?
model
end
# Creates a new ActiveModel model (and the associated table)
def new_model(&block)
model = Class.new do
include ActiveModel::Model
include ActiveModel::Attributes
include ActiveModel::Dirty
attribute :state, :string
def self.name
'Foo'
end
def self.create
new.tap { |instance| instance.save if instance.respond_to?(:save) }
end
end
model.class_eval(&block) if block_given?
model
end
end
|