Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
AllCops:
TargetRubyVersion: 2.0.0

Documentation:
Enabled: false

Metrics/AbcSize:
Enabled: false

Metrics/BlockLength:
Exclude:
- 'features/*'
- 'spec/**/*'

Metrics/ClassLength:
Enabled: false

Metrics/LineLength:
Max: 120

Metrics/MethodLength:
Enabled: false

Metrics/ModuleLength:
Enabled: false

Security/Eval:
Exclude:
- 'features/**/*'

Style/Attr:
Exclude:
- 'lib/aws-record/record/attributes.rb'

Style/BlockDelimiters:
Exclude:
- 'spec/**/*'

Style/TrivialAccessors:
Enabled: false
6 changes: 6 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,9 @@ end
group :release do
gem 'octokit'
end

group :development do
# rubocop's TargetRubyVersion is 2.0.0
# Ruby version required less than 3.0
# gem 'rubocop', '0.50.0'
end
4 changes: 2 additions & 2 deletions features/batch/step_definitions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
And(/^a (Parent|Child) model with TableConfig of:$/) do |model, code_block|
case model
when 'Parent'
ParentTableModel = @parent
ParentTableModel = @parent # rubocop:disable Naming/ConstantName
when 'Child'
ChildTableModel = @model
ChildTableModel = @model # rubocop:disable Naming/ConstantName
else
raise 'Model must be either a Parent or Child'
end
Expand Down
42 changes: 21 additions & 21 deletions features/inheritance/step_definitions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,35 @@

Given(/^a (Parent|Child) model with definition:$/) do |model, string|
case model
when 'Parent'
@parent = Class.new do
include(Aws::Record)
end
@parent.class_eval(string)
@table_name = @parent.table_name
when 'Child'
@model = Class.new(@parent) do
include(Aws::Record)
end
@model.class_eval(string)
@table_name = @model.table_name
else
raise 'Model must be either a Parent or Child'
when 'Parent'
@parent = Class.new do
include(Aws::Record)
end
@parent.class_eval(string)
@table_name = @parent.table_name
when 'Child'
@model = Class.new(@parent) do
include(Aws::Record)
end
@model.class_eval(string)
@table_name = @model.table_name
else
raise 'Model must be either a Parent or Child'
end
end

And(/^we create a new instance of the (Parent|Child) model with attribute value pairs:$/) do |model, string|
data = JSON.parse(string)
case model
when 'Parent'
@instance = @parent.new
when 'Child'
@instance = @model.new
else
raise 'Model must be either a Parent or Child'
when 'Parent'
@instance = @parent.new
when 'Child'
@instance = @model.new
else
raise 'Model must be either a Parent or Child'
end
data.each do |row|
attribute, value = row
@instance.send(:"#{attribute}=", value)
end
end
end
2 changes: 1 addition & 1 deletion features/migrations/step_definitions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
end

Then(/^calling 'table_exists\?' on the model should return "([^"]*)"$/) do |b|
boolean = b == "false" || b.nil? ? false : true
boolean = b == 'false' || b.nil? ? false : true
expect(@model.table_exists?).to eq(boolean)
end

Expand Down
18 changes: 9 additions & 9 deletions features/searching/step_definitions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
# This is definitely a hack which takes advantage of an accident in test
# design. In the future, we'll need to have some sort of shared collection
# state to cope with the fact that scan order is not guaranteed.
page.size == 2
page.size == 2 # rubocop:disable Void
# Results do not have guaranteed order, check each expected value individually
page.each do |item|
h = item.to_h
Expand All @@ -48,19 +48,19 @@
@collection = @model.scan(exclusive_start_key: @last_evaluated_key)
end

When("we run the following search:") do |code|
SearchTestModel = @model
When('we run the following search:') do |code|
SearchTestModel = @model # rubocop:disable Naming/ConstantName
@collection = eval(code)
end

When(/^we run a heterogeneous query$/) do
@model_1 = @model.dup
@model_2 = @model.dup
@model1 = @model.dup
@model2 = @model.dup
scan = @model.build_scan.multi_model_filter do |raw_item_attributes|
if raw_item_attributes['id'] == "1"
@model_1
elsif raw_item_attributes['id'] == "2"
@model_2
if raw_item_attributes['id'] == '1'
@model1
elsif raw_item_attributes['id'] == '2'
@model2
end
end
@collection = scan.complete!
Expand Down
36 changes: 17 additions & 19 deletions features/step_definitions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,25 @@
require 'aws-record'

def cleanup_table
begin
log "Cleaning Up Table: #{@table_name}"
@client.delete_table(table_name: @table_name)
log "Cleaned up table: #{@table_name}"
@table_name = nil
rescue Aws::DynamoDB::Errors::ResourceNotFoundException
log "Cleanup: Table #{@table_name} doesn't exist, continuing."
@table_name = nil
rescue Aws::DynamoDB::Errors::ResourceInUseException => e
log "Failed to delete table, waiting to retry."
@client.wait_until(:table_exists, table_name: @table_name)
sleep(10)
retry
end
log "Cleaning Up Table: #{@table_name}"
@client.delete_table(table_name: @table_name)
log "Cleaned up table: #{@table_name}"
@table_name = nil
rescue Aws::DynamoDB::Errors::ResourceNotFoundException
log "Cleanup: Table #{@table_name} doesn't exist, continuing."
@table_name = nil
rescue Aws::DynamoDB::Errors::ResourceInUseException
log 'Failed to delete table, waiting to retry.'
@client.wait_until(:table_exists, table_name: @table_name)
sleep(10)
retry
end

Before do
@client = Aws::DynamoDB::Client.new(region: "us-east-1")
@client = Aws::DynamoDB::Client.new(region: 'us-east-1')
end

After("@dynamodb") do
After('@dynamodb') do
cleanup_table
end

Expand Down Expand Up @@ -129,16 +127,16 @@ def cleanup_table
Then(/^the DynamoDB table should have exactly the following item attributes:$/) do |string|
data = JSON.parse(string)
key = {}
data["key"].each do |row|
data['key'].each do |row|
attribute, value = row
key[attribute] = value
end
resp = @client.get_item(
table_name: @table_name,
key: key
)
expect(resp.item.keys.sort).to eq(data["item"].keys.sort)
data["item"].each do |k,v|
expect(resp.item.keys.sort).to eq(data['item'].keys.sort)
data['item'].each do |k, v|
expect(resp.item[k]).to eq(v)
end
end
2 changes: 1 addition & 1 deletion features/table_config/step_definitions.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

Given(/^a TableConfig of:$/) do |code_block|
TableConfigTestModel = @model
TableConfigTestModel = @model # rubocop:disable Naming/ConstantName
@table_config = eval(code_block)
end

Expand Down
10 changes: 5 additions & 5 deletions features/transactions/step_definitions.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# frozen_string_literal: true

When("we make a global transact_find call with parameters:") do |param_block|
When('we make a global transact_find call with parameters:') do |param_block|
params = eval(param_block)
@transact_get_result = Aws::Record::Transactions.transact_find(params)
end

When("we run the following transactional find:") do |code|
When('we run the following transactional find:') do |code|
@transact_get_result = eval(code)
end

Then("we expect a transact_find result that includes the following items:") do |result_block|
Then('we expect a transact_find result that includes the following items:') do |result_block|
tfind_result = eval(result_block)
expected = tfind_result.map do |item|
if item.nil?
Expand All @@ -28,14 +28,14 @@
expect(expected).to eq(actual)
end

When("we run the following code:") do |code|
When('we run the following code:') do |code|
begin
@arbitrary_code_ret = eval(code)
rescue StandardError => e
@arbitrary_code_exception = e
end
end

Then("we expect the code to raise an {string} exception") do |exception_class|
Then('we expect the code to raise an {string} exception') do |exception_class|
expect(@arbitrary_code_exception.class).to eq(Kernel.const_get(exception_class))
end
Loading