Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 24, 2025

Thanks for assigning this issue to me. I'm starting to work on it and will keep this PR's description up to date as I form a plan and make progress.

Original issue description:

test_ransack.rb

require 'bundler/inline'

gemfile(true) do
  source 'https://rubygems.org'
  gem 'activerecord', '~> 6.1', '>= 6.1.4', require: "active_record"
  gem 'sqlite3', '~> 1.4'
  gem 'ransack', '~> 2.4', '>= 2.4.2'
  gem 'minitest', '~> 5.14', '>= 5.14.2', require: "minitest/autorun"
end

ActiveRecord::Base.establish_connection(
  adapter:  "sqlite3",
  database: "./test_ransack_alias"
)

ActiveRecord::Schema.define do
  drop_table(:fees, if_exists: true)

  create_table :fees do |t|
    t.integer :amount
  end
end


class Fee < ActiveRecord::Base
  ransack_alias :amount_a, :amount
end

class MyTest < Minitest::Test
  # success
  def test_1
    query_params = { amount_not_eq: 1 }
    assert_equal "SELECT \"fees\".* FROM \"fees\" WHERE \"fees\".\"amount\" != 1", Fee.ransack(query_params).result.to_sql
  end

  # success
  def test_2
    query_params = { amount_not_eq: 1, amount_a_not_eq: 2 }
    assert_equal "SELECT \"fees\".* FROM \"fees\" WHERE (\"fees\".\"amount\" != 1 AND \"fees\".\"amount\" != 2)", Fee.ransack(query_params).result.to_sql
  end

  # failure
  def test_3
    query_params = { amount_a_not_eq: 2, amount_not_eq: 1 }
    assert_equal "SELECT \"fees\".* FROM \"fees\" WHERE (\"fees\".\"amount\" != 2 AND \"fees\".\"amount\" != 1)", Fee.ransack(query_params).result.to_sql
  end
end
deploy@local-vm:~$ ruby test_ransack.rb
Fetching gem metadata from https://gems.ruby-china.com/........
Resolving dependencies...
Using concurrent-ruby 1.1.9
Using i18n 1.8.10
Using minitest 5.14.4
Using tzinfo 2.0.4
Using zeitwerk 2.4.2
Using activesupport 6.1.4
Using activemodel 6.1.4
Using activerecord 6.1.4
Using bundler 2.2.19
Using ransack 2.4.2
Using sqlite3 1.4.2
-- drop_table(:fees, {:if_exists=>true})
   -> 0.0094s
-- create_table(:fees)
   -> 0.0052s
Run options: --seed 9735

# Running:

..F

Finished in 0.008001s, 374.9565 runs/s, 374.9565 assertions/s.

  1) Failure:
MyTest#test_3 [test_ransack.rb:45]:
--- expected
+++ actual
@@ -1 +1 @@
-"SELECT \"fees\".* FROM \"fees\" WHERE (\"fees\".\"amount\" != 2 AND \"fees\".\"amount\" != 1)"
+"SELECT \"fees\".* FROM \"fees\" WHERE \"fees\".\"amount\" != 1"


3 runs, 3 assertions, 1 failures, 0 errors, 0 skips

Additional instructions:

create a failing test only - investiagte and recommend a direciotn

Fixes #1239


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ransack_alias sometimes does not work correctly
2 participants