prix-fixe

Expand History Expand History
Collapse History Collapse History

Add name="content" to <textarea>

This commit is in response to the previous error:

Error:
UserSharesAMessageTest#test_visiting_the_index:
ActionView::Template::Error: param is missing or the value is empty: content
    app/views/notes/create.html.erb:1

The params.fetch(:content) invocation fails because our <form> element’s submission does not transmit the value of its <textarea>.

The <textarea> element is declared with an id="content" attribute to instruct the browser to interprets the <label for="content"> element as its corresponding label. This attribute is a helpful declaration to make on the client-side, but does not signal any information to our server when the <form> is submitted.

This commit declares the <textarea> with a name="content" attribute to encode its value as part of the HTTP POST request the <form> submits.

Once this change is made, Rails interprets the HTTP request’s body to contain a value for content, which it makes available from params.

When we run the test again, it outputs a new message:


Capybara starting Puma...
* Version 3.12.1 , codename: Llamas in Pajamas
* Min threads: 0, max threads: 4
* Listening on tcp://127.0.0.1:53909
.

Finished in 4.229706s, 0.2364 runs/s, 0.2364 assertions/s.
1 runs, 1 assertions, 0 failures, 0 errors, 0 skips

In our first Test Driven Development cycle’s Red-Green-Refactor, we’ve progressed from the Red Phase (i.e. the test is failing) to the Green Phase (the test is passing).

The test passed! The application’s behavior meets the criteria the we’ve declared in our system test.

Before considering this feature’s work “finished”, there is one more TDD Phase: Refactoring.