Commit bd7341a

mo khan <mo@mokhan.ca>
2013-11-06 04:51:55
add movies to library.
1 parent 8e73b31
lib/movie.js
@@ -0,0 +1,11 @@
+// Generated by CoffeeScript 1.6.3
+var Movie;
+
+module.exports = Movie = (function() {
+  function Movie(attributes) {
+    this.title = attributes['title'];
+  }
+
+  return Movie;
+
+})();
lib/movie_library.js
@@ -0,0 +1,22 @@
+// Generated by CoffeeScript 1.6.3
+var MovieLibrary,
+  __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
+
+module.exports = MovieLibrary = (function() {
+  function MovieLibrary() {
+    this.movies = [];
+  }
+
+  MovieLibrary.prototype.add = function(movie) {
+    if (__indexOf.call(this.movies, movie) < 0) {
+      return this.movies.push(movie);
+    }
+  };
+
+  MovieLibrary.prototype.total_count = function() {
+    return this.movies.length;
+  };
+
+  return MovieLibrary;
+
+})();
lib/studio.js
@@ -0,0 +1,10 @@
+// Generated by CoffeeScript 1.6.3
+var Studio;
+
+module.exports = Studio = {
+  CastleRock: "",
+  MiramaxFilms: "",
+  RegencyEnterprises: "",
+  Pixar: "",
+  Disney: ""
+};
src/movie.coffee
@@ -0,0 +1,3 @@
+module.exports = class Movie
+  constructor: (attributes) ->
+    @title = attributes['title']
src/movie_library.coffee
@@ -0,0 +1,9 @@
+module.exports = class MovieLibrary
+  constructor: ->
+    @movies = []
+
+  add: (movie) ->
+    @movies.push(movie) unless movie in @movies
+
+  total_count: ->
+    @movies.length
src/studio.coffee
@@ -0,0 +1,7 @@
+module.exports = Studio =
+  CastleRock: ""
+  MiramaxFilms: ""
+  RegencyEnterprises: ""
+  Pixar: ""
+  Disney: ""
+
test/movie_library_spec.coffee
@@ -0,0 +1,36 @@
+should = require('chai').should
+MovieLibrary = require('../src/movie_library')
+Movie = require('../src/movie')
+Studio = require('../src/studio')
+
+describe "MovieLibrary", ->
+  beforeEach ->
+    @sut = new MovieLibrary
+    @shawshank_redemption = new Movie(title: "The Shawshank Redemption", studio: Studio.CastleRock, year_published: 1994)
+    @chasing_amy = new Movie(title: "Chasing Amy", studio: Studio.MiramaxFilms, year_published: 1997)
+    @man_on_fire = new Movie(title: "Man on Fire", studio: Studio.RegencyEnterprises, year_published: 2004)
+    @toy_story = new Movie(title: "Toy Story", studio: Studio.Pixar, year_published: 1995)
+    @up = new Movie(title: "Up", studio: Studio.Pixar, year_published: 2006)
+    @cars = new Movie(title: "Cars", studio: Studio.Pixar, year_published: 2009)
+    @monsters_inc = new Movie(title: "Monsters Inc.", studio: Studio.Pixar, year_published: 2001)
+    @fantasia = new Movie(title: "Fantasia", studio: Studio.Disney, year_published: 1940)
+    @dumbo = new Movie(title: "Dumbo", studio: Studio.Disney, year_published: 1941)
+    @pinocchio = new Movie(title: "Pinocchio", studio: Studio.Disney, year_published: 1940)
+    @all_movies = [@shawshank_redemption, @chasing_amy, @man_on_fire, @toy_story, @up, @cars, @monsters_inc, @fantasia, @dumbo, @pinocchio]
+
+  context "when adding a movie to the library", ->
+    it "increases the total number of movies in the library", ->
+      @sut.add(@shawshank_redemption)
+      @sut.add(@chasing_amy)
+      @sut.total_count().should.equal(2)
+
+    it "does not allow duplicate movies into the library", ->
+      @sut.add(@man_on_fire)
+      @sut.add(@man_on_fire)
+      @sut.total_count().should.equal(1)
+
+    xit "does not add two movies that have the same title (logically the same)", ->
+      @sut.add(new Movie(title: 'old school'))
+      @sut.add(new Movie(title: 'old school'))
+      @sut.total_count().should.equal(1)
+