module ObjectDaddy::RailsClassMethods
Public Instance Methods
Source
# File lib/object_daddy.rb, line 188 def exemplar_path paths = ['spec', 'test'].inject([]) do |array, dir| if File.directory?(File.join(RAILS_ROOT, dir)) array << File.join(RAILS_ROOT, dir, 'exemplars') end array end end
Source
# File lib/object_daddy.rb, line 216 def generate(args = {}) spawn(args) do |instance| instance.save yield instance if block_given? end end
Creates and tries to save an instance of this class, using any known generators. The generated instance is yielded to a block if provided.
This will not raise errors on a failed save. Use generate! if you want errors raised.
Source
# File lib/object_daddy.rb, line 234 def generate!(args = {}) spawn(args) do |instance| instance.save! yield instance if block_given? end end
Creates and tries to save! an instance of this class, using any known generators. The generated instance is yielded to a block if provided.
This will raise errors on a failed save. Use generate if you do not want errors raised.
Source
# File lib/object_daddy.rb, line 197 def validates_presence_of_with_object_daddy(*attr_names) @presence_validated_attributes ||= {} new_attr = attr_names.dup new_attr.pop if new_attr.last.is_a?(Hash) new_attr.each {|a| @presence_validated_attributes[a] = true } validates_presence_of_without_object_daddy(*attr_names) end