我正在尝试使用Ruby on Rails 4.0 HStore扩展来操作PostreSQL。我想将我的HStore字段之一设为必需:
class Thing < ActiveRecord::Base
# ...
validates :field_name, presence: true
# ...
end
作为一个HStore的新手,我使用rails g scaffold Thing field_name:hstore
生成了Thing的脚手架。这样做后,我的fixture文件(test/fixtures/things.yml
)没有为field_name
指定默认值:
one:
# ...
field_name:
# ...
由于必填字段没有提供值,导致rake test
失败。
我的问题是:如何在我的固件YAML文件中为field_name
设置一个值,以便我的测试能够通过?
目前我知道的是:
This does not work:
one: # ... field_name: small: 2 medium: 5 large: 4 # ...
This also does not work:
one: # ... field_name: {"small"=>"2", "medium"=>"5", "large"=>"4"} # ...
谢谢!