Coder Social home page Coder Social logo

Comments (5)

bmorrall avatar bmorrall commented on July 23, 2024

Hi @Hirurg103, I'm not associated with the simple_command project, but I gave this a look.

I am not seeing this problem; I tried looking through the code and it appears to act the way you expect it to work. I wrote an rspec test to verify this behaviour, and it works as expected.

I created a new Rails, wrote a Command that recreates the errors in your example, and it still behaved as expected.

Have you found this issue to be resolved? or have I missed something while looking into it?

from simple_command.

bmorrall avatar bmorrall commented on July 23, 2024

I have missed something, not including ActiveModel::Validations does produce the errors object you are referencing.

I wrote a small gist that replicates this problem:

# app/commands/authenticate_user.rb
class AuthenticateUser
  prepend SimpleCommand
  # include ActiveModel::Validations

  def initialize(email, password)
    @email = email
    @password = password
  end

  def call
    errors.add(:email, "is invalid")
    errors.add(:email, "is from a blocked domain")
    errors.add(:password, "is too common")
    nil
  end
end

# app/controllers/authenticate_controller.rb
class AuthenticateController < ApplicationController
  def create
    load_users = AuthenticateUser.(params[:email], params[:password])
    if load_users.success?
      render json: load_users.result
    else
      render json: { errors: load_users.errors }
    end
  end
end

Output:

"errors" => {"email"=>"is from a blocked domain", "password"=>"is too common"}

from simple_command.

Hirurg103 avatar Hirurg103 commented on July 23, 2024

Hi @bmorrall , yes, this error is reproducible with pure SimpleCommand (without including ActiveModel::Validations)

from simple_command.

bmorrall avatar bmorrall commented on July 23, 2024

This PR should fix that #25

from simple_command.

juliofalbo avatar juliofalbo commented on July 23, 2024

I had the same issue, thanks for reporting and for the PR, hope they will merge it soon and release a new version. The bump from 0.0.9 would be a MAJOR release since we had break changes and not a minor how it was.

from simple_command.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.