Files
fizzy/test/test_helpers/search_test_helper.rb
T
Mike Dalessio e3d86bb21e Clean up some spots where "current account" is ambiguous
Primarily this is in tests (which were caught by temporarily
introducing acts_as_tenant and enabling safety checks), but notably
action cable connections were not working properly, and that's now
fixed.
2025-11-17 09:12:41 -05:00

36 lines
1.1 KiB
Ruby

module SearchTestHelper
extend ActiveSupport::Concern
included do
self.use_transactional_tests = false
setup :setup_search_test
teardown :teardown_search_test
end
def setup_search_test
clear_search_records
Account.find_by(name: "Search Test")&.destroy
Identity.find_by(email_address: "test@example.com")&.destroy
@account = Account.create!(name: "Search Test", external_account_id: ActiveRecord::FixtureSet.identify("search_test"))
Current.account = @account
@identity = Identity.create!(email_address: "test@example.com")
@user = User.create!(name: "Test User", account: @account, identity: @identity)
@board = Board.create!(name: "Test Board", account: @account, creator: @user)
end
def teardown_search_test
clear_search_records
Account.find_by(name: "Search Test")&.destroy
Identity.find_by(email_address: "test@example.com")&.destroy
end
private
def clear_search_records
Search::Record::SHARD_COUNT.times do |shard_id|
ActiveRecord::Base.connection.execute("DELETE FROM search_records_#{shard_id}")
end
end
end