提交 1bedee56 编写于 作者: K Ken Mazaika 提交者: Santiago Pastorino

ActiveResource validation tests did not test ActiveModel validations. Adjust...

ActiveResource validation tests did not test ActiveModel validations. Adjust the test to be done the Rails3 way.
Signed-off-by: NSantiago Pastorino <santiago@wyeworks.com>
上级 47132716
......@@ -48,6 +48,12 @@ def test_validate_callback
assert p.save, "should have saved after fixing the validation, but had: #{p.errors.inspect}"
end
def test_client_side_validation_maximum
project = Project.new(:description => '123456789012345')
assert ! project.valid?
assert_equal ['is too long (maximum is 10 characters)'], project.errors[:description]
end
protected
# quickie helper to create a new project with all the required
......
# used to test validations
class Project < ActiveResource::Base
self.site = "http://37s.sunrise.i:3000"
schema do
string :email
string :name
end
validates_presence_of :name
validates :name, :presence => true
validates :description, :presence => false, :length => {:maximum => 10}
validate :description_greater_than_three_letters
# to test the validate *callback* works
def description_greater_than_three_letters
errors.add :description, 'must be greater than three letters long' if description.length < 3 unless description.blank?
end
# stop-gap accessor to default this attribute to nil
# Otherwise the validations fail saying that the method does not exist.
# In future, method_missing will be updated to not explode on a known
# attribute.
def name
attributes['name'] || nil
end
def description
attributes['description'] || nil
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册