Skip to content

Conversation

@Sabineth17
Copy link

Last updates on the GreenBox and tests to be added and updated this afternoon.

Copy link

@CheezItMan CheezItMan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall pretty good waves 1-2.

You do need more work on available_movies and rent_movie and the tests.

You have a good number of commits and good commit messages and the code is overall pretty well done. I'd like you to first look through the MovieReserver class and the two incomplete methods and then work on the tests with Andrew if you can.

if (date >= @start_date) && (date < @end_date)
return true
else
date < @start_date || date >= @end_date

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need this 2nd conditional since if it's not inside you can return false.

if (date >= @start_date) && (date < @end_date)
        return true
      else
        return false
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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@actors = actors
end

movie = GreenBox::Movie.new(4,'Happiness','Fox',actors:['Denzel Washington', 'LL Cool J'])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can take this line out

def initialize
@movies = MovieReserver.load_movies
@rentals = []
@date_range = GreenBox::DateRange.new(Time.parse('2018-08-08'),Time.parse('2018-08-09'))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This @date_range is unnecessary since there isn't one daterange needed by the system. Instead each Rental will have it's own DateRange

publisher = line[2]
all_actors = line[3]
actors_names = all_actors.split(':')
actors = {actors: actors_names}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also make this:

actors = actors_names

And just use an array instead of a has containing one array.

# them with the ones in the movie list
#

if @rentals.length > 0

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you have the previous if statement, you don't need this one.

@rentals.each do |movie|
movie.id
if @movies.include(movie.id)
available_movies = @movies.delete(movie.id)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since delete will remove any matching movies from the@movies array permanently, you would do better to:

  1. Make a copy of @movies
  2. Use .reject to remove movies that match the given id
  3. Return that resulting list of movies

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

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')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're going to comment this out, you'll need to manually add a rented movie to the system.

reserver.rentals << Rental.new('movie title', Time.parse('2018-08-08'), Time.parse('2018-08-09'))

# assert
## the rent_movie methods will return

@rental.rent_movie(id = 3)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be easier just to give the title of the movie, although you could do it by ID. However you'll need a MovieReserver instance.

You are right these tests below need work. You might try replicating some of the format of the tests written for you.

Copy link

@CheezItMan CheezItMan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a few more suggestions here, your tests are not bad, and they are catching some bugs in your code.

Some strong improvement here.

xit 'cannot rent a movie already rented' do
# TODO Your Code goes here

it 'cannot rent a movie already rented' do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a well written test! 👍

Nice work!

# * `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)
@movies.each do |movie|

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As your test shows, this isn't working because it always rents a movie as long as the movie is in the inventory.

If I can make a suggestion:

  1. See if the list of available_movies has this movie title, you can use .each or find_by to do so.
  2. If so, you can create a rental,
  3. add it to the list
  4. return the rental


#Assertions - something that has changed that tells
#us we have the expected result
expect(rental).wont_be_nil

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good, you also might want to test that
expect(rental.movie.title).must_equal title (the title of the movie being rented is right.

You can also test that the number of rentals has increased by one (so the length of rentals increased by one).

it 'can rent multiple movies with the same title' do
# TODO Your Code goes here

movie_reserver = GreenBox::MovieReserver.new

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nicely done!

# @movies is a MovieReserver object that contains movies.
available_movies = []
@movies.each do |movie|
if @rentals.date_range == date_range

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part is not quite right. @rentals is an array and so doesn't have a date_range attribute.
Instead you should:

  1. make a copy of the movies list
  2. then loop through your rentals array and remove any movies who have a rental that conflicts.

You can look up the select method to find movies that don't have a given ID or object id.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants