where_conditioner 1.0.0 → 1.1.0

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: 2cbdd592512b031ccd2c5d372c5c523e2397d361
4
- data.tar.gz: 33e5d99969813c2ec9bb10e986f62e96a79b27b7
3
+ metadata.gz: c44ce09a4fe3727fe41e7db71d8dc99635964804
4
+ data.tar.gz: 8ee269cec9b22ef62b15669b4b61a1f4ed03aeee
5
5
  SHA512:
6
- metadata.gz: dbcb4cc8993e3188161690f895a3ac38ac39212172370b8d656fd6290de211e3026a704036c0ad2188537ab9e540d685bda2b8f55145cc1509ad60c34a5fb806
7
- data.tar.gz: fa8d21e6d95897283363f2713d17c0b37815c6b3d51895879658859ca4aa82e53c03b0870db63a1f171c57685b3395725a27e4d53912776aa46fc9a39f032a44
6
+ metadata.gz: c266e1cb927721587d933c59b39461acffa37c854052d45785cb2e5899a55b8d091157ed275bf3ea7965539b65df433f4f29433d9efefd80dfc97b69fb88403c
7
+ data.tar.gz: 8797fabf41f090281b204ed1df708f76458334ae49ec23e44595c914f120765c410a7c0b620e5b2dccb44ff294e353960715722046c6ab2738de709f394dda3d
@@ -24,6 +24,12 @@ module WhereConditioner
24
24
  conditional !@last_condition, &block
25
25
  end
26
26
 
27
+ def elsif condition, &block
28
+ result = conditional (!@last_condition && condition), &block
29
+ @last_condition = condition
30
+ result
31
+ end
32
+
27
33
  def where_if_present *args
28
34
  if Hash === args.first && args.length == 1
29
35
  hash = args.first.compact
@@ -132,4 +132,70 @@ describe WhereConditioner do
132
132
  end
133
133
  end
134
134
  end
135
+
136
+ describe '#elsif' do
137
+ context 'chained' do
138
+ context 'with true, true condition' do
139
+ it 'passes method calls to relation' do
140
+ expect(relation).to receive(:foo).and_return(relation)
141
+ expect(relation).to receive(:baz)
142
+ relation.if(true).foo.elsif(true).bar.baz
143
+ end
144
+ end
145
+
146
+ context 'with false, true condition' do
147
+ it 'passes method calls to relation' do
148
+ expect(relation).to receive_message_chain(:bar, :baz)
149
+ relation.if(false).foo.elsif(true).bar.baz
150
+ end
151
+ end
152
+
153
+ context 'with false, false condition' do
154
+ it 'passes method calls to relation' do
155
+ expect(relation).to receive(:baz)
156
+ relation.if(false).foo.elsif(false).bar.baz
157
+ end
158
+ end
159
+
160
+ context 'with true, false condition' do
161
+ it 'passes method calls to relation' do
162
+ expect(relation).to receive(:foo).and_return(relation)
163
+ expect(relation).to receive(:baz)
164
+ relation.if(true).foo.elsif(false).bar.baz
165
+ end
166
+ end
167
+ end
168
+
169
+ context 'with a block' do
170
+ context 'with true, true condition' do
171
+ it 'passes method calls to relation' do
172
+ expect(relation).to receive(:foo).and_return(relation)
173
+ expect(relation).to receive(:moop)
174
+ relation.if(true).foo.elsif(true) { bar.baz }.moop
175
+ end
176
+ end
177
+
178
+ context 'with false, true condition' do
179
+ it 'passes method calls to relation' do
180
+ expect(relation).to receive_message_chain(:bar, :baz, :moop)
181
+ relation.if(false).foo.elsif(true) { bar.baz }.moop
182
+ end
183
+ end
184
+
185
+ context 'with false, false condition' do
186
+ it 'passes method calls to relation' do
187
+ expect(relation).to receive(:moop)
188
+ relation.if(false).foo.elsif(false) { bar.baz }.moop
189
+ end
190
+ end
191
+
192
+ context 'with true, false condition' do
193
+ it 'passes method calls to relation' do
194
+ expect(relation).to receive(:foo).and_return(relation)
195
+ expect(relation).to receive(:moop)
196
+ relation.if(true).foo.elsif(false) { bar.baz }.moop
197
+ end
198
+ end
199
+ end
200
+ end
135
201
  end
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: where_conditioner
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Novak
8
+ - Jonathan Aizen
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2014-04-28 00:00:00.000000000 Z
12
+ date: 2014-05-21 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: activerecord
@@ -71,7 +72,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
71
72
  version: '0'
72
73
  requirements: []
73
74
  rubyforge_project:
74
- rubygems_version: 2.2.1
75
+ rubygems_version: 2.2.2
75
76
  signing_key:
76
77
  specification_version: 4
77
78
  summary: Where Conditioner