【发布时间】:2011-11-16 17:55:55
【问题描述】:
我有一个覆盖 update_attributes 的模型类:
class Foo < ActiveRecord::Base
def update_attributes(attributes)
if super(attributes)
#do some other cool stuff
end
end
end
我试图弄清楚如何在 update_attributes 的超级版本上设置期望和/或存根,以确保在成功的情况下完成其他工作。另外我想确保超级方法实际上被调用了。
这是我迄今为止尝试过的(当然没有成功):
describe "#update_attributes override" do
it "calls the base class version" do
parameters = Factory.attributes_for(:foo)
foo = Factory(:foo, :title => "old title")
ActiveRecord::Base.should_receive(:update_attributes).once
foo.update_attributes(parameters)
end
end
这当然行不通:
Failure/Error: ActiveRecord::Base.should_recieve(:update_attributes).once
NoMethodError:
undefined method `should_recieve' for ActiveRecord::Base:Class
有什么想法吗?
【问题讨论】:
标签: ruby-on-rails activerecord rspec