jets 1.4.10 → 1.4.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/.gitmodules +0 -3
  3. data/CHANGELOG.md +4 -0
  4. data/Gemfile +1 -0
  5. data/Gemfile.lock +6 -2
  6. data/lib/jets/application.rb +4 -0
  7. data/lib/jets/commands/templates/skeleton/Gemfile.tt +1 -0
  8. data/lib/jets/db.rb +11 -5
  9. data/lib/jets/resource/lambda/function.rb +7 -1
  10. data/lib/jets/version.rb +1 -1
  11. data/lib/jets.rb +0 -7
  12. data/vendor/jets-gems/lib/jets/gems/check.rb +2 -2
  13. metadata +2 -41
  14. data/vendor/dynomite/CHANGELOG.md +0 -45
  15. data/vendor/dynomite/Gemfile +0 -6
  16. data/vendor/dynomite/Gemfile.lock +0 -61
  17. data/vendor/dynomite/README.md +0 -141
  18. data/vendor/dynomite/Rakefile +0 -2
  19. data/vendor/dynomite/bin/console +0 -14
  20. data/vendor/dynomite/bin/setup +0 -8
  21. data/vendor/dynomite/docs/migrations/long-example.rb +0 -123
  22. data/vendor/dynomite/docs/migrations/short-example.rb +0 -40
  23. data/vendor/dynomite/dynomite.gemspec +0 -29
  24. data/vendor/dynomite/lib/dynomite/core.rb +0 -25
  25. data/vendor/dynomite/lib/dynomite/db_config.rb +0 -107
  26. data/vendor/dynomite/lib/dynomite/erb.rb +0 -53
  27. data/vendor/dynomite/lib/dynomite/item.rb +0 -292
  28. data/vendor/dynomite/lib/dynomite/log.rb +0 -15
  29. data/vendor/dynomite/lib/dynomite/migration/common.rb +0 -86
  30. data/vendor/dynomite/lib/dynomite/migration/dsl/base_secondary_index.rb +0 -73
  31. data/vendor/dynomite/lib/dynomite/migration/dsl/global_secondary_index.rb +0 -4
  32. data/vendor/dynomite/lib/dynomite/migration/dsl/local_secondary_index.rb +0 -8
  33. data/vendor/dynomite/lib/dynomite/migration/dsl.rb +0 -194
  34. data/vendor/dynomite/lib/dynomite/migration/executor.rb +0 -38
  35. data/vendor/dynomite/lib/dynomite/migration/generator.rb +0 -68
  36. data/vendor/dynomite/lib/dynomite/migration/templates/create_table.rb +0 -32
  37. data/vendor/dynomite/lib/dynomite/migration/templates/update_table.rb +0 -26
  38. data/vendor/dynomite/lib/dynomite/migration.rb +0 -27
  39. data/vendor/dynomite/lib/dynomite/version.rb +0 -3
  40. data/vendor/dynomite/lib/dynomite.rb +0 -23
  41. data/vendor/dynomite/pkg/dynomite-1.0.8.gem +0 -0
  42. data/vendor/dynomite/pkg/dynomite-1.0.9.gem +0 -0
  43. data/vendor/dynomite/pkg/dynomite-1.1.0.gem +0 -0
  44. data/vendor/dynomite/spec/fixtures/app_root/config/dynamodb.yml +0 -7
  45. data/vendor/dynomite/spec/fixtures/dynamodb/migrate/20190108061826-comments_migration.rb +0 -30
  46. data/vendor/dynomite/spec/lib/dynomite/item_spec.rb +0 -102
  47. data/vendor/dynomite/spec/lib/dynomite/migration/dsl/global_secondary_index_spec.rb +0 -106
  48. data/vendor/dynomite/spec/lib/dynomite/migration/dsl/local_secondary_index_spec.rb +0 -71
  49. data/vendor/dynomite/spec/lib/dynomite/migration/dsl_spec.rb +0 -76
  50. data/vendor/dynomite/spec/lib/dynomite/migration/generator_spec.rb +0 -23
  51. data/vendor/dynomite/spec/lib/dynomite/migration_spec.rb +0 -60
  52. data/vendor/dynomite/spec/spec_helper.rb +0 -110
@@ -1,73 +0,0 @@
1
- # Base class for LocalSecondaryIndex and GlobalSecondaryIndex
2
- class Dynomite::Migration::Dsl
3
- class BaseSecondaryIndex
4
- include Common
5
-
6
- attr_accessor :action, :key_schema, :attribute_definitions
7
- attr_accessor :index_name
8
- def initialize(action, index_name=nil, &block)
9
- @action = action.to_sym
10
- # for gsi action can be: :create, :update, :delete
11
- # for lsi action is always: :create
12
- @index_name = index_name
13
- @block = block
14
-
15
- # Dsl fills these atttributes in as methods are called within
16
- # the block
17
- @key_schema = []
18
- @attribute_definitions = []
19
- # default provisioned_throughput
20
- @provisioned_throughput = {
21
- read_capacity_units: 5,
22
- write_capacity_units: 5
23
- }
24
- end
25
-
26
- def index_name
27
- @index_name || conventional_index_name
28
- end
29
-
30
- def conventional_index_name
31
- # @partition_key_identifier and @sort_key_identifier are set as immediately
32
- # when the partition_key and sort_key methods are called in the dsl block.
33
- # Usually look like this:
34
- #
35
- # @partition_key_identifier: post_id:string
36
- # @sort_key_identifier: updated_at:string
37
- #
38
- # We strip the :string portion in case it is provided
39
- #
40
- partition_key = @partition_key_identifier.split(':').first
41
- sort_key = @sort_key_identifier.split(':').first if @sort_key_identifier
42
- [partition_key, sort_key, "index"].compact.join('-')
43
- end
44
-
45
- def evaluate
46
- return if @evaluated
47
- @block.call(self) if @block
48
- @evaluated = true
49
- end
50
-
51
- def params
52
- evaluate # lazy evaluation: wait until as long as possible before evaluating code block
53
-
54
- params = { index_name: index_name } # required for all actions
55
-
56
- if @action == :create
57
- params[:key_schema] = @key_schema # required for create action
58
- # hardcode to ALL for now
59
- params[:projection] = { # required
60
- projection_type: "ALL", # accepts ALL, KEYS_ONLY, INCLUDE
61
- # non_key_attributes: ["NonKeyAttributeName"],
62
- }
63
- end
64
-
65
- if self.is_a?(GlobalSecondaryIndex) && [:create, :update].include?(@action)
66
- # provisioned_throughput is required for gsi index definition
67
- params[:provisioned_throughput] = @provisioned_throughput
68
- end
69
-
70
- params
71
- end
72
- end
73
- end
@@ -1,4 +0,0 @@
1
- class Dynomite::Migration::Dsl
2
- class GlobalSecondaryIndex < BaseSecondaryIndex
3
- end
4
- end
@@ -1,8 +0,0 @@
1
- class Dynomite::Migration::Dsl
2
- class LocalSecondaryIndex < BaseSecondaryIndex
3
- def initialize(index_name=nil, &block)
4
- # Can only create local secondary index when creating a table
5
- super(:create, index_name, &block)
6
- end
7
- end
8
- end
@@ -1,194 +0,0 @@
1
- class Dynomite::Migration
2
- class Dsl
3
- autoload :Common, "dynomite/migration/common"
4
- autoload :BaseSecondaryIndex, "dynomite/migration/dsl/base_secondary_index"
5
- autoload :LocalSecondaryIndex, "dynomite/migration/dsl/local_secondary_index"
6
- autoload :GlobalSecondaryIndex, "dynomite/migration/dsl/global_secondary_index"
7
-
8
- include Dynomite::DbConfig
9
- include Common
10
-
11
- attr_accessor :key_schema, :attribute_definitions
12
- attr_accessor :table_name
13
- def initialize(method_name, table_name, &block)
14
- @method_name = method_name
15
- @table_name = table_name
16
- @block = block
17
-
18
- # Dsl fills in atttributes in as methods are called within the block.
19
- # Attributes for both create_table and updated_table:
20
- @attribute_definitions = []
21
- @provisioned_throughput = {
22
- read_capacity_units: 5,
23
- write_capacity_units: 5
24
- }
25
-
26
- # Attributes for create_table only:
27
- @key_schema = []
28
-
29
- # Attributes for update_table only:
30
- @gsi_indexes = []
31
- @lsi_indexes = []
32
- end
33
-
34
- # t.gsi(:create) do |i|
35
- # i.partition_key = "category:string"
36
- # i.sort_key = "created_at:string" # optional
37
- # end
38
- def gsi(action=:create, index_name=nil, &block)
39
- gsi_index = GlobalSecondaryIndex.new(action, index_name, &block)
40
- @gsi_indexes << gsi_index # store @gsi_index for the parent Dsl to use
41
- end
42
- alias_method :global_secondary_index, :gsi
43
-
44
- # t.lsi(:create) do |i|
45
- # i.partition_key = "category:string"
46
- # i.sort_key = "created_at:string" # optional
47
- # end
48
- def lsi(action=:create, index_name=nil, &block)
49
- # dont need action create but have it to keep the lsi and gsi method consistent
50
- lsi_index = LocalSecondaryIndex.new(index_name, &block)
51
- @lsi_indexes << lsi_index # store @lsi_index for the parent Dsl to use
52
- end
53
- alias_method :local_secondary_index, :lsi
54
-
55
- def evaluate
56
- return if @evaluated
57
- @block.call(self) if @block
58
- @evaluated = true
59
- end
60
-
61
- # http://docs.aws.amazon.com/sdk-for-ruby/v3/developer-guide/dynamo-example-create-table.html
62
- # build the params up from dsl in memory and provides params to the
63
- # executor
64
- def params
65
- evaluate # lazy evaluation: wait until as long as possible before evaluating code block
66
-
67
- # Not using send because think its clearer in this case
68
- case @method_name
69
- when :create_table
70
- params_create_table
71
- when :update_table
72
- params_update_table
73
- end
74
- end
75
-
76
- def params_create_table
77
- merge_lsi_attribute_definitions!
78
- merge_gsi_attribute_definitions!
79
-
80
- params = {
81
- table_name: namespaced_table_name,
82
- key_schema: @key_schema,
83
- attribute_definitions: @attribute_definitions,
84
- provisioned_throughput: @provisioned_throughput
85
- }
86
-
87
- params[:local_secondary_indexes] = lsi_secondary_index_creates unless @lsi_indexes.empty?
88
- params[:global_secondary_indexes] = gsi_secondary_index_creates unless @gsi_indexes.empty?
89
- params
90
- end
91
-
92
- def params_update_table
93
- merge_gsi_attribute_definitions!
94
-
95
- params = {
96
- table_name: namespaced_table_name,
97
- attribute_definitions: @attribute_definitions,
98
- # update table take values only some values for the "parent" table
99
- # no key_schema, update_table does not handle key_schema for the "parent" table
100
- }
101
- # only set "parent" table provisioned_throughput if user actually invoked
102
- # it in the dsl
103
- params[:provisioned_throughput] = @provisioned_throughput if @provisioned_throughput_set_called
104
- params[:global_secondary_index_updates] = global_secondary_index_updates
105
- params
106
- end
107
-
108
- # Goes thorugh all the lsi_indexes that have been built up in memory.
109
- # Find the lsi object that creates an index and then grab the
110
- # attribute_definitions from it.
111
- def merge_lsi_attribute_definitions!
112
- lsi = @lsi_indexes.first # DynamoDB only supports adding one index at a time anyway. The reason @lsi_indexes is an Array is because we're sharing the same class code for LSI and GSI
113
- if lsi
114
- lsi.evaluate # force early evaluate since we need the params to
115
- # add: gsi_attribute_definitions + lsi_attrs
116
- lsi_attrs = lsi.attribute_definitions
117
- end
118
- all_attrs = if lsi_attrs
119
- @attribute_definitions + lsi_attrs
120
- else
121
- @attribute_definitions
122
- end
123
- @attribute_definitions = all_attrs.uniq
124
- end
125
-
126
- # maps each lsi to the hash structure expected by dynamodb update_table
127
- # under the global_secondary_index_updates key:
128
- #
129
- # { create: {...} }
130
- # { update: {...} }
131
- # { delete: {...} }
132
- def lsi_secondary_index_creates
133
- @lsi_indexes.map do |lsi|
134
- lsi.params
135
- end
136
- end
137
-
138
- # maps each lsi to the hash structure expected by dynamodb update_table
139
- # under the global_secondary_index_updates key:
140
- #
141
- # { create: {...} }
142
- # { update: {...} }
143
- # { delete: {...} }
144
- def gsi_secondary_index_creates
145
- @gsi_indexes.map do |gsi|
146
- gsi.params
147
- end
148
- end
149
-
150
- # Goes thorugh all the gsi_indexes that have been built up in memory.
151
- # Find the gsi object that creates an index and then grab the
152
- # attribute_definitions from it.
153
- def merge_gsi_attribute_definitions!
154
- gsi_attrs = []
155
-
156
- gsi = @gsi_indexes.find { |i| i.action == :create }
157
- if gsi
158
- gsi.evaluate # force early evaluate since we need the params to
159
- # add: gsi_attribute_definitions + gsi_attrs
160
- gsi_attrs = gsi.attribute_definitions
161
- end
162
-
163
- # Merge existing attributes for update table
164
- all_gsi_attrs = @method_name == :update_table ?
165
- gsi_attribute_definitions + gsi_attrs :
166
- gsi_attrs
167
-
168
- all_attrs = (@attribute_definitions + all_gsi_attrs).uniq
169
- @attribute_definitions = all_attrs
170
- end
171
-
172
- # maps each gsi to the hash structure expected by dynamodb update_table
173
- # under the global_secondary_index_updates key:
174
- #
175
- # { create: {...} }
176
- # { update: {...} }
177
- # { delete: {...} }
178
- def global_secondary_index_updates
179
- @gsi_indexes.map do |gsi|
180
- { gsi.action => gsi.params }
181
- end
182
- end
183
-
184
- # >> resp = Post.db.describe_table(table_name: "demo-dev-posts")
185
- # >> resp.table.attribute_definitions.map(&:to_h)
186
- # => [{:attribute_name=>"id", :attribute_type=>"S"}]
187
- def gsi_attribute_definitions
188
- return @gsi_attribute_definitions if @gsi_attribute_definitions
189
-
190
- resp = db.describe_table(table_name: namespaced_table_name)
191
- @gsi_attribute_definitions = resp.table.attribute_definitions.map(&:to_h)
192
- end
193
- end
194
- end
@@ -1,38 +0,0 @@
1
- class Dynomite::Migration
2
- class Executor
3
- include Dynomite::DbConfig
4
-
5
- # Examples:
6
- # Executor.new(:create_table, params) or
7
- # Executor.new(:update_table, params)
8
- #
9
- # The params are generated frmo the dsl.params
10
- attr_accessor :table_name
11
- def initialize(table_name, method_name, params)
12
- @table_name = table_name
13
- @method_name = method_name # create_table or update_table
14
- @params = params
15
- end
16
-
17
- def run
18
- begin
19
- # Examples:
20
- # result = db.create_table(@params)
21
- # result = db.update_table(@params)
22
-
23
- # Leaving this verbose output in here until this DSL is more hardened to help debug
24
- unless ENV['DYNOMITE_ENV'] == 'test'
25
- puts "Calling #{@method_name} with params:"
26
- pp @params
27
- end
28
-
29
- return if ENV['DYNOMITE_DRY'] # dry run flag
30
- result = db.send(@method_name, @params)
31
-
32
- puts "DynamoDB Table: #{@table_name} Status: #{result.table_description.table_status}"
33
- rescue Aws::DynamoDB::Errors::ServiceError => error
34
- puts "Unable to #{@method_name.to_s.gsub('_',' ')}: #{error.message}".colorize(:red)
35
- end
36
- end
37
- end
38
- end
@@ -1,68 +0,0 @@
1
- require "active_support/core_ext/string"
2
-
3
- class Dynomite::Migration
4
- # jets dynamodb:generate posts --partition-key id:string
5
- class Generator
6
- include Dynomite::DbConfig
7
-
8
- attr_reader :migration_name, :table_name
9
- def initialize(migration_name, options)
10
- @migration_name = migration_name
11
- @options = options
12
- end
13
-
14
- def generate
15
- puts "Generating migration for #{@table_name}" unless @options[:quiet]
16
- return if @options[:noop]
17
- create_migration
18
- end
19
-
20
- def create_migration
21
- FileUtils.mkdir_p(File.dirname(migration_path))
22
- IO.write(migration_path, migration_code)
23
- puts "Migration file created: #{migration_path}. \nTo run:"
24
- puts " jets dynamodb:migrate #{migration_path}"
25
- end
26
-
27
- def migration_code
28
- path = File.expand_path("../templates/#{table_action}.rb", __FILE__)
29
- result = Dynomite::Erb.result(path,
30
- migration_class_name: migration_class_name,
31
- table_name: table_name,
32
- partition_key: @options[:partition_key],
33
- sort_key: @options[:sort_key],
34
- provisioned_throughput: @options[:provisioned_throughput] || 5,
35
- )
36
- end
37
-
38
- def table_action
39
- @options[:table_action] || conventional_table_action
40
- end
41
-
42
- def conventional_table_action
43
- @migration_name.include?("update") ? "update_table" : "create_table"
44
- end
45
-
46
- def table_name
47
- @options[:table_name] || conventional_table_name
48
- end
49
-
50
- # create_posts => posts
51
- # update_posts => posts
52
- def conventional_table_name
53
- @migration_name.sub(/^(create|update)_/, '')
54
- end
55
-
56
- def migration_class_name
57
- "#{@migration_name}_migration".classify # doesnt include timestamp
58
- end
59
-
60
- def migration_path
61
- "#{Dynomite.app_root}dynamodb/migrate/#{timestamp}-#{@migration_name}_migration.rb"
62
- end
63
-
64
- def timestamp
65
- @timestamp ||= Time.now.strftime("%Y%m%d%H%M%S")
66
- end
67
- end
68
- end
@@ -1,32 +0,0 @@
1
- class <%= @migration_class_name %> < Dynomite::Migration
2
- def up
3
- create_table :<%= @table_name %> do |t|
4
- t.partition_key "<%= @partition_key %>" # required
5
- <% if @sort_key # so extra spaces are not added when generated -%>
6
- t.sort_key "<%= @sort_key %>" # optional
7
- <% end -%>
8
- t.provisioned_throughput(<%= @provisioned_throughput %>) # sets both read and write, defaults to 5 when not set
9
-
10
- # Instead of using partition_key and sort_key you can set the
11
- # key schema directly also
12
- # t.key_schema([
13
- # {attribute_name: "id", :key_type=>"HASH"},
14
- # {attribute_name: "created_at", :key_type=>"RANGE"}
15
- # ])
16
- # t.attribute_definitions([
17
- # {attribute_name: "id", attribute_type: "N"},
18
- # {attribute_name: "created_at", attribute_type: "S"}
19
- # ])
20
-
21
- # other ways to set provisioned_throughput
22
- # t.provisioned_throughput(:read, 10)
23
- # t.provisioned_throughput(:write, 10)
24
- # t.provisioned_throughput(
25
- # read_capacity_units: 5,
26
- # write_capacity_units: 5
27
- # )
28
- end
29
- end
30
- end
31
-
32
- # More examples: https://github.com/tongueroo/dynomite/tree/master/docs
@@ -1,26 +0,0 @@
1
- class <%= @migration_class_name %> < Dynomite::Migration
2
- def up
3
- update_table :<%= @table_name %> do |t|
4
- t.gsi(:create) do |i|
5
- i.partition_key "<%= @partition_key %>" # required
6
- <% if @sort_key # so extra spaces are not added when generated -%>
7
- t.sort_key "<%= @sort_key %>" # optional
8
- <% end -%>
9
-
10
- i.provisioned_throughput(5)
11
- end
12
-
13
- # Examples:
14
- # t.gsi(:update, "update-me-index") do |i|
15
- # i.provisioned_throughput(10)
16
- # end
17
-
18
- # t.gsi(:delete, "delete-me-index")
19
-
20
- # Must use :create, :update, :delete one at a time in separate migration files.
21
- # DynamoDB imposes this.
22
- end
23
- end
24
- end
25
-
26
- # More examples: https://github.com/tongueroo/dynomite/tree/master/docs
@@ -1,27 +0,0 @@
1
- module Dynomite
2
- class Migration
3
- autoload :Dsl, "dynomite/migration/dsl"
4
- autoload :Generator, "dynomite/migration/generator"
5
- autoload :Executor, "dynomite/migration/executor"
6
-
7
- def up
8
- puts "Should defined an up method for your migration: #{self.class.name}"
9
- end
10
-
11
- def create_table(table_name, &block)
12
- execute_with_dsl_params(table_name, :create_table, &block)
13
- end
14
-
15
- def update_table(table_name, &block)
16
- execute_with_dsl_params(table_name, :update_table, &block)
17
- end
18
-
19
- private
20
- def execute_with_dsl_params(table_name, method_name, &block)
21
- dsl = Dsl.new(method_name, table_name, &block)
22
- params = dsl.params
23
- executor = Executor.new(table_name, method_name, params)
24
- executor.run
25
- end
26
- end
27
- end
@@ -1,3 +0,0 @@
1
- module Dynomite
2
- VERSION = "1.1.0"
3
- end
@@ -1,23 +0,0 @@
1
- $:.unshift(File.expand_path("../", __FILE__))
2
- require "dynomite/version"
3
-
4
- module Dynomite
5
- ATTRIBUTE_TYPES = {
6
- 'string' => 'S',
7
- 'number' => 'N',
8
- 'binary' => 'B',
9
- 's' => 'S',
10
- 'n' => 'N',
11
- 'b' => 'B',
12
- }
13
-
14
- autoload :Migration, "dynomite/migration"
15
- autoload :Dsl, "dynomite/dsl"
16
- autoload :DbConfig, "dynomite/db_config"
17
- autoload :Item, "dynomite/item"
18
- autoload :Core, "dynomite/core"
19
- autoload :Erb, "dynomite/erb"
20
- autoload :Log, "dynomite/log"
21
-
22
- extend Core
23
- end
Binary file
Binary file
Binary file
@@ -1,7 +0,0 @@
1
- # Throwing this in here to make tests easier to write
2
- development:
3
- endpoint: http://localhost:8000
4
-
5
- test:
6
- table_namespace: 'testnamespace'
7
- endpoint: http://localhost:8000
@@ -1,30 +0,0 @@
1
- class CommentsMigration < Dynomite::Migration
2
- def up
3
- create_table :comments do |t|
4
- t.partition_key "post_id:string" # required
5
- t.sort_key "created_at:string" # optional
6
- t.provisioned_throughput(5) # sets both read and write, defaults to 5 when not set
7
-
8
- # Instead of using partition_key and sort_key you can set the
9
- # key schema directly also
10
- # t.key_schema([
11
- # {attribute_name: "id", :key_type=>"HASH"},
12
- # {attribute_name: "created_at", :key_type=>"RANGE"}
13
- # ])
14
- # t.attribute_definitions([
15
- # {attribute_name: "id", attribute_type: "N"},
16
- # {attribute_name: "created_at", attribute_type: "S"}
17
- # ])
18
-
19
- # other ways to set provisioned_throughput
20
- # t.provisioned_throughput(:read, 10)
21
- # t.provisioned_throughput(:write, 10)
22
- # t.provisioned_throughput(
23
- # read_capacity_units: 5,
24
- # write_capacity_units: 5
25
- # )
26
- end
27
- end
28
- end
29
-
30
- # More examples: https://github.com/tongueroo/dynomite/tree/master/docs
@@ -1,102 +0,0 @@
1
- require "spec_helper"
2
-
3
- class Post < Dynomite::Item
4
- end
5
- class Comment < Dynomite::Item
6
- partition_key "post_id" # defaults to id
7
- end
8
-
9
- describe Dynomite::Item do
10
- describe "general" do
11
- it "loads attributes" do
12
- post = Post.new(title: "my title", desc: "my desc")
13
- expect(post.attrs).to eq("title" => "my title", "desc" => "my desc")
14
-
15
- post.attrs(title: "my title2")
16
- expect(post.attrs).to eq("title" => "my title2", "desc" => "my desc")
17
- end
18
-
19
- it "table_name" do
20
- expect(Post.table_name).to eq "testnamespace-posts"
21
- expect(Comment.table_name).to eq "testnamespace-comments"
22
- # hack to quickly test blank and namespaces
23
- old_namespace = Comment.instance_variable_get(:@table_namespace)
24
- Comment.instance_variable_set(:@table_namespace, '')
25
- expect(Comment.table_name).to eq "comments"
26
- Comment.instance_variable_set(:@table_namespace, old_namespace)
27
- end
28
-
29
- it "partition_key" do
30
- expect(Post.partition_key).to eq "id"
31
- expect(Comment.partition_key).to eq "post_id"
32
- end
33
- end
34
-
35
- describe "CRUD-ish" do
36
- before(:each) { Post.db = db }
37
- let(:db) { double(:db) }
38
-
39
- let(:find_resp) do
40
- fake_attributes = {"id" => "myid", "title" => "my title"}
41
- resp = double(:resp)
42
- expect(resp).to receive(:item).and_return(fake_attributes)
43
- resp
44
- end
45
- it "find" do
46
- expect(Post.db).to receive(:get_item).and_return(find_resp)
47
-
48
- post = Post.find("myid")
49
-
50
- expect(post.attrs).to eq("id" => "myid", "title" => "my title")
51
- end
52
-
53
- it "replace" do
54
- # Not returning a resp with receive because it is not useful
55
- # Dynanmodb doesnt provide much useful info there.
56
- expect(Post.db).to receive(:put_item)
57
-
58
- post = Post.new(title: "my title")
59
- post.replace
60
- attrs = post.attrs
61
-
62
- expect(attrs[:title]).to eq "my title"
63
- expect(attrs[:id].size).to eq 40 # generated unique id
64
- end
65
-
66
- it "replace with hash" do
67
- # Not returning a resp with receive because it is not useful
68
- # Dynanmodb doesnt provide much useful info there.
69
- expect(Post.db).to receive(:put_item)
70
-
71
- post = Post.new(title: "my title")
72
- post.replace(title: "my title 2")
73
- attrs = post.attrs
74
-
75
- expect(attrs[:title]).to eq "my title 2"
76
- expect(attrs[:id].size).to eq 40 # generated unique id
77
- end
78
-
79
- it "delete" do
80
- allow(Post.db).to receive(:delete_item)
81
-
82
- Post.delete("myid")
83
-
84
- expect(Post.db).to have_received(:delete_item)
85
- end
86
-
87
- let(:scan_resp) do
88
- fake_attributes = [{"id" => "myid", "title" => "my title"}]
89
- resp = double(:resp)
90
- expect(resp).to receive(:items).and_return(fake_attributes)
91
- resp
92
- end
93
- it "scan" do
94
- allow(Post.db).to receive(:scan).and_return(scan_resp)
95
-
96
- post = Post.scan
97
-
98
- expect(Post.db).to have_received(:scan)
99
- end
100
- end
101
- end
102
-