0

「has_and_belongs_to_many」と「accept_nested_attributes_for」について、製作とモンゴイドの文脈で質問があります

私は多くのサービスを持つことができる場所を持っています

class Location
  include Mongoid::Document

  field :name
  field :service

  has_and_belongs_to_many :services, inverse_of: :locations, autosave: true, dependent: :delete
  accepts_nested_attributes_for :services

  attr_accessible :services, :name



class Service
  include Mongoid::Document

  field :name, type: String

  has_and_belongs_to_many :locations, inverse_of: :services, autosave: true
  accepts_nested_attributes_for :locations
  attr_accessible :name, :icon, :description

私の製作ファイルにはこれがあります

Fabricator(:service) do
  initialize_with { Location.produce(:location) }
  name "Service Name"
  description "Lorem ipsum est lauda en radios"
  location
end

Fabricator(:location) do
  name "Special Club"
  service
end

この場合、rspec がハングアップします。

誰かが*accept_nested_attributes*および/または*has_and_belongs_to_many*をモンゴイドとファブリケーションジェム(モンゴイドで「箱から出して」動作する)で動作する例を提供できますか?

助言がありますか?

私はmongoid3で作業しています

4

1 に答える 1

3

これはすべて、Fabrication をどのように使用しているかによって異なります。

コントローラーをテストするためのパラメーターの入れ子は厄介な世界であり、params ハッシュを手動で作成する必要があります。

モデルの場合、これを試してください:

Fabricator(:service) do
  name "Service Name"
  description "Lorem ipsum est lauda en radios"
  locations {[Fabricate.build(:location)]}
end

Fabricator(:location) do
  name "Special Club"
  service
end

あなたの関係にはおそらく必要ありません:inverse_of

于 2012-11-15T05:16:07.633 に答える