Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

ActiveResource Client Validation Tests #191

Closed
wants to merge 1 commit into from

2 participants

ken mazaika Santiago Pastorino
ken mazaika

I updated the test to include a test for ActiveModel style validation.

Santiago Pastorino
Owner

Pushed

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 14, 2011
  1. ken mazaika

    ActiveResource validation tests did not test ActiveModel validations.…

    kenmazaika authored
    … Adjust the test to be done the Rails3 way.
This page is out of date. Refresh to see the latest.
8 activeresource/test/cases/validations_test.rb
View
@@ -47,7 +47,13 @@ def test_validate_callback
p.description = 'abcd'
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
19 activeresource/test/fixtures/project.rb
View
@@ -1,25 +1,18 @@
# 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
Something went wrong with that request. Please try again.