Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSS Gate Workshop: ゆるい勉強会旭川: 2024-07-28: satou-haruka-37: ransack: Work log #1858

Closed
satou-haruka-37 opened this issue Jul 28, 2024 · 49 comments
Labels
work log ワークショップ作業メモ

Comments

@satou-haruka-37
Copy link
Contributor

This is a work log of a "OSS Gate workshop".
"OSS Gate workshop" is an activity to increase OSS developers.
Here's been discussed in Japanese. Thanks.

作業ログ作成時の説明

以下のテンプレートを埋めてタイトルに設定します。埋め方例はスクロールすると見えてきます。

OSS Gate Workshop: ${LOCATION}: ${YEAR}-${MONTH}-${DAY}: ${ACCOUNT_NAME}: ${OSS_NAME}: Work log

タイトル例↓:

OSS Gate Workshop: Tokyo: 2017-01-16: kou: Rabbit: Work log

OSS Gateワークショップ関連情報

  • スライド:ワークショップの進行に使っているスライドがあります。
  • チャット:OSS開発に関することならなんでも相談できます。ワークショップが終わった後もオンラインで相談しながら継続的にOSSの開発に参加しましょう!
  • シナリオ:ワークショップの目的・内容・進め方の詳細が書いています。
  • 過去のビギナーの作業ログ:他の人の作業ログから学べることがいろいろあるはずです。
@satou-haruka-37 satou-haruka-37 added the work log ワークショップ作業メモ label Jul 28, 2024
@satou-haruka-37
Copy link
Contributor Author

https://github.com/activerecord-hackery/ransack を選びました。

https://github.com/activerecord-hackery/ransack/blob/main/LICENSE と、MITライセンスがあったので、OSSだと確認できました。

@satou-haruka-37
Copy link
Contributor Author

@satou-haruka-37
Copy link
Contributor Author

サポーターよりOSS contributeのアイデアの助言
ドキュメントの日本語版翻訳して、日本語に切り替えるページの追加
・今たくさん立っているissue の中で自分でも解決できそうなものに取り組む
・使っていた時にこんな機能あったらいいのに、と思ったこと

@satou-haruka-37
Copy link
Contributor Author

使っていた時にこんな機能あったらいいのにと思ったこと

日本語とカタカナを同じものとみなして検索する方法
例)ラーメン、らーめんを両方検索結果に表示する

@satou-haruka-37
Copy link
Contributor Author

satou-haruka-37 commented Jul 28, 2024

サポーターより助言
機能追加は大きな変更すぎる
issueを選ぶもしなくていい
まずransackをローカルに持ってきてテスト通してみる

@satou-haruka-37
Copy link
Contributor Author

https://github.com/activerecord-hackery/ransack/blob/main/CONTRIBUTING.md#pull-requests
こちらを参考にforkしてローカルに持ってきた

@satou-haruka-37
Copy link
Contributor Author

bundle install

実行したらエラーが出た

satouharuka@satouharukanoMacBook-Pro ransack % bundle install
Fetching https://github.com/rails/rails.git
Fetching gem metadata from https://rubygems.org/.........
Resolving dependencies...
Fetching parallel 1.25.1
Fetching coderay 1.1.3
Fetching json 2.7.2
Fetching diff-lcs 1.5.1
Fetching machinist 1.0.6
Fetching method_source 1.1.0
Fetching docile 1.4.1
Installing mysql2 0.5.6 with native extensions
Installing parallel 1.25.1
Fetching pg 1.5.6
Installing coderay 1.1.3
Fetching regexp_parser 2.9.2
Installing docile 1.4.1
Fetching strscan 3.1.0
Installing method_source 1.1.0
Fetching rspec-support 3.13.1
Installing json 2.7.2 with native extensions
Installing machinist 1.0.6
Fetching simplecov-html 0.12.3
Installing diff-lcs 1.5.1
Fetching simplecov_json_formatter 0.1.4
Installing pg 1.5.6 with native extensions
Installing regexp_parser 2.9.2
Fetching sqlite3 1.7.3 (arm64-darwin)
Installing strscan 3.1.0 with native extensions
Installing rspec-support 3.13.1
Fetching nokogiri 1.16.7 (arm64-darwin)
Installing simplecov-html 0.12.3
Fetching parser 3.3.4.0
Installing simplecov_json_formatter 0.1.4
Fetching pry 0.14.2
Installing sqlite3 1.7.3 (arm64-darwin)
Fetching rspec-core 3.13.0
Fetching rspec-expectations 3.13.1
Fetching rspec-mocks 3.13.1
Installing nokogiri 1.16.7 (arm64-darwin)
Installing parser 3.3.4.0
Installing pry 0.14.2
Installing rspec-core 3.13.0
Fetching faker 3.4.2
Fetching simplecov 0.22.0
Fetching rexml 3.3.2
Fetching rubocop-ast 1.31.3
Installing rspec-expectations 3.13.1
Installing rspec-mocks 3.13.1
Fetching rspec 3.13.0
Installing faker 3.4.2
Installing simplecov 0.22.0
Installing rexml 3.3.2
Installing rubocop-ast 1.31.3
Fetching rubocop 1.65.0
Installing rspec 3.13.0
Installing rubocop 1.65.0
Gem::Ext::BuildError: ERROR: Failed to build gem
native extension.

current directory:
/Users/satouharuka/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/mysql2-0.5.6/ext/mysql2
/Users/satouharuka/.rbenv/versions/3.2.2/bin/ruby
extconf.rb
checking for rb_absint_size()... yes
checking for rb_absint_singlebit_p()... yes
checking for rb_gc_mark_movable()... yes
checking for rb_wait_for_single_fd()... yes
checking for rb_enc_interned_str() in ruby.h...
yes
-----
Using
--with-openssl-dir=/Users/satouharuka/.rbenv/versions/3.2.2/openssl
-----
-----
Using mysql_config at
/opt/homebrew/bin/mysql_config
-----
checking for mysql.h... yes
checking for errmsg.h... yes
checking for SSL_MODE_DISABLED in mysql.h... yes
checking for SSL_MODE_PREFERRED in mysql.h... yes
checking for SSL_MODE_REQUIRED in mysql.h... yes
checking for SSL_MODE_VERIFY_CA in mysql.h... yes
checking for SSL_MODE_VERIFY_IDENTITY in
mysql.h... yes
checking for MYSQL.net.vio in mysql.h... yes
checking for MYSQL.net.pvio in mysql.h... no
checking for MYSQL_DEFAULT_AUTH in mysql.h... yes
checking for MYSQL_ENABLE_CLEARTEXT_PLUGIN in
mysql.h... yes
checking for SERVER_QUERY_NO_GOOD_INDEX_USED in
mysql.h... yes
checking for SERVER_QUERY_NO_INDEX_USED in
mysql.h... yes
checking for SERVER_QUERY_WAS_SLOW in mysql.h...
yes
checking for MYSQL_OPTION_MULTI_STATEMENTS_ON in
mysql.h... yes
checking for MYSQL_OPTION_MULTI_STATEMENTS_OFF in
mysql.h... yes
checking for my_bool in mysql.h... no
checking for mysql_ssl_set() in mysql.h... no
-----
Don't know how to set rpath on your system, if
MySQL libraries are not in path mysql2 may not
load
-----
-----
Setting libpath to
/opt/homebrew/Cellar/mysql/8.3.0_1/lib
-----
creating Makefile

current directory:
/Users/satouharuka/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/mysql2-0.5.6/ext/mysql2
make DESTDIR\=
sitearchdir\=./.gem.20240728-38926-x7uaay
sitelibdir\=./.gem.20240728-38926-x7uaay clean

current directory:
/Users/satouharuka/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/mysql2-0.5.6/ext/mysql2
make DESTDIR\=
sitearchdir\=./.gem.20240728-38926-x7uaay
sitelibdir\=./.gem.20240728-38926-x7uaay
compiling client.c
In file included from client.c:15:
./mysql_enc_name_to_ruby.h:43:1: warning: a
function definition without a prototype is
deprecated in all versions of C and is not
supported in C2x [-Wdeprecated-non-prototype]
mysql2_mysql_enc_name_to_rb_hash (str, len)
^
./mysql_enc_name_to_ruby.h:86:1: warning: a
function definition without a prototype is
deprecated in all versions of C and is not
supported in C2x [-Wdeprecated-non-prototype]
mysql2_mysql_enc_name_to_rb (str, len)
^
2 warnings generated.
compiling infile.c
compiling mysql2_ext.c
compiling result.c
result.c:304:35: warning: implicit conversion
loses integer precision: 'unsigned long' to 'int'
[-Wshorten-64-to-32]
precision = field->length -
(field->decimals > 0 ? 2 : 1);
~
~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
compiling statement.c
linking shared-object mysql2/mysql2.bundle
ld: warning: ignoring duplicate libraries:
'-lruby.3.2'
ld: library 'zstd' not found
clang: error: linker command failed with exit code
1 (use -v to see invocation)
make: *** [mysql2.bundle] Error 1

make failed, exit code 2

Gem files will remain installed in
/Users/satouharuka/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/mysql2-0.5.6
for inspection.
Results logged to
/Users/satouharuka/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/extensions/arm64-darwin-23/3.2.0/mysql2-0.5.6/gem_make.out

/Users/satouharuka/.rbenv/versions/3.2.2/lib/ruby/3.2.0/rubygems/ext/builder.rb:119:in
`run'
/Users/satouharuka/.rbenv/versions/3.2.2/lib/ruby/3.2.0/rubygems/ext/builder.rb:51:in
`block in make'
/Users/satouharuka/.rbenv/versions/3.2.2/lib/ruby/3.2.0/rubygems/ext/builder.rb:43:in
`each'
/Users/satouharuka/.rbenv/versions/3.2.2/lib/ruby/3.2.0/rubygems/ext/builder.rb:43:in
`make'
/Users/satouharuka/.rbenv/versions/3.2.2/lib/ruby/3.2.0/rubygems/ext/ext_conf_builder.rb:41:in
`build'
/Users/satouharuka/.rbenv/versions/3.2.2/lib/ruby/3.2.0/rubygems/ext/builder.rb:187:in
`build_extension'
/Users/satouharuka/.rbenv/versions/3.2.2/lib/ruby/3.2.0/rubygems/ext/builder.rb:221:in
`block in build_extensions'
/Users/satouharuka/.rbenv/versions/3.2.2/lib/ruby/3.2.0/rubygems/ext/builder.rb:218:in
`each'
/Users/satouharuka/.rbenv/versions/3.2.2/lib/ruby/3.2.0/rubygems/ext/builder.rb:218:in
`build_extensions'
/Users/satouharuka/.rbenv/versions/3.2.2/lib/ruby/3.2.0/rubygems/installer.rb:843:in
`build_extensions'
/Users/satouharuka/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.5.10/lib/bundler/rubygems_gem_installer.rb:76:in
`build_extensions'
/Users/satouharuka/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.5.10/lib/bundler/rubygems_gem_installer.rb:28:in
`install'
/Users/satouharuka/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.5.10/lib/bundler/source/rubygems.rb:205:in
`install'
/Users/satouharuka/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.5.10/lib/bundler/installer/gem_installer.rb:54:in
`install'
/Users/satouharuka/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.5.10/lib/bundler/installer/gem_installer.rb:16:in
`install_from_spec'
/Users/satouharuka/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.5.10/lib/bundler/installer/parallel_installer.rb:132:in
`do_install'
/Users/satouharuka/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.5.10/lib/bundler/installer/parallel_installer.rb:123:in
`block in worker_pool'
/Users/satouharuka/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.5.10/lib/bundler/worker.rb:62:in
`apply_func'
/Users/satouharuka/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.5.10/lib/bundler/worker.rb:57:in
`block in process_queue'
/Users/satouharuka/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.5.10/lib/bundler/worker.rb:54:in
`loop'
/Users/satouharuka/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.5.10/lib/bundler/worker.rb:54:in
`process_queue'
/Users/satouharuka/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.5.10/lib/bundler/worker.rb:90:in
`block (2 levels) in create_threads'

An error occurred while installing mysql2
(0.5.6), and Bundler cannot continue.

In Gemfile:
  mysql2

@satou-haruka-37
Copy link
Contributor Author

抜粋

Gem::Ext::BuildError: ERROR: Failed to build gem
native extension.

current directory:
/Users/satouharuka/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/mysql2-0.5.6/ext/mysql2
/Users/satouharuka/.rbenv/versions/3.2.2/bin/ruby
extconf.rb
checking for rb_absint_size()... yes
checking for rb_absint_singlebit_p()... yes
checking for rb_gc_mark_movable()... yes
checking for rb_wait_for_single_fd()... yes
checking for rb_enc_interned_str() in ruby.h...
yes
-----
Using
--with-openssl-dir=/Users/satouharuka/.rbenv/versions/3.2.2/openssl
-----
-----
Using mysql_config at
/opt/homebrew/bin/mysql_config
-----
checking for mysql.h... yes
checking for errmsg.h... yes
checking for SSL_MODE_DISABLED in mysql.h... yes
checking for SSL_MODE_PREFERRED in mysql.h... yes
checking for SSL_MODE_REQUIRED in mysql.h... yes
checking for SSL_MODE_VERIFY_CA in mysql.h... yes
checking for SSL_MODE_VERIFY_IDENTITY in
mysql.h... yes
checking for MYSQL.net.vio in mysql.h... yes
checking for MYSQL.net.pvio in mysql.h... no
checking for MYSQL_DEFAULT_AUTH in mysql.h... yes
checking for MYSQL_ENABLE_CLEARTEXT_PLUGIN in
mysql.h... yes
checking for SERVER_QUERY_NO_GOOD_INDEX_USED in
mysql.h... yes
checking for SERVER_QUERY_NO_INDEX_USED in
mysql.h... yes
checking for SERVER_QUERY_WAS_SLOW in mysql.h...
yes
checking for MYSQL_OPTION_MULTI_STATEMENTS_ON in
mysql.h... yes
checking for MYSQL_OPTION_MULTI_STATEMENTS_OFF in
mysql.h... yes
checking for my_bool in mysql.h... no
checking for mysql_ssl_set() in mysql.h... no
-----
Don't know how to set rpath on your system, if
MySQL libraries are not in path mysql2 may not
load
-----
-----
Setting libpath to
/opt/homebrew/Cellar/mysql/8.3.0_1/lib
-----
creating Makefile

current directory:
/Users/satouharuka/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/mysql2-0.5.6/ext/mysql2
make DESTDIR\=
sitearchdir\=./.gem.20240728-38926-x7uaay
sitelibdir\=./.gem.20240728-38926-x7uaay clean

current directory:
/Users/satouharuka/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/mysql2-0.5.6/ext/mysql2
make DESTDIR\=
sitearchdir\=./.gem.20240728-38926-x7uaay
sitelibdir\=./.gem.20240728-38926-x7uaay
compiling client.c
In file included from client.c:15:
./mysql_enc_name_to_ruby.h:43:1: warning: a
function definition without a prototype is
deprecated in all versions of C and is not
supported in C2x [-Wdeprecated-non-prototype]
mysql2_mysql_enc_name_to_rb_hash (str, len)
^
./mysql_enc_name_to_ruby.h:86:1: warning: a
function definition without a prototype is
deprecated in all versions of C and is not
supported in C2x [-Wdeprecated-non-prototype]
mysql2_mysql_enc_name_to_rb (str, len)
^
2 warnings generated.
compiling infile.c
compiling mysql2_ext.c
compiling result.c
result.c:304:35: warning: implicit conversion
loses integer precision: 'unsigned long' to 'int'
[-Wshorten-64-to-32]
precision = field->length -
(field->decimals > 0 ? 2 : 1);
~
~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
compiling statement.c
linking shared-object mysql2/mysql2.bundle
ld: warning: ignoring duplicate libraries:
'-lruby.3.2'
ld: library 'zstd' not found
clang: error: linker command failed with exit code
1 (use -v to see invocation)
make: *** [mysql2.bundle] Error 1

make failed, exit code 2

@satou-haruka-37
Copy link
Contributor Author

サポーターより助言
これが原因ではないか

ld: library 'zstd' not found

@satou-haruka-37
Copy link
Contributor Author

コントリビューションガイド通りにやってるのにセットアップができないと言うことがわかった。

@satou-haruka-37
Copy link
Contributor Author

解決方法の記事を見つけた
https://zenn.dev/yukionodera/articles/how-to-fix-error-mysql2

@satou-haruka-37
Copy link
Contributor Author

下記のように実行して bundle install できた

satouharuka@satouharukanoMacBook-Pro ransack % export LIBRARY_PATH=$LIBRARY_PATH:$(brew --prefix zstd)/lib/

satouharuka@satouharukanoMacBook-Pro ransack % bundle install                                              
Fetching https://github.com/rails/rails.git
Fetching gem metadata from https://rubygems.org/.........
Resolving dependencies...
Installing mysql2 0.5.6 with native extensions
Bundle complete! 16 Gemfile dependencies, 61 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.

@satou-haruka-37
Copy link
Contributor Author

次の段階に移る

bundle exec rake spec

実行したらテストが通らなかった。

satouharuka@satouharukanoMacBook-Pro ransack % bundle exec rake spec
/Users/satouharuka/.rbenv/versions/3.2.2/bin/ruby -I/Users/satouharuka/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-core-3.13.0/lib:/Users/satouharuka/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-support-3.13.1/lib /Users/satouharuka/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-core-3.13.0/exe/rspec spec/ransack/adapters/active_record/base_spec.rb spec/ransack/adapters/active_record/context_spec.rb spec/ransack/configuration_spec.rb spec/ransack/helpers/form_builder_spec.rb spec/ransack/helpers/form_helper_spec.rb spec/ransack/nodes/condition_spec.rb spec/ransack/nodes/grouping_spec.rb spec/ransack/nodes/value_spec.rb spec/ransack/predicate_spec.rb spec/ransack/search_spec.rb spec/ransack/translate_spec.rb
====================================================================================
Running Ransack specs with SQLite, Active Record 7.1.3.4, Arel 10.0.0 and Ruby 3.2.2
====================================================================================
................F......FFFF................................................................................FFFF................................................................................................................................................................................................................................FF.......................*........................................

Pending: (Failures listed here are expected and do not affect your suite's status)

  1) Ransack::Search#build preserves (inverts) default scope and conditions for negative subqueries
     # spec should pass, but I do not know how/where to fix lib code
     Failure/Error:
             base_klass.with_connection do |connection|
               # The chain starts with the target table, but we want to end with it here (makes
               # more sense in this context), so we reverse
               chain.reverse_each do |reflection, table|
                 klass = reflection.klass
       
                 join_scope = reflection.join_scope(table, foreign_table, foreign_klass)
       
                 unless join_scope.references_values.empty?
                   join_dependency = join_scope.construct_join_dependency(
     
     NoMethodError:
       undefined method `with_connection' for Article:Class
     # ./lib/polyamorous/activerecord/join_association_7_2.rb:16:in `join_constraints_with_tables'
     # ./lib/ransack/adapters/active_record/context.rb:334:in `extract_joins'
     # ./lib/ransack/adapters/active_record/context.rb:165:in `build_correlated_subquery'
     # ./lib/ransack/nodes/condition.rb:290:in `block in arel_predicate'
     # ./lib/ransack/nodes/condition.rb:287:in `map'
     # ./lib/ransack/nodes/condition.rb:287:in `arel_predicate'
     # ./lib/ransack/visitor.rb:17:in `visit_Ransack_Nodes_Condition'
     # ./lib/ransack/visitor.rb:54:in `visit'
     # ./lib/ransack/visitor.rb:5:in `accept'
     # ./lib/ransack/visitor.rb:29:in `block in visit_and'
     # ./lib/ransack/visitor.rb:29:in `map'
     # ./lib/ransack/visitor.rb:29:in `visit_and'
     # ./lib/ransack/visitor.rb:24:in `visit_Ransack_Nodes_Grouping'
     # ./lib/ransack/visitor.rb:54:in `visit'
     # ./lib/ransack/visitor.rb:5:in `accept'
     # ./lib/ransack/adapters/active_record/context.rb:27:in `evaluate'
     # ./lib/ransack/search.rb:44:in `result'
     # ./spec/ransack/search_spec.rb:183:in `block (3 levels) in <module:Ransack>'

Failures:

  1) Ransack::Adapters::ActiveRecord::Base#search with scopes applies scopes that define string SQL joins
     Failure/Error:
             base_klass.with_connection do |connection|
               # The chain starts with the target table, but we want to end with it here (makes
               # more sense in this context), so we reverse
               chain.reverse_each do |reflection, table|
                 klass = reflection.klass
       
                 join_scope = reflection.join_scope(table, foreign_table, foreign_klass)
       
                 unless join_scope.references_values.empty?
                   join_dependency = join_scope.construct_join_dependency(
     
     NoMethodError:
       undefined method `with_connection' for Note:Class
     # ./lib/polyamorous/activerecord/join_association_7_2.rb:16:in `join_constraints_with_tables'
     # ./lib/ransack/adapters/active_record/context.rb:334:in `extract_joins'
     # ./lib/ransack/adapters/active_record/context.rb:165:in `build_correlated_subquery'
     # ./lib/ransack/nodes/condition.rb:290:in `block in arel_predicate'
     # ./lib/ransack/nodes/condition.rb:287:in `map'
     # ./lib/ransack/nodes/condition.rb:287:in `arel_predicate'
     # ./lib/ransack/visitor.rb:17:in `visit_Ransack_Nodes_Condition'
     # ./lib/ransack/visitor.rb:54:in `visit'
     # ./lib/ransack/visitor.rb:5:in `accept'
     # ./lib/ransack/visitor.rb:29:in `block in visit_and'
     # ./lib/ransack/visitor.rb:29:in `map'
     # ./lib/ransack/visitor.rb:29:in `visit_and'
     # ./lib/ransack/visitor.rb:24:in `visit_Ransack_Nodes_Grouping'
     # ./lib/ransack/visitor.rb:54:in `visit'
     # ./lib/ransack/visitor.rb:5:in `accept'
     # ./lib/ransack/adapters/active_record/context.rb:27:in `evaluate'
     # ./lib/ransack/search.rb:44:in `result'
     # ./spec/ransack/adapters/active_record/base_spec.rb:87:in `block (4 levels) in <module:ActiveRecord>'

  2) Ransack::Adapters::ActiveRecord::Base negative conditions on HABTM associations removes redundant joins from top query
     Failure/Error:
             base_klass.with_connection do |connection|
               # The chain starts with the target table, but we want to end with it here (makes
               # more sense in this context), so we reverse
               chain.reverse_each do |reflection, table|
                 klass = reflection.klass
       
                 join_scope = reflection.join_scope(table, foreign_table, foreign_klass)
       
                 unless join_scope.references_values.empty?
                   join_dependency = join_scope.construct_join_dependency(
     
     NoMethodError:
       undefined method `with_connection' for Tag:Class
     # ./lib/polyamorous/activerecord/join_association_7_2.rb:16:in `join_constraints_with_tables'
     # ./lib/ransack/adapters/active_record/context.rb:334:in `extract_joins'
     # ./lib/ransack/adapters/active_record/context.rb:165:in `build_correlated_subquery'
     # ./lib/ransack/nodes/condition.rb:290:in `block in arel_predicate'
     # ./lib/ransack/nodes/condition.rb:287:in `map'
     # ./lib/ransack/nodes/condition.rb:287:in `arel_predicate'
     # ./lib/ransack/visitor.rb:17:in `visit_Ransack_Nodes_Condition'
     # ./lib/ransack/visitor.rb:54:in `visit'
     # ./lib/ransack/visitor.rb:5:in `accept'
     # ./lib/ransack/visitor.rb:29:in `block in visit_and'
     # ./lib/ransack/visitor.rb:29:in `map'
     # ./lib/ransack/visitor.rb:29:in `visit_and'
     # ./lib/ransack/visitor.rb:24:in `visit_Ransack_Nodes_Grouping'
     # ./lib/ransack/visitor.rb:54:in `visit'
     # ./lib/ransack/visitor.rb:5:in `accept'
     # ./lib/ransack/adapters/active_record/context.rb:27:in `evaluate'
     # ./lib/ransack/search.rb:44:in `result'
     # ./spec/ransack/adapters/active_record/base_spec.rb:174:in `block (3 levels) in <module:ActiveRecord>'

  3) Ransack::Adapters::ActiveRecord::Base negative conditions on HABTM associations handles != for single values
     Failure/Error:
             base_klass.with_connection do |connection|
               # The chain starts with the target table, but we want to end with it here (makes
               # more sense in this context), so we reverse
               chain.reverse_each do |reflection, table|
                 klass = reflection.klass
       
                 join_scope = reflection.join_scope(table, foreign_table, foreign_klass)
       
                 unless join_scope.references_values.empty?
                   join_dependency = join_scope.construct_join_dependency(
     
     NoMethodError:
       undefined method `with_connection' for Tag:Class
     # ./lib/polyamorous/activerecord/join_association_7_2.rb:16:in `join_constraints_with_tables'
     # ./lib/ransack/adapters/active_record/context.rb:334:in `extract_joins'
     # ./lib/ransack/adapters/active_record/context.rb:165:in `build_correlated_subquery'
     # ./lib/ransack/nodes/condition.rb:290:in `block in arel_predicate'
     # ./lib/ransack/nodes/condition.rb:287:in `map'
     # ./lib/ransack/nodes/condition.rb:287:in `arel_predicate'
     # ./lib/ransack/visitor.rb:17:in `visit_Ransack_Nodes_Condition'
     # ./lib/ransack/visitor.rb:54:in `visit'
     # ./lib/ransack/visitor.rb:5:in `accept'
     # ./lib/ransack/visitor.rb:29:in `block in visit_and'
     # ./lib/ransack/visitor.rb:29:in `map'
     # ./lib/ransack/visitor.rb:29:in `visit_and'
     # ./lib/ransack/visitor.rb:24:in `visit_Ransack_Nodes_Grouping'
     # ./lib/ransack/visitor.rb:54:in `visit'
     # ./lib/ransack/visitor.rb:5:in `accept'
     # ./lib/ransack/adapters/active_record/context.rb:27:in `evaluate'
     # ./lib/ransack/search.rb:44:in `result'
     # ./spec/ransack/adapters/active_record/base_spec.rb:180:in `block (3 levels) in <module:ActiveRecord>'

  4) Ransack::Adapters::ActiveRecord::Base negative conditions on HABTM associations handles NOT IN for multiple attributes
     Failure/Error:
             base_klass.with_connection do |connection|
               # The chain starts with the target table, but we want to end with it here (makes
               # more sense in this context), so we reverse
               chain.reverse_each do |reflection, table|
                 klass = reflection.klass
       
                 join_scope = reflection.join_scope(table, foreign_table, foreign_klass)
       
                 unless join_scope.references_values.empty?
                   join_dependency = join_scope.construct_join_dependency(
     
     NoMethodError:
       undefined method `with_connection' for Tag:Class
     # ./lib/polyamorous/activerecord/join_association_7_2.rb:16:in `join_constraints_with_tables'
     # ./lib/ransack/adapters/active_record/context.rb:334:in `extract_joins'
     # ./lib/ransack/adapters/active_record/context.rb:165:in `build_correlated_subquery'
     # ./lib/ransack/nodes/condition.rb:290:in `block in arel_predicate'
     # ./lib/ransack/nodes/condition.rb:287:in `map'
     # ./lib/ransack/nodes/condition.rb:287:in `arel_predicate'
     # ./lib/ransack/visitor.rb:17:in `visit_Ransack_Nodes_Condition'
     # ./lib/ransack/visitor.rb:54:in `visit'
     # ./lib/ransack/visitor.rb:5:in `accept'
     # ./lib/ransack/visitor.rb:29:in `block in visit_and'
     # ./lib/ransack/visitor.rb:29:in `map'
     # ./lib/ransack/visitor.rb:29:in `visit_and'
     # ./lib/ransack/visitor.rb:24:in `visit_Ransack_Nodes_Grouping'
     # ./lib/ransack/visitor.rb:54:in `visit'
     # ./lib/ransack/visitor.rb:5:in `accept'
     # ./lib/ransack/adapters/active_record/context.rb:27:in `evaluate'
     # ./lib/ransack/search.rb:44:in `result'
     # ./spec/ransack/adapters/active_record/base_spec.rb:187:in `block (3 levels) in <module:ActiveRecord>'

  5) Ransack::Adapters::ActiveRecord::Base negative conditions on self-referenced associations handles multiple associations and aliases
     Failure/Error:
             base_klass.with_connection do |connection|
               # The chain starts with the target table, but we want to end with it here (makes
               # more sense in this context), so we reverse
               chain.reverse_each do |reflection, table|
                 klass = reflection.klass
       
                 join_scope = reflection.join_scope(table, foreign_table, foreign_klass)
       
                 unless join_scope.references_values.empty?
                   join_dependency = join_scope.construct_join_dependency(
     
     NoMethodError:
       undefined method `with_connection' for Person:Class
     # ./lib/polyamorous/activerecord/join_association_7_2.rb:16:in `join_constraints_with_tables'
     # ./lib/ransack/adapters/active_record/context.rb:334:in `extract_joins'
     # ./lib/ransack/adapters/active_record/context.rb:165:in `build_correlated_subquery'
     # ./lib/ransack/nodes/condition.rb:290:in `block in arel_predicate'
     # ./lib/ransack/nodes/condition.rb:287:in `map'
     # ./lib/ransack/nodes/condition.rb:287:in `arel_predicate'
     # ./lib/ransack/visitor.rb:17:in `visit_Ransack_Nodes_Condition'
     # ./lib/ransack/visitor.rb:54:in `visit'
     # ./lib/ransack/visitor.rb:5:in `accept'
     # ./lib/ransack/visitor.rb:29:in `block in visit_and'
     # ./lib/ransack/visitor.rb:29:in `map'
     # ./lib/ransack/visitor.rb:29:in `visit_and'
     # ./lib/ransack/visitor.rb:24:in `visit_Ransack_Nodes_Grouping'
     # ./lib/ransack/visitor.rb:54:in `visit'
     # ./lib/ransack/visitor.rb:5:in `accept'
     # ./lib/ransack/adapters/active_record/context.rb:27:in `evaluate'
     # ./lib/ransack/search.rb:44:in `result'
     # ./spec/ransack/adapters/active_record/base_spec.rb:219:in `block (3 levels) in <module:ActiveRecord>'

  6) Ransack::Adapters::ActiveRecord::Context#build_correlated_subquery build correlated subquery for Root STI model
     Failure/Error:
             base_klass.with_connection do |connection|
               # The chain starts with the target table, but we want to end with it here (makes
               # more sense in this context), so we reverse
               chain.reverse_each do |reflection, table|
                 klass = reflection.klass
       
                 join_scope = reflection.join_scope(table, foreign_table, foreign_klass)
       
                 unless join_scope.references_values.empty?
                   join_dependency = join_scope.construct_join_dependency(
     
     NoMethodError:
       undefined method `with_connection' for Article:Class
     # ./lib/polyamorous/activerecord/join_association_7_2.rb:16:in `join_constraints_with_tables'
     # ./lib/ransack/adapters/active_record/context.rb:334:in `extract_joins'
     # ./lib/ransack/adapters/active_record/context.rb:165:in `build_correlated_subquery'
     # ./spec/ransack/adapters/active_record/context_spec.rb:46:in `block (3 levels) in <module:ActiveRecord>'

  7) Ransack::Adapters::ActiveRecord::Context#build_correlated_subquery build correlated subquery for Child STI model when predicate is not_eq
     Failure/Error:
             base_klass.with_connection do |connection|
               # The chain starts with the target table, but we want to end with it here (makes
               # more sense in this context), so we reverse
               chain.reverse_each do |reflection, table|
                 klass = reflection.klass
       
                 join_scope = reflection.join_scope(table, foreign_table, foreign_klass)
       
                 unless join_scope.references_values.empty?
                   join_dependency = join_scope.construct_join_dependency(
     
     NoMethodError:
       undefined method `with_connection' for StoryArticle:Class
     # ./lib/polyamorous/activerecord/join_association_7_2.rb:16:in `join_constraints_with_tables'
     # ./lib/ransack/adapters/active_record/context.rb:334:in `extract_joins'
     # ./lib/ransack/adapters/active_record/context.rb:165:in `build_correlated_subquery'
     # ./spec/ransack/adapters/active_record/context_spec.rb:59:in `block (3 levels) in <module:ActiveRecord>'

  8) Ransack::Adapters::ActiveRecord::Context#build_correlated_subquery build correlated subquery for Child STI model when predicate is eq
     Failure/Error:
             base_klass.with_connection do |connection|
               # The chain starts with the target table, but we want to end with it here (makes
               # more sense in this context), so we reverse
               chain.reverse_each do |reflection, table|
                 klass = reflection.klass
       
                 join_scope = reflection.join_scope(table, foreign_table, foreign_klass)
       
                 unless join_scope.references_values.empty?
                   join_dependency = join_scope.construct_join_dependency(
     
     NoMethodError:
       undefined method `with_connection' for StoryArticle:Class
     # ./lib/polyamorous/activerecord/join_association_7_2.rb:16:in `join_constraints_with_tables'
     # ./lib/ransack/adapters/active_record/context.rb:334:in `extract_joins'
     # ./lib/ransack/adapters/active_record/context.rb:165:in `build_correlated_subquery'
     # ./spec/ransack/adapters/active_record/context_spec.rb:72:in `block (3 levels) in <module:ActiveRecord>'

  9) Ransack::Adapters::ActiveRecord::Context#build_correlated_subquery build correlated subquery for multiple conditions (default scope)
     Failure/Error:
             base_klass.with_connection do |connection|
               # The chain starts with the target table, but we want to end with it here (makes
               # more sense in this context), so we reverse
               chain.reverse_each do |reflection, table|
                 klass = reflection.klass
       
                 join_scope = reflection.join_scope(table, foreign_table, foreign_klass)
       
                 unless join_scope.references_values.empty?
                   join_dependency = join_scope.construct_join_dependency(
     
     NoMethodError:
       undefined method `with_connection' for Comment:Class
     # ./lib/polyamorous/activerecord/join_association_7_2.rb:16:in `join_constraints_with_tables'
     # ./lib/ransack/adapters/active_record/context.rb:334:in `extract_joins'
     # ./lib/ransack/adapters/active_record/context.rb:165:in `build_correlated_subquery'
     # ./lib/ransack/nodes/condition.rb:290:in `block in arel_predicate'
     # ./lib/ransack/nodes/condition.rb:287:in `map'
     # ./lib/ransack/nodes/condition.rb:287:in `arel_predicate'
     # ./lib/ransack/visitor.rb:17:in `visit_Ransack_Nodes_Condition'
     # ./lib/ransack/visitor.rb:54:in `visit'
     # ./lib/ransack/visitor.rb:5:in `accept'
     # ./lib/ransack/visitor.rb:29:in `block in visit_and'
     # ./lib/ransack/visitor.rb:29:in `map'
     # ./lib/ransack/visitor.rb:29:in `visit_and'
     # ./lib/ransack/visitor.rb:24:in `visit_Ransack_Nodes_Grouping'
     # ./lib/ransack/visitor.rb:54:in `visit'
     # ./lib/ransack/visitor.rb:5:in `accept'
     # ./lib/ransack/adapters/active_record/context.rb:27:in `evaluate'
     # ./lib/ransack/search.rb:44:in `result'
     # ./spec/ransack/adapters/active_record/context_spec.rb:98:in `block (3 levels) in <module:ActiveRecord>'

  10) Ransack::Predicate not_null with association query generates a value IS NOT NULL query
      Failure/Error:
              base_klass.with_connection do |connection|
                # The chain starts with the target table, but we want to end with it here (makes
                # more sense in this context), so we reverse
                chain.reverse_each do |reflection, table|
                  klass = reflection.klass
        
                  join_scope = reflection.join_scope(table, foreign_table, foreign_klass)
        
                  unless join_scope.references_values.empty?
                    join_dependency = join_scope.construct_join_dependency(
      
      NoMethodError:
        undefined method `with_connection' for Comment:Class
      # ./lib/polyamorous/activerecord/join_association_7_2.rb:16:in `join_constraints_with_tables'
      # ./lib/ransack/adapters/active_record/context.rb:334:in `extract_joins'
      # ./lib/ransack/adapters/active_record/context.rb:165:in `build_correlated_subquery'
      # ./lib/ransack/nodes/condition.rb:290:in `block in arel_predicate'
      # ./lib/ransack/nodes/condition.rb:287:in `map'
      # ./lib/ransack/nodes/condition.rb:287:in `arel_predicate'
      # ./lib/ransack/visitor.rb:17:in `visit_Ransack_Nodes_Condition'
      # ./lib/ransack/visitor.rb:54:in `visit'
      # ./lib/ransack/visitor.rb:5:in `accept'
      # ./lib/ransack/visitor.rb:29:in `block in visit_and'
      # ./lib/ransack/visitor.rb:29:in `map'
      # ./lib/ransack/visitor.rb:29:in `visit_and'
      # ./lib/ransack/visitor.rb:24:in `visit_Ransack_Nodes_Grouping'
      # ./lib/ransack/visitor.rb:54:in `visit'
      # ./lib/ransack/visitor.rb:5:in `accept'
      # ./lib/ransack/adapters/active_record/context.rb:27:in `evaluate'
      # ./lib/ransack/search.rb:44:in `result'
      # ./spec/ransack/predicate_spec.rb:409:in `block (4 levels) in <module:Ransack>'

  11) Ransack::Predicate not_null with association query generates a value IS NULL query when assigned false
      Failure/Error:
              base_klass.with_connection do |connection|
                # The chain starts with the target table, but we want to end with it here (makes
                # more sense in this context), so we reverse
                chain.reverse_each do |reflection, table|
                  klass = reflection.klass
        
                  join_scope = reflection.join_scope(table, foreign_table, foreign_klass)
        
                  unless join_scope.references_values.empty?
                    join_dependency = join_scope.construct_join_dependency(
      
      NoMethodError:
        undefined method `with_connection' for Comment:Class
      # ./lib/polyamorous/activerecord/join_association_7_2.rb:16:in `join_constraints_with_tables'
      # ./lib/ransack/adapters/active_record/context.rb:334:in `extract_joins'
      # ./lib/ransack/adapters/active_record/context.rb:165:in `build_correlated_subquery'
      # ./lib/ransack/nodes/condition.rb:290:in `block in arel_predicate'
      # ./lib/ransack/nodes/condition.rb:287:in `map'
      # ./lib/ransack/nodes/condition.rb:287:in `arel_predicate'
      # ./lib/ransack/visitor.rb:17:in `visit_Ransack_Nodes_Condition'
      # ./lib/ransack/visitor.rb:54:in `visit'
      # ./lib/ransack/visitor.rb:5:in `accept'
      # ./lib/ransack/visitor.rb:29:in `block in visit_and'
      # ./lib/ransack/visitor.rb:29:in `map'
      # ./lib/ransack/visitor.rb:29:in `visit_and'
      # ./lib/ransack/visitor.rb:24:in `visit_Ransack_Nodes_Grouping'
      # ./lib/ransack/visitor.rb:54:in `visit'
      # ./lib/ransack/visitor.rb:5:in `accept'
      # ./lib/ransack/adapters/active_record/context.rb:27:in `evaluate'
      # ./lib/ransack/search.rb:44:in `result'
      # ./spec/ransack/predicate_spec.rb:419:in `block (4 levels) in <module:Ransack>'

Finished in 0.71838 seconds (files took 12.55 seconds to load)
401 examples, 11 failures, 1 pending

Failed examples:

rspec ./spec/ransack/adapters/active_record/base_spec.rb:80 # Ransack::Adapters::ActiveRecord::Base#search with scopes applies scopes that define string SQL joins
rspec ./spec/ransack/adapters/active_record/base_spec.rb:172 # Ransack::Adapters::ActiveRecord::Base negative conditions on HABTM associations removes redundant joins from top query
rspec ./spec/ransack/adapters/active_record/base_spec.rb:178 # Ransack::Adapters::ActiveRecord::Base negative conditions on HABTM associations handles != for single values
rspec ./spec/ransack/adapters/active_record/base_spec.rb:185 # Ransack::Adapters::ActiveRecord::Base negative conditions on HABTM associations handles NOT IN for multiple attributes
rspec ./spec/ransack/adapters/active_record/base_spec.rb:209 # Ransack::Adapters::ActiveRecord::Base negative conditions on self-referenced associations handles multiple associations and aliases
rspec ./spec/ransack/adapters/active_record/context_spec.rb:43 # Ransack::Adapters::ActiveRecord::Context#build_correlated_subquery build correlated subquery for Root STI model
rspec ./spec/ransack/adapters/active_record/context_spec.rb:56 # Ransack::Adapters::ActiveRecord::Context#build_correlated_subquery build correlated subquery for Child STI model when predicate is not_eq
rspec ./spec/ransack/adapters/active_record/context_spec.rb:69 # Ransack::Adapters::ActiveRecord::Context#build_correlated_subquery build correlated subquery for Child STI model when predicate is eq
rspec ./spec/ransack/adapters/active_record/context_spec.rb:82 # Ransack::Adapters::ActiveRecord::Context#build_correlated_subquery build correlated subquery for multiple conditions (default scope)
rspec ./spec/ransack/predicate_spec.rb:407 # Ransack::Predicate not_null with association query generates a value IS NOT NULL query
rspec ./spec/ransack/predicate_spec.rb:417 # Ransack::Predicate not_null with association query generates a value IS NULL query when assigned false

Coverage report generated for RSpec to /Users/satouharuka/workspace/ransack/coverage. 1580 / 1670 LOC (94.61%) covered.
Stopped processing SimpleCov as a previous error not related to SimpleCov has been detected
/Users/satouharuka/.rbenv/versions/3.2.2/bin/ruby -I/Users/satouharuka/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-core-3.13.0/lib:/Users/satouharuka/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-support-3.13.1/lib /Users/satouharuka/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-core-3.13.0/exe/rspec spec/ransack/adapters/active_record/base_spec.rb spec/ransack/adapters/active_record/context_spec.rb spec/ransack/configuration_spec.rb spec/ransack/helpers/form_builder_spec.rb spec/ransack/helpers/form_helper_spec.rb spec/ransack/nodes/condition_spec.rb spec/ransack/nodes/grouping_spec.rb spec/ransack/nodes/value_spec.rb spec/ransack/predicate_spec.rb spec/ransack/search_spec.rb spec/ransack/translate_spec.rb failed

@satou-haruka-37
Copy link
Contributor Author

satou-haruka-37 commented Jul 28, 2024

Pending: (Failures listed here are expected and do not affect your suite's status)
の1つ目

Pending: (Failures listed here are expected and do not affect your suite's status)

  1) Ransack::Search#build preserves (inverts) default scope and conditions for negative subqueries
     # spec should pass, but I do not know how/where to fix lib code
     Failure/Error:
             base_klass.with_connection do |connection|
               # The chain starts with the target table, but we want to end with it here (makes
               # more sense in this context), so we reverse
               chain.reverse_each do |reflection, table|
                 klass = reflection.klass
       
                 join_scope = reflection.join_scope(table, foreign_table, foreign_klass)
       
                 unless join_scope.references_values.empty?
                   join_dependency = join_scope.construct_join_dependency(
     
     NoMethodError:
       undefined method `with_connection' for Article:Class
     # ./lib/polyamorous/activerecord/join_association_7_2.rb:16:in `join_constraints_with_tables'
     # ./lib/ransack/adapters/active_record/context.rb:334:in `extract_joins'
     # ./lib/ransack/adapters/active_record/context.rb:165:in `build_correlated_subquery'
     # ./lib/ransack/nodes/condition.rb:290:in `block in arel_predicate'
     # ./lib/ransack/nodes/condition.rb:287:in `map'
     # ./lib/ransack/nodes/condition.rb:287:in `arel_predicate'
     # ./lib/ransack/visitor.rb:17:in `visit_Ransack_Nodes_Condition'
     # ./lib/ransack/visitor.rb:54:in `visit'
     # ./lib/ransack/visitor.rb:5:in `accept'
     # ./lib/ransack/visitor.rb:29:in `block in visit_and'
     # ./lib/ransack/visitor.rb:29:in `map'
     # ./lib/ransack/visitor.rb:29:in `visit_and'
     # ./lib/ransack/visitor.rb:24:in `visit_Ransack_Nodes_Grouping'
     # ./lib/ransack/visitor.rb:54:in `visit'
     # ./lib/ransack/visitor.rb:5:in `accept'
     # ./lib/ransack/adapters/active_record/context.rb:27:in `evaluate'
     # ./lib/ransack/search.rb:44:in `result'
     # ./spec/ransack/search_spec.rb:183:in `block (3 levels) in <module:Ransack>'

@satou-haruka-37
Copy link
Contributor Author

spec/ransack/search_spec.rbの183行目

        pending("spec should pass, but I do not know how/where to fix lib code")
        s = Search.new(Person, published_articles_title_not_eq: 'Test')
        expect(s.result.to_sql).to include 'default_scope'
        expect(s.result.to_sql).to include 'published'

で、with_connection というメソッドが無いと言われている。

NoMethodError:
       undefined method ' for Article:Class

@satou-haruka-37
Copy link
Contributor Author

こちらは Pending だが、他の Failures も同じように
with_connection というメソッドが無いと言われているため原因を探す

@satou-haruka-37
Copy link
Contributor Author

with_connection を検索すると、
lib/polyamorous/activerecord/join_association_7_2.rb
でヒットする。

module Polyamorous
  module JoinAssociationExtensions
    # Same as #join_constraints, but instead of constructing tables from the
    # given block, uses the ones passed
    def join_constraints_with_tables(foreign_table, foreign_klass, join_type, alias_tracker, tables)
      joins = []
      chain = []

      reflection.chain.each.with_index do |reflection, i|
        table = tables[i]

        @table ||= table
        chain << [reflection, table]
      end

      base_klass.with_connection do |connection|
        # The chain starts with the target table, but we want to end with it here (makes
        # more sense in this context), so we reverse
        chain.reverse_each do |reflection, table|
          klass = reflection.klass

          join_scope = reflection.join_scope(table, foreign_table, foreign_klass)

          unless join_scope.references_values.empty?
            join_dependency = join_scope.construct_join_dependency(
              join_scope.eager_load_values | join_scope.includes_values, Arel::Nodes::OuterJoin
            )
            join_scope.joins!(join_dependency)
          end

          arel = join_scope.arel(alias_tracker.aliases)
          nodes = arel.constraints.first

          if nodes.is_a?(Arel::Nodes::And)
            others = nodes.children.extract! do |node|
              !Arel.fetch_attribute(node) { |attr| attr.relation.name == table.name }
            end
          end

          joins << table.create_join(table, table.create_on(nodes), join_type)

          if others && !others.empty?
            joins.concat arel.join_sources
            append_constraints(connection, joins.last, others)
          end

          # The current table in this iteration becomes the foreign table in the next
          foreign_table, foreign_klass = table, klass
        end

        joins
      end
    end
  end
end

@satou-haruka-37
Copy link
Contributor Author

base_klass を探す

@satou-haruka-37
Copy link
Contributor Author

ググって見つかったもの
Method: ActiveRecord::Associations::JoinDependency::JoinPart#base_klass

https://www.rubydoc.info/github/rails/rails/ActiveRecord%2FAssociations%2FJoinDependency%2FJoinPart:base_klass

@satou-haruka-37
Copy link
Contributor Author

base_klass とは、
おそらく、ransack独自のものかRailsのActiveRecord関係のもの、ということがわかった

@satou-haruka-37
Copy link
Contributor Author

その後何から手をつけたら良いか分からずとりあえず
with_connection も検索してみたところ下記の記事を見つけた。

Rails 5.0より前は、これらの一部をRackミドルウェアのクラス(ActiveRecord::ConnectionAdapters::ConnectionManagement)で扱ったり、ActiveRecord::Base.connection_pool.with_connectionなどのメソッドで直接ラップしていました。Executorはこれらをより抽象度の高い単一のインターフェイスで置き換えます。

Railsガイドより

@satou-haruka-37
Copy link
Contributor Author

@satou-haruka-37
Copy link
Contributor Author

RubyやRailsのバージョンが関係しているのかと思い確認した。

satouharuka@satouharukanoMacBook-Pro ransack % rails -v
Rails 7.1.3.4
satouharuka@satouharukanoMacBook-Pro ransack % ruby -v
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [arm64-darwin23]

@satou-haruka-37
Copy link
Contributor Author

報告1つ目
Contributing to Ransack の通りに
リポジトリをforkし、 bundle install を実行したところ、
以下のエラーが出ました。

1 warning generated.
compiling statement.c
linking shared-object mysql2/mysql2.bundle
ld: warning: ignoring duplicate libraries:
'-lruby.3.2'
ld: library 'zstd' not found
clang: error: linker command failed with exit code
1 (use -v to see invocation)
make: *** [mysql2.bundle] Error 1

make failed, exit code 2

調べたところ記事によると以下を実行すると良いと言うことだったので、

export LIBRARY_PATH=$LIBRARY_PATH:$(brew --prefix zstd)/lib/

実行後、再度 bundle install をするとうまくいきました。
Contributing to Ransack のページ内には mysql2 のエラーが出た場合の記載が無いため、追記が必要ではないかと思いました。

@satou-haruka-37
Copy link
Contributor Author

報告2つ目
Contributing to Ransack の通りに進め、

bundle exec rake spec

を実行したところ、テストが通らず以下のエラーになったことを報告します。

satouharuka@satouharukanoMacBook-Pro ransack % bundle exec rake spec
/Users/satouharuka/.rbenv/versions/3.2.2/bin/ruby -I/Users/satouharuka/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-core-3.13.0/lib:/Users/satouharuka/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-support-3.13.1/lib /Users/satouharuka/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-core-3.13.0/exe/rspec spec/ransack/adapters/active_record/base_spec.rb spec/ransack/adapters/active_record/context_spec.rb spec/ransack/configuration_spec.rb spec/ransack/helpers/form_builder_spec.rb spec/ransack/helpers/form_helper_spec.rb spec/ransack/nodes/condition_spec.rb spec/ransack/nodes/grouping_spec.rb spec/ransack/nodes/value_spec.rb spec/ransack/predicate_spec.rb spec/ransack/search_spec.rb spec/ransack/translate_spec.rb
====================================================================================
Running Ransack specs with SQLite, Active Record 7.1.3.4, Arel 10.0.0 and Ruby 3.2.2
====================================================================================
................F......FFFF................................................................................FFFF................................................................................................................................................................................................................................FF.......................*........................................

Pending: (Failures listed here are expected and do not affect your suite's status)

  1) Ransack::Search#build preserves (inverts) default scope and conditions for negative subqueries
     # spec should pass, but I do not know how/where to fix lib code
     Failure/Error:
             base_klass.with_connection do |connection|
               # The chain starts with the target table, but we want to end with it here (makes
               # more sense in this context), so we reverse
               chain.reverse_each do |reflection, table|
                 klass = reflection.klass
       
                 join_scope = reflection.join_scope(table, foreign_table, foreign_klass)
       
                 unless join_scope.references_values.empty?
                   join_dependency = join_scope.construct_join_dependency(
     
     NoMethodError:
       undefined method `with_connection' for Article:Class
     # ./lib/polyamorous/activerecord/join_association_7_2.rb:16:in `join_constraints_with_tables'
     # ./lib/ransack/adapters/active_record/context.rb:334:in `extract_joins'
     # ./lib/ransack/adapters/active_record/context.rb:165:in `build_correlated_subquery'
     # ./lib/ransack/nodes/condition.rb:290:in `block in arel_predicate'
     # ./lib/ransack/nodes/condition.rb:287:in `map'
     # ./lib/ransack/nodes/condition.rb:287:in `arel_predicate'
     # ./lib/ransack/visitor.rb:17:in `visit_Ransack_Nodes_Condition'
     # ./lib/ransack/visitor.rb:54:in `visit'
     # ./lib/ransack/visitor.rb:5:in `accept'
     # ./lib/ransack/visitor.rb:29:in `block in visit_and'
     # ./lib/ransack/visitor.rb:29:in `map'
     # ./lib/ransack/visitor.rb:29:in `visit_and'
     # ./lib/ransack/visitor.rb:24:in `visit_Ransack_Nodes_Grouping'
     # ./lib/ransack/visitor.rb:54:in `visit'
     # ./lib/ransack/visitor.rb:5:in `accept'
     # ./lib/ransack/adapters/active_record/context.rb:27:in `evaluate'
     # ./lib/ransack/search.rb:44:in `result'
     # ./spec/ransack/search_spec.rb:183:in `block (3 levels) in <module:Ransack>'

Failures:

  1) Ransack::Adapters::ActiveRecord::Base#search with scopes applies scopes that define string SQL joins
     Failure/Error:
             base_klass.with_connection do |connection|
               # The chain starts with the target table, but we want to end with it here (makes
               # more sense in this context), so we reverse
               chain.reverse_each do |reflection, table|
                 klass = reflection.klass
       
                 join_scope = reflection.join_scope(table, foreign_table, foreign_klass)
       
                 unless join_scope.references_values.empty?
                   join_dependency = join_scope.construct_join_dependency(
     
     NoMethodError:
       undefined method `with_connection' for Note:Class
     # ./lib/polyamorous/activerecord/join_association_7_2.rb:16:in `join_constraints_with_tables'
     # ./lib/ransack/adapters/active_record/context.rb:334:in `extract_joins'
     # ./lib/ransack/adapters/active_record/context.rb:165:in `build_correlated_subquery'
     # ./lib/ransack/nodes/condition.rb:290:in `block in arel_predicate'
     # ./lib/ransack/nodes/condition.rb:287:in `map'
     # ./lib/ransack/nodes/condition.rb:287:in `arel_predicate'
     # ./lib/ransack/visitor.rb:17:in `visit_Ransack_Nodes_Condition'
     # ./lib/ransack/visitor.rb:54:in `visit'
     # ./lib/ransack/visitor.rb:5:in `accept'
     # ./lib/ransack/visitor.rb:29:in `block in visit_and'
     # ./lib/ransack/visitor.rb:29:in `map'
     # ./lib/ransack/visitor.rb:29:in `visit_and'
     # ./lib/ransack/visitor.rb:24:in `visit_Ransack_Nodes_Grouping'
     # ./lib/ransack/visitor.rb:54:in `visit'
     # ./lib/ransack/visitor.rb:5:in `accept'
     # ./lib/ransack/adapters/active_record/context.rb:27:in `evaluate'
     # ./lib/ransack/search.rb:44:in `result'
     # ./spec/ransack/adapters/active_record/base_spec.rb:87:in `block (4 levels) in <module:ActiveRecord>'

  2) Ransack::Adapters::ActiveRecord::Base negative conditions on HABTM associations removes redundant joins from top query
     Failure/Error:
             base_klass.with_connection do |connection|
               # The chain starts with the target table, but we want to end with it here (makes
               # more sense in this context), so we reverse
               chain.reverse_each do |reflection, table|
                 klass = reflection.klass
       
                 join_scope = reflection.join_scope(table, foreign_table, foreign_klass)
       
                 unless join_scope.references_values.empty?
                   join_dependency = join_scope.construct_join_dependency(
     
     NoMethodError:
       undefined method `with_connection' for Tag:Class
     # ./lib/polyamorous/activerecord/join_association_7_2.rb:16:in `join_constraints_with_tables'
     # ./lib/ransack/adapters/active_record/context.rb:334:in `extract_joins'
     # ./lib/ransack/adapters/active_record/context.rb:165:in `build_correlated_subquery'
     # ./lib/ransack/nodes/condition.rb:290:in `block in arel_predicate'
     # ./lib/ransack/nodes/condition.rb:287:in `map'
     # ./lib/ransack/nodes/condition.rb:287:in `arel_predicate'
     # ./lib/ransack/visitor.rb:17:in `visit_Ransack_Nodes_Condition'
     # ./lib/ransack/visitor.rb:54:in `visit'
     # ./lib/ransack/visitor.rb:5:in `accept'
     # ./lib/ransack/visitor.rb:29:in `block in visit_and'
     # ./lib/ransack/visitor.rb:29:in `map'
     # ./lib/ransack/visitor.rb:29:in `visit_and'
     # ./lib/ransack/visitor.rb:24:in `visit_Ransack_Nodes_Grouping'
     # ./lib/ransack/visitor.rb:54:in `visit'
     # ./lib/ransack/visitor.rb:5:in `accept'
     # ./lib/ransack/adapters/active_record/context.rb:27:in `evaluate'
     # ./lib/ransack/search.rb:44:in `result'
     # ./spec/ransack/adapters/active_record/base_spec.rb:174:in `block (3 levels) in <module:ActiveRecord>'

  3) Ransack::Adapters::ActiveRecord::Base negative conditions on HABTM associations handles != for single values
     Failure/Error:
             base_klass.with_connection do |connection|
               # The chain starts with the target table, but we want to end with it here (makes
               # more sense in this context), so we reverse
               chain.reverse_each do |reflection, table|
                 klass = reflection.klass
       
                 join_scope = reflection.join_scope(table, foreign_table, foreign_klass)
       
                 unless join_scope.references_values.empty?
                   join_dependency = join_scope.construct_join_dependency(
     
     NoMethodError:
       undefined method `with_connection' for Tag:Class
     # ./lib/polyamorous/activerecord/join_association_7_2.rb:16:in `join_constraints_with_tables'
     # ./lib/ransack/adapters/active_record/context.rb:334:in `extract_joins'
     # ./lib/ransack/adapters/active_record/context.rb:165:in `build_correlated_subquery'
     # ./lib/ransack/nodes/condition.rb:290:in `block in arel_predicate'
     # ./lib/ransack/nodes/condition.rb:287:in `map'
     # ./lib/ransack/nodes/condition.rb:287:in `arel_predicate'
     # ./lib/ransack/visitor.rb:17:in `visit_Ransack_Nodes_Condition'
     # ./lib/ransack/visitor.rb:54:in `visit'
     # ./lib/ransack/visitor.rb:5:in `accept'
     # ./lib/ransack/visitor.rb:29:in `block in visit_and'
     # ./lib/ransack/visitor.rb:29:in `map'
     # ./lib/ransack/visitor.rb:29:in `visit_and'
     # ./lib/ransack/visitor.rb:24:in `visit_Ransack_Nodes_Grouping'
     # ./lib/ransack/visitor.rb:54:in `visit'
     # ./lib/ransack/visitor.rb:5:in `accept'
     # ./lib/ransack/adapters/active_record/context.rb:27:in `evaluate'
     # ./lib/ransack/search.rb:44:in `result'
     # ./spec/ransack/adapters/active_record/base_spec.rb:180:in `block (3 levels) in <module:ActiveRecord>'

  4) Ransack::Adapters::ActiveRecord::Base negative conditions on HABTM associations handles NOT IN for multiple attributes
     Failure/Error:
             base_klass.with_connection do |connection|
               # The chain starts with the target table, but we want to end with it here (makes
               # more sense in this context), so we reverse
               chain.reverse_each do |reflection, table|
                 klass = reflection.klass
       
                 join_scope = reflection.join_scope(table, foreign_table, foreign_klass)
       
                 unless join_scope.references_values.empty?
                   join_dependency = join_scope.construct_join_dependency(
     
     NoMethodError:
       undefined method `with_connection' for Tag:Class
     # ./lib/polyamorous/activerecord/join_association_7_2.rb:16:in `join_constraints_with_tables'
     # ./lib/ransack/adapters/active_record/context.rb:334:in `extract_joins'
     # ./lib/ransack/adapters/active_record/context.rb:165:in `build_correlated_subquery'
     # ./lib/ransack/nodes/condition.rb:290:in `block in arel_predicate'
     # ./lib/ransack/nodes/condition.rb:287:in `map'
     # ./lib/ransack/nodes/condition.rb:287:in `arel_predicate'
     # ./lib/ransack/visitor.rb:17:in `visit_Ransack_Nodes_Condition'
     # ./lib/ransack/visitor.rb:54:in `visit'
     # ./lib/ransack/visitor.rb:5:in `accept'
     # ./lib/ransack/visitor.rb:29:in `block in visit_and'
     # ./lib/ransack/visitor.rb:29:in `map'
     # ./lib/ransack/visitor.rb:29:in `visit_and'
     # ./lib/ransack/visitor.rb:24:in `visit_Ransack_Nodes_Grouping'
     # ./lib/ransack/visitor.rb:54:in `visit'
     # ./lib/ransack/visitor.rb:5:in `accept'
     # ./lib/ransack/adapters/active_record/context.rb:27:in `evaluate'
     # ./lib/ransack/search.rb:44:in `result'
     # ./spec/ransack/adapters/active_record/base_spec.rb:187:in `block (3 levels) in <module:ActiveRecord>'

  5) Ransack::Adapters::ActiveRecord::Base negative conditions on self-referenced associations handles multiple associations and aliases
     Failure/Error:
             base_klass.with_connection do |connection|
               # The chain starts with the target table, but we want to end with it here (makes
               # more sense in this context), so we reverse
               chain.reverse_each do |reflection, table|
                 klass = reflection.klass
       
                 join_scope = reflection.join_scope(table, foreign_table, foreign_klass)
       
                 unless join_scope.references_values.empty?
                   join_dependency = join_scope.construct_join_dependency(
     
     NoMethodError:
       undefined method `with_connection' for Person:Class
     # ./lib/polyamorous/activerecord/join_association_7_2.rb:16:in `join_constraints_with_tables'
     # ./lib/ransack/adapters/active_record/context.rb:334:in `extract_joins'
     # ./lib/ransack/adapters/active_record/context.rb:165:in `build_correlated_subquery'
     # ./lib/ransack/nodes/condition.rb:290:in `block in arel_predicate'
     # ./lib/ransack/nodes/condition.rb:287:in `map'
     # ./lib/ransack/nodes/condition.rb:287:in `arel_predicate'
     # ./lib/ransack/visitor.rb:17:in `visit_Ransack_Nodes_Condition'
     # ./lib/ransack/visitor.rb:54:in `visit'
     # ./lib/ransack/visitor.rb:5:in `accept'
     # ./lib/ransack/visitor.rb:29:in `block in visit_and'
     # ./lib/ransack/visitor.rb:29:in `map'
     # ./lib/ransack/visitor.rb:29:in `visit_and'
     # ./lib/ransack/visitor.rb:24:in `visit_Ransack_Nodes_Grouping'
     # ./lib/ransack/visitor.rb:54:in `visit'
     # ./lib/ransack/visitor.rb:5:in `accept'
     # ./lib/ransack/adapters/active_record/context.rb:27:in `evaluate'
     # ./lib/ransack/search.rb:44:in `result'
     # ./spec/ransack/adapters/active_record/base_spec.rb:219:in `block (3 levels) in <module:ActiveRecord>'

  6) Ransack::Adapters::ActiveRecord::Context#build_correlated_subquery build correlated subquery for Root STI model
     Failure/Error:
             base_klass.with_connection do |connection|
               # The chain starts with the target table, but we want to end with it here (makes
               # more sense in this context), so we reverse
               chain.reverse_each do |reflection, table|
                 klass = reflection.klass
       
                 join_scope = reflection.join_scope(table, foreign_table, foreign_klass)
       
                 unless join_scope.references_values.empty?
                   join_dependency = join_scope.construct_join_dependency(
     
     NoMethodError:
       undefined method `with_connection' for Article:Class
     # ./lib/polyamorous/activerecord/join_association_7_2.rb:16:in `join_constraints_with_tables'
     # ./lib/ransack/adapters/active_record/context.rb:334:in `extract_joins'
     # ./lib/ransack/adapters/active_record/context.rb:165:in `build_correlated_subquery'
     # ./spec/ransack/adapters/active_record/context_spec.rb:46:in `block (3 levels) in <module:ActiveRecord>'

  7) Ransack::Adapters::ActiveRecord::Context#build_correlated_subquery build correlated subquery for Child STI model when predicate is not_eq
     Failure/Error:
             base_klass.with_connection do |connection|
               # The chain starts with the target table, but we want to end with it here (makes
               # more sense in this context), so we reverse
               chain.reverse_each do |reflection, table|
                 klass = reflection.klass
       
                 join_scope = reflection.join_scope(table, foreign_table, foreign_klass)
       
                 unless join_scope.references_values.empty?
                   join_dependency = join_scope.construct_join_dependency(
     
     NoMethodError:
       undefined method `with_connection' for StoryArticle:Class
     # ./lib/polyamorous/activerecord/join_association_7_2.rb:16:in `join_constraints_with_tables'
     # ./lib/ransack/adapters/active_record/context.rb:334:in `extract_joins'
     # ./lib/ransack/adapters/active_record/context.rb:165:in `build_correlated_subquery'
     # ./spec/ransack/adapters/active_record/context_spec.rb:59:in `block (3 levels) in <module:ActiveRecord>'

  8) Ransack::Adapters::ActiveRecord::Context#build_correlated_subquery build correlated subquery for Child STI model when predicate is eq
     Failure/Error:
             base_klass.with_connection do |connection|
               # The chain starts with the target table, but we want to end with it here (makes
               # more sense in this context), so we reverse
               chain.reverse_each do |reflection, table|
                 klass = reflection.klass
       
                 join_scope = reflection.join_scope(table, foreign_table, foreign_klass)
       
                 unless join_scope.references_values.empty?
                   join_dependency = join_scope.construct_join_dependency(
     
     NoMethodError:
       undefined method `with_connection' for StoryArticle:Class
     # ./lib/polyamorous/activerecord/join_association_7_2.rb:16:in `join_constraints_with_tables'
     # ./lib/ransack/adapters/active_record/context.rb:334:in `extract_joins'
     # ./lib/ransack/adapters/active_record/context.rb:165:in `build_correlated_subquery'
     # ./spec/ransack/adapters/active_record/context_spec.rb:72:in `block (3 levels) in <module:ActiveRecord>'

  9) Ransack::Adapters::ActiveRecord::Context#build_correlated_subquery build correlated subquery for multiple conditions (default scope)
     Failure/Error:
             base_klass.with_connection do |connection|
               # The chain starts with the target table, but we want to end with it here (makes
               # more sense in this context), so we reverse
               chain.reverse_each do |reflection, table|
                 klass = reflection.klass
       
                 join_scope = reflection.join_scope(table, foreign_table, foreign_klass)
       
                 unless join_scope.references_values.empty?
                   join_dependency = join_scope.construct_join_dependency(
     
     NoMethodError:
       undefined method `with_connection' for Comment:Class
     # ./lib/polyamorous/activerecord/join_association_7_2.rb:16:in `join_constraints_with_tables'
     # ./lib/ransack/adapters/active_record/context.rb:334:in `extract_joins'
     # ./lib/ransack/adapters/active_record/context.rb:165:in `build_correlated_subquery'
     # ./lib/ransack/nodes/condition.rb:290:in `block in arel_predicate'
     # ./lib/ransack/nodes/condition.rb:287:in `map'
     # ./lib/ransack/nodes/condition.rb:287:in `arel_predicate'
     # ./lib/ransack/visitor.rb:17:in `visit_Ransack_Nodes_Condition'
     # ./lib/ransack/visitor.rb:54:in `visit'
     # ./lib/ransack/visitor.rb:5:in `accept'
     # ./lib/ransack/visitor.rb:29:in `block in visit_and'
     # ./lib/ransack/visitor.rb:29:in `map'
     # ./lib/ransack/visitor.rb:29:in `visit_and'
     # ./lib/ransack/visitor.rb:24:in `visit_Ransack_Nodes_Grouping'
     # ./lib/ransack/visitor.rb:54:in `visit'
     # ./lib/ransack/visitor.rb:5:in `accept'
     # ./lib/ransack/adapters/active_record/context.rb:27:in `evaluate'
     # ./lib/ransack/search.rb:44:in `result'
     # ./spec/ransack/adapters/active_record/context_spec.rb:98:in `block (3 levels) in <module:ActiveRecord>'

  10) Ransack::Predicate not_null with association query generates a value IS NOT NULL query
      Failure/Error:
              base_klass.with_connection do |connection|
                # The chain starts with the target table, but we want to end with it here (makes
                # more sense in this context), so we reverse
                chain.reverse_each do |reflection, table|
                  klass = reflection.klass
        
                  join_scope = reflection.join_scope(table, foreign_table, foreign_klass)
        
                  unless join_scope.references_values.empty?
                    join_dependency = join_scope.construct_join_dependency(
      
      NoMethodError:
        undefined method `with_connection' for Comment:Class
      # ./lib/polyamorous/activerecord/join_association_7_2.rb:16:in `join_constraints_with_tables'
      # ./lib/ransack/adapters/active_record/context.rb:334:in `extract_joins'
      # ./lib/ransack/adapters/active_record/context.rb:165:in `build_correlated_subquery'
      # ./lib/ransack/nodes/condition.rb:290:in `block in arel_predicate'
      # ./lib/ransack/nodes/condition.rb:287:in `map'
      # ./lib/ransack/nodes/condition.rb:287:in `arel_predicate'
      # ./lib/ransack/visitor.rb:17:in `visit_Ransack_Nodes_Condition'
      # ./lib/ransack/visitor.rb:54:in `visit'
      # ./lib/ransack/visitor.rb:5:in `accept'
      # ./lib/ransack/visitor.rb:29:in `block in visit_and'
      # ./lib/ransack/visitor.rb:29:in `map'
      # ./lib/ransack/visitor.rb:29:in `visit_and'
      # ./lib/ransack/visitor.rb:24:in `visit_Ransack_Nodes_Grouping'
      # ./lib/ransack/visitor.rb:54:in `visit'
      # ./lib/ransack/visitor.rb:5:in `accept'
      # ./lib/ransack/adapters/active_record/context.rb:27:in `evaluate'
      # ./lib/ransack/search.rb:44:in `result'
      # ./spec/ransack/predicate_spec.rb:409:in `block (4 levels) in <module:Ransack>'

  11) Ransack::Predicate not_null with association query generates a value IS NULL query when assigned false
      Failure/Error:
              base_klass.with_connection do |connection|
                # The chain starts with the target table, but we want to end with it here (makes
                # more sense in this context), so we reverse
                chain.reverse_each do |reflection, table|
                  klass = reflection.klass
        
                  join_scope = reflection.join_scope(table, foreign_table, foreign_klass)
        
                  unless join_scope.references_values.empty?
                    join_dependency = join_scope.construct_join_dependency(
      
      NoMethodError:
        undefined method `with_connection' for Comment:Class
      # ./lib/polyamorous/activerecord/join_association_7_2.rb:16:in `join_constraints_with_tables'
      # ./lib/ransack/adapters/active_record/context.rb:334:in `extract_joins'
      # ./lib/ransack/adapters/active_record/context.rb:165:in `build_correlated_subquery'
      # ./lib/ransack/nodes/condition.rb:290:in `block in arel_predicate'
      # ./lib/ransack/nodes/condition.rb:287:in `map'
      # ./lib/ransack/nodes/condition.rb:287:in `arel_predicate'
      # ./lib/ransack/visitor.rb:17:in `visit_Ransack_Nodes_Condition'
      # ./lib/ransack/visitor.rb:54:in `visit'
      # ./lib/ransack/visitor.rb:5:in `accept'
      # ./lib/ransack/visitor.rb:29:in `block in visit_and'
      # ./lib/ransack/visitor.rb:29:in `map'
      # ./lib/ransack/visitor.rb:29:in `visit_and'
      # ./lib/ransack/visitor.rb:24:in `visit_Ransack_Nodes_Grouping'
      # ./lib/ransack/visitor.rb:54:in `visit'
      # ./lib/ransack/visitor.rb:5:in `accept'
      # ./lib/ransack/adapters/active_record/context.rb:27:in `evaluate'
      # ./lib/ransack/search.rb:44:in `result'
      # ./spec/ransack/predicate_spec.rb:419:in `block (4 levels) in <module:Ransack>'

Finished in 0.70468 seconds (files took 1 second to load)
401 examples, 11 failures, 1 pending

Failed examples:

rspec ./spec/ransack/adapters/active_record/base_spec.rb:80 # Ransack::Adapters::ActiveRecord::Base#search with scopes applies scopes that define string SQL joins
rspec ./spec/ransack/adapters/active_record/base_spec.rb:172 # Ransack::Adapters::ActiveRecord::Base negative conditions on HABTM associations removes redundant joins from top query
rspec ./spec/ransack/adapters/active_record/base_spec.rb:178 # Ransack::Adapters::ActiveRecord::Base negative conditions on HABTM associations handles != for single values
rspec ./spec/ransack/adapters/active_record/base_spec.rb:185 # Ransack::Adapters::ActiveRecord::Base negative conditions on HABTM associations handles NOT IN for multiple attributes
rspec ./spec/ransack/adapters/active_record/base_spec.rb:209 # Ransack::Adapters::ActiveRecord::Base negative conditions on self-referenced associations handles multiple associations and aliases
rspec ./spec/ransack/adapters/active_record/context_spec.rb:43 # Ransack::Adapters::ActiveRecord::Context#build_correlated_subquery build correlated subquery for Root STI model
rspec ./spec/ransack/adapters/active_record/context_spec.rb:56 # Ransack::Adapters::ActiveRecord::Context#build_correlated_subquery build correlated subquery for Child STI model when predicate is not_eq
rspec ./spec/ransack/adapters/active_record/context_spec.rb:69 # Ransack::Adapters::ActiveRecord::Context#build_correlated_subquery build correlated subquery for Child STI model when predicate is eq
rspec ./spec/ransack/adapters/active_record/context_spec.rb:82 # Ransack::Adapters::ActiveRecord::Context#build_correlated_subquery build correlated subquery for multiple conditions (default scope)
rspec ./spec/ransack/predicate_spec.rb:407 # Ransack::Predicate not_null with association query generates a value IS NOT NULL query
rspec ./spec/ransack/predicate_spec.rb:417 # Ransack::Predicate not_null with association query generates a value IS NULL query when assigned false

Coverage report generated for RSpec to /Users/satouharuka/workspace/ransack/coverage. 1580 / 1670 LOC (94.61%) covered.
Stopped processing SimpleCov as a previous error not related to SimpleCov has been detected
/Users/satouharuka/.rbenv/versions/3.2.2/bin/ruby -I/Users/satouharuka/.rbenv/versions/3.2.2/lib/ruby/geger, parent_id: integer, name: string, email: string, only_search: string, only_sort: string, only_admin: string, new_start: string, stop_end: string, salary: integer, life_start: date, awesome: boolean, terms_and_conditions: boolean, true_or_false: boolean, created_at: datetime, updated_at: datetime), @plural_name="people", @join_table=nil, @foreign_key="person_id", @association_foreign_key=nil, @association_primary_key=nil, @inverse_name=nil>, @inverse_which_updates_counter_cache_defined=false, @inverse_which_updates_counter_cache=nil, @name=:comments, @scope=nil, @options={}, @active_record=Person(id: integer, parent_id: integer, name: string, email: string, only_s

@satou-haruka-37
Copy link
Contributor Author

satou-haruka-37 commented Jul 28, 2024

#1858 (comment)
の清書版

日本語
もし macOS ユーザーかつ homebrew を使用していて zstd を入れる場合には、以下のコマンドを実行してください。

export LIBRARY_PATH=$LIBRARY_PATH:$(brew --prefix zstd)/lib/

英語
If you are a macOS user and using homebrew and want to include zstd, run the following command

export LIBRARY_PATH=$LIBRARY_PATH:$(brew --prefix zstd)/lib/

@satou-haruka-37
Copy link
Contributor Author

サポーターの助言より
手順の中ではなく、下の方に注意書きとして以下の内容を記載


もし macOS ユーザー( homebrew )を使用していて、以下のエラーが出た場合には

ld: library 'zstd' not found

環境変数ライブラリエクスポートに zstd のパスを設定する必要があります。
.zshrc に以下のコマンドを追記してください。

export LIBRARY_PATH=$LIBRARY_PATH:$(brew --prefix zstd)/lib/

@satou-haruka-37
Copy link
Contributor Author

If you are a macOS user ( homebrew ) and you get the following error

ld: library 'zstd' not found

You need to set the path to zstd in the environment variable library export.
Add the following command to your .zshrc.

export LIBRARY_PATH=$LIBRARY_PATH:$(brew --prefix zstd)/lib/

@satou-haruka-37
Copy link
Contributor Author

プルリクの文面

Contributing to Ransack の通りに
リポジトリをforkし、 bundle install を実行したところ、
以下のエラーが出ました。

1 warning generated.
compiling statement.c
linking shared-object mysql2/mysql2.bundle
ld: warning: ignoring duplicate libraries:
'-lruby.3.2'
ld: library 'zstd' not found
clang: error: linker command failed with exit code
1 (use -v to see invocation)
make: *** [mysql2.bundle] Error 1

make failed, exit code 2

そのため、注釈を追記するのがベターでは無いかと考えました。

@satou-haruka-37
Copy link
Contributor Author

As per Contributing to Ransack
I forked the repository and ran bundle install,
I got the following error

1 warning generated.
compiling statement.c
linking shared-object mysql2/mysql2.bundle
ld: warning: ignoring duplicate libraries: '-lruby.3.2'.
'-lruby.3.2'.
ld: library 'zstd' not found
clang: error: linker command failed with exit code
1 (use -v to see invocation)
make: *** [mysql2.bundle] Error 1

make failed, exit code 2

Therefore, I thought it would be better to add an annotation.

@satou-haruka-37
Copy link
Contributor Author

satou-haruka-37 commented Jul 28, 2024

報告2つ目

I was proceeding as described in Contributing to Ransack,

bundle exec rake spec

command, the test did not pass,
The following error occurred.

(テスト実行結果を貼付)

@satou-haruka-37
Copy link
Contributor Author

現時点で報告するならこれで、
解決方法を探したい。

@satou-haruka-37
Copy link
Contributor Author

satou-haruka-37 commented Jul 28, 2024

2つ目で報告しようとしていたものが既に他の人が報告していた。
activerecord-hackery/ransack#1507

さらにその返信で、既に対応していた。(マージは未)
activerecord-hackery/ransack#1506

@satou-haruka-37
Copy link
Contributor Author

サポーターより助言
対応済みのプルリクをローカルで動かしてみてうまくいくか試す。
それでうまくいった場合には、修正の対応をしたプルリクにコメントを追加する
「私も同じエラーが発生したためこのプルリクエストをローカルに持ってきて動かしてみたらうまくいきました」などのような

@satou-haruka-37
Copy link
Contributor Author

satou-haruka-37 commented Jul 28, 2024

ransack の元のリポジトリのプルリクを、
fork して clone した自分のリポジトリから fetch でとってくることはできなかった

satouharuka@satouharukanoMacBook-Pro ransack % git fetch origin robingram:fix-rails72-require:robingram:fix-rails72-require
fatal: invalid refspec 'robingram:fix-rails72-require:robingram:fix-rails72-require'

@satou-haruka-37
Copy link
Contributor Author

  1. https://patch-diff.githubusercontent.com/raw/activerecord-hackery/ransack/pull/1506.patch にアクセス
  2. 内容を全てコピー
  3. 以下を実行
% pbpaste > patch
  1. patchというファイルが生成され、内容に先ほどコピーしたものが書かれている。
  2. 以下を実行
% git am patch

実行結果

Applying: Fix require of rails 7.2 join association file
Applying: Use 7.1.3.4 for rails 7.1 version in tests
  1. fork&cloneしたローカルの自分のリポジトリのGitに、このプルリクエスト上のコミットが追加された状態となった。

@satou-haruka-37
Copy link
Contributor Author

git log コマンドでも、コミットが追加されていることが確認できた

satouharuka@satouharukanoMacBook-Pro ransack % git log
commit ef55d0d0020abad16d6e29e24aaae28120140ed6 (HEAD -> main)
Author: Rob Ingram <[email protected]>
Date:   Tue Jul 16 09:00:38 2024 +1200

    Use 7.1.3.4 for rails 7.1 version in tests

commit d4a8ff61a005492f508dba0f4ae359003a4dd514
Author: Rob Ingram <[email protected]>
Date:   Tue Jul 16 08:42:35 2024 +1200

    Fix require of rails 7.2 join association file
    
    Don't require the file for rails > 7.1 but < 7.2.

@satou-haruka-37
Copy link
Contributor Author

この状態で再度テストを走らせたところ、Pending以外全て通った。

satouharuka@satouharukanoMacBook-Pro ransack % bundle exec rake spec                                                                         
/Users/satouharuka/.rbenv/versions/3.2.2/bin/ruby -I/Users/satouharuka/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-core-3.13.0/lib:/Users/satouharuka/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-support-3.13.1/lib /Users/satouharuka/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-core-3.13.0/exe/rspec spec/ransack/adapters/active_record/base_spec.rb spec/ransack/adapters/active_record/context_spec.rb spec/ransack/configuration_spec.rb spec/ransack/helpers/form_builder_spec.rb spec/ransack/helpers/form_helper_spec.rb spec/ransack/nodes/condition_spec.rb spec/ransack/nodes/grouping_spec.rb spec/ransack/nodes/value_spec.rb spec/ransack/predicate_spec.rb spec/ransack/search_spec.rb spec/ransack/translate_spec.rb
====================================================================================
Running Ransack specs with SQLite, Active Record 7.1.3.4, Arel 10.0.0 and Ruby 3.2.2
====================================================================================
........................................................................................................................................................................................................................................................................................................................................................................*........................................

Pending: (Failures listed here are expected and do not affect your suite's status)

  1) Ransack::Search#build preserves (inverts) default scope and conditions for negative subqueries
     # spec should pass, but I do not know how/where to fix lib code
     Failure/Error: expect(s.result.to_sql).to include 'default_scope'
       expected "SELECT \"people\".* FROM \"people\" WHERE \"people\".\"id\" NOT IN (SELECT \"articles\".\"person_id\...d\" = \"people\".\"id\" AND NOT (\"articles\".\"title\" != 'Test')) ORDER BY \"people\".\"id\" DESC" to include "default_scope"
     # ./spec/ransack/search_spec.rb:183:in `block (3 levels) in <module:Ransack>'

Finished in 0.74304 seconds (files took 1.1 seconds to load)
401 examples, 0 failures, 1 pending

Coverage report generated for RSpec to /Users/satouharuka/workspace/ransack/coverage. 1608 / 1670 LOC (96.29%) covered.

@satou-haruka-37
Copy link
Contributor Author

このことをプルリクエストにコメントする。

@satou-haruka-37
Copy link
Contributor Author

bundle exec rake spec

のコマンドを実行すると、私も他の方と同様のエラーが発生し、テストが通りませんでした。

NoMethodError: undefined method 'with_connection' for class Ignore error.

bundle exec rake spec

command, I get the same error as the others and the test does not pass.

NoMethodError: undefined method 'with_connection' for class Ignore error.
```

@satou-haruka-37
Copy link
Contributor Author

このプルリクエストをpatchを用いてローカルに持ってきて、
テストを実行すると、無事にテストが通りました。

satouharuka@satouharukanoMacBook-Pro ransack % pbpaste > patch
satouharuka@satouharukanoMacBook-Pro ransack % git am patch
Applying: Fix require of rails 7.2 join association file
Applying: Use 7.1.3.4 for rails 7.1 version in tests
satouharuka@satouharukanoMacBook-Pro ransack % bundle exec rake spec                                                                         
/Users/satouharuka/.rbenv/versions/3.2.2/bin/ruby -I/Users/satouharuka/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-core-3.13.0/lib:/Users/satouharuka/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-support-3.13.1/lib /Users/satouharuka/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-core-3.13.0/exe/rspec spec/ransack/adapters/active_record/base_spec.rb spec/ransack/adapters/active_record/context_spec.rb spec/ransack/configuration_spec.rb spec/ransack/helpers/form_builder_spec.rb spec/ransack/helpers/form_helper_spec.rb spec/ransack/nodes/condition_spec.rb spec/ransack/nodes/grouping_spec.rb spec/ransack/nodes/value_spec.rb spec/ransack/predicate_spec.rb spec/ransack/search_spec.rb spec/ransack/translate_spec.rb
====================================================================================
Running Ransack specs with SQLite, Active Record 7.1.3.4, Arel 10.0.0 and Ruby 3.2.2
====================================================================================
........................................................................................................................................................................................................................................................................................................................................................................*........................................

Pending: (Failures listed here are expected and do not affect your suite's status)

  1) Ransack::Search#build preserves (inverts) default scope and conditions for negative subqueries
     # spec should pass, but I do not know how/where to fix lib code
     Failure/Error: expect(s.result.to_sql).to include 'default_scope'
       expected "SELECT \"people\".* FROM \"people\" WHERE \"people\".\"id\" NOT IN (SELECT \"articles\".\"person_id\...d\" = \"people\".\"id\" AND NOT (\"articles\".\"title\" != 'Test')) ORDER BY \"people\".\"id\" DESC" to include "default_scope"
     # ./spec/ransack/search_spec.rb:183:in `block (3 levels) in <module:Ransack>'

Finished in 0.74304 seconds (files took 1.1 seconds to load)
401 examples, 0 failures, 1 pending

Coverage report generated for RSpec to /Users/satouharuka/workspace/ransack/coverage. 1608 / 1670 LOC (96.29%) covered.

Bring this pull request locally using patch,
The test passed successfully.

(ターミナルのログを貼付)

@satou-haruka-37
Copy link
Contributor Author

実際に送ろうと思うコメント

@satou-haruka-37
Copy link
Contributor Author

satou-haruka-37 commented Jul 28, 2024

I saw the same thing in the main branch.

NoMethodError: undefined method 'with_connection' for class Ignore error.

I applied this pull request locally and got it to work, and it passed the test.

% curl -O -L 'https://github.com/activerecord-hackery/ransack/pull/1506.patch'
% git am 1506.patch
Below is the execution log.
satouharuka@satouharukanoMacBook-Pro ransack % curl -O -L 'https://github.com/activerecord-hackery/ransack/pull/1506.patch'
satouharuka@satouharukanoMacBook-Pro ransack % git am 1506.patch           
Applying: Fix require of rails 7.2 join association file
Applying: Use 7.1.3.4 for rails 7.1 version in tests
satouharuka@satouharukanoMacBook-Pro ransack % bundle exec rake spec                                                       
/Users/satouharuka/.rbenv/versions/3.2.2/bin/ruby -I/Users/satouharuka/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-core-3.13.0/lib:/Users/satouharuka/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-support-3.13.1/lib /Users/satouharuka/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-core-3.13.0/exe/rspec spec/ransack/adapters/active_record/base_spec.rb spec/ransack/adapters/active_record/context_spec.rb spec/ransack/configuration_spec.rb spec/ransack/helpers/form_builder_spec.rb spec/ransack/helpers/form_helper_spec.rb spec/ransack/nodes/condition_spec.rb spec/ransack/nodes/grouping_spec.rb spec/ransack/nodes/value_spec.rb spec/ransack/predicate_spec.rb spec/ransack/search_spec.rb spec/ransack/translate_spec.rb
====================================================================================
Running Ransack specs with SQLite, Active Record 7.1.3.4, Arel 10.0.0 and Ruby 3.2.2
====================================================================================
........................................................................................................................................................................................................................................................................................................................................................................*........................................

Pending: (Failures listed here are expected and do not affect your suite's status)

  1) Ransack::Search#build preserves (inverts) default scope and conditions for negative subqueries
     # spec should pass, but I do not know how/where to fix lib code
     Failure/Error: expect(s.result.to_sql).to include 'default_scope'
       expected "SELECT \"people\".* FROM \"people\" WHERE \"people\".\"id\" NOT IN (SELECT \"articles\".\"person_id\...d\" = \"people\".\"id\" AND NOT (\"articles\".\"title\" != 'Test')) ORDER BY \"people\".\"id\" DESC" to include "default_scope"
     # ./spec/ransack/search_spec.rb:183:in `block (3 levels) in <module:Ransack>'

Finished in 0.75446 seconds (files took 1.22 seconds to load)
401 examples, 0 failures, 1 pending

Coverage report generated for RSpec to /Users/satouharuka/workspace/ransack/coverage. 1608 / 1670 LOC (96.29%) covered.

@satou-haruka-37
Copy link
Contributor Author

satou-haruka-37 commented Jul 28, 2024

いつ誰がやっても実行しやすい方のコマンド(他の人が再現しやすい)
さっきのコピーして書き込みのやり方は、他の人がやったら、全然違うものコピーしてるとうまくいかないため、
コメントとして記載するのであればこのコマンドを他の人にシェアする方が良い

curl -O -L 'https://github.com/activerecord-hackery/ransack/pull/1506.patch'
git am 1506.patch

@satou-haruka-37
Copy link
Contributor Author

コメントした。
これで早くマージして!と言う圧をかけられるらしい

@satou-haruka-37
Copy link
Contributor Author

今回は本来コントリビュートするべき手前の段階でエラーになってしまった。本来であればこの段階を通過した後どのようなコントリビュートをする想定だったのか?
と質問

→これは想定通り。これが今回の回でやりたかった意図通りのこと
大体コントリビュートの手順中にエラーが起こる。

@zonuexe zonuexe changed the title OSS Gate Workshop: ゆるい勉強会旭川-2024-07-28 satou-haruka-37: ransack: Work log OSS Gate Workshop: ゆるい勉強会旭川-2024-07-28: satou-haruka-37: ransack: Work log Jul 28, 2024
@zonuexe zonuexe changed the title OSS Gate Workshop: ゆるい勉強会旭川-2024-07-28: satou-haruka-37: ransack: Work log OSS Gate Workshop: ゆるい勉強会旭川: 2024-07-28: satou-haruka-37: ransack: Work log Jul 28, 2024
Copy link

おつかれさまでした!

ワークショップの終了にともないissueを閉じますが、このまま作業メモとして使っても構いません 👌

ワークショップの感想を集めています!

ブログなどに書かれた際は、このページへリンクの追加をお願いします 🙏

またの参加をお待ちしています!

@satou-haruka-37
Copy link
Contributor Author

コメントしたプルリクエストがクローズされた。

activerecord-hackery/ransack#1506 (comment)

おそらく以下のプルリクエストで修正されている。
activerecord-hackery/ransack#1503
様々な方が同じ問題についてプルリクエストを立てていたのではないかと考える。

@satou-haruka-37
Copy link
Contributor Author

別件で立てたこちらのプルリクエストはまだ反応なし。
activerecord-hackery/ransack#1511

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
work log ワークショップ作業メモ
Projects
None yet
Development

No branches or pull requests

1 participant