Sha256: 633f8131a354d44b49b5e8d9d04d7ffed3b4842002b2f4e71231401d9dec65e4

Contents?: true

Size: 840 Bytes

Versions: 2

Compression:

Stored size: 840 Bytes

Contents

# frozen_string_literal: true

require 'active_support/test_case'
require 'minitest/autorun'
require 'pry-byebug'

module Warning
  def self.warn(message)
    raise message.to_s
  end
end
Warning[:deprecated] = true

class TestRecord
  class Association
    def initialize(loaded:)
      @loaded = loaded
    end

    def loaded?
      @loaded
    end
  end

  class << self
    attr_accessor :reflections

    def inherited(subclass)
      super
      subclass.reflections = {}
    end

    def belongs_to(name)
      reflections[name.to_s] = :belongs_to
      define_method(name) { attributes[name.to_s] }
    end
  end

  def initialize(**attributes)
    @attributes = attributes
  end

  def attributes
    @attributes.transform_keys(&:to_s)
  end

  def association(name)
    Association.new(loaded: !public_send(name).nil?)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
upgrow-0.0.5 test/test_helper.rb
upgrow-0.0.4 test/test_helper.rb