diff options
Diffstat (limited to 'spec/lib/unnested_in_filters/rewriter_spec.rb')
-rw-r--r-- | spec/lib/unnested_in_filters/rewriter_spec.rb | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/spec/lib/unnested_in_filters/rewriter_spec.rb b/spec/lib/unnested_in_filters/rewriter_spec.rb index bba27276037..fe34fba579b 100644 --- a/spec/lib/unnested_in_filters/rewriter_spec.rb +++ b/spec/lib/unnested_in_filters/rewriter_spec.rb @@ -69,21 +69,15 @@ RSpec.describe UnnestedInFilters::Rewriter do let(:recorded_queries) { ActiveRecord::QueryRecorder.new { rewriter.rewrite.load } } let(:relation) { User.where(state: :active, user_type: %i(support_bot alert_bot)).limit(2) } - let(:users_default_select_fields) do - User.default_select_columns - .map { |field| "\"users\".\"#{field.name}\"" } - .join(',') - end - let(:expected_query) do <<~SQL SELECT - #{users_default_select_fields} + "users".* FROM unnest('{1,2}'::smallint[]) AS "user_types"("user_type"), LATERAL ( SELECT - #{users_default_select_fields} + "users".* FROM "users" WHERE @@ -107,13 +101,13 @@ RSpec.describe UnnestedInFilters::Rewriter do let(:expected_query) do <<~SQL SELECT - #{users_default_select_fields} + "users".* FROM unnest(ARRAY(SELECT "users"."state" FROM "users")::character varying[]) AS "states"("state"), unnest('{1,2}'::smallint[]) AS "user_types"("user_type"), LATERAL ( SELECT - #{users_default_select_fields} + "users".* FROM "users" WHERE @@ -135,12 +129,12 @@ RSpec.describe UnnestedInFilters::Rewriter do let(:expected_query) do <<~SQL SELECT - #{users_default_select_fields} + "users".* FROM unnest('{active,blocked,banned}'::charactervarying[]) AS "states"("state"), LATERAL ( SELECT - #{users_default_select_fields} + "users".* FROM "users" WHERE @@ -187,6 +181,8 @@ RSpec.describe UnnestedInFilters::Rewriter do let(:expected_query) do <<~SQL + SELECT + "users".* FROM "users" WHERE @@ -221,7 +217,7 @@ RSpec.describe UnnestedInFilters::Rewriter do end it 'changes the query' do - expect(issued_query.gsub(/\s/, '')).to include(expected_query.gsub(/\s/, '')) + expect(issued_query.gsub(/\s/, '')).to start_with(expected_query.gsub(/\s/, '')) end end @@ -230,6 +226,8 @@ RSpec.describe UnnestedInFilters::Rewriter do let(:expected_query) do <<~SQL + SELECT + "users".* FROM "users" WHERE @@ -259,7 +257,7 @@ RSpec.describe UnnestedInFilters::Rewriter do end it 'does not rewrite the in statement for the joined table' do - expect(issued_query.gsub(/\s/, '')).to include(expected_query.gsub(/\s/, '')) + expect(issued_query.gsub(/\s/, '')).to start_with(expected_query.gsub(/\s/, '')) end end |