Sha256: 7745e0b58c643f4a67a876d15d848ae1cf9b608312655598a0bbc3b4662695cc
Contents?: true
Size: 1.8 KB
Versions: 17
Compression:
Stored size: 1.8 KB
Contents
require 'teststrap' context "validates associated" do should "add a validation macro" do WhyValidationsSuckIn96::ValidationBuilder.instance_methods end.includes('validates_associated') context "with some default options" do setup do WhyValidationsSuckIn96::ValidatesAssociated.new(Object.new, :attribute => :things) end should "have a message accessor with a default message" do topic.message end.equals("is invalid") end # with some default options context "validating a singular association" do associated = OpenStruct.new(:valid? => true) validatable = OpenStruct.new(:thing => associated) setup do WhyValidationsSuckIn96::ValidatesAssociated.new(validatable, :attribute => :thing) end should "be valid if associated object is valid" do def associated.valid?; true; end topic.validates? end should "be invalid if associated object is invalid" do def associated.valid?; false; end topic.validates? end.equals(false) end # validating a singular association context "validating a collection association" do associated = [OpenStruct.new(:valid? => true), OpenStruct.new(:valid? => false)] validatable = OpenStruct.new(:things => associated) setup do WhyValidationsSuckIn96::ValidatesAssociated.new(validatable, :attribute => :things) end should "be valid if all associated objects are valid" do associated.each do |assoc| def assoc.valid?; true; end end topic.validates? end should "be invalid if any associated objects are invalid" do associated.each do |assoc| def assoc.valid?; false; end end topic.validates? end.equals(false) end # validating a collection association end # validates associated
Version data entries
17 entries across 17 versions & 1 rubygems