Skip to content

Commit

Permalink
Merge pull request #139 from nronas/on-batch-request-ignore-undefined…
Browse files Browse the repository at this point in the history
…-attributes
  • Loading branch information
mullermp authored Jul 18, 2024
2 parents dc6d97b + 9e92888 commit d4c487f
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 12 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
Unreleased Changes
------------------

* Issue - Do not try to hydrate undeclared attributes from storage on `batch_read`. (#139)

2.13.0 (2023-10-17)
------------------

* Feature - Allow custom `update_expression` to be passed through to the
* Feature - Allow custom `update_expression` to be passed through to the
underlying client calls. (#137)

2.12.0 (2023-09-28)
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ group :release do
end

group :development do
gem 'pry'
gem 'rubocop'
end
3 changes: 3 additions & 0 deletions lib/aws-record/record/batch_read.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ def build_item(item, item_class)
new_item_opts = {}
item.each do |db_name, value|
name = item_class.attributes.db_to_attribute_name(db_name)

next unless name

new_item_opts[name] = value
end
item = item_class.new(new_item_opts)
Expand Down
2 changes: 2 additions & 0 deletions lib/aws-record/record/transactions.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require 'ostruct'

module Aws
module Record
module Transactions
Expand Down
30 changes: 19 additions & 11 deletions spec/aws-record/record/batch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
{ 'Food ID' => 2, 'dish' => 'Waffles', 'spicy' => false, 'gluten_free' => true }
],
'DrinkTable' => [
{ 'id' => 1, 'drink' => 'Hot Chocolate' }
{ 'id' => 1, 'drink' => 'Hot Chocolate', 'gluten_free' => true }
]
}
)
Expand All @@ -138,19 +138,27 @@
end
end

let(:actual_food) { result.items[0] }
let(:actual_breakfast) { result.items[1] }
let(:actual_drink) { result.items[2] }

it 'reads a batch of operations and returns modeled items' do
expect(result).to be_an(Aws::Record::BatchRead)
expect(result.items.size).to eq(3)
expect(result.items[0].class).to eq(food)
expect(result.items[1].class).to eq(breakfast)
expect(result.items[2].class).to eq(drink)
expect(result.items[0].dirty?).to be_falsey
expect(result.items[1].dirty?).to be_falsey
expect(result.items[2].dirty?).to be_falsey
expect(result.items[0].spicy).to be_falsey
expect(result.items[1].spicy).to be_falsey
expect(result.items[1].gluten_free).to be_truthy
expect(result.items[2].drink).to eq('Hot Chocolate')

expect(actual_food).to be_a(food)
expect(actual_food).to_not be_dirty
expect(actual_food.spicy).to be_falsey

expect(actual_breakfast).to be_a(breakfast)
expect(actual_breakfast).to_not be_dirty
expect(actual_breakfast.spicy).to be_falsey
expect(actual_breakfast.gluten_free).to be_truthy

expect(actual_drink).to be_a(drink)
expect(actual_drink).to_not be_dirty
expect(actual_drink.drink).to eq('Hot Chocolate')
expect(actual_drink).to_not respond_to(:gluten_free)
end

it 'is complete' do
Expand Down

0 comments on commit d4c487f

Please sign in to comment.