Skip to content

Commit

Permalink
Fix Rails edge tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Marius Bobin committed May 5, 2023
1 parent b8eeac1 commit c4c4a2a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion test/machine_with_event_attributes_on_autosave_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def teardown
remove_const('Vehicle')
remove_const('Owner')
end
ActiveSupport::Dependencies.clear if defined?(ActiveSupport::Dependencies)
clear_active_support_dependencies
super
end
end
3 changes: 2 additions & 1 deletion test/machine_with_scopes_and_joins_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def teardown
remove_const('Vehicle')
remove_const('Company')
end
ActiveSupport::Dependencies.clear

clear_active_support_dependencies
end
end
3 changes: 2 additions & 1 deletion test/machine_with_static_initial_state_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ def teardown
remove_const('Owner') if defined?(MachineWithStaticInitialStateTest::Owner)
remove_const('Driver') if defined?(MachineWithStaticInitialStateTest::Driver)
end
ActiveSupport::Dependencies.clear

clear_active_support_dependencies
super
end
end
Expand Down
16 changes: 16 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,20 @@ class << self;
model.reset_column_information if create_table
model
end

def clear_active_support_dependencies
return unless defined?(ActiveSupport::Dependencies)

if ActiveSupport::Dependencies.respond_to?(:autoloader=)
ActiveSupport::Dependencies.autoloader ||= stubbed_autoloader
end

ActiveSupport::Dependencies.clear
end

def stubbed_autoloader
Object.new.tap do |obj|
obj.define_singleton_method(:reload) {}
end
end
end

0 comments on commit c4c4a2a

Please sign in to comment.