ngmoco-cache-money 0.2.13 → 0.2.14

Sign up to get free protection for your applications and to get access to all the features.
data/UNSUPPORTED_FEATURES CHANGED
@@ -6,7 +6,7 @@
6
6
  * update_all, delete, update_counter, increment_counter, decrement_counter, counter_caches in general - counter caches are replaced by this gem, bear that in mind.
7
7
  * attr_readonly - no technical obstacle, just not yet supported
8
8
  * attributes before typecast behave unpredictably - hard to support
9
- * ActiveRecord::Rollback is unsupported - the exception gets swallowed so there isn't an opportunity to rollback the cache transaction - not hard to support
9
+ * Named bind variables :conditions => ["name = :name", { :name => "37signals!" }] - not hard to support
10
10
  * printf style binds: :conditions => ["name = '%s'", "37signals!"] - not too hard to support
11
11
  * objects as attributes that are serialized. story.title = {:foo => :bar}; customer.balance = Money.new(...) - these could be coerced using Column#type_cast?
12
12
 
data/lib/cache_money.rb CHANGED
@@ -57,11 +57,13 @@ module Cash
57
57
  end
58
58
  end
59
59
 
60
- def transaction_with_cache_transaction(&block)
60
+ def transaction_with_cache_transaction(*args)
61
61
  if cache_config
62
- repository.transaction { transaction_without_cache_transaction(&block) }
62
+ transaction_without_cache_transaction(*args) do
63
+ repository.transaction { yield }
64
+ end
63
65
  else
64
- transaction_without_cache_transaction(&block)
66
+ transaction_without_cache_transaction(*args)
65
67
  end
66
68
  end
67
69
 
@@ -187,9 +187,9 @@ module Cash
187
187
 
188
188
  def find_from_keys(*missing_keys)
189
189
  missing_ids = Array(missing_keys).flatten.collect { |key| key.split('/')[2].to_i }
190
- options = @options1.dup
191
- options.delete(:conditions)
192
- options.delete(:limit)
190
+ options = {}
191
+ order_sql = @options1[:order] || @options2[:order]
192
+ options[:order] = order_sql if order_sql
193
193
  find_from_ids_without_cache(missing_ids, options)
194
194
  end
195
195
  end
@@ -219,5 +219,27 @@ module Cash
219
219
  end
220
220
  end
221
221
  end
222
+
223
+ describe 'Transactions' do
224
+ def create_story_and_update
225
+ @story = Story.create!(:title => original_title = "original title")
226
+
227
+ Story.transaction do
228
+ @story.title = "new title"
229
+ @story.save
230
+ yield if block_given?
231
+ end
232
+ end
233
+
234
+ it 'should commit on success' do
235
+ create_story_and_update
236
+ @story.reload.title.should == "new title"
237
+ end
238
+
239
+ it 'should roll back transactions when ActiveRecord::Rollback is raised' do
240
+ create_story_and_update { raise ActiveRecord::Rollback }
241
+ @story.reload.title.should == "original title"
242
+ end
243
+ end
222
244
  end
223
245
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 13
9
- version: 0.2.13
8
+ - 14
9
+ version: 0.2.14
10
10
  platform: ruby
11
11
  authors:
12
12
  - Nick Kallen
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2010-08-05 00:00:00 -07:00
20
+ date: 2010-08-23 00:00:00 -07:00
21
21
  default_executable:
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency