Permalink
Browse files

Testing giving the form builder an invalid object, and raising a more…

… sensible error message when it occurs.
  • Loading branch information...
augustl committed Mar 19, 2009
1 parent 24cc3c0 commit 0f696f6ab0bb73ed3ca82c93cb2a54ad833c64a3
View
@@ -1,6 +1,7 @@
module LiveValidations
class AdapterNotSpecified < StandardError; end
class AdapterNotFound < StandardError; end
+ class InvalidFormBuilderObject < ArgumentError; end
# Set which adapter to use. Pass the adapter class directly. Example:
#
@@ -14,7 +14,7 @@ def form_for_with_live_validations(record_name_or_array, *args, &block)
when ActiveRecord::Base
record_name_or_array
else
- raise ArgumentError, 'live_validation_form_for only supports an array (e.g. [:admin, @post]) or an active record instance (e.g. @post) as its first argument.'
+ raise InvalidFormBuilderObject, "`form_for(x, :live_validotions => true)` requires `x` to be an array (e.g. [:admin, @post]) or an active record instance (e.g. @post) as its first argument. Got an instance of `#{record_name_or_array.class}`."
end
self.adapter_instance = LiveValidations.current_adapter.new(record)
@@ -65,4 +65,13 @@ def test_validation_on_attributes_without_form_field
assert rendered_view.include?(%{"rules": {}})
assert !rendered_view.include?("post[title]")
end
+
+ def test_silly_form_for_input
+ assert_raises(LiveValidations::InvalidFormBuilderObject) {
+ render <<-eof
+ <% form_for(Object.new, :live_validations => true) do |f| %>
+ <% end %>
+ eof
+ }
+ end
end

0 comments on commit 0f696f6

Please sign in to comment.