onyx-cache-money 0.2.6 → 0.2.6.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/cash/query/abstract.rb +8 -7
- data/spec/cash/active_record_spec.rb +9 -0
- metadata +1 -1
data/lib/cash/query/abstract.rb
CHANGED
@@ -194,7 +194,7 @@ module Cash
|
|
194
194
|
match = results.select do |result|
|
195
195
|
found_match = false
|
196
196
|
missing_keys_values_pair.each_slice(2) do |key, value|
|
197
|
-
found_match = upcase_if_possible(result.send(key)) ==
|
197
|
+
found_match = upcase_if_possible(result.send(key)) == upcase_if_possible(type_cast(key,value))
|
198
198
|
break unless found_match
|
199
199
|
end
|
200
200
|
found_match
|
@@ -215,7 +215,9 @@ module Cash
|
|
215
215
|
# { :id => [1,2], :title => [foo] }
|
216
216
|
|
217
217
|
conditions = keys_values.collect do |key,values|
|
218
|
-
quoted_values = values.collect
|
218
|
+
quoted_values = values.collect do |value|
|
219
|
+
quote_value(type_cast(key, value), columns_hash[key])
|
220
|
+
end
|
219
221
|
quoted_table_and_column_name = "#{quoted_table_name}.#{connection.quote_column_name(key)}"
|
220
222
|
if quoted_values.size == 1
|
221
223
|
"#{quoted_table_and_column_name} = #{quoted_values}"
|
@@ -227,14 +229,13 @@ module Cash
|
|
227
229
|
|
228
230
|
protected
|
229
231
|
|
230
|
-
def
|
231
|
-
|
232
|
+
def type_cast(column_name, value)
|
233
|
+
columns_hash[column_name].type_cast(value)
|
232
234
|
end
|
233
235
|
|
234
|
-
def
|
235
|
-
|
236
|
+
def upcase_if_possible(value)
|
237
|
+
value.respond_to?(:upcase) ? value.upcase : value
|
236
238
|
end
|
237
|
-
|
238
239
|
end
|
239
240
|
end
|
240
241
|
end
|
@@ -204,6 +204,15 @@ module Cash
|
|
204
204
|
end.should_not raise_error(ActiveRecord::MissingAttributeError)
|
205
205
|
end
|
206
206
|
end
|
207
|
+
|
208
|
+
describe "#find(:first, :conditions => '...')" do
|
209
|
+
it 'correctly retrives by boolean field' do
|
210
|
+
story1 = Story.create! :title => 'a story', :published => true
|
211
|
+
story2 = Story.create! :title => 'another story', :published => false
|
212
|
+
$memcache.flush_all
|
213
|
+
Story.find(:first, :conditions => {:published => true}).should == story1
|
214
|
+
end
|
215
|
+
end
|
207
216
|
|
208
217
|
describe '#find(id1, id2, ...)' do
|
209
218
|
it "handles finds with multiple ids correctly" do
|