1
0
Fork 0
mirror of https://github.com/activerecord-hackery/ransack.git synced 2022-11-09 13:47:45 -05:00

Merge remote-tracking branch 'upstream/master' into fix_1115

This commit is contained in:
lichao 2020-11-25 14:21:10 +00:00
commit 05750ce539
9 changed files with 46 additions and 38 deletions

View file

@ -1,3 +1,5 @@
branches: master
language: ruby
rvm:
@ -7,17 +9,9 @@ services:
- mysql
env:
- RAILS=v6.0.2 DB=sqlite3
- RAILS=v6.0.2 DB=mysql
- RAILS=v6.0.2 DB=postgres
- RAILS=v6.0.1 DB=sqlite3
- RAILS=v6.0.1 DB=mysql
- RAILS=v6.0.1 DB=postgres
- RAILS=v6.0.0 DB=sqlite3
- RAILS=v6.0.0 DB=mysql
- RAILS=v6.0.0 DB=postgres
- RAILS=v6.0.3 DB=sqlite3
- RAILS=v6.0.3 DB=mysql
- RAILS=v6.0.3 DB=postgres
- RAILS=6-0-stable DB=sqlite3
- RAILS=6-0-stable DB=mysql
@ -27,9 +21,9 @@ env:
- RAILS=5-2-stable DB=mysql
- RAILS=5-2-stable DB=postgres
- RAILS=v5.2.3 DB=sqlite3
- RAILS=v5.2.3 DB=mysql
- RAILS=v5.2.3 DB=postgres
- RAILS=v5.2.4 DB=sqlite3
- RAILS=v5.2.4 DB=mysql
- RAILS=v5.2.4 DB=postgres
before_script:
- if [ "$DB" = "mysql" ];

View file

@ -2,6 +2,9 @@
* Fix for ActiveRecord 5.2.4 (note security fix in 5.2.4.2 for ActiveView's escape_javascript CVE-2020-5267 for all earlier versions)
* Drop support for ActiveRecord older than 5.2.4.
PR [1166](https://github.com/activerecord-hackery/ransack/pull/1166)
## 2.3.2 - 2020-01-11
* Breakfix to bump Polyamorous

View file

@ -14,7 +14,7 @@ rails_version = case rails
rails
end
gem 'faker', '~> 0.9.5'
gem 'faker', '~> 1.0'
gem 'sqlite3', ::Gem::Version.new(rails_version) >= ::Gem::Version.new('6-0-stable') ? '~> 1.4.1' : '~> 1.3.3'
gem 'pg', '~> 1.0'
gem 'pry', '~> 0.12.2'

View file

@ -1,5 +1,9 @@
# ![Ransack](./logo/ransack-h.png "Ransack")
**MAINTAINER WANTED**
Please see the [Maintainer wanted issue](https://github.com/activerecord-hackery/ransack/issues/1159) if you are interested.
[![Build Status](https://travis-ci.org/activerecord-hackery/ransack.svg)](https://travis-ci.org/activerecord-hackery/ransack)
[![Gem Version](https://badge.fury.io/rb/ransack.svg)](http://badge.fury.io/rb/ransack)
[![Code Climate](https://codeclimate.com/github/activerecord-hackery/ransack/badges/gpa.svg)](https://codeclimate.com/github/activerecord-hackery/ransack)
@ -460,7 +464,7 @@ List of all possible predicates
| `*_not_cont` | Does not contain |
| `*_not_cont_any` | Does not contain any of | |
| `*_not_cont_all` | Does not contain all of | |
| `*_i_cont` | Contains value with case insensitive | uses `LIKE` |
| `*_i_cont` | Contains value with case insensitive | uses `ILIKE` |
| `*_i_cont_any` | Contains any of values with case insensitive | |
| `*_i_cont_all` | Contains all of values with case insensitive | |
| `*_not_i_cont` | Does not contain with case insensitive |

View file

@ -1,11 +1,10 @@
module Polyamorous
module ReflectionExtensions
def build_join_constraint(table, foreign_table)
if polymorphic?
super(table, foreign_table)
.and(foreign_table[foreign_type].eq(klass.name))
def join_scope(table, foreign_table, foreign_klass)
if respond_to?(:polymorphic?) && polymorphic?
super.where!(foreign_table[foreign_type].eq(klass.name))
else
super(table, foreign_table)
super
end
end
end

View file

@ -47,12 +47,19 @@ module Ransack
end
def casted_array?(predicate)
predicate.respond_to?(:val) && predicate.val.is_a?(Array)
(predicate.respond_to?(:value) && predicate.value.is_a?(Array)) || # Rails 6.1
(predicate.respond_to?(:val) && predicate.val.is_a?(Array)) # Rails 5.2, 6.0
end
def format_values_for(predicate)
predicate.val.map do |value|
value.is_a?(String) ? Arel::Nodes.build_quoted(value) : value
value = if predicate.respond_to?(:value)
predicate.value # Rails 6.1
else
predicate.val # Rails 5.2, 6.0
end
value.map do |val|
val.is_a?(String) ? Arel::Nodes.build_quoted(val) : val
end
end

View file

@ -14,8 +14,8 @@ Gem::Specification.new do |s|
s.required_ruby_version = '>= 2.3'
s.license = 'MIT'
s.add_dependency 'activerecord', '>= 5.2.1'
s.add_dependency 'activesupport', '>= 5.2.1'
s.add_dependency 'activerecord', '>= 5.2.4'
s.add_dependency 'activesupport', '>= 5.2.4'
s.add_dependency 'i18n'
s.files = `git ls-files`.split("\n")

View file

@ -265,10 +265,12 @@ module Ransack
# end
it 'creates ransack attributes' do
person = Person.create!(name: 'Aric Smith')
s = Person.ransack(reversed_name_eq: 'htimS cirA')
expect(s.result.size).to eq(1)
expect(s.result.first).to eq Person.where(name: 'Aric Smith').first
expect(s.result.first).to eq person
end
it 'can be accessed through associations' do

View file

@ -263,6 +263,9 @@ module Ransack
let(:children_people_name_field) {
"#{quote_table_name("children_people")}.#{quote_column_name("name")}"
}
let(:notable_type_field) {
"#{quote_table_name("notes")}.#{quote_column_name("notable_type")}"
}
it 'evaluates conditions contextually' do
s = Search.new(Person, children_name_eq: 'Ernie')
expect(s.result).to be_an ActiveRecord::Relation
@ -271,6 +274,8 @@ module Ransack
end
it 'use appropriate table alias' do
skip "Rails 6 regressed here, but it's fixed in 6-0-stable since https://github.com/rails/rails/commit/f9ba52477ca288e7effa5f6794ae3df3f4e982bc" if ENV["RAILS"] == "v6.0.3"
s = Search.new(Person, {
name_eq: "person_name_query",
articles_title_eq: "person_article_title_query",
@ -280,17 +285,10 @@ module Ransack
real_query = remove_quotes_and_backticks(s.to_sql)
if ::Gem::Version.new(::ActiveRecord::VERSION::STRING) > ::Gem::Version.new(Constants::RAILS_6_0)
expect(real_query)
.to match(%r{LEFT OUTER JOIN articles ON (\('default_scope' = 'default_scope'\) AND )?articles.person_id = parents_people.id})
expect(real_query)
.to match(%r{LEFT OUTER JOIN articles articles_people ON (\('default_scope' = 'default_scope'\) AND )?articles_people.person_id = people.id})
else
expect(real_query)
.to match(%r{LEFT OUTER JOIN articles ON (\('default_scope' = 'default_scope'\) AND )?articles.person_id = people.id})
expect(real_query)
.to match(%r{LEFT OUTER JOIN articles articles_people ON (\('default_scope' = 'default_scope'\) AND )?articles_people.person_id = parents_people.id})
end
expect(real_query)
.to match(%r{LEFT OUTER JOIN articles ON (\('default_scope' = 'default_scope'\) AND )?articles.person_id = people.id})
expect(real_query)
.to match(%r{LEFT OUTER JOIN articles articles_people ON (\('default_scope' = 'default_scope'\) AND )?articles_people.person_id = parents_people.id})
expect(real_query)
.to include "people.name = 'person_name_query'"
@ -334,6 +332,7 @@ module Ransack
s = Search.new(Note, notable_of_Person_type_name_eq: 'Ernie').result
expect(s).to be_an ActiveRecord::Relation
expect(s.to_sql).to match /#{people_name_field} = 'Ernie'/
expect(s.to_sql).to match /#{notable_type_field} = 'Person'/
end
it 'evaluates nested conditions' do