title: Grails unit test mocking domain class within its controller
body: <p>I am new with grails. In my web application I am using spock for unit test.</p>
  
  <p>I have used searchable plugin for search functionality.</p>
  
  <p>In my controller search method is defined as :</p>
  
  <pre><code>def search(SearchQueryCommand searchQueryCommand) {
          def question
          if (!searchQueryCommand.q?.trim() &amp;&amp; !searchQueryCommand.tag?.trim() &amp;&amp; !searchQueryCommand.name?.trim()) {
              params.sort='sortableTitle'
              params.order='desc'
              question = Question.search(MessageStatusEnum.ACTIVE.getType().toString(), params)
          }
      render(view: "include_questionlist", model: [questionList: question.results, totalSize:question.total , max:params.max?:'Constants.PAGINATION_DEFAULT_MAX', pagination:true ,questionDescription:true])
  }
  </code></pre>
  
  <p>while testing I have defined </p>
  
  <pre><code>void "action search questions : search with blank search query" () {
  
          setup:
          controller.params.q=""
          mockForConstraintsTests(Question)
          mockDomain(User)
          def question1 =new Question(title:'demo1', owner:new User(username:"Jini").save())
          def question2 =new Question(title:'demo2', owner:new User(username:"Jini").save())
  
          Question.search() &gt;&gt; [question1,question2]
          when:
          controller.search()
  
          then:
          view == '/question/include_questionlist'
  
      }
  </code></pre>
  
  <p>But I cannot mock Question.search() method.</p>
  
  <p>Error message receiving as </p>
  
  <pre><code>Failure:  action search questions : search with blank search query(com.orb.question.QuestionControllerSpec)
  |  groovy.lang.MissingMethodException: No signature of method: com.orb.question.Question.search() is applicable for argument types: (java.lang.String, org.codehaus.groovy.grails.web.servlet.mvc.GrailsParameterMap) values: [1992, [q:, sort:sortableTitle, order:desc]]
  Possible solutions: each(groovy.lang.Closure), attach(), merge(), refresh(), save(), attach()
      at org.grails.datastore.gorm.GormStaticApi.methodMissing(GormStaticApi.groovy:97)
      at com.orb.question.QuestionController.search(QuestionController.groovy:115)
      at com.orb.question.QuestionControllerSpec.action search questions : search with blank search query(QuestionControllerSpec.groovy:200)
  | Completed 22 spock tests, 1 failed in 7480ms
  </code></pre>
  
  <p>please anyone help me to resolve this issue.</p>
  
  <p>Thanks in advance.</p>