These are chat archives for dry-rb/chat

Aug 2018
Aug 01 2018 08:37

i’m working thru the workshop-app, and can’t figure out this error:

 $ bundle exec rspec

An error occurred while loading ./spec/admin/unit/articles/form_schema_spec.rb.
Failure/Error: require "blog/admin/articles/form_schema"

  Nothing registered with the key "#”

Relevant code:

require "dry/validation"
require "types"

module Blog
  module Admin
    module Articles
      FormSchema = Dry::Validation.Form do
        required(:status).filled(type?: Types::ArticleStatus)

and types.rb:

module Types
  include Dry::Types.module
  ArticleStatus = Strict::String.enum('draft', 'published', 'archived')

what’s going wrong here?

Tim Riley
Aug 01 2018 09:57
@jonahx can you run rspec with -b and show the backtrace?
I haven’t looked at that codebase in >9mos, but I’ll try to help
Piotr Solnica
Aug 01 2018 10:55
type? doesn't work the way you think it works, see here
I'd do this required(:status).filled(included_in?: Types::ArticleStatus.values)
Tim Riley
Aug 01 2018 11:06
yeah, that what I have done/would do
I never had type?: Types::ArticleStatus in the workshop exercises I ran people through
Aug 01 2018 13:41

Hi, I have a problem with dry-container

I want to test a transaction who have Redis connection for pub/sub and cache.

I have a RedisContainer who register the redis instance, and I have PublishContainer CacheContainer who have the logic about publishing and caching.

My transaction have

    include Dry::AutoInject(RedisContainer)['redis_instance']
    include Dry::AutoInject(PublishContainer)['publisher']
    include Dry::AutoInject(CacheContainer)[cacher: 'cache.increment']
    def publish(input)
      publisher.('hit:created', input[:hit].id, instance: redis_instance)

I don't want to my transaction to be dependent about my RedisContainer, but I need it for my spec, any idea?

Aug 01 2018 14:32
It work with
module CacheContainer
  extend Dry::Container::Mixin
  merge RedisContainer
Aug 01 2018 17:33

@solnic ty for the clarification re:

required(:status).filled(included_in?: Types::ArticleStatus.values)

that said, the above feels to me like pushing too implementation details onto the client vs the way i had expected it to work:

required(:status).filled(type?: Types::ArticleStatus)

The latter is also more consistent with the way built in types work.

I’d expect the type itself to be able to say if something was a valid instance (eg, this is how the sanctuary-def project works), and then the FormSchema would be delegating to that, and my original code would be a one liner to implement within the Schema lib code. Whereas here the client of the form schema needs to know how enums work and manually write part of the validation. Do you agree this is not ideal or am I missing something?