Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/stateful_enum/machine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def initialize(model, column, states, prefix, suffix, name, &block)
if to && (!condition || instance_exec(&condition))
#TODO transaction?
run_callbacks new_method_name do
original_method = self.class.send(:_enum_methods_module).instance_method "#{prefix}#{to}#{suffix}!"
original_method = self.class.base_class.send(:_enum_methods_module).instance_method "#{prefix}#{to}#{suffix}!"
original_method.bind(self).call
end
else
Expand Down
4 changes: 4 additions & 0 deletions test/dummy/app/models/special_bug.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

class SpecialBug < Bug
end
1 change: 1 addition & 0 deletions test/dummy/db/migrate/20160307203948_create_bugs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def change
t.integer :status, default: 0
t.integer :assigned_to_id
t.datetime :resolved_at
t.string :type

t.timestamps null: false
end
Expand Down
8 changes: 8 additions & 0 deletions test/mechanic_machine_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ def test_transition
assert_equal 'assigned', bug.status
end

def test_transition_to_sti
special_bug = SpecialBug.new
assert_equal 'unassigned', special_bug.status
special_bug.assigned_to = User.create!(name: 'user 1')
special_bug.assign
assert_equal 'assigned', special_bug.status
end

def test_transition!
bug = Bug.new
bug.assigned_to = User.create!(name: 'user 1')
Expand Down