Grails
  1. Grails
  2. GRAILS-8360

Unique constraint is not working with in-memory GORM implementation

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0-RC1
    • Fix Version/s: 2.0-RC2
    • Component/s: Persistence, Testing
    • Labels:
    • Environment:
      Kubuntu linux, IntellijIDEA 10.5.2
    • Testcase included:
      yes

      Description

      I have a simple class and test for it:

      class User {
          String username
      
          static constraints = {
              username(unique: true)
          }
      }
      
      @TestFor(User)
      @Mock(User)
      class UserTests {
      
          void testUniqueConstraintSave() {
              def first = new User(username: "foo")
              assert first.save()
              def second = new User(username: "foo")
              assert !second.save() //fails
          }
      }
      

      Second User instance is saved correctly. Of course it's wrong since it has the same username as first instance. It only occurs in unit tests. If you simulate the same with scaffolded controller and views - unique constraint is working properly.

        Issue Links

          Activity

          Show
          Graeme Rocher added a comment - Fixed by https://github.com/SpringSource/grails-data-mapping/commit/0b654470f11cc917295e6ec76c1328b7fff30edc
          Hide
          Tomasz Kalkosinski added a comment -

          Thank you!

          Show
          Tomasz Kalkosinski added a comment - Thank you!

            People

            • Assignee:
              Graeme Rocher
              Reporter:
              Tomasz Kalkosinski
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development