ar_after_transaction 0.3.0 → 0.4.0

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.
data/Appraisals CHANGED
@@ -4,4 +4,5 @@ end
4
4
 
5
5
  appraise "rails3" do
6
6
  gem "activerecord", "~>3.2.7"
7
+ gem 'railties'
7
8
  end
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ar_after_transaction (0.3.0)
4
+ ar_after_transaction (0.4.0)
5
5
  activerecord
6
6
 
7
7
  GEM
@@ -26,7 +26,7 @@ GEM
26
26
  bump (0.3.5)
27
27
  diff-lcs (1.1.3)
28
28
  i18n (0.6.1)
29
- multi_json (1.7.3)
29
+ multi_json (1.7.7)
30
30
  rake (10.0.2)
31
31
  rspec (2.12.0)
32
32
  rspec-core (~> 2.12.0)
data/Readme.md CHANGED
@@ -77,7 +77,7 @@ Authors
77
77
  - [Bogdan Gusiev](http://gusiev.com)
78
78
  - [Benedikt Deicke](http://blog.synatic.net)
79
79
  - [Tyler Rick](https://github.com/TylerRick)
80
- - [michaelmwu](https://github.com/michaelmwu)
80
+ - [Michael Wu](https://github.com/michaelmwu)
81
81
 
82
82
  [Michael Grosser](http://grosser.it)<br/>
83
83
  michael@grosser.it<br/>
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/mgrosser/code/tools/ar_after_transaction
3
3
  specs:
4
- ar_after_transaction (0.2.6)
4
+ ar_after_transaction (0.3.0)
5
5
  activerecord
6
6
 
7
7
  GEM
@@ -8,5 +8,6 @@ gem "rake"
8
8
  gem "rspec", "~>2"
9
9
  gem "sqlite3"
10
10
  gem "activerecord", "~>3.2.7"
11
+ gem "railties"
11
12
 
12
13
  gemspec :path=>"../"
@@ -1,12 +1,22 @@
1
1
  PATH
2
2
  remote: /Users/mgrosser/code/tools/ar_after_transaction
3
3
  specs:
4
- ar_after_transaction (0.2.6)
4
+ ar_after_transaction (0.3.0)
5
5
  activerecord
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
+ actionpack (3.2.8)
11
+ activemodel (= 3.2.8)
12
+ activesupport (= 3.2.8)
13
+ builder (~> 3.0.0)
14
+ erubis (~> 2.7.0)
15
+ journey (~> 1.0.4)
16
+ rack (~> 1.4.0)
17
+ rack-cache (~> 1.2)
18
+ rack-test (~> 0.6.1)
19
+ sprockets (~> 2.1.3)
10
20
  activemodel (3.2.8)
11
21
  activesupport (= 3.2.8)
12
22
  builder (~> 3.0.0)
@@ -25,9 +35,29 @@ GEM
25
35
  builder (3.0.4)
26
36
  bump (0.3.5)
27
37
  diff-lcs (1.1.3)
38
+ erubis (2.7.0)
39
+ hike (1.2.3)
28
40
  i18n (0.6.1)
41
+ journey (1.0.4)
42
+ json (1.8.0)
29
43
  multi_json (1.3.6)
44
+ rack (1.4.5)
45
+ rack-cache (1.2)
46
+ rack (>= 0.4)
47
+ rack-ssl (1.3.3)
48
+ rack
49
+ rack-test (0.6.2)
50
+ rack (>= 1.0)
51
+ railties (3.2.8)
52
+ actionpack (= 3.2.8)
53
+ activesupport (= 3.2.8)
54
+ rack-ssl (~> 1.3.2)
55
+ rake (>= 0.8.7)
56
+ rdoc (~> 3.4)
57
+ thor (>= 0.14.6, < 2.0)
30
58
  rake (0.9.2.2)
59
+ rdoc (3.12.2)
60
+ json (~> 1.4)
31
61
  rspec (2.11.0)
32
62
  rspec-core (~> 2.11.0)
33
63
  rspec-expectations (~> 2.11.0)
@@ -36,7 +66,13 @@ GEM
36
66
  rspec-expectations (2.11.3)
37
67
  diff-lcs (~> 1.1.3)
38
68
  rspec-mocks (2.11.3)
69
+ sprockets (2.1.3)
70
+ hike (~> 1.2)
71
+ rack (~> 1.0)
72
+ tilt (~> 1.1, != 1.3.0)
39
73
  sqlite3 (1.3.6)
74
+ thor (0.18.1)
75
+ tilt (1.4.1)
40
76
  tzinfo (0.3.33)
41
77
 
42
78
  PLATFORMS
@@ -47,6 +83,7 @@ DEPENDENCIES
47
83
  appraisal
48
84
  ar_after_transaction!
49
85
  bump
86
+ railties
50
87
  rake
51
88
  rspec (~> 2)
52
89
  sqlite3
@@ -1,3 +1,3 @@
1
1
  module ARAfterTransaction
2
- VERSION = Version = '0.3.0'
2
+ VERSION = Version = '0.4.0'
3
3
  end
@@ -3,9 +3,18 @@ require 'ar_after_transaction/version'
3
3
 
4
4
  module ARAfterTransaction
5
5
  module ClassMethods
6
- def transaction(*args)
6
+ def self.extended( base )
7
+ base.class_eval do
8
+ class << self
9
+ alias_method :transaction_without_after, :transaction
10
+ alias_method :transaction, :transaction_with_after
11
+ end
12
+ end
13
+ end
14
+
15
+ def transaction_with_after(*args)
7
16
  clean = true
8
- super(*args) do
17
+ transaction_without_after(*args) do
9
18
  begin
10
19
  yield
11
20
  rescue ActiveRecord::Rollback
@@ -0,0 +1,96 @@
1
+ require 'active_record'
2
+ require File.expand_path '../setup_database', __FILE__
3
+
4
+ if ActiveRecord::VERSION::MAJOR > 2
5
+ require 'action_controller/railtie'
6
+
7
+ Rack::Session::Cookie
8
+
9
+ module Passthrough
10
+ def self.extended( base )
11
+ base.class_eval do
12
+ class << self
13
+ alias_method :transaction_without_passthrough, :transaction
14
+ alias_method :transaction, :transaction_with_passthrough
15
+ end
16
+ end
17
+ end
18
+
19
+ def transaction_with_passthrough(*args, &block)
20
+ transaction_without_passthrough(*args, &block)
21
+ end
22
+ end
23
+
24
+ class Railtie < ::Rails::Railtie
25
+ config.after_initialize do
26
+ ActiveRecord::Base.send(:extend, Passthrough)
27
+ end
28
+ end
29
+
30
+ module ARAfterTransaction
31
+ class Application < ::Rails::Application
32
+ config.active_support.deprecation = :log
33
+
34
+ config.after_initialize do
35
+ require 'ar_after_transaction'
36
+ end
37
+ end
38
+ end
39
+
40
+ Rack::Session::Cookie.send(:define_method, :warn){|_|} # seilence secret warning
41
+ ARAfterTransaction::Application.initialize! # initialize app
42
+
43
+ class AnExpectedError < Exception
44
+ end
45
+
46
+ class User
47
+ cattr_accessor :test_callbacks, :test_stack
48
+ self.test_stack = []
49
+ self.test_callbacks = []
50
+
51
+ after_create :do_it
52
+ def do_it
53
+ self.class.test_callbacks.map{|callback| send(callback)}.last
54
+ end
55
+
56
+ def do_after
57
+ after_transaction do
58
+ ActiveRecord::Base.transaction do
59
+ # nested transaction should not cause infinitive recursion
60
+ end
61
+ self.class.test_stack << :after
62
+ end
63
+ end
64
+
65
+ def do_normal
66
+ self.class.test_stack << :normal
67
+ end
68
+
69
+ def oops
70
+ raise AnExpectedError
71
+ end
72
+
73
+ def raise_rollback
74
+ raise ActiveRecord::Rollback
75
+ end
76
+ end
77
+
78
+ describe ARAfterTransaction do
79
+ before do
80
+ User.normally_open_transactions = nil
81
+ User.send(:transactions_open?).should == false
82
+ User.test_stack.clear
83
+ User.test_callbacks.clear
84
+ end
85
+
86
+ it "has a VERSION" do
87
+ ARAfterTransaction::VERSION.should =~ /^\d+\.\d+\.\d+$/
88
+ end
89
+
90
+ it "executes after a transaction" do
91
+ User.test_callbacks = [:do_after, :do_normal]
92
+ User.create!
93
+ User.test_stack.should == [:normal, :after]
94
+ end
95
+ end
96
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ar_after_transaction
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-05 00:00:00.000000000 Z
12
+ date: 2013-06-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -46,6 +46,7 @@ files:
46
46
  - gemfiles/rails3.gemfile.lock
47
47
  - lib/ar_after_transaction.rb
48
48
  - lib/ar_after_transaction/version.rb
49
+ - spec/after_initialize_spec.rb
49
50
  - spec/ar_after_transaction_spec.rb
50
51
  - spec/setup_database.rb
51
52
  - spec/spec_helper.rb
@@ -64,7 +65,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
64
65
  version: '0'
65
66
  segments:
66
67
  - 0
67
- hash: -2540261946806490361
68
+ hash: 2099536990730070045
68
69
  required_rubygems_version: !ruby/object:Gem::Requirement
69
70
  none: false
70
71
  requirements:
@@ -73,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
74
  version: '0'
74
75
  segments:
75
76
  - 0
76
- hash: -2540261946806490361
77
+ hash: 2099536990730070045
77
78
  requirements: []
78
79
  rubyforge_project:
79
80
  rubygems_version: 1.8.25