unit_record 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ *0.4.0* (December 9th, 2007)
2
+
3
+ * Rails 2.0 compatibility.
4
+
1
5
  *0.3.0* (August 22nd, 2007)
2
6
 
3
7
  * Works with models using non-conventional table names.
data/README CHANGED
@@ -6,15 +6,11 @@ This plugin provides unit testing for ActiveRecord by disconnecting tests from t
6
6
 
7
7
  Rationale: http://www.dcmanges.com/blog/rails-unit-record-test-without-the-database
8
8
 
9
- One huge benefit to disconnecting unit tests from the database is having a faster test suite. Here is the benchmark from my current ThoughtWorks project:
9
+ One huge benefit to disconnecting unit tests from the database is having a faster test suite. Here is the benchmark from one of my current projects:
10
10
 
11
11
  Finished in 11.541093 seconds.
12
12
  3001 tests, 5325 assertions, 0 failures, 0 errors
13
13
 
14
- == Requirements
15
-
16
- * Rails >= 1.2
17
-
18
14
  == Installation
19
15
 
20
16
  gem install unit_record
data/Rakefile CHANGED
@@ -40,7 +40,7 @@ Gem::manage_gems
40
40
  specification = Gem::Specification.new do |s|
41
41
  s.name = "unit_record"
42
42
  s.summary = "UnitRecord enables unit testing without hitting the database."
43
- s.version = "0.3.0"
43
+ s.version = "0.4.0"
44
44
  s.author = "Dan Manges"
45
45
  s.description = "UnitRecord enables unit testing without hitting the database."
46
46
  s.email = "daniel.manges@gmail.com"
@@ -59,3 +59,29 @@ Rake::GemPackageTask.new(specification) do |package|
59
59
  package.need_zip = false
60
60
  package.need_tar = false
61
61
  end
62
+
63
+ RUBY_VERSIONS = %w[1.8.5-p52 1.8.5-p114 1.8.6]
64
+ JRUBY_VERSIONS = %w[1.1b1 1.0.2]
65
+ RAILS_VERSIONS = %w[1.2.5 1.99.0 2.0.1]
66
+
67
+ namespace :test do
68
+ desc "test with multiple versions of ruby and rails"
69
+ task :multi do
70
+ RUBY_VERSIONS.each do |ruby_version|
71
+ bin = "/usr/local/ruby-#{ruby_version}/bin"
72
+ RAILS_VERSIONS.each do |rails_version|
73
+ sh "RAILS_VERSION='#{rails_version}' #{bin}/rake test > /dev/null 2>&1"
74
+ end
75
+ end
76
+ end
77
+
78
+ desc "test with multiple versions of jruby and rails"
79
+ task :multi_jruby do
80
+ JRUBY_VERSIONS.each do |jruby_version|
81
+ home = "/usr/local/jruby/jruby-#{jruby_version}"
82
+ RAILS_VERSIONS.each do |rails_version|
83
+ sh "JRUBY_HOME=#{home} RAILS_VERSION='#{rails_version}' #{home}/bin/rake test > /dev/null 2>&1"
84
+ end
85
+ end
86
+ end
87
+ end
@@ -14,7 +14,7 @@ module UnitRecord
14
14
  raise("Columns are not cached for '#{table_name}' - check schema.rb")
15
15
  end
16
16
  def connection
17
- raise "ActiveRecord is disconnected; database access is unavailable in unit tests."
17
+ raise "(from #{to_s}): ActiveRecord is disconnected; database access is unavailable in unit tests."
18
18
  end
19
19
  def connected?
20
20
  false
@@ -22,6 +22,9 @@ module UnitRecord
22
22
  def disconnected?
23
23
  true
24
24
  end
25
+ def table_exists?
26
+ true
27
+ end
25
28
  end
26
29
  Fixtures.disconnect!
27
30
  Test::Unit::TestCase.disconnect!
@@ -3,6 +3,7 @@ module UnitRecord
3
3
  def disconnect!
4
4
  (class << self; self; end).class_eval do
5
5
  def create_fixtures(*args); end
6
+ def reset_cache; end
6
7
  end
7
8
  end
8
9
  end
@@ -1,11 +1,20 @@
1
- require File.dirname(__FILE__) + "/./functional_test_helper"
2
- # The '.' is intentional to have a TestCase require a different relative path.
1
+ require File.dirname(__FILE__) + "/functional_test_helper"
3
2
 
4
3
  functional_tests do
5
4
  test "accessing connection raises" do
6
5
  assert_raises(RuntimeError) { ActiveRecord::Base.connection }
7
6
  end
8
7
 
8
+ test "accessing connection gives exception message with class name" do
9
+ exception = nil
10
+ begin
11
+ Person.connection
12
+ rescue => exception
13
+ end
14
+ assert_not_nil exception
15
+ assert_equal "(from Person): ActiveRecord is disconnected; database access is unavailable in unit tests.", exception.message
16
+ end
17
+
9
18
  test "connected? is false" do
10
19
  assert_equal false, ActiveRecord::Base.connected?
11
20
  end
@@ -13,4 +22,12 @@ functional_tests do
13
22
  test "disconnected? is true" do
14
23
  assert_equal true, ActiveRecord::Base.disconnected?
15
24
  end
25
+
26
+ test "inspect does not blow up" do
27
+ assert_nothing_raised { Person.inspect }
28
+ end
29
+
30
+ test "table_exists?" do
31
+ assert_equal true, Person.table_exists?
32
+ end
16
33
  end
@@ -1,2 +1,4 @@
1
1
  require File.dirname(__FILE__) + "/../test_helper" unless defined?(RAILS_ROOT)
2
2
  ActiveRecord::Base.disconnect!
3
+ # make sure calling disconnect multiple times does not cause problems
4
+ ActiveRecord::Base.disconnect!
data/test/test_helper.rb CHANGED
@@ -3,10 +3,13 @@ RAILS_ROOT = File.dirname(__FILE__)
3
3
 
4
4
  require 'rubygems'
5
5
  require 'test/unit'
6
+
7
+ if version = ENV['RAILS_VERSION']
8
+ gem "rails", version
9
+ end
6
10
  require 'active_record'
7
11
  require 'active_record/fixtures'
8
- require 'active_support/binding_of_caller'
9
- require 'active_support/breakpoint'
12
+
10
13
  begin
11
14
  require 'mocha'
12
15
  require 'dust'
@@ -19,6 +22,10 @@ require "#{File.dirname(__FILE__)}/../init"
19
22
 
20
23
  Test::Unit::TestCase.use_transactional_fixtures = true
21
24
 
25
+ # Needed because of this line in setup_with_fixtures and teardown_with_fixtures:
26
+ # return unless defined?(ActiveRecord::Base) && !ActiveRecord::Base.configurations.blank?
27
+ ActiveRecord::Base.configurations = {"irrelevant" => {:adapter => "stub"}}
28
+
22
29
  class Preference < ActiveRecord::Base
23
30
  end
24
31
  class Person < ActiveRecord::Base
@@ -28,4 +35,4 @@ class Foo < ActiveRecord::Base
28
35
  end
29
36
  class DoesNotExist < ActiveRecord::Base
30
37
  set_table_name "table_does_not_exist"
31
- end
38
+ end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + "/../test_helper"
1
+ require File.dirname(__FILE__) + "/unit_test_helper"
2
2
 
3
3
  unit_tests do
4
4
  test "equality" do
@@ -0,0 +1,5 @@
1
+ require File.dirname(__FILE__) + "/../test_helper"
2
+
3
+ ActiveRecord::Base.establish_connection \
4
+ :adapter => "mysql",
5
+ :database => "stub_development"
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.3
2
+ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: unit_record
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.3.0
7
- date: 2007-08-22 00:00:00 -04:00
6
+ version: 0.4.0
7
+ date: 2007-12-09 00:00:00 -06:00
8
8
  summary: UnitRecord enables unit testing without hitting the database.
9
9
  require_paths:
10
10
  - lib
@@ -44,6 +44,7 @@ files:
44
44
  - test/functional/disconnected_test_case_test.rb
45
45
  - test/functional/functional_test_helper.rb
46
46
  - test/unit/column_extension_test.rb
47
+ - test/unit/unit_test_helper.rb
47
48
  - CHANGELOG
48
49
  - README
49
50
  - Rakefile