thumblemonks-forklift 0.1.0

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 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/lib/forklift.rb ADDED
@@ -0,0 +1,41 @@
1
+ require 'shoulda'
2
+ require 'factory_girl'
3
+
4
+ module Thumblemonks
5
+ module Forklift
6
+ module ContextExtensions
7
+
8
+
9
+ def depot(&block)
10
+ captured_instance_vars, depot_ran = nil, false
11
+ setup do
12
+ inject_instance_vars(captured_instance_vars) && next if depot_ran
13
+ captured_instance_vars, depot_ran = run_depot_and_capture_vars(block), true
14
+ end
15
+ end
16
+
17
+ end # ContextExtensions
18
+ module TestUnitTestCaseExtensions
19
+
20
+ private
21
+
22
+ def inject_instance_vars(var_hash)
23
+ var_hash.each { |var_name, var_value| instance_variable_set(var_name, var_value) }
24
+ end
25
+
26
+ def run_depot_and_capture_vars(depot_block)
27
+ before_variables = instance_variables
28
+ instance_eval(&depot_block)
29
+ after_variables = instance_variables
30
+ (after_variables - before_variables).inject({}) do |vars,var_name|
31
+ vars[var_name] = instance_variable_get(var_name)
32
+ vars
33
+ end
34
+ end
35
+
36
+ end # TestUnitTestCaseExtensions
37
+ end # Forklift
38
+ end
39
+
40
+ Test::Unit::TestCase.instance_eval { include Thumblemonks::Forklift::TestUnitTestCaseExtensions }
41
+ Thoughtbot::Shoulda::Context.instance_eval { include Thumblemonks::Forklift::ContextExtensions }
@@ -0,0 +1,17 @@
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
+ inject_instance_vars(captured_instance_vars) && next if depot_ran
9
+ captured_instance_vars, depot_ran = run_depot_and_capture_vars(block), true
10
+ end
11
+ end
12
+
13
+ end # RailsContextExtensions
14
+ end # Forklift
15
+ end # Thumblemonks
16
+
17
+ Thoughtbot::Shoulda::Context.instance_eval { include Thumblemonks::Forklift::RailsContextExtensions }
@@ -0,0 +1,44 @@
1
+ require 'active_record/fixtures'
2
+
3
+ module Thumblemonks
4
+ module Forklift
5
+ module FixtureLoadingCallbacks
6
+
7
+ def self.included(klass)
8
+ klass.class_eval do
9
+ class_inheritable_hash :callbacks
10
+ self.callbacks = {}
11
+ alias_method_chain :setup_fixtures, :callback_invocation
12
+ end
13
+ klass.extend(ClassMethods)
14
+ end
15
+
16
+ def setup_fixtures_with_callback_invocation
17
+ run_callback(:before_fixture_load)
18
+ setup_fixtures_without_callback_invocation
19
+ end
20
+
21
+ private
22
+
23
+ def run_callback(callback_name)
24
+ to_run = callbacks[callback_name]
25
+ return unless to_run.any?
26
+ to_run.each { |callback| instance_eval(&callback) }
27
+ end
28
+
29
+
30
+ module ClassMethods
31
+
32
+ def add_callback(callback_name, method = nil, &block)
33
+ raise(ArgumentError, "Require either a method or a block") unless method || block
34
+ callback = block_given? ? block : lambda { send(method) }
35
+ existing = callbacks[callback_name] || []
36
+ write_inheritable_hash :callbacks, {callback_name => (existing + [callback])}
37
+ end
38
+
39
+ end # ClassMethods
40
+ end # FixtureLoadingCallbacks
41
+ end # Forklift
42
+ end # Thumblemonks
43
+
44
+ Test::Unit::TestCase.instance_eval { include Thumblemonks::Forklift::FixtureLoadingCallbacks }
data/rails/init.rb ADDED
@@ -0,0 +1,2 @@
1
+ require File.dirname(__FILE__) + '/fixture_loading_callbacks'
2
+ require File.dirname(__FILE__) + '/context_extensions'
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :forklift do
3
+ # # Task goes here
4
+ # end
@@ -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,6 @@
1
+ class Poodle < ActiveRecord::Base
2
+ end
3
+
4
+ Factory.define(:poodle) do |poodle|
5
+ poodle.name "Mister Woofypants"
6
+ end
@@ -0,0 +1,37 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+ require File.dirname(__FILE__) + '/../../rails/init'
3
+
4
+ class FixtureTransactionsTest < Test::Unit::TestCase
5
+ self.use_transactional_fixtures = true
6
+
7
+ def setup_fixtures_with_a_stubbed_configuration
8
+ ActiveRecord::Base.configurations.stubs(:blank?).returns(false)
9
+ setup_fixtures_without_a_stubbed_configuration
10
+ end
11
+ alias_method_chain :setup_fixtures, :a_stubbed_configuration
12
+
13
+ context "when using rails transactional tests" do
14
+
15
+ depot_runs = 0
16
+ poodle_object_id = nil
17
+ local_dawg = nil
18
+
19
+ depot do
20
+ depot_runs += 1
21
+ @poodle = Factory(:poodle)
22
+ end
23
+
24
+ 2.times do |i|
25
+ should "create our #{i.ordinalize} poodle" do
26
+ assert Poodle.find(@poodle.id)
27
+ assert_equal 1, depot_runs
28
+ assert @poodle
29
+ assert_equal(local_dawg.object_id, @poodle.object_id) if local_dawg
30
+ local_dawg ||= @poodle
31
+ end
32
+ end # 2.times
33
+
34
+ should_eventually "think of a better way to test that @poodle is always the same poodle"
35
+ end # with a new context
36
+
37
+ end
data/test/schema.rb ADDED
@@ -0,0 +1,9 @@
1
+ ActiveRecord::Schema.suppress_messages do
2
+ ActiveRecord::Schema.define(:version => 1) do
3
+
4
+ create_table :poodles, :force => true do |t|
5
+ t.string :name
6
+ end
7
+
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ $: << File.dirname(__FILE__) + '/../lib'
2
+ require 'rubygems'
3
+ require 'active_record'
4
+ require 'forklift'
5
+ require 'test/unit'
6
+ require 'mocha'
7
+ require 'ruby-debug'
8
+ ActiveRecord::Base.establish_connection('adapter' => 'sqlite3', 'dbfile' => ':memory:')
9
+ require File.dirname(__FILE__) + '/schema'
10
+ require File.dirname(__FILE__) + '/model_factory'
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: thumblemonks-forklift
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Justin Knowlden
8
+ - Gabriel Gironda
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2008-12-05 00:00:00 -08: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
+ - init.rb
34
+ - install.rb
35
+ - lib/forklift.rb
36
+ - rails/context_extensions.rb
37
+ - rails/fixture_loading_callbacks.rb
38
+ - rails/init.rb
39
+ - tasks/forklift_tasks.rake
40
+ has_rdoc: false
41
+ homepage: http://github.com/thumblemonks/forklift/tree/master
42
+ post_install_message:
43
+ rdoc_options:
44
+ - --main
45
+ - README.markdown
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: "0"
53
+ version:
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "0"
59
+ version:
60
+ requirements: []
61
+
62
+ rubyforge_project:
63
+ rubygems_version: 1.2.0
64
+ signing_key:
65
+ specification_version: 2
66
+ summary: IT'S FORKLIFT DUMMY
67
+ test_files:
68
+ - test/gem/forklift_test.rb
69
+ - test/model_factory.rb
70
+ - test/rails/fixture_transactions_test.rb
71
+ - test/schema.rb
72
+ - test/test_helper.rb