test_seeds 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,23 @@
1
+ source "http://rubygems.org"
2
+
3
+ group :development do
4
+ gem "jeweler", "~> 1.6.4"
5
+ gem "rake"
6
+
7
+ gem 'mysql2', '< 0.3'
8
+
9
+ activerecord_version = ENV['ACTIVERECORD_VERSION']
10
+
11
+ if activerecord_version == "edge"
12
+ git "git://github.com/rails/rails.git" do
13
+ gem "activerecord"
14
+ gem "activesupport"
15
+ end
16
+ elsif activerecord_version && activerecord_version.strip != ""
17
+ gem "activerecord", activerecord_version
18
+ else
19
+ gem "activerecord", "~> 3.0.0"
20
+ end
21
+
22
+ end
23
+
data/Gemfile.lock ADDED
@@ -0,0 +1,33 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activemodel (3.0.9)
5
+ activesupport (= 3.0.9)
6
+ builder (~> 2.1.2)
7
+ i18n (~> 0.5.0)
8
+ activerecord (3.0.9)
9
+ activemodel (= 3.0.9)
10
+ activesupport (= 3.0.9)
11
+ arel (~> 2.0.10)
12
+ tzinfo (~> 0.3.23)
13
+ activesupport (3.0.9)
14
+ arel (2.0.10)
15
+ builder (2.1.2)
16
+ git (1.2.5)
17
+ i18n (0.5.0)
18
+ jeweler (1.6.4)
19
+ bundler (~> 1.0)
20
+ git (>= 1.2.5)
21
+ rake
22
+ mysql2 (0.2.6)
23
+ rake (0.9.2)
24
+ tzinfo (0.3.29)
25
+
26
+ PLATFORMS
27
+ ruby
28
+
29
+ DEPENDENCIES
30
+ activerecord (~> 3.0.0)
31
+ jeweler (~> 1.6.4)
32
+ mysql2 (< 0.3)
33
+ rake
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Paul Kmiec
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,141 @@
1
+ = test_seeds
2
+
3
+ Test Seeds allow efficient usage of object factories (like Factory Girl) in tests. Instead of creating objects for similar scenarios in each test case, Test Seeds start a db transaction for each test file, create all the common objects once, and then uses db savepoints for each test case allowing for the common objects to be re-used.
4
+
5
+ == Description
6
+
7
+ Fixtures are a great way to get started. However, as your application becomes more complex, fixtures become a nightmare to manage and maintain. To alleviate this problem, people have flocked to object factories which allow creating complex testing scenarios right next to the code that tests those scenarios. Often similar scenarios are needed for a set of tests and the following pattern emerges,
8
+
9
+ class TestSomething < ActiveSupport::TestCase
10
+ setup :create_scenario
11
+
12
+ def create_scenario
13
+ @object_1 = ...create AR objects...
14
+ @object_2 = ...create AR objects...
15
+ @object_3 = ...create AR objects...
16
+ end
17
+
18
+ def test_case_1
19
+ end
20
+
21
+ ...
22
+
23
+
24
+ def test_case_N
25
+ end
26
+
27
+ end
28
+
29
+ Sometimes creating the scenario in the setup callback, create_scenario is called by tests directly as needed. Either way, the problem is that create_scenario is called multiple times and creating objects via ActiveRecord is very slow. Test Seeds addresses this problem.
30
+
31
+ == How It Works
32
+
33
+ Transactional fixtures work as follows,
34
+
35
+ test file do
36
+ load fixtures
37
+ transaction do
38
+ test case 1
39
+ end
40
+ transaction do
41
+ test case 2
42
+ end
43
+ transaction do
44
+ test case 3
45
+ end
46
+ end
47
+
48
+
49
+ Test Seeds piggy backs on the transaction fixtures functionality. Test Seeds load fixtures into the database in the same way but then start a db transaction for the duration of the test file. Any objects for the common scenarios are then created and inserted into the database. Test Seeds then execute each test case within a context of a db savepoint (or nested db transactions). This allows test seeds to be inserted into the database once and then re-used for each test case that needs it. Here is the pseudo code,
50
+
51
+ test file do
52
+ load fixtures
53
+ transaction do
54
+ load seeds
55
+ savepoint do
56
+ test case 1
57
+ end
58
+ savepoint do
59
+ test case 2
60
+ end
61
+ savepoint do
62
+ test case 3
63
+ end
64
+ end
65
+ end
66
+
67
+ == How To Use
68
+
69
+ There are two main ways of using Test Seeds. The first way makes all the seeds available to all the tests,
70
+
71
+ class TestSomething < ActiveSupport::TestCase
72
+ include TestSeeds
73
+
74
+ seeds do
75
+ @object_1 = ...create AR objects...
76
+ @object_2 = ...create AR objects...
77
+ @object_3 = ...create AR objects...
78
+ end
79
+
80
+ def test_case_1
81
+ # @object_1, @object_2, and @object_3 are available here
82
+ end
83
+
84
+ ...
85
+
86
+
87
+ def test_case_N
88
+ # @object_1, @object_2, and @object_3 are available here
89
+ end
90
+
91
+ end
92
+
93
+ Alternatively, you can be more selective which seeds go with which test cases,
94
+
95
+ class TestSomething < ActiveSupport::TestCase
96
+ include TestSeeds
97
+
98
+ seeds(:scenario_a) do
99
+ @object_a1 = ...create AR objects...
100
+ @object_a2 = ...create AR objects...
101
+ @object_a3 = ...create AR objects...
102
+ end
103
+
104
+ seeds(:scenario_b) do
105
+ @object_b1 = ...create AR objects...
106
+ @object_b2 = ...create AR objects...
107
+ @object_b3 = ...create AR objects...
108
+ end
109
+
110
+ def test_case_1
111
+ setup_seeds(:scenario_a)
112
+ # @object_a1, @object_a2, and @object_a3 are available here
113
+ end
114
+
115
+ def test_case_2
116
+ setup_seeds(:scenario_b)
117
+ # @object_b1, @object_b2, and @object_b3 are available here
118
+ end
119
+
120
+ def test_case_3
121
+ setup_seeds(:scenario_a, :scenario_b)
122
+ # @object_a1, @object_a2, and @object_a3 are available here
123
+ # @object_b1, @object_b2, and @object_b3 are available here
124
+ end
125
+
126
+ end
127
+
128
+ == Contributing to test_seeds
129
+
130
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
131
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
132
+ * Fork the project
133
+ * Start a feature/bugfix branch
134
+ * Commit and push until you are happy with your contribution
135
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
136
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
137
+
138
+ == Copyright
139
+
140
+ Copyright (c) 2011 Paul Kmiec. See LICENSE.txt for further details.
141
+
data/Rakefile ADDED
@@ -0,0 +1,35 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "test_seeds"
18
+ gem.homepage = "http://github.com/pkmiec/test_seeds"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Test Seeds allow efficient usage of object factories (like Factory Girl) in tests. Instead of creating objects for similar scenarios in each test case, Test Seeds start a db transaction for each test file, creates all the common objects once, and then uses db savepoints for each test case.}
21
+ gem.description = %Q{Test Seeds piggy backs on the transaction fixtures functionality. Test Seeds load fixtures into the database in the same way but then start a db transaction for the duration of the test file. Any objects for the common scenarios are then created and inserted into the database. Test Seeds then execute each test case within a context of a db savepoint (or nested db transactions). This allows test seeds to be inserted into the database once and then re-used for each test case that needs it.}
22
+ gem.email = "pkmiec@gmail.com"
23
+ gem.authors = ["Paul Kmiec"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ task :default => :test
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
data/lib/test_seeds.rb ADDED
@@ -0,0 +1,169 @@
1
+ require 'active_support'
2
+ require 'active_record'
3
+ require 'active_record/fixtures'
4
+
5
+ module TestSeeds
6
+
7
+ class SeedFixture < ActiveRecord.const_defined?(:Fixture) ? ActiveRecord::Fixture : Fixture
8
+
9
+ # Override find to call find with exclusive scope. Shouldn't fixtures do that already?
10
+ def find
11
+ if model_class
12
+ model_class.send(:with_exclusive_scope) do
13
+ model_class.find(@fixture[model_class.primary_key])
14
+ end
15
+ else
16
+ raise FixtureClassNotFound, "No class attached to find."
17
+ end
18
+ end
19
+
20
+ end
21
+
22
+ extend ActiveSupport::Concern
23
+
24
+ included do
25
+ include ActiveSupport::Callbacks
26
+ define_callbacks :seed
27
+ end
28
+
29
+ module ClassMethods
30
+ def seeds(name = nil, &block)
31
+ set_callback(:seed, :before) do
32
+ pre_vars = self.instance_variables
33
+ self.instance_eval &block
34
+ post_vars = self.instance_variables
35
+
36
+ (post_vars - pre_vars).each do |seed_var|
37
+ seed_accessor = self.set_seed_fixture(seed_var.to_s[1..-1], self.instance_variable_get(seed_var))
38
+ self.instance_variable_set(seed_var, nil) # avoid memory bloat
39
+
40
+ defined_seeds = self.class.defined_seeds
41
+ defined_seeds[name] ||= {}
42
+ defined_seeds[name][seed_var] = seed_accessor
43
+ end
44
+
45
+ end
46
+ end
47
+
48
+ def defined_seeds
49
+ @defined_seeds ||= {}
50
+ end
51
+
52
+ end
53
+
54
+ # Re-implement setup_fixtures to use save points instead of transactions.
55
+ def setup_fixtures
56
+ return unless defined?(ActiveRecord) && !ActiveRecord::Base.configurations.blank?
57
+
58
+ if pre_loaded_fixtures && !use_transactional_fixtures
59
+ raise RuntimeError, 'pre_loaded_fixtures requires use_transactional_fixtures'
60
+ end
61
+
62
+ @fixture_cache = {}
63
+ @@already_loaded_fixtures ||= {}
64
+
65
+ @loaded_seeds = []
66
+
67
+ if run_in_transaction?
68
+ if @@already_loaded_fixtures[self.class]
69
+ @loaded_fixtures = @@already_loaded_fixtures[self.class]
70
+ else
71
+ @loaded_fixtures = load_fixtures
72
+ @@already_loaded_fixtures[self.class] = @loaded_fixtures
73
+ end
74
+
75
+ # Use safe points
76
+ ActiveRecord::Base.connection.create_savepoint
77
+ ActiveRecord::Base.connection.increment_open_transactions
78
+ ActiveRecord::Base.connection.transaction_joinable = false
79
+ @created_save_point = true
80
+
81
+ setup_seeds(nil)
82
+ else
83
+ Fixtures.reset_cache
84
+ @@already_loaded_fixtures[self.class] = nil
85
+ @loaded_fixtures = load_fixtures
86
+ end
87
+
88
+ instantiate_fixtures if use_instantiated_fixtures
89
+ end
90
+
91
+ # Re-implement setup_fixtures to use save points instead of transactions.
92
+ def teardown_fixtures
93
+ teardown_seeds(*@loaded_seeds)
94
+
95
+ return unless defined?(ActiveRecord) && !ActiveRecord::Base.configurations.blank?
96
+
97
+ unless run_in_transaction?
98
+ Fixtures.reset_cache
99
+ end
100
+
101
+ if run_in_transaction? && @created_save_point
102
+ # Use safe points
103
+ ActiveRecord::Base.connection.decrement_open_transactions
104
+ ActiveRecord::Base.connection.rollback_to_savepoint
105
+ @created_save_point = false
106
+ end
107
+ ActiveRecord::Base.clear_active_connections!
108
+ end
109
+
110
+ # Load fixture is called once for each test class which is a good place to inject db transactions
111
+ # and to create the seeds.
112
+ def load_fixtures
113
+ if run_in_transaction? && ActiveRecord::Base.connection.open_transactions != 0
114
+ ActiveRecord::Base.connection.decrement_open_transactions
115
+ ActiveRecord::Base.connection.rollback_db_transaction
116
+ end
117
+ ActiveRecord::Base.clear_active_connections!
118
+
119
+ # In Rails 3.0.x, load_fixtures sets the @loades_fixtures instance variable. In Rails 3.1, load_fixtures returns the
120
+ # fixtures which are then assigned to @loaded_fixtures by the caller. The following line ensures compability with
121
+ # Rails 3.1.
122
+ result = super
123
+ @loaded_fixtures = result if result.is_a? Hash
124
+
125
+ if run_in_transaction?
126
+ ActiveRecord::Base.connection.begin_db_transaction
127
+ ActiveRecord::Base.connection.increment_open_transactions
128
+ ActiveRecord::Base.connection.transaction_joinable = false
129
+ end
130
+
131
+ load_seed_fixtures
132
+
133
+ @loaded_fixtures
134
+ end
135
+
136
+ def setup_seeds(*seeds)
137
+ seeds.each do |seed|
138
+ (self.class.defined_seeds[seed] || []).each do |seed_var, seed_accessor|
139
+ instance_variable_set(seed_var, send(*seed_accessor))
140
+ end
141
+ @loaded_seeds << seed
142
+ end
143
+ end
144
+
145
+ def teardown_seeds(*seeds)
146
+ seeds.each do |seed|
147
+ (self.class.defined_seeds[seed] || []).each do |seed_var, seed_accessor|
148
+ instance_variable_set(seed_var, nil)
149
+ end
150
+ @loaded_seeds.delete(seed)
151
+ end
152
+ end
153
+
154
+ def set_seed_fixture(seed_name, seed_model)
155
+ raise "Seed fixture must be an instance of ActiveRecord::Base" unless seed_model.is_a? ActiveRecord::Base
156
+
157
+ seed_class = seed_model.class
158
+ fixture = { seed_class.primary_key => seed_model.send(seed_class.primary_key) }
159
+ @loaded_fixtures[seed_class.table_name][seed_name.to_s] = SeedFixture.new(fixture, seed_class)
160
+
161
+ [ seed_class.table_name, seed_name.to_sym ]
162
+ end
163
+
164
+ def load_seed_fixtures
165
+ ActiveRecord::Base.connection.transaction(:requires_new => true) do
166
+ _run_seed_callbacks
167
+ end
168
+ end
169
+ end
@@ -0,0 +1,3 @@
1
+ actual_fixture:
2
+ id: 1
3
+ name: "Bob Dole"
data/test/helper.rb ADDED
@@ -0,0 +1,52 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+
12
+ require 'active_support'
13
+ require 'active_record'
14
+ require 'active_record/fixtures'
15
+
16
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
17
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
18
+ require 'test_seeds'
19
+
20
+ ActiveRecord::Base.logger = Logger.new("debug.log")
21
+
22
+ # Re-create test database
23
+ `mysql -uroot -e "DROP DATABASE IF EXISTS test_test_seeds; CREATE DATABASE IF NOT EXISTS test_test_seeds;"`
24
+
25
+ # Define connection configuration
26
+ ActiveRecord::Base.configurations = {
27
+ 'test_test_seeds' => {
28
+ :adapter => 'mysql2',
29
+ :username => 'root',
30
+ :encoding => 'utf8',
31
+ :database => 'test_test_seeds',
32
+ }
33
+ }
34
+ ActiveRecord::Base.establish_connection 'test_test_seeds'
35
+
36
+ # Define schema
37
+ ActiveRecord::Schema.define do
38
+
39
+ create_table :authors, :force => true do |t|
40
+ t.string :name
41
+ end
42
+
43
+ end
44
+
45
+ class Author < ActiveRecord::Base
46
+ end
47
+
48
+ class ActiveSupport::TestCase
49
+ include ActiveRecord::TestFixtures
50
+ end
51
+
52
+ ActiveSupport::TestCase.fixture_path = File.join(File.dirname(__FILE__), 'fixtures')
@@ -0,0 +1,10 @@
1
+ source "http://rubygems.org"
2
+
3
+ group :development do
4
+ gem "jeweler", "~> 1.6.4"
5
+ gem "rake"
6
+
7
+ gem 'mysql2', '0.2.6'
8
+ gem 'activerecord', "3.0.9"
9
+ end
10
+
@@ -0,0 +1,33 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activemodel (3.0.9)
5
+ activesupport (= 3.0.9)
6
+ builder (~> 2.1.2)
7
+ i18n (~> 0.5.0)
8
+ activerecord (3.0.9)
9
+ activemodel (= 3.0.9)
10
+ activesupport (= 3.0.9)
11
+ arel (~> 2.0.10)
12
+ tzinfo (~> 0.3.23)
13
+ activesupport (3.0.9)
14
+ arel (2.0.10)
15
+ builder (2.1.2)
16
+ git (1.2.5)
17
+ i18n (0.5.0)
18
+ jeweler (1.6.4)
19
+ bundler (~> 1.0)
20
+ git (>= 1.2.5)
21
+ rake
22
+ mysql2 (0.2.6)
23
+ rake (0.9.2)
24
+ tzinfo (0.3.29)
25
+
26
+ PLATFORMS
27
+ ruby
28
+
29
+ DEPENDENCIES
30
+ activerecord (= 3.0.9)
31
+ jeweler (~> 1.6.4)
32
+ mysql2 (= 0.2.6)
33
+ rake
@@ -0,0 +1,10 @@
1
+ source "http://rubygems.org"
2
+
3
+ group :development do
4
+ gem "jeweler", "~> 1.6.4"
5
+ gem "rake"
6
+
7
+ gem 'mysql2', '0.3.6'
8
+ gem 'activerecord', "3.1.0.rc5"
9
+ end
10
+
@@ -0,0 +1,37 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activemodel (3.1.0.rc5)
5
+ activesupport (= 3.1.0.rc5)
6
+ bcrypt-ruby (~> 2.1.4)
7
+ builder (~> 3.0.0)
8
+ i18n (~> 0.6)
9
+ activerecord (3.1.0.rc5)
10
+ activemodel (= 3.1.0.rc5)
11
+ activesupport (= 3.1.0.rc5)
12
+ arel (~> 2.1.4)
13
+ tzinfo (~> 0.3.29)
14
+ activesupport (3.1.0.rc5)
15
+ multi_json (~> 1.0)
16
+ arel (2.1.4)
17
+ bcrypt-ruby (2.1.4)
18
+ builder (3.0.0)
19
+ git (1.2.5)
20
+ i18n (0.6.0)
21
+ jeweler (1.6.4)
22
+ bundler (~> 1.0)
23
+ git (>= 1.2.5)
24
+ rake
25
+ multi_json (1.0.3)
26
+ mysql2 (0.3.6)
27
+ rake (0.9.2)
28
+ tzinfo (0.3.29)
29
+
30
+ PLATFORMS
31
+ ruby
32
+
33
+ DEPENDENCIES
34
+ activerecord (= 3.1.0.rc5)
35
+ jeweler (~> 1.6.4)
36
+ mysql2 (= 0.3.6)
37
+ rake
@@ -0,0 +1,77 @@
1
+ require 'helper'
2
+
3
+ class TestTestSeeds < ActiveSupport::TestCase
4
+ include TestSeeds
5
+
6
+ fixtures :authors
7
+
8
+ seeds do
9
+ @default_1 = Author.create!(:name => 'default first')
10
+ @default_2 = Author.create!(:name => 'default second')
11
+ end
12
+
13
+ seeds(:foo) do
14
+ @foo_1 = Author.create!(:name => 'foo first')
15
+ @foo_2 = Author.create!(:name => 'foo second')
16
+ end
17
+
18
+ def test_default_seeds
19
+ assert_not_nil @default_1
20
+ assert_equal "default first", @default_1.name
21
+
22
+ assert_not_nil @default_2
23
+ assert_equal "default second", @default_2.name
24
+
25
+ assert_nil @foo_1
26
+ assert_nil @foo_2
27
+ end
28
+
29
+ def test_setup_and_teardown
30
+ assert_not_nil @default_1
31
+ assert_not_nil @default_2
32
+
33
+ setup_seeds(:foo)
34
+
35
+ assert_not_nil @default_1
36
+ assert_not_nil @default_2
37
+
38
+ assert_not_nil @foo_1
39
+ assert_equal "foo first", @foo_1.name
40
+
41
+ assert_not_nil @foo_2
42
+ assert_equal "foo second", @foo_2.name
43
+
44
+ teardown_seeds(:foo)
45
+
46
+ assert_nil @foo_1
47
+ assert_nil @foo_2
48
+ assert_not_nil @default_1
49
+ assert_not_nil @default_2
50
+ end
51
+
52
+ def test_set_seed_fixture
53
+ author = Author.create!(:name => 'tolkien')
54
+ assert_equal ["authors", :tolkien], set_seed_fixture("tolkien", author)
55
+ assert_equal author, authors(:tolkien)
56
+ end
57
+
58
+ def test_set_seed_fixture__expects_active_record
59
+ assert_raises(RuntimeError) do
60
+ set_seed_fixture("hmm", Object.new)
61
+ end
62
+ end
63
+
64
+ def test_does_not_interfere_with_actual_fixtures
65
+ assert_not_nil authors(:actual_fixture)
66
+ assert_equal "Bob Dole", authors(:actual_fixture).name
67
+ end
68
+
69
+ end
70
+
71
+ class TestTestSeedsWithoutSeedSet < ActiveSupport::TestCase
72
+ include TestSeeds
73
+
74
+ def test_does_not_blow_up_when_test_seeds_is_not_used
75
+ assert true
76
+ end
77
+ end
data/test_all.sh ADDED
@@ -0,0 +1,14 @@
1
+ #!/bin/sh
2
+
3
+ set -e
4
+
5
+ versions="rails_3_0 rails_3_1"
6
+
7
+ for version in $versions
8
+ do
9
+ echo "Running BUNDLE_GEMFILE=test/${version} bundle exec rake..."
10
+ BUNDLE_GEMFILE=test/${version}/Gemfile bundle install
11
+ BUNDLE_GEMFILE=test/${version}/Gemfile bundle exec rake
12
+ done
13
+
14
+ echo 'Success!'
@@ -0,0 +1,65 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{test_seeds}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = [%q{Paul Kmiec}]
12
+ s.date = %q{2011-08-16}
13
+ s.description = %q{Test Seeds piggy backs on the transaction fixtures functionality. Test Seeds load fixtures into the database in the same way but then start a db transaction for the duration of the test file. Any objects for the common scenarios are then created and inserted into the database. Test Seeds then execute each test case within a context of a db savepoint (or nested db transactions). This allows test seeds to be inserted into the database once and then re-used for each test case that needs it.}
14
+ s.email = %q{pkmiec@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE.txt",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "lib/test_seeds.rb",
28
+ "test/fixtures/authors.yml",
29
+ "test/helper.rb",
30
+ "test/rails_3_0/Gemfile",
31
+ "test/rails_3_0/Gemfile.lock",
32
+ "test/rails_3_1/Gemfile",
33
+ "test/rails_3_1/Gemfile.lock",
34
+ "test/test_test_seeds.rb",
35
+ "test_all.sh",
36
+ "test_seeds.gemspec"
37
+ ]
38
+ s.homepage = %q{http://github.com/pkmiec/test_seeds}
39
+ s.licenses = [%q{MIT}]
40
+ s.require_paths = [%q{lib}]
41
+ s.rubygems_version = %q{1.8.6}
42
+ s.summary = %q{Test Seeds allow efficient usage of object factories (like Factory Girl) in tests. Instead of creating objects for similar scenarios in each test case, Test Seeds start a db transaction for each test file, creates all the common objects once, and then uses db savepoints for each test case.}
43
+
44
+ if s.respond_to? :specification_version then
45
+ s.specification_version = 3
46
+
47
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
48
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
49
+ s.add_development_dependency(%q<rake>, [">= 0"])
50
+ s.add_development_dependency(%q<mysql2>, ["< 0.3"])
51
+ s.add_development_dependency(%q<activerecord>, ["~> 3.0.0"])
52
+ else
53
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
54
+ s.add_dependency(%q<rake>, [">= 0"])
55
+ s.add_dependency(%q<mysql2>, ["< 0.3"])
56
+ s.add_dependency(%q<activerecord>, ["~> 3.0.0"])
57
+ end
58
+ else
59
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
60
+ s.add_dependency(%q<rake>, [">= 0"])
61
+ s.add_dependency(%q<mysql2>, ["< 0.3"])
62
+ s.add_dependency(%q<activerecord>, ["~> 3.0.0"])
63
+ end
64
+ end
65
+
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: test_seeds
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Paul Kmiec
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-08-16 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ requirement: &id001 !ruby/object:Gem::Requirement
22
+ none: false
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ hash: 7
27
+ segments:
28
+ - 1
29
+ - 6
30
+ - 4
31
+ version: 1.6.4
32
+ version_requirements: *id001
33
+ name: jeweler
34
+ prerelease: false
35
+ type: :development
36
+ - !ruby/object:Gem::Dependency
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ version_requirements: *id002
47
+ name: rake
48
+ prerelease: false
49
+ type: :development
50
+ - !ruby/object:Gem::Dependency
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - <
55
+ - !ruby/object:Gem::Version
56
+ hash: 13
57
+ segments:
58
+ - 0
59
+ - 3
60
+ version: "0.3"
61
+ version_requirements: *id003
62
+ name: mysql2
63
+ prerelease: false
64
+ type: :development
65
+ - !ruby/object:Gem::Dependency
66
+ requirement: &id004 !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ~>
70
+ - !ruby/object:Gem::Version
71
+ hash: 7
72
+ segments:
73
+ - 3
74
+ - 0
75
+ - 0
76
+ version: 3.0.0
77
+ version_requirements: *id004
78
+ name: activerecord
79
+ prerelease: false
80
+ type: :development
81
+ description: Test Seeds piggy backs on the transaction fixtures functionality. Test Seeds load fixtures into the database in the same way but then start a db transaction for the duration of the test file. Any objects for the common scenarios are then created and inserted into the database. Test Seeds then execute each test case within a context of a db savepoint (or nested db transactions). This allows test seeds to be inserted into the database once and then re-used for each test case that needs it.
82
+ email: pkmiec@gmail.com
83
+ executables: []
84
+
85
+ extensions: []
86
+
87
+ extra_rdoc_files:
88
+ - LICENSE.txt
89
+ - README.rdoc
90
+ files:
91
+ - .document
92
+ - Gemfile
93
+ - Gemfile.lock
94
+ - LICENSE.txt
95
+ - README.rdoc
96
+ - Rakefile
97
+ - VERSION
98
+ - lib/test_seeds.rb
99
+ - test/fixtures/authors.yml
100
+ - test/helper.rb
101
+ - test/rails_3_0/Gemfile
102
+ - test/rails_3_0/Gemfile.lock
103
+ - test/rails_3_1/Gemfile
104
+ - test/rails_3_1/Gemfile.lock
105
+ - test/test_test_seeds.rb
106
+ - test_all.sh
107
+ - test_seeds.gemspec
108
+ homepage: http://github.com/pkmiec/test_seeds
109
+ licenses:
110
+ - MIT
111
+ post_install_message:
112
+ rdoc_options: []
113
+
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ none: false
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ hash: 3
122
+ segments:
123
+ - 0
124
+ version: "0"
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ none: false
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ hash: 3
131
+ segments:
132
+ - 0
133
+ version: "0"
134
+ requirements: []
135
+
136
+ rubyforge_project:
137
+ rubygems_version: 1.8.6
138
+ signing_key:
139
+ specification_version: 3
140
+ summary: Test Seeds allow efficient usage of object factories (like Factory Girl) in tests. Instead of creating objects for similar scenarios in each test case, Test Seeds start a db transaction for each test file, creates all the common objects once, and then uses db savepoints for each test case.
141
+ test_files: []
142
+