我有模特
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文件。如何解决?
答案 0 :(得分:0)
哦,由于uninitialized constant Moped::BSON in rails 4 app on heroku
,我的config / application.rb中有这段代码require "bson"
require "moped"
Moped::BSON = BSON
删除此工作和所有工作。