Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Working on certification lists inside the vendor

  • Loading branch information...
commit f77848fa06961a92bdd01e54d3061be8c3d51c33 1 parent d578d6c
@jc00ke authored
Showing with 29 additions and 13 deletions.
  1. +19 −12 test/vendors/vendors.js
  2. +10 −1 vendors.js
View
31 test/vendors/vendors.js
@@ -10,7 +10,7 @@ $(document).ready(function() {
certs: ["hvac", "green"]
});
ok(vendor, "created");
- equals("Bob's HVAC", vendor.get('name'), "name works");
+ equals(vendor.get('name'), "Bob's HVAC", "name works");
ok(_.include(vendor.get('certs'), 'hvac'), "hvac cert is included");
ok(!_.include(vendor.get('certs'), 'red'), "red cert is not included");
});
@@ -18,7 +18,7 @@ $(document).ready(function() {
module("Vendor Collection sanity check");
test("basic collection", function() {
- expect(1);
+ expect(3);
var list = new VendorList;
list.comparator = function(vendor) {
return vendor.get('name');
@@ -26,26 +26,33 @@ $(document).ready(function() {
list.add(new Vendor({name: "Cooke's", certs: ["auction", "real_estate"]}));
list.add(new Vendor({name: "Hoffman's", certs: ["perl", "real_estate"]}));
- equals(2, list.length, "length");
+ equals(list.length, 2, "length");
+ equals(list.at(0).get("name"), "Cooke's", "order should be set");
+ list.add(new Vendor({name: "Dave's", certs: ["ruby", "auction"]}));
+ equals(list.at(1).get("name"), "Dave's", "order should be set on added items");
});
test("collection from page", function() {
- var list = new VendorList;
- list.comparator = function(vendor) {
- return vendor.get('name');
- }
+ var vendorList = new VendorList;
+
$("#vendors li").each(function() {
var v = $(this);
- list.add(
+ var certList = _.map($('.solutions', v).html().split(','), function(solution) {
+ var name = $.trim(solution);
+ return new Cert({name: name});
+ });
+
+ vendorList.add(
new Vendor({
name: $('.name', v).text(),
- certs: _.map($('.solutions', v), function(solution) {
- return $(solution).html().replace(/\s|&\;\-/,'_').split(',');
- })
+ certs: certList
})
);
});
- equals(78, list.length);
+
+ equals(78, vendorList.length, "should be the known count of 78");
+ equals(vendorList.at(0).get('certs').map(function(c) { return c.get('name') } ), ["Energy Audit", "Solar Electric"], "first vendor's certs");
+ equals(vendorList.at(0).get('name'), "A Bright Idea Electrical", "check name of first model in collection");
});
});
View
11 vendors.js
@@ -3,5 +3,14 @@ var Vendor = Backbone.Model.extend({
});
var VendorList = Backbone.Collection.extend({
- model: Vendor
+ model: Vendor,
+ comparator: function(vendor) { return vendor.get('name') }
+});
+
+var Cert = Backbone.Model.extend({
+});
+
+var CertList = Backbone.Collection.extend({
+ model: Cert,
+ comparator: function(cert) { return cert.get('name'); },
});
Please sign in to comment.
Something went wrong with that request. Please try again.