Skip to content

Commit

Permalink
Skip specs for callback aborting on Rails 4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
andrykonchin committed Nov 3, 2024
1 parent d0e321b commit 4b28635
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 0 deletions.
8 changes: 8 additions & 0 deletions spec/dynamoid/persistence_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4852,6 +4852,10 @@ def around_destroy_callback
end

it 'aborts destroying and returns false if a before_destroy callback throws :abort' do
if ActiveSupport.version < Gem::Version.new('5.0')
skip "Rails 4.x and below don't support aborting with `throw :abort`"
end

klass = new_class do
before_destroy { throw :abort }
end
Expand All @@ -4870,6 +4874,10 @@ def around_destroy_callback

describe 'destroy!' do
it 'aborts destroying and raises RecordNotDestroyed if a before_destroy callback throws :abort' do
if ActiveSupport.version < Gem::Version.new('5.0')
skip "Rails 4.x and below don't support aborting with `throw :abort`"
end

klass = new_class do
before_destroy { throw :abort }
end
Expand Down
16 changes: 16 additions & 0 deletions spec/dynamoid/transaction_write/create_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,10 @@ def around_save_callback
end

it 'aborts creation and returns false if callback throws :abort' do
if ActiveSupport.version < Gem::Version.new('5.0')
skip "Rails 4.x and below don't support aborting with `throw :abort`"
end

klass = new_class do
field :name
before_create { throw :abort }
Expand All @@ -294,6 +298,10 @@ def around_save_callback
end

it 'does not roll back the transaction when a model creation aborted by a callback' do
if ActiveSupport.version < Gem::Version.new('5.0')
skip "Rails 4.x and below don't support aborting with `throw :abort`"
end

klass_with_callback = new_class do
field :name
before_create { throw :abort }
Expand Down Expand Up @@ -642,6 +650,10 @@ def around_save_callback
end

it 'aborts creation and raises exception if callback throws :abort' do
if ActiveSupport.version < Gem::Version.new('5.0')
skip "Rails 4.x and below don't support aborting with `throw :abort`"
end

klass = new_class do
field :name
before_create { throw :abort }
Expand All @@ -658,6 +670,10 @@ def around_save_callback
end

it 'rolls back the transaction when a model creation aborted by a callback' do
if ActiveSupport.version < Gem::Version.new('5.0')
skip "Rails 4.x and below don't support aborting with `throw :abort`"
end

klass_with_callback = new_class do
field :name
before_create { throw :abort }
Expand Down
16 changes: 16 additions & 0 deletions spec/dynamoid/transaction_write/destroy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ def around_destroy_callback
end

it 'aborts destroying and returns false if callback throws :abort' do
if ActiveSupport.version < Gem::Version.new('5.0')
skip "Rails 4.x and below don't support aborting with `throw :abort`"
end

klass = new_class do
before_destroy { throw :abort }
end
Expand All @@ -155,6 +159,10 @@ def around_destroy_callback
end

it 'does not roll back the transaction when a destroying of some model aborted by a before_destroy callback' do
if ActiveSupport.version < Gem::Version.new('5.0')
skip "Rails 4.x and below don't support aborting with `throw :abort`"
end

klass = new_class do
before_destroy { throw :abort }
end
Expand Down Expand Up @@ -277,6 +285,10 @@ def around_destroy_callback
end

it 'returns false if :abort is thrown' do
if ActiveSupport.version < Gem::Version.new('5.0')
skip "Rails 4.x and below don't support aborting with `throw :abort`"
end

klass_with_callback = new_class do
before_destroy { throw :abort }
end
Expand Down Expand Up @@ -325,6 +337,10 @@ def around_destroy_callback
end

it 'aborts destroying and raises RecordNotDestroyed if callback throws :abort' do
if ActiveSupport.version < Gem::Version.new('5.0')
skip "Rails 4.x and below don't support aborting with `throw :abort`"
end

klass = new_class do
before_destroy { throw :abort }
end
Expand Down
32 changes: 32 additions & 0 deletions spec/dynamoid/transaction_write/save_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,10 @@ def around_save_callback
end

it 'aborts creation and returns false if callback throws :abort' do
if ActiveSupport.version < Gem::Version.new('5.0')
skip "Rails 4.x and below don't support aborting with `throw :abort`"
end

klass = new_class do
field :name
before_create { throw :abort }
Expand All @@ -565,6 +569,10 @@ def around_save_callback
end

it 'aborts updating and returns false if callback throws :abort' do
if ActiveSupport.version < Gem::Version.new('5.0')
skip "Rails 4.x and below don't support aborting with `throw :abort`"
end

klass = new_class do
field :name
before_update { throw :abort }
Expand All @@ -584,6 +592,10 @@ def around_save_callback
end

it 'does not roll back the transaction when a model creation aborted by a callback' do
if ActiveSupport.version < Gem::Version.new('5.0')
skip "Rails 4.x and below don't support aborting with `throw :abort`"
end

klass_with_callback = new_class do
field :name
before_create { throw :abort }
Expand Down Expand Up @@ -611,6 +623,10 @@ def around_save_callback
end

it 'does not roll back the transaction when a model updating aborted by a callback' do
if ActiveSupport.version < Gem::Version.new('5.0')
skip "Rails 4.x and below don't support aborting with `throw :abort`"
end

klass_with_callback = new_class do
field :name
before_update { throw :abort }
Expand Down Expand Up @@ -1253,6 +1269,10 @@ def around_update_callback
end

it 'aborts creation and raises exception if callback throws :abort' do
if ActiveSupport.version < Gem::Version.new('5.0')
skip "Rails 4.x and below don't support aborting with `throw :abort`"
end

klass = new_class do
field :name
before_create { throw :abort }
Expand All @@ -1273,6 +1293,10 @@ def around_update_callback
end

it 'aborts updating and raises exception if callback throws :abort' do
if ActiveSupport.version < Gem::Version.new('5.0')
skip "Rails 4.x and below don't support aborting with `throw :abort`"
end

klass = new_class do
field :name
before_update { throw :abort }
Expand All @@ -1292,6 +1316,10 @@ def around_update_callback
end

it 'rolls back the transaction when a model creation aborted by a callback' do
if ActiveSupport.version < Gem::Version.new('5.0')
skip "Rails 4.x and below don't support aborting with `throw :abort`"
end

klass_with_callback = new_class do
field :name
before_create { throw :abort }
Expand Down Expand Up @@ -1321,6 +1349,10 @@ def around_update_callback
end

it 'rolls back the transaction when a model updating aborted by a callback' do
if ActiveSupport.version < Gem::Version.new('5.0')
skip "Rails 4.x and below don't support aborting with `throw :abort`"
end

klass_with_callback = new_class do
field :name
before_update { throw :abort }
Expand Down
16 changes: 16 additions & 0 deletions spec/dynamoid/transaction_write/update_attributes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,10 @@ def around_save_callback
end

it 'aborts updating and returns false if callback throws :abort' do
if ActiveSupport.version < Gem::Version.new('5.0')
skip "Rails 4.x and below don't support aborting with `throw :abort`"
end

klass = new_class do
before_update { throw :abort }
end
Expand All @@ -270,6 +274,10 @@ def around_save_callback
end

it 'does not roll back the transaction when a model updating aborted by a callback' do
if ActiveSupport.version < Gem::Version.new('5.0')
skip "Rails 4.x and below don't support aborting with `throw :abort`"
end

klass = new_class do
before_update { throw :abort }
end
Expand Down Expand Up @@ -622,6 +630,10 @@ def around_update_callback
end

it 'aborts updating and raises exception if callback throws :abort' do
if ActiveSupport.version < Gem::Version.new('5.0')
skip "Rails 4.x and below don't support aborting with `throw :abort`"
end

klass = new_class do
field :name
before_update { throw :abort }
Expand All @@ -638,6 +650,10 @@ def around_update_callback
end

it 'rolls back the transaction when a model updating aborted by a callback' do
if ActiveSupport.version < Gem::Version.new('5.0')
skip "Rails 4.x and below don't support aborting with `throw :abort`"
end

klass = new_class do
field :name
before_update { throw :abort }
Expand Down

0 comments on commit 4b28635

Please sign in to comment.