title: How to create Grails domain object but do not save?
body: <p>I have a method that should create a domain object.  However, if during the course of building the object a condition occurs, the method should just return and not save the object.  </p>
  
  <p>Given:</p>
  
  <pre><code>class SomeDomainObjectClass {
      String name
  }
  
  class DomCreatorService {
      def createDom() {
          SomeDomainObjectClass obj = new SomeDomainObjectClass(name: "name")
  
          // do some processing here and realise we don't want to save the object to the database
          if (!dontWannaSave) {
              obj.save(flush: true)
          }
      }
  }
  </code></pre>
  
  <p>within my test (service is instance of DomCreatorService):</p>
  
  <pre><code>expect: "it doesn't exist at first" 
  SomeDomainObjectClass.findByName("name") == null
  
  when: "we attempt to create the object under conditions that mean it shouldn't be saved"
  // assume that my test conditions will mean dontWannaSave == true and we shouldn't save     
  service.createDom() 
  
  then: "we shouldn't be able to find it and it shouldn't exist in the database"
  // check that we still haven't created an instance
  SomeDomainObjectClass.findByName("name") == null
  </code></pre>
  
  <p>My last line is failing.  Why does the last findByName return true, i.e. why can my object be found?  I thought it would only find objects saved to the database.  What should I be testing for to see if my object has not been created?</p>