Created
March 1, 2012 03:35
-
-
Save leadVisionary/1947063 to your computer and use it in GitHub Desktop.
Initial stab
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.visionarysoftwaresolutions | |
import grails.test.mixin.* | |
import org.junit.* | |
/** | |
* See the API for {@link grails.test.mixin.web.ControllerUnitTestMixin} for usage instructions | |
*/ | |
@TestFor(DemoController) | |
@Mock([ ZapCard, Zapper ]) | |
class DemoControllerTests { | |
void setUp(){ | |
def control = mockFor(DatastoreService) | |
control.demand.exchangeCards { Zapper o, String n, String pn -> | |
return new ZapCard(name:n, phoneNumber:pn, owner:o, parseObjectId: "dummy") | |
} | |
controller.datastoreService = control.createMock() | |
def zapp = Zapper.findByEmail("zapp@zapapp.com") ?: | |
new Zapper(email:"zapp@zapapp.com",parseObjectId:"boobah").save() | |
def card = ZapCard.findByName("Zapp Appiganigan") ?: | |
new ZapCard( owner: zapp, | |
name:"Zapp Appiganigan", | |
phoneNumber:"999-999-9999", | |
parseObjectId:"loory").save() | |
} | |
void testLiveWhenCardAlreadyLocal(){ | |
def zapper = new Zapper(email:"moo@you.com", parseObjectId:"112233").save() | |
def newCard = new ZapCard( | |
name:"Visionary Software Solutions", | |
phoneNumber: "(480)111-2222", | |
owner:zapper, | |
parseObjectId:"FOOTCHIE" | |
).save() | |
controller.params.email = zapper.email | |
controller.params.name = newCard.name | |
controller.params.phoneNumber = newCard.phoneNumber | |
println "What exists right now ${ZapCard.list()}" | |
def model = controller.live() | |
assert "Zapp Appiganigan" == model.card.name | |
assert "999-999-9999" == model.card.phoneNumber | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment