Note that there are some explanatory texts on larger screens.

plurals
  1. POMongoid3 + FactoryGirl Incompatible?
    text
    copied!<p>I just upgrade to Mongoid3 and Im getting a TON of these errors:</p> <pre><code>TypeError: can't convert String into Integer </code></pre> <p>The issue is always when Im trying to build a model that belongs_to another model and I assign the referenced model:</p> <pre><code>@entry = FactoryGirl.create(:entry_image, user_id: @user.id, day: 18, month: 6) </code></pre> <p>It seems to be the "user_id: @user.id" part. Ive tried:</p> <pre><code>@entry = FactoryGirl.build(:entry_image, day: 18, month: 6) @entry.user = @user @entry.save </code></pre> <p>Same error every time. </p> <p>Here is the factory file:</p> <pre><code> FactoryGirl.define do factory :user do name 'Test User' email 'example@example.com' password 'please' password_confirmation 'please' pin '1234' default_time_zone 'America/New_York' end ... </code></pre> <p>Im using devise, here is the controller macro we run:</p> <pre><code> module ControllerMacros def login_user before(:each) do @request.env["devise.mapping"] = Devise.mappings[:user] @user = FactoryGirl.create(:user) #user.confirm! # or set a confirmed_at inside the factory. Only necessary if you are using the confirmable module sign_in @user end end end </code></pre> <p>Here is the full stack trace:</p> <pre><code>&gt; 1.9.3p194 :016 &gt; user = User.all[0] =&gt; #&lt;User _id: 503e9c807adf9d6551000001, _type: nil, email: "joe@email.com", encrypted_password: "$5a$10$Mt1kx/TtbDma4gVtcTLdLeeP6tcSiF2AJkjeJmv73/U5OWF.M34v.", remember_created_at: 2012-08-29 23:30:17 UTC, sign_in_count: 3, current_sign_in_at: 2012-08-29 23:30:17 UTC, last_sign_in_at: 2012-08-29 22:49:57 UTC, current_sign_in_ip: "127.0.0.1", last_sign_in_ip: "127.0.0.1", s3_access_key: #&lt;Moped::BSON::Binary type=:generic length=24&gt;, s3_secret_key: #&lt;Moped::BSON::Binary type=:generic length=48&gt;, pin: nil, default_time_zone: "America/New_York", name: "Joe Smith"&gt; 1.9.3p194 :017 &gt; e = FactoryGirl.create(("entry_image").to_s, user_id: user.id, items: [ FactoryGirl.build(:image, user_id: user.id) ]) TypeError: can't convert String into Integer from /Users/lee/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/set.rb:185:in `include?' from /Users/lee/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/set.rb:185:in `include?' from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.5/lib/mongoid/callbacks.rb:140:in `block (3 levels) in cascadable_children' from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.5/lib/mongoid/callbacks.rb:139:in `each' from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.5/lib/mongoid/callbacks.rb:139:in `block (2 levels) in cascadable_children' from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.5/lib/mongoid/relations/accessors.rb:103:in `without_autobuild' from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.5/lib/mongoid/callbacks.rb:133:in `block in cascadable_children' from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.5/lib/mongoid/callbacks.rb:131:in `each_pair' from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.5/lib/mongoid/callbacks.rb:131:in `cascadable_children' from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.5/lib/mongoid/callbacks.rb:95:in `run_callbacks' from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/activemodel-3.2.0/lib/active_model/validations/callbacks.rb:53:in `run_validations!' from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/activemodel-3.2.0/lib/active_model/validations.rb:179:in `valid?' from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.5/lib/mongoid/validations.rb:78:in `valid?' from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/activemodel-3.2.0/lib/active_model/validations.rb:187:in `invalid?' from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.5/lib/mongoid/persistence/insertion.rb:22:in `prepare' from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.5/lib/mongoid/persistence/operations/insert.rb:26:in `persist' ... 4 levels... from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/factory_girl-4.0.0/lib/factory_girl/evaluation.rb:15:in `[]' from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/factory_girl-4.0.0/lib/factory_girl/evaluation.rb:15:in `create' from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/factory_girl-4.0.0/lib/factory_girl/strategy/create.rb:12:in `block in result' from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/factory_girl-4.0.0/lib/factory_girl/strategy/create.rb:9:in `tap' from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/factory_girl-4.0.0/lib/factory_girl/strategy/create.rb:9:in `result' from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/factory_girl-4.0.0/lib/factory_girl/factory.rb:42:in `run' from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/factory_girl-4.0.0/lib/factory_girl/factory_runner.rb:23:in `block in run' from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.0/lib/active_support/notifications.rb:125:in `instrument' from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/factory_girl-4.0.0/lib/factory_girl/factory_runner.rb:22:in `run' from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/factory_girl-4.0.0/lib/factory_girl/strategy_syntax_method_registrar.rb:19:in `block in define_singular_strategy_method' from (irb):17 from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.0/lib/rails/commands/console.rb:47:in `start' from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.0/lib/rails/commands/console.rb:8:in `start' from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.0/lib/rails/commands.rb:41:in `&lt;top (required)&gt;' from script/rails:6:in `require' from script/rails:6:in `&lt;main&gt;' </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload