acts_as 0.3.0 → 0.3.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 514a5965f8825f4c4bc1f2cb8155585c042f891c
4
- data.tar.gz: 81513cdac4a29c051fd3be2240e0b9cc1a3f74b7
3
+ metadata.gz: f6e9ee1715570c9e8a97e3212b76ad5a66fb65bb
4
+ data.tar.gz: 38bc6aa48979d056cf86ec03903d741d1200eabe
5
5
  SHA512:
6
- metadata.gz: fa3a00abcba6a4fe27727232a9a3b142d5934343106417147d703fe2707a973793c642ff861fb7f0bcb3de54cbb668946b03cfaaa14286e0251f7b88f0430ae0
7
- data.tar.gz: 0608465f2b7ffa2f0027df6bed6113253da3acafdc3c37e2ea590d564af6c045702e2374d6cce49c75e700886e2ab512bf7a49356344002db34deeb12183edff
6
+ metadata.gz: 8ec4605e84506cf2765025d68812542c37ae548400f6176e78b3d313abe97acbe71eada88542baafdb4d6346c4d0156e4483c7d653b29b62a1060ebe0b4cfb23
7
+ data.tar.gz: 6c055ebd63e0abc5a1c00aa472333cfa88b8a3d924bcc574c9b9a08aef5353ef655d7a951188d1955644b4f099678dfc429181298cdc7a3c2113ee47e72b7134
data/README.md CHANGED
@@ -82,16 +82,15 @@ Now a whole slew of methods related to ActiveRecord attributes are available for
82
82
  # Any method you want
83
83
  rebel.delegate_at_will #=> '10'
84
84
 
85
+ ## Automagical joins through .where Hash syntax
85
86
 
86
- ## Roadmap / Ideas
87
+ Just get to what you want
87
88
 
88
- How does the active record join hash-parsing stuff work? EX-
89
-
90
- Rebel.joins(:clan).where(clan: {cool: true)
91
-
92
- Can we make this work for ruby-sql autojoins? Is that even a good idea?
89
+ ```ruby
90
+ Rebel.where(strength: 10) #=> the same as Rebel.joins(:clan).where(clan: {strength: 10)
91
+ ```
93
92
 
94
- Rebel.where(cool: true) #auto-joins :clan and queries clans table
93
+ One major caveat, it only works for first-level attributes at the moment. (see pending spec)
95
94
 
96
95
  ## Contributing
97
96
 
@@ -1,3 +1,3 @@
1
1
  module ActsAs
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
data/lib/acts_as.rb CHANGED
@@ -56,9 +56,11 @@ module ActsAs
56
56
  relation = super
57
57
  #TODO support nested attribute joins like Guns.where(rebels: {strength: 10}))
58
58
  # for now, only first level joins will happen automagically
59
- detected_associations = opts.keys.map {|attr| acts_as_fields_match(attr) }
60
- .reject {|attr| attr.nil?}
61
- return relation.joins(detected_associations) if detected_associations.any?
59
+ if opts.is_a? Hash
60
+ detected_associations = opts.keys.map {|attr| acts_as_fields_match(attr) }
61
+ .reject {|attr| attr.nil?}
62
+ return relation.joins(detected_associations) if detected_associations.any?
63
+ end
62
64
  relation
63
65
  end
64
66
 
data/spec/acts_as_spec.rb CHANGED
@@ -104,9 +104,12 @@ describe ActsAs do
104
104
  end
105
105
 
106
106
  describe 'automagic .where hash syntax helpers' do
107
- it 'should auto-expand acted attributes' do
107
+ it 'should auto-expand acted hash attributes' do
108
108
  Rebel.where(strength: rebel.strength).should include(rebel)
109
109
  Rebel.where(strength: rebel.strength, name: 'Jimbo').should_not include(rebel)
110
+ expect {
111
+ Rebel.where('strength = ?', 12).any?
112
+ }.to raise_error(ActiveRecord::StatementInvalid)
110
113
  end
111
114
 
112
115
  it 'should auto-expand acted attribuets that are nested as well' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - winfred