I'm trying to do some Rails integration testing.
I have a case almost right out of the Rails guide on form helpers.
My HTML contains:
<input name="to_org[][str2int]" value="1" type="checkbox">
<input name="to_org[][str2int]" value="2" type="checkbox">
<input name="to_org[][str2int]" value="3" type="checkbox">
The application works fine with Rails 3.2.2.
Now I want to write an integration test. I need to post the the data the
same way my JavaScript does. I'd like to indicate "to_org[]" values 1 and
2 are selected. Assume form_url is a properly set value.
post( form_url, { "to_org[][str2int]" => ???WHAT_GOES_HERE??? } )
After the post, I'm expecting params to hold:
"to_org" => [ {"str2int" => "1"}, {"str2int" => "2"} ]
I've tried a bunch of different things, looked through the guides, googled.
Hasn't anyone tried to post the result of multiple checkboxes being
checked? I don't think the answer is obvious.
How does one set the parameters for post() in integration test to make
this work?
PS: As one might guess, I have a filter that recognizes "str2int", and
does the conversion with appropriate checking and error recovery for the
app. Eventually my app sees :to_org = [ 1, 2 ].
Basically, I did some digging through the rails code (would be nice to
see it make the API documentation.)
A right answer is:
post( form_url, { "to_org" => [ { "str2int" => "1" }, { "str2int" => "2" } ] } )
Most helpful was discovering the to_param() function, as in:
{ "to_org" => [ { "str2int" => "1" }, { "str2int" => "2" } ] }.to_param()
This allowed me to deduce the fact that I had to vary what I used as the
name to get the values passed thru post() correctly.
Rails gods: Is there a better way to do this? More that should be said?
Related
I have extended database table fe_users with new field using extension builder. The fields are visible in backend user-interface, but not available in frontend in Typo3 10.4.x . But the same code works fine in Typo3 9.x frontend and backend.
I have also tried setting recordType to nothing in the ext_typoscript_setup.typoscript but this also does not help
mapping {
tableName = fe_users
recordType =
}
Any ideas on what more to look for?
The table mapping of the Extbase persistence is not longer possible in TypoScript. Migrate your TypoScript to a PHP file named EXT:myextension/Configuration/Extbase/Persistence/Classes.php.
See breaking change 87623 for further details.
A typical Classes.php file looks like the following.
<?php
return [
\Vendor\Extension\Domain\Model\Object::class => [
'tableName' => 'tx_extension_domain_model_object',
]
];
This is how I implemented it. There was one more line (.i.e 'subclasses') that had to be added to Michael's response. (This is tested in Typo3 11.x as well)
My Configuration/Extbase/Persistence/Classes.php
<?php
declare(strict_types=1);
return [
\TYPO3\CMS\Extbase\Domain\Model\FrontendUser::class => [
'subclasses' => [
'\T3IN\T3inStores\Domain\Model\UserStore' => \T3IN\T3inStores\Domain\Model\UserStore::class,
]
],
\T3IN\T3inStores\Domain\Model\UserStore::class => [
'tableName' => 'fe_users',
'recordType' => 'Tx_T3inStores_UserStore',
],
];
Ref
For every superclass additional all subclasses have to be declared under subclasses
recordType : Look up the TCA of the model to get this value. Or lookup DB after creating a record of that type.
I've just finished building a nuxt.js & contentful website. There are several routes that need to be generated when people hit the website but it doesn't seem to generate all the routes or not recognise some pages unless I refresh. Example - I upload a blog post to contentful and it doesn't appear in the list of blog posts but when I change the text of a blog that is appearing with no issue, I have attached my config generate below
generate: {
routes () {
return Promise.all([
client.getEntries({
'content_type': 'product'
}),
client.getEntries({
'content_type': 'kebaProduct'
}),
client.getEntries({
'content_type': 'blogPost'
}),
])
.then(([productEntries, kebaEntries, blogEntries]) => {
return [
...blogEntries.items.map(entry => `/blog/${entry.fields.slug}`),
...productEntries.items.map(entry => `/products/${entry.fields.slug}`),
...kebaEntries.items.map(entry => `/products/ev-charging/${entry.fields.slug}`),
]
})
}
It works fine when I am on localhost and all the product routes are being generated and updated fine, only some of the 'kebaProduct' routes are being created when I run npm run generate. Not sure what I am missing
Note when I do generate although I have 5 'kebaProducts on contentful' it only generates one .html file not sure what the expected behaviour is.
Figured it out. If some content has been specified and it isn't present in the contentful code then the page will fail to be generated as it will throw an error. You can do checks with v-if for content and conditionally render it that way or make sure all fields are 'required' in the Contentful validations
I am working on Rest Api on YII. I integrated RESTFULL extention. In this some one used this below code. What is SINGLE in below onRest Event. Can anybody explain plz.
$this->onRest('req.get.single.render', function ($id, $user_id) {
$data="hi";
$this->emitRest('req.render.json', [
[
'type' => 'raw',
'data' => $data
]
]);
It's might be called when a GET request for a single resource is to be rendered. But, I never saw SINGLE in *Yii RESTFULL extension's event. You can reference in this or this
Hi I am currently working on a trash bin/recycling bin location application using google maps for rails.
I have a recyclingbin.rb model with the address as its attributes, that itself is enough to put markers on a map that can get displayed using the gem. I believe the gem converts the model and its attributes into json data.
I am trying to implement a feature where I can input my location and get direction to the nearest marker.
I have looked at the wiki , https://github.com/apneadiving/Google-Maps-for-Rails/wiki/Direction
Am I suppose to put this in the view ?
{ "data" => { "from" => "Paris, france", "to" => "Toulon, france" } }
})
%>
with the from to be embedded with my location for now? I understand I can pass options to this reference from google.
The wiki is quite short, can someone give me a quick explanation ?
The wiki does need some more work. I have a simple app working that shows the directions on the map from a location to another (pre-defined) location
<%= gmaps("map_options" => {"zoom" => 14}, "markers" => { "data" => #json },
"direction" => { "data" => {"from" => #location.address, "to" => "New York City"},"travelMode" => "DRIVING"}) %>
I just put this in my view. It shouldn't matter where, just as long as its there. Hope this helps
I'm building a sort-of clone of CoverItLive in Rails 3.1 and want to have the stream of comments automatically update. I'm using a partial in the view to display comments. There's a lot of info out there on doing UJS and AJAX wit forms or buttons or links in Rails, but I can't find any specific examples for what I need to do.
I'm assuming that .ajax() is the best approach, but I've never used it before and not sure if I need to provide .js.erb files when using this particular function? Could I just have the controller send JSON back to the client and go from there, or is there a better approach in rails?
This is what I'm thinking so far, based on what I read at another question:
setInterval(function() {
$.ajax({
type: 'GET',
url: ''<%= comments_path(:json) %>'',
data: {
data: "comments_data"
},
cache: false,
success: function(result) {
if (result == "true"){
alert("true");
}else{
alert("false");
}
}
});
}, 3000);
As an alternative you should look into Private Pub, a gem that Ryan Bates has put togeather. See a screencast about it on railscasts.
The trouble with your solution is now often you server will be hit unnecessarily, i guess it depends on the number of concurrent users you thing will be viewing this page.
if you do go down your route the .js.erb could just have a somthing like this in it:
$('#id_of_area_to_replace').html("<%= escape_javascript(render"comments/index") %>")
This would replace the whole area else you could just append new comments to the bottom of the area