【问题标题】:Factory Girl (BSON::Binary::InvalidType)工厂女孩 (BSON::Binary::InvalidType)
【发布时间】:2014-08-26 14:43:46
【问题描述】:

我有模特

class GameSafe
  mount_uploader :content, AppFileUploader
end

我有工厂

FactoryGirl.define do
  factory :game_safe do
    app
    player {FactoryGirl.create(:player, :without_smtp_validation)}
    game
    content { File.open(
        File.join(Rails.root,'spec', 'support', 'game_saves', 'custom.json')
    )}
  end
end

然后测试

describe MyApp::V1::GameSavesController do
  before(:each) do
    @save = FactoryGirl.create(:game_safe)
  end
end

当我运行测试时出现错误

Failure/Error: @save = FactoryGirl.create(:game_safe)
 BSON::Binary::InvalidType:
   "{\n  \"name\": \"pixelserve\",\n  \"version\": \"0.0.1\",\n  \"devDependencies\": {\n    \"grunt\": \"0.4.0\",\n    \"bower\": \"0.9.2\",\n    \"grunt-contrib-clean\": \"0.4.0\",\n    \"grunt-contrib-compress\": \"0.4.1\",\n    \"grunt-contrib-connect\": \"0.1.2\",\n    \"grunt-contrib-copy\": \"0.4.1\",\n    \"grunt-shell\": \"~0.2.2\",\n    \"jasmine-node\": \"1.2.3\",\n    \"q\": \"~0.9.2\",\n    \"q-fs\": \"0.1.36\",\n    \"qq\": \"0.3.5\",\n    \"shelljs\": \"0.1.2\",\n    \"karma\": \"~0.9.4\",\n    \"karma-jasmine\": \"~0.0.1\",\n    \"karma-chrome-launcher\": \"~0.0.2\",\n    \"karma-firefox-launcher\": \"~0.0.1\",\n    \"karma-ng-scenario\": \"~0.0.1\",\n    \"karma-junit-reporter\": \"~0.0.1\",\n    \"karma-sauce-launcher\": \"~0.0.4\",\n    \"karma-script-launcher\": \"~0.0.1\",\n    \"yaml-js\": \"0.0.5\",\n    \"showdown\": \"0.3.1\",\n    \"rewire\": \"1.1.3\",\n    \"grunt-contrib-jasmine-node\": \"~0.1.1\",\n    \"grunt-parallel\": \"~0.2.0\",\n    \"grunt-ddescribe-iit\": \"~0.0.1\",\n    \"grunt-merge-conflict\": \"~0.0.1\"\n  },\n  \"description\": \"Pixelserve app, video embeds\",\n  \"directories\": {\n    \"doc\": \"doc\"\n  },\n  \"repository\": {\n    \"type\": \"git\",\n    \"url\": \"git://github.com/bizlaunchequity/pixelserve.git\"\n  },\n  \"author\": \"highbeats\",\n  \"license\": \"BSD\",\n  \"bugs\": {\n    \"url\": \"https://github.com/bizlaunchequity/pixelserve/issues\"\n  }\n}\n" is not a valid binary type. Please use one of :generic, :function, :old, :uuid_old, :uuid, :md5, :user.
 # (eval):2:in `[]='
 # ./spec/controllers/red_sky_api/v1/game_saves_controller_spec.rb:5:in `block (2 levels) in <top (required)>'
 # -e:1:in `<main>'

这个 json 字符串是我在工厂中定义的 custom.json 文件。如何解决?

【问题讨论】:

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


    【解决方案1】:

    因为uninitialized constant Moped::BSON in rails 4 app on heroku,我的 config/application.rb 中有这段代码

    require "bson"
    require "moped"
    Moped::BSON = BSON  
    

    删除这个和所有工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多