unit_record 0.4.0 → 0.4.1

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/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ *0.4.1* (December 10th, 2007)
2
+
3
+ * Stub caching for compatibility with ActionController::Caching::SqlCache in Rails 2.
4
+
1
5
  *0.4.0* (December 9th, 2007)
2
6
 
3
7
  * Rails 2.0 compatibility.
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.0"
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 version = ENV['RAILS_VERSION']
8
- gem "rails", version
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.0
7
- date: 2007-12-09 00:00:00 -06:00
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