unit_record 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +4 -0
- data/README +4 -0
- data/Rakefile +1 -1
- data/lib/unit_record/disconnected_active_record.rb +9 -0
- data/test/functional/controller_test.rb +41 -0
- data/test/test_helper.rb +8 -2
- metadata +3 -2
data/CHANGELOG
CHANGED
data/README
CHANGED
@@ -51,6 +51,10 @@ The <tt>disconnect!</tt> method will do everything necessary to run your unit te
|
|
51
51
|
Thanks to Jay Fields for the original implementation:
|
52
52
|
http://blog.jayfields.com/2007/03/rails-activerecord-unit-testing-part-ii.html
|
53
53
|
|
54
|
+
== Contributors
|
55
|
+
|
56
|
+
* Rob Sanheim
|
57
|
+
|
54
58
|
== License
|
55
59
|
Released under Ruby's license.
|
56
60
|
http://www.ruby-lang.org/en/LICENSE.txt
|
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.4.
|
43
|
+
s.version = "0.4.1"
|
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"
|
@@ -6,22 +6,31 @@ module UnitRecord
|
|
6
6
|
def disconnect!
|
7
7
|
return if disconnected?
|
8
8
|
(class << self; self; end).class_eval do
|
9
|
+
def cache
|
10
|
+
yield
|
11
|
+
end
|
12
|
+
|
9
13
|
def cached_columns
|
10
14
|
@@_cached_columns ||= {}
|
11
15
|
end
|
16
|
+
|
12
17
|
def columns
|
13
18
|
cached_columns[table_name] ||
|
14
19
|
raise("Columns are not cached for '#{table_name}' - check schema.rb")
|
15
20
|
end
|
21
|
+
|
16
22
|
def connection
|
17
23
|
raise "(from #{to_s}): ActiveRecord is disconnected; database access is unavailable in unit tests."
|
18
24
|
end
|
25
|
+
|
19
26
|
def connected?
|
20
27
|
false
|
21
28
|
end
|
29
|
+
|
22
30
|
def disconnected?
|
23
31
|
true
|
24
32
|
end
|
33
|
+
|
25
34
|
def table_exists?
|
26
35
|
true
|
27
36
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/functional_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
|
+
test "sql caching is enabled" do
|
22
|
+
assert_equal true, (SampleController < ActionController::Caching::SqlCache)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
else # Rails 1.x
|
27
|
+
|
28
|
+
class ControllerTest < Test::Unit::TestCase
|
29
|
+
def setup
|
30
|
+
@controller = SampleController.new
|
31
|
+
@request = ActionController::TestRequest.new
|
32
|
+
@response = ActionController::TestResponse.new
|
33
|
+
end
|
34
|
+
|
35
|
+
test "render" do
|
36
|
+
get :sample_action
|
37
|
+
assert_equal "OK", @response.body
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -4,11 +4,17 @@ RAILS_ROOT = File.dirname(__FILE__)
|
|
4
4
|
require 'rubygems'
|
5
5
|
require 'test/unit'
|
6
6
|
|
7
|
-
if
|
8
|
-
gem "rails",
|
7
|
+
if rails_version = ENV['RAILS_VERSION']
|
8
|
+
gem "rails", rails_version
|
9
9
|
end
|
10
|
+
require "rails/version"
|
10
11
|
require 'active_record'
|
11
12
|
require 'active_record/fixtures'
|
13
|
+
require "action_controller"
|
14
|
+
if Rails::VERSION::MAJOR == 2
|
15
|
+
require "action_controller/test_case"
|
16
|
+
end
|
17
|
+
require "action_controller/test_process"
|
12
18
|
|
13
19
|
begin
|
14
20
|
require 'mocha'
|
metadata
CHANGED
@@ -3,8 +3,8 @@ 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.4.
|
7
|
-
date: 2007-12-
|
6
|
+
version: 0.4.1
|
7
|
+
date: 2007-12-10 00:00:00 -05:00
|
8
8
|
summary: UnitRecord enables unit testing without hitting the database.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -39,6 +39,7 @@ files:
|
|
39
39
|
- test/db/schema.rb
|
40
40
|
- test/functional/column_cacher_test.rb
|
41
41
|
- test/functional/column_test.rb
|
42
|
+
- test/functional/controller_test.rb
|
42
43
|
- test/functional/disconnected_active_record_test.rb
|
43
44
|
- test/functional/disconnected_fixtures_test.rb
|
44
45
|
- test/functional/disconnected_test_case_test.rb
|