forklift 0.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.
- data/HISTORY.txt +0 -0
- data/MIT-LICENSE +20 -0
- data/README.markdown +1 -0
- data/Rakefile +29 -0
- data/forklift.gemspec +37 -0
- data/lib/forklift.rb +38 -0
- data/lib/forklift/context_extensions.rb +19 -0
- data/lib/forklift/fixture_loading_callbacks.rb +42 -0
- data/lib/forklift/rails.rb +2 -0
- data/rails/init.rb +1 -0
- data/tasks/forklift_tasks.rake +4 -0
- data/test/gem/forklift_test.rb +28 -0
- data/test/model_factory.rb +6 -0
- data/test/rails/fixture_transactions_test.rb +42 -0
- data/test/schema.rb +9 -0
- data/test/test_helper.rb +11 -0
- metadata +74 -0
data/HISTORY.txt
ADDED
File without changes
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 [Justin Knowlden, Gabriel Gironda]
|
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.markdown
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# ForkLift
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
|
5
|
+
desc 'Default: run unit tests.'
|
6
|
+
task :default => %w[test:gem test:rails]
|
7
|
+
|
8
|
+
desc 'Test the forklift plugin for Rails.'
|
9
|
+
Rake::TestTask.new('test:rails') do |t|
|
10
|
+
t.libs << 'lib'
|
11
|
+
t.pattern = 'test/rails/*_test.rb'
|
12
|
+
t.verbose = true
|
13
|
+
end
|
14
|
+
|
15
|
+
Rake::TestTask.new('test:gem') do |t|
|
16
|
+
t.libs << 'lib'
|
17
|
+
t.pattern = 'test/gem/*_test.rb'
|
18
|
+
t.verbose = true
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
desc 'Generate documentation for the forklift plugin.'
|
23
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
24
|
+
rdoc.rdoc_dir = 'rdoc'
|
25
|
+
rdoc.title = 'Forklift'
|
26
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
27
|
+
rdoc.rdoc_files.include('README')
|
28
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
29
|
+
end
|
data/forklift.gemspec
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "forklift"
|
3
|
+
s.version = "0.2"
|
4
|
+
s.date = "2009-03-26"
|
5
|
+
s.summary = "IT'S FORKLIFT DUMMY"
|
6
|
+
s.email = %w[gus@gusg.us gabriel.gironda@gmail.com]
|
7
|
+
s.homepage = "http://github.com/thumblemonks/forklift/tree/master"
|
8
|
+
s.description = "Testing tool that allows for transactionless fixture data within specific contexts (useful in Shoulda and Factory Girl)"
|
9
|
+
s.authors = %w[Justin\ Knowlden Gabriel\ Gironda]
|
10
|
+
|
11
|
+
s.has_rdoc = false
|
12
|
+
s.rdoc_options = ["--main", "README.markdown"]
|
13
|
+
s.extra_rdoc_files = ["HISTORY.txt", "README.markdown"]
|
14
|
+
|
15
|
+
# run git ls-files to get an updated list
|
16
|
+
s.files = %w[
|
17
|
+
HISTORY.txt
|
18
|
+
MIT-LICENSE
|
19
|
+
README.markdown
|
20
|
+
Rakefile
|
21
|
+
forklift.gemspec
|
22
|
+
lib/forklift.rb
|
23
|
+
lib/forklift/context_extensions.rb
|
24
|
+
lib/forklift/fixture_loading_callbacks.rb
|
25
|
+
lib/forklift/rails.rb
|
26
|
+
rails/init.rb
|
27
|
+
]
|
28
|
+
|
29
|
+
s.test_files = %w[
|
30
|
+
tasks/forklift_tasks.rake
|
31
|
+
test/gem/forklift_test.rb
|
32
|
+
test/model_factory.rb
|
33
|
+
test/rails/fixture_transactions_test.rb
|
34
|
+
test/schema.rb
|
35
|
+
test/test_helper.rb
|
36
|
+
]
|
37
|
+
end
|
data/lib/forklift.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'shoulda'
|
2
|
+
require 'factory_girl'
|
3
|
+
|
4
|
+
module Thumblemonks
|
5
|
+
module Forklift
|
6
|
+
module ContextExtensions
|
7
|
+
def depot(&block)
|
8
|
+
captured_instance_vars, depot_ran = nil, false
|
9
|
+
setup do
|
10
|
+
inject_instance_vars(captured_instance_vars) && next if depot_ran
|
11
|
+
captured_instance_vars, depot_ran = run_depot_and_capture_vars(block), true
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end # ContextExtensions
|
15
|
+
|
16
|
+
module TestUnitTestCaseExtensions
|
17
|
+
# private
|
18
|
+
#
|
19
|
+
def inject_instance_vars(var_hash)
|
20
|
+
var_hash.each { |var_name, var_value| instance_variable_set(var_name, var_value) }
|
21
|
+
end
|
22
|
+
|
23
|
+
def run_depot_and_capture_vars(depot_block)
|
24
|
+
before_variables = instance_variables
|
25
|
+
instance_eval(&depot_block)
|
26
|
+
after_variables = instance_variables
|
27
|
+
(after_variables - before_variables).inject({}) do |vars,var_name|
|
28
|
+
vars[var_name] = instance_variable_get(var_name)
|
29
|
+
vars
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end # TestUnitTestCaseExtensions
|
34
|
+
end # Forklift
|
35
|
+
end
|
36
|
+
|
37
|
+
Test::Unit::TestCase.instance_eval { include Thumblemonks::Forklift::TestUnitTestCaseExtensions }
|
38
|
+
Shoulda::Context.instance_eval { include Thumblemonks::Forklift::ContextExtensions }
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Thumblemonks
|
2
|
+
module Forklift
|
3
|
+
module RailsContextExtensions
|
4
|
+
|
5
|
+
def depot(&block)
|
6
|
+
captured_instance_vars, depot_ran = nil, false
|
7
|
+
add_callback(:before_fixture_load) do
|
8
|
+
ActiveRecord::Base.connection.rollback_to_savepoint and puts("Rolling back to savepoint") if depot_ran
|
9
|
+
inject_instance_vars(captured_instance_vars) && next if depot_ran
|
10
|
+
captured_instance_vars, depot_ran = run_depot_and_capture_vars(block), true
|
11
|
+
ActiveRecord::Base.connection.create_savepoint and puts("Creating savepoint")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end # RailsContextExtensions
|
16
|
+
end # Forklift
|
17
|
+
end # Thumblemonks
|
18
|
+
|
19
|
+
Shoulda::Context.instance_eval { include Thumblemonks::Forklift::RailsContextExtensions }
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Thumblemonks
|
2
|
+
module Forklift
|
3
|
+
module FixtureLoadingCallbacks
|
4
|
+
|
5
|
+
def self.included(klass)
|
6
|
+
klass.class_eval do
|
7
|
+
class_inheritable_hash :callbacks
|
8
|
+
self.callbacks = {}
|
9
|
+
puts "Callbacks starts out as #{self.callbacks.inspect} for #{klass}"
|
10
|
+
alias_method_chain :setup_fixtures, :callback_invocation
|
11
|
+
end
|
12
|
+
klass.extend(ClassMethods)
|
13
|
+
end
|
14
|
+
|
15
|
+
def setup_fixtures_with_callback_invocation
|
16
|
+
run_callback(:before_fixture_load)
|
17
|
+
setup_fixtures_without_callback_invocation
|
18
|
+
end
|
19
|
+
|
20
|
+
module ClassMethods
|
21
|
+
def add_callback(callback_name, method = nil, &block)
|
22
|
+
raise(ArgumentError, "Require either a method or a block") unless method || block
|
23
|
+
callback = block_given? ? block : lambda { send(method) }
|
24
|
+
puts "Adding callback for #{self.name}"
|
25
|
+
existing = (self.callbacks || {})[callback_name] || []
|
26
|
+
write_inheritable_hash :callbacks, {callback_name => (existing + [callback])}
|
27
|
+
end
|
28
|
+
end # ClassMethods
|
29
|
+
#
|
30
|
+
# private
|
31
|
+
#
|
32
|
+
def run_callback(callback_name)
|
33
|
+
to_run = callbacks[callback_name]
|
34
|
+
return unless to_run.any?
|
35
|
+
to_run.each { |callback| instance_eval(&callback) }
|
36
|
+
end
|
37
|
+
|
38
|
+
end # FixtureLoadingCallbacks
|
39
|
+
end # Forklift
|
40
|
+
end # Thumblemonks
|
41
|
+
|
42
|
+
ActiveSupport::TestCase.instance_eval { include Thumblemonks::Forklift::FixtureLoadingCallbacks }
|
data/rails/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'forklift/rails'
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class ForkliftTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
context "with a new context" do
|
6
|
+
depot_runs = 0
|
7
|
+
poodle_object_id = nil
|
8
|
+
local_dawg = nil
|
9
|
+
|
10
|
+
depot do
|
11
|
+
depot_runs += 1
|
12
|
+
@poodle = Factory(:poodle)
|
13
|
+
end
|
14
|
+
|
15
|
+
2.times do |i|
|
16
|
+
should "create our #{i.ordinalize} poodle" do
|
17
|
+
assert Poodle.find(@poodle.id)
|
18
|
+
assert_equal 1, depot_runs
|
19
|
+
assert @poodle
|
20
|
+
assert_equal(local_dawg.object_id, @poodle.object_id) if local_dawg
|
21
|
+
local_dawg ||= @poodle
|
22
|
+
end
|
23
|
+
end # 2.times
|
24
|
+
|
25
|
+
should_eventually "think of a better way to test that @poodle is always the same poodle"
|
26
|
+
end # with a new context
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
RAILS_ROOT = File.dirname(__FILE__)
|
4
|
+
require 'action_controller'
|
5
|
+
require 'test_help'
|
6
|
+
|
7
|
+
require File.dirname(__FILE__) + '/../../rails/init'
|
8
|
+
|
9
|
+
class FixtureTransactionsTest < ActiveSupport::TestCase
|
10
|
+
self.use_transactional_fixtures = true
|
11
|
+
|
12
|
+
def setup_fixtures_with_a_stubbed_configuration
|
13
|
+
ActiveRecord::Base.configurations.stubs(:blank?).returns(false)
|
14
|
+
setup_fixtures_without_a_stubbed_configuration
|
15
|
+
end
|
16
|
+
alias_method_chain :setup_fixtures, :a_stubbed_configuration
|
17
|
+
|
18
|
+
context "when using rails transactional tests" do
|
19
|
+
|
20
|
+
depot_runs = 0
|
21
|
+
poodle_object_id = nil
|
22
|
+
local_dawg = nil
|
23
|
+
|
24
|
+
depot do
|
25
|
+
depot_runs += 1
|
26
|
+
@poodle = Factory(:poodle)
|
27
|
+
end
|
28
|
+
|
29
|
+
2.times do |i|
|
30
|
+
should "create our #{i.ordinalize} poodle" do
|
31
|
+
assert Poodle.find(@poodle.id)
|
32
|
+
assert_equal 1, depot_runs
|
33
|
+
assert @poodle
|
34
|
+
assert_equal(local_dawg.object_id, @poodle.object_id) if local_dawg
|
35
|
+
local_dawg ||= @poodle
|
36
|
+
end
|
37
|
+
end # 2.times
|
38
|
+
|
39
|
+
should_eventually "think of a better way to test that @poodle is always the same poodle"
|
40
|
+
end # with a new context
|
41
|
+
|
42
|
+
end
|
data/test/schema.rb
ADDED
data/test/test_helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
$: << File.dirname(__FILE__) + '/../lib'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'active_support'
|
4
|
+
require 'active_record'
|
5
|
+
require 'forklift'
|
6
|
+
require 'test/unit'
|
7
|
+
require 'mocha'
|
8
|
+
require 'ruby-debug'
|
9
|
+
ActiveRecord::Base.establish_connection('adapter' => 'sqlite3', 'dbfile' => ':memory:')
|
10
|
+
require File.dirname(__FILE__) + '/schema'
|
11
|
+
require File.dirname(__FILE__) + '/model_factory'
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: forklift
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "0.2"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Justin Knowlden
|
8
|
+
- Gabriel Gironda
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2009-03-26 00:00:00 -05:00
|
14
|
+
default_executable:
|
15
|
+
dependencies: []
|
16
|
+
|
17
|
+
description: Testing tool that allows for transactionless fixture data within specific contexts (useful in Shoulda and Factory Girl)
|
18
|
+
email:
|
19
|
+
- gus@gusg.us
|
20
|
+
- gabriel.gironda@gmail.com
|
21
|
+
executables: []
|
22
|
+
|
23
|
+
extensions: []
|
24
|
+
|
25
|
+
extra_rdoc_files:
|
26
|
+
- HISTORY.txt
|
27
|
+
- README.markdown
|
28
|
+
files:
|
29
|
+
- HISTORY.txt
|
30
|
+
- MIT-LICENSE
|
31
|
+
- README.markdown
|
32
|
+
- Rakefile
|
33
|
+
- forklift.gemspec
|
34
|
+
- lib/forklift.rb
|
35
|
+
- lib/forklift/context_extensions.rb
|
36
|
+
- lib/forklift/fixture_loading_callbacks.rb
|
37
|
+
- lib/forklift/rails.rb
|
38
|
+
- rails/init.rb
|
39
|
+
has_rdoc: true
|
40
|
+
homepage: http://github.com/thumblemonks/forklift/tree/master
|
41
|
+
licenses: []
|
42
|
+
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options:
|
45
|
+
- --main
|
46
|
+
- README.markdown
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "0"
|
54
|
+
version:
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: "0"
|
60
|
+
version:
|
61
|
+
requirements: []
|
62
|
+
|
63
|
+
rubyforge_project:
|
64
|
+
rubygems_version: 1.3.5
|
65
|
+
signing_key:
|
66
|
+
specification_version: 3
|
67
|
+
summary: IT'S FORKLIFT DUMMY
|
68
|
+
test_files:
|
69
|
+
- tasks/forklift_tasks.rake
|
70
|
+
- test/gem/forklift_test.rb
|
71
|
+
- test/model_factory.rb
|
72
|
+
- test/rails/fixture_transactions_test.rb
|
73
|
+
- test/schema.rb
|
74
|
+
- test/test_helper.rb
|