summaryrefslogtreecommitdiff
path: root/spec/movie_library_spec.rb
blob: 430158b6226e7a1efd395780afdf92ac1aa555b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
describe MovieLibrary do
  let(:library) { MovieLibrary.new }
  let(:shawshank_redemption) { create_movie(title: "The Shawshank Redemption", studio: Studio::CastleRock, year_published: 1994) }
  let(:chasing_amy) { create_movie(title: "Chasing Amy", studio: Studio::MiramaxFilms, year_published: 1997) }
  let(:man_on_fire) { create_movie(title: "Man on Fire", studio: Studio::RegencyEnterprises, year_published: 2004) }
  let(:toy_story) { create_movie(title: "Toy Story", studio: Studio::Pixar, year_published: 1995) }
  let(:up) { create_movie(title: "Up", studio: Studio::Pixar, year_published: 2006) }
  let(:cars) { create_movie(title: "Cars", studio: Studio::Pixar, year_published: 2009) }
  let(:monsters_inc) { create_movie(title: "Monsters Inc.", studio: Studio::Pixar, year_published: 2001) }
  let(:fantasia) { create_movie(title: "Fantasia", studio: Studio::Disney, year_published: 1940) }
  let(:dumbo) { create_movie(title: "Dumbo", studio: Studio::Disney, year_published: 1941) }
  let(:pinocchio) { create_movie(title: "Pinocchio", studio: Studio::Disney, year_published: 1940) }
  let(:all_movies) { [shawshank_redemption, chasing_amy, man_on_fire, toy_story, up, cars, monsters_inc, fantasia, dumbo, pinocchio] }

  def create_movie(details)
    Movie.new(details)
  end

  context "when adding a movie to the library" do
    xit "increases the total number of movies in the library" do
      library.add(shawshank_redemption)
      library.add(chasing_amy)
      expect(library.total_count).to eql(2)
    end

    xit "does not allow duplicate movies into the library" do
      library.add(man_on_fire)
      library.add(man_on_fire)
      expect(library.total_count).to eql( 1)
    end

    xit 'cannot add two movies that have the same title (logically the same)' do
      library.add(create_movie(:title => 'Old School'))
      library.add(create_movie(:title => 'Old School'))
      expect(library.total_count).to eql( 1)
    end
  end

  context 'Searching for movies' do
    before :each do
      all_movies.each { |x| library.add(x) }
    end

    xit 'Can find all pixar movies' do
      results = library.find_all_movies_by_pixar
      expect(results.count).to eql(4)
      expect(results).to include(toy_story)
      expect(results).to include(up)
      expect(results).to include(cars)
      expect(results).to include(monsters_inc)
    end

    xit 'Can find all movies published by pixar or disney' do
      results = library.find_all_movies_by_pixar_or_disney
      expect(results.count).to eql(7)
      expect(results).to include(toy_story)
      expect(results).to include(up)
      expect(results).to include(cars)
      expect(results).to include(monsters_inc)
      expect(results).to include(fantasia)
      expect(results).to include(dumbo)
      expect(results).to include(pinocchio)
    end

    xit 'Can find all movies not published by pixar' do
      results = library.find_all_movies_not_published_by_pixar
      expect(results.length).to eql(6)
      expect(results).to include(fantasia)
      expect(results).to include(dumbo)
      expect(results).to include(pinocchio)
      expect(results).to include(shawshank_redemption)
      expect(results).to include(chasing_amy)
      expect(results).to include(man_on_fire)
    end

    xit 'Can find all movies released after 2004' do
      results = library.find_all_movies_published_after_2004
      expect(results.length).to eql(2)
      expect(results).to include(up)
      expect(results).to include(cars)
    end

    xit 'Can find all movies released between 1982 and 2003 - Inclusive' do
      results = library.find_all_movies_between_1982_and_2003
      expect(results.length).to eql(4)
      expect(results).to include(shawshank_redemption)
      expect(results).to include(chasing_amy)
      expect(results).to include(toy_story)
      expect(results).to include(monsters_inc)
    end
  end

  context 'Sorting movies' do
    before :each do
      all_movies.each { |x| library.add(x) }
    end

    xit 'Sorts all movies by descending title' do
      expected_order = [ cars, chasing_amy, dumbo, fantasia, man_on_fire, monsters_inc, pinocchio, shawshank_redemption, toy_story, up]
      results = library.sort_movies_by_title_descending
      expect(results).to eql(expected_order)
    end

    xit 'Sorts all movies by ascending title' do
      expected_order = [up, toy_story, shawshank_redemption, pinocchio, monsters_inc, man_on_fire, fantasia, dumbo, chasing_amy, cars]
      results = library.sort_movies_by_title_ascending
      expect(results).to eql( expected_order)
    end

    xit 'Sorts all movies by descending release date' do
      expected_order = [cars, up, man_on_fire, monsters_inc, chasing_amy, toy_story, shawshank_redemption, dumbo, fantasia, pinocchio ]
      results = library.sort_movies_by_descending_release_date
      expect(results).to eql( expected_order )
    end

    xit 'Sorts all movies by ascending release date' do
      expected_order = [pinocchio, fantasia, dumbo, shawshank_redemption, toy_story, chasing_amy, monsters_inc, man_on_fire, up, cars]
      results = library.sort_movies_by_ascending_release_date
      expect(results).to eql( expected_order )
    end

    xit 'Sorts all movies by preferred studios and release date ascending' do
      #rankings: Pixar, Disney, CastleRock, MiramaxFilms, RegenceyEnterprises
      expected_order = [ toy_story, monsters_inc, up, cars, fantasia, pinocchio, dumbo, shawshank_redemption, chasing_amy, man_on_fire]
      results = library.sort_movies_by_preferred_studios_and_release_date_ascending
      expect(results).to eql( expected_order )
    end
  end

  context "equality" do
    xit "is not equal" do
      blah = create_movie(title: 'blah')
      huh = create_movie(title: 'huh')
      expect(blah).to eql( huh )
    end

    xit "is equal" do
      huh1 = create_movie(title: 'huh')
      huh2 = create_movie(title: 'huh')
      expect(huh1).to eql( huh2 )
    end
  end
end