Skip to content

Commit

Permalink
Allow GSI in TableConfig without capacity settings (#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
jterapin authored Aug 21, 2024
1 parent a6f2aa8 commit 18456f6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Unreleased Changes
------------------

* Issue - Allow `global_secondary_index` to be defined in `TableConfig` without
supplying capacity settings. (#140)

2.13.1 (2024-07-18)
------------------

Expand Down
2 changes: 1 addition & 1 deletion lib/aws-record/record/table_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def write_capacity_units(units)
# @api private
def global_secondary_index(name, &block)
gsi = GlobalSecondaryIndex.new
gsi.instance_eval(&block)
gsi.instance_eval(&block) if block_given?
@global_secondary_indexes[name] = gsi
end

Expand Down
28 changes: 19 additions & 9 deletions spec/aws-record/record/table_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,26 @@ def configure_test_client(client)
end
end

it 'accepts global secondary indexes in the definition' do
TableConfig.define do |t|
t.model_class(TestModelWithGsi)
t.read_capacity_units(2)
t.write_capacity_units(2)
t.global_secondary_index(:gsi) do |i|
i.read_capacity_units(1)
i.write_capacity_units(1)
context 'global secondary indexes' do
it 'accepts with capacity settings defined' do
TableConfig.define do |t|
t.model_class(TestModelWithGsi)
t.read_capacity_units(2)
t.write_capacity_units(2)
t.global_secondary_index(:gsi) do |i|
i.read_capacity_units(1)
i.write_capacity_units(1)
end
t.client_options(stub_responses: true)
end
end

it 'accepts without capacity settings defined' do
TableConfig.define do |t|
t.model_class(TestModelWithGsi)
t.global_secondary_index(:gsi)
t.client_options(stub_responses: true)
end
t.client_options(stub_responses: true)
end
end

Expand Down

0 comments on commit 18456f6

Please sign in to comment.