Skip to content

Commit

Permalink
Send the fileHash with new learning materials
Browse files Browse the repository at this point in the history
  • Loading branch information
jrjohnson committed Dec 9, 2015
1 parent f06c278 commit 226e246
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
10 changes: 10 additions & 0 deletions app/serializers/learning-material.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
import Ember from 'ember';
import DS from 'ember-data';

const { get } = Ember;

export default DS.RESTSerializer.extend({
isNewSerializerAPI: true,
serialize: function(snapshot, options) {
var json = this._super(snapshot, options);

//When POSTing new file learningMaterials we need to include the file hash
const fileHash = get(snapshot.record, 'fileHash');
if (fileHash) {
json.fileHash = fileHash;
}

//don't persist this, it is handled by the server
delete json.absoluteFileUri;
delete json.uploadDate;
Expand Down
17 changes: 17 additions & 0 deletions tests/unit/serializers/learning-material-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,20 @@ test('it removes all non postable fields', function(assert) {
assert.ok(!("uploadDate" in serializedRecord));
assert.ok(!("absoluteFileUri" in serializedRecord));
});

test('no filehash usually', function(assert) {
var record = this.subject();

var serializedRecord = record.serialize();

assert.ok(!("fileHash" in serializedRecord));
});

test('filehash when it is added', function(assert) {
var record = this.subject();
record.set('fileHash', 'BigPhatBass');
var serializedRecord = record.serialize();

assert.ok(("fileHash" in serializedRecord));
assert.equal(serializedRecord.fileHash, 'BigPhatBass');
});

0 comments on commit 226e246

Please sign in to comment.