From c35757fcd39cbdbd19c5f18607a6b84bef33f624 Mon Sep 17 00:00:00 2001 From: sabine Date: Tue, 4 Sep 2018 16:11:03 -0700 Subject: [PATCH 01/19] Created movie class with attributes and created starring(actor_name) method --- lib/date_range.rb | 23 +++++++++++++++++++++++ lib/movie.rb | 23 +++++++++++++++++++++++ specs/date_range_spec.rb | 8 ++++---- specs/movie_spec.rb | 4 ++-- specs/spec_helper.rb | 3 +-- 5 files changed, 53 insertions(+), 8 deletions(-) diff --git a/lib/date_range.rb b/lib/date_range.rb index b6009b4..1228172 100644 --- a/lib/date_range.rb +++ b/lib/date_range.rb @@ -2,6 +2,29 @@ module GreenBox class DateRange + attr_reader :start_date , :end_date + def initialize(start_date, end_date) + @start_date = start_date + @end_date = end_date + # date_range = GreenBox::DateRange.new(Time.parse('2018-08-08'), + # Time.parse('2018-08-10')) + + if GreenBox::DateRange.new(Time.parse('2018-08-09'), + Time.parse('2018-08-08')) + raise ArgumentError.new "The end date is before the start date" + end + end + + def contains(date) + end + + def overlaps(other_date_range) + end + + def nights + end + + end end diff --git a/lib/movie.rb b/lib/movie.rb index f28fa85..4facff8 100644 --- a/lib/movie.rb +++ b/lib/movie.rb @@ -1,5 +1,28 @@ + +require 'csv' + module GreenBox class Movie + attr_reader :id, :title, :publisher, :actors + + def initialize(id,title,publisher,actors:[]) + @id = id + @title = title + @publisher = publisher + @actors = actors #--> this needs to contain values - array/hash + # actors = [] + end + movie = GreenBox::Movie.new(4,'Happiness','Fox',actors:['Denzel Washington', 'LL Cool J']) + + + def stars_actor(actor_name) + actors.each do |i| + if actor_name == i + return true + end + end + return false + end end end diff --git a/specs/date_range_spec.rb b/specs/date_range_spec.rb index 75153d4..e8d7341 100644 --- a/specs/date_range_spec.rb +++ b/specs/date_range_spec.rb @@ -2,7 +2,7 @@ require_relative 'spec_helper' -xdescribe 'GreenBox::DateRange' do +describe 'GreenBox::DateRange' do describe 'initialization' do it 'can be created' do @@ -19,7 +19,7 @@ end end - describe 'overlaps' do + xdescribe 'overlaps' do it "returns true if two DateRange objects overlap, one date's start date inside another" do date_1 = GreenBox::DateRange.new(Time.parse('2018-08-01'), @@ -52,7 +52,7 @@ end end - describe 'contains' do + xdescribe 'contains' do let (:date_range) do GreenBox::DateRange.new(Time.parse('2018-08-01'), Time.parse('2018-08-05')) @@ -69,7 +69,7 @@ end end - describe 'nights' do + xdescribe 'nights' do let (:date_range) do GreenBox::DateRange.new(Time.parse('2018-08-01'), Time.parse('2018-08-05')) diff --git a/specs/movie_spec.rb b/specs/movie_spec.rb index 679d630..c7a1f72 100644 --- a/specs/movie_spec.rb +++ b/specs/movie_spec.rb @@ -1,6 +1,6 @@ require_relative 'spec_helper' -xdescribe 'GreenBox::Movie' do +describe 'GreenBox::Movie' do let (:movie) { GreenBox::Movie.new(3, 'Green Lantern', 'Fox', actors: ['Ryan Reynolds', 'Blake Lively']) } @@ -34,7 +34,7 @@ end end - xdescribe 'stars_actor' do + describe 'stars_actor' do it 'returns true if the movie does feature the actor' do expect(movie.stars_actor('Ryan Reynolds')).must_equal true end diff --git a/specs/spec_helper.rb b/specs/spec_helper.rb index 906c711..4793ff7 100644 --- a/specs/spec_helper.rb +++ b/specs/spec_helper.rb @@ -1,4 +1,3 @@ -require 'time' require 'minitest' require 'minitest/autorun' require 'minitest/reporters' @@ -8,5 +7,5 @@ Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new -# Require_relative your lib files here! +require_relative '../lib/movie' require_relative '../lib/date_range' From 712ed68dc5259abcb60577ff43d3895b5e31da9d Mon Sep 17 00:00:00 2001 From: sabine Date: Tue, 4 Sep 2018 17:12:21 -0700 Subject: [PATCH 02/19] Started contain date_range method --- lib/date_range.rb | 15 ++++++++++----- specs/date_range_spec.rb | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/date_range.rb b/lib/date_range.rb index 1228172..92d3b0d 100644 --- a/lib/date_range.rb +++ b/lib/date_range.rb @@ -7,24 +7,29 @@ class DateRange def initialize(start_date, end_date) @start_date = start_date @end_date = end_date - # date_range = GreenBox::DateRange.new(Time.parse('2018-08-08'), - # Time.parse('2018-08-10')) - if GreenBox::DateRange.new(Time.parse('2018-08-09'), - Time.parse('2018-08-08')) + if start_date > end_date raise ArgumentError.new "The end date is before the start date" end end + def contains(date) + if ((date = start_date) || (date > start_date)) && (date < end_date) + return true + elsif + date < start_date || date = end_date + return false + end end + + def overlaps(other_date_range) end def nights end - end end diff --git a/specs/date_range_spec.rb b/specs/date_range_spec.rb index e8d7341..4d5bcee 100644 --- a/specs/date_range_spec.rb +++ b/specs/date_range_spec.rb @@ -52,7 +52,7 @@ end end - xdescribe 'contains' do + describe 'contains' do let (:date_range) do GreenBox::DateRange.new(Time.parse('2018-08-01'), Time.parse('2018-08-05')) From aadb210c72fbd4bf80c9c7c0c76ae938a7ee5ef0 Mon Sep 17 00:00:00 2001 From: sabine Date: Tue, 4 Sep 2018 20:15:16 -0700 Subject: [PATCH 03/19] Successfully passed all tests for contains method --- lib/date_range.rb | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/date_range.rb b/lib/date_range.rb index 92d3b0d..ecf8383 100644 --- a/lib/date_range.rb +++ b/lib/date_range.rb @@ -13,18 +13,15 @@ def initialize(start_date, end_date) end end - def contains(date) - if ((date = start_date) || (date > start_date)) && (date < end_date) + if (date >= start_date) && (date < end_date) return true - elsif - date < start_date || date = end_date + else + date < start_date && date >= end_date return false end end - - def overlaps(other_date_range) end From 519749ff409264dc6c5e2fb5f483c7eca2c93ea2 Mon Sep 17 00:00:00 2001 From: sabine Date: Wed, 5 Sep 2018 14:35:33 -0700 Subject: [PATCH 04/19] created and successfully passed method nights to tally number nights --- README.md | 4 ++-- lib/date_range.rb | 19 ++++++++++++++++++- lib/movie.rb | 2 +- specs/date_range_spec.rb | 2 +- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 7530093..f726dcf 100644 --- a/README.md +++ b/README.md @@ -89,7 +89,7 @@ A `Rental` will contain an `initialize` method and the following attributes: * movie: The movie being rented * customer: The name of the customer making the rental -A `Rental` will have the follwing methods: +A `Rental` will have the following methods: * `cost`: This method will return the cost of the rental. A movie rental will cost $3.0 per night. The customer is **not** charged for the day the movie is checked in. So a movie checked out on August 8th and checked in August 10th would cost $3.00 * 2 days = $6.00 @@ -114,4 +114,4 @@ The `RentalManager` will be able to perform the following actions (methods): ## Optional Enhancements You can add the following methods along with tests to further enhance this project: -- movies_staring(actor_name, date_range): This method will list all movies available in the given date range and with the provied actor. +- movies_staring(actor_name, date_range): This method will list all movies available in the given date range and with the provided actor. diff --git a/lib/date_range.rb b/lib/date_range.rb index ecf8383..b69f81a 100644 --- a/lib/date_range.rb +++ b/lib/date_range.rb @@ -22,11 +22,28 @@ def contains(date) end end + def overlaps(other_date_range) + (start_date <= other_date_rage.start_date) && (other_date_rage.end_date < end_date) end + + # current_date_range = (start_date...end_date) + # # if start_date....end_date) + # if (current_date_range).overlaps?(other_date_range) + # return true + # end + # end + # if (start_date...end_date.include? other_date_rage) + # return true + # else + # return false + # end + def nights - end + count = (end_date - start_date)/(60*60*24) + return count + end end end diff --git a/lib/movie.rb b/lib/movie.rb index 4facff8..0c41da9 100644 --- a/lib/movie.rb +++ b/lib/movie.rb @@ -25,4 +25,4 @@ def stars_actor(actor_name) end end -end +end diff --git a/specs/date_range_spec.rb b/specs/date_range_spec.rb index 4d5bcee..ec3a7f4 100644 --- a/specs/date_range_spec.rb +++ b/specs/date_range_spec.rb @@ -69,7 +69,7 @@ end end - xdescribe 'nights' do + describe 'nights' do let (:date_range) do GreenBox::DateRange.new(Time.parse('2018-08-01'), Time.parse('2018-08-05')) From f0626269304f34ca0b78060a88f2cbc5859a1a48 Mon Sep 17 00:00:00 2001 From: sabine Date: Thu, 6 Sep 2018 14:36:48 -0700 Subject: [PATCH 05/19] Completed overlaps methods and tests --- lib/date_range.rb | 28 +++++++++++++++++++--------- lib/rental.rb | 20 +++++++++++++++++++- specs/date_range_spec.rb | 8 ++++---- specs/movie_spec.rb | 2 +- 4 files changed, 43 insertions(+), 15 deletions(-) diff --git a/lib/date_range.rb b/lib/date_range.rb index b69f81a..3944d4e 100644 --- a/lib/date_range.rb +++ b/lib/date_range.rb @@ -17,22 +17,32 @@ def contains(date) if (date >= start_date) && (date < end_date) return true else - date < start_date && date >= end_date + date < start_date || date >= end_date return false end end def overlaps(other_date_range) - (start_date <= other_date_rage.start_date) && (other_date_rage.end_date < end_date) + if contains(other_date_range.start_date) || contains(other_date_range.end_date) + true + elsif other_date_range.contains(start_date) && other_date_range.contains(end_date) + true + else + false + end end - # current_date_range = (start_date...end_date) - # # if start_date....end_date) - # if (current_date_range).overlaps?(other_date_range) - # return true - # end + # if + # start_date < other_date_range.start_date && other_date_range.end_date < end_date + # false + # end + # current_date_range = (start_date...end_date) + # # if start_date....end_date) + # if (current_date_range).overlaps?(other_date_range) + # return true + # end # end # if (start_date...end_date.include? other_date_rage) # return true @@ -42,8 +52,8 @@ def overlaps(other_date_range) def nights count = (end_date - start_date)/(60*60*24) - return count - end + return count + end end end diff --git a/lib/rental.rb b/lib/rental.rb index 432dbc9..1390d12 100644 --- a/lib/rental.rb +++ b/lib/rental.rb @@ -1,6 +1,24 @@ +require_relative 'date_range' + module GreenBox - class Rental + class Rental < DateRange + attr_reader :date_range, :movie, :customer + def initialize(date_range, movie, customer) + @date_range = date_range + @movie = movies + @customer = customer + end end + + + + def cost + count = (end_date - start_date)/(60*60*24) + cost = count * 3 + return "The cost of renting a movie for #{count} days is $ #{cost}" + end + + end diff --git a/specs/date_range_spec.rb b/specs/date_range_spec.rb index ec3a7f4..98debd3 100644 --- a/specs/date_range_spec.rb +++ b/specs/date_range_spec.rb @@ -4,7 +4,7 @@ describe 'GreenBox::DateRange' do - describe 'initialization' do + xdescribe 'initialization' do it 'can be created' do date_range = GreenBox::DateRange.new(Time.parse('2018-08-08'), Time.parse('2018-08-09')) @@ -19,7 +19,7 @@ end end - xdescribe 'overlaps' do + describe 'overlaps' do it "returns true if two DateRange objects overlap, one date's start date inside another" do date_1 = GreenBox::DateRange.new(Time.parse('2018-08-01'), @@ -52,7 +52,7 @@ end end - describe 'contains' do + xdescribe 'contains' do let (:date_range) do GreenBox::DateRange.new(Time.parse('2018-08-01'), Time.parse('2018-08-05')) @@ -69,7 +69,7 @@ end end - describe 'nights' do + xdescribe 'nights' do let (:date_range) do GreenBox::DateRange.new(Time.parse('2018-08-01'), Time.parse('2018-08-05')) diff --git a/specs/movie_spec.rb b/specs/movie_spec.rb index c7a1f72..bfb7da9 100644 --- a/specs/movie_spec.rb +++ b/specs/movie_spec.rb @@ -1,6 +1,6 @@ require_relative 'spec_helper' -describe 'GreenBox::Movie' do +xdescribe 'GreenBox::Movie' do let (:movie) { GreenBox::Movie.new(3, 'Green Lantern', 'Fox', actors: ['Ryan Reynolds', 'Blake Lively']) } From 651442d0c615ae09caffc7e34451694e6f0c0176 Mon Sep 17 00:00:00 2001 From: sabine Date: Thu, 6 Sep 2018 16:24:06 -0700 Subject: [PATCH 06/19] Trying to refactor an adjust my rental initialize methods --- lib/date_range.rb | 17 +---------------- lib/movie.rb | 6 +++--- lib/rental.rb | 29 ++++++++++++++++++----------- specs/movie_spec.rb | 2 +- specs/rental_spec.rb | 4 ++-- 5 files changed, 25 insertions(+), 33 deletions(-) diff --git a/lib/date_range.rb b/lib/date_range.rb index 3944d4e..38ce49b 100644 --- a/lib/date_range.rb +++ b/lib/date_range.rb @@ -1,5 +1,6 @@ require 'time' + module GreenBox class DateRange attr_reader :start_date , :end_date @@ -34,22 +35,6 @@ def overlaps(other_date_range) end - # if - # start_date < other_date_range.start_date && other_date_range.end_date < end_date - # false - # end - # current_date_range = (start_date...end_date) - # # if start_date....end_date) - # if (current_date_range).overlaps?(other_date_range) - # return true - # end - # end - # if (start_date...end_date.include? other_date_rage) - # return true - # else - # return false - # end - def nights count = (end_date - start_date)/(60*60*24) return count diff --git a/lib/movie.rb b/lib/movie.rb index 0c41da9..ee9d1d1 100644 --- a/lib/movie.rb +++ b/lib/movie.rb @@ -9,9 +9,9 @@ def initialize(id,title,publisher,actors:[]) @id = id @title = title @publisher = publisher - @actors = actors #--> this needs to contain values - array/hash - # actors = [] + @actors = actors end + movie = GreenBox::Movie.new(4,'Happiness','Fox',actors:['Denzel Washington', 'LL Cool J']) @@ -25,4 +25,4 @@ def stars_actor(actor_name) end end -end +end diff --git a/lib/rental.rb b/lib/rental.rb index 1390d12..ab78ba5 100644 --- a/lib/rental.rb +++ b/lib/rental.rb @@ -1,24 +1,31 @@ require_relative 'date_range' +require 'time' +require_relative 'movie' module GreenBox - class Rental < DateRange - attr_reader :date_range, :movie, :customer + class Rental + attr_reader :movie,:date_range,:customer - def initialize(date_range, movie, customer) + def initialize(movie, date_range, customer) + @movie = movie @date_range = date_range - @movie = movies @customer = customer - end - end + if + date_range = GreenBox::DateRange.new(start_date = end_date)) + raise ArgumentError.new "The date range is illegal" + end + end + rental = GreenBox::Rental.new(movie, date_range, 'Ada Lovelace') - def cost - count = (end_date - start_date)/(60*60*24) - cost = count * 3 - return "The cost of renting a movie for #{count} days is $ #{cost}" - end + def cost + count = (end_date - start_date)/(60*60*24) + cost = count * 3 + return "The cost of renting a movie for #{count} days is $ #{cost}" + end + end end diff --git a/specs/movie_spec.rb b/specs/movie_spec.rb index bfb7da9..c7a1f72 100644 --- a/specs/movie_spec.rb +++ b/specs/movie_spec.rb @@ -1,6 +1,6 @@ require_relative 'spec_helper' -xdescribe 'GreenBox::Movie' do +describe 'GreenBox::Movie' do let (:movie) { GreenBox::Movie.new(3, 'Green Lantern', 'Fox', actors: ['Ryan Reynolds', 'Blake Lively']) } diff --git a/specs/rental_spec.rb b/specs/rental_spec.rb index ab67eb2..cb6c5b8 100644 --- a/specs/rental_spec.rb +++ b/specs/rental_spec.rb @@ -1,7 +1,7 @@ require 'time' require_relative 'spec_helper' -xdescribe 'GreenBox::Rental' do +describe 'GreenBox::Rental' do let (:date_range) do GreenBox::DateRange.new(Time.parse('2018-08-09'), Time.parse('2018-08-11')) end @@ -23,7 +23,7 @@ end end - describe 'cost' do + xdescribe 'cost' do it 'calculates the cost for a rental' do rental = GreenBox::Rental.new(movie, date_range, 'Ada Lovelace') From bf943a91d9bb000f13664ec5785a374f8b8e8193 Mon Sep 17 00:00:00 2001 From: sabine Date: Thu, 6 Sep 2018 21:29:12 -0700 Subject: [PATCH 07/19] Trying to update my methods for Rental so the test can pass --- lib/date_range.rb | 1 + lib/movie.rb | 4 +++- lib/rental.rb | 25 +++++++++++++++++-------- specs/rental_spec.rb | 2 +- specs/spec_helper.rb | 2 ++ 5 files changed, 24 insertions(+), 10 deletions(-) diff --git a/lib/date_range.rb b/lib/date_range.rb index 38ce49b..c547668 100644 --- a/lib/date_range.rb +++ b/lib/date_range.rb @@ -9,6 +9,7 @@ def initialize(start_date, end_date) @start_date = start_date @end_date = end_date + if start_date > end_date raise ArgumentError.new "The end date is before the start date" end diff --git a/lib/movie.rb b/lib/movie.rb index ee9d1d1..1c32970 100644 --- a/lib/movie.rb +++ b/lib/movie.rb @@ -12,7 +12,7 @@ def initialize(id,title,publisher,actors:[]) @actors = actors end - movie = GreenBox::Movie.new(4,'Happiness','Fox',actors:['Denzel Washington', 'LL Cool J']) + # movie = GreenBox::Movie.new(4,'Happiness','Fox',actors:['Denzel Washington', 'LL Cool J']) def stars_actor(actor_name) @@ -26,3 +26,5 @@ def stars_actor(actor_name) end end + +movie = GreenBox::Movie.new(4,'Happiness','Fox',actors:['Denzel Washington', 'LL Cool J']) diff --git a/lib/rental.rb b/lib/rental.rb index ab78ba5..74f22d4 100644 --- a/lib/rental.rb +++ b/lib/rental.rb @@ -4,21 +4,28 @@ module GreenBox class Rental - attr_reader :movie,:date_range,:customer + # attr_reader :movie, :start_date, :end_date, :customer + attr_writer :movie, :date_range , :customer - def initialize(movie, date_range, customer) + # def initialize(movie, start_date, end_date, customer) + def initialize(movie, date_range = end_date - start_date, customer) @movie = movie - @date_range = date_range + # @start_date = Time.parse(start_date) + # @end_date = Time.parse(end_date) + @date_range = Time.parse.date_range @customer = customer - if - date_range = GreenBox::DateRange.new(start_date = end_date)) - raise ArgumentError.new "The date range is illegal" + + # For future I would say make an instance of a date_range class and call a + # date_range = + if date_range = ('2018-08-09' - '2018-08-09') + raise ArgumentError.new "This is an illegal date range" end - end - rental = GreenBox::Rental.new(movie, date_range, 'Ada Lovelace') + end + # rental = GreenBox::Rental + rental = GreenBox::Rental.new("Princess Bride", 3, "Abi") def cost count = (end_date - start_date)/(60*60*24) @@ -29,3 +36,5 @@ def cost end end + +# rental = GreenBox::Rental.new("Princess Bride", '3', "Abi") diff --git a/specs/rental_spec.rb b/specs/rental_spec.rb index cb6c5b8..ba9771e 100644 --- a/specs/rental_spec.rb +++ b/specs/rental_spec.rb @@ -1,7 +1,7 @@ require 'time' require_relative 'spec_helper' -describe 'GreenBox::Rental' do +xdescribe 'GreenBox::Rental' do let (:date_range) do GreenBox::DateRange.new(Time.parse('2018-08-09'), Time.parse('2018-08-11')) end diff --git a/specs/spec_helper.rb b/specs/spec_helper.rb index 4793ff7..6bfba7d 100644 --- a/specs/spec_helper.rb +++ b/specs/spec_helper.rb @@ -7,5 +7,7 @@ Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new +require_relative '../lib/rental' require_relative '../lib/movie' require_relative '../lib/date_range' +# require_relative '../lib/movie_reserver' From 06db9297c432362eb1c92a5f932720042fd3b450 Mon Sep 17 00:00:00 2001 From: sabine Date: Thu, 6 Sep 2018 23:23:08 -0700 Subject: [PATCH 08/19] Wave 2 Rental initialization and cost methods completed --- lib/date_range.rb | 15 +++++---------- lib/rental.rb | 40 ++++++++++++++-------------------------- specs/date_range_spec.rb | 2 +- specs/rental_spec.rb | 4 ++-- 4 files changed, 22 insertions(+), 39 deletions(-) diff --git a/lib/date_range.rb b/lib/date_range.rb index c547668..a5a7575 100644 --- a/lib/date_range.rb +++ b/lib/date_range.rb @@ -1,45 +1,40 @@ require 'time' - module GreenBox class DateRange - attr_reader :start_date , :end_date + attr_reader :start_date , :end_date, :nights def initialize(start_date, end_date) @start_date = start_date @end_date = end_date - if start_date > end_date raise ArgumentError.new "The end date is before the start date" end end def contains(date) - if (date >= start_date) && (date < end_date) + if (date >= @start_date) && (date < @end_date) return true else - date < start_date || date >= end_date + date < @start_date || date >= @end_date return false end end - def overlaps(other_date_range) if contains(other_date_range.start_date) || contains(other_date_range.end_date) true - elsif other_date_range.contains(start_date) && other_date_range.contains(end_date) + elsif other_date_range.contains(@start_date) && other_date_range.contains(@end_date) true else false end end - def nights - count = (end_date - start_date)/(60*60*24) + count = (@end_date - @start_date)/(60*60*24) return count end - end end diff --git a/lib/rental.rb b/lib/rental.rb index 74f22d4..fcddbe7 100644 --- a/lib/rental.rb +++ b/lib/rental.rb @@ -4,37 +4,25 @@ module GreenBox class Rental - # attr_reader :movie, :start_date, :end_date, :customer - attr_writer :movie, :date_range , :customer + attr_accessor :movie, :date_range, :customer - - # def initialize(movie, start_date, end_date, customer) - def initialize(movie, date_range = end_date - start_date, customer) - @movie = movie - # @start_date = Time.parse(start_date) - # @end_date = Time.parse(end_date) - @date_range = Time.parse.date_range - @customer = customer - - - # For future I would say make an instance of a date_range class and call a - # date_range = - if date_range = ('2018-08-09' - '2018-08-09') + def initialize(movie, date_range, customer) + if date_range.nights <= 0 raise ArgumentError.new "This is an illegal date range" end - + @movie = movie + @date_range = date_range + @customer = customer end - # rental = GreenBox::Rental - rental = GreenBox::Rental.new("Princess Bride", 3, "Abi") def cost - count = (end_date - start_date)/(60*60*24) - cost = count * 3 - return "The cost of renting a movie for #{count} days is $ #{cost}" + # date_range.nights returns an integer of total nights + # need to subtract one night (day) to calculate correct cost + rent = @date_range.nights + # cost is number of days multipled by three dollars (per day) + cost = rent * 3.0 + # rounding should return the correct cents. + return cost.round(2) end - - end -end - -# rental = GreenBox::Rental.new("Princess Bride", '3', "Abi") +end \ No newline at end of file diff --git a/specs/date_range_spec.rb b/specs/date_range_spec.rb index 98debd3..d2734eb 100644 --- a/specs/date_range_spec.rb +++ b/specs/date_range_spec.rb @@ -69,7 +69,7 @@ end end - xdescribe 'nights' do + describe 'nights' do let (:date_range) do GreenBox::DateRange.new(Time.parse('2018-08-01'), Time.parse('2018-08-05')) diff --git a/specs/rental_spec.rb b/specs/rental_spec.rb index ba9771e..caf72c8 100644 --- a/specs/rental_spec.rb +++ b/specs/rental_spec.rb @@ -1,7 +1,7 @@ require 'time' require_relative 'spec_helper' -xdescribe 'GreenBox::Rental' do +describe 'GreenBox::Rental' do let (:date_range) do GreenBox::DateRange.new(Time.parse('2018-08-09'), Time.parse('2018-08-11')) end @@ -23,7 +23,7 @@ end end - xdescribe 'cost' do + describe 'cost' do it 'calculates the cost for a rental' do rental = GreenBox::Rental.new(movie, date_range, 'Ada Lovelace') From d6d83ef01f74115273b5b3cceba2aab8d274c1b8 Mon Sep 17 00:00:00 2001 From: sabine Date: Fri, 7 Sep 2018 13:06:16 -0700 Subject: [PATCH 09/19] Created a self.load_movies method, still need to instantiate --- lib/date_range.rb | 1 + lib/movie.rb | 13 +++---------- lib/movie_reserver.rb | 37 ++++++++++++++++++++++++++++++++++++ lib/rental.rb | 10 +++------- specs/date_range_spec.rb | 4 ++-- specs/movie_reserver_spec.rb | 20 +++++++++---------- specs/spec_helper.rb | 2 +- 7 files changed, 57 insertions(+), 30 deletions(-) diff --git a/lib/date_range.rb b/lib/date_range.rb index a5a7575..bd7b325 100644 --- a/lib/date_range.rb +++ b/lib/date_range.rb @@ -1,4 +1,5 @@ require 'time' +require_relative 'movie_reserver' module GreenBox class DateRange diff --git a/lib/movie.rb b/lib/movie.rb index 1c32970..65be0dc 100644 --- a/lib/movie.rb +++ b/lib/movie.rb @@ -1,30 +1,23 @@ - require 'csv' module GreenBox class Movie attr_reader :id, :title, :publisher, :actors - def initialize(id,title,publisher,actors:[]) + def initialize(id,title,publisher, actors:[]) @id = id @title = title @publisher = publisher @actors = actors end - # movie = GreenBox::Movie.new(4,'Happiness','Fox',actors:['Denzel Washington', 'LL Cool J']) - - def stars_actor(actor_name) - actors.each do |i| - if actor_name == i + actors.each do |actor| + if actor_name == actor return true end end return false end - end end - -movie = GreenBox::Movie.new(4,'Happiness','Fox',actors:['Denzel Washington', 'LL Cool J']) diff --git a/lib/movie_reserver.rb b/lib/movie_reserver.rb index a151bc5..6adcb93 100644 --- a/lib/movie_reserver.rb +++ b/lib/movie_reserver.rb @@ -1,7 +1,44 @@ require 'csv' +require_relative 'date_range' +require_relative 'movie' +require_relative 'rental' + module GreenBox class MovieReserver + attr_reader :movies,:rentals + + def initialize(movies,rentals) + @movies = load_movies + @rentals = rentals + end + + # reservation = GreenBox::MovieReserver.new(movies,rentals) + + def self.load_movies + showtime_movies = [] + + CSV.read('data/movies.csv', headers: false).each do |line| + movie_id = line[0].to_i + title = line[1] + publisher = line[2] + all_actors = line[3] + actors_names = all_actors.split(':') + actors = {actors: actors_names} + + showtime_movies << GreenBox::Movie.new(movie_id,title,publisher,actors) + end + + return showtime_movies + end + + + + def available_movies(date_range) + end + + def rent_movie(movie_title, date_range, customer_name) + end end end diff --git a/lib/rental.rb b/lib/rental.rb index fcddbe7..2132cd9 100644 --- a/lib/rental.rb +++ b/lib/rental.rb @@ -16,13 +16,9 @@ def initialize(movie, date_range, customer) end def cost - # date_range.nights returns an integer of total nights - # need to subtract one night (day) to calculate correct cost rent = @date_range.nights - # cost is number of days multipled by three dollars (per day) - cost = rent * 3.0 - # rounding should return the correct cents. - return cost.round(2) + cost = rent * 3.0 + return cost.round(2) end end -end \ No newline at end of file +end diff --git a/specs/date_range_spec.rb b/specs/date_range_spec.rb index d2734eb..335ed33 100644 --- a/specs/date_range_spec.rb +++ b/specs/date_range_spec.rb @@ -4,7 +4,7 @@ describe 'GreenBox::DateRange' do - xdescribe 'initialization' do + describe 'initialization' do it 'can be created' do date_range = GreenBox::DateRange.new(Time.parse('2018-08-08'), Time.parse('2018-08-09')) @@ -52,7 +52,7 @@ end end - xdescribe 'contains' do + describe 'contains' do let (:date_range) do GreenBox::DateRange.new(Time.parse('2018-08-01'), Time.parse('2018-08-05')) diff --git a/specs/movie_reserver_spec.rb b/specs/movie_reserver_spec.rb index bd6282c..51e07f0 100644 --- a/specs/movie_reserver_spec.rb +++ b/specs/movie_reserver_spec.rb @@ -2,17 +2,17 @@ MOVIES_IN_CSV = 11 -xdescribe 'GreenBox::MovieReserver' do +describe 'GreenBox::MovieReserver' do let (:reserver) { GreenBox::MovieReserver.new } let (:date_range) { GreenBox::DateRange.new(Time.parse('2018-08-08'), Time.parse('2018-08-09')) } describe 'initialization' do - xit 'can be instantiated' do + it 'can be instantiated' do expect(reserver).must_be_instance_of GreenBox::MovieReserver end - xit 'has the proper number of movies' do + it 'has the proper number of movies' do expect(reserver.movies.length).must_equal MOVIES_IN_CSV end end @@ -20,11 +20,11 @@ describe 'load_movies' do let (:movie_list) { GreenBox::MovieReserver.load_movies } - xit 'loads the right number of movies' do + it 'loads the right number of movies' do expect(movie_list.length).must_equal MOVIES_IN_CSV end - xit 'loads the 1st movie' do + it 'loads the 1st movie' do first_movie = movie_list.first expect(first_movie.title).must_equal 'Green Lantern' @@ -32,7 +32,7 @@ expect(first_movie.publisher).must_equal 'Fox' end - xit 'loads the last movie' do + it 'loads the last movie' do last_movie = movie_list.last expect(last_movie.title).must_equal 'Crazy Rich Asians' @@ -40,7 +40,7 @@ expect(last_movie.publisher).must_equal 'Warner Bros' end - xit 'loads the right actors' do + it 'loads the right actors' do first_movie = movie_list.first expect(first_movie.actors).must_include 'Blake Lively' @@ -51,15 +51,15 @@ end end - describe 'movies available' do + xdescribe 'movies available' do - xit 'will list the available movies' do + it 'will list the available movies' do available_movies = reserver.available_movies(date_range) expect(available_movies.length).must_equal 11 end - xit 'will not include rented movies' do + it 'will not include rented movies' do date_range = GreenBox::DateRange.new(Time.parse('2018-08-08'), Time.parse('2018-08-09')) reserver.rent_movie('Crazy Rich Asians', date_range, 'Ada Lovelace') diff --git a/specs/spec_helper.rb b/specs/spec_helper.rb index 6bfba7d..9f185d7 100644 --- a/specs/spec_helper.rb +++ b/specs/spec_helper.rb @@ -10,4 +10,4 @@ require_relative '../lib/rental' require_relative '../lib/movie' require_relative '../lib/date_range' -# require_relative '../lib/movie_reserver' +require_relative '../lib/movie_reserver' From e4528e113f643269089e5c120bfba7192af2987c Mon Sep 17 00:00:00 2001 From: sabine Date: Fri, 7 Sep 2018 13:14:03 -0700 Subject: [PATCH 10/19] Add coverage directory to .gitignore file --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 5e1422c..c0ac3dc 100644 --- a/.gitignore +++ b/.gitignore @@ -48,3 +48,4 @@ build-iPhoneSimulator/ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this: .rvmrc +coverage From 8bb4291f621e704fd055df13ce4ade0e799fd1ab Mon Sep 17 00:00:00 2001 From: sabine Date: Fri, 7 Sep 2018 13:15:47 -0700 Subject: [PATCH 11/19] added Simplecov in spec files --- specs/spec_helper.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/specs/spec_helper.rb b/specs/spec_helper.rb index 9f185d7..a657471 100644 --- a/specs/spec_helper.rb +++ b/specs/spec_helper.rb @@ -3,7 +3,8 @@ require 'minitest/reporters' require 'minitest/skip_dsl' require 'awesome_print' -# Add simplecov +require 'simplecov' +Simplecov.start Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new From 2a143a8673a1ea2fdf55d42244b17e0e4c076978 Mon Sep 17 00:00:00 2001 From: sabine Date: Fri, 7 Sep 2018 14:53:59 -0700 Subject: [PATCH 12/19] finalized self.load_movies and passed all instantialization tests --- lib/movie.rb | 3 +++ lib/movie_reserver.rb | 16 ++++++++-------- specs/spec_helper.rb | 2 +- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/movie.rb b/lib/movie.rb index 65be0dc..ffc130b 100644 --- a/lib/movie.rb +++ b/lib/movie.rb @@ -11,6 +11,9 @@ def initialize(id,title,publisher, actors:[]) @actors = actors end + movie = GreenBox::Movie.new(4,'Happiness','Fox',actors:['Denzel Washington', 'LL Cool J']) + + def stars_actor(actor_name) actors.each do |actor| if actor_name == actor diff --git a/lib/movie_reserver.rb b/lib/movie_reserver.rb index 6adcb93..9f57cd2 100644 --- a/lib/movie_reserver.rb +++ b/lib/movie_reserver.rb @@ -6,15 +6,15 @@ module GreenBox class MovieReserver - attr_reader :movies,:rentals + attr_accessor :movies,:rentals - def initialize(movies,rentals) - @movies = load_movies - @rentals = rentals + def initialize + @movies = MovieReserver.load_movies + @rentals = [] + # @reserver = reserver + # @date_range = date_range end - # reservation = GreenBox::MovieReserver.new(movies,rentals) - def self.load_movies showtime_movies = [] @@ -32,8 +32,6 @@ def self.load_movies return showtime_movies end - - def available_movies(date_range) end @@ -41,4 +39,6 @@ def rent_movie(movie_title, date_range, customer_name) end end + # reserver = GreenBox::MovieReserver.new + # date_range = GreenBox::DateRange.new(Time.parse('2018-08-08'), Time.parse('2018-08-09') end diff --git a/specs/spec_helper.rb b/specs/spec_helper.rb index a657471..03f66f8 100644 --- a/specs/spec_helper.rb +++ b/specs/spec_helper.rb @@ -4,7 +4,7 @@ require 'minitest/skip_dsl' require 'awesome_print' require 'simplecov' -Simplecov.start +SimpleCov.start Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new From f58479ff80f60fe4caf77e29e005d608be387478 Mon Sep 17 00:00:00 2001 From: sabine Date: Sat, 8 Sep 2018 18:41:20 -0700 Subject: [PATCH 13/19] Working through available movies method --- lib/movie_reserver.rb | 34 +++++++++++++++++++++++++++++++--- specs/movie_reserver_spec.rb | 2 +- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/lib/movie_reserver.rb b/lib/movie_reserver.rb index 9f57cd2..34a6a9f 100644 --- a/lib/movie_reserver.rb +++ b/lib/movie_reserver.rb @@ -6,13 +6,13 @@ module GreenBox class MovieReserver - attr_accessor :movies,:rentals + attr_accessor :movies,:rentals,:reserver, :date_range def initialize @movies = MovieReserver.load_movies @rentals = [] - # @reserver = reserver - # @date_range = date_range + @reserver = reserver + @date_range = date_range end def self.load_movies @@ -30,11 +30,39 @@ def self.load_movies end return showtime_movies + end + + + # `available_movies(date_range)`: This method will take a `DateRange` instance and return a list of movies available (not rented yet) in that range. def available_movies(date_range) + available_movies = @movies.map do |movie| + if movie.date_range <= 0 + return available_movies + else + @rentals << movie + end + end + end + # movies not rented yet = showtime_movies + # movies rented = rentals + + # available_movies << GreenBox::Movie.new(movie_id,title,publisher,actors) + # available_movies = MovieReserver.load_movies + + # @rentals = available_movies.each do |date_range| + # if @rentals.date_range <= 0 + # @rentals << movie + # end + # end + # # return available_movies + + + # `rent_movie(movie_title, date_range, customer_name)`: This method will attempt to reserve a movie with the given title for the given date range. If the movie is not available in that range the method should raise a `StandardError`. + # - Note: This method's tests are not completely written. You will need to fill-in the provided `it` blocks def rent_movie(movie_title, date_range, customer_name) end diff --git a/specs/movie_reserver_spec.rb b/specs/movie_reserver_spec.rb index 51e07f0..06829aa 100644 --- a/specs/movie_reserver_spec.rb +++ b/specs/movie_reserver_spec.rb @@ -51,7 +51,7 @@ end end - xdescribe 'movies available' do + describe 'movies available' do it 'will list the available movies' do available_movies = reserver.available_movies(date_range) From 4908faec15d4682be504906d71059fe5d45a1ae3 Mon Sep 17 00:00:00 2001 From: sabine Date: Sat, 8 Sep 2018 21:30:55 -0700 Subject: [PATCH 14/19] Test0001 of movies available passed. Test002 failed because it requires rent_movie method writtent --- lib/movie_reserver.rb | 91 +++++++++++++++++++++++------------- lib/rental.rb | 4 +- specs/movie_reserver_spec.rb | 4 +- 3 files changed, 64 insertions(+), 35 deletions(-) diff --git a/lib/movie_reserver.rb b/lib/movie_reserver.rb index 34a6a9f..e121d5d 100644 --- a/lib/movie_reserver.rb +++ b/lib/movie_reserver.rb @@ -1,4 +1,5 @@ require 'csv' +require 'pry' require_relative 'date_range' require_relative 'movie' require_relative 'rental' @@ -6,13 +7,14 @@ module GreenBox class MovieReserver - attr_accessor :movies,:rentals,:reserver, :date_range + attr_accessor :movies,:rentals + # :reserver, :date_range def initialize @movies = MovieReserver.load_movies @rentals = [] - @reserver = reserver - @date_range = date_range + @date_range = GreenBox::DateRange.new(Time.parse('2018-08-08'),Time.parse('2018-08-09')) + end def self.load_movies @@ -28,45 +30,70 @@ def self.load_movies showtime_movies << GreenBox::Movie.new(movie_id,title,publisher,actors) end - return showtime_movies - end - - - # `available_movies(date_range)`: This method will take a `DateRange` instance and return a list of movies available (not rented yet) in that range. def available_movies(date_range) - available_movies = @movies.map do |movie| - if movie.date_range <= 0 - return available_movies - else - @rentals << movie + # If @rentals = [] - is empty, + if @rentals = [] + # then all the movies are available + return @movies + end + #PSEUDOCODE + # If there is a movie in rentals + ##### Want to check what movies are in rentals + # that fall into that date date_range + # and remove that movie only + # will need to use a data structure to only use the ID that are in the date_range + #use data structure to store those and match + # them with the ones in the movie list + # + + if @rentals.length > 0 + @rentals.each do |movie| + movie.id + if @movies.include(movie.id) + available_movies = @movies.delete(movie.id) + end end end - end - # movies not rented yet = showtime_movies - # movies rented = rentals + end + + def rent_movie(movie_title, date_range, customer_name) + end - # available_movies << GreenBox::Movie.new(movie_id,title,publisher,actors) - # available_movies = MovieReserver.load_movies +end - # @rentals = available_movies.each do |date_range| - # if @rentals.date_range <= 0 - # @rentals << movie - # end - # end - # # return available_movies +# available_movies = @rentals.map do |movie| +# if @rentals.date_range.contains(movie.id) +# return available_movies +# else +# @rentals << movie +# end +# end +# movies not rented yet = showtime_movies +# movies rented = rentals +# +# available_movies << GreenBox::Rental.new(movie,date_range) +# +# available_movies = MovieReserver.load_movies +# +# @rentals = available_movies.each do |date_range| +# if @rentals.date_range <= 0 +# @rentals << movie +# end +# end +# return available_movies - # `rent_movie(movie_title, date_range, customer_name)`: This method will attempt to reserve a movie with the given title for the given date range. If the movie is not available in that range the method should raise a `StandardError`. - # - Note: This method's tests are not completely written. You will need to fill-in the provided `it` blocks - def rent_movie(movie_title, date_range, customer_name) - end - end - # reserver = GreenBox::MovieReserver.new - # date_range = GreenBox::DateRange.new(Time.parse('2018-08-08'), Time.parse('2018-08-09') -end + +# `rent_movie(movie_title, date_range, customer_name)`: This method will attempt to reserve a movie with the given title for the given date range. If the movie is not available in that range the method should raise a `StandardError`. +# - Note: This method's tests are not completely written. You will need to fill-in the provided `it` blocks + + + +# reserver = GreenBox::MovieReserver.new +# date_range = GreenBox::DateRange.new(Time.parse('2018-08-08'), Time.parse('2018-08-09') diff --git a/lib/rental.rb b/lib/rental.rb index 2132cd9..d516aff 100644 --- a/lib/rental.rb +++ b/lib/rental.rb @@ -2,6 +2,7 @@ require 'time' require_relative 'movie' + module GreenBox class Rental attr_accessor :movie, :date_range, :customer @@ -15,9 +16,10 @@ def initialize(movie, date_range, customer) @customer = customer end + def cost rent = @date_range.nights - cost = rent * 3.0 + cost = rent * 3.0 return cost.round(2) end end diff --git a/specs/movie_reserver_spec.rb b/specs/movie_reserver_spec.rb index 06829aa..5dad22e 100644 --- a/specs/movie_reserver_spec.rb +++ b/specs/movie_reserver_spec.rb @@ -88,13 +88,13 @@ end - xit 'cannot rent a movie already rented' do + it 'cannot rent a movie already rented' do # TODO Your Code goes here end - xit 'raises an error if a movie is requested that does not appear in the list' do + it 'raises an error if a movie is requested that does not appear in the list' do # TODO Your Code goes here end From a66520861ba3e7a6128ea9ad227941a13a8d3ddb Mon Sep 17 00:00:00 2001 From: sabine Date: Mon, 10 Sep 2018 06:26:28 -0700 Subject: [PATCH 15/19] Updated code and test code to 'hide' rent_movie method. Movie available method still failing --- README.md | 2 +- lib/date_range.rb | 5 ++++ lib/movie.rb | 2 ++ lib/movie_reserver.rb | 25 +++++++++-------- lib/rental.rb | 4 ++- specs/movie_reserver_spec.rb | 52 +++++++++++++++++++----------------- 6 files changed, 52 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index f726dcf..4c4167b 100644 --- a/README.md +++ b/README.md @@ -102,7 +102,7 @@ This class will contain an `initialize` method and the following attributes: * movies: The list of movies available in the system * rentals: A list of all the rentals which have occurred. -The `RentalManager` will be able to perform the following actions (methods): +The `MovieReserver` will be able to perform the following actions (methods): * `self.load_movies`: This method will open the csv file `movies.csv` and read in the movies and return an array of the given movies. Note the actors are separated by the `:` character. You will need to break up that field. - The `initialize` method should use `self.load_movies` to read in the movie list for the application diff --git a/lib/date_range.rb b/lib/date_range.rb index bd7b325..8ccbaf9 100644 --- a/lib/date_range.rb +++ b/lib/date_range.rb @@ -2,6 +2,7 @@ require_relative 'movie_reserver' module GreenBox + # When a movie is being rented you need to understand when that rental occurs. To represent that interval of time, you will create a `DateRange` class. class DateRange attr_reader :start_date , :end_date, :nights @@ -14,6 +15,7 @@ def initialize(start_date, end_date) end end +# `contains(date)` - This method returns true if the date occurs on or after the start date and before the end date. def contains(date) if (date >= @start_date) && (date < @end_date) return true @@ -23,6 +25,8 @@ def contains(date) end end + +# `overlaps(other_date_range)` - This method takes another date range as a parameter and returns `true` if the date ranges overlap. def overlaps(other_date_range) if contains(other_date_range.start_date) || contains(other_date_range.end_date) true @@ -33,6 +37,7 @@ def overlaps(other_date_range) end end +# `nights` - This method will return the number of nights included in the given `DateRange. def nights count = (@end_date - @start_date)/(60*60*24) return count diff --git a/lib/movie.rb b/lib/movie.rb index ffc130b..55a01bc 100644 --- a/lib/movie.rb +++ b/lib/movie.rb @@ -1,6 +1,7 @@ require 'csv' module GreenBox + #A 'movie class' represents a film in our system database class Movie attr_reader :id, :title, :publisher, :actors @@ -13,6 +14,7 @@ def initialize(id,title,publisher, actors:[]) movie = GreenBox::Movie.new(4,'Happiness','Fox',actors:['Denzel Washington', 'LL Cool J']) + #This method will return true if the given actor does appear in the movie. def stars_actor(actor_name) actors.each do |actor| diff --git a/lib/movie_reserver.rb b/lib/movie_reserver.rb index e121d5d..946188f 100644 --- a/lib/movie_reserver.rb +++ b/lib/movie_reserver.rb @@ -17,6 +17,8 @@ def initialize end + +# `self.load_movies`: This method will open the csv file `movies.csv` and read in the movies and return an array of the given movies. Note the actors are separated by the `:` character. You will need to break up that field. def self.load_movies showtime_movies = [] @@ -33,12 +35,15 @@ def self.load_movies return showtime_movies end + +# * `available_movies(date_range)`: This method will take a `DateRange` instance and return a list of movies available (not rented yet) in that range. def available_movies(date_range) # If @rentals = [] - is empty, - if @rentals = [] + if @rentals == [] # then all the movies are available return @movies end + #PSEUDOCODE # If there is a movie in rentals ##### Want to check what movies are in rentals @@ -60,7 +65,15 @@ def available_movies(date_range) end end + + + # * `rent_movie(movie_title, date_range, customer_name)`: This method will attempt to reserve a movie with the given title for the given date range. If the movie is not available in that range the method should raise a `StandardError`. + def rent_movie(movie_title, date_range, customer_name) + # It seems like rent movie, moves the movie (title, date range and customer from available_movie array to @rentals array) + # Look to see if the movie with the given title is available within that date_range (method above)in rentals + # if that movie not part of available_movie method, we should raise an argumeent error. + end end @@ -87,13 +100,3 @@ def rent_movie(movie_title, date_range, customer_name) # end # end # return available_movies - - - -# `rent_movie(movie_title, date_range, customer_name)`: This method will attempt to reserve a movie with the given title for the given date range. If the movie is not available in that range the method should raise a `StandardError`. -# - Note: This method's tests are not completely written. You will need to fill-in the provided `it` blocks - - - -# reserver = GreenBox::MovieReserver.new -# date_range = GreenBox::DateRange.new(Time.parse('2018-08-08'), Time.parse('2018-08-09') diff --git a/lib/rental.rb b/lib/rental.rb index d516aff..fef36af 100644 --- a/lib/rental.rb +++ b/lib/rental.rb @@ -4,6 +4,7 @@ module GreenBox + # A `Rental` represents a movie rental in the system. class Rental attr_accessor :movie, :date_range, :customer @@ -13,10 +14,11 @@ def initialize(movie, date_range, customer) end @movie = movie @date_range = date_range + # * customer: The name of the customer making the rental @customer = customer end - +# * `cost`: This method will return the cost of the rental. A movie rental will cost $3.0 per night. The customer is **not** charged for the day the movie is checked in. So a movie checked out on August 8th and checked in August 10th would cost $3.00 * 2 days = $6.00 def cost rent = @date_range.nights cost = rent * 3.0 diff --git a/specs/movie_reserver_spec.rb b/specs/movie_reserver_spec.rb index 5dad22e..351fbce 100644 --- a/specs/movie_reserver_spec.rb +++ b/specs/movie_reserver_spec.rb @@ -61,7 +61,7 @@ it 'will not include rented movies' do date_range = GreenBox::DateRange.new(Time.parse('2018-08-08'), Time.parse('2018-08-09')) - reserver.rent_movie('Crazy Rich Asians', date_range, 'Ada Lovelace') + #reserver.rent_movie('Crazy Rich Asians', date_range, 'Ada Lovelace') available_movies = reserver.available_movies(date_range) expect(available_movies.length).must_equal 10 @@ -75,28 +75,30 @@ end end - xdescribe 'rent_movie' do - it 'returns a rental for a successfully rented movie' do - # TODO Your Code goes here - - - end - - it 'can rent multiple movies with the same title' do - # TODO Your Code goes here - - - end - - it 'cannot rent a movie already rented' do - # TODO Your Code goes here - - - end - - it 'raises an error if a movie is requested that does not appear in the list' do - # TODO Your Code goes here - - end - end + # xdescribe 'rent_movie' do + # xit 'returns a rental for a successfully rented movie' do + # @rental.rent_movie(id = 3) + # expect(@rental.rent.movie).must.be.equal_to ('Blackklansman', Time.parse('2018-08-08'), Time.parse('2018-08-09')) end + # end + # + # it 'can rent multiple movies with the same title' do + # Your Code goes here + # + # + # end + # + # it 'cannot rent a movie already rented' do + # rental = @rental.rent_movie() + # expect{available_movies}.must_be_empty + # + # + # end + # + # it 'raises an error if a movie is requested that does not appear in the list' do + # @rental.find_movie().movie_rented + # @rental.find_movie().movie_rented + # expect{rental.rent_movie}.must_raise ArgumentError + # + # end + # end end From d2275d49af5bb3203715c8dc4eb0266a77d65cc1 Mon Sep 17 00:00:00 2001 From: sabine Date: Mon, 10 Sep 2018 12:32:28 -0700 Subject: [PATCH 16/19] Tests and Codes to be updated this afternoon --- lib/movie_reserver.rb | 8 ++++-- specs/movie_reserver_spec.rb | 55 ++++++++++++++++++++---------------- 2 files changed, 36 insertions(+), 27 deletions(-) diff --git a/lib/movie_reserver.rb b/lib/movie_reserver.rb index 946188f..5e62fe0 100644 --- a/lib/movie_reserver.rb +++ b/lib/movie_reserver.rb @@ -70,9 +70,11 @@ def available_movies(date_range) # * `rent_movie(movie_title, date_range, customer_name)`: This method will attempt to reserve a movie with the given title for the given date range. If the movie is not available in that range the method should raise a `StandardError`. def rent_movie(movie_title, date_range, customer_name) - # It seems like rent movie, moves the movie (title, date range and customer from available_movie array to @rentals array) - # Look to see if the movie with the given title is available within that date_range (method above)in rentals - # if that movie not part of available_movie method, we should raise an argumeent error. + + + # Look to see if the movie with the given title is available within that date_range (method above)in rentals + # If available rent movie, moves the movie (title, date range and customer from available_movie array to @rentals array) + # if that movie not part of available_movie method, we should raise an Argument error. end diff --git a/specs/movie_reserver_spec.rb b/specs/movie_reserver_spec.rb index 351fbce..5addf5f 100644 --- a/specs/movie_reserver_spec.rb +++ b/specs/movie_reserver_spec.rb @@ -76,29 +76,36 @@ end # xdescribe 'rent_movie' do - # xit 'returns a rental for a successfully rented movie' do - # @rental.rent_movie(id = 3) - # expect(@rental.rent.movie).must.be.equal_to ('Blackklansman', Time.parse('2018-08-08'), Time.parse('2018-08-09')) end - # end - # - # it 'can rent multiple movies with the same title' do + xit 'returns a rental for a successfully rented movie' do + + # arrange + @rental = [ ] + # act + # assert + ## the rent_movie methods will return + + @rental.rent_movie(id = 3) + expect(@rental.rent.movie).must.be.equal_to ('Blackklansman', Time.parse('2018-08-08'), Time.parse('2018-08-09')) end + end + + it 'can rent multiple movies with the same title' do # Your Code goes here - # - # - # end - # - # it 'cannot rent a movie already rented' do - # rental = @rental.rent_movie() - # expect{available_movies}.must_be_empty - # - # - # end - # - # it 'raises an error if a movie is requested that does not appear in the list' do - # @rental.find_movie().movie_rented - # @rental.find_movie().movie_rented - # expect{rental.rent_movie}.must_raise ArgumentError - # - # end - # end + + + end + + it 'cannot rent a movie already rented' do + rental = @rental.rent_movie() + expect{available_movies}.must_include + + + end + + it 'raises an error if a movie is requested that does not appear in the list' do + @rental.find_movie().movie_rented + @rental.find_movie().movie_rented + expect{rental.rent_movie}.must_raise ArgumentError + + end + end end From 704b131aa5735fead083b07a35a684ca23d62b16 Mon Sep 17 00:00:00 2001 From: sabine Date: Mon, 10 Sep 2018 18:36:19 -0700 Subject: [PATCH 17/19] rent_movie methods are almost completed --- lib/movie_reserver.rb | 17 +++----- specs/movie_reserver_spec.rb | 83 +++++++++++++++++++++++++++--------- 2 files changed, 70 insertions(+), 30 deletions(-) diff --git a/lib/movie_reserver.rb b/lib/movie_reserver.rb index 5e62fe0..e28da63 100644 --- a/lib/movie_reserver.rb +++ b/lib/movie_reserver.rb @@ -18,7 +18,7 @@ def initialize end -# `self.load_movies`: This method will open the csv file `movies.csv` and read in the movies and return an array of the given movies. Note the actors are separated by the `:` character. You will need to break up that field. + # `self.load_movies`: This method will open the csv file `movies.csv` and read in the movies and return an array of the given movies. Note the actors are separated by the `:` character. You will need to break up that field. def self.load_movies showtime_movies = [] @@ -63,19 +63,16 @@ def available_movies(date_range) end end end - end - - + # * `rent_movie(movie_title, date_range, customer_name)`: This method will attempt to reserve a movie with the given title for the given date range. If the movie is not available in that range the method should raise a `StandardError`. - # * `rent_movie(movie_title, date_range, customer_name)`: This method will attempt to reserve a movie with the given title for the given date range. If the movie is not available in that range the method should raise a `StandardError`. + def rent_movie(movie_title, date_range, customer_name) - def rent_movie(movie_title, date_range, customer_name) + # Look to see if the movie with the given title is available within that date_range (method above)in rentals + # If available rent movie, moves the movie (title, date range and customer from available_movie array to @rentals array) + # if that movie not part of available_movie method, we should raise an Argument error. - # Look to see if the movie with the given title is available within that date_range (method above)in rentals - # If available rent movie, moves the movie (title, date range and customer from available_movie array to @rentals array) - # if that movie not part of available_movie method, we should raise an Argument error. - + end end end diff --git a/specs/movie_reserver_spec.rb b/specs/movie_reserver_spec.rb index 5addf5f..9ed261a 100644 --- a/specs/movie_reserver_spec.rb +++ b/specs/movie_reserver_spec.rb @@ -59,9 +59,9 @@ expect(available_movies.length).must_equal 11 end - it 'will not include rented movies' do + xit 'will not include rented movies' do date_range = GreenBox::DateRange.new(Time.parse('2018-08-08'), Time.parse('2018-08-09')) - #reserver.rent_movie('Crazy Rich Asians', date_range, 'Ada Lovelace') + reserver.rent_movie('Crazy Rich Asians', date_range, 'Ada Lovelace') available_movies = reserver.available_movies(date_range) expect(available_movies.length).must_equal 10 @@ -75,36 +75,79 @@ end end - # xdescribe 'rent_movie' do - xit 'returns a rental for a successfully rented movie' do - - # arrange - @rental = [ ] - # act - # assert - ## the rent_movie methods will return - - @rental.rent_movie(id = 3) - expect(@rental.rent.movie).must.be.equal_to ('Blackklansman', Time.parse('2018-08-08'), Time.parse('2018-08-09')) end + describe 'rent_movie' do + it 'returns a rental for a successfully rented movie' do + #Setup + movie_reserver = GreenBox::MovieReserver.new + title = 'Crazy Rich Asians' + date_range = GreenBox::DateRange.new(Time.parse('2018-08-08'),Time.parse('2018-08-09')) + customer_name = ' Sabine ' + + #Method under testn(call the things that I am verifying) + rental = movie_reserver.rent_movie(title, date_range, customer_name) + + #Assertions - something that has changed that tells + #us we have the expected result + expect(rental).wont_be_nil + end + it 'can rent multiple movies with the same title' do - # Your Code goes here + + movie_reserver = GreenBox::MovieReserver.new + title = 'Crazy Rich Asians' + + date_range_a = GreenBox::DateRange.new(Time.parse('2018-08-09'),Time.parse('2018-08-10')) + customer_name_a = ' Andrew ' + + date_range_b = GreenBox::DateRange.new(Time.parse('2018-08-08'),Time.parse('2018-08-09')) + customer_name_b = ' Sabine ' + + rental_a = movie_reserver.rent_movie(title, date_range_a, customer_name_a) + + rental_b = movie_reserver.rent_movie(title, date_range_b, customer_name_b) + + expect(rental_a).wont_be_nil + expect(rental_b).wont_be_nil + expect(rental_a).wont_equal(rental_b) end - it 'cannot rent a movie already rented' do - rental = @rental.rent_movie() - expect{available_movies}.must_include + it 'cannot rent a movie already rented' do + # movie_reserver = GreenBox::MovieReserver.new + # + # title = 'Crazy Rich Asians' + # + # date_range_a = GreenBox::DateRange.new(Time.parse('2018-08-09'),Time.parse('2018-08-10')) + # customer_name_a = ' Andrew ' + # + # date_range_b = GreenBox::DateRange.new(Time.parse('2018-08-08'),Time.parse('2018-08-09')) + # customer_name_b = ' Sabine ' + + + movie_reserver = GreenBox::MovieReserver.new + title = 'Crazy Rich Asians' + date_range = GreenBox::DateRange.new(Time.parse('2018-08-08'),Time.parse('2018-08-09')) + customer_name = ' Sabine ' + + #Method under test(call the things that I am verifying) + rental_a = movie_reserver.rent_movie(title, date_range, customer_name) + rental_b = movie_reserver.rent_movie(title, date_range, customer_name) + + #Assertions/Expectation - something that has changed that tells + #us we have the expected result + expect(rental_a).wont_be_nil + expect(rental_b).must_be_nil + end it 'raises an error if a movie is requested that does not appear in the list' do - @rental.find_movie().movie_rented - @rental.find_movie().movie_rented - expect{rental.rent_movie}.must_raise ArgumentError + + end end From 7bbb9033763aaa18c8437731ae68d9c3d8065c7f Mon Sep 17 00:00:00 2001 From: sabine Date: Tue, 11 Sep 2018 05:06:23 -0700 Subject: [PATCH 18/19] All tests for rent_movies are written, need to ccomplete codes for rent_movies and available_movies --- specs/movie_reserver_spec.rb | 60 ++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/specs/movie_reserver_spec.rb b/specs/movie_reserver_spec.rb index 9ed261a..73a2c95 100644 --- a/specs/movie_reserver_spec.rb +++ b/specs/movie_reserver_spec.rb @@ -59,7 +59,7 @@ expect(available_movies.length).must_equal 11 end - xit 'will not include rented movies' do + it 'will not include rented movies' do date_range = GreenBox::DateRange.new(Time.parse('2018-08-08'), Time.parse('2018-08-09')) reserver.rent_movie('Crazy Rich Asians', date_range, 'Ada Lovelace') @@ -77,18 +77,18 @@ describe 'rent_movie' do it 'returns a rental for a successfully rented movie' do - #Setup - movie_reserver = GreenBox::MovieReserver.new - title = 'Crazy Rich Asians' - date_range = GreenBox::DateRange.new(Time.parse('2018-08-08'),Time.parse('2018-08-09')) - customer_name = ' Sabine ' + #Setup + movie_reserver = GreenBox::MovieReserver.new + title = 'Crazy Rich Asians' + date_range = GreenBox::DateRange.new(Time.parse('2018-08-08'),Time.parse('2018-08-09')) + customer_name = ' Sabine ' - #Method under testn(call the things that I am verifying) - rental = movie_reserver.rent_movie(title, date_range, customer_name) + #Method under testn(call the things that I am verifying) + rental = movie_reserver.rent_movie(title, date_range, customer_name) - #Assertions - something that has changed that tells - #us we have the expected result - expect(rental).wont_be_nil + #Assertions - something that has changed that tells + #us we have the expected result + expect(rental).wont_be_nil end @@ -118,36 +118,36 @@ it 'cannot rent a movie already rented' do - # movie_reserver = GreenBox::MovieReserver.new - # - # title = 'Crazy Rich Asians' - # - # date_range_a = GreenBox::DateRange.new(Time.parse('2018-08-09'),Time.parse('2018-08-10')) - # customer_name_a = ' Andrew ' - # - # date_range_b = GreenBox::DateRange.new(Time.parse('2018-08-08'),Time.parse('2018-08-09')) - # customer_name_b = ' Sabine ' - movie_reserver = GreenBox::MovieReserver.new title = 'Crazy Rich Asians' date_range = GreenBox::DateRange.new(Time.parse('2018-08-08'),Time.parse('2018-08-09')) customer_name = ' Sabine ' - #Method under test(call the things that I am verifying) - rental_a = movie_reserver.rent_movie(title, date_range, customer_name) - rental_b = movie_reserver.rent_movie(title, date_range, customer_name) - - #Assertions/Expectation - something that has changed that tells - #us we have the expected result - expect(rental_a).wont_be_nil - expect(rental_b).must_be_nil + #Method under test(call the things that I am verifying) + rental_a = movie_reserver.rent_movie(title, date_range, customer_name) + rental_b = movie_reserver.rent_movie(title, date_range, customer_name) + #Assertions/Expectation - something that has changed that tells + #us we have the expected result + expect(rental_a).wont_be_nil + expect(rental_b).must_be_nil + # expect(rental_a).must_equal(rental_b) end it 'raises an error if a movie is requested that does not appear in the list' do - + movie_reserver = GreenBox::MovieReserver.new + title = 'Crazy Rich Asians' + date_range = GreenBox::DateRange.new(Time.parse('2018-08-08'),Time.parse('2018-08-09')) + customer_name = ' Sabine ' + + # checking for errors + expect { + movie_reserver.rent_movie(title, date_range, customer_name) + + # (the "method under test" section goes inside!) + }.must_raise StandardError end end From e3167e4b62556d99eec0c4021e504430bdaa77c4 Mon Sep 17 00:00:00 2001 From: sabine Date: Wed, 12 Sep 2018 07:48:44 -0700 Subject: [PATCH 19/19] Still working on completing available_movies and rent_movies methods. 2 test failrures and 1 test error --- lib/movie_reserver.rb | 84 ++++++++++++++++++++++-------------- specs/movie_reserver_spec.rb | 6 +-- 2 files changed, 54 insertions(+), 36 deletions(-) diff --git a/lib/movie_reserver.rb b/lib/movie_reserver.rb index e28da63..bfaf477 100644 --- a/lib/movie_reserver.rb +++ b/lib/movie_reserver.rb @@ -7,17 +7,15 @@ module GreenBox class MovieReserver - attr_accessor :movies,:rentals + attr_accessor :movies, :rentals, :date_range # :reserver, :date_range def initialize @movies = MovieReserver.load_movies @rentals = [] @date_range = GreenBox::DateRange.new(Time.parse('2018-08-08'),Time.parse('2018-08-09')) - end - # `self.load_movies`: This method will open the csv file `movies.csv` and read in the movies and return an array of the given movies. Note the actors are separated by the `:` character. You will need to break up that field. def self.load_movies showtime_movies = [] @@ -30,48 +28,70 @@ def self.load_movies actors_names = all_actors.split(':') actors = {actors: actors_names} - showtime_movies << GreenBox::Movie.new(movie_id,title,publisher,actors) + showtime_movies << GreenBox::Movie.new(movie_id, title, publisher, actors) end return showtime_movies end -# * `available_movies(date_range)`: This method will take a `DateRange` instance and return a list of movies available (not rented yet) in that range. + # `available_movies(date_range)`: This method will take a `DateRange` instance and return a list of + # movies available (not rented yet) in that range. def available_movies(date_range) - # If @rentals = [] - is empty, - if @rentals == [] - # then all the movies are available - return @movies - end - #PSEUDOCODE - # If there is a movie in rentals - ##### Want to check what movies are in rentals - # that fall into that date date_range - # and remove that movie only - # will need to use a data structure to only use the ID that are in the date_range - #use data structure to store those and match - # them with the ones in the movie list - # - - if @rentals.length > 0 - @rentals.each do |movie| - movie.id - if @movies.include(movie.id) - available_movies = @movies.delete(movie.id) + # @movies = available_movies + # If @rentals = [] - is empty, + if @rentals.empty? + # then all the movies are available + return @movies + else + # @movies is a MovieReserver object that contains movies. + available_movies = [] + @movies.each do |movie| + if @rentals.date_range == date_range + available_movies << movie + end end + return @rentals end - end end + #PSEUDOCODE + # If there is a movie in rentals + ##### Want to check what movies are in rentals + # that fall into that date date_range + # and remove that movie only + # will need to use a data structure to only use the ID that are in the date_range + #use data structure to store those and match + # them with the ones in the movie list + # + + # if @rentals.length > 0 + # @rentals.each do |movies| + # date_range + # if @movies.include(date_range) + # available_movies = @movies.delete(date_range) + # end + + # @rentals.each do |movie| + # movie.id + # if @movies.include(movie.id) + # available_movies = @movies.delete(movie.id) + # end + + # end + + # end + # * `rent_movie(movie_title, date_range, customer_name)`: This method will attempt to reserve a movie with the given title for the given date range. If the movie is not available in that range the method should raise a `StandardError`. def rent_movie(movie_title, date_range, customer_name) - - - # Look to see if the movie with the given title is available within that date_range (method above)in rentals - # If available rent movie, moves the movie (title, date range and customer from available_movie array to @rentals array) - # if that movie not part of available_movie method, we should raise an Argument error. - + @movies.each do |movie| + if movie.title == movie_title + @rentals << movie + return @rentals + end + end + # If we finish the loop and nothing is found, raise an error here. + raise ArgumentError.new("No movies found!") end end diff --git a/specs/movie_reserver_spec.rb b/specs/movie_reserver_spec.rb index 73a2c95..7c07bb4 100644 --- a/specs/movie_reserver_spec.rb +++ b/specs/movie_reserver_spec.rb @@ -64,7 +64,7 @@ reserver.rent_movie('Crazy Rich Asians', date_range, 'Ada Lovelace') available_movies = reserver.available_movies(date_range) - expect(available_movies.length).must_equal 10 + expect(available_movies).must_equal 10 movie_id = 2 movie_id_2 = available_movies.find do |movie| @@ -112,11 +112,9 @@ expect(rental_b).wont_be_nil expect(rental_a).wont_equal(rental_b) - end - it 'cannot rent a movie already rented' do movie_reserver = GreenBox::MovieReserver.new @@ -138,7 +136,7 @@ it 'raises an error if a movie is requested that does not appear in the list' do movie_reserver = GreenBox::MovieReserver.new - title = 'Crazy Rich Asians' + title = 'Blackklansman' date_range = GreenBox::DateRange.new(Time.parse('2018-08-08'),Time.parse('2018-08-09')) customer_name = ' Sabine '