rsanheim-unit_record 0.9.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +34 -0
- data/LICENSE +20 -0
- data/README.markdown +137 -0
- data/Rakefile +94 -0
- data/lib/active_record/connection_adapters/unit_record_adapter.rb +97 -0
- data/lib/unit_record.rb +32 -0
- data/lib/unit_record/association_stubbing.rb +39 -0
- data/lib/unit_record/column_extension.rb +18 -0
- data/lib/unit_record/disconnected_active_record.rb +21 -0
- data/lib/unit_record/disconnected_fixtures.rb +10 -0
- data/lib/unit_record/disconnected_test_case.rb +13 -0
- data/test/active_record/connection_adapters/unit_record_adapter_test.rb +103 -0
- data/test/db/schema.rb +26 -0
- data/test/sample_spec.rb +44 -0
- data/test/test_helper.rb +73 -0
- data/test/unit_record/association_stubbing_test.rb +37 -0
- data/test/unit_record/column_cacher_test.rb +26 -0
- data/test/unit_record/column_extension_test.rb +33 -0
- data/test/unit_record/column_test.rb +40 -0
- data/test/unit_record/controller_test.rb +43 -0
- data/test/unit_record/disconnected_active_record_test.rb +52 -0
- data/test/unit_record/disconnected_fixtures_test.rb +7 -0
- data/test/unit_record/disconnected_test_case_test.rb +19 -0
- data/test/unit_record/unit_record_test.rb +14 -0
- data/vendor/dust-0.1.6/lib/array_extension.rb +5 -0
- data/vendor/dust-0.1.6/lib/definition_error.rb +20 -0
- data/vendor/dust-0.1.6/lib/dust.rb +8 -0
- data/vendor/dust-0.1.6/lib/nil_extension.rb +5 -0
- data/vendor/dust-0.1.6/lib/object_extension.rb +62 -0
- data/vendor/dust-0.1.6/lib/string_extension.rb +5 -0
- data/vendor/dust-0.1.6/lib/symbol_extension.rb +5 -0
- data/vendor/dust-0.1.6/lib/test_case_extension.rb +76 -0
- data/vendor/dust-0.1.6/rakefile.rb +50 -0
- data/vendor/dust-0.1.6/test/all_tests.rb +1 -0
- data/vendor/dust-0.1.6/test/failing_with_helper_unit_test.rb +16 -0
- data/vendor/dust-0.1.6/test/failing_with_setup_unit_test.rb +16 -0
- data/vendor/dust-0.1.6/test/functional_test.rb +12 -0
- data/vendor/dust-0.1.6/test/passing_unit_test.rb +11 -0
- data/vendor/dust-0.1.6/test/passing_with_helper_unit_test.rb +10 -0
- data/vendor/dust-0.1.6/test/passing_with_helpers_unit_test.rb +13 -0
- data/vendor/dust-0.1.6/test/passing_with_setup_unit_test.rb +10 -0
- data/vendor/dust-0.1.6/test/test_helper.rb +1 -0
- metadata +94 -0
@@ -0,0 +1,43 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class SampleController < ActionController::Base
|
4
|
+
def sample_action
|
5
|
+
render :text => "OK"
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
ActionController::Routing::Routes.add_route "/sample/sample_action", :controller => "sample", :action => "sample_action"
|
10
|
+
|
11
|
+
if defined?(ActionController::TestCase) # Rails 2
|
12
|
+
|
13
|
+
class ControllerTest < ActionController::TestCase
|
14
|
+
tests SampleController
|
15
|
+
|
16
|
+
test "render" do
|
17
|
+
get :sample_action
|
18
|
+
assert_equal "OK", @response.body
|
19
|
+
end
|
20
|
+
|
21
|
+
if defined?(ActionController::Caching::SqlCache) # SqlCache goes away in Rails 2.3.1
|
22
|
+
test "sql caching is enabled" do
|
23
|
+
assert_equal true, (SampleController < ActionController::Caching::SqlCache)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
else # Rails 1.x
|
29
|
+
|
30
|
+
class ControllerTest < Test::Unit::TestCase
|
31
|
+
def setup
|
32
|
+
@controller = SampleController.new
|
33
|
+
@request = ActionController::TestRequest.new
|
34
|
+
@response = ActionController::TestResponse.new
|
35
|
+
end
|
36
|
+
|
37
|
+
test "render" do
|
38
|
+
get :sample_action
|
39
|
+
assert_equal "OK", @response.body
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../test_helper"
|
2
|
+
|
3
|
+
functional_tests do
|
4
|
+
test "find_by_sql gives disconnected exception message" do
|
5
|
+
exception = nil
|
6
|
+
begin
|
7
|
+
Person.find_by_sql "SELECT * FROM people"
|
8
|
+
rescue => exception
|
9
|
+
end
|
10
|
+
assert_not_nil exception
|
11
|
+
assert_equal "ActiveRecord is disconnected; database access is unavailable in unit tests.", exception.message
|
12
|
+
end
|
13
|
+
|
14
|
+
test "connected? is true" do
|
15
|
+
assert_equal true, ActiveRecord::Base.connected?
|
16
|
+
end
|
17
|
+
|
18
|
+
test "disconnected? is true" do
|
19
|
+
assert_equal true, ActiveRecord::Base.disconnected?
|
20
|
+
end
|
21
|
+
|
22
|
+
test "inspect does not blow up" do
|
23
|
+
assert_nothing_raised { Person.inspect }
|
24
|
+
end
|
25
|
+
|
26
|
+
test "table_exists?" do
|
27
|
+
assert_equal true, Person.table_exists?
|
28
|
+
if ActiveRecord::Base.connection.respond_to?(:table_exists?)
|
29
|
+
assert_equal false, ActiveRecord::Base.connection.table_exists?("bogus_table")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
test "setting a has_one association" do
|
34
|
+
person = Person.new
|
35
|
+
person.profile = Profile.new
|
36
|
+
end
|
37
|
+
|
38
|
+
test "boolean columns do type casting" do
|
39
|
+
pref = Preference.new
|
40
|
+
pref.show_help = "0"
|
41
|
+
assert_equal false, pref.send(:read_attribute, :show_help)
|
42
|
+
assert_equal false, pref.show_help
|
43
|
+
assert_equal false, pref.show_help?
|
44
|
+
pref.show_help = "1"
|
45
|
+
assert_equal true, pref.show_help
|
46
|
+
assert_equal true, pref.show_help?
|
47
|
+
end
|
48
|
+
|
49
|
+
test "migrations are not verbose" do
|
50
|
+
assert_equal false, ActiveRecord::Migration.verbose
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../test_helper"
|
2
|
+
|
3
|
+
functional_tests do
|
4
|
+
test "use_transactional_fixtures is false" do
|
5
|
+
assert_equal false, UnitRecord.base_rails_test_class.use_transactional_fixtures
|
6
|
+
end
|
7
|
+
|
8
|
+
test "trying to use fixtures gives useful message" do
|
9
|
+
exception = nil
|
10
|
+
begin
|
11
|
+
Class.new(UnitRecord.base_rails_test_class) do
|
12
|
+
fixtures :users
|
13
|
+
end
|
14
|
+
rescue => exception
|
15
|
+
end
|
16
|
+
assert_not_nil exception
|
17
|
+
assert_equal "Fixtures cannot be used with UnitRecord. ActiveRecord is disconnected; database access is unavailable in unit tests.", exception.message
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../test_helper"
|
2
|
+
|
3
|
+
unit_tests do
|
4
|
+
if UnitRecord.rails_version > "2.3"
|
5
|
+
test "test case base class" do
|
6
|
+
assert_equal ActiveSupport::TestCase, UnitRecord.base_rails_test_class
|
7
|
+
end
|
8
|
+
else
|
9
|
+
test "test case base class" do
|
10
|
+
assert_equal Test::Unit::TestCase, UnitRecord.base_rails_test_class
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Dust #:nodoc:
|
2
|
+
# Dust::DefinitionError is raised when you attempt to define a disallowed method within a test file.
|
3
|
+
#
|
4
|
+
# Test::Unit::TestCase.disallow_setup!
|
5
|
+
#
|
6
|
+
# unit_tests do
|
7
|
+
# def setup
|
8
|
+
# ...
|
9
|
+
# end
|
10
|
+
#
|
11
|
+
# test "name" do
|
12
|
+
# ...
|
13
|
+
# end
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# The above code will generate the following error
|
17
|
+
# Dust::DefinitionError: setup is not allowed on class Units::[TestClassName]
|
18
|
+
class DefinitionError < StandardError
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/object_extension')
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + '/array_extension')
|
4
|
+
require File.expand_path(File.dirname(__FILE__) + '/nil_extension')
|
5
|
+
require File.expand_path(File.dirname(__FILE__) + '/string_extension')
|
6
|
+
require File.expand_path(File.dirname(__FILE__) + '/symbol_extension')
|
7
|
+
require File.expand_path(File.dirname(__FILE__) + '/test_case_extension')
|
8
|
+
require File.expand_path(File.dirname(__FILE__) + '/definition_error')
|
@@ -0,0 +1,62 @@
|
|
1
|
+
class Object
|
2
|
+
# call-seq: unit_tests(options={}, &block)
|
3
|
+
#
|
4
|
+
# Used to define a block of unit tests.
|
5
|
+
#
|
6
|
+
# unit_tests do
|
7
|
+
# test "verify something" do
|
8
|
+
# ...
|
9
|
+
# end
|
10
|
+
# end
|
11
|
+
#
|
12
|
+
# Configuration Options:
|
13
|
+
# * allow - Allows you to specify the methods that are allowed despite being disallowed.
|
14
|
+
# See Test::Unit::TestCase.disallow_helpers! or Test::Unit::TestCase.disallow_setup! for more info
|
15
|
+
def unit_tests(options={}, &block)
|
16
|
+
do_tests("Units", options, &block)
|
17
|
+
end
|
18
|
+
|
19
|
+
# call-seq: functional_tests(options={}, &block)
|
20
|
+
#
|
21
|
+
# Used to define a block of functional tests.
|
22
|
+
#
|
23
|
+
# functional_tests do
|
24
|
+
# test "verify something" do
|
25
|
+
# ...
|
26
|
+
# end
|
27
|
+
# end
|
28
|
+
#
|
29
|
+
# Configuration Options:
|
30
|
+
# * allow - Allows you to specify the methods that are allowed despite being disallowed.
|
31
|
+
# See Test::Unit::TestCase.disallow_helpers! or Test::Unit::TestCase.disallow_setup! for more info
|
32
|
+
def functional_tests(options={}, &block)
|
33
|
+
do_tests("Functionals", options, &block)
|
34
|
+
end
|
35
|
+
|
36
|
+
protected
|
37
|
+
def do_tests(type, options, &block) #:nodoc:
|
38
|
+
options[:allow] = options[:allow].arrayize
|
39
|
+
full_path_file_name = eval "__FILE__", block.binding
|
40
|
+
test_name = File.basename(full_path_file_name, ".rb")
|
41
|
+
test_class = eval "module #{type}; class #{test_name.to_class_name} < Test::Unit::TestCase; self; end; end"
|
42
|
+
test_class.class_eval &block
|
43
|
+
check_for_setup(test_class, options)
|
44
|
+
check_for_helpers(test_class, options)
|
45
|
+
end
|
46
|
+
|
47
|
+
def check_for_setup(test_class, options) #:nodoc:
|
48
|
+
if test_class.instance_methods(false).include?("setup") && Test::Unit::TestCase.disallow_setup? &&
|
49
|
+
!options[:allow].include?(:setup)
|
50
|
+
raise Dust::DefinitionError.new("setup is not allowed on class #{test_class.name}")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def check_for_helpers(test_class, options) #:nodoc:
|
55
|
+
test_class.instance_methods(false).each do |method_name|
|
56
|
+
if method_name !~ /^test_/ && Test::Unit::TestCase.disallow_helpers? && !options[:allow].include?(method_name.to_sym)
|
57
|
+
p method_name.to_sym
|
58
|
+
raise Dust::DefinitionError.new("helper methods are not allowed on class #{test_class.name}")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module Test #:nodoc:
|
2
|
+
module Unit #:nodoc:
|
3
|
+
class TestCase
|
4
|
+
# call-seq: disallow_setup!
|
5
|
+
#
|
6
|
+
# Used to disallow setup methods in test specifications.
|
7
|
+
#
|
8
|
+
# Test::Unit::TestCase.disallow_setup!
|
9
|
+
#
|
10
|
+
# A test specification can override this behavior by passing :setup in the :allow options.
|
11
|
+
#
|
12
|
+
# unit_tests :allow => :setup do
|
13
|
+
# def setup
|
14
|
+
# ...
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# test "verify something" do
|
18
|
+
# ...
|
19
|
+
# end
|
20
|
+
# end
|
21
|
+
def self.disallow_setup!
|
22
|
+
@disallow_setup = true
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.disallow_setup? #:nodoc:
|
26
|
+
@disallow_setup
|
27
|
+
end
|
28
|
+
|
29
|
+
# call-seq: disallow_helpers!
|
30
|
+
#
|
31
|
+
# Used to disallow helper methods in test specifications.
|
32
|
+
#
|
33
|
+
# Test::Unit::TestCase.disallow_helper!
|
34
|
+
#
|
35
|
+
# A test specification can override this behavior by passing the helper name (as a symbol) in the :allow options.
|
36
|
+
#
|
37
|
+
# unit_tests :allow => [:create_something, :destroy_something] do
|
38
|
+
# test "verify something" do
|
39
|
+
# ...
|
40
|
+
# end
|
41
|
+
#
|
42
|
+
# def create_something
|
43
|
+
# ...
|
44
|
+
# end
|
45
|
+
#
|
46
|
+
# def destroy_something
|
47
|
+
# ...
|
48
|
+
# end
|
49
|
+
# end
|
50
|
+
def self.disallow_helpers!
|
51
|
+
@disallow_helpers = true
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.disallow_helpers? #:nodoc:
|
55
|
+
@disallow_helpers
|
56
|
+
end
|
57
|
+
|
58
|
+
# call-seq: test(name, &block)
|
59
|
+
#
|
60
|
+
# Used to define a test and assign it a descriptive name.
|
61
|
+
#
|
62
|
+
# unit_tests do
|
63
|
+
# test "verify something" do
|
64
|
+
# ...
|
65
|
+
# end
|
66
|
+
# end
|
67
|
+
def self.test(name, &block)
|
68
|
+
test_name = "test_#{name.gsub(/[\s]/,'_')}".to_sym
|
69
|
+
raise "#{test_name} is already defined in #{self}" if self.instance_methods.include? test_name.to_s
|
70
|
+
define_method test_name do
|
71
|
+
instance_eval &block
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake/gempackagetask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
require 'rake/contrib/sshpublisher'
|
5
|
+
|
6
|
+
task :default => :test
|
7
|
+
|
8
|
+
task :test do
|
9
|
+
require File.dirname(__FILE__) + '/test/all_tests.rb'
|
10
|
+
end
|
11
|
+
|
12
|
+
desc 'Generate RDoc'
|
13
|
+
Rake::RDocTask.new do |task|
|
14
|
+
task.main = 'README'
|
15
|
+
task.title = 'Dust'
|
16
|
+
task.rdoc_dir = 'doc'
|
17
|
+
task.options << "--line-numbers" << "--inline-source"
|
18
|
+
task.rdoc_files.include('README', 'lib/**/*.rb')
|
19
|
+
end
|
20
|
+
|
21
|
+
desc "Upload RDoc to RubyForge"
|
22
|
+
task :publish_rdoc => [:rdoc] do
|
23
|
+
Rake::SshDirPublisher.new("jaycfields@rubyforge.org", "/var/www/gforge-projects/dust", "doc").upload
|
24
|
+
end
|
25
|
+
|
26
|
+
Gem::manage_gems
|
27
|
+
|
28
|
+
specification = Gem::Specification.new do |s|
|
29
|
+
s.name = "dust"
|
30
|
+
s.summary = "Dust is an add on for Test::Unit that allows an alternative test definintion syntax."
|
31
|
+
s.version = "0.1.6"
|
32
|
+
s.author = 'Jay Fields'
|
33
|
+
s.description = "Dust is an add on for Test::Unit that allows an alternative test definintion syntax."
|
34
|
+
s.email = 'dust-developer@rubyforge.org'
|
35
|
+
s.homepage = 'http://dust.rubyforge.org'
|
36
|
+
s.rubyforge_project = 'dust'
|
37
|
+
|
38
|
+
s.has_rdoc = true
|
39
|
+
s.extra_rdoc_files = ['README']
|
40
|
+
s.rdoc_options << '--title' << 'Dust' << '--main' << 'README' << '--line-numbers'
|
41
|
+
|
42
|
+
s.autorequire = 'dust'
|
43
|
+
s.files = FileList['{lib,test}/**/*.rb', '[A-Z]*$', 'rakefile.rb'].to_a
|
44
|
+
s.test_file = "test/all_tests.rb"
|
45
|
+
end
|
46
|
+
|
47
|
+
Rake::GemPackageTask.new(specification) do |package|
|
48
|
+
package.need_zip = false
|
49
|
+
package.need_tar = false
|
50
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
Dir['**/*_test.rb'].each { |test_case| require test_case }
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/test_helper")
|
2
|
+
|
3
|
+
begin
|
4
|
+
unit_tests do
|
5
|
+
Test::Unit::TestCase.disallow_helpers!
|
6
|
+
def helper_method
|
7
|
+
end
|
8
|
+
|
9
|
+
test("true"){}
|
10
|
+
end
|
11
|
+
raise "shouldn't be here"
|
12
|
+
rescue Dust::DefinitionError => ex
|
13
|
+
raise unless ex.message == "helper methods are not allowed on class Units::FailingWithHelperUnitTest"
|
14
|
+
ensure
|
15
|
+
Test::Unit::TestCase.class_eval { @disallow_helpers = nil }
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/test_helper")
|
2
|
+
|
3
|
+
begin
|
4
|
+
unit_tests do
|
5
|
+
Test::Unit::TestCase.disallow_setup!
|
6
|
+
def setup
|
7
|
+
end
|
8
|
+
|
9
|
+
test("true"){}
|
10
|
+
end
|
11
|
+
raise "shouldn't be here"
|
12
|
+
rescue Dust::DefinitionError => ex
|
13
|
+
raise unless ex.message == "setup is not allowed on class Units::FailingWithSetupUnitTest"
|
14
|
+
ensure
|
15
|
+
Test::Unit::TestCase.class_eval { @disallow_setup = nil }
|
16
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/test_helper")
|
2
|
+
|
3
|
+
functional_tests do
|
4
|
+
test "assert true" do
|
5
|
+
assert_equal true, true
|
6
|
+
end
|
7
|
+
|
8
|
+
test "class name is Functionals::FunctionalTest" do
|
9
|
+
assert_equal "Functionals::FunctionalTest", self.class.name
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|