class RelatedList < ActiveRecord::Base
extend Enumerize
enumerize :list_type, in: %w(groups projects)
belongs_to :content
has_many :contents, :order => :position
end
Run Code Online (Sandbox Code Playgroud)
我在我的rails应用程序中有这个模型,当我尝试在控制台中创建记录时会抛出警告.
DEPRECATION警告:不推荐使用RelatedList.has_many:contents声明中的以下选项:: order.请改用示波器块.例如,以下内容:has_many:spam_comments,conditions:{spam:true},class_name:'Comment'应重写如下:has_many:spam_comments, - > {where spam:true},class_name:'Comment'.(来自/Users/shivam/Code/auroville/avorg/app/models/related_list.rb:7)
看起来Rails 4有新的:用于模型的命令语法,但我似乎无法在Rails指南中找到文档.
有谁知道如何规定有效的支持通知?以下似乎不起作用.它会检测默认的rails框架通知,但不会检测我的自定义通知.
it 'sends a "product.search" notification to any subscribers listening'
ActiveSupport::Notifications.should_receive(:instrument).with("product.search", :search => search)
get :search, ...
end
Run Code Online (Sandbox Code Playgroud)
如果我更改规范以检查订户代码的结果(例如,创建数据库记录时记录计数更改),它就会通过.这证实它工作正常.但是,指出订户在这里做什么似乎是错误的,我只想说明通知正在发送.任何想法将不胜感激.
编辑:
这是我正在尝试规范的控制器代码:
ActiveSupport::Notifications.instrument("product.search", :search => 'test')
Run Code Online (Sandbox Code Playgroud)