Skip to content

Commit

Permalink
Allow saving empty arrays
Browse files Browse the repository at this point in the history
Closes #294
  • Loading branch information
paulcsmith committed Mar 17, 2020
1 parent bb57679 commit 309ad03
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions spec/save_operation_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ describe "Avram::SaveOperation" do
operation.required_attributes.should eq({operation.title})
end

it "can save empty arrays" do
bucket = BucketBox.create

bucket = Bucket::SaveOperation.update!(bucket, names: [] of String)

bucket.names.should eq([] of String)
end

it "set params if passed in" do
now = Time.utc.at_beginning_of_minute
user = SaveUser.create!(name: "Dan", age: 34, joined_at: now)
Expand Down
2 changes: 1 addition & 1 deletion src/avram/validations.cr
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ module Avram::Validations
# ```
def validate_required(*attributes, message : Avram::Attribute::ErrorMessage = "is required")
attributes.each do |attribute|
if attribute.value.blank? && attribute.value != false
if (attribute.value.blank? || attribute.value == false) && !attribute.value.is_a?(Array)
attribute.add_error message
end
end
Expand Down

0 comments on commit 309ad03

Please sign in to comment.