<commit_before>package org.codehaus.groovy.grails.orm.hibernate
/**
 * @author <NAME>
 * @since 1.1
 */

public class CascadeValidationForDomainSubClassTests extends AbstractGrailsHibernateTests{

    protected void onSetUp() {
        gcl.parseClass('''
import grails.persistence.*

@Entity
class Book {
   String title
   Integer pages
   static belongsTo = [Author]
   static constraints = { pages(range: 0..100) }
}

@Entity
class Author {
   String name
   Book book
}

@Entity
class Novelist extends Author {
}
''')
    }

    void testCascadingValidation() {
      def Book = ga.getDomainClass("Book").clazz
      def Novelist = ga.getDomainClass("Novelist").clazz

      def b = Book.newInstance(title:'War & Peace', pages:9999) // pages violates range constraint
      def a = Novelist.newInstance(name:'Tolstoy', book:b)
      assert a.validate() == false : "Should have failed validation for subclass!"        
    }

}<commit_msg>changed name to avoid class name clash<commit_after>package org.codehaus.groovy.grails.orm.hibernate
/**
 * @author <NAME>
 * @since 1.1
 */

public class CascadeValidationForDomainSubClassTests extends AbstractGrailsHibernateTests{

    protected void onSetUp() {
        gcl.parseClass('''
import grails.persistence.*

@Entity
class CascadeValidationForDomainSubClassBook {
   String title
   Integer pages
   static belongsTo = [CascadeValidationForDomainSubClassAuthor]
   static constraints = { pages(range: 0..100) }
}

@Entity
class CascadeValidationForDomainSubClassAuthor {
   String name
   CascadeValidationForDomainSubClassBook book
}

@Entity
class CascadeValidationForDomainSubClassNovelist extends CascadeValidationForDomainSubClassAuthor {
}
''')
    }

    void testCascadingValidation() {
      def Book = ga.getDomainClass("CascadeValidationForDomainSubClassBook").clazz
      def Novelist = ga.getDomainClass("CascadeValidationForDomainSubClassNovelist").clazz

      def b = Book.newInstance(title:'War & Peace', pages:9999) // pages violates range constraint
      def a = Novelist.newInstance(name:'Tolstoy', book:b)
      assert a.validate() == false : "Should have failed validation for subclass!"        
    }

}
{'fraction_non_alphanumeric': 0.09720311783585511, 'fraction_numerical': 0.009170105456212746, 'mean_word_length': 4.0392609699769055, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1896245', 'n_tokens_mistral': 667, 'n_tokens_neox': 624, 'n_words': 152}