From dd0c391dbdc01133d40aad30d2e417acb9d21116 Mon Sep 17 00:00:00 2001 From: Nick Sutterer Date: Thu, 10 Aug 2023 12:26:31 +0200 Subject: [PATCH] add a failing test for :virtual attributes. addresses https://github.com/trailblazer/reform-rails/issues/103 --- test/activemodel_validation_test.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test/activemodel_validation_test.rb b/test/activemodel_validation_test.rb index eb9d6e3..682718a 100644 --- a/test/activemodel_validation_test.rb +++ b/test/activemodel_validation_test.rb @@ -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