Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BE validation for supply product #378

Merged

Conversation

marlena-b
Copy link
Collaborator

Issue: #373

This PR adds BE validations for supply product form. This validations checks if the quantity is integer greater than 0 and if not, the proper validation error is rendered.
Zrzut ekranu 2024-08-14 o 13 51 28

Copy link

netlify bot commented Aug 14, 2024

Deploy Preview for ecommerce-events failed.

Name Link
🔨 Latest commit 2053208
🔍 Latest deploy log https://app.netlify.com/sites/ecommerce-events/deploys/66bc9b8621db990008fedd28

Comment on lines +3 to +11
include ActiveModel::Model
include ActiveModel::Validations

attr_reader :product_id, :quantity

def initialize(params)
@product_id = params[:product_id]
@quantity = params[:quantity]
end
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't use ActiveModel::Attributes like in other places because then only_integer: true does not work as expected. It seems like ActiveModel::Attributes converts the value to integer during the initialization of the object. This is problematic because "abc".to_i # => 0, so the validation error was "Quantity must be greater than 0" instead of "Quantity is not a number".

@marlena-b marlena-b marked this pull request as ready for review August 14, 2024 12:06
Copy link
Collaborator

@lukaszreszke lukaszreszke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done :)

@marlena-b marlena-b merged commit 360e274 into RailsEventStore:master Aug 19, 2024
0 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants