Rails 已删除 model 直接的关联关系,怎么还是有这样的错误?(集成测试环境下)

shangrenzhidao · 2014年11月03日 · 1586 次阅读
orders.yml
one:
  name: David Thomas
  address: MyText
  email: dave@example.com
  pay_type: Check

order.rb
class Order < ActiveRecord::Base
  has_many :line_items, dependent: :destroy
  #belongs_to :pay_type
  #validates :pay_type_id, presence: true
  PAYMENT_TYPES = ["Check", "Credit card", "Purchase order"]
  #PAYMENT_TYPES = PayType.names

  validates :name, :email, :address, presence: true
  validates :pay_type, inclusion: PAYMENT_TYPES

  def add_line_items_from_cart(cart)
    cart.line_items.each do |item|
      item.cart_id = nil
      line_items << item
    end
  end
end

test 代码

class UserStoriesTest < ActionDispatch::IntegrationTest

fixtures :products

  test "buying a product" do
    LineItem.delete_all
    Order.delete_all
    ruby_book = products(:ruby)
   end
end

error 信息 ActiveRecord::StatementInvalid: Could not find table 'pay_types'

pay_type 是字符串,没有关联关系,也允许了 rake db:test:prepare 了。到底问题出现在哪里了。

========================================== "looks like you didn't run some of the migrations. What happens if you do "rake db:drop && rake db:migrate"? " http://stackoverflow.com/questions/21970160/rails-4-sqlite3sqlexception-error 解决了我的问题。

暂无回复。
需要 登录 后方可回复, 如果你还没有账号请 注册新账号