homeschool 0.0.1.38 → 0.0.1.41

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,24 @@
1
+ module Homeschool::ControllerExtensions
2
+ # Add find_object, model_name
3
+ module ClassMethods
4
+ def find_object(options={})
5
+ find_by_id(model_name, {:only => [:update, :edit, :show, :destroy]}.merge(options))
6
+ end
7
+
8
+ def find_by_id(klass, options={})
9
+ options = {:name => klass.name.underscore, :param => :id}.merge(options)
10
+ before_filter options.filter(:only, :except) do |controller|
11
+ controller.send(:instance_variable_set, options[:name].to_sym.iv, klass.find(controller.params[options[:param]]))
12
+ end
13
+ end
14
+
15
+ def model_name
16
+ name.sub(/Controller$/, '').singularize.underscore
17
+ end
18
+
19
+ def model_class
20
+ model_name.classify.constantize
21
+ end
22
+ end
23
+ end
24
+ ActionController::Base.add_extension(Homeschool::ControllerExtensions)
@@ -2,12 +2,12 @@ require 'test/unit'
2
2
  module Homeschool::StandardizedTest; end
3
3
  module Homeschool::StandardizedTest::Assertions
4
4
  module InstanceMethods
5
- def assert_fails
5
+ def assert_fails(message="")
6
6
  yield
7
7
  passed = true
8
8
  rescue
9
9
  ensure
10
- assert !passed
10
+ assert !passed, message
11
11
  end
12
12
 
13
13
  def diff(one, two)
@@ -33,6 +33,7 @@ module Homeschool::StandardizedTest::Assertions
33
33
  assert_equal_without_diffing(expected, actual, message)
34
34
  end
35
35
  end
36
+
36
37
  def self.included(klass)
37
38
  klass.send :alias_method, :assert_equal_without_diffing, :assert_equal
38
39
  klass.send :alias_method, :assert_equal, :assert_equal_with_diffing
@@ -50,21 +51,39 @@ module HomeschoolTestHelper
50
51
  klass.rdef(/last_(.*)/) do |match|
51
52
  match[1].classify.constantize.find(:all).last
52
53
  end
53
- class << klass
54
- def homeschool_fixtures(*fixtures)
55
- fixtures.each do |fixture|
56
- fixture_class = fixture.to_s.classify.constantize
57
- rdef(/.*#{fixture_class.name.underscore}.*/) do |match, *options|
58
- iv_cache(match[0]) do
59
- options = {:save => true}.merge(options[0] || {})
60
- save = options.delete(:save)
61
- instance = fixture_class.new(options)
62
- instance.save if save && instance.respond_to?(:save)
63
- instance
64
- end
54
+ end
55
+ end
56
+
57
+ module Homeschool::StandardizedTest::RailsExtentions
58
+ def self.included(klass)
59
+ klass.add_extension(self)
60
+ end
61
+
62
+ def self.extended(klass)
63
+ (klass.class == Class ? klass : klass.class).add_extension(self)
64
+ end
65
+
66
+ module ClassMethods
67
+ def homeschool_fixtures(*fixtures)
68
+ fixtures.each do |fixture|
69
+ fixture_class = fixture.to_s.classify.constantize
70
+ rdef(/.*#{fixture_class.name.underscore}.*/) do |match, *options|
71
+ iv_cache(match[0]) do
72
+ options = {:save => true}.merge(options[0] || {})
73
+ save = options.delete(:save)
74
+ instance = fixture_class.new(options)
75
+ instance.save if save && instance.respond_to?(:save)
76
+ instance
65
77
  end
66
78
  end
67
79
  end
68
80
  end
69
81
  end
70
- end
82
+ module InstanceMethods
83
+ # last(:person)
84
+ def last(sym)
85
+ sym.to_s.classify.constantize.find(:first, :order => 'id DESC')
86
+ end
87
+ end
88
+ end
89
+ Test::Unit::TestCase.add_extension(Homeschool::StandardizedTest::RailsExtentions) if defined?(RAILS_ENV) && RAILS_ENV == 'test'
data/lib/tame_rails.rb CHANGED
@@ -1,24 +1,3 @@
1
1
  require 'form_buildr'
2
2
  require 'model_extensions'
3
-
4
- # Add find_object, model_name
5
- class ActionController::Base
6
- def self.find_object(options={})
7
- find_by_id(model_name, {:only => [:update, :edit, :show, :destroy]}.merge(options))
8
- end
9
-
10
- def self.find_by_id(klass, options={})
11
- options = {:name => klass.name.underscore, :param => :id}.merge(options)
12
- before_filter options.filter(:only, :except) do |controller|
13
- controller.send(:instance_variable_set, options[:name].to_sym.iv, klass.find(controller.params[options[:param]]))
14
- end
15
- end
16
-
17
- def self.model_name
18
- name.sub(/Controller$/, '').singularize.underscore
19
- end
20
-
21
- def self.model_class
22
- model_name.classify.constantize
23
- end
24
- end
3
+ require 'controller_extensions'
@@ -24,13 +24,6 @@ end
24
24
  class HomeschoolTest < Test::Unit::TestCase
25
25
  include HomeschoolTestHelper
26
26
  include RdefHelper
27
- homeschool_fixtures :chickens
28
-
29
- def test_fixtures
30
- assert_equal red_chicken, red_chicken
31
- assert_not_equal red_chicken, blue_chicken
32
- assert_equal 3, chicken_experiment(:feet => 3).feet
33
- end
34
27
 
35
28
  def test_last
36
29
  assert_equal 2, last_chicken
@@ -0,0 +1,27 @@
1
+ TEST_ENV = true
2
+ require 'test/unit'
3
+ require File.dirname(__FILE__) + "/../lib/homeschool"
4
+ Test::Unit::TestCase.add_extension(Homeschool::StandardizedTest::RailsExtentions)
5
+
6
+ class Chicken
7
+ attr_accessor :feet
8
+ def initialize(properties)
9
+ @feet = properties[:feet]
10
+ end
11
+ def self.find(*args)
12
+ args[0] == :first && args[1][:order].include?('DESC') || [2]
13
+ end
14
+ end
15
+
16
+ class StandardizedTestTest < Test::Unit::TestCase
17
+ homeschool_fixtures :chickens
18
+ def test_last
19
+ assert last(:chicken)
20
+ end
21
+
22
+ def test_fixtures
23
+ assert_equal red_chicken, red_chicken
24
+ assert_not_equal red_chicken, blue_chicken
25
+ assert_equal 3, chicken_experiment(:feet => 3).feet
26
+ end
27
+ end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: homeschool
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.1.38
7
- date: 2007-10-07 00:00:00 -04:00
6
+ version: 0.0.1.41
7
+ date: 2007-10-08 00:00:00 -04:00
8
8
  summary: The homeschool gem
9
9
  require_paths:
10
10
  - lib
@@ -38,7 +38,9 @@ files:
38
38
  - bin/svm
39
39
  - test/homeschool_test.rb
40
40
  - test/module_tests.rb
41
+ - test/standardized_test_test.rb
41
42
  - test/the_test.rb
43
+ - lib/controller_extensions.rb
42
44
  - lib/fight.rb
43
45
  - lib/form_buildr.rb
44
46
  - lib/homeschool.rb