aasm/spec/unit
Daniel Nolan 5d22f691fe Fix ClassInvoker instantiating class twice
* I'm in the process of updating a rails app from rails 5.2 to rails 7.
  Currently the app is using AASM version 4.12.3. When I update to AASM
  version 5.x we start getting a failing spec in our app. The
  implementation uses the `after:` dsl and passes it a class.

  ``` ruby
   event :run_payment_create do
      transitions to: :active, after: Payment::GoCardless::Subscription::Charge
    end
  ```

  The spec in our app expects that class to receive new 1 time with the args
  passed from after, but the spec is failing saying that `Payment::GoCardless::Subscription::Charge`
  received `.new` with the expected args twice.
  I started debugging with `bundle open aasm` and pry and I found that the
  `ClassInvoker` has a `instance` method that memoizes the instance
  returned from the `retrieve_instance` method, but the `instance`
  method was only being used by `log_source_location` and `log_method_info`
  methods while `invoke_subject` was calling `retrieve_instance` directly
  resulting in `retrieve_instance` being called twice.
* Update `invoke_subject` method to use `instance.call` so that the
  instance will be memoized and subsequent calls to `instance` won't try
  to instantiate the class a second time.
2023-01-26 11:54:11 +08:00
..
invokers Fix ClassInvoker instantiating class twice 2023-01-26 11:54:11 +08:00
persistence
abstract_class_spec.rb
api_spec.rb
basic_two_state_machines_example_spec.rb
callback_multiple_spec.rb
callbacks_spec.rb Cast string to symbol in fire/fire!, and fix deceptive error class and message (#788) 2022-07-27 15:28:17 +05:30
complex_example_spec.rb Cast string to symbol in fire/fire!, and fix deceptive error class and message (#788) 2022-07-27 15:28:17 +05:30
complex_multiple_example_spec.rb
edge_cases_spec.rb
event_multiple_spec.rb
event_naming_spec.rb
event_spec.rb Cast string to symbol in fire/fire!, and fix deceptive error class and message (#788) 2022-07-27 15:28:17 +05:30
event_with_keyword_arguments_spec.rb Fixed an error in Ruby 3 when specifying a method that takes keyword arguments, such as event's before hook. (#777) 2022-04-14 23:31:56 +05:30
exception_spec.rb
guard_arguments_check_spec.rb
guard_multiple_spec.rb
guard_spec.rb
guard_with_params_multiple_spec.rb
guard_with_params_spec.rb
guard_without_from_specified_spec.rb
initial_state_multiple_spec.rb
initial_state_spec.rb
inspection_multiple_spec.rb
inspection_spec.rb
invoker_spec.rb
localizer_spec.rb
memory_leak_spec.rb
multiple_transitions_that_differ_only_by_guard_spec.rb
namespaced_multiple_example_spec.rb
new_dsl_spec.rb
override_warning_spec.rb
readme_spec.rb
reloading_spec.rb
rspec_matcher_spec.rb
simple_custom_example_spec.rb
simple_example_spec.rb
simple_multiple_example_spec.rb
state_spec.rb
states_on_one_line_example_spec.rb
subclassing_multiple_spec.rb
subclassing_spec.rb
timestamps_spec.rb
transition_spec.rb