Skip to content

Instantly share code, notes, and snippets.

@paulnicholsen27
Created September 26, 2018 19:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulnicholsen27/94f9bf0bdcfa15f1cfee3df4a777996b to your computer and use it in GitHub Desktop.
Save paulnicholsen27/94f9bf0bdcfa15f1cfee3df4a777996b to your computer and use it in GitHub Desktop.
require 'bundler/setup'
Bundler.require
require_rel '../app'
describe "Challenge" do
before(:all) do
@customer1 = Customer.new("Bob", "Bobbington")
@customer2 = Customer.new("Mary", "Maryberg")
@customer3 = Customer.new("Bob", "SomeoneElse")
@restaurant1 = Restaurant.new("McDonalds")
@restaurant2 = Restaurant.new("Olive Garden")
@review1 = Review.new(@customer1, @restaurant1, 5, "I love McNuggets")
@review2 = Review.new(@customer2, @restaurant2, 3, "Endless breadsticks did in fact end.")
@new_review = @customer1.add_review(@restaurant2, "It stinks", 1)
end
describe Customer do
context "attributes" do
it "has a first and last name" do
expect(@customer1.first_name).to eql("Bob")
expect(@customer1.last_name).to eql("Bobbington")
end
end
context ".all" do
it "returns all customers" do
expect(Customer.all).to match_array([@customer1, @customer2, @customer3])
end
end
context ".find_by_name" do
it "can find a customer by full name" do
expect(Customer.find_by_name("Bob Bobbington")).to eql(@customer1)
expect(Customer.find_by_name("Mary Maryberg")).to eql(@customer2)
end
end
context ".find_all_by_first_name" do
it "can get all customers with matching first name" do
expect(Customer.find_all_by_first_name("Bob")).to match_array(
[@customer1, @customer3])
end
end
context ".all_names" do
it "can return an array of all names" do
expect(Customer.all_names).to match_array(["Bob Bobbington", "Mary Maryberg", "Bob SomeoneElse"])
end
end
context "#add_review" do
it "can add a review" do
expect(@new_review.customer).to eq(@customer1)
expect(@new_review.restaurant).to eq(@restaurant2)
end
end
context "#num_reviews" do
it "returns number of reviews by customer" do
expect(@customer1.num_reviews).to eq(2)
end
end
context "#restaurants" do
it "returns array of unique restaurants the customer has reviewed" do
expect(@customer1.restaurants).to match_array([@restaurant1, @restaurant2])
end
end
end
describe Restaurant do
it "has a name" do
expect(@restaurant1.name).to eql("McDonalds")
end
it "can get all restaurants" do
expect(Restaurant.all).to match_array([@restaurant1, @restaurant2])
end
it "can find a restaurant by name" do
expect(Restaurant.find_by_name("McDonalds")).to eq(@restaurant1)
end
context("#customers") do
it "Returns a **unique** list of all customers who have reviewed a particular restaurant." do
expect(@restaurant2.customers).to match_array([@customer1, @customer2])
end
end
context("#reviews") do
it "returns an array of all reviews for that restaurant" do
expect(@restaurant2.reviews).to match_array([@review2, @new_review])
end
end
context("#average_star_rating") do
it ("returns the average star rating for a restaurant based on its reviews") do
expect(@restaurant2.average_star_rating).to eq(2)
end
end
context("#longest_review") do
it ("returns the longest review content for a given restaurant") do
expect(@restaurant2.longest_review).to eq("Endless breadsticks did in fact end.")
end
end
end
describe Review do
it "can get all reviews" do
expect(Review.all.length).to eq(3)
end
it "can get attributes of a review" do
expect(@review1.customer).to eq(@customer1)
expect(@review1.restaurant).to eq(@restaurant1)
expect(@review1.rating).to eq(5)
expect(@review1.content).to eq("I love McNuggets")
end
it "cannot change restaurant or customer" do
expect { @review1.customer = @customer2 }.to raise_error(NoMethodError)
expect { @review1.restaurant = @restaurant2 }.to raise_error(NoMethodError)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment