trailblazer / reform

Form objects decoupled from models.
https://trailblazer.to/2.1/docs/reform.html
MIT License
2.5k stars 184 forks source link

Out of the box dry-validation not working #500

Closed Xanthus closed 5 years ago

Xanthus commented 5 years ago

Been toying with the idea of using Trailblazer operations in an existing app for a while (already using Cells) so added the following to our Gemfile:

gem 'trailblazer-operation'
gem 'trailblazer-macro'  
gem 'trailblazer-macro-contract'
gem 'dry-validation'
gem 'reform'  #Also tried 'reform-rails', no change

which resulted in the following being pulled:

dry-validation (1.3.1)
reform (2.2.4)
trailblazer-activity (0.10.0)
trailblazer-operation (0.6.0)
trailblazer-macro-contract (2.1.0)
trailblazer-macro (2.1.0)

I added the following initializer:

require "reform/form/dry"

Reform::Form.class_eval do
  feature Reform::Form::Dry
end

And wrote a simple test class to hook into a simple Create operation:

class Contract::Create < Reform::Form
  property :name

  validation do
    required(:name).filled
  end
end

Initially the app refused to boot with:

LoadError:
  cannot load such file -- dry/validation/schema/form

Which I traced back to this line. I looked into the dry-validation gem and that file was removed from v1.0.0 on 10 June 2019.

I tried pegging the dry-validation version in my Gemfile with 0.13, 0.12, 0.11 and 0.10 (where that file still existed). The require line in Reform no longer caused a LoadError but the basic example still fails (see below). I haven't managed to find a version that works and gave up on Reform/Trailblazer Operations for now.

NoMethodError:
  undefined method `Form' for Dry::Validation:Module
  Did you mean?  for

Bottom line, out of the box Reform using Dry doesn't work (at least for me and I could be doing something stupid) using the instructions given and it's non-trivial to sort out. Sadly I'm a bit pressed for time so I can't contribute to a fix besides this issue but I think a fair bit of work needs to go into dependency loading and version checking - or possibly a separate reform-dry gem that bundles the right version of dry-validation and hooks it into Reform. Easier said than done, I know :)

EDITS: Me fixing some mistakes in the issue and editing out some problems which were caused by me.

emaglio commented 5 years ago

@Xanthus thanks for reporting this - can you please use branch v2.3.rc2 for reform? Version 2.2.4 has well known issues and we are working on releasing 2.3.0 which will include compatibility with any version of dry-v. I'm going to close this since refers to an old "unsupported" reform version :+1: