Sha256: daf3e9f802bc02de2e834767f7ef478a251da9d1e0728c8fac94b8f44bda0817

Contents?: true

Size: 1.36 KB

Versions: 13

Compression:

Stored size: 1.36 KB

Contents

begin
  require 'pry-byebug'
rescue LoadError
end

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 < MiniTest::Test
  protected
  # Creates a new ActiveModel model (and the associated table)
  def new_model(&block)
    # Simple ActiveModel superclass
    parent = Class.new do
      def self.model_attribute(name)
        define_method(name) { instance_variable_defined?("@#{name}") ? instance_variable_get("@#{name}") : nil }
        define_method("#{name}=") do |value|
          send("#{name}_will_change!") if self.class <= ActiveModel::Dirty && value != send(name)
          instance_variable_set("@#{name}", value)
        end
      end

      def self.create
        object = new
        object.save
        object
      end

      def initialize(attrs = {})
        attrs.each { |attr, value| send("#{attr}=", value) }
        @changed_attributes = {}
      end

      def attributes
        @attributes ||= {}
      end

      def save
        @changed_attributes = {}
        true
      end
    end

    model = Class.new(parent) do
      def self.name
        'Foo'
      end

      model_attribute :state
    end
    model.class_eval(&block) if block_given?
    model
  end
end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
state_machines-activemodel-0.5.0 test/test_helper.rb
state_machines-activemodel-0.4.1 test/test_helper.rb
state_machines-activemodel-0.4.0 test/test_helper.rb
state_machines-activemodel-0.4.0.pre test/test_helper.rb
solidus_backend-1.0.0.pre3 vendor/bundle/gems/state_machines-activemodel-0.1.2/test/test_helper.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/state_machines-activemodel-0.1.2/test/test_helper.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/state_machines-activemodel-0.1.2/test/test_helper.rb
state_machines-activemodel-0.3.0 test/test_helper.rb
state_machines-activemodel-0.2.0 test/test_helper.rb
state_machines-activemodel-0.1.2 test/test_helper.rb
state_machines-activemodel-0.1.1 test/test_helper.rb
state_machines-activemodel-0.1.0 test/test_helper.rb
state_machines-activemodel-0.0.3 test/test_helper.rb