From 851dcc36fdc261011b68c1eb3551d381b0cce0a2 Mon Sep 17 00:00:00 2001 From: werleo Date: Fri, 4 Aug 2017 14:19:22 +0200 Subject: [PATCH] Test for aasm guard arguments (#485) --- spec/models/guard_arguments_check.rb | 17 +++++++++++++++++ spec/unit/guard_arguments_check_spec.rb | 9 +++++++++ 2 files changed, 26 insertions(+) create mode 100644 spec/models/guard_arguments_check.rb create mode 100644 spec/unit/guard_arguments_check_spec.rb diff --git a/spec/models/guard_arguments_check.rb b/spec/models/guard_arguments_check.rb new file mode 100644 index 0000000..25d3423 --- /dev/null +++ b/spec/models/guard_arguments_check.rb @@ -0,0 +1,17 @@ +class GuardArgumentsCheck + include AASM + + aasm do + state :new, :reviewed, :finalized + + event :mark_as_reviewed, + :guard => proc { |*args| arguments_list(*args) } do + transitions :from => :new, :to => :reviewed + end + end + + def arguments_list(arg1, arg2) + return false unless arg1.nil? + true + end +end diff --git a/spec/unit/guard_arguments_check_spec.rb b/spec/unit/guard_arguments_check_spec.rb new file mode 100644 index 0000000..6ee6a5d --- /dev/null +++ b/spec/unit/guard_arguments_check_spec.rb @@ -0,0 +1,9 @@ +require 'spec_helper' + +describe "nil as first argument" do + let(:guard) { GuardArgumentsCheck.new } + + it 'does not raise errors' do + expect { guard.mark_as_reviewed(nil, 'second arg') }.not_to raise_error + end +end