prefactory 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/.rvmrc +1 -0
- data/.travis.yml +8 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +114 -0
- data/Rakefile +11 -0
- data/lib/prefactory.rb +24 -0
- data/lib/prefactory/active_record_integration.rb +112 -0
- data/lib/prefactory/version.rb +25 -0
- data/lib/rspec/core/prefactory.rb +159 -0
- data/prefactory.gemspec +39 -0
- data/spec/database.yml +10 -0
- data/spec/database_setup.rb +73 -0
- data/spec/prefactory_spec.rb +267 -0
- data/spec/spec_helper.rb +53 -0
- data/spec/support/callback_matcher.rb +109 -0
- data/spec/transaction_spec.rb +163 -0
- metadata +180 -0
@@ -0,0 +1,163 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# Copyright (c) 2014, VMware, Inc. All Rights Reserved.
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
# of this software and associated documentation files (the "Software"), to deal
|
7
|
+
# in the Software without restriction, including without limitation the rights to
|
8
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
9
|
+
# of the Software, and to permit persons to whom the Software is furnished to do
|
10
|
+
# so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included in all
|
13
|
+
# copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
# SOFTWARE.
|
22
|
+
|
23
|
+
require 'spec_helper'
|
24
|
+
|
25
|
+
describe "WithDisposableTransactionExtension#with_disposable_transaction" do
|
26
|
+
let!(:blog) { Blog.create! :title => 'foo' }
|
27
|
+
it "runs a transaction and rolls it back" do
|
28
|
+
previous_open_transaction_count = Blog.connection.open_transactions
|
29
|
+
Blog.with_disposable_transaction do
|
30
|
+
blog.update_attributes! :title => 'bar'
|
31
|
+
blog.reload.title.should == 'bar'
|
32
|
+
Blog.connection.open_transactions.should == previous_open_transaction_count + 1
|
33
|
+
end
|
34
|
+
blog.reload.title.should == 'foo'
|
35
|
+
Blog.connection.open_transactions.should == previous_open_transaction_count
|
36
|
+
end
|
37
|
+
it "preserves the return value" do
|
38
|
+
result = Blog.with_disposable_transaction do
|
39
|
+
1
|
40
|
+
end
|
41
|
+
result.should == 1
|
42
|
+
end
|
43
|
+
it "raises any StandardError occuring in the block" do
|
44
|
+
expect do
|
45
|
+
Blog.with_disposable_transaction do
|
46
|
+
raise "Example Error"
|
47
|
+
end
|
48
|
+
end.to raise_error("Example Error")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "Transactional wrapping" do
|
53
|
+
shared_examples_for "synthetic after_commit" do
|
54
|
+
it "calls after_commit hooks at this open transaction level, but not above" do
|
55
|
+
blog = Blog.create! :title => 'foo'
|
56
|
+
blog.called_after_commit.should == 1
|
57
|
+
blog.reload.title.should == 'foo'
|
58
|
+
|
59
|
+
blog.update_attributes! :title => 'bar'
|
60
|
+
blog.called_after_commit.should == 2
|
61
|
+
blog.reload.title.should == 'bar'
|
62
|
+
|
63
|
+
ActiveRecord::Base.connection.transaction(:requires_new => true) do
|
64
|
+
blog.update_attributes! :title => 'quux'
|
65
|
+
blog.called_after_commit.should == 2
|
66
|
+
end
|
67
|
+
blog.reload.title.should == 'quux'
|
68
|
+
|
69
|
+
blog.called_after_commit.should == 3
|
70
|
+
ActiveRecord::Base.connection.transaction(:requires_new => true) do
|
71
|
+
blog.update_attributes! :title => 'ragz'
|
72
|
+
blog.called_after_commit.should == 3
|
73
|
+
raise ActiveRecord::Rollback
|
74
|
+
end
|
75
|
+
blog.called_after_commit.should == 3
|
76
|
+
blog.reload.title.should == 'quux'
|
77
|
+
end
|
78
|
+
|
79
|
+
it "does not call after_commit hooks when an error is raised" do
|
80
|
+
blog = Blog.create! :title => 'foo'
|
81
|
+
blog.called_after_commit.should == 1
|
82
|
+
|
83
|
+
# raise the level at which a synthetic commit should take place
|
84
|
+
Blog.with_disposable_transaction do
|
85
|
+
blog.update_attributes! :title => 'ragz'
|
86
|
+
blog.called_after_commit.should == 2
|
87
|
+
end
|
88
|
+
|
89
|
+
# raise the level at which a synthetic commit should take place
|
90
|
+
Blog.with_disposable_transaction do
|
91
|
+
expect do
|
92
|
+
ActiveRecord::Base.connection.transaction(:requires_new => true) do
|
93
|
+
blog.update_attributes! :title => 'ragz'
|
94
|
+
blog.called_after_commit.should == 2
|
95
|
+
raise "Something blows up"
|
96
|
+
end
|
97
|
+
end.to raise_error("Something blows up")
|
98
|
+
blog.called_after_commit.should == 2
|
99
|
+
blog.reload.title.should == 'foo'
|
100
|
+
end
|
101
|
+
|
102
|
+
blog.called_after_commit.should == 2
|
103
|
+
blog.reload.title.should == 'foo'
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
|
108
|
+
it "wraps describe blocks in a savepoint transaction" do
|
109
|
+
ActiveRecord::Base.connection.current_transaction.should be_a ActiveRecord::ConnectionAdapters::SavepointTransaction
|
110
|
+
end
|
111
|
+
it "wrapped the suite before this describe block" do
|
112
|
+
ActiveRecord::Base.connection.open_transactions.should == 2
|
113
|
+
end
|
114
|
+
it "considers this level as commitable" do
|
115
|
+
ActiveRecord::Base.connection.commit_at_open_transaction_level.should == 2
|
116
|
+
end
|
117
|
+
it "does not consider a nested transaction to be commitable" do
|
118
|
+
ActiveRecord::Base.connection.transaction(:requires_new => true) do
|
119
|
+
ActiveRecord::Base.connection.open_transactions.should == 3
|
120
|
+
ActiveRecord::Base.connection.commit_at_open_transaction_level.should == 2
|
121
|
+
end
|
122
|
+
end
|
123
|
+
it_behaves_like "synthetic after_commit"
|
124
|
+
|
125
|
+
[:describe, :context].each do |nesting_method|
|
126
|
+
send(nesting_method, "with a nested #{nesting_method}") do
|
127
|
+
it "is wrapped in in a new savepoint transaction" do
|
128
|
+
ActiveRecord::Base.connection.current_transaction.should be_a ActiveRecord::ConnectionAdapters::SavepointTransaction
|
129
|
+
ActiveRecord::Base.connection.open_transactions.should == 3
|
130
|
+
end
|
131
|
+
it "considers this level as commitable" do
|
132
|
+
ActiveRecord::Base.connection.commit_at_open_transaction_level.should == 3
|
133
|
+
end
|
134
|
+
it "does not consider a nested transaction to be commitable" do
|
135
|
+
ActiveRecord::Base.connection.transaction(:requires_new => true) do
|
136
|
+
ActiveRecord::Base.connection.open_transactions.should == 4
|
137
|
+
ActiveRecord::Base.connection.commit_at_open_transaction_level.should == 3
|
138
|
+
end
|
139
|
+
end
|
140
|
+
it_behaves_like "synthetic after_commit"
|
141
|
+
|
142
|
+
[:describe, :context].each do |nesting_method|
|
143
|
+
send(nesting_method, "with a nested #{nesting_method}") do
|
144
|
+
it "is wrapped in in a new savepoint transaction" do
|
145
|
+
ActiveRecord::Base.connection.current_transaction.should be_a ActiveRecord::ConnectionAdapters::SavepointTransaction
|
146
|
+
ActiveRecord::Base.connection.open_transactions.should == 4
|
147
|
+
end
|
148
|
+
it "considers this level as commitable" do
|
149
|
+
ActiveRecord::Base.connection.commit_at_open_transaction_level.should == 4
|
150
|
+
end
|
151
|
+
it "does not consider a nested transaction to be commitable" do
|
152
|
+
ActiveRecord::Base.connection.transaction(:requires_new => true) do
|
153
|
+
ActiveRecord::Base.connection.open_transactions.should == 5
|
154
|
+
ActiveRecord::Base.connection.commit_at_open_transaction_level.should == 4
|
155
|
+
end
|
156
|
+
end
|
157
|
+
it_behaves_like "synthetic after_commit"
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
metadata
ADDED
@@ -0,0 +1,180 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: prefactory
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- developers@socialcast.com
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec_around_all
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activerecord
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '4'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: factory_girl_rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '4'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '4'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: mysql2
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.3'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.3'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: sqlite3
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: bundler
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rake
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '10.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '10.0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: socialcast-git-extensions
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '3'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '3'
|
125
|
+
description: Create factory objects in before-all blocks for fixture-like performance
|
126
|
+
email:
|
127
|
+
- developers@socialcast.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- ".gitignore"
|
133
|
+
- ".rvmrc"
|
134
|
+
- ".travis.yml"
|
135
|
+
- Gemfile
|
136
|
+
- LICENSE.txt
|
137
|
+
- README.md
|
138
|
+
- Rakefile
|
139
|
+
- lib/prefactory.rb
|
140
|
+
- lib/prefactory/active_record_integration.rb
|
141
|
+
- lib/prefactory/version.rb
|
142
|
+
- lib/rspec/core/prefactory.rb
|
143
|
+
- prefactory.gemspec
|
144
|
+
- spec/database.yml
|
145
|
+
- spec/database_setup.rb
|
146
|
+
- spec/prefactory_spec.rb
|
147
|
+
- spec/spec_helper.rb
|
148
|
+
- spec/support/callback_matcher.rb
|
149
|
+
- spec/transaction_spec.rb
|
150
|
+
homepage: https://github.socialcast.com/prefactory
|
151
|
+
licenses:
|
152
|
+
- MIT
|
153
|
+
metadata: {}
|
154
|
+
post_install_message:
|
155
|
+
rdoc_options: []
|
156
|
+
require_paths:
|
157
|
+
- lib
|
158
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
159
|
+
requirements:
|
160
|
+
- - ">="
|
161
|
+
- !ruby/object:Gem::Version
|
162
|
+
version: '0'
|
163
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
164
|
+
requirements:
|
165
|
+
- - ">="
|
166
|
+
- !ruby/object:Gem::Version
|
167
|
+
version: '0'
|
168
|
+
requirements: []
|
169
|
+
rubyforge_project:
|
170
|
+
rubygems_version: 2.2.2
|
171
|
+
signing_key:
|
172
|
+
specification_version: 4
|
173
|
+
summary: Transaction-wrapped RSpec example groups with FactoryGirl integration
|
174
|
+
test_files:
|
175
|
+
- spec/database.yml
|
176
|
+
- spec/database_setup.rb
|
177
|
+
- spec/prefactory_spec.rb
|
178
|
+
- spec/spec_helper.rb
|
179
|
+
- spec/support/callback_matcher.rb
|
180
|
+
- spec/transaction_spec.rb
|