我有两个问题
1.如何在rails测试用例中存根nil对象.
2.Mock一个Active Record Abstract类
例如
Y::table.find_by_email("hello@gmail.com").selected_lan["iden"]
module Y
class table <Base
belongs_to:selected_lan, :class =>lan
def self.find_by_email(iden)
find_by_email(license_iden)
end
end
end
module Y
class Base <ActiveRecord::Base
self.abstract_class = true
end
end
Run Code Online (Sandbox Code Playgroud) 任何人都可以解释这个例外在红宝石中意味着什么。
TypeError 异常:无法转储匿名类 Class
代码示例
Class X_controller
before filer: validate, :only => [:meth1]
def meth1
y.new.send_later(:issue1) #throws me exception
end
def meth2
y.new.send_later(:issue1) #works
end
private
def valiadate
y.new.send_later(:issue1) #throws me exception
end
end
class y
include x::z
def issue1
end
end
module x::z
def send_later(meth,*args)
end
end
Run Code Online (Sandbox Code Playgroud) 我想覆盖一个ActiveRecord保存方法,以便从事务中带来一些东西.覆盖方法是个好主意吗?
我正在使用rails 2.3.8版本有任何特殊原因,为什么update_attributes不会触发before_validation回调
class x < ActiveRecord::Base
before_validation :testing
def testing
debugger
end
end
Run Code Online (Sandbox Code Playgroud)
x.update_attributes(:name =>"hello")不会触发before_validation