Skip to content

Commit

Permalink
fix: timestamp will work with named machine
Browse files Browse the repository at this point in the history
  • Loading branch information
RolandStuder committed Apr 22, 2021
1 parent 252ade3 commit f9906ef
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/aasm/base.rb
Expand Up @@ -268,7 +268,7 @@ def setup_timestamps(aasm_name)

after_all_transitions do
if self.class.aasm(:"#{aasm_name}").state_machine.config.timestamps
ts_setter = "#{aasm.to_state}_at="
ts_setter = "#{aasm(aasm_name).to_state}_at="
respond_to?(ts_setter) && send(ts_setter, ::Time.now)
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/models/timestamps_example.rb
Expand Up @@ -4,7 +4,7 @@ class TimestampsExample
attr_accessor :opened_at
attr_reader :closed_at

aasm timestamps: true do
aasm :state, timestamps: true do
state :opened
state :closed

Expand Down
4 changes: 2 additions & 2 deletions spec/unit/timestamps_spec.rb
Expand Up @@ -19,9 +19,9 @@

it 'can be turned off and on' do
object = TimestampsExample.new
object.class.aasm.state_machine.config.timestamps = false
object.class.aasm(:state).state_machine.config.timestamps = false
expect { object.open }.not_to change { object.opened_at }
object.class.aasm.state_machine.config.timestamps = true
object.class.aasm(:state).state_machine.config.timestamps = true
expect { object.open }.to change { object.opened_at }
end
end

0 comments on commit f9906ef

Please sign in to comment.