Sha256: 5d5202ac5bd780d2a4487004a3c235df6ece3ba3828ec74410467cc5651c78ba
Contents?: true
Size: 1.67 KB
Versions: 11
Compression:
Stored size: 1.67 KB
Contents
require File.dirname(__FILE__) + '/spec_helper' module NoPeepingTomsSpec class Person < ActiveRecord::Base; end class PersonObserver < ActiveRecord::Observer def before_update(person) $observer_called_names.push person.name end end class AnotherObserver < ActiveRecord::Observer observe Person def before_update(person) $calls_to_another_observer += 1 end end describe Person, " when changing a name" do before(:each) do $observer_called_names = [] $calls_to_another_observer = 0 @person = Person.create! :name => "Pat Maddox" end it "should not register a name change" do @person.update_attribute :name, "Name change" $observer_called_names.pop.should be_blank $calls_to_another_observer.should == 0 end it "should register a name change with the person observer turned on" do Person.with_observers("NoPeepingTomsSpec::PersonObserver") do @person.update_attribute :name, "Name change" $observer_called_names.pop.should == "Name change" end @person.update_attribute :name, "Man Without a Name" $observer_called_names.pop.should be_blank $calls_to_another_observer.should == 0 end it "should handle multiple observers" do Person.with_observers("NoPeepingTomsSpec::PersonObserver", "NoPeepingTomsSpec::AnotherObserver") do @person.update_attribute :name, "Name change" $observer_called_names.pop.should == "Name change" end @person.update_attribute :name, "Man Without a Name" $observer_called_names.pop.should be_blank $calls_to_another_observer.should == 1 end end end
Version data entries
11 entries across 11 versions & 1 rubygems