Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #15 Messages are now escaped properly for javascript
Add spock for testing, add ignores for intellij
- Loading branch information
1 parent
ca76e39
commit 44e838e
Showing
4 changed files
with
56 additions
and
5 deletions.
There are no files selected for viewing
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
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
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
44 changes: 44 additions & 0 deletions
44
test/unit/org/grails/jquery/validation/ui/JqueryValidationServiceSpec.groovy
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package org.grails.jquery.validation.ui | ||
|
||
import spock.lang.* | ||
import grails.test.mixin.* | ||
import org.springframework.context.MessageSource | ||
|
||
@TestFor(JqueryValidationService) | ||
public class JqueryValidationServiceSpec extends Specification { | ||
def setup() { | ||
String.metaClass.encodeAsJavaScript = { -> | ||
org.codehaus.groovy.grails.plugins.codecs.JavaScriptCodec.encode(delegate) | ||
} | ||
} | ||
|
||
@Issue("https://github.com/limcheekin/jquery-validation-ui/issues/15") | ||
def "Escaped messages"() { | ||
given: | ||
MessageSource messageSource = Mock() | ||
service.messageSource = messageSource | ||
|
||
when: | ||
def message = service.getMessage(this.class, "prop", null, "max", null) | ||
|
||
then: | ||
1 * messageSource.getMessage("${this.class.name}.prop.max", null, null, null) >> "my 'message'" | ||
0 * _._ | ||
message=="my \\'message\\'" | ||
} | ||
|
||
@Issue("https://github.com/limcheekin/jquery-validation-ui/issues/15") | ||
def "Escaped typeMismatch messages"() { | ||
given: | ||
MessageSource messageSource = Mock() | ||
service.messageSource = messageSource | ||
|
||
when: | ||
def message = service.getTypeMismatchMessage(this.class, null, null, "prop", null) | ||
|
||
then: | ||
1 * messageSource.getMessage("typeMismatch.${this.class.name}.prop", null, null, null) >> "my 'message'" | ||
0 * _._ | ||
message=="my \\'message\\'" | ||
} | ||
} |