Skip to content

Commit 9dfc15e

Browse files
authored
Merge pull request #379 from balvig/main
Support usage of `invalid?` and `validate!` methods from `ActiveModel::Validations`
2 parents 1d93405 + 74cf29e commit 9dfc15e

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/active_resource/validations.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def load_remote_errors(remote_errors, save_cache = false) # :nodoc:
160160
# my_person.valid?
161161
# # => false
162162
#
163-
def valid?
163+
def valid?(context = nil)
164164
run_callbacks :validate do
165165
super
166166
load_remote_errors(@remote_errors, true) if defined?(@remote_errors) && @remote_errors.present?

test/cases/validations_test.rb

+12
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,18 @@ def test_client_side_validation_maximum
5656
assert_equal ["is too long (maximum is 10 characters)"], project.errors[:description]
5757
end
5858

59+
def test_invalid_method
60+
p = new_project
61+
62+
assert_not p.invalid?
63+
end
64+
65+
def test_validate_bang_method
66+
p = new_project(name: nil)
67+
68+
assert_raise(ActiveModel::ValidationError) { p.validate! }
69+
end
70+
5971
protected
6072
# quickie helper to create a new project with all the required
6173
# attributes.

0 commit comments

Comments
 (0)