test/rails/association_validation_test.rb in whyvalidationssuckin96-1.6.1 vs test/rails/association_validation_test.rb in whyvalidationssuckin96-1.6.2
- old
+ new
@@ -5,108 +5,121 @@
has_association_validation = lambda do |klass,assoc|
!klass.validation_collection.detect do |(validation_klass,opts)|
validation_klass == WhyValidationsSuckIn96::ValidatesAssociated && opts[:attribute] == assoc && opts[:on] == :save
end.nil?
end
-
+
+ teardown do
+ next unless topic.kind_of?(Class)
+ Object.send(:remove_const, topic.name)
+ end
+
context "against has_many" do
context "with :validate set to true" do
setup do
- Class.new(Book) do
+ class ::TestBook < Book
has_many :chapters, :validate => true
+ self
end
end
-
+
should "set up an association validation" do
has_association_validation[topic, :chapters]
end
end # with :validate set to true
-
+
context "with :validate set to false" do
setup do
- Class.new(Book) do
+ class ::TestBook < Book
has_many :chapters, :validate => false
+ self
end
end
-
+
should "not set up an association validation" do
has_association_validation[topic, :chapters]
end.equals(false)
end # with :validate set to false
end # against has_many
-
+
context "against has_and_belongs_to_many" do
context "with :validate set to true" do
setup do
- Class.new(Genre) do
+ class ::TestGenre < Genre
has_and_belongs_to_many :books, :validate => true
+ self
end
end
-
+
should "set up an association validation" do
has_association_validation[topic, :books]
end
end # with :validate set to true
-
+
context "with :validate set to false" do
setup do
- Class.new(Genre) do
+ class ::TestGenre < Genre
has_and_belongs_to_many :books, :validate => false
+ self
end
end
-
+
should "not set up an association validation" do
has_association_validation[topic, :books]
end.equals(false)
end # with :validate set to false
end # against has_and_belongs_to_many
-
+
context "against has_one" do
context "with :validate set to true" do
setup do
- Class.new(Book) do
+ class ::TestBook < Book
has_one :glossary, :validate => true
+ self
end
end
-
+
should "set up an association validation" do
has_association_validation[topic, :glossary]
end
end # with :validate set to true
-
+
context "with :validate set to false" do
setup do
- Class.new(Book) do
+ class ::TestBook < Book
has_one :glossary, :validate => false
+ self
end
end
-
+
should "not set up an association validation" do
has_association_validation[topic, :glossary]
end.equals(false)
end # with :validate set to false
end # against has_one
-
+
context "against belongs_to" do
context "with :validate set to true" do
setup do
- Class.new(Chapter) do
+ class ::TestChapter < Chapter
belongs_to :book, :validate => true
+ self
end
end
-
+
should "set up an association validation" do
has_association_validation[topic, :book]
end
end # with :validate set to true
-
+
context "with :validate set to false" do
setup do
- Class.new(Chapter) do
+ class ::TestChapter < Chapter
belongs_to :book, :validate => false
+ self
end
end
-
+
should "not set up an association validation" do
has_association_validation[topic, :book]
end.equals(false)
end # with :validate set to false
end # against belongs_to
\ No newline at end of file