<commit_before>package org.codehaus.groovy.grails.orm.hibernate;

import org.codehaus.groovy.grails.commons.*
import org.codehaus.groovy.grails.commons.test.*

class SavePersistentMethodTests extends AbstractGrailsHibernateTests {     

    void testFlush() {
        def bookClass = ga.getDomainClass("Book")
        def authorClass = ga.getDomainClass("Author")
        def addressClass = ga.getDomainClass("Address")

        def book = bookClass.newInstance()
        book.title = "Foo"
        def author = authorClass.newInstance()
        book.author = author
        author.name = "Bar"
        def address = addressClass.newInstance()
        author.address = address
        address.location = "Foo Bar"

        assert book.save(flush:true)
        assert book.id
    }
	void testToOneCascadingValidation() {
        def bookClass = ga.getDomainClass("Book")
        def authorClass = ga.getDomainClass("Author")
        def addressClass = ga.getDomainClass("Address")

        def book = bookClass.newInstance()

        assert !book.save()
        assert !book.save(deepValidate:false)

        book.title = "Foo"

        assert !book.save()
        assert !book.save(deepValidate:false)

        def author = authorClass.newInstance()        
        author.name = "Bar"
        author.save()
        
        book.author = author

        // will validate book is owned by author
        assert book.save()
        assert book.save(deepValidate:false)


        assert book.save()
        assert book.save(deepValidate:false)

        def address = addressClass.newInstance()

        author.address = address

        assert !author.save()
        

        address.location = "Foo Bar"

        assert author.save()
        assert author.save(deepValidate:false)
	}

	void testToManyCascadingValidation() {
        def bookClass = ga.getDomainClass("Book")
        def authorClass = ga.getDomainClass("Author")
        def addressClass = ga.getDomainClass("Address")

        def author = authorClass.newInstance()

        assert !author.save()
        author.name = "Foo"

        assert !author.save()
        assert !author.save(deepValidate:false)

        def address = addressClass.newInstance()
        author.address = address

        assert !author.save()


        address.location = "Foo Bar"
        assert author.save()


        def book = bookClass.newInstance()

        author.addToBooks(book)
        assert !author.save()
        

        book.title = "TDGTG"
        assert author.save()
        assert author.save(deepValidate:false)
	}

	void onSetUp() {
		this.gcl.parseClass('''
class Book {
    Long id
    Long version
    String title
    Author author
    static belongsTo = Author
    static constraints = {
       title(blank:false, size:1..255)
       author(nullable:false)
    }
}
class Author {
   Long id
   Long version
   String name
   Address address
   Set books = new HashSet()
   static hasMany = [books:Book]
   static constraints = {
        address(nullable:false)
        name(size:1..255, blank:false)
   }
}
class Address {
    Long id
    Long version
    Author author
    String location
    static belongsTo = Author
    static constraints = {
       author(nullable:false)
       location(blank:false)
    }
}
'''
		)
	}
	
	void onTearDown() {
		
	}
}<commit_msg>attempted fix for failing test, seems a conflict with class names introduced?<commit_after>package org.codehaus.groovy.grails.orm.hibernate;

import org.codehaus.groovy.grails.commons.*
import org.codehaus.groovy.grails.commons.test.*

class SavePersistentMethodTests extends AbstractGrailsHibernateTests {     

    void testFlush() {
        def bookClass = ga.getDomainClass("SaveBook")
        def authorClass = ga.getDomainClass("SaveAuthor")
        def addressClass = ga.getDomainClass("SaveAddress")

        def book = bookClass.newInstance()
        book.title = "Foo"
        def author = authorClass.newInstance()
        book.author = author
        author.name = "Bar"
        def address = addressClass.newInstance()
        author.address = address
        address.location = "Foo Bar"

        assert book.save(flush:true)
        assert book.id
    }
	void testToOneCascadingValidation() {
        def bookClass = ga.getDomainClass("SaveBook")
        def authorClass = ga.getDomainClass("SaveAuthor")
        def addressClass = ga.getDomainClass("SaveAddress")

        def book = bookClass.newInstance()

        assert !book.save()
        assert !book.save(deepValidate:false)

        book.title = "Foo"

        assert !book.save()
        assert !book.save(deepValidate:false)

        def author = authorClass.newInstance()        
        author.name = "Bar"
        author.save()
        
        book.author = author

        // will validate book is owned by author
        assert book.save()
        assert book.save(deepValidate:false)


        assert book.save()
        assert book.save(deepValidate:false)

        def address = addressClass.newInstance()

        author.address = address

        assert !author.save()
        

        address.location = "Foo Bar"

        assert author.save()
        assert author.save(deepValidate:false)
	}

	void testToManyCascadingValidation() {
        def bookClass = ga.getDomainClass("SaveBook")
        def authorClass = ga.getDomainClass("SaveAuthor")
        def addressClass = ga.getDomainClass("SaveAddress")

        def author = authorClass.newInstance()

        assert !author.save()
        author.name = "Foo"

        assert !author.save()
        assert !author.save(deepValidate:false)

        def address = addressClass.newInstance()
        author.address = address

        assert !author.save()


        address.location = "Foo Bar"
        assert author.save()


        def book = bookClass.newInstance()

        author.addToBooks(book)
        assert !author.save()
        

        book.title = "TDGTG"
        assert author.save()
        assert author.save(deepValidate:false)
	}

	void onSetUp() {
		this.gcl.parseClass('''
class SaveBook {
    Long id
    Long version
    String title
    SaveAuthor author
    static belongsTo = SaveAuthor
    static constraints = {
       title(blank:false, size:1..255)
       author(nullable:false)
    }
}
class SaveAuthor {
   Long id
   Long version
   String name
   SaveAddress address
   Set books = new HashSet()
   static hasMany = [books:SaveBook]
   static constraints = {
        address(nullable:false)
        name(size:1..255, blank:false)
   }
}
class SaveAddress {
    Long id
    Long version
    SaveAuthor author
    String location
    static belongsTo = SaveAuthor
    static constraints = {
       author(nullable:false)
       location(blank:false)
    }
}
'''
		)
	}
	
	void onTearDown() {
		
	}
}
{'fraction_non_alphanumeric': 0.09632892804698973, 'fraction_numerical': 0.0023494860499265785, 'mean_word_length': 2.299903100775194, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1895051', 'n_tokens_mistral': 1976, 'n_tokens_neox': 1887, 'n_words': 439}