-
Notifications
You must be signed in to change notification settings - Fork 17
Open
Description
Hi there,
I'm having difficulties saving an object with a polymorphic association that's empty.
This is my code:
class Object < ActiveRecord::Base
include Tenacity
t_has_one :tag, as: :taggable
endclass Tag
include Mongoid::Document
include Tenacity
t_belongs_to :taggable, polymorphic: true
endt = Tag.new
t.valid? # NoMethodError: undefined method `empty?' for nil:NilClass
# from /home/.../gems/tenacity-0.6.0/lib/tenacity/association.rb:115:in `qualified_const_get'
t.save # Same errorBut if I add a taggable object to it, it works as expected:
t = Tag.new
t.taggable = Object.new
t.valid? # true
t.save # trueTo solve this I used Rails' blank? method in several places:
- in
lib/tenacity/instance_methods.rb:21I changedunless associate_id.nil?tounless associate_id.blank? - in
lib/tenacity/association.rb:114I changedreturn nil if clazz.nil?toreturn nil if clazz.blank? - and in
lib/tenacity/associations/belongs_to.rb:21I changedclazz._t_find(associate_id)toclazz._t_find(associate_id) unless clazz.nil?.
Rethinking it, using blank? isn't good, because this gem should work without Rails. I also tried to run the tests but I had difficulties installing the rcov gem.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels