test_after_commit 0.2.1 → 0.2.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0771c33d6db21be88b98458395d484ee9414352a
4
- data.tar.gz: 154e46ea5761f401201401913c2af9dc9ebf698e
3
+ metadata.gz: 0c6a0f9af37b262aa154f706d6c1cd365bb09814
4
+ data.tar.gz: c796d6a95a93bedfb11597f3aa691de3582c6883
5
5
  SHA512:
6
- metadata.gz: 9188eaac46d1ea76037eebbde65b5ee700d173ab597a9e0e04165fcc689875c3382a84acdc474dbccd7949ed75cfa2958975547552136a548b53670209d783aa
7
- data.tar.gz: 0cbf8d71596dfd913df0160e1a5932b7bbc844472cab2e968cb5f075b1ae1597f73e4fcad5837adbbaca6a3a784367a10831b781141b5bcf99415c2bf257ad17
6
+ metadata.gz: 68ce3977a1cf2200cda9321b773b34c13b390673c91aca9b20b400eb38bab23351a4c2c9e7c133e23a2bb530768933a85578118c1d052aab96ad996af431495b
7
+ data.tar.gz: 51cb9ce5298a091819895566921a7736621ec11c897391f9e1cadfe93f7a4e1e5a9a194f989921380f19007799473992dc3058fdf34d10555194d2b8e82fac58
data/.travis.yml CHANGED
@@ -1,3 +1,4 @@
1
+ bundler_args: ""
1
2
  language: ruby
2
3
  rvm:
3
4
  - ree
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- test_after_commit (0.2.1)
4
+ test_after_commit (0.2.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/Readme.md CHANGED
@@ -41,6 +41,7 @@ Inspired by https://gist.github.com/1305285
41
41
 
42
42
  ### [Contributors](https://github.com/grosser/test_after_commit/contributors)
43
43
  - [James Le Cuirot](https://github.com/chewi)
44
+ - [emirose](https://github.com/emirose)
44
45
 
45
46
  [Michael Grosser](http://grosser.it)<br/>
46
47
  michael@grosser.it<br/>
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/mgrosser/code/tools/test_after_commit
3
3
  specs:
4
- test_after_commit (0.2.0)
4
+ test_after_commit (0.2.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/mgrosser/code/tools/test_after_commit
3
3
  specs:
4
- test_after_commit (0.2.0)
4
+ test_after_commit (0.2.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/mgrosser/code/tools/test_after_commit
3
3
  specs:
4
- test_after_commit (0.2.0)
4
+ test_after_commit (0.2.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/mgrosser/code/tools/test_after_commit
3
3
  specs:
4
- test_after_commit (0.2.0)
4
+ test_after_commit (0.2.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -63,3 +63,14 @@ ActiveRecord::ConnectionAdapters::DatabaseStatements.class_eval do
63
63
  end
64
64
  end
65
65
  end
66
+
67
+ if ActiveRecord::VERSION::MAJOR >= 4
68
+ # disable parts of the sync code that starts looping
69
+ ActiveRecord::Base.class_eval do
70
+ alias_method :sync_with_transaction_state_with_state, :sync_with_transaction_state
71
+ def sync_with_transaction_state
72
+ @reflects_state[0] = true
73
+ sync_with_transaction_state_with_state
74
+ end
75
+ end
76
+ end
@@ -1,3 +1,3 @@
1
1
  module TestAfterCommit
2
- VERSION = '0.2.1'
2
+ VERSION = '0.2.2'
3
3
  end
data/spec/database.rb CHANGED
@@ -30,7 +30,20 @@ ActiveRecord::Schema.define(:version => 1) do
30
30
  end
31
31
  end
32
32
 
33
+ module Called
34
+ def called(x=nil)
35
+ @called ||= []
36
+ if x
37
+ @called << x
38
+ else
39
+ @called
40
+ end
41
+ end
42
+ end
43
+
33
44
  class Car < ActiveRecord::Base
45
+ extend Called
46
+
34
47
  has_many :cars
35
48
 
36
49
  after_commit :simple_after_commit
@@ -43,15 +56,6 @@ class Car < ActiveRecord::Base
43
56
 
44
57
  attr_accessor :make_rollback, :raise_error, :do_after_create_save
45
58
 
46
- def self.called(x=nil)
47
- @called ||= []
48
- if x
49
- @called << x
50
- else
51
- @called
52
- end
53
- end
54
-
55
59
  def trigger_rollback
56
60
  raise ActiveRecord::Rollback if make_rollback
57
61
  end
@@ -96,6 +100,7 @@ class CarObserver < ActiveRecord::Observer
96
100
  define_method action do |record|
97
101
  return unless recording
98
102
  Car.called << :observed_after_commit
103
+ Untracked.create!
99
104
  end
100
105
  end
101
106
  end
@@ -108,6 +113,23 @@ class Bar < ActiveRecord::Base
108
113
  has_many :bars, :foreign_key => :car_id
109
114
  end
110
115
 
116
+ class MultiBar < ActiveRecord::Base
117
+ extend Called
118
+
119
+ self.table_name = "cars"
120
+
121
+ after_commit :one, :on => :create
122
+ after_commit :two, :on => :create
123
+
124
+ def one
125
+ self.class.called << :one
126
+ end
127
+
128
+ def two
129
+ self.class.called << :two
130
+ end
131
+ end
132
+
111
133
  class Address < ActiveRecord::Base
112
134
  has_many :people
113
135
 
@@ -134,3 +156,7 @@ class Person < ActiveRecord::Base
134
156
  address.update_attributes(:number_of_residents => address.number_of_residents + 1)
135
157
  end
136
158
  end
159
+
160
+ class Untracked < ActiveRecord::Base
161
+ self.table_name = "cars"
162
+ end
@@ -1,6 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe TestAfterCommit do
4
+ def rails4?
5
+ ActiveRecord::VERSION::MAJOR >= 4
6
+ end
7
+
4
8
  before do
5
9
  CarObserver.recording = false
6
10
  Car.called.clear
@@ -67,7 +71,7 @@ describe TestAfterCommit do
67
71
  car.do_after_create_save = true
68
72
  car.save!
69
73
 
70
- expected = if ActiveRecord::VERSION::MAJOR >= 4
74
+ expected = if rails4?
71
75
  [:update, :always, :save_once, :always] # some kind of loop prevention ... investigate we must
72
76
  else
73
77
  [:save_once, :create, :always, :save_once, :create, :always]
@@ -78,12 +82,17 @@ describe TestAfterCommit do
78
82
 
79
83
  it "returns on create and on create of associations" do
80
84
  Car.create!.class.should == Car
81
- Car.create!.cars.create.class.should == Car
85
+ Car.create!.cars.create.class.should == (rails4? ? NilClass : Car)
82
86
  end
83
87
 
84
88
  it "returns on create and on create of associations without after_commit" do
85
89
  Bar.create!.class.should == Bar
86
- Bar.create!.bars.create.class.should == Bar
90
+ Bar.create!.bars.create.class.should == (rails4? ? NilClass : Bar)
91
+ end
92
+
93
+ it "calls callbacks in correct order" do
94
+ MultiBar.create!
95
+ MultiBar.called.should == [:two, :one]
87
96
  end
88
97
 
89
98
  context "Observer" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: test_after_commit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Grosser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-22 00:00:00.000000000 Z
11
+ date: 2013-10-31 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: michael@grosser.it