|
13 | 13 | BasicFilterableTestModel::FILTER_SCOPE_MAPPINGS = { # rubocop:disable RSpec/LeakyConstantDeclaration
|
14 | 14 | "name": :filter_by_name,
|
15 | 15 | "favorite_number": :filter_by_favorite_number,
|
16 |
| - "search": :search_by_name_favorite_number |
| 16 | + "search": :search_by_name |
17 | 17 | }.freeze
|
18 | 18 |
|
19 | 19 | BasicFilterableTestModel::SORT_SCOPE_MAPPINGS = { # rubocop:disable RSpec/LeakyConstantDeclaration
|
|
26 | 26 |
|
27 | 27 | scope :sort_by_name, -> { order :name }
|
28 | 28 | scope :sort_by_favorite_number, -> { order :favorite_number }
|
29 |
| - |
30 |
| - pg_search_scope :search_by_name_favorite_number, |
31 |
| - against: { name: "A", favorite_number: "B" }, |
32 |
| - using: { |
33 |
| - tsearch: { prefix: true, dictionary: "english" } |
34 |
| - }, |
35 |
| - ignoring: :accents |
| 29 | + scope :search_by_name, ->(search) { where("name like ?", "%#{search}%")} |
36 | 30 | end
|
37 | 31 | end
|
38 | 32 |
|
|
193 | 187 | expect(filtered.items.map(&:name)).to eq(expected_items)
|
194 | 188 | end
|
195 | 189 |
|
196 |
| - it "can search ignoring diacritics" do |
197 |
| - all_items = BasicFilterableTestModel.where(nil) |
198 |
| - expected_items = [all_items.first.name] |
199 |
| - |
200 |
| - filtered = BasicFilterableTestModel.filter(params: ActionController::Parameters.new({ filter: { search: target_user.name.split(//).join("").tr("aeiouylszcn", "àèîôûÿłšżçñ") } })) |
201 |
| - |
202 |
| - expect(filtered.items.map(&:name)).to eq(expected_items) |
203 |
| - end |
204 |
| - |
205 | 190 | it "can search with other params" do
|
206 | 191 | expected_items = []
|
207 | 192 |
|
@@ -532,15 +517,23 @@ def generate_join_sql(model)
|
532 | 517 | polymorphic_association_id = "#{polymorphic_association}_id"
|
533 | 518 | polymorphic_association_type = "#{polymorphic_association}_type"
|
534 | 519 |
|
535 |
| - "LEFT OUTER JOIN \"#{first_model_table}\" ON \"#{first_model_table}\".id = \"#{base_model_table}\".\"#{polymorphic_association_id}\" AND \"#{base_model_table}\".\"#{polymorphic_association_type}\" = '#{first_model_name}'" |
| 520 | + if ActiveRecord::Base.connection_db_config.adapter == "mysql2" |
| 521 | + "LEFT OUTER JOIN `#{first_model_table}` ON `#{first_model_table}`.id = `#{base_model_table}`.`#{polymorphic_association_id}` AND `#{base_model_table}`.`#{polymorphic_association_type}` = '#{first_model_name}'" |
| 522 | + else |
| 523 | + "LEFT OUTER JOIN \"#{first_model_table}\" ON \"#{first_model_table}\".id = \"#{base_model_table}\".\"#{polymorphic_association_id}\" AND \"#{base_model_table}\".\"#{polymorphic_association_type}\" = '#{first_model_name}'" |
| 524 | + end |
536 | 525 | end
|
537 | 526 | end
|
538 | 527 |
|
539 | 528 | describe ".coalesce" do
|
540 | 529 | it "creates a valid function" do
|
541 | 530 | actual_output = described_class.coalesce([DummyModel], "some_column")
|
542 | 531 |
|
543 |
| - expect(actual_output).to eq("coalesce(\"dummy_models\".\"some_column\")") |
| 532 | + if ActiveRecord::Base.connection_db_config.adapter == "mysql2" |
| 533 | + expect(actual_output).to eq("coalesce(`dummy_models`.`some_column`)") |
| 534 | + else |
| 535 | + expect(actual_output).to eq("coalesce(\"dummy_models\".\"some_column\")") |
| 536 | + end |
544 | 537 | end
|
545 | 538 | end
|
546 | 539 | end
|
0 commit comments