Module: TemporaryModel::TestHelper
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/temporary_model/test_helper.rb
Instance Method Summary collapse
Instance Method Details
#after_teardown ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/temporary_model/test_helper.rb', line 34 def after_teardown super if @temporary_classes.any? TemporaryModel::Record.connection.disable_referential_integrity do @temporary_classes.each do |temporary_class| drop_temporary_table temporary_class.table_name Object.send(:remove_const, temporary_class.name) end end # テンポラリクラスでリレーションを使っている場合、 # ActiveSupport::Dependencies.clear をしないとリレーションのklassに再利用され、 # # Post == Tag.find_by(name: 'Tag').posts.klass # => false # # になる ActiveSupport::Dependencies.clear @temporary_classes.clear end end |
#before_setup ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/temporary_model/test_helper.rb', line 19 def before_setup @temporary_classes = self.class.temporary_class_definitions.map do |model_name, class_definition| Class.new(TemporaryModel::Record).tap do |temporary_class| # 先に定数に設定しておかないと # https://circleci.com/gh/takeyuwebinc/takeyuweb-rails/83 Object.const_set(model_name, temporary_class) temporary_class.class_eval(&class_definition) create_temporary_table(temporary_class.table_name, &temporary_class.define_table) end end super end |