test_after_commit 0.2.2 → 0.2.3

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: 0c6a0f9af37b262aa154f706d6c1cd365bb09814
4
- data.tar.gz: c796d6a95a93bedfb11597f3aa691de3582c6883
3
+ metadata.gz: 53cbdbb3d9ee9acf28c18f6b56ecb98ddc40ff43
4
+ data.tar.gz: 8322e536b61c930041d92539f7beca47a6eb6e51
5
5
  SHA512:
6
- metadata.gz: 68ce3977a1cf2200cda9321b773b34c13b390673c91aca9b20b400eb38bab23351a4c2c9e7c133e23a2bb530768933a85578118c1d052aab96ad996af431495b
7
- data.tar.gz: 51cb9ce5298a091819895566921a7736621ec11c897391f9e1cadfe93f7a4e1e5a9a194f989921380f19007799473992dc3058fdf34d10555194d2b8e82fac58
6
+ metadata.gz: b5b3f3d5d52b4a049107d4b57ab70c849db440bb2d862f8cae85f8b0fb1f81a6cf9fe2826538ed1da082c6efbd615e71267c1e983e1533c9623e42685b89f6fa
7
+ data.tar.gz: b0c2cfbcd1f9cd263389cdbee3b249f2a6072af5ebd694eaf2668a515a86abc939e87de007365d9da9c75965cb6bebc94124a941bcd4ce0b598fa7828203688a
@@ -10,7 +10,7 @@ ActiveRecord::ConnectionAdapters::DatabaseStatements.class_eval do
10
10
  begin
11
11
  @test_open_transactions += 1
12
12
  result = yield
13
- rescue ActiveRecord::Rollback => e
13
+ rescue ActiveRecord::Rollback, ActiveRecord::RecordInvalid => e
14
14
  rolled_back = true
15
15
  raise e
16
16
  ensure
@@ -1,3 +1,3 @@
1
1
  module TestAfterCommit
2
- VERSION = '0.2.2'
2
+ VERSION = '0.2.3'
3
3
  end
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.2
4
+ version: 0.2.3
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-10-31 00:00:00.000000000 Z
11
+ date: 2014-03-13 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: michael@grosser.it
@@ -16,27 +16,9 @@ executables: []
16
16
  extensions: []
17
17
  extra_rdoc_files: []
18
18
  files:
19
- - .travis.yml
20
- - Appraisals
21
- - Gemfile
22
- - Gemfile.lock
23
- - Rakefile
24
- - Readme.md
25
- - gemfiles/30.gemfile
26
- - gemfiles/30.gemfile.lock
27
- - gemfiles/31.gemfile
28
- - gemfiles/31.gemfile.lock
29
- - gemfiles/32.gemfile
30
- - gemfiles/32.gemfile.lock
31
- - gemfiles/40.gemfile
32
- - gemfiles/40.gemfile.lock
33
19
  - lib/test_after_commit.rb
34
20
  - lib/test_after_commit/version.rb
35
- - spec/database.rb
36
- - spec/spec_helper.rb
37
- - spec/test_after_commit_spec.rb
38
- - test_after_commit.gemspec
39
- homepage: http://github.com/grosser/test_after_commit
21
+ homepage: https://github.com/grosser/test_after_commit
40
22
  licenses:
41
23
  - MIT
42
24
  metadata: {}
@@ -56,7 +38,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
56
38
  version: '0'
57
39
  requirements: []
58
40
  rubyforge_project:
59
- rubygems_version: 2.0.6
41
+ rubygems_version: 2.0.14
60
42
  signing_key:
61
43
  specification_version: 4
62
44
  summary: makes after_commit callbacks testable in Rails 3+ with transactional_fixtures
data/.travis.yml DELETED
@@ -1,6 +0,0 @@
1
- bundler_args: ""
2
- language: ruby
3
- rvm:
4
- - ree
5
- - 1.9.3
6
- - 2.0.0
data/Appraisals DELETED
@@ -1,18 +0,0 @@
1
- appraise "30" do
2
- gem "activerecord", "~> 3.0.15"
3
- end
4
-
5
- appraise "31" do
6
- gem "activerecord", "~> 3.1.6"
7
- end
8
-
9
- appraise "32" do
10
- gem "activerecord", "~> 3.2.6"
11
- end
12
-
13
- if RUBY_VERSION > "1.9.0"
14
- appraise "40" do
15
- gem "activerecord", "~> 4.0.0.beta1"
16
- gem "rails-observers"
17
- end
18
- end
data/Gemfile DELETED
@@ -1,9 +0,0 @@
1
- source "https://rubygems.org"
2
- gemspec
3
-
4
- gem 'rake'
5
- gem 'bump'
6
- gem 'rspec', '~>2'
7
- gem 'sqlite3'
8
- gem 'appraisal'
9
- gem 'activerecord', :require => 'active_record'
data/Gemfile.lock DELETED
@@ -1,51 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- test_after_commit (0.2.2)
5
-
6
- GEM
7
- remote: https://rubygems.org/
8
- specs:
9
- activemodel (3.2.13)
10
- activesupport (= 3.2.13)
11
- builder (~> 3.0.0)
12
- activerecord (3.2.13)
13
- activemodel (= 3.2.13)
14
- activesupport (= 3.2.13)
15
- arel (~> 3.0.2)
16
- tzinfo (~> 0.3.29)
17
- activesupport (3.2.13)
18
- i18n (= 0.6.1)
19
- multi_json (~> 1.0)
20
- appraisal (0.4.1)
21
- bundler
22
- rake
23
- arel (3.0.2)
24
- builder (3.0.4)
25
- bump (0.3.12)
26
- diff-lcs (1.2.1)
27
- i18n (0.6.1)
28
- multi_json (1.7.2)
29
- rake (0.9.2)
30
- rspec (2.13.0)
31
- rspec-core (~> 2.13.0)
32
- rspec-expectations (~> 2.13.0)
33
- rspec-mocks (~> 2.13.0)
34
- rspec-core (2.13.1)
35
- rspec-expectations (2.13.0)
36
- diff-lcs (>= 1.1.3, < 2.0)
37
- rspec-mocks (2.13.0)
38
- sqlite3 (1.3.6)
39
- tzinfo (0.3.37)
40
-
41
- PLATFORMS
42
- ruby
43
-
44
- DEPENDENCIES
45
- activerecord
46
- appraisal
47
- bump
48
- rake
49
- rspec (~> 2)
50
- sqlite3
51
- test_after_commit!
data/Rakefile DELETED
@@ -1,11 +0,0 @@
1
- require 'bundler/gem_tasks'
2
- require 'appraisal'
3
- require 'bump/tasks'
4
-
5
- task :spec do
6
- sh "rspec spec/"
7
- end
8
-
9
- task :default do
10
- sh "bundle exec rake appraisal:install && bundle exec rake appraisal spec && REAL=1 bundle exec rake appraisal spec"
11
- end
data/Readme.md DELETED
@@ -1,49 +0,0 @@
1
- Make after_commit callbacks fire in tests for Rails 3+ with transactional_fixtures = true.
2
-
3
- Install
4
- =======
5
-
6
- gem install test_after_commit
7
-
8
- # Gemfile (never include in :development !)
9
- gem 'test_after_commit', :group => :test
10
-
11
- Usage
12
- =====
13
- Test that the methods get called or the side-effect of the methods, something like:
14
-
15
- ```Ruby
16
- class Car < ActiveRecord::Base
17
- after_commit :foo, :on => :update
18
-
19
- def foo
20
- $foo = 1
21
- end
22
- end
23
-
24
- ...
25
-
26
- it "sets $foo on commit" do
27
- $foo.should == nil
28
- car.save!
29
- $foo.should == 1
30
- end
31
- ```
32
-
33
- TIPS
34
- ====
35
- - hooks do not re-raise errors (with or without this gem)
36
-
37
- Author
38
- ======
39
-
40
- Inspired by https://gist.github.com/1305285
41
-
42
- ### [Contributors](https://github.com/grosser/test_after_commit/contributors)
43
- - [James Le Cuirot](https://github.com/chewi)
44
- - [emirose](https://github.com/emirose)
45
-
46
- [Michael Grosser](http://grosser.it)<br/>
47
- michael@grosser.it<br/>
48
- License: MIT<br/>
49
- [![Build Status](https://travis-ci.org/grosser/test_after_commit.png)](https://travis-ci.org/grosser/test_after_commit)
data/gemfiles/30.gemfile DELETED
@@ -1,12 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "rake"
6
- gem "bump"
7
- gem "rspec", "~>2"
8
- gem "sqlite3"
9
- gem "appraisal"
10
- gem "activerecord", "~> 3.0.15"
11
-
12
- gemspec :path=>"../"
@@ -1,49 +0,0 @@
1
- PATH
2
- remote: /Users/mgrosser/code/tools/test_after_commit
3
- specs:
4
- test_after_commit (0.2.1)
5
-
6
- GEM
7
- remote: https://rubygems.org/
8
- specs:
9
- activemodel (3.0.16)
10
- activesupport (= 3.0.16)
11
- builder (~> 2.1.2)
12
- i18n (~> 0.5.0)
13
- activerecord (3.0.16)
14
- activemodel (= 3.0.16)
15
- activesupport (= 3.0.16)
16
- arel (~> 2.0.10)
17
- tzinfo (~> 0.3.23)
18
- activesupport (3.0.16)
19
- appraisal (0.4.1)
20
- bundler
21
- rake
22
- arel (2.0.10)
23
- builder (2.1.2)
24
- bump (0.4.0)
25
- diff-lcs (1.1.3)
26
- i18n (0.5.0)
27
- rake (0.9.2.2)
28
- rspec (2.11.0)
29
- rspec-core (~> 2.11.0)
30
- rspec-expectations (~> 2.11.0)
31
- rspec-mocks (~> 2.11.0)
32
- rspec-core (2.11.1)
33
- rspec-expectations (2.11.2)
34
- diff-lcs (~> 1.1.3)
35
- rspec-mocks (2.11.1)
36
- sqlite3 (1.3.6)
37
- tzinfo (0.3.33)
38
-
39
- PLATFORMS
40
- ruby
41
-
42
- DEPENDENCIES
43
- activerecord (~> 3.0.15)
44
- appraisal
45
- bump
46
- rake
47
- rspec (~> 2)
48
- sqlite3
49
- test_after_commit!
data/gemfiles/31.gemfile DELETED
@@ -1,12 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "rake"
6
- gem "bump"
7
- gem "rspec", "~>2"
8
- gem "sqlite3"
9
- gem "appraisal"
10
- gem "activerecord", "~> 3.1.6"
11
-
12
- gemspec :path=>"../"
@@ -1,51 +0,0 @@
1
- PATH
2
- remote: /Users/mgrosser/code/tools/test_after_commit
3
- specs:
4
- test_after_commit (0.2.1)
5
-
6
- GEM
7
- remote: https://rubygems.org/
8
- specs:
9
- activemodel (3.1.7)
10
- activesupport (= 3.1.7)
11
- builder (~> 3.0.0)
12
- i18n (~> 0.6)
13
- activerecord (3.1.7)
14
- activemodel (= 3.1.7)
15
- activesupport (= 3.1.7)
16
- arel (~> 2.2.3)
17
- tzinfo (~> 0.3.29)
18
- activesupport (3.1.7)
19
- multi_json (>= 1.0, < 1.3)
20
- appraisal (0.4.1)
21
- bundler
22
- rake
23
- arel (2.2.3)
24
- builder (3.0.0)
25
- bump (0.4.0)
26
- diff-lcs (1.1.3)
27
- i18n (0.6.0)
28
- multi_json (1.2.0)
29
- rake (0.9.2.2)
30
- rspec (2.11.0)
31
- rspec-core (~> 2.11.0)
32
- rspec-expectations (~> 2.11.0)
33
- rspec-mocks (~> 2.11.0)
34
- rspec-core (2.11.1)
35
- rspec-expectations (2.11.2)
36
- diff-lcs (~> 1.1.3)
37
- rspec-mocks (2.11.1)
38
- sqlite3 (1.3.6)
39
- tzinfo (0.3.33)
40
-
41
- PLATFORMS
42
- ruby
43
-
44
- DEPENDENCIES
45
- activerecord (~> 3.1.6)
46
- appraisal
47
- bump
48
- rake
49
- rspec (~> 2)
50
- sqlite3
51
- test_after_commit!
data/gemfiles/32.gemfile DELETED
@@ -1,12 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "rake"
6
- gem "bump"
7
- gem "rspec", "~>2"
8
- gem "sqlite3"
9
- gem "appraisal"
10
- gem "activerecord", "~> 3.2.6"
11
-
12
- gemspec :path=>"../"
@@ -1,51 +0,0 @@
1
- PATH
2
- remote: /Users/mgrosser/code/tools/test_after_commit
3
- specs:
4
- test_after_commit (0.2.1)
5
-
6
- GEM
7
- remote: https://rubygems.org/
8
- specs:
9
- activemodel (3.2.7)
10
- activesupport (= 3.2.7)
11
- builder (~> 3.0.0)
12
- activerecord (3.2.7)
13
- activemodel (= 3.2.7)
14
- activesupport (= 3.2.7)
15
- arel (~> 3.0.2)
16
- tzinfo (~> 0.3.29)
17
- activesupport (3.2.7)
18
- i18n (~> 0.6)
19
- multi_json (~> 1.0)
20
- appraisal (0.4.1)
21
- bundler
22
- rake
23
- arel (3.0.2)
24
- builder (3.0.0)
25
- bump (0.4.0)
26
- diff-lcs (1.1.3)
27
- i18n (0.6.0)
28
- multi_json (1.3.6)
29
- rake (0.9.2.2)
30
- rspec (2.11.0)
31
- rspec-core (~> 2.11.0)
32
- rspec-expectations (~> 2.11.0)
33
- rspec-mocks (~> 2.11.0)
34
- rspec-core (2.11.1)
35
- rspec-expectations (2.11.2)
36
- diff-lcs (~> 1.1.3)
37
- rspec-mocks (2.11.1)
38
- sqlite3 (1.3.6)
39
- tzinfo (0.3.33)
40
-
41
- PLATFORMS
42
- ruby
43
-
44
- DEPENDENCIES
45
- activerecord (~> 3.2.6)
46
- appraisal
47
- bump
48
- rake
49
- rspec (~> 2)
50
- sqlite3
51
- test_after_commit!
data/gemfiles/40.gemfile DELETED
@@ -1,13 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "rake"
6
- gem "bump"
7
- gem "rspec", "~>2"
8
- gem "sqlite3"
9
- gem "appraisal"
10
- gem "activerecord", "~> 4.0.0.beta1"
11
- gem "rails-observers"
12
-
13
- gemspec :path=>"../"
@@ -1,82 +0,0 @@
1
- PATH
2
- remote: /Users/mgrosser/code/tools/test_after_commit
3
- specs:
4
- test_after_commit (0.2.1)
5
-
6
- GEM
7
- remote: https://rubygems.org/
8
- specs:
9
- actionpack (4.0.0.beta1)
10
- activesupport (= 4.0.0.beta1)
11
- builder (~> 3.1.0)
12
- erubis (~> 2.7.0)
13
- rack (~> 1.5.2)
14
- rack-test (~> 0.6.2)
15
- activemodel (4.0.0.beta1)
16
- activesupport (= 4.0.0.beta1)
17
- builder (~> 3.1.0)
18
- activerecord (4.0.0.beta1)
19
- activemodel (= 4.0.0.beta1)
20
- activerecord-deprecated_finders (~> 0.0.3)
21
- activesupport (= 4.0.0.beta1)
22
- arel (~> 4.0.0.beta1)
23
- activerecord-deprecated_finders (0.0.3)
24
- activesupport (4.0.0.beta1)
25
- i18n (~> 0.6.2)
26
- minitest (~> 4.2)
27
- multi_json (~> 1.3)
28
- thread_safe (~> 0.1)
29
- tzinfo (~> 0.3.33)
30
- appraisal (0.5.1)
31
- bundler
32
- rake
33
- arel (4.0.0.beta2)
34
- atomic (1.0.1)
35
- builder (3.1.4)
36
- bump (0.4.0)
37
- diff-lcs (1.2.1)
38
- erubis (2.7.0)
39
- i18n (0.6.4)
40
- json (1.7.7)
41
- minitest (4.6.2)
42
- multi_json (1.6.1)
43
- rack (1.5.2)
44
- rack-test (0.6.2)
45
- rack (>= 1.0)
46
- rails-observers (0.1.1)
47
- railties (~> 4.0.0.beta)
48
- railties (4.0.0.beta1)
49
- actionpack (= 4.0.0.beta1)
50
- activesupport (= 4.0.0.beta1)
51
- rake (>= 0.8.7)
52
- rdoc (~> 3.4)
53
- thor (>= 0.17.0, < 2.0)
54
- rake (10.0.3)
55
- rdoc (3.12.2)
56
- json (~> 1.4)
57
- rspec (2.13.0)
58
- rspec-core (~> 2.13.0)
59
- rspec-expectations (~> 2.13.0)
60
- rspec-mocks (~> 2.13.0)
61
- rspec-core (2.13.1)
62
- rspec-expectations (2.13.0)
63
- diff-lcs (>= 1.1.3, < 2.0)
64
- rspec-mocks (2.13.0)
65
- sqlite3 (1.3.7)
66
- thor (0.17.0)
67
- thread_safe (0.1.0)
68
- atomic
69
- tzinfo (0.3.37)
70
-
71
- PLATFORMS
72
- ruby
73
-
74
- DEPENDENCIES
75
- activerecord (~> 4.0.0.beta1)
76
- appraisal
77
- bump
78
- rails-observers
79
- rake
80
- rspec (~> 2)
81
- sqlite3
82
- test_after_commit!
data/spec/database.rb DELETED
@@ -1,162 +0,0 @@
1
- # setup database
2
- require 'active_record'
3
-
4
- if ActiveRecord::VERSION::MAJOR > 3
5
- require "rails/observers/activerecord/active_record"
6
- end
7
-
8
- ActiveRecord::Base.establish_connection(
9
- :adapter => 'sqlite3',
10
- :database => ':memory:'
11
- )
12
-
13
- ActiveRecord::Migration.verbose = false
14
-
15
- ActiveRecord::Schema.define(:version => 1) do
16
- create_table "cars", :force => true do |t|
17
- t.integer :counter, :default => 0, :null => false
18
- t.integer :car_id
19
- t.timestamps
20
- end
21
-
22
- create_table "addresses", :force => true do |t|
23
- t.integer :number_of_residents, :default => 0, :null => false
24
- t.timestamps
25
- end
26
-
27
- create_table "people", :force => true do |t|
28
- t.belongs_to :address
29
- t.timestamps
30
- end
31
- end
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
-
44
- class Car < ActiveRecord::Base
45
- extend Called
46
-
47
- has_many :cars
48
-
49
- after_commit :simple_after_commit
50
- after_commit :simple_after_commit_on_create, :on => :create
51
- after_commit :save_once, :on => :create, :if => :do_after_create_save
52
- after_commit :simple_after_commit_on_update, :on => :update
53
- after_commit :maybe_raise_errors
54
-
55
- after_save :trigger_rollback
56
-
57
- attr_accessor :make_rollback, :raise_error, :do_after_create_save
58
-
59
- def trigger_rollback
60
- raise ActiveRecord::Rollback if make_rollback
61
- end
62
-
63
- def self.returning_method_with_transaction
64
- Car.transaction do
65
- return Car.create
66
- end
67
- end
68
-
69
- private
70
-
71
- def save_once
72
- update_attributes(:counter => 3) unless counter == 3
73
- self.class.called :save_once
74
- end
75
-
76
- def maybe_raise_errors
77
- if raise_error
78
- # puts "MAYBE RAISE" # just debugging, but it really does not work ...
79
- raise "Expected error"
80
- end
81
- end
82
-
83
- def simple_after_commit
84
- self.class.called :always
85
- end
86
-
87
- def simple_after_commit_on_create
88
- self.class.called :create
89
- end
90
-
91
- def simple_after_commit_on_update
92
- self.class.called :update
93
- end
94
- end
95
-
96
- class CarObserver < ActiveRecord::Observer
97
- cattr_accessor :recording
98
-
99
- [:after_commit, :after_rollback].each do |action|
100
- define_method action do |record|
101
- return unless recording
102
- Car.called << :observed_after_commit
103
- Untracked.create!
104
- end
105
- end
106
- end
107
-
108
- Car.observers = :car_observer
109
- Car.instantiate_observers
110
-
111
- class Bar < ActiveRecord::Base
112
- self.table_name = "cars"
113
- has_many :bars, :foreign_key => :car_id
114
- end
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
-
133
- class Address < ActiveRecord::Base
134
- has_many :people
135
-
136
- after_commit :create_residents, :on => :create
137
-
138
- def create_residents
139
- if ActiveRecord::VERSION::MAJOR == 3
140
- # stupid hack because nested after_commit is broken on rails 3 and loops
141
- return if @create_residents
142
- @create_residents = true
143
- end
144
-
145
- Person.create!(:address => self)
146
- Person.create!(:address => self)
147
- end
148
- end
149
-
150
- class Person < ActiveRecord::Base
151
- belongs_to :address
152
-
153
- after_commit :update_number_of_residents_on_address, :on => :create
154
-
155
- def update_number_of_residents_on_address
156
- address.update_attributes(:number_of_residents => address.number_of_residents + 1)
157
- end
158
- end
159
-
160
- class Untracked < ActiveRecord::Base
161
- self.table_name = "cars"
162
- end
data/spec/spec_helper.rb DELETED
@@ -1,32 +0,0 @@
1
- $LOAD_PATH.unshift 'lib'
2
- require File.expand_path '../database', __FILE__
3
-
4
- if ENV['REAL']
5
- puts 'using real transactions'
6
- else
7
- require 'test_after_commit'
8
- end
9
-
10
- RSpec.configure do |config|
11
- unless ENV['REAL']
12
- config.around do |example|
13
- # open a transaction without using .transaction as activerecord use_transactional_fixtures does
14
- if ActiveRecord::VERSION::MAJOR > 3
15
- connection = ActiveRecord::Base.connection_handler.connection_pool_list.map(&:connection).first
16
- connection.begin_transaction :joinable => false
17
- else
18
- connection = ActiveRecord::Base.connection_handler.connection_pools.values.map(&:connection).first
19
- connection.increment_open_transactions
20
- connection.transaction_joinable = false
21
- connection.begin_db_transaction
22
- end
23
-
24
- example.call
25
-
26
- connection.rollback_db_transaction
27
- if ActiveRecord::VERSION::MAJOR == 3
28
- connection.decrement_open_transactions
29
- end
30
- end
31
- end
32
- end
@@ -1,126 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe TestAfterCommit do
4
- def rails4?
5
- ActiveRecord::VERSION::MAJOR >= 4
6
- end
7
-
8
- before do
9
- CarObserver.recording = false
10
- Car.called.clear
11
- end
12
-
13
- it "has a VERSION" do
14
- TestAfterCommit::VERSION.should =~ /^[\.\da-z]+$/
15
- end
16
-
17
- it "fires on create" do
18
- Car.create
19
- Car.called.should == [:create, :always]
20
- end
21
-
22
- it "fires on update" do
23
- car = Car.create
24
- Car.called.clear
25
- car.save!
26
- Car.called.should == [:update, :always]
27
- end
28
-
29
- it "fires on update_attribute" do
30
- car = Car.create
31
- Car.called.clear
32
- car.update_attribute :counter, 123
33
- Car.called.should == [:update, :always]
34
- end
35
-
36
- it "does not fire on rollback" do
37
- car = Car.new
38
- car.make_rollback = true
39
- car.save.should == nil
40
- Car.called.should == []
41
- end
42
-
43
- it "does not fire multiple times in nested transactions" do
44
- Car.transaction do
45
- Car.transaction do
46
- Car.create!
47
- Car.called.should == []
48
- end
49
- Car.called.should == []
50
- end
51
- Car.called.should == [:create, :always]
52
- end
53
-
54
- it "fires when transaction block returns from method" do
55
- Car.returning_method_with_transaction
56
- Car.called.should == [:create, :always]
57
- end
58
-
59
- it "does not raises errors" do
60
- car = Car.new
61
- car.raise_error = true
62
- car.save!
63
- end
64
-
65
- it "can do 1 save in after_commit" do
66
- if !ENV['REAL']
67
- pending "this results in infinite loop in REAL mode except on 4.0 but works in tests except for rails 3.0"
68
- end
69
-
70
- car = Car.new
71
- car.do_after_create_save = true
72
- car.save!
73
-
74
- expected = if rails4?
75
- [:update, :always, :save_once, :always] # some kind of loop prevention ... investigate we must
76
- else
77
- [:save_once, :create, :always, :save_once, :create, :always]
78
- end
79
- Car.called.should == expected
80
- car.counter.should == 3
81
- end
82
-
83
- it "returns on create and on create of associations" do
84
- Car.create!.class.should == Car
85
- Car.create!.cars.create.class.should == (rails4? ? NilClass : Car)
86
- end
87
-
88
- it "returns on create and on create of associations without after_commit" do
89
- Bar.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]
96
- end
97
-
98
- context "Observer" do
99
- before do
100
- CarObserver.recording = true
101
- end
102
-
103
- it "should record commits" do
104
- Car.transaction do
105
- Car.create
106
- end
107
- Car.called.should == [:observed_after_commit, :create, :always]
108
- end
109
- end
110
-
111
- context "nested after_commit" do
112
- before do
113
- @address = Address.create!
114
- end
115
-
116
- it 'is executed' do
117
- pending unless ENV["REAL"] && ActiveRecord::VERSION::MAJOR == 4
118
- lambda { Person.create!(:address => @address) }.should change(@address, :number_of_residents).by(1)
119
-
120
- # one from the line above and two from the after_commit
121
- @address.people.count.should == 3
122
-
123
- @address.number_of_residents.should == 3
124
- end
125
- end
126
- end
@@ -1,12 +0,0 @@
1
- $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
2
- name = "test_after_commit"
3
- require "#{name}/version"
4
-
5
- Gem::Specification.new name, TestAfterCommit::VERSION do |s|
6
- s.summary = "makes after_commit callbacks testable in Rails 3+ with transactional_fixtures"
7
- s.authors = ["Michael Grosser"]
8
- s.email = "michael@grosser.it"
9
- s.homepage = "http://github.com/grosser/#{name}"
10
- s.files = `git ls-files`.split("\n")
11
- s.license = 'MIT'
12
- end