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 解决了我的问题。