mirror of
https://github.com/aasm/aasm
synced 2023-03-27 23:22:41 -04:00
Don't add named_scope if the ActiveRecord object responds to the method name already (such as 'new')
Signed-off-by: Scott Barron <scott@elitists.net>
This commit is contained in:
parent
656984f8b2
commit
f1748118ba
2 changed files with 55 additions and 36 deletions
|
@ -238,7 +238,7 @@ module AASM
|
||||||
module NamedScopeMethods
|
module NamedScopeMethods
|
||||||
def aasm_state_with_named_scope name, options = {}
|
def aasm_state_with_named_scope name, options = {}
|
||||||
aasm_state_without_named_scope name, options
|
aasm_state_without_named_scope name, options
|
||||||
self.named_scope name, :conditions => {self.aasm_column => name.to_s} unless self.scopes.include?(name)
|
self.named_scope name, :conditions => {self.aasm_column => name.to_s} unless self.respond_to?(name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -200,6 +200,25 @@ begin
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe AASM::Persistence::ActiveRecordPersistence::NamedScopeMethods do
|
||||||
|
class NamedScopeExample < ActiveRecord::Base
|
||||||
|
include AASM
|
||||||
|
end
|
||||||
|
|
||||||
|
context "Does not already respond_to? the scope name" do
|
||||||
|
it "should add a named_scope" do
|
||||||
|
NamedScopeExample.should_receive(:named_scope)
|
||||||
|
NamedScopeExample.aasm_state :unknown_scope
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "Already respond_to? the scope name" do
|
||||||
|
it "should not add a named_scope" do
|
||||||
|
NamedScopeExample.should_not_receive(:named_scope)
|
||||||
|
NamedScopeExample.aasm_state :new
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# TODO: figure out how to test ActiveRecord reload! without a database
|
# TODO: figure out how to test ActiveRecord reload! without a database
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue