user.coffee 680 B

123456789101112131415161718192021222324
  1. define [
  2. "libs/chai"
  3. "models/User"
  4. "libs/sinon"
  5. ], (chai, User) ->
  6. describe "User", ->
  7. describe "findOrBuild", ->
  8. describe "with an existing model", ->
  9. beforeEach ->
  10. @user = User.build "user-1"
  11. @user.set("email", "test@example.com")
  12. it "should return the same model", ->
  13. @newUser = User.findOrBuild "user-1", email: "new@example.com"
  14. @newUser.should.equal @user
  15. @newUser.get("email").should.equal "new@example.com"
  16. describe "without an existing model", ->
  17. it "should return new a model with the correct id", ->
  18. user = User.findOrBuild("user-2")
  19. user.id.should.equal "user-2"
  20. afterEach ->
  21. User.loadedModels = {}