Skip to content

Commit

Permalink
fix tests for real this time
Browse files Browse the repository at this point in the history
  • Loading branch information
ethowitz committed Jan 26, 2024
1 parent 4b3ba22 commit eaaa778
Showing 1 changed file with 22 additions and 41 deletions.
63 changes: 22 additions & 41 deletions spec/railtie_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ def index
end

describe 'readyset.query_annotator' do
after do
Rails.configuration.active_record.query_log_tags.reject! do |tag|
tag.is_a?(Hash) && tag.keys == [:destination]
end
end

context 'when Rails.env.development? is true' do
context 'when query log tags are enabled' do
it 'adds a query_log_tag for routing to Readyset' do
Expand All @@ -43,16 +37,17 @@ def index
allow(Rails).to receive(:env).and_return(rails_env)
allow(Rails.configuration.active_record).to receive(:query_log_tags_enabled).
and_return(true)
expected_tag = {
destination: ->(context) do
ActiveRecord::Base.connection_db_config.name
end,
}
allow(Rails.configuration.active_record.query_log_tags).to receive(:<<).with(expected_tag)
Readyset::Railtie.setup_query_annotator

# Verify
expect(Rails.configuration.active_record.query_log_tags).to include(
{
destination: ->(context) do
ActiveRecord::Base.connection_db_config.name
end,
}
)
expect(Rails.configuration.active_record.query_log_tags).to have_received(:<<).
with(expected_tag)
end
end

Expand All @@ -79,16 +74,11 @@ def index
allow(Rails).to receive(:env).and_return(rails_env)
allow(Rails.configuration.active_record).to receive(:query_log_tags_enabled).
and_return(false)
allow(Rails.configuration.active_record.query_log_tags).to receive(:<<)
Readyset::Railtie.setup_query_annotator

# Verify
expect(Rails.configuration.active_record.query_log_tags).not_to include(
{
destination: ->(context) do
ActiveRecord::Base.connection_db_config.name
end,
}
)
expect(Rails.configuration.active_record.query_log_tags).not_to have_received(:<<)
end
end
end
Expand All @@ -101,16 +91,17 @@ def index
allow(Rails).to receive(:env).and_return(rails_env)
allow(Rails.configuration.active_record).to receive(:query_log_tags_enabled).
and_return(true)
expected_tag = {
destination: ->(context) do
ActiveRecord::Base.connection_db_config.name
end,
}
allow(Rails.configuration.active_record.query_log_tags).to receive(:<<).with(expected_tag)
Readyset::Railtie.setup_query_annotator

# Verify
expect(Rails.configuration.active_record.query_log_tags).to include(
{
destination: ->(context) do
ActiveRecord::Base.connection_db_config.name
end,
}
)
expect(Rails.configuration.active_record.query_log_tags).to have_received(:<<).
with(expected_tag)
end
end

Expand All @@ -137,16 +128,11 @@ def index
allow(Rails).to receive(:env).and_return(rails_env)
allow(Rails.configuration.active_record).to receive(:query_log_tags_enabled).
and_return(false)
allow(Rails.configuration.active_record.query_log_tags).to receive(:<<)
Readyset::Railtie.setup_query_annotator

# Verify
expect(Rails.configuration.active_record.query_log_tags).not_to include(
{
destination: ->(context) do
ActiveRecord::Base.connection_db_config.name
end,
}
)
expect(Rails.configuration.active_record.query_log_tags).not_to have_received(:<<)
end
end
end
Expand All @@ -158,16 +144,11 @@ def index
allow(Rails).to receive(:env).and_return(rails_env)
allow(Rails.configuration.active_record).to receive(:query_log_tags_enabled).
and_return(true)
allow(Rails.configuration.active_record.query_log_tags).to receive(:<<)
Readyset::Railtie.setup_query_annotator

# Verify
expect(Rails.configuration.active_record.query_log_tags).not_to include(
{
destination: ->(context) do
ActiveRecord::Base.connection_db_config.name
end,
}
)
expect(Rails.configuration.active_record.query_log_tags).not_to have_received(:<<)
end
end
end
Expand Down

0 comments on commit eaaa778

Please sign in to comment.