Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rspec加载过去(错误)的模型_Ruby On Rails_Ruby_Rspec - Fatal编程技术网

Ruby on rails Rspec加载过去(错误)的模型

Ruby on rails Rspec加载过去(错误)的模型,ruby-on-rails,ruby,rspec,Ruby On Rails,Ruby,Rspec,我有一个Rails迁移文件 class CreateUserData < ActiveRecord::Migration def change create_table :user_data do |t| t.belongs_to :user, index: true t.string :country t.string :city t.string :state t.string :language t.

我有一个Rails迁移文件

class CreateUserData < ActiveRecord::Migration
  def change
    create_table :user_data do |t|
      t.belongs_to :user, index: true
      t.string :country
      t.string :city
      t.string :state
      t.string :language
      t.string :device_advertising_id
      t.string :client_type
      t.string :data_type

      t.timestamps
    end
  end
end
class CreateUserData
我玩过几次。然后,我把它改成了

class CreateUserData < ActiveRecord::Migration
  def change
    create_table :user_data do |t|
      t.belongs_to :user, index: true
      t.string :country
      t.string :city
      t.string :sublocality # added
      t.string :zip_code # added
      t.string :language
      t.string :device_advertising_id
      t.string :client_type
      t.string :data_type

      t.timestamps
    end
  end
end
class CreateUserData
这是模型文件

# a class to store user data based on initial and latest
class UserData < ActiveRecord::Base
  belongs_to :user, class_name: 'Spree::User'
  validates :device_advertising_id, presence: true

  enum data_type: { initial: 'initial', latest: 'latest' }

  scope :no_initial, -> { where(device_advertising_id: device_advertising_id).where(data_type: 'initial') }

  def first_update(country='', city='', sublocality='', zip_code='', language='', client_type='')
    self.country ||= country
    self.city ||= city
    self.sublocality ||= sublocality
    self.zip_code ||= zip_code
    self.language ||= language
    self.client_type ||= client_type
  end
end
#基于初始值和最新值存储用户数据的类
类UserData{where(设备广告id:device_广告id).where(数据类型:'initial')}
def首次更新(国家=“”,城市=“”,子地区=“”,邮政编码=“”,语言=“”,客户类型=“”)
self.country | |=国家
self.city | |=城市
self.sublocality | |=sublocality
self.zip|u code |=邮政编码
self.language | |=语言
self.client_type | |=client_type
结束
结束
当我在rails控制台上检查UserData模型时

UserData(id:integer,user\u id:integer,country:string,city:string, 子位置:string,邮政编码:string,语言:string, 设备\u广告\u id:字符串,客户端\u类型:字符串,数据\u类型:字符串, 创建时间:datetime,更新时间:datetime)

但是,当我运行rspec时。我的工厂倒闭了<代码>未定义的方法子局部性=for#

当我跑过去检查教室的时候

UserData(id:integer,user\u id:integer,country:string,city:string, 状态:string,语言:string,设备\u id:string, 客户端类型:字符串,创建时间:datetime,更新时间:datetime)


知道为什么rspec总是加载类的过去版本吗?我已经迁移到最新的迁移并检查了数据库表。

很抱歉,我忘记了Rails测试数据库与开发数据库不同。我只需要跑

rake db:rollback RAILS_ENV=test
rake db:migrate RAILS_ENV=test

让它工作。

可以,但我需要等两天。:)。