Skip to content

Commit

Permalink
add a failing test for :virtual attributes.
Browse files Browse the repository at this point in the history
addresses #103
  • Loading branch information
apotonick committed Aug 10, 2023
1 parent 4ff896b commit dd0c391
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions test/activemodel_validation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -378,3 +378,24 @@ class ValidateEachForm2 < Reform::Form
it { _(ValidateEachForm2.new(Album.new).validate(songs: "red")).must_equal true }
end
end

class ActiveModelValidationWithIfTest < MiniTest::Spec
Session = Struct.new(:id)
# Album = Struct.new(:name, :songs, :artist)
# Artist = Struct.new(:name)

class SessionForm < Reform::Form
include Reform::Form::ActiveModel::Validations

property :id, virtual: true

validates :id, presence: true, if: -> { raise id.inspect }
end

let (:form) { SessionForm.new(Session.new(2)) }

# valid.
it do
assert_equal form.id, nil
end
end

0 comments on commit dd0c391

Please sign in to comment.