我正在使用 rspec 来测试我的 Rails 3 应用程序。我需要在测试开始之前为数据库播种。如何使用以下内容为数据库播种:
/db/seeds.rb
["Admin", "Member"].each do |role_name|
Role.find_or_create_by_name(role_name)
end
Thanks
在spec_helper.rb或rails_helper.rb中:
RSpec.configure do |config|
config.before(:suite) do
Rails.application.load_seed # loading seeds
end
end
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)