where_conditioner 1.1.1 → 1.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cadede51475344b93a3d88c4220b047430a5668a
4
- data.tar.gz: 386286509e4c3fee25ec8b5c5b5ea39b14aca939
3
+ metadata.gz: 4413174ed2b12c678a7961447406a1af1bc9be81
4
+ data.tar.gz: 5daab752c7324355971f1847001096273a02fd08
5
5
  SHA512:
6
- metadata.gz: 0c81ade509e725b5e2c1a22fb0eac3572f522c3e33a9efed92c96ccca2d41e50141c23b30c2b1aadf4ff35d8006fe368a2c91ef7f229467201a7530dc472ee53
7
- data.tar.gz: ac5d175acabfb3722c2287d6aa1eade21ee40733c63d593d0dae1d9b08318b85ed0789cb9592b1ae0d4dd4bb9c3cfe17c820aeecab21ba566aaeb8ce95f85085
6
+ metadata.gz: f0549831f127959ebaaf0fc2be5da7e730c9546ea8c35f2a2591a280f9c24cc7b497818d9cb1cbdab715c5f8b94983f110dc2c27d6deecee130fba37ffb7eb64
7
+ data.tar.gz: 92eb7f6550cd9023da4a7279aaf910c2b3cdb374e00cfee6599de3f5586ca0e4cb61de1a203350396613a1d6e11fde4d031a15ed240571d53e8d25dc8b640cf3
@@ -25,9 +25,9 @@ module WhereConditioner
25
25
  end
26
26
 
27
27
  def elsif condition, &block
28
- result = conditional (!@last_condition && condition), &block
29
- @last_condition = condition
30
- result
28
+ condition &&= !@last_condition # falsify condition if an "if" or "elsif" branch has already succeeded
29
+ @last_condition ||= condition # @last_condition is true if at least one branch has succeeded, including this elsif
30
+ conditional condition, &block
31
31
  end
32
32
 
33
33
  def where_if_present *args
@@ -169,6 +169,22 @@ describe WhereConditioner do
169
169
  relation.if(true).foo.elsif(false).bar.baz
170
170
  end
171
171
  end
172
+
173
+ context 'with multiple elsifs' do
174
+ it 'passes method calls to relation' do
175
+ expect(relation).to receive(:foo).and_return(relation)
176
+ expect(relation).to receive(:bar)
177
+ relation.if(true).foo.elsif(false).bad.elsif(true).other_bad.else.really_bad.bar
178
+ end
179
+ end
180
+
181
+ context 'with an else clause' do
182
+ it 'passes method calls to relation' do
183
+ expect(relation).to receive(:foo).and_return(relation)
184
+ expect(relation).to receive(:bar)
185
+ relation.if(true).foo.elsif(false).bad.elsif(false).other_bad.else.really_bad.bar
186
+ end
187
+ end
172
188
  end
173
189
 
174
190
  context 'with a block' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: where_conditioner
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Novak
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-05-21 00:00:00.000000000 Z
12
+ date: 2014-07-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord