Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ module.exports = function( grunt ) {
src: [ "assets/*.*" ],
dest: "dist/",
cwd: "src/"
},
data: {
expand: true,
src: [ "*.json" ],
dest: "dist/",
cwd: "src/"
}
},

Expand Down
35 changes: 19 additions & 16 deletions specs/beer-model.html
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Beer Model</title>
<link rel="stylesheet" href="qunit/qunit.css">
</head>
<body>

<div id="qunit"></div>
<div id="qunit-fixture"></div>
<head>
<meta charset="utf-8">
<title>Beer Model</title>
<link rel="stylesheet" href="qunit/qunit.css">
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>

<script src="qunit/qunit.js"></script>

<script src="../src/js/vendor/underscore/underscore.js"></script>
<script src="../src/js/models/beer.js"></script>

<script src="beer.model.spec.js"></script>
</body>
<script src="../src/js/vendor/jquery/dist/jquery.js"></script>
<script src="../src/js/vendor/underscore/underscore.js"></script>

<script src="qunit/jquery.mockjax.js"></script>
<script src="qunit/qunit.js"></script>

<script src="../src/js/models/beer.js"></script>

<script src="beer.model.spec.js"></script>
</body>
</html>
72 changes: 67 additions & 5 deletions specs/beer.model.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
(function(QUnit, global) {
"use strict";

QUnit.module("Creating Beers");

QUnit.test("Confirm model exists", function(assert) {
assert.ok(global.beerApp.Beer, "The Beer model exists on the beerApp object");
});
Expand All @@ -16,11 +18,6 @@
assert.equal(b.updated_at, b.created_at, "The Beer has an update timestamp that matches the create timestamp");
});

QUnit.test("Beer stringification works", function(assert) {
var b = new global.beerApp.Beer();
assert.equal(b.toString(), "Beer(?) by Unknown (abv ?%)", "Default string is correct");
});

QUnit.test("Passing options creates custom Beer", function(assert) {
var b = new global.beerApp.Beer({
name: "Shiner",
Expand All @@ -36,4 +33,69 @@
assert.equal(b.abv, 4.5, "The correct abv was used");
});


QUnit.module("Finding Beers", {
beforeEach: function() {
$.mockjax({
url: "/data.json",
dataType: "json",
response: function(req) {
var data = [
{ "name": "Foo", "brewery": "Bar", "description": "beer", "abv": 1 },
// We could, of course, fill out the rest of this data...
{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}];

this.status = 200;
this.responseText = data.slice(0, req.data.limit);

// Handle a "request" for an error...
if (req.data.query && req.data.query.foo === "bar") {
this.status = 500;
this.responseText = "Foo error!"
}
}
});
},
afterEach: function() {
$.mockjax.clear();
}
});

QUnit.test("Find with single cb arg", function(assert) {
var done = assert.async();

global.beerApp.Beer.find(function(results) {
assert.equal(results.length, 10, "Correct number of results by default");
// What else could/should we assert?
done();
});
});

QUnit.test("Limit search results", function(assert) {
var done = assert.async();

global.beerApp.Beer.find({}, 5, function(results) {
assert.equal(results.length, 5, "Correct number of results by default");
done();
});
});

QUnit.test("Check HTTP error handling", function(assert) {
var done = assert.async();

global.beerApp.Beer.find({ foo: "bar" }, 5, function(err) {
assert.ok(err instanceof Error, "An error object was received in the cb");
assert.equal(err.message, "Unable to process beer search!", "Error has correct message");
done();
});
});


QUnit.module("Beer helpers");

QUnit.test("Beer stringification works", function(assert) {
var b = new global.beerApp.Beer();
assert.equal(b.toString(), "Beer(?) by Unknown (abv ?%)", "Default string is correct");
});

})(window.QUnit, window);
Loading