activerecord_any_of 1.3 → 1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3086cee8dc2889c8e3f8874ef32631af08c750c2
4
- data.tar.gz: 5e01aa2499c952e4fc215c24890b215d1749f104
3
+ metadata.gz: 47eee92223e93989b63ad4b3ae077bf438bf70fc
4
+ data.tar.gz: 31b4d5f385ea3d699ad5abca878ef7612649959c
5
5
  SHA512:
6
- metadata.gz: 2288d0dec57e66b4b9b454f6082eca83125d30912044de57aedfc828f8aa20b98137b0d71c7de5b53a81f94a9c2f3ec6b2b6373b7afa1f10be58e1c127013832
7
- data.tar.gz: 59c3984d1052c8cff9b04cf5bd8bd07b19fef3e3082d7379f56383a6531bf63bf94b002c810c24aa56d899948b14f923313f06a2c41fd78697dbd11632a36c8b
6
+ metadata.gz: 1b2d782aa4da21b7823f1ae978f6effcc0d55460dbbdb51bb7fabdd34d21ce9e50023de2c237857dfba6729d9d1d5c2f377d76d5f842f158d8ff5c4ff6a50552
7
+ data.tar.gz: f174291bbc3e50f0a48ac8414988f84d01413f21a3a603b63ebc8270afd9163800d91f87f72351b9972ecc6f433fec5860ebb24deb3f17cfd77d6ff058549d7b
data/README.md CHANGED
@@ -1,41 +1,5 @@
1
1
  # ActiverecordAnyOf
2
2
 
3
- ## A note for < 1.2 users
4
-
5
- There was a lot of confusion about explit/implicit hash parameter notation,
6
- with people expecting this to generate an OR query :
7
-
8
- ```ruby
9
- User.where.any_of(name: 'Doe', active: true)
10
- ```
11
-
12
- This wouldn't work, since there is only one parameter, here : `{name: 'Doe', active: true}`,
13
- so there's a single group of condition that is joined as a AND. To achieve
14
- expected result, this should have been used :
15
-
16
- ```ruby
17
- User.where.any_of({name: 'Doe'}, {active: true})
18
- ```
19
-
20
-
21
- To be true to principle of least surprise, we now automatically expand
22
- parameters consisting of a single Hash as a hash for each key, so first
23
- query will indeed generate :
24
-
25
- ```ruby
26
- User.where.any_of(name: 'Doe', active: true)
27
- # => SELECT * FROM users WHERE name = 'Doe' OR active = '1'
28
- ```
29
-
30
-
31
- Grouping conditions can still be achieved using explicit curly brackets :
32
-
33
- ```ruby
34
- User.where.any_of({first_name: 'John', last_name: 'Doe'}, active: true)
35
- # => SELECT * FROM users WHERE (first_name = 'John' AND last_name = 'Doe') OR active = '1'
36
- ```
37
-
38
-
39
3
  ## Introduction
40
4
 
41
5
  This gem provides `#any_of` and `#none_of` on ActiveRecord.
@@ -161,9 +125,6 @@ conditions are grouped through `OR` and which are grouped through `AND` :
161
125
  * `User.where( "email LIKE '%@example.com" ).where.any_of({ active: true }, { offline: true })`
162
126
  * `fakes = User.where( "email LIKE '%@example.com'" ).where( active: true ); User.where.any_of( fakes, { offline: true })`
163
127
 
164
- ## I want this in active_record
165
-
166
- You can [say it there](https://github.com/rails/rails/pull/10891).
167
128
 
168
129
  ## Running test
169
130
 
data/Rakefile CHANGED
@@ -1,29 +1,2 @@
1
- #!/usr/bin/env rake
2
- $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
3
-
4
- require 'rubygems'
5
- require 'bundler/setup'
6
- require 'activerecord_any_of/version'
7
-
1
+ require "bundler/gem_tasks"
8
2
  task :default => :spec
9
-
10
- task :spec do
11
- puts "\n" + (cmd = "bundle exec rspec spec")
12
- system cmd
13
- end
14
-
15
- begin
16
- require 'rdoc/task'
17
- rescue LoadError
18
- require 'rdoc/rdoc'
19
- require 'rake/rdoctask'
20
- RDoc::Task = Rake::RDocTask
21
- end
22
-
23
- RDoc::Task.new(:rdoc) do |rdoc|
24
- rdoc.rdoc_dir = 'rdoc'
25
- rdoc.title = 'ActiverecordAnyOf'
26
- rdoc.options << '--line-numbers'
27
- rdoc.rdoc_files.include('README.rdoc')
28
- rdoc.rdoc_files.include('lib/**/*.rb')
29
- end
@@ -46,10 +46,10 @@ module ActiverecordAnyOf
46
46
  @uniq_queries_joins_values ||= begin
47
47
  { includes: [], joins: [], references: [] }.tap do |values|
48
48
  queries_joins_values.each do |join_type, statements|
49
- if Symbol === statements.first or String === statements.first
50
- values[ join_type ] = statements.uniq
51
- else
49
+ if statements.first.respond_to?(:to_sql)
52
50
  values[ join_type ] = statements.uniq( &:to_sql )
51
+ else
52
+ values[ join_type ] = statements.uniq
53
53
  end
54
54
  end
55
55
  end
@@ -76,8 +76,8 @@ module ActiverecordAnyOf
76
76
  end
77
77
 
78
78
  def unprepare_query(query)
79
- query.gsub(/((?<!\\)'.*?(?<!\\)'|(?<!\\)".*?(?<!\\)")|(\=\ \$\d)/) do |match|
80
- $2 and $2.gsub(/\=\ \$\d/, "= ?") or match
79
+ query.gsub(/((?<!\\)'.*?(?<!\\)'|(?<!\\)".*?(?<!\\)")|(\=\ \$\d+)/) do |match|
80
+ $2 and $2.gsub(/\=\ \$\d+/, "= ?") or match
81
81
  end
82
82
  end
83
83
  end
@@ -1,3 +1,3 @@
1
1
  module ActiverecordAnyOf
2
- VERSION = "1.3"
2
+ VERSION = "1.4"
3
3
  end
@@ -154,7 +154,7 @@ describe ActiverecordAnyOf do
154
154
  end
155
155
  end
156
156
 
157
- it 'calling #any_of with no argument raise exception' do
157
+ it 'calling #any_of with no argument raises exception' do
158
158
  if ActiveRecord::VERSION::MAJOR >= 4
159
159
  expect { Author.where.any_of }.to raise_exception(ArgumentError)
160
160
  else
@@ -162,7 +162,7 @@ describe ActiverecordAnyOf do
162
162
  end
163
163
  end
164
164
 
165
- it 'calling #none_of with no argument raise exception' do
165
+ it 'calling #none_of with no argument raises exception' do
166
166
  if ActiveRecord::VERSION::MAJOR >= 4
167
167
  expect { Author.where.none_of }.to raise_exception(ArgumentError)
168
168
  else
@@ -170,6 +170,16 @@ describe ActiverecordAnyOf do
170
170
  end
171
171
  end
172
172
 
173
+ it 'calling #any_of after including via a hash does not raise an exception' do
174
+ if ActiveRecord::VERSION::MAJOR >= 4
175
+ expect { User.includes(memberships: :companies).where.any_of(user_id: 1, company_id: 1) }.
176
+ to_not raise_exception
177
+ else
178
+ expect { User.includes(memberships: :companies).any_of(user_id: 1, company_id: 1) }.
179
+ to_not raise_exception
180
+ end
181
+ end
182
+
173
183
  it 'calling #any_of after a wildcard query works' do
174
184
  if ActiveRecord::VERSION::MAJOR >= 4
175
185
  expect(Author.where("name like '%av%'").where.any_of({name: 'David'}, {name: 'Mary'})).to match_array([authors(:david)])
@@ -186,6 +196,33 @@ describe ActiverecordAnyOf do
186
196
  end
187
197
  end
188
198
 
199
+ it "does not fail on hudge number for bind values" do
200
+ conditions = [
201
+ { name: 'Mary' },
202
+ { name: 'David' },
203
+ { name: 'David1' },
204
+ { name: 'David2' },
205
+ { name: 'David3' },
206
+ { name: 'David4' },
207
+ { name: 'David5' },
208
+ { name: 'David6' },
209
+ { name: 'David7' },
210
+ { name: 'David8' },
211
+ { name: 'David9' },
212
+ { name: 'David10' },
213
+ { name: 'David11' },
214
+ { name: 'David12' },
215
+ { name: 'David13' },
216
+ { name: 'David14' }
217
+ ]
218
+
219
+ if ActiveRecord::VERSION::MAJOR >= 4
220
+ expect(Author.where.any_of(*conditions)).to match_array(authors(:david, :mary))
221
+ else
222
+ expect(Author.any_of(*conditions)).to match_array(authors(:david, :mary))
223
+ end
224
+ end
225
+
189
226
  if ActiveRecord::VERSION::MAJOR >= 4
190
227
  it 'calling directly #any_of is deprecated in rails-4' do
191
228
  allow(ActiveSupport::Deprecation).to receive(:warn)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord_any_of
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.3'
4
+ version: '1.4'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Olivier El Mekki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-04 00:00:00.000000000 Z
11
+ date: 2016-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -127,17 +127,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
127
127
  version: '0'
128
128
  requirements: []
129
129
  rubyforge_project:
130
- rubygems_version: 2.2.2
130
+ rubygems_version: 2.5.1
131
131
  signing_key:
132
132
  specification_version: 4
133
133
  summary: Mongoid's any_of like implementation for activerecord
134
134
  test_files:
135
- - spec/db/schema.rb
136
- - spec/db/database.yml
137
- - spec/support/models.rb
138
- - spec/spec_helper.rb
135
+ - spec/activerecord_any_of_spec.rb
139
136
  - spec/fixtures/users.yml
140
- - spec/fixtures/posts.yml
141
137
  - spec/fixtures/authors.yml
142
- - spec/activerecord_any_of_spec.rb
143
- has_rdoc:
138
+ - spec/fixtures/posts.yml
139
+ - spec/support/models.rb
140
+ - spec/db/database.yml
141
+ - spec/db/schema.rb
142
+ - spec/spec_helper.rb