Skip to content

Commit

Permalink
@wip Add missing specs (save_spec.rb)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrykonchin committed Oct 12, 2024
1 parent 4de4279 commit ad6cf00
Show file tree
Hide file tree
Showing 2 changed files with 403 additions and 123 deletions.
43 changes: 22 additions & 21 deletions spec/dynamoid/transaction_write/create_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,25 @@

expect {
described_class.execute do |txn|
txn.create klass, name: 'three'
txn.create klass, name: 'Alex'
end
}.to change { klass.count }.by(1)

obj = klass.last
expect(obj.name).to eql('three')
expect(obj.name).to eql 'Alex'
end

it 'returns a new model' do
klass.create_table

obj = nil
described_class.execute do |txn|
obj = txn.create klass, name: 'three'
obj = txn.create klass, name: 'Alex'
end

expect(obj).to be_a(klass)
expect(obj).to be_persisted
expect(obj.name).to eql 'three'
expect(obj.name).to eql 'Alex'
end

describe 'primary key schema' do
Expand All @@ -41,7 +41,7 @@

expect {
described_class.execute do |txn|
txn.create klass, name: 'three'
txn.create klass, name: 'Alex'
end
}.to change { klass.count }.by(1)
end
Expand All @@ -53,7 +53,7 @@

expect {
described_class.execute do |txn|
txn.create klass_with_composite_key, name: 'three', age: 3
txn.create klass_with_composite_key, name: 'Alex', age: 3
end
}.to change { klass_with_composite_key.count }.by(1)
end
Expand All @@ -71,11 +71,11 @@

obj = nil
described_class.execute do |txn|
obj = txn.create klass, name: 'three'
obj = txn.create klass, name: 'Alex'
end

expect(obj.created_at.to_i).to eql(time_now.to_i)
expect(obj.updated_at.to_i).to eql(time_now.to_i)
expect(obj.created_at.to_i).to eql time_now.to_i
expect(obj.updated_at.to_i).to eql time_now.to_i
end
end

Expand All @@ -88,15 +88,15 @@
obj = txn.create klass, created_at: created_at, updated_at: updated_at
end

expect(obj.created_at.to_i).to eql(created_at.to_i)
expect(obj.updated_at.to_i).to eql(updated_at.to_i)
expect(obj.created_at.to_i).to eql created_at.to_i
expect(obj.updated_at.to_i).to eql updated_at.to_i
end
end

it 'does not raise error if Config.timestamps=false', config: { timestamps: false } do
expect {
described_class.execute do |txn|
txn.create klass
txn.create klass, {}
end
}.not_to raise_error
end
Expand Down Expand Up @@ -157,12 +157,12 @@

context 'when an issue detected on the DynamoDB side' do
it 'rolls back the changes when id is not unique' do
existing = klass.create!(name: 'one')
existing = klass.create!(name: 'Alex')

expect {
described_class.execute do |txn|
txn.create! klass, name: 'one', id: existing.id
txn.create! klass, name: 'two'
txn.create! klass, name: 'Alex', id: existing.id
txn.create! klass, name: 'Michael'
end
}.to raise_error(Aws::DynamoDB::Errors::TransactionCanceledException)

Expand All @@ -171,11 +171,12 @@
end
end

# TODO test each callback separately
it 'uses callbacks' do
klass_with_callbacks.create_table
expect {
described_class.execute do |txn|
txn.create! klass_with_callbacks, name: 'two'
txn.create! klass_with_callbacks, name: 'Alex'
end
}.to output('validating validated saving creating created saved ').to_stdout
end
Expand All @@ -184,7 +185,7 @@
klass_with_around_callbacks.create_table
expect {
described_class.execute do |txn|
txn.create! klass_with_around_callbacks, name: 'two'
txn.create! klass_with_around_callbacks, name: 'Alex'
end
}.to output('saving creating created saved ').to_stdout
end
Expand All @@ -198,25 +199,25 @@

expect {
described_class.execute do |txn|
txn.create! klass, name: 'three'
txn.create! klass, name: 'Alex'
end
}.to change { klass.count }.by(1)

obj = klass.last
expect(obj.name).to eql('three')
expect(obj.name).to eql 'Alex'
end

it 'returns a new model' do
klass.create_table

obj = nil
described_class.execute do |txn|
obj = txn.create! klass, name: 'three'
obj = txn.create! klass, name: 'Alex'
end

expect(obj).to be_a(klass)
expect(obj).to be_persisted
expect(obj.name).to eql 'three'
expect(obj.name).to eql 'Alex'
end

describe 'validation' do
Expand Down
Loading

0 comments on commit ad6cf00

Please sign in to comment.