From cfb5479a8ded1b7ab829cf02155e43e54c4bc725 Mon Sep 17 00:00:00 2001 From: Ahmed AbdelHalim <347712+a14m@users.noreply.github.com> Date: Mon, 10 Dec 2018 15:19:23 +0100 Subject: [PATCH 1/6] Update InvalidTransition to include state_machine_name For easier debugging and error handling for models with multiple state_machines. This non-breaking change add the state_machine name to the attributes of the InvalidTransition error --- lib/aasm/errors.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/aasm/errors.rb b/lib/aasm/errors.rb index 751fd35..6950699 100644 --- a/lib/aasm/errors.rb +++ b/lib/aasm/errors.rb @@ -3,10 +3,11 @@ module AASM class UnknownStateMachineError < RuntimeError; end class InvalidTransition < RuntimeError - attr_reader :object, :event_name, :originating_state, :failures + attr_reader :object, :event_name, :originating_state, :failures, :state_machine def initialize(object, event_name, state_machine_name, failures = []) @object, @event_name, @originating_state, @failures = object, event_name, object.aasm(state_machine_name).current_state, failures + @state_machine = state_machine_name super("Event '#{event_name}' cannot transition from '#{originating_state}'.#{reasoning}") end From 7bdf3eacd23b64af4b954ed0fde001124e21769b Mon Sep 17 00:00:00 2001 From: Ahmed AbdelHalim <347712+a14m@users.noreply.github.com> Date: Wed, 2 Jan 2019 23:26:39 +0100 Subject: [PATCH 2/6] Update the attr_reader to match the convention --- lib/aasm/errors.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/aasm/errors.rb b/lib/aasm/errors.rb index 6950699..8e9c744 100644 --- a/lib/aasm/errors.rb +++ b/lib/aasm/errors.rb @@ -3,11 +3,11 @@ module AASM class UnknownStateMachineError < RuntimeError; end class InvalidTransition < RuntimeError - attr_reader :object, :event_name, :originating_state, :failures, :state_machine + attr_reader :object, :event_name, :originating_state, :failures, :state_machine_name def initialize(object, event_name, state_machine_name, failures = []) @object, @event_name, @originating_state, @failures = object, event_name, object.aasm(state_machine_name).current_state, failures - @state_machine = state_machine_name + @state_machine_name = state_machine_name super("Event '#{event_name}' cannot transition from '#{originating_state}'.#{reasoning}") end From 57ffc986a88a8fd52b751f1bc8d32d0a24c260e9 Mon Sep 17 00:00:00 2001 From: Ben Koshy Date: Wed, 16 Jan 2019 12:13:50 +0530 Subject: [PATCH 3/6] update Readme: add headings, improve formatting ### What is this change? * It is a simply change in the formatting and presentation: bullet points have been added, and an extra heading has been added. ### Why this change? * to make it clearer to the user: I was searching for a bug when I realised that a simple 'require' statement was omitted in code. This change request makes it explicitly clear so that it basically cannot be overlooked by future users. I hope to spare them some pain. I hope this helps. chrs. --- README.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1aa4fda..1a33b34 100644 --- a/README.md +++ b/README.md @@ -1178,7 +1178,15 @@ the 'instance method symbol / string' way whenever possible when defining guardi #### RSpec -AASM provides some matchers for [RSpec](http://rspec.info): `transition_from`, `have_state`, `allow_event` and `allow_transition_to`. Add `require 'aasm/rspec'` to your `spec_helper.rb` file and use them like this: +AASM provides some matchers for [RSpec](http://rspec.info): +*`transition_from`, +* `have_state`, `allow_event` +* and `allow_transition_to`. + +##### Installation Instructions: +* Add `require 'aasm/rspec'` to your `spec_helper.rb` file. + +##### Examples Of Usage in Rspec: ```ruby # classes with only the default state machine @@ -1225,6 +1233,9 @@ AASM provides assertions and rspec-like expectations for [Minitest](https://gith List of supported assertions: `assert_have_state`, `refute_have_state`, `assert_transitions_from`, `refute_transitions_from`, `assert_event_allowed`, `refute_event_allowed`, `assert_transition_to_allowed`, `refute_transition_to_allowed`. + +##### Examples Of Usage (Minitest): + Add `require 'aasm/minitest'` to your `test_helper.rb` file and use them like this: ```ruby From e28d5a4efb889a2b19752da88a4cca6396842a15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Gomes=20J=C3=BAnior?= Date: Thu, 29 Nov 2018 11:02:10 -0200 Subject: [PATCH 4/6] Adds Class Invoker documentation on README --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index 1a33b34..ca881f6 100644 --- a/README.md +++ b/README.md @@ -385,6 +385,21 @@ If you prefer a more Ruby-like guard syntax, you can use `if` and `unless` as we end ``` +You can invoke a Class instead a method since this Class responds to `call` + +```ruby + event :sleep do + transitions :from => :running, :to => :sleeping, :guards => Dog + end +``` +```ruby + class Dog + def call + cleaning_needed? && walked? + end + ... + end +``` ### Transitions From cd25a1eeaeaec49238ec19b6cdd2b28d23c56f71 Mon Sep 17 00:00:00 2001 From: Kerem Bozdas Date: Tue, 20 Nov 2018 00:15:03 +0300 Subject: [PATCH 5/6] Remove obsolete Gemnasium badge --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index ca881f6..49875cf 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,6 @@ [![Gem Version](https://badge.fury.io/rb/aasm.svg)](http://badge.fury.io/rb/aasm) [![Build Status](https://travis-ci.org/aasm/aasm.svg?branch=master)](https://travis-ci.org/aasm/aasm) -[![Dependency Status](https://gemnasium.com/aasm/aasm.svg)](https://gemnasium.com/aasm/aasm) [![Code Climate](https://codeclimate.com/github/aasm/aasm/badges/gpa.svg)](https://codeclimate.com/github/aasm/aasm) ## Index From 81ab368d601a698ab70a5648d0aec1e06dfdbcfa Mon Sep 17 00:00:00 2001 From: J Scotti Date: Fri, 25 Jan 2019 12:04:17 +0100 Subject: [PATCH 6/6] Clarify `on_event` can accept *multiple* events It was clear it could have accept arguments as the previous examples already did cover the case. This chagne clarifies what the examples is covering. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 49875cf..7105623 100644 --- a/README.md +++ b/README.md @@ -1213,7 +1213,7 @@ expect(job).to allow_event :run expect(job).to_not allow_event :clean expect(job).to allow_transition_to(:running) expect(job).to_not allow_transition_to(:cleaning) -# on_event also accept arguments +# on_event also accept multiple arguments expect(job).to transition_from(:sleeping).to(:running).on_event(:run, :defragmentation) # classes with multiple state machine