mirror of
https://github.com/aasm/aasm
synced 2023-03-27 23:22:41 -04:00
make the NamedScopeMethods test -actually- test that the scope was defined, and fix the silently broken logic for defining scopes in rails 2.x
This commit is contained in:
parent
3b4520ea7f
commit
ff1f9fbd5e
2 changed files with 10 additions and 4 deletions
|
@ -38,7 +38,7 @@ module AASM
|
||||||
base.send(:include, AASM::Persistence::ActiveRecordPersistence::WriteState) unless base.method_defined?(:aasm_write_state)
|
base.send(:include, AASM::Persistence::ActiveRecordPersistence::WriteState) unless base.method_defined?(:aasm_write_state)
|
||||||
base.send(:include, AASM::Persistence::ActiveRecordPersistence::WriteStateWithoutPersistence) unless base.method_defined?(:aasm_write_state_without_persistence)
|
base.send(:include, AASM::Persistence::ActiveRecordPersistence::WriteStateWithoutPersistence) unless base.method_defined?(:aasm_write_state_without_persistence)
|
||||||
|
|
||||||
if base.respond_to?(:scope)
|
if base.respond_to?(:named_scope) || base.respond_to?(:scope)
|
||||||
base.extend(AASM::Persistence::ActiveRecordPersistence::NamedScopeMethods)
|
base.extend(AASM::Persistence::ActiveRecordPersistence::NamedScopeMethods)
|
||||||
|
|
||||||
base.class_eval do
|
base.class_eval do
|
||||||
|
@ -238,7 +238,13 @@ module AASM
|
||||||
module NamedScopeMethods
|
module NamedScopeMethods
|
||||||
def aasm_state_with_scope name, options = {}
|
def aasm_state_with_scope name, options = {}
|
||||||
aasm_state_without_scope name, options
|
aasm_state_without_scope name, options
|
||||||
self.scope name, :conditions => { "#{table_name}.#{self.aasm_column}" => name.to_s} unless self.respond_to?(name)
|
|
||||||
|
unless self.respond_to?(name)
|
||||||
|
scope_options = {:conditions => { "#{table_name}.#{self.aasm_column}" => name.to_s}}
|
||||||
|
scope_method = ActiveRecord::VERSION::MAJOR >= 3 ? :scope : :named_scope
|
||||||
|
self.send(scope_method, name, scope_options)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -216,15 +216,15 @@ begin
|
||||||
|
|
||||||
context "Does not already respond_to? the scope name" do
|
context "Does not already respond_to? the scope name" do
|
||||||
it "should add a scope" do
|
it "should add a scope" do
|
||||||
NamedScopeExample.should_receive(:scope)
|
|
||||||
NamedScopeExample.aasm_state :unknown_scope
|
NamedScopeExample.aasm_state :unknown_scope
|
||||||
|
NamedScopeExample.scopes.keys.should include(:unknown_scope)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "Already respond_to? the scope name" do
|
context "Already respond_to? the scope name" do
|
||||||
it "should not add a scope" do
|
it "should not add a scope" do
|
||||||
NamedScopeExample.should_not_receive(:scope)
|
|
||||||
NamedScopeExample.aasm_state :new
|
NamedScopeExample.aasm_state :new
|
||||||
|
NamedScopeExample.scopes.keys.should_not include(:new)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue