Grails 2.0 - Upgrading Controller Testing and losing renderArgs and redirectArgs - grails-2.0

Problem:
I upgraded from Grails 1.3.7 to Grails 2.0.
I had to then refactor my controller tests to use annotations: #TestFor(controller) and Mock(domain) which took care of a lot of problems.
However, in 1.3.7 controller.renderArgs and controller.redirectArgs were available. This seems to no longer be the case in 2.0 and I am having a difficult time figuring out how to get the data these very convenient variables provided.
It appears that this data will not be provided based off of this Grails Jira posting. The last comment in this post by James Lang, which has no response, is my exact question:
In Grails 2.0 controller unit testing, how can you get to the renderArgs such as action, id, params, etc?
The Jira comments only supply inputs to getting to the response.redirectUrl
Any ideas?

Thanks for the update and the link to the post by Graeme.
Our solution to the problem was to metaclass the controller to get to these variables.
I created corresponding member variables and then added the following code to the setup of the unit test:
controller.metaClass.redirect = { Map map ->
redirectAction = map.action
redirectID = map.id
redirectUrl = map.url
}
controller.metaClass.render = {Map map ->
renderView = map.view
renderModel = map.model
}

At the moment it appears you can't. I saw this forum post where Graeme replied and mentioned it would take a feature request.

Related

Why the parameter TransitRadius in HERE Routing API with public transport do not change the response

Trying to use the parameter TransitRaduis in the routing API of HERE. It works well with 'car mode' but when using it with 'public transport' it seems to me that it changes nothing !
So setting one waypoint with the following three differents ways, gives the same result !
&waypoint0=geo!37.7914050,-122.3987030
&waypoint0=geo!37.7914050,-122.3987030;50
&waypoint0=geo!37.7914050,-122.3987030;500
To request a public transport route using the CalculateRoute service you need to specify a departure time as
https://route.api.here.com/routing/7.2/calculateroute.json?app_id={YOUR_APP_ID}&app_code={YOUR_APP_CODE}&waypoint0=geo!52.530,13.326&waypoint1=geo!52.513,13.407&departure=now&mode=fastest;publicTransport&combineChange=true
For further details kindly go through the documentation
https://developer.here.com/documentation/routing/topics/request-public-transport-routes.html
Good Luck !

Use PUT or PATCH verb when request is updating and deleting: Real life design

I've been trying to get the HTTP verbs right lately, however I have a doubt regarding using PUT, PATCH or even POST for the following scenario.
The front end part is sending the following JSON data:
{
name: "Spanish-01",
code: "ESP01",
students: [{
IdStudent: 1,
name: "Peter Parker"
},
{
IdStudent: 2
name: "Ben Reilly",
dirtyRemove: true
}]
}
The back end code will update the Class record (e.g name and code). However, it will also delete the students with flag dirtyRemove, and those live in another table called Student.
So what's the rule here? Since PUT and PATCH according to w3.org here is for updating an existing resource. In this case the back end is both updating and deleting at the same time?
Should I use PUT or PATCH or neither?
NOTE: Don't mind about the FE part, I minimized the scope in order to get a more straightforward example
How your resources are implemented internally using tables is an implementation detail. It doesn't matter.
That said, your example payload doesn't fit PUT (to remove a student, you would omit it). It might fit PATCH, if you properly label the payload with a content type describing what semantics you expect.
Nit: the HTTP spec is not a W3 document, and the version you're looking at is outdated.

Javascript and Wordpress

Two related questions:
Is there any good documentation on the Fusion Tables Javascript API? I've found a list of methods, but with little info on return values, semantics, or usage idioms.
Is there any guidance (or suggested plugins or idioms) for integrating the FT Javascript API into a locally hosted Wordpress site?
There is some documentation here:
https://developers.google.com/fusiontables/docs/v1/getting_started#JS
but I didn't find it very useful.
But this example, in the context of the Google Maps API I found very useful for the new API 1.0
https://googledrive.com/host/0B5KVZ6J1ohN_Q3ZqVkFGSGZ2cEE/custom%20markers%20code/customicons_viaApi.html
You'll need to view and save the source. Also if you search the FT tag for JSONP you will find many examples using the old pre 1.0 API but the concepts are the same, just the AJAX end point has changed and the need for an apiKey.
The basic idea is that any FT query will return a JSON object with both columns and rows members, very much like a CSV response.
As the example above shows:
function onDataFetched(data) {
var rows = data.rows;
var cols = data.cols;
...
}

Returning ItemStats from Tridion UGC

I was wondering if anyone can offer any pointers on this one. I'm trying to return ItemStats from the Tridion UGC web service but I'm getting the following error when trying to bind the results:-
The closed type TridionWebUGC.CDS.ItemStat does not have a corresponding LastRatedDate settable property.
An example of code is:-
WebServiceClient ugcCall2 = new WebServiceClient();
Uri uri = new Uri("http://new.ugc.service/odata.svc");
CDS.ContentDeliveryService cds = new CDS.ContentDeliveryService(uri);
var myItemStats = cds.ItemStats.Where(p => p.PublicationId == 68 && p.Id == 17792 && p.Type==16);
I can get comments and ratings with no problem. E.g.
var myComments = cds.Comments.Where(p => p.ItemId == 17805).OrderBy(p => p.CreationDate);
It's just ItemStats that are giving me an issue. Anybody any ideas?
Thanks
John
Unfortunately, the metadata of the UGC WebService is not correct in regards to the ItemsStats. For you it means that the webservice metadata does not expose the fact that the ItemStat entity contains the LastRatedDate property. This makes your .NET proxies not to be aware of this property and makes your query fail.
To work-around this defect you have two option:
Add to your service the following property: cds.IgnoreMissingProperties = true;. Advantage of this approach is that you're done with it in 2 sec. Disadvantage is that you will not be able to access that property (in case you actually use it);
Modify the proxies generated by Visual Studio and manually add that property to the ItemStat class. Advantage of this approach is that you will be able to access the property from your project. Disadvantage is that it's totally not manageable from the coding point of view, you need to be careful when you upgrade or regenerate the proxies and it's easy to make a mistake while manually adding the property.
Note 1: to access the metadata of your webServer from the browser your can go to /odata.svc/$metadata.
Note 2: on a closer look there are 2 properties missing from the webService metadata: LastRatedDate and LastCommentedDate.
Hope this helps.

Drupal node.save and JSONP

I am having an issue with call Drupal node.save using MooTool's JSONP. Here is an example.
Here is my request:
callback Request.JSONP.request_map.request_1
method node.save
sessid 123123123123123
node {"type":"blog","title":"New Title","body":"This is the blog body"}
Here is my result
HTTP/1.0 500 Internal Server Error
I got this working before, but i used AMFPHP and was able to send objects to drupal. I am assuming that this has to do with Drupal expecting an object, but since it is a GET it gets transformed as a string. Is there any way of getting around this with out hacking the code?
Here is my code:
$('newBlogSubmit').addEvent('click', function()
{
var node = {
type : "blog",
title:"New Title",
body :"This is the blog body"
}
var string = JSON.encode(node);
string.escapeRegExp()
var sessID = _sessID;
DrupalService.getInstance().node_save(string, sessID, drupal_handleBlogSubmit);
});
My Drupal Service JS Code:
//NODE
DrupalService.prototype.node_save = function(node, sessid, callback){
var dataObj = {
method : "node.save",
sessid : sessid,
node : node
}
DrupalService.getInstance().request(dataObj, callback);
}
//SEND REQUEST AND CALLBACK FUNCTION
DrupalService.prototype.request = function(dataObject, callback){
new JsonP('http://myDrupalSite.com/services/json', {data: dataObject,onComplete: callback}).request();
}
I am trying to connect the dots, but not too familiar with Drupal, but i would guess all I need to do is turn the string back into an object. Any ideas where I should be looking, or if there is an existing patch?
A first question could be why you use mootools since Drupal comes with jQuery and use it extensively throughout the different modules and Drupal core itself.
Anyways I don't know mootools so can't help you there, but if your request in ending in a internal server error, you have a problem with your drupal code or your js code. So even if I knew exactly what you were doing, I couldn't tell you the problem without looking at the drupal code for your http://myDrupalSite.com/services/json callback.
In general, what you want to make sure is:
You make a POST request, as drupal will cache get's and the semantic of this, is that you are posting data - the node - to the server.
Your data should be sent as post params, this will make them end up in the PHP $_POST variable
Your callback should validate the data and act accordingly, creating a node when the data is intact. You don't need session id's since the script will have the same session the browser has.
I've answered a similar question in detail, which was about altering a field instead of saving a node, but much of the work is still the same. You can take a look on the post, although this is with jQuery and not Mootools.

Resources