Chapter 6. Controlling application flow

 

This chapter covers

  • Introducing mocking
  • Unit testing your view code
  • Exploring scopes
  • Working with redirects

In chapters 3 and 5, you learned how Grails handles domain objects as you went about creating, updating, saving, deleting, and querying all kinds of domain classes. Along the way, you used scaffolding controllers to route the user around the application, and you implemented a few GSP views to host your forms. But, for the most part, you ignored how controllers do their work. It’s time to set that right.

In this chapter, we’ll focus exclusively on controllers—and all the important roles they play in dealing with data from the web tier, routing it to services, and shipping off results to the view. And all those Spock testing skills you’ve been learning along the way? Well, you’ll extend those into the controller space, learning a whole swag of new techniques for controller-specific testing to make sure all the new code you write is rock solid. By the end of the chapter, you’ll be ready to implement all the common controller use cases in your own applications as well as many of the edge cases.

We’ll get the chapter underway by pulling together all you’ve learned so far about controllers, forms, and domain classes. Then we’ll show you how to modify Hubbub to add and display user posts on a Twitter-style timeline.

6.1. Controller essentials

6.2. Implementing a timeline for Hubbub

6.3. Testing controller actions: an introduction to mocking

6.4. From controller to view

6.5. Exploring scopes

6.6. Handling default actions

6.7. Summary and best practices

sitemap