Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add test for required_attributes

  • Loading branch information...
commit f778dd538e21e0e9b31fabdbe8baa1facb91b169 1 parent 534a6df
scambra authored
View
2  lib/globalize/active_record.rb
@@ -104,7 +104,7 @@ def quoted_translation_table_name
def required_attributes
@required_attributes ||= reflect_on_all_validations.select do |validation|
- validation.macro == :validates_presence_of && translated_attribute_names.include?(validation.name.to_s)
+ validation.macro == :validates_presence_of && translated_attribute_names.include?(validation.name)
end.map(&:name)
end
View
9 test/active_record_test.rb
@@ -433,6 +433,15 @@ class Baz < ActiveRecord::Base
blog = Blog.create
assert_nothing_raised { blog.posts.foobar }
end
+
+ test "required_attribuets don't include non-translated attributes" do
+ validations = [
+ stub(:name => :name, :macro => :validates_presence_of),
+ stub(:name => :email, :macro => :validates_presence_of)
+ ]
+ User.expects(:reflect_on_all_validations => validations)
+ assert_equal [:name], User.required_attributes
+ end
end
# TODO error checking for fields that exist in main table, don't exist in
View
5 test/data/models.rb
@@ -49,3 +49,8 @@ def do_reload
class Validatee < ActiveRecord::Base
translates :string
end
+
+class User < ActiveRecord::Base
+ translates :name
+ validates_presence_of :name, :email
+end
View
9 test/data/schema.rb
@@ -43,4 +43,13 @@
t.references :validatee
t.string :string
end
+
+ create_table :users, :force => true do |t|
+ t.string :email
+ end
+
+ create_table :users_translations, :force => true do |t|
+ t.references :user
+ t.string :name
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.