Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
b8341f6
chore: Rails7.1に対応させた。
tokai3594 Jun 8, 2025
9a416b6
chore: concurrent-ruby gem1.3.5ではLogger関連の処理に変更が入ったことでエラーになったので、1.3.4にした
tokai3594 Jun 11, 2025
b63e24f
test: データベースの内容をクリアする方法がtransactionの場合、SQLite3Adapterにはlockメソッドが存在しない…
tokai3594 Jun 11, 2025
db6c631
test: minitest gem5.19.0より「MiniTest」という名前空間は削除されたため、「Minitest」に変更した。
tokai3594 Jun 11, 2025
4981b13
ci:chore: Rails7.1のテスト追加、Ruby3.2,3.3,3.4のテストパターンを追加した
tokai3594 Jun 11, 2025
ed708df
chore: Ruby3.4からbundled gemではなくなったgemを明示的に指定した。
tokai3594 Jun 11, 2025
28254d1
test:chore: Ruby3.2, Rails6系でscopeでキーワード引数はエラーになるという情報があり、実際にテストでエラーに…
tokai3594 Jun 11, 2025
9d3fea2
chore: 依存関係に対してwarningが出るので定義した
tokai3594 Jun 11, 2025
40decc6
test: データベースクリアを「rails_5.0.gemfile」では「truncation」にし、それ以外は「transaction…
tokai3594 Jun 11, 2025
7e1f437
chore: Rails5.1ではtransactionでデータベースクリアさせるためにsqlite3を1.4系に固定
tokai3594 Jun 11, 2025
91cb72e
test: テストでのメソッドの引数をもとに戻した
tokai3594 Jun 12, 2025
2f96431
chore: define_singleton_methodで対象クラスにクラスメソッドとして定義した。
tokai3594 Jun 12, 2025
620052b
chore: database_cleanerとsqlite3のバージョンが合うように修正した
patorash Jun 12, 2025
314096c
chore: Rubyのバージョンによってsqlite3のバージョンを切り替えるよう修正
patorash Jun 12, 2025
2ce3fa0
refactor: class_evalしているので、そのままdefine_singleton_methodが使える。scopeを使わずに…
patorash Jun 12, 2025
f8c90b7
Merge pull request #2 from tokai3594/support_rails7.1-for-resolving-d…
patorash Jun 13, 2025
2fa631b
chore: バージョンを1.4.4にした。
tokai3594 Jun 19, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ruby: ['2.6', '2.7', '3.0', '3.1']
gemfile: ['rails_5.0', 'rails_5.1', 'rails_5.2', 'rails_6.0', 'rails_6.1', 'rails_7.0']
ruby: ['2.6', '2.7', '3.0', '3.1', '3.2', '3.3', '3.4']
gemfile: ['rails_5.0', 'rails_5.1', 'rails_5.2', 'rails_6.0', 'rails_6.1', 'rails_7.0', 'rails_7.1']
exclude:
- ruby: '2.6'
gemfile: 'rails_7.0'
- ruby: '2.6'
gemfile: 'rails_7.1'
- ruby: '3.0'
gemfile: 'rails_5.0'
- ruby: '3.0'
Expand All @@ -28,6 +30,24 @@ jobs:
gemfile: 'rails_5.1'
- ruby: '3.1'
gemfile: 'rails_5.2'
- ruby: '3.2'
gemfile: 'rails_5.0'
- ruby: '3.2'
gemfile: 'rails_5.1'
- ruby: '3.2'
gemfile: 'rails_5.2'
- ruby: '3.3'
gemfile: 'rails_5.0'
- ruby: '3.3'
gemfile: 'rails_5.1'
- ruby: '3.3'
gemfile: 'rails_5.2'
- ruby: '3.4'
gemfile: 'rails_5.0'
- ruby: '3.4'
gemfile: 'rails_5.1'
- ruby: '3.4'
gemfile: 'rails_5.2'
env:
BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile

Expand Down
1 change: 1 addition & 0 deletions gemfiles/rails_5.0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ source 'https://rubygems.org'

gem 'activerecord', '~> 5.0.0'
gem 'sqlite3', '~> 1.3.0'
gem 'database_cleaner', '~> 1.99'

gemspec path: '../'
2 changes: 1 addition & 1 deletion gemfiles/rails_5.1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
source 'https://rubygems.org'

gem 'activerecord', '~> 5.1.0'
gem 'sqlite3', '~> 1.3.0'
gem 'sqlite3', '~> 1.4'

gemspec path: '../'
13 changes: 13 additions & 0 deletions gemfiles/rails_7.1.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gem 'activerecord', '~> 7.1.3'

if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.0.0')
gem 'sqlite3', '~> 2.0'
else
gem 'sqlite3', '~> 1.4'
end

gemspec path: '../'
10 changes: 7 additions & 3 deletions imyou.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@ Gem::Specification.new do |spec|
spec.require_paths = ['lib']
spec.required_ruby_version = '>= 2.6'

spec.add_dependency 'activerecord', '< 7.1.0', '>= 5.0.0'
spec.add_development_dependency 'database_cleaner', '~> 2.0'
spec.add_dependency 'activerecord', '< 7.2.0', '>= 5.0.0'
spec.add_development_dependency 'database_cleaner', '< 3.0', '>= 1.99.0'
spec.add_development_dependency 'rake', '~> 13.0'
spec.add_development_dependency 'rubocop', '~> 1.24'
spec.add_development_dependency 'rubocop-minitest', '~> 0.17'
spec.add_development_dependency 'rubocop-performance', '~> 1.13'
spec.add_development_dependency 'rubocop-rake', '~> 0.6'
spec.add_development_dependency 'sqlite3', '~> 1.3'
spec.add_development_dependency 'sqlite3', '< 3.0', '>= 1.3'
spec.add_development_dependency 'concurrent-ruby', '1.3.4'
spec.add_development_dependency 'mutex_m', '~> 0.1'
spec.add_development_dependency 'bigdecimal', '~> 3.0'
spec.add_development_dependency 'base64', '~> 0.1'
spec.metadata['rubygems_mfa_required'] = 'true'
end
12 changes: 8 additions & 4 deletions lib/imyou/models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ def has_imyou(name_column = nil)

scope :with_nicknames, -> { preload(:imyou_nicknames) }

scope :match_by_nickname, lambda { |nickname, with_name_column: true|
# 本来はscopeで定義するべきだが、Ruby 3.2以降とActiveRecord 6.1系ではエラーになるため、
# 苦肉の策で特異メソッドとして定義する。
# Rails 6.1のサポートを終了したら、scopeに戻すこと。
# @see https://qiita.com/usk0513/items/c2968733415c806f56fc
define_singleton_method(:match_by_nickname) do |nickname, with_name_column: true|
if Gem::Version.new(ActiveRecord.version) >= Gem::Version.new(5)
records = left_outer_joins(:imyou_nicknames).where(Imyou::Nickname.arel_table[:name].eq(nickname))
unless name_column.nil? || with_name_column == false
Expand Down Expand Up @@ -47,9 +51,9 @@ def has_imyou(name_column = nil)
end
end
records
}
end

scope :partial_match_by_nickname, lambda { |nickname, with_name_column: true|
define_singleton_method(:partial_match_by_nickname) do |nickname, with_name_column: true|
if Gem::Version.new(ActiveRecord.version) >= Gem::Version.new(5)
records = left_outer_joins(:imyou_nicknames).
where(Imyou::Nickname.arel_table[:name].
Expand Down Expand Up @@ -82,7 +86,7 @@ def has_imyou(name_column = nil)
end
end
records
}
end

alias_method :save_with_nicknames, :save
alias_method :save_with_nicknames!, :save!
Expand Down
2 changes: 1 addition & 1 deletion lib/imyou/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Imyou
VERSION = '1.4.3'
VERSION = '1.4.4'
end
2 changes: 1 addition & 1 deletion test/nickname_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@

describe 'If with_name_column = false' do
it 'should not search by users.name' do
expect(User.match_by_nickname('user_name', with_name_column: false)).wont_be :exists?
expect(User.match_by_nickname("user_name", with_name_column: false)).wont_be :exists?
end
end
end
Expand Down
9 changes: 6 additions & 3 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
require 'minitest/autorun'
require 'active_record'

require 'database_cleaner/active_record'
# database_cleaner 1~2系のどちらでも動くようにするため、パスを修正
require 'database_cleaner'
require 'imyou'

Dir["#{Dir.pwd}/test/internal/app/models/*.rb"].sort.each { |f| require f }
Expand Down Expand Up @@ -49,19 +50,21 @@ class Spec
end

# @see https://stackoverflow.com/questions/20329387/how-to-assert-the-contents-of-an-array-indifferent-of-the-ordering
module MiniTest
module Minitest
module Assertions
def assert_matched_arrays(exp, act)
exp_ary = exp.to_ary

assert_kind_of Array, exp_ary
act_ary = act.to_ary

assert_kind_of Array, act_ary
assert_equal exp_ary.sort, act_ary.sort
end
end
end

module MiniTest
module Minitest
module Expectations
infect_an_assertion :assert_matched_arrays, :must_match_array
end
Expand Down