Changeset 860


Ignore:
Timestamp:
Aug 30, 2010, 3:13:30 PM (13 years ago)
Author:
keesvb
Message:

added test for Sample name uniqueness at the validate() stage

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/conf/BootStrap.groovy

    r858 r860  
    115115
    116116                        // If in development mode and no studies are present, add example studies
    117                         if (Study.count() == 0) { // && grails.util.GrailsUtil.environment == GrailsApplication.ENV_DEVELOPMENT) {
     117                        if (Study.count() == 0 && grails.util.GrailsUtil.environment != GrailsApplication.ENV_TEST) {
    118118                                // check if special file is present in project directory
    119119                                if ((new File(System.properties['user.dir']+"/.skip-studies").exists())) {
  • trunk/test/integration/gscf/SampleTests.groovy

    r817 r860  
    291291        }
    292292
     293        /**
     294         * Test whether it's indeed not possible to add two yet-to-be-saved samples with the same name to a yet-to-be-saved study
     295         */
     296        void testSampleUniqueNameConstraintAtValidate() {
     297                def sample = Sample.findByName(testSampleName)
     298                assert sample
     299
     300                def study = sample.parent
     301                assert study
     302
     303                def sample1 = new Sample(
     304                    name: testSampleName + "-double",
     305                    template: sample.template,
     306                    parentEvent: sample.parentEvent
     307                )
     308
     309                def sample2 = new Sample(
     310                        name: testSampleName + "-double",
     311                    template: sample.template,
     312                    parentEvent: sample.parentEvent
     313                )
     314
     315                // Add the sample to the retrieved parent study
     316                study.addToSamples(sample1)
     317                study.addToSamples(sample2)
     318
     319                // At this point, the sample should not validate or save, because there is already a sample with that name in the study
     320                assert !sample1.validate()
     321                assert !sample1.save(flush:true)
     322
     323                assert !sample2.validate()
     324                assert !sample2.save(flush:true)
     325        }
     326
    293327        void testFindViaSamplingEvent() {
    294328                // Try to retrieve the sampling event by using the time...
Note: See TracChangeset for help on using the changeset viewer.