Skip to content

Commit

Permalink
Extract the ransack patch to a separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
elia committed Dec 20, 2023
1 parent 8f1db9e commit 7d91dc7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
17 changes: 0 additions & 17 deletions core/lib/solidus_core.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,3 @@
# frozen_string_literal: true

require 'spree_core'

class Arel::Table
def table_name
name
end
end


module RansackNodeConditionPatch
private

def casted_array?(predicate)
predicate.is_a?(Arel::Nodes::Casted) && predicate.value.is_a?(Array)
end

Ransack::Nodes::Condition.prepend(self)
end
3 changes: 3 additions & 0 deletions core/lib/spree/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@
require 'monetize'
require 'paperclip'
require 'ransack'
require 'state_machines-activemodel'
require 'state_machines-activerecord'

require_relative './ransack-4-1-patch'

# This is required because ActiveModel::Validations#invalid? conflicts with the
# invalid state of a Payment. In the future this should be removed.
StateMachines::Machine.ignore_method_conflicts = true
Expand Down
16 changes: 16 additions & 0 deletions core/lib/spree/ransack_4_1_patch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

require "ransack/version"

return unless Ransack::VERSION.start_with?("4.1.")

module RansackNodeConditionPatch
private

# Waiting for https://github.com/activerecord-hackery/ransack/pull/1468
def casted_array?(predicate)
predicate.is_a?(Arel::Nodes::Casted) && predicate.value.is_a?(Array)
end

Ransack::Nodes::Condition.prepend(self)
end

0 comments on commit 7d91dc7

Please sign in to comment.