在规范上获得未知属性错误并且不确定原因 - 在开发环境中正常工作

时间:2014-10-13 21:32:10

标签: ruby-on-rails rspec ruby-on-rails-3.2 rspec2

我有一个规范(rspec 2.13.1和rails 3.2.19)并且收到以下错误

1)ApiMenusController task0041:测试保存新菜单将创建新菜单      失败/错误:post:create,{is_new:“true”,location_id:lucques.id,name:“my newer jtjt menu”}      ActiveRecord的:: UnknownAttributeError:        未知属性:attributes_changes      #。/ app/models/save_app_event.rb:37:在`before_save'

我的AppEvent看起来像这样:

class AppEvent < ActiveRecord::Base
  attr_accessible :loggable_id, :loggable_type, :user_id, :event, :attributes_changes, :location_id, :menu_id

在before_save中调用

class SaveAppEvent
  def self.before_save(model)
    Rails.logger.info("within SaveAppEvent with a " + model.class.to_s)
    tmp=model.changes.except(:admin_frag).except(:menu_item_frag)
    if model.class.to_s=='Menu'
      Rails.logger.info("within SaveAppEvent with menu.location_id #{model.location_id}")
      tmp_menu_id=model.id
      tmp_menu_id=0 if !tmp_menu_id
      tmp_location_id=model.location_id
      event="a menu was saved with location_id: #{tmp_location_id} "
      #Rails.logger.info("within SaveAppEvent with name location_id: #{location_id} and menu_id: #{menu_id}")
    else
      menu_id=nil
      location_id=nil
    end
    Rails.logger.info("within SaveAppEvent right before creation location_id: #{tmp_location_id} and menu_id: #{tmp_menu_id} and attributes_changes: #{tmp}")
    AppEvent.create event: event, menu_id: tmp_menu_id,  attributes_changes: tmp, user_id: model.current_user_id, loggable_type: model.class.name, loggable_id: model.id 
  end  

信息在那里:

within SaveAppEvent right before creation location_id: 95 and menu_id: 0 and attributes_changes: {"location_id"=>[nil, 95], "name"=>[nil, "my newer jtjt menu"]}

出于某种原因,在这种情况下,它并不认为attributes_changes存在。在开发上,它工作正常。为什么测试环境会以不同的方式查看对象的属性?

THX

0 个答案:

没有答案