{"action":"created","issue":{"url":"https://api.github.com/repos/solnic/virtus/issues/231","repository_url":"https://api.github.com/repos/solnic/virtus","labels_url":"https://api.github.com/repos/solnic/virtus/issues/231/labels{/name}","comments_url":"https://api.github.com/repos/solnic/virtus/issues/231/comments","events_url":"https://api.github.com/repos/solnic/virtus/issues/231/events","html_url":"https://github.com/solnic/virtus/issues/231","id":23966343,"number":231,"title":"Virtus + Factory Girl = trouble","user":{"login":"rzv01","id":6143342,"avatar_url":"https://avatars.githubusercontent.com/u/6143342?v=3","gravatar_id":"","url":"https://api.github.com/users/rzv01","html_url":"https://github.com/rzv01","followers_url":"https://api.github.com/users/rzv01/followers","following_url":"https://api.github.com/users/rzv01/following{/other_user}","gists_url":"https://api.github.com/users/rzv01/gists{/gist_id}","starred_url":"https://api.github.com/users/rzv01/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rzv01/subscriptions","organizations_url":"https://api.github.com/users/rzv01/orgs","repos_url":"https://api.github.com/users/rzv01/repos","events_url":"https://api.github.com/users/rzv01/events{/privacy}","received_events_url":"https://api.github.com/users/rzv01/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":9,"created_at":"2013-12-09T14:45:50Z","updated_at":"2016-06-02T22:04:52Z","closed_at":"2013-12-10T22:57:16Z","body":"I'm using Virtus and it works great for what I need, but it somehow interferes with FactoryGirl when creating objects for rspecs..\r\n\r\nSimply including Virtus.model into a model and trying to create an instance of it using FactoryGirl.create crashes spectacularly.. \r\n\r\nHere's the full stacktrace: \r\n```\r\n←[K  1) V1::ShopsController Example test Should work\r\n     Failure/Error: @shop = create(:shop)\r\n     NoMethodError:\r\n       undefined method `delete' for nil:NilClass\r\n     # H:/_work/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.0.0/lib/active_record/attribute_methods/write.rb:37:in `write_attribute'\r\n     # H:/_work/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.0.0/lib/active_record/attribute_methods/dirty.rb:70:in `write_attribute'\r\n     # H:/_work/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.0.0/lib/active_record/attribute_methods/write.rb:19:in `__temp__e616d656='\r\n     # H:/_work/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.0.0/lib/active_record/attribute_methods.rb:126:in `method_missing'\r\n     # H:/_work/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/factory_girl-4.3.0/lib/factory_girl/attribute_assigner.rb:16:in `block (2 levels) in object'\r\n     # H:/_work/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/factory_girl-4.3.0/lib/factory_girl/attribute_assigner.rb:15:in `each'\r\n     # H:/_work/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/factory_girl-4.3.0/lib/factory_girl/attribute_assigner.rb:15:in `block in object'\r\n     # H:/_work/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/factory_girl-4.3.0/lib/factory_girl/attribute_assigner.rb:14:in `tap'\r\n     # H:/_work/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/factory_girl-4.3.0/lib/factory_girl/attribute_assigner.rb:14:in `object'\r\n     # H:in `object'\r\n     # H:/_work/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/factory_girl-4.3.0/lib/factory_girl/strategy/create.rb:9:in `result'\r\n     # H:/_work/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/factory_girl-4.3.0/lib/factory_girl/factory.rb:42:in `run'\r\n     # H:/_work/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/factory_girl-4.3.0/lib/factory_girl/factory_runner.rb:23:in `block in run'\r\n     # H:/_work/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activesupport-4.0.0/lib/active_support/notifications.rb:161:in `instrument'\r\n     # H:/_work/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/factory_girl-4.3.0/lib/factory_girl/factory_runner.rb:22:in `run'\r\n     # H:/_work/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/factory_girl-4.3.0/lib/factory_girl/strategy_syntax_method_registrar.rb:20:in `block in define_singular_strategy_m\r\nethod'\r\n     # ./spec/controllers/v1/shops_controller_spec.rb:187:in `block (3 levels) in <top (required)>'\r\n     # H:/_work/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/example.rb:237:in `instance_eval'\r\n     # H:/_work/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/example.rb:237:in `instance_eval'\r\n     # H:/_work/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/hooks.rb:21:in `run'\r\n     # H:/_work/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/hooks.rb:85:in `block in run'\r\n     # H:/_work/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/hooks.rb:85:in `each'\r\n     # H:/_work/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/hooks.rb:85:in `run'\r\n     # H:/_work/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/hooks.rb:446:in `run_hook'\r\n     # H:/_work/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:345:in `run_before_each_hooks'\r\n     # H:/_work/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/example.rb:294:in `run_before_each'\r\n     # H:/_work/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/example.rb:113:in `block in run'\r\n     # H:/_work/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/extensions/instance_eval_with_args.rb:16:in `instance_exec'\r\n     # H:/_work/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/extensions/instance_eval_with_args.rb:16:in `instance_eval_with_args'\r\n     # H:/_work/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/example.rb:247:in `instance_eval_with_args'\r\n     # H:/_work/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/hooks.rb:106:in `block (2 levels) in run'\r\n     # H:/_work/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/example.rb:179:in `call'\r\n     # H:/_work/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/example.rb:179:in `run'\r\n     # H:/_work/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/extensions/instance_eval_with_args.rb:16:in `instance_exec'\r\n     # H:/_work/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/extensions/instance_eval_with_args.rb:16:in `instance_eval_with_args'\r\n     # H:/_work/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/example.rb:247:in `instance_eval_with_args'\r\n     # H:/_work/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/hooks.rb:106:in `block (2 levels) in run'\r\n     # H:/_work/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/hooks.rb:108:in `call'\r\n     # H:/_work/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/hooks.rb:108:in `run'\r\n     # H:/_work/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/hooks.rb:446:in `run_hook'\r\n     # H:/_work/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:340:in `run_around_each_hooks'\r\n     # H:/_work/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/example.rb:256:in `with_around_each_hooks'\r\n     # H:/_work/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/example.rb:111:in `run'\r\n     # H:/_work/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:390:in `block in run_examples'\r\n     # H:/_work/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:386:in `map'\r\n     # H:/_work/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:386:in `run_examples'\r\n     # H:/_work/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:371:in `run'\r\n     # H:/_work/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:372:in `block in run'\r\n     # H:/_work/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:372:in `map'\r\n     # H:/_work/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:372:in `run'\r\n     # H:/_work/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/command_line.rb:28:in `block (2 levels) in run'\r\n     # H:/_work/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/command_line.rb:28:in `map'\r\n     # H:/_work/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/command_line.rb:28:in `block in run'\r\n     # H:/_work/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/reporter.rb:58:in `report'\r\n     # H:/_work/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/command_line.rb:25:in `run'\r\n     # H:/_work/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/runner.rb:80:in `run'\r\n     # H:/_work/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/runner.rb:17:in `block in autorun'\r\n```\r\nFrom what I could glean by browsing through the source code of ActiveRecord (4.0), the @attributes_cache hash isn't initialized.. the initialization happens in a method called init_internals (in file core.rb of AR), which in turn is called in initialize (and some other places).. \r\n\r\nFor whatever reason, when including Virtus.model, this \"process\" is skipped and that hash (and some others) are nil, therefore leading to this error.\r\n\r\nOnce again, this works fine when calling from a controller, it's creating with FactoryGirl that causes the issue.\r\n\r\nAny idea about this behavior? Been pulling my hairs for the past few days over this.. \r\n\r\nLet me know if you need other details!\r\n\r\nThanks a lot in advance!\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/solnic/virtus/issues/comments/223436708","html_url":"https://github.com/solnic/virtus/issues/231#issuecomment-223436708","issue_url":"https://api.github.com/repos/solnic/virtus/issues/231","id":223436708,"user":{"login":"dkniffin","id":1680080,"avatar_url":"https://avatars.githubusercontent.com/u/1680080?v=3","gravatar_id":"","url":"https://api.github.com/users/dkniffin","html_url":"https://github.com/dkniffin","followers_url":"https://api.github.com/users/dkniffin/followers","following_url":"https://api.github.com/users/dkniffin/following{/other_user}","gists_url":"https://api.github.com/users/dkniffin/gists{/gist_id}","starred_url":"https://api.github.com/users/dkniffin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dkniffin/subscriptions","organizations_url":"https://api.github.com/users/dkniffin/orgs","repos_url":"https://api.github.com/users/dkniffin/repos","events_url":"https://api.github.com/users/dkniffin/events{/privacy}","received_events_url":"https://api.github.com/users/dkniffin/received_events","type":"User","site_admin":false},"created_at":"2016-06-02T22:04:52Z","updated_at":"2016-06-02T22:04:52Z","body":"Fyi for anyone having issues with factory_girl and virtus, #271 is related."}}
{"actor":{"display_login":"dkniffin"}}