From c2f90d6530dfd0ed68df9f4c429d0f498235e1d4 Mon Sep 17 00:00:00 2001 From: taryn Date: Wed, 19 Aug 2009 11:57:50 +0100 Subject: Added validations to ActiveResource. Added a smoke test to see if we can add a validation and use it, and add a validates callback and use it. Signed-off-by: Joshua Peek --- activeresource/test/fixtures/project.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 activeresource/test/fixtures/project.rb (limited to 'activeresource/test/fixtures') diff --git a/activeresource/test/fixtures/project.rb b/activeresource/test/fixtures/project.rb new file mode 100644 index 0000000000..e15fa6f620 --- /dev/null +++ b/activeresource/test/fixtures/project.rb @@ -0,0 +1,25 @@ +# used to test validations +class Project < ActiveResource::Base + self.site = "http://37s.sunrise.i:3000" + + validates_presence_of :name + 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 + -- cgit v1.2.3