activerecord-like 2.1 → 2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/Appraisals +4 -6
- data/README.md +1 -1
- data/gemfiles/rails_5_0.gemfile +1 -1
- data/gemfiles/rails_5_1.gemfile +1 -1
- data/gemfiles/rails_5_2.gemfile +7 -0
- data/lib/active_record/like.rb +5 -1
- data/lib/active_record/like/version.rb +1 -1
- data/test/unit/like_test.rb +11 -4
- data/test/unit/not_like_test.rb +11 -4
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a5c0c2ab913d52c04984736a54d8a2cd2832ea9
|
4
|
+
data.tar.gz: 665673067501add2fff21343a6b73d2449ca2604
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e4cca0a25e3480c37a079bbb41c80e88b6bf06dc73f59fa56640fe6d1dec4ce1c147e6b79cca32db42a3f59f313ec4cac38297acf5d2a371809579bf035be369
|
7
|
+
data.tar.gz: 208c3fba7b26f6f59b5ea7b7cc82b409c0fc3baeb8aca2da51e017992f027e9087c5fea6dbae303c06ab8d81af7583ccd4db0f8cdd6b7bacd34b67925dc4738d
|
data/.travis.yml
CHANGED
data/Appraisals
CHANGED
data/README.md
CHANGED
@@ -9,7 +9,7 @@
|
|
9
9
|
|
10
10
|
An Active Record Plugin that allows chaining a more DSL-style 'like' or 'not-like' query to an ActiveRecord::Base#where. Requires Rails 5 or higher.
|
11
11
|
|
12
|
-
This plugin has been salvaged from the stellar work done by @amatsuda and @claudiob, and updated to ActiveRecord 5 by @PikachuEXE. Most of the code was previously in Active Record master, but was subsequently removed due to, amongst other, scope creep.
|
12
|
+
This plugin has been salvaged from the stellar work done by @amatsuda and @claudiob, and updated to ActiveRecord 5 by @PikachuEXE and 5.2 by @robotdana. Most of the code was previously in Active Record master, but was subsequently removed due to, amongst other, scope creep (see discussion [here](https://github.com/rails/rails/commit/8d02afeaee8993bd0fde69687fdd9bf30921e805)).
|
13
13
|
Array parameter handling was added by @rzane - thanks!
|
14
14
|
|
15
15
|
## Installation
|
data/gemfiles/rails_5_0.gemfile
CHANGED
data/gemfiles/rails_5_1.gemfile
CHANGED
data/lib/active_record/like.rb
CHANGED
@@ -47,7 +47,11 @@ module ActiveRecord
|
|
47
47
|
# Will lose the binding values since 5.1
|
48
48
|
# due to this PR
|
49
49
|
# https://github.com/rails/rails/pull/26073
|
50
|
-
new_where_clause =
|
50
|
+
new_where_clause = if equal_where_clause.respond_to?(:binds)
|
51
|
+
Relation::WhereClause.new([new_predicate], equal_where_clause.binds)
|
52
|
+
else
|
53
|
+
Relation::WhereClause.new([new_predicate])
|
54
|
+
end
|
51
55
|
|
52
56
|
s.where_clause += new_where_clause
|
53
57
|
end
|
data/test/unit/like_test.rb
CHANGED
@@ -13,9 +13,8 @@ describe ActiveRecord::QueryMethods::WhereChain do
|
|
13
13
|
@attribute = "title"
|
14
14
|
@value = '%value%'
|
15
15
|
|
16
|
-
relation = Post.where.like(@attribute => @value)
|
17
|
-
@first_predicate
|
18
|
-
@first_bind = relation.where_clause.send(:binds).first
|
16
|
+
@relation = Post.where.like(@attribute => @value)
|
17
|
+
@first_predicate = @relation.where_clause.send(:predicates).first
|
19
18
|
end
|
20
19
|
|
21
20
|
it "has the attribute as the left operand" do
|
@@ -23,7 +22,15 @@ describe ActiveRecord::QueryMethods::WhereChain do
|
|
23
22
|
end
|
24
23
|
|
25
24
|
it "has the value as the right operand" do
|
26
|
-
|
25
|
+
# Rails 5.0 & 5.1
|
26
|
+
first_bind = if @relation.where_clause.respond_to?(:binds)
|
27
|
+
@relation.where_clause.send(:binds).first
|
28
|
+
else
|
29
|
+
# Rails 5.2
|
30
|
+
@first_predicate.right.value
|
31
|
+
end
|
32
|
+
|
33
|
+
first_bind.value.must_equal @value
|
27
34
|
end
|
28
35
|
end
|
29
36
|
end
|
data/test/unit/not_like_test.rb
CHANGED
@@ -13,9 +13,8 @@ describe ActiveRecord::QueryMethods::WhereChain do
|
|
13
13
|
@attribute = "title"
|
14
14
|
@value = '%value%'
|
15
15
|
|
16
|
-
relation = Post.where.like(@attribute => @value)
|
17
|
-
@first_predicate
|
18
|
-
@first_bind = relation.where_clause.send(:binds).first
|
16
|
+
@relation = Post.where.like(@attribute => @value)
|
17
|
+
@first_predicate = @relation.where_clause.send(:predicates).first
|
19
18
|
end
|
20
19
|
|
21
20
|
it "has the attribute as the left operand" do
|
@@ -23,7 +22,15 @@ describe ActiveRecord::QueryMethods::WhereChain do
|
|
23
22
|
end
|
24
23
|
|
25
24
|
it "has the value as the right operand" do
|
26
|
-
|
25
|
+
# Rails 5.0 & 5.1
|
26
|
+
first_bind = if @relation.where_clause.respond_to?(:binds)
|
27
|
+
@relation.where_clause.send(:binds).first
|
28
|
+
else
|
29
|
+
# Rails 5.2
|
30
|
+
@first_predicate.right.value
|
31
|
+
end
|
32
|
+
|
33
|
+
first_bind.value.must_equal @value
|
27
34
|
end
|
28
35
|
end
|
29
36
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-like
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '2.
|
4
|
+
version: '2.2'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- René van den Berg
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-11-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -126,6 +126,7 @@ files:
|
|
126
126
|
- activerecord-like.gemspec
|
127
127
|
- gemfiles/rails_5_0.gemfile
|
128
128
|
- gemfiles/rails_5_1.gemfile
|
129
|
+
- gemfiles/rails_5_2.gemfile
|
129
130
|
- lib/active_record/like.rb
|
130
131
|
- lib/active_record/like/version.rb
|
131
132
|
- lib/activerecord-like.rb
|