代码之家  ›  专栏  ›  技术社区  ›  Josiah Kiehl

工厂女工对女工问题

  •  0
  • Josiah Kiehl  · 技术社区  · 14 年前

    当我对我的工厂女孩对象调用json时,我得到一个零的错误。

    我在Rails3上使用了DataMapper,当我在一个真正的DataMapper对象上调用_json时,它工作得很好。你知道为什么工厂女孩的东西会坏吗?

    Factory.define :something do |b|
      b.date_foo { 3.days.ago - 4.hours }
      b.date_bar { 3.days.ago - 4.hours }
      b.somestring '11'
      b.anotherstring 'ASTRINGYAY'
      b.thirdstring 'STRINGG'
      b.fourthstring 'STRING'
      b.otherstring 'thestring'
      b.longerstring 'The string that is longer'
      b.somenumber 3
      b.someothernumber 2
      b.an_id 5593
      b.a_version '1.2.2.2'
      b.a_string '1.2.2.2'
      b.something '1.2.2.2'
      b.code 'SOME CODE'
      b.other_code 'API'
      b.something_id 49
      b.something_version 'OMG'
      b.otherthing 'N/A'
      b.lastthing 'A'
    end
    

    此外,我还发现了以下情况:

    factory_girl_object.to_json 工作良好。

    [factory_girl_object].to_json 失败。

    显然,DataMapper使用的是DataMapper::Collection对象而不是数组,后者处理的对象与数组的内容稍有不同。但是,我似乎不知道如何创建datamapper::collection对象来保存我的工厂女孩对象。

    思想?

    1 回复  |  直到 14 年前
        1
  •  0
  •   Josiah Kiehl    14 年前