Cucumber capybara fill_in failing - tdd

I've been building a rails4 app and running through testing with cucumber and capybara but have hit a snag. I'm doing standard testing for user creation and user edit.
The user create test ran through without any issue but upon running through the test for editing the user I can't get capybara to actually fill in the new values into the fields. The form is the same for new and edit (I am including the same _form partial to both) and again it works fine on new but not edit.
Cucumber New User test:
When I fill in a User with:
| First Name | Rufus |
| Last Name | Firefly |
| Email | rfirefly#fake.com |
| Role(S) | System Admin |
Cucumber Edit User test:
When I fill in a User with:
| First Name | Otis |
| Last Name | Driftwood |
| Email | otis#fake.com |
Corresponding method:
When /^(?:|I) fill in (?:a|an|the) (.+) with:$/ do |obj, fields|
attrs = {}
fields.rows_hash.each do |name, value|
fill_in(name, with: value) unless name =~ /\((?:R|S)\)$/
choose(value) if name =~ /\(R\)$/
select(value) if name =~ /\(S\)$/
end
end
Rendered html form:
<form accept-charset="UTF-8" action="/members/1" class="edit_user" id="edit_user_1" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓" /><input name="_method" type="hidden" value="put" /></div><div class='field'>
<label for="user_first_name">First Name</label>
<input id="user_first_name" name="user[first_name]" type="text" value="Ronald" />
</div>
<div class='field'>
<label for="user_last_name">Last Name</label>
<input id="user_last_name" name="user[last_name]" type="text" value="Kornblow" />
</div>
<div class='field'>
<label for="user_email">Email</label>
<input id="user_email" name="user[email]" type="email" value="kornblow#fake.com" />
</div>
<div class='field'>
<label for="user_password">Password</label>
<input id="user_password" name="user[password]" type="password" />
</div>
... omitted fields (not required) ...
<input name="commit" type="submit" value="Update User" />
</form>
Any help or insight anyone could give me I would greatly appreciate it.
Thanks in advance

In your code you have:
When /^(?:|I) fill in (?:a|an|the) (.+) with:$/ do |obj, fields|
attrs = {}
fields.rows_hash.each do |name, value|
fill_in(name, with: value) unless name =~ /\((?:R|S)\)$/
choose(value) if name =~ /\(R\)$/
select(value) if name =~ /\(S\)$/
end
end
here, the fill_in(name, :value) method normally automatically looks for the ID tag id=name, but here your names don't line up exactly as shown by your rendered HTML form.
<div class='field'>
<label for="user_last_name">Last Name</label>
<input id="user_last_name" name="user[last_name]" type="text" value="Kornblow" />
</div>
Try changing your cucumber test to:
When I fill in a User with:
| user_first_name | Otis |
| user_last_name | Driftwood |
| user_email | otis#fake.com |
Hope this helps

So I did find the issue and I'm not happy about the last hour and a half that I lost due to what I believe was the problem...
I was using a nice little debugging tool for capybara to render the page and show it in the browser and this was not displaying the updated fields like I said above, but when i ran click_button() these values were in fact being saved.
The issue I was really having was that Devise, in all its infinite wisdom, was saving the new email address to unconfirmed_email and keeping the old email until the user gets the email and confirms. Makes sense but it was the first time I apparently ran into this.
So in my test:
Given a "User" was updated with:
| Last Name | Driftwood |
| Email | otis#fake.com |
the email attribute really wasn't 'otis#fake.com' and the test, as it always is (no matter how much I argue with it) was right. This user was not updated in with that email. Changing this to:
Given a "User" was updated with:
| Last Name | Driftwood |
| Email | kornblow#fake.com |
| Unconfirmed Email | otis#fake.com |
Solved the problem. I'm still confused why I was not seeing the fill(ed)_in() values when I rendered the page out tho. Kinda led me barking up the wrong tree.
Oh well...
Thanks for your help and hope this helps others...

Related

blade variables inside a string that can be compiled in the view

In my database I have two tables, Pages and Articles.
In my Pages table I have the following:
+----+------------------+--------------+
| id | content | slug |
+----+------------------+--------------+
| 1 | {{$articleBody}} | /news/{slug} |
+----+------------------+--------------+
In my Articles table I have the following:
+----+----------------+--------------+
| id | content | slug |
+----+----------------+--------------+
| 1 | Blah blah balh | /news/1 |
+----+----------------+--------------+
I also have a standard blade file called wrapper.blade.php:
<body>{{$pageContent}}</body>
In my web.php file I do the following to return Page (ID:1) and Article:
return view("wrapper", ["Article"=> Article::find(1), "pageContent" => Page::find(1)->content]);
The idea is that I can change the Page content around Article in a CMS manner that includes.
I have tried:
return view("wrapper", ["articleBody"=> Article::find(1)->content, "pageContent" => Blade::compileString(Page::find(1)->content)]);
But I haven't had much luck.
When you use blade , first thing that it does, is to compile the file to something understandable by PHP. For example {{ => <?php or #if(...) #endif => <?php if(...){} ?>.
when you use {{first_name}} in your string the {{ and }} are not there in the file.blade.php when the blade is caching the views.
after the caching of blade files is done, the server run the php file and {{first_name}} will be placed in the file and treated as string.
something that you are looking for is str_replace().
lets say your string is $String = "Hello something_unique, how are you?"
then in your blade file use {{ str_replace("something_unique", $first_name, $String ); }}. I think it is what you are looking for.
you should use
$string = "Hello".$first_name.", how are you ? "

Angular 2 Template Form

I have a template-driven Login form and below/outside my form there is a button for "forgot password".
Whenever I click on the "forgot password" button, it first validates my form then at the next click, it navigates.
{{'userNameRequired' | translate}}
{{'userName should between 8-15 letters and contain alphabet, digits and special character like _ , -, . ' | translate}}
{{'passwordRequired' | translate}}
{{'Password must be of a Capital Letter, alphabets and special character like # and _' | translate}}
{{'login' | translate}}
<p style="text-align: center; ">
<a [routerLink]="/forgotpassword">Forgot Password</a>
</p>

Laravel blade template not rendering table properly

I'm quite new to Laravel, but have recently taken over a project from someone and trying to get the mail blade templates to render but I am having problems.
The code used for the enquiry email template is as follows:
#component('mail::message')
#New customer enquiry
We have received a new customer enquiry.
#component('mail::table')
| **Name** | **Email** | **Telephone** |
| ---------------------------------------------- |:---------------------:| -----------------------:|
| {{$enquiry->firstname}} {{$enquiry->lastname}} | <{{$enquiry->email}}> | {{$enquiry->telephone}} |
#endcomponent
Thanks,<br>
{{ config('app.name') }}
#endcomponent
But the table always renders as raw HTML, here is a screenshot of how the email looks in MailCatcher:
I've checked a couple of other posts that concern this kind of issue but usually it's due to the attempt to render more than one table in a mail template, but this is just a single table. Is there a component I have missed or is it just MailCatcher not rendering correctly?
When using Markdown to render emails, avoid using indents excessively. Your code should look like this
#component('mail::message')
#New customer enquiry
We have received a new customer enquiry.
#component('mail::table')
| **Name** | **Email** | **Telephone** |
| ---------------------------------------------- |:---------------------:| -----------------------:|
| {{$enquiry->firstname}} {{$enquiry->lastname}} | <{{$enquiry->email}}> | {{$enquiry->telephone}} |
#endcomponent
Thanks,<br>
{{ config('app.name') }}
#endcomponent
You didn't show how the html which is not being rendered is being loaded.
But it's possible you need to use {!! !!} instead of {{ }} for the variables that contain html.

Laravel 5.1 - Routes Error - NotFoundHttpException in RouteCollection.php line 143:

This error happen in my laravel 5.1 project, when trying to access http://localhost:8000/dashboard.user.update after I click Submit on my edit form.
NotFoundHttpException in RouteCollection.php line 143:
This error happen when I run update function in my controller. I have no error when runing other function like index or show.
This is my routes:
...
// Dashboard routes...
Route::resource('dashboard/user', 'UserController');
Route::resource('dashboard', 'DashboardController');
...
I already runs php artisan route:list to see if my routes are working:
+--------+----------+-----------------------+------------------------+---------------------------------------------+------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+----------+-----------------------+------------------------+---------------------------------------------+------------+
...
| | POST | dashboard/user | dashboard.user.store | App\Http\Controllers\UserController#store | auth |
| | GET|HEAD | dashboard/user | dashboard.user.index | App\Http\Controllers\UserController#index | auth |
| | GET|HEAD | dashboard/user/create | dashboard.user.create | App\Http\Controllers\UserController#create | auth |
| | DELETE | dashboard/user/{user} | dashboard.user.destroy | App\Http\Controllers\UserController#destroy | auth |
| | GET|HEAD | dashboard/user/{user} | dashboard.user.show | App\Http\Controllers\UserController#show | auth |
| | PUT | dashboard/user/{user} | dashboard.user.update | App\Http\Controllers\UserController#update | auth |
| | PATCH | dashboard/user/{user} | | App\Http\Controllers\UserController#update | auth |
...
Now I don't know what to do, can help?
Like your routes table says you need PUT or PATCH for an update call. Your route is correct but laravel checks the routes also for the method type.
I think you want to display a view and not return a json (RestAPI) if so than the implicit controllers are much better than resources!
http://laravel.com/docs/5.1/controllers#implicit-controllers
If you want to use them you have to rename your methods to getIndex(), getEdit(), postStore() and if you want post not put than postUpdate().
If it's an update, tell laravel it's a "PUT" request. Since simply POST method for that url with the user_id not exists.
<input name="_method" type="hidden" value="PUT">
Something like this:
<form method="POST" action="http://localhost:8000/dashboard/user/1">
<input name="_method" type="hidden" value="PUT">
//...

Wordpress image and link in header

I have a Wordpress child theme of TwentyTwelve with a header image and I would like to place another smaller image with a hyperlink centered in the header image.
---------------------------------------------------------------------
| 1 |
| ----- ----- |
| | 2 | | 3 | |
| ----- ----- |
| |
---------------------------------------------------------------------
From the diagram above, I have [1] being the link to the main site (standard from twentytwelve) and I would like to add [2] and [3] as images and hyperlinks. Any suggestions on how I would to this? I'm just starting to learn theming. Thanks in advance!
I've found a solution if anyone else is looking to do this. In my header.php, I added this just before </header>:
<div style="position:relative; visibility:show; left: 50%; top: -<?php echo get_custom_header()->height/2; ?>px; z-index:2; >
<img src="image" ><br>
</div>

Resources