Permalink
Browse files

Fix scope name pluralization not being applied correctly [#13 state:r…

…esolved]
  • Loading branch information...
1 parent 97cf57a commit cd16cad297f5bf1fcaae385b08d2e2a4aa19ad87 @obrie obrie committed Feb 14, 2009
View
2 CHANGELOG.rdoc
@@ -1,5 +1,7 @@
== master
+* Fix scope name pluralization not being applied correctly
+
== 0.5.1 / 2009-02-11
* Allow states to be drawn as ellipses to accommodate long names
View
2 lib/state_machine/machine.rb
@@ -1016,7 +1016,7 @@ def define_attribute_predicate
# name or adding an "s" to the end of the name.
def define_scopes(custom_plural = nil)
attribute = self.attribute
- plural = custom_plural || (attribute.respond_to?(:pluralize) ? attribute.pluralize : "#{attribute}s")
+ plural = custom_plural || (attribute.to_s.respond_to?(:pluralize) ? attribute.to_s.pluralize : "#{attribute}s")
[attribute, plural].uniq.each do |name|
[:with, :without].each do |kind|
View
15 test/unit/integrations/active_record_test.rb
@@ -307,6 +307,21 @@ def test_should_set_initial_state_on_created_object
end
end
+ class MachineWithComplexPluralizationTest < ActiveRecord::TestCase
+ def setup
+ @model = new_model
+ @machine = StateMachine::Machine.new(@model, :status)
+ end
+
+ def test_should_create_singular_with_scope
+ assert @model.respond_to?(:with_status)
+ end
+
+ def test_should_create_plural_with_scope
+ assert @model.respond_to?(:with_statuses)
+ end
+ end
+
class MachineWithCallbacksTest < ActiveRecord::TestCase
def setup
@model = new_model
View
15 test/unit/integrations/data_mapper_test.rb
@@ -201,6 +201,21 @@ def test_should_define_an_attribute_predicate
end
end
+ class MachineWithComplexPluralizationTest < BaseTestCase
+ def setup
+ @resource = new_resource
+ @machine = StateMachine::Machine.new(@resource, :status)
+ end
+
+ def test_should_create_singular_with_scope
+ assert @resource.respond_to?(:with_status)
+ end
+
+ def test_should_create_plural_with_scope
+ assert @resource.respond_to?(:with_statuses)
+ end
+ end
+
class MachineWithNonColumnStateAttributeDefinedTest < BaseTestCase
def setup
@resource = new_resource do
View
15 test/unit/integrations/sequel_test.rb
@@ -202,6 +202,21 @@ def test_should_set_initial_state_on_created_object
end
end
+ class MachineWithComplexPluralizationTest < BaseTestCase
+ def setup
+ @model = new_model
+ @machine = StateMachine::Machine.new(@model, :status)
+ end
+
+ def test_should_create_singular_with_scope
+ assert @model.respond_to?(:with_status)
+ end
+
+ def test_should_create_plural_with_scope
+ assert @model.respond_to?(:with_statuses)
+ end
+ end
+
class MachineWithCallbacksTest < BaseTestCase
def setup
@model = new_model

0 comments on commit cd16cad

Please sign in to comment.