Sha256: cd5a7948912aea6ed9bf68c804339d9ba9f2ed2d12a7665ee21bbf05766f3dda

Contents?: true

Size: 1.56 KB

Versions: 29

Compression:

Stored size: 1.56 KB

Contents

# frozen_string_literal: true

require 'lhc'
class LHC::Config

  def _cleanup
    @endpoints = {}
    @placeholders = {}
    @interceptors = nil
  end
end

class LHS::Record

  DESCENDANTS = []

  def self.inherited(child)
    DESCENDANTS.push(child)
    child.singleton_class.class_eval do
      define_method(:inherited) do |grand_child|
        DESCENDANTS.push(grand_child)
      end
    end
    super
  end

end

def reset_lhc
  LHC::Config.instance._cleanup
end

def reset_lhs
  LHS::Record::Endpoints.all = {}
  LHS::Record::DESCENDANTS.each do |decendant|
    decendant.endpoints = [] if !decendant.name['LHS'] && defined?(decendant.endpoints)
    decendant.configuration({}) if !decendant.name['LHS']
  end
end

def model_files_to_reload
  Dir.glob(Rails.root.join('app', 'models', '**', '*.rb'))
end

def reload_direct_inheritance
  model_files_to_reload.map do |file|
    next unless File.read(file).match('LHS::Record')
    load file
    file.split('models/').last.gsub('.rb', '').classify
  end.compact
end

def reload_inheriting_records(parents)
  model_files_to_reload.each do |file|
    next if parents.none? { |parent| File.read(file).match(parent) }
    load file
  end
end

RSpec.configure do |config|
  config.before do |spec|
    reset_lhc unless spec.metadata.key?(:reset_before) && spec.metadata[:reset_before] == false
    reset_lhs unless spec.metadata.key?(:reset_before) && spec.metadata[:reset_before] == false
    next if !spec.metadata.key?(:dummy_models) || spec.metadata[:dummy_models] != true
    reload_inheriting_records(reload_direct_inheritance)
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
lhs-26.2.0 spec/support/reset.rb
lhs-26.1.0 spec/support/reset.rb
lhs-26.0.1 spec/support/reset.rb
lhs-26.0.0 spec/support/reset.rb
lhs-25.2.0 spec/support/reset.rb
lhs-25.1.0 spec/support/reset.rb
lhs-25.0.4 spec/support/reset.rb
lhs-25.0.3 spec/support/reset.rb
lhs-25.0.2 spec/support/reset.rb
lhs-25.0.1 spec/support/reset.rb
lhs-25.0.0 spec/support/reset.rb
lhs-24.1.2 spec/support/reset.rb
lhs-24.1.1 spec/support/reset.rb
lhs-24.1.0 spec/support/reset.rb
lhs-24.1.0.pre.2 spec/support/reset.rb
lhs-24.1.0.pre.1 spec/support/reset.rb
lhs-24.0.0 spec/support/reset.rb
lhs-23.0.2 spec/support/reset.rb
lhs-23.0.1 spec/support/reset.rb
lhs-23.0.0 spec/support/reset.rb