public
Description: enhanced form handling for rails applications
Homepage: http://upstream-berlin.com/blog/open-source/#forms_fu
Clone URL: git://github.com/langalex/forms-fu.git
fixed a bug where defining a validation in a subclass using STI resulted in a 
stack overflow error
Alexander Lang (author)
Tue Jul 15 09:33:29 -0700 2008
commit  8469f585cf3aa63ece237d805b13ac2a680135ef
tree    3610a89930b2cd22e7a91eedae3986b334dafc05
parent  148beee065627a92cab7c1aa1c1e38f20c2f35ea
...
12
13
14
15
16
17
18
 
 
 
 
 
 
19
20
21
...
12
13
14
 
 
 
 
15
16
17
18
19
20
21
22
23
0
@@ -12,10 +12,12 @@ module ValidationReflection
0
       
0
       public
0
       
0
-      class <<self
0
-        alias_method_chain :validates_presence_of, :reflection
0
-        alias_method_chain :validates_acceptance_of, :reflection
0
-        alias_method_chain :validates_inclusion_of, :reflection
0
+      unless self.respond_to? :validates_presence_of_without_reflection
0
+        class <<self
0
+          alias_method_chain :validates_presence_of, :reflection
0
+          alias_method_chain :validates_acceptance_of, :reflection
0
+          alias_method_chain :validates_inclusion_of, :reflection
0
+        end
0
       end
0
     end
0
   end
...
2
3
4
5
 
6
7
8
...
14
15
16
 
 
 
 
17
18
19
...
43
44
45
 
 
 
 
46
47
...
2
3
4
 
5
6
7
8
...
14
15
16
17
18
19
20
21
22
23
...
47
48
49
50
51
52
53
54
55
0
@@ -2,7 +2,7 @@ require File.join(File.dirname(__FILE__), '..', 'helper')
0
 require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'validation_reflection')
0
 
0
 ActiveRecord::Base.connection.execute 'DROP TABLE test_users' rescue nil
0
-ActiveRecord::Base.connection.execute 'CREATE TABLE test_users (id int(4), first_name varchar(255), last_name varchar(255))'
0
+ActiveRecord::Base.connection.execute 'CREATE TABLE test_users (id int(4), first_name varchar(255), last_name varchar(255), type varchar(255))'
0
 
0
 class TestUser < ActiveRecord::Base
0
   validates_presence_of :name
0
@@ -14,6 +14,10 @@ class TestUser < ActiveRecord::Base
0
   validates_inclusion_of :optional_status_2, :in => ['new', 'old'], :allow_nil => true
0
 end
0
 
0
+class TestPremiumUser < TestUser
0
+  validates_presence_of :name
0
+end
0
+
0
 describe TestUser, 'required_field' do
0
   
0
   it "should require a field with validates_presence_of" do
0
@@ -43,5 +47,9 @@ describe TestUser, 'required_field' do
0
   it "should not require a field with an :on option not set to :create" do
0
     TestUser.should_not be_required_field(:on_update_field)
0
   end
0
+  
0
+  it "should work with single table inheritance" do
0
+    TestPremiumUser.should be_required_field(:name)
0
+  end
0
 end
0
 

Comments