Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: timestamp will work with named machine #739

Merged

Conversation

RolandStuder
Copy link
Contributor

This PR makes sure timestamps work also with named machines. Which currently is not the case.

Using timestamps on a named machine like so:

aasm :state, timestamps: true do 

Will result in an error:

AASM::UnknownStateMachineError:
       There is no state machine with the name 'default' defined in TimestampsExample!
     # ./lib/aasm/aasm.rb:70:in `aasm'
     # ./lib/aasm/base.rb:271:in `block in setup_timestamps'

The fix is simple, in ts_setter = "#{aasm(aasm_name).to_state}_at=" it was just missing the aasm_name as an argument. It missing tried to use the default state machine which did not exist.

Tests are updated,to use the timestamps functionality with a named machine. Let me know, if you would prefer for the test to be more explicit about what it checks.

btw: Really love the addition of timestamps, thx to @jaynetics !

@codecov-commenter
Copy link

codecov-commenter commented Apr 22, 2021

Codecov Report

Merging #739 (23ada79) into master (252ade3) will increase coverage by 0.06%.
The diff coverage is 100.00%.

❗ Current head 23ada79 differs from pull request most recent head ab86f8b. Consider uploading reports for the commit ab86f8b to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master     #739      +/-   ##
==========================================
+ Coverage   95.39%   95.45%   +0.06%     
==========================================
  Files          35       35              
  Lines        1260     1255       -5     
==========================================
- Hits         1202     1198       -4     
+ Misses         58       57       -1     
Impacted Files Coverage Δ
lib/aasm/base.rb 97.79% <100.00%> (ø)
lib/aasm/core/transition.rb 97.82% <0.00%> (-0.05%) ⬇️
lib/aasm/core/event.rb 97.77% <0.00%> (-0.03%) ⬇️
lib/aasm/core/invoker.rb 100.00% <0.00%> (ø)
lib/aasm/core/invokers/literal_invoker.rb 100.00% <0.00%> (ø)
lib/aasm/persistence/active_record_persistence.rb 92.10% <0.00%> (+1.19%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 252ade3...ab86f8b. Read the comment docs.

@anilmaurya
Copy link
Member

Hi @RolandStuder

Thank you for reporting bug and sending PR to fix it.

Instead of updating current test, can you add a separate test for named state machine ?

@RolandStuder RolandStuder force-pushed the fix-timestamps-for-named-machines branch from f9906ef to ade2484 Compare April 23, 2021 08:14
@RolandStuder RolandStuder force-pushed the fix-timestamps-for-named-machines branch from ade2484 to ab86f8b Compare April 23, 2021 08:16
@codeclimate
Copy link

codeclimate bot commented Apr 23, 2021

Code Climate has analyzed commit ab86f8b and detected 0 issues on this pull request.

View more on Code Climate.

@RolandStuder
Copy link
Contributor Author

@anilmaurya updated to use a separate test, I hope this is more or less what you had in mind. (force pushed btw). Thx for the quick response!

@anilmaurya anilmaurya merged commit ad8fa48 into aasm:master Apr 23, 2021
@anilmaurya
Copy link
Member

Thank you @RolandStuder for contributing 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants