active_record-acts_as 2.4.1 → 2.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -1
- data/lib/active_record/acts_as/querying.rb +11 -8
- data/lib/active_record/acts_as/version.rb +1 -1
- data/spec/acts_as_spec.rb +48 -28
- data/spec/models.rb +2 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d36aaa8f22e66b7d9fd5c2280f4548e9efe3b3fe
|
4
|
+
data.tar.gz: 9f30018fa7aaaffc40c8c915b0ed6cc7cd8abda3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b9a24160409f92c1bc8e1e81e85dcd2553c133804507bf1eb848aff3865a65a9bb173a0cc6f237d7877998761acd7d89fa838ff7484486e4a50ba188429d1e0
|
7
|
+
data.tar.gz: 672a6b0320fdaa101567546b887a652a993a61d1ccb0d130d3eb55c332c68b09750d2cceb5990aac57cfbc03fee4536c6d3c20b68f03dbdcac614b1ca56c014d
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
|
|
4
4
|
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
5
5
|
and this project adheres to [Semantic Versioning](http://semver.org/).
|
6
6
|
|
7
|
+
## [2.4.2] - 2017-04-20
|
8
|
+
### Fixed
|
9
|
+
- Fix querying for conditions with hashes.
|
10
|
+
|
7
11
|
## [2.4.1] - 2017-04-19
|
8
12
|
### Fixed
|
9
13
|
- Make ActiveRecord::Relation#where! work.
|
@@ -88,7 +92,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
|
88
92
|
### Fixed
|
89
93
|
- Fixed `remove_actable` migration helper (https://github.com/hzamani/active_record-acts_as/pull/71, thanks to [nuclearpidgeon](https://github.com/nuclearpidgeon)!)
|
90
94
|
|
91
|
-
[Unreleased]: https://github.com/krautcomputing/active_record-acts_as/compare/v2.4.
|
95
|
+
[Unreleased]: https://github.com/krautcomputing/active_record-acts_as/compare/v2.4.2...HEAD
|
96
|
+
[2.4.2]: https://github.com/krautcomputing/active_record-acts_as/compare/v2.4.1...v2.4.2
|
92
97
|
[2.4.1]: https://github.com/krautcomputing/active_record-acts_as/compare/v2.4.0...v2.4.1
|
93
98
|
[2.4.0]: https://github.com/krautcomputing/active_record-acts_as/compare/v2.3.1...v2.4.0
|
94
99
|
[2.3.1]: https://github.com/krautcomputing/active_record-acts_as/compare/v2.3.0...v2.3.1
|
@@ -1,24 +1,27 @@
|
|
1
1
|
module ActiveRecord
|
2
2
|
module ActsAs
|
3
3
|
module QueryMethods
|
4
|
-
def where!(opts, *)
|
4
|
+
def where!(opts, *rest)
|
5
5
|
if acting_as? && opts.is_a?(Hash)
|
6
|
-
if table_name_opts = opts.delete(
|
6
|
+
if table_name_opts = opts.delete(table_name)
|
7
7
|
opts = opts.merge(table_name_opts)
|
8
8
|
end
|
9
9
|
|
10
|
-
# Filter out the conditions that should be
|
11
|
-
#
|
12
|
-
#
|
13
|
-
|
14
|
-
|
10
|
+
# Filter out the conditions that should be applied to the `acting_as_model`, which are
|
11
|
+
# those that neither target specific tables explicitly (where the condition value
|
12
|
+
# is a hash or the condition key contains a dot) nor are attributes of the submodel.
|
13
|
+
opts, acts_as_opts = opts.stringify_keys.partition do |k, v|
|
14
|
+
v.is_a?(Hash) ||
|
15
|
+
k =~ /\./ ||
|
16
|
+
column_names.include?(k.to_s)
|
17
|
+
end.map(&:to_h)
|
15
18
|
|
16
19
|
if acts_as_opts.any?
|
17
20
|
opts[acting_as_model.table_name] = acts_as_opts
|
18
21
|
end
|
19
22
|
end
|
20
23
|
|
21
|
-
super
|
24
|
+
super opts, *rest
|
22
25
|
end
|
23
26
|
end
|
24
27
|
|
data/spec/acts_as_spec.rb
CHANGED
@@ -440,46 +440,66 @@ RSpec.describe "ActiveRecord::Base model with #acts_as called" do
|
|
440
440
|
end
|
441
441
|
|
442
442
|
context "Querying" do
|
443
|
-
before
|
443
|
+
before do
|
444
|
+
clear_database
|
445
|
+
|
446
|
+
@red_pen = Pen.create!(name: 'red pen', price: 0.8, color: 'red')
|
447
|
+
@blue_pen = Pen.create!(name: 'blue pen', price: 0.8, color: 'blue')
|
448
|
+
@black_pen = Pen.create!(name: 'black pen', price: 0.9, color: 'black')
|
444
449
|
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
black_pen = Pen.create(name: 'black pen', price: 0.9, color: 'black')
|
450
|
+
@red_pen.pen_caps.create! size: 'S'
|
451
|
+
@blue_pen.pen_caps.create! size: 'M'
|
452
|
+
@black_pen.pen_caps.create! size: 'M'
|
449
453
|
|
450
|
-
|
454
|
+
@red_pen.buyers.create! name: 'Tim'
|
455
|
+
@blue_pen.buyers.create! name: 'Tim'
|
456
|
+
@black_pen.buyers.create! name: 'John'
|
451
457
|
end
|
452
458
|
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
black_pen = Pen.create(name: 'black pen', price: 0.9, color: 'black')
|
459
|
+
describe '.where and .where!' do
|
460
|
+
it 'respects supermodel attributes' do
|
461
|
+
conditions = { price: 0.8 }
|
457
462
|
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
463
|
+
expect(Pen.where(conditions).to_a).to eq([@red_pen, @blue_pen])
|
464
|
+
|
465
|
+
relation = Pen.all
|
466
|
+
relation.where!(conditions)
|
467
|
+
expect(relation.to_a).to eq([@red_pen, @blue_pen])
|
468
|
+
end
|
469
|
+
|
470
|
+
it 'works with hashes' do
|
471
|
+
conditions = {
|
472
|
+
pen_caps: { size: 'M' },
|
473
|
+
buyers: { name: 'Tim' }
|
474
|
+
}
|
462
475
|
|
463
|
-
|
464
|
-
red_pen = Pen.create(name: 'red pen', price: 0.8, color: 'red')
|
465
|
-
blue_pen = Pen.create(name: 'blue pen', price: 0.8, color: 'blue')
|
466
|
-
black_pen = Pen.create(name: 'black pen', price: 0.9, color: 'black')
|
476
|
+
expect(Pen.joins(:pen_caps, :buyers).where(conditions).to_a).to eq([@blue_pen])
|
467
477
|
|
468
|
-
|
469
|
-
|
470
|
-
|
478
|
+
relation = Pen.joins(:pen_caps, :buyers)
|
479
|
+
relation.where!(conditions)
|
480
|
+
expect(relation.to_a).to eq([@blue_pen])
|
481
|
+
end
|
471
482
|
end
|
472
483
|
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
484
|
+
describe '.find_by' do
|
485
|
+
it 'respects supermodel attributes' do
|
486
|
+
expect(Pen.find_by(name: 'red pen')).to eq(@red_pen)
|
487
|
+
expect(Pen.find_by(name: 'blue pen')).to eq(@blue_pen)
|
488
|
+
expect(Pen.find_by(name: 'black pen')).to eq(@black_pen)
|
489
|
+
end
|
490
|
+
|
491
|
+
it 'works with specifying the table name' do
|
492
|
+
expect(Pen.find_by('pens.color' => 'red')).to eq(@red_pen)
|
493
|
+
end
|
477
494
|
end
|
478
495
|
|
479
|
-
|
480
|
-
|
496
|
+
describe '.scope_for_create' do
|
497
|
+
it 'includes supermodel attributes' do
|
498
|
+
relation = Pen.where(name: 'new name', price: 1.4, color: 'red')
|
481
499
|
|
482
|
-
|
500
|
+
expect(relation.scope_for_create.keys).to include('name')
|
501
|
+
expect(relation.scope_for_create['name']).to eq('new name')
|
502
|
+
end
|
483
503
|
end
|
484
504
|
end
|
485
505
|
|
data/spec/models.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_record-acts_as
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.4.
|
4
|
+
version: 2.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hassan Zamani
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-04-
|
12
|
+
date: 2017-04-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sqlite3
|