returning 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ 0.0.2 - 2011-08-22
2
+ -----
3
+ * Add support for ActiveRecord::ConnectionAdapters::QueryCache
@@ -13,27 +13,36 @@ module Returning
13
13
  !!@_returning
14
14
  end
15
15
 
16
- def update(sql, name = nil, binds = [])
17
- if @_returning
18
- records = @_returning[1].find_by_sql("#{to_sql(sql)} RETURNING #{@_returning[0]}", binds)
19
- records.each { |r| r.readonly! }
20
- records
21
- else
22
- super
23
- end
16
+ def exec_with_returning(sql, binds)
17
+ records = @_returning[1].find_by_sql("#{to_sql(sql)} RETURNING #{@_returning[0]}", binds)
18
+ records.each { |r| r.readonly! }
19
+ records
24
20
  end
25
21
 
26
- def delete(arel, name = nil, binds = [])
27
- if @_returning
28
- records = @_returning[1].find_by_sql("#{to_sql(arel)} RETURNING #{@_returning[0]}", binds)
29
- records.each { |r| r.readonly! }
30
- records
22
+ [:update, :delete].each do |method|
23
+ if ::ActiveRecord::VERSION::STRING =~ /^3\.0/
24
+ class_eval <<-RUBY, __FILE__, __LINE__+1
25
+ def #{method}(sql, name = nil)
26
+ if @_returning
27
+ exec_with_returning(sql, [])
28
+ else
29
+ super
30
+ end
31
+ end
32
+ RUBY
31
33
  else
32
- super
34
+ class_eval <<-RUBY, __FILE__, __LINE__+1
35
+ def #{method}(sql, name = nil, binds = [])
36
+ if @_returning
37
+ exec_with_returning(sql, binds)
38
+ else
39
+ super
40
+ end
41
+ end
42
+ RUBY
33
43
  end
34
44
  end
35
45
 
36
-
37
46
  def returning(columns, klass)
38
47
  old_returning, @_returning = @_returning, [columns, klass]
39
48
  yield
@@ -1,3 +1,3 @@
1
1
  module Returning
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/returning.rb CHANGED
@@ -1,9 +1,10 @@
1
+ require 'active_record'
2
+ require 'active_record/connection_adapters/postgresql_adapter'
3
+
1
4
  require "returning/version"
2
5
  require 'returning/active_record/returning'
3
6
  require 'returning/active_record/adapter'
4
7
 
5
- require 'active_record'
6
- require 'active_record/connection_adapters/postgresql_adapter'
7
8
 
8
9
  module Returning
9
10
  # Your code goes here...
@@ -22,6 +22,12 @@ describe Returning do
22
22
  post.save(:returning => 'name').should eql(post)
23
23
  end
24
24
  end
25
+
26
+ context 'with query cache' do
27
+ it 'works' do
28
+ PostQueryCache.first.update_attributes :name => 'cached'
29
+ end
30
+ end
25
31
  end
26
32
 
27
33
  describe '#destroy' do
@@ -30,5 +36,11 @@ describe Returning do
30
36
  post.name = 'hello world'
31
37
  post.destroy(:returning => 'name').name.should == 'hello world'
32
38
  end
39
+
40
+ context 'with query cache' do
41
+ it 'works' do
42
+ expect { PostQueryCache.first.destroy }.not_to raise_error
43
+ end
44
+ end
33
45
  end
34
46
  end
data/spec/support/ar.rb CHANGED
@@ -34,3 +34,8 @@ Migration.up
34
34
 
35
35
  class Post < ActiveRecord::Base
36
36
  end
37
+
38
+ class PostQueryCache < ActiveRecord::Base
39
+ set_table_name :posts
40
+ include ActiveRecord::ConnectionAdapters::QueryCache
41
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: returning
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Eugene Pimenov
@@ -58,6 +58,7 @@ extra_rdoc_files: []
58
58
 
59
59
  files:
60
60
  - .gitignore
61
+ - CHANGELOG.md
61
62
  - Gemfile
62
63
  - Gemfile3.1
63
64
  - README.md