Skip to content
Permalink
Browse files

Change Posts schema to have title and body, reflect in controllers, v…

…iews.

Searched for .name and name: in public/modules/posts and /app
  • Loading branch information...
John Troxel
John Troxel committed Jul 11, 2014
1 parent 3d354bf commit 01016a371e4bdc37dfd75ee97955fd1a8d722a8c
@@ -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
},
@@ -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);
@@ -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
@@ -20,7 +21,8 @@ angular.module('posts').controller('PostsController', ['$scope', '$stateParams',
});

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

// Remove existing Post
@@ -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
@@ -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
@@ -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);
@@ -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);
@@ -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
@@ -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">
@@ -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">
@@ -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">
@@ -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">
@@ -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

0 comments on commit 01016a3

Please sign in to comment.
You can’t perform that action at this time.