如何处理FactoryGirl

时间:2016-02-01 04:02:08

标签: ruby-on-rails ruby-on-rails-4 factory-bot

我有两个模型通过他们共享的foreign_key属性加入。

# app/models/building.rb
belongs_to :building_basic_info, primary_key: "name", foreign_key:"name"

# app/models/building_basic_info.rb
has_many :buildings, primary_key: "name", foreign_key:"name"

我尝试编写一个工厂,创建buildingbuilding_basic_info并通过属性name关联它们。

FactoryGirl.define do 
  factory :building do
    name "cannon"
    factory :building_with_bbi do
       name "cannon"
    end
  end
end

building = build_stubbed(:building)
building.building_basic_info
# => nil... but I want it to return the associated building_basic_info object

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:1)

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301,NC]