Skip to content

Commit

Permalink
Change Posts schema to have title and body, reflect in controllers, v…
Browse files Browse the repository at this point in the history
…iews.

Searched for .name and name: in public/modules/posts and /app
  • Loading branch information
John Troxel committed Jul 11, 2014
1 parent 3d354bf commit 01016a3
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 20 deletions.
13 changes: 10 additions & 3 deletions app/models/post.server.model.js
Expand Up @@ -10,13 +10,20 @@ var mongoose = require('mongoose'),
* Post Schema
*/
var PostSchema = new Schema({
name: {
title: {
type: String,
default: '',
required: 'Please fill Post name',
required: 'Please fill Post title',
trim: true
},
created: {
// calling the body post_body because just body is a pretty common string
post_body: {
type: String,
default: '',
required: 'Please fill Post body',
trim: true
},
created: {
type: Date,
default: Date.now
},
Expand Down
5 changes: 3 additions & 2 deletions app/tests/post.server.model.test.js
Expand Up @@ -45,8 +45,9 @@ describe('Post Model Unit Tests:', function() {
});
});

it('should be able to show an error when try to save without name', function(done) {
post.name = '';
it('should be able to show an error when try to save without name', function(done) {
post.title = '';
post.text = '';

return post.save(function(err) {
should.exist(err);
Expand Down
6 changes: 4 additions & 2 deletions public/modules/posts/controllers/posts.client.controller.js
Expand Up @@ -9,7 +9,8 @@ angular.module('posts').controller('PostsController', ['$scope', '$stateParams',
$scope.create = function() {
// Create new Post object
var post = new Posts ({
name: this.name
title: this.title,
post_body: this.post_body
});

// Redirect after save
Expand All @@ -20,7 +21,8 @@ angular.module('posts').controller('PostsController', ['$scope', '$stateParams',
});

// Clear form fields
this.name = '';
this.title = '';
this.post_body = '';
};

// Remove existing Post
Expand Down
21 changes: 14 additions & 7 deletions public/modules/posts/tests/posts.client.controller.test.js
Expand Up @@ -53,7 +53,8 @@
it('$scope.find() should create an array with at least one Post object fetched from XHR', inject(function(Posts) {
// Create sample Post using the Posts service
var samplePost = new Posts({
name: 'New Post'
title: 'New Post',
post_body: 'This is the body, it is very insightful'
});

// Create a sample Posts array that includes the new Post
Expand All @@ -73,7 +74,8 @@
it('$scope.findOne() should create an array with one Post object fetched from XHR using a postId URL parameter', inject(function(Posts) {
// Define a sample Post object
var samplePost = new Posts({
name: 'New Post'
title: 'New Post',
post_body: 'This is the body, it is very insightful'
});

// Set the URL parameter
Expand All @@ -93,17 +95,20 @@
it('$scope.create() with valid form data should send a POST request with the form input values and then locate to new object URL', inject(function(Posts) {
// Create a sample Post object
var samplePostPostData = new Posts({
name: 'New Post'
title: 'New Post',
post_body: 'This is the body, it is very insightful'
});

// Create a sample Post response
var samplePostResponse = new Posts({
_id: '525cf20451979dea2c000001',
name: 'New Post'
title: 'New Post',
post_body: 'This is the body, it is very insightful'
});

// Fixture mock form input values
scope.name = 'New Post';
scope.title = 'New Post';
scope.post_body = 'This is the body, it is very insightful';

// Set POST response
$httpBackend.expectPOST('posts', samplePostPostData).respond(samplePostResponse);
Expand All @@ -113,7 +118,8 @@
$httpBackend.flush();

// Test form inputs are reset
expect(scope.name).toEqual('');
expect(scope.title).toEqual('');
expect(scope.post_body).toEqual('');

// Test URL redirection after the Post was created
expect($location.path()).toBe('/posts/' + samplePostResponse._id);
Expand All @@ -123,7 +129,8 @@
// Define a sample Post put data
var samplePostPutData = new Posts({
_id: '525cf20451979dea2c000001',
name: 'New Post'
title: 'New Post',
post_body: 'This is the body, it is very insightful'
});

// Mock Post in scope
Expand Down
8 changes: 6 additions & 2 deletions public/modules/posts/views/create-post.client.view.html
Expand Up @@ -6,9 +6,13 @@ <h1>New Post</h1>
<form class="form-horizontal" data-ng-submit="create()" novalidate>
<fieldset>
<div class="form-group">
<label class="control-label" for="name">Name</label>
<label class="control-label" for="title">Title</label>
<div class="controls">
<input type="text" data-ng-model="name" id="name" class="form-control" placeholder="Name" required>
<input type="text" data-ng-model="title" id="title" class="form-control" placeholder="Title" required>
</div>
<label class="control-label" for="post_body">Post</label>
<div class="controls">
<input type="text" data-ng-model="post_body" id="post_body" class="form-control" placeholder="Post text" required>
</div>
</div>
<div class="form-group">
Expand Down
8 changes: 6 additions & 2 deletions public/modules/posts/views/edit-post.client.view.html
Expand Up @@ -6,9 +6,13 @@ <h1>Edit Post</h1>
<form class="form-horizontal" data-ng-submit="update()" novalidate>
<fieldset>
<div class="form-group">
<label class="control-label" for="name">Name</label>
<label class="control-label" for="title">Title</label>
<div class="controls">
<input type="text" data-ng-model="post.name" id="name" class="form-control" placeholder="Name" required>
<input type="text" data-ng-model="post.title" id="title" class="form-control" placeholder="Title" required>
</div>
<label class="control-label" for="post_body">Post</label>
<div class="controls">
<input type="text" data-ng-model="post.post_body" id="post_body" class="form-control" placeholder="Post text" required>
</div>
</div>
<div class="form-group">
Expand Down
2 changes: 1 addition & 1 deletion public/modules/posts/views/list-posts.client.view.html
Expand Up @@ -10,7 +10,7 @@ <h1>Posts</h1>
by
<span data-ng-bind="post.user.displayName"></span>
</small>
<h4 class="list-group-item-heading" data-ng-bind="post.name"></h4>
<h4 class="list-group-item-heading" data-ng-bind="post.title"></h4>
</a>
</div>
<div class="alert alert-warning text-center" data-ng-hide="!posts.$resolved || posts.length">
Expand Down
6 changes: 5 additions & 1 deletion public/modules/posts/views/view-post.client.view.html
@@ -1,6 +1,6 @@
<section data-ng-controller="PostsController" data-ng-init="findOne()">
<div class="page-header">
<h1 data-ng-bind="post.name"></h1>
<h1 data-ng-bind="post.title"></h1>
</div>
<div class="pull-right" data-ng-show="authentication.user._id == post.user._id">
<a class="btn btn-primary" href="/#!/posts/{{post._id}}/edit">
Expand All @@ -10,6 +10,10 @@ <h1 data-ng-bind="post.name"></h1>
<i class="glyphicon glyphicon-trash"></i>
</a>
</div>
<div class="text-left">
<p data-ng-bind="post.post_body">
</p>
</div>
<small>
<em class="text-muted">
Posted on
Expand Down

0 comments on commit 01016a3

Please sign in to comment.