Permalink
Browse files

Send post form data to save action

We get the component test to pass by making the input an Ember input helper, retrieving the saved value in it, and sending that in an object to the `save` action closure.

Inner green; outer green

The unit and acceptance test both pass. We've successfully let our acceptance test drive out the behavior of this feature!

Interestingly, note that the tests didn't drive us to actually add attributes to our Post model. Apparently Ember will allow assigning arbitrary attributes to a model in-memory and will preserve them. But we know we need those attributes to be defined.

The TDD way to approach this problem is to find the test that will demonstrate the problem with the attributes not being defined. In this case, a test of the post retrieval page pulling up a post from the backend will show the problem.
  • Loading branch information...
CodingItWrong committed Jan 11, 2018
1 parent d82b075 commit 8f2020cbedb952b92adaad1583b78e69bdb4ac8b
Showing with 7 additions and 3 deletions.
  1. +5 −1 app/components/post-form.js
  2. +2 −2 app/templates/components/post-form.hbs
@@ -3,7 +3,11 @@ import Component from '@ember/component';
export default Component.extend({
actions: {
submitForm() {
this.submitHandler();
const postData = {
title: this.title,
body: this.body,
};
this.submitHandler(postData);
}
}
});
@@ -1,11 +1,11 @@
<form>
<div>
<label for="js-post-form-title">Title</label>
<input type="text" class="js-post-form-title">
{{input type="text" class="js-post-form-title" value=title}}
</div>
<div>
<label for="js-post-form-body">Body</label>
<textarea class="js-post-form-body" />
{{textarea class="js-post-form-body" value=body}}
</div>
<button type="button" class="js-post-form-save" onclick={{action "submitForm"}}>Save</button>

0 comments on commit 8f2020c

Please sign in to comment.