Angel Ruiz
grails, spock, testing

Integrated vs Functional testing: how to test REST APIs in Grails using Spock

Angel Ruiz grails, spock, testing
This guide was written using Grails 2.4.4 although it should work the same for Grails 2.3.x and 3.x (almost the same :-P)

Since current official documentation only covers unit testing for controllers and that it took me a while to to figure them out completely, I thought I would leave it here in case it helps someone else.

The reason for writing these tests was to validate some REST API endpoints implemented using Grails Controllers.

Read More
Angel Ruiz
grails, how-to, javascript

How to render JSON properly (without escaping quotes) inside a GSP script tag

Angel Ruiz grails, how-to, javascript


Grails logo

This issue was encountered while using Grails version 2.3.11

In theory it should be as simple as:

  1. Return JSON in your model from your controller
def index() = {  
    [data: data as JSON]
}
  1. Render the model attribute without encoding using the raw() method
<r:script>  
    var data = ${raw(data)};
</r:script>  

Unfortunately this does not work, at least when you are using the resources plugin. You know it does not work because all the quotes have

Read More
Angel Ruiz
grails, plugins, how-to

How to reference a file inside a Grails plugin

Angel Ruiz grails, plugins, how-to


Grails logo

Recently I had to creat a Groovy script that copies some files from my plugin to the host application. The problem is I did not know how to reference those files inside my plugin.

If you have the same problem here is the solution:

String yourPluginDir = GrailsPluginUtils.pluginInfos.find { it.name == 'your-plugin-name' }.pluginDir  
Read More
Angel Ruiz
grails, migration, programming

Migrating from Grails 2.2 to 2.3

Angel Ruiz grails, migration, programming


Grails logo

I am writing this post to record all the things I have done in order to migrate an existing Grails 2.2.x app to 2.3.x.

The reasons for me to upgrade are:

  • Project progress is at an early stage where is not very risky to do that. We also have a considerable amount of automatic tests. You have also need to take into consideration that the more major versions you skip, the harder it gets to migrate
Read More