Skip to content

Commit

Permalink
hotfix: unfreeze items of esse_callback to let it be defined in same …
Browse files Browse the repository at this point in the history
…group for each type
  • Loading branch information
marcosgz committed Jul 10, 2024
1 parent 613c3e8 commit d01d46c
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
esse-active_record (0.3.1)
esse-active_record (0.3.2)
activerecord (>= 4.2, < 8)
esse (>= 0.3.0)

Expand Down
2 changes: 1 addition & 1 deletion ci/Gemfile.rails-5.2.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
esse-active_record (0.3.1)
esse-active_record (0.3.2)
activerecord (>= 4.2, < 8)
esse (>= 0.3.0)

Expand Down
2 changes: 1 addition & 1 deletion ci/Gemfile.rails-6.0.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
esse-active_record (0.3.1)
esse-active_record (0.3.2)
activerecord (>= 4.2, < 8)
esse (>= 0.3.0)

Expand Down
2 changes: 1 addition & 1 deletion ci/Gemfile.rails-6.1.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
esse-active_record (0.3.1)
esse-active_record (0.3.2)
activerecord (>= 4.2, < 8)
esse (>= 0.3.0)

Expand Down
2 changes: 1 addition & 1 deletion ci/Gemfile.rails-7.0.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
esse-active_record (0.3.1)
esse-active_record (0.3.2)
activerecord (>= 4.2, < 8)
esse (>= 0.3.0)

Expand Down
2 changes: 1 addition & 1 deletion ci/Gemfile.rails-7.1.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
esse-active_record (0.3.1)
esse-active_record (0.3.2)
activerecord (>= 4.2, < 8)
esse (>= 0.3.0)

Expand Down
2 changes: 1 addition & 1 deletion lib/esse/active_record/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def esse_callback(index_repo_name, operation_name, on: %i[create update destroy]
raise ArgumentError, format('index repository %<name>p already registered %<op>s operation', name: index_repo_name, op: operation_name)
end

@esse_callbacks[index_repo_name] ||= {}
@esse_callbacks[index_repo_name] = @esse_callbacks[index_repo_name]&.dup || {}
@esse_callbacks[index_repo_name][identifier] = [klass, options, block]

after_commit(on: event, if: if_enabled) do
Expand Down
2 changes: 1 addition & 1 deletion lib/esse/active_record/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module Esse
module ActiveRecord
VERSION = '0.3.1'
VERSION = '0.3.2'
end
end
15 changes: 15 additions & 0 deletions spec/esse/active_record/model/esse_callback_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,21 @@ class DumpTempCallbackOnDestroy < DumpTempCallback; end
end
end

it 'allows to define multiple callbacks in the same model' do
model_class.esse_callback('states:state', :temp, on: :create) { :ok }
expect {
model_class.esse_callback('states:state', :temp, on: :update) { :ok }
}.not_to raise_error
expect(model_class.esse_callbacks).to a_hash_including(
'states:state' => a_hash_including(
temp_on_create: contain_exactly(DumpTempCallbackOnCreate, {}, an_instance_of(Proc)),
temp_on_update: contain_exactly(DumpTempCallbackOnUpdate, {}, an_instance_of(Proc)),
)
)
expect(model_class.esse_callbacks).to be_frozen
expect(model_class.esse_callbacks['states:state']).to be_frozen
end

context 'when on :create' do
it 'raises an error when the callback is not registered' do
expect {
Expand Down

0 comments on commit d01d46c

Please sign in to comment.