我将离开RSpec并开始使用Test :: Unit和Fixtures。 请问,我的关系有什么问题?
我有关系
def class InputSet < ActiveRecord::Base
has_many :input_units
end
require 'test_helper'
class InputSetTest < ActiveSupport::TestCase
test 'fixture is valid' do
input_set = input_sets(:one)
assert input_set.valid?
end
end
# input_sets.yml
one:
name: 'Kalkulacia 1'
input_units: product_1 <<<------- this is causing the problem
# input_units.yml
product_1:
data: {val1: 'test', val2: 'test'}
kind: 'product'
我运行rake test
并看到错误:
1) Error:
InputSetTest#test_fixture_is_valid:
ActiveRecord::StatementInvalid: PG::UndefinedColumn: ERROR: column "input_units" of relation "input_sets" does not exist
LINE 1: INSERT INTO "input_sets" ("name", "input_units", "created_at...
^
: INSERT INTO "input_sets" ("name", "input_units", "created_at", "updated_at", "id") VALUES ('Kalkulacia 1', 'product_1', '2014-03-09 09:43:40', '2014-03-09 09:43:40', 980190962)
答案 0 :(得分:0)
我遇到了同样的问题。您可能需要在InputUnit
模型中添加相应的关系:
# input_unit.rb
class InputUnit < ActiveRecord::Base
belongs_to :input_unit_set
end