Skip to content

Commit 427d736

Browse files
committed
Properly handle suppressed: false on create/update
1 parent 18064fd commit 427d736

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

app/controllers/items_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def set_item
6767

6868
# Only allow a list of trusted parameters through.
6969
def item_params
70-
@item_params ||= jsonapi_deserialize(params, only: Item::EDIT_ATTRS).transform_values(&:presence)
70+
@item_params ||= jsonapi_deserialize(params, only: Item::EDIT_ATTRS).transform_values { |v| v unless v.nil? }
7171
end
7272

7373
def ensure_image_param!

spec/requests/items_spec.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,8 @@ def to_relationships(terms: nil, image: nil)
360360
value: '800',
361361
appraisal_date: '2006',
362362
notes: '17741786',
363-
reserve_date: Date.new(2019, 9, 16) # '2019-09-16'
363+
reserve_date: Date.new(2019, 9, 16), # '2019-09-16'
364+
suppressed: false
364365
}
365366
end
366367

@@ -400,6 +401,7 @@ def expected_errors_for(attributes, terms: valid_terms, image: valid_image, item
400401
relationships: valid_relationships
401402
}
402403
}
404+
# TODO: figure out how to test w/suppressed as JSON boolean rather than string
403405
expect { post items_url, params: payload, as: :jsonapi }.to change(Item, :count).by(1)
404406

405407
expect(response).to have_http_status(:created)
@@ -469,10 +471,11 @@ def expected_errors_for(attributes, terms: valid_terms, image: valid_image, item
469471
end
470472

471473
it 'accepts a suppressed item without an image' do
474+
expected_attributes = valid_attributes.merge(suppressed: true)
472475
payload = {
473476
data: {
474477
type: 'item',
475-
attributes: valid_attributes.merge(suppressed: true),
478+
attributes: expected_attributes,
476479
relationships: to_relationships(terms: valid_terms)
477480
}
478481
}
@@ -486,7 +489,7 @@ def expected_errors_for(attributes, terms: valid_terms, image: valid_image, item
486489

487490
item = Item.find(item_id)
488491
expect(item).not_to be_nil
489-
valid_attributes.each { |attr, val| expect(item.send(attr)).to eq(val) }
492+
expected_attributes.each { |attr, val| expect(item.send(attr)).to eq(val) }
490493

491494
expect(item.terms).to contain_exactly(*valid_terms)
492495
expect(item.image).to be_nil

0 commit comments

Comments
 (0)