Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
Nikita Shilnikov
@flash-gordon
I personally only watched a talk by @solnic where he measured this
tldr we just don't mutate anything thus don't have a problem with mutation :)
Piotr Solnica
@solnic
it is too slow, deep freezing kills perf. Do it only with memoized objects that are instantiates once per process
Gustavo Caso
@GustavoCaso
:clap: :clap:
Hamza Khan-Cheema
@hamzakc
Hi, Just a quick question. I am using dry-web-roda and making a API application. I am toying with a few ideas on how to test it. How do other people test API apps? I was playing with the idea of using bacon, but would like to use Rspec. Capybara is not really used to test API's so feature tests are out. The other option is just to use rack-test directly
Oskar Szrajer
@gotar
I use rack-test always
workings great
Hamza Khan-Cheema
@hamzakc
Thanks, I was leaning towards that as well.
you got any links on getting that working with dry-web by any chance
Hamza Khan-Cheema
@hamzakc
isn't that using RSpec
Oskar Szrajer
@gotar
i uses rack-tests too
for requests
I can extract you some tests from my projects
if you want
Hamza Khan-Cheema
@hamzakc
don't want to trouble you :)
i will try and use berg as a template and get it working
thanks for the offer
you tried bacon ?
here you go, spec_helpers. and some tests
using berg as a template is quite hard at the beginning
if you need any more files, tests just ask
I used that combination (rack-test, rspec) for 4-5 different APIs in last few years always working great
Oskar Szrajer
@gotar
https://github.com/gotar/sinatra-rom - some very old repo but shows how to connects rack-test with sinatra (in roda is almost exactly the same) - much easier one
Gustavo Caso
@GustavoCaso
I think using the dry-web-roda cli will build some spec helpers with some sort of configuration already
Here is the one generated for one of my toy project
Oskar Szrajer
@gotar
yeah but it's overkill for API
and do not use rack-test in pure direct way as I remember
Gustavo Caso
@GustavoCaso
Sure
Totally true
Oskar Szrajer
@gotar
one day will be great to have --only-api switch for generator :)
one day
Gustavo Caso
@GustavoCaso
:+1:
Hamza Khan-Cheema
@hamzakc
@gotar Thanks, really appreciate it :thumbsup:
Opan Mustopah
@opan
Hi guys, is it possible to use Dry::Struct like this way?
class Foo < Dry::Struct
  # I reference the class with string
  # Just like active record do when we define relation in model
  attribute :bar, 'Zoo'
end
Well I need this feature because I have a problem when I trying to load these files.
let say if Foo is loaded first than Zoo, then if I define like the standar way, it would be trigger an error that said Zoo is undefined or something because Zoo is not loaded yet, except I define require_relative 'zoo' on top of foo.rb file and I want to avoid this.
Is it possible to do? Thanks in advance
Tim Riley
@timriley
@opan we don’t support that, no. We encourage you to require files you need :)
Adding require or require_relative for any other constants I need to refer to (like Zoo in your case) to the top of my struct class files is exactly what I do in my apps.
Opan Mustopah
@opan
I see, thanks @timriley for your answer
Chris Richards
@cmrichards
With dry-rb validation, how would I validate that 2 dates aren't more than 2 months apart?
Sean Winner
@swinner2
in dry-validation. If I use type_specs = true do I have to declare a type for each rule? Any way to only define a type spec for one rule?
Tim Riley
@timriley
@swinner2 you have to declare a spec for every key, yeah
Tim Riley
@timriley
@cmrichards something like this?
require "dry/validation"
require "time_math"

schema = Dry::Validation.Schema do
  configure do
    def self.messages
      super.merge(en: {errors: {ends_at_within_two_weeks_of_starts_at: 'must be within two weeks of start time'}})
    end
  end

  required(:starts_at).filled(:time?)
  required(:ends_at).filled(:time?)

  validate(ends_at_within_two_weeks_of_starts_at: [:starts_at, :ends_at]) do |starts_at, ends_at|
    two_weeks = 2 * 7 * 24 * 60

    (ends_at - starts_at) <= two_weeks
  end
end

valid_input = {
  starts_at: TimeMath.day.decrease(Time.now, 10),
  ends_at: Time.now,
}

schema.(valid_input).messages
# => {}

invalid_input = {
  starts_at: TimeMath.day.decrease(Time.now, 20),
  ends_at: Time.now,
}

schema.(invalid_input).messages
# => {:ends_at_within_two_weeks_of_starts_at=>["must be within two weeks of start time"]}