1
0
Fork 0
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:
Travis Tilley 2010-09-13 00:02:47 -04:00
parent 3b4520ea7f
commit ff1f9fbd5e
2 changed files with 10 additions and 4 deletions

View file

@ -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::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.class_eval do
@ -238,7 +238,13 @@ module AASM
module NamedScopeMethods
def aasm_state_with_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

View file

@ -216,15 +216,15 @@ begin
context "Does not already respond_to? the scope name" do
it "should add a scope" do
NamedScopeExample.should_receive(:scope)
NamedScopeExample.aasm_state :unknown_scope
NamedScopeExample.scopes.keys.should include(:unknown_scope)
end
end
context "Already respond_to? the scope name" do
it "should not add a scope" do
NamedScopeExample.should_not_receive(:scope)
NamedScopeExample.aasm_state :new
NamedScopeExample.scopes.keys.should_not include(:new)
end
end
end