Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add factory bot, faker and pull out add attendees method #33

Merged
merged 1 commit into from
Dec 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ gem 'faraday'

group :development, :test do
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
gem 'factory_bot_rails'
gem 'faker'
gem 'pry'
gem 'rspec-rails'
end
Expand Down
10 changes: 9 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ GEM
diff-lcs (1.5.0)
docile (1.4.0)
erubi (1.12.0)
factory_bot (6.4.2)
activesupport (>= 5.0.0)
factory_bot_rails (6.4.2)
factory_bot (~> 6.4)
railties (>= 5.0.0)
faker (3.2.2)
i18n (>= 1.8.11, < 2)
faraday (2.7.12)
base64
faraday-net_http (>= 2.0, < 3.1)
Expand Down Expand Up @@ -267,12 +274,13 @@ GEM
zeitwerk (2.6.12)

PLATFORMS
arm64-darwin-21
arm64-darwin-23

DEPENDENCIES
bootsnap
capybara
factory_bot_rails
faker
faraday
importmap-rails
jbuilder
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/movies_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class MoviesController < ApplicationController
def index
@user = User.find(params[:id])

@movies = if params[:q] == 'top-rated'
MovieFacade.top_rated
else
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def create
if @user.save
redirect_to user_dashboard_path(@user)
else
flash[:alert] = "Error: Please fill out all fields and use a unique email"
flash[:alert] = 'Error: Please fill out all fields and use a unique email'
render :new
end
end
Expand Down
22 changes: 6 additions & 16 deletions app/controllers/viewing_parties_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,21 @@ def create

@viewing_party = ViewingParty.create!(viewing_party_params)

#write the helper method
#goes through the params[:user_ids] (which is everyone who is checked off), find the user related to that user_id, and add them to the VP.users
if @attendees != nil
@attendees.each do |id|
x = User.find_by(id: id)
@viewing_party.users << x
end
end
@viewing_party.add_attendees(@attendees)

#adds in the user who created the viewing party
# adds in the user who created the viewing party
@viewing_party.users << @user

#find the host in the UserViewingParty table
# find the host in the UserViewingParty table
@user_viewing_party = UserViewingParty.find_by(user_id: @user.id, viewing_party_id: @viewing_party.id)

if @user_viewing_party
@user_viewing_party.update(host: true)
else
end
@user_viewing_party&.update(host: true)

if @viewing_party.save
flash[:alert] = "Viewing Party Created!"
flash[:alert] = 'Viewing Party Created!'
redirect_to user_dashboard_path(@user.id)
else
flash[:alert] = "Error: Please fill out all fields"
flash[:alert] = 'Error: Please fill out all fields'
render :new
end
end
Expand Down
1 change: 0 additions & 1 deletion app/facades/movie_facade.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class MovieFacade

def self.top_rated
json_response = MovieService.top_rated
json_response[:results].map do |movie|
Expand Down
10 changes: 10 additions & 0 deletions app/models/viewing_party.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,14 @@ class ViewingParty < ApplicationRecord
has_many :users, through: :user_viewing_parties

validates :party_duration, :start_time, :movie_title, :movie_id, presence: true

def add_attendees(attendees)
# goes through the params[:user_ids] (which is everyone who is checked off),
# find the user related to that user_id, and add them to the VP.users
return if attendees.nil?

attendees.each do |id|
users << User.find_by(id:)
end
end
end
3 changes: 1 addition & 2 deletions app/services/movie_service.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
class MovieService

def self.conn
Faraday.new(url: "https://api.themoviedb.org") do |faraday|
Faraday.new(url: 'https://api.themoviedb.org') do |faraday|
faraday.params['api_key'] = Rails.application.credentials.TMDB[:key]
end
end
Expand Down
2 changes: 1 addition & 1 deletion config/credentials.yml.enc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
taq89yjKJZn6RHR0sBWE1W/nOdb+cVK4UtX/INR6+Wv4jdkTNffKopIoK9EOGjRsXvXptOx0t7XaVp/Vp+R+ngW2YnfNdyO0el2FfX7m+dzbzdbj4YJo18uEoxoXuWrQSPCy2kDdkyhIy3Tv+cFwpcKraI81xPTxM43HpzCF9PvTf+WDhtqbbpEV6sPEaL2ZATZ88cz3KkPZ3kajMxM/jAV2xQk95JEPdNBpUz1HS4L/RIa80pXELCDicnWAMtndlIWj/sbAwiJicl3y8zLPe8o3ZtriVEBcozAWQfRdrYRHTw4JdoMABZcz+btHR2eCJ72rhdghXfzgY/Gyui2rz/FN2+bxJU4WXo0LOL/pseTwneMZBO5XA6x8KxQMDCFm2w3f2teR8qhzmXbcXSwlFWeXa1lZ7lVUvtyqQZ0P9NzX35elWiVrYOVNV/dVmoKLKAAtHt92rBVLNvWCTu2FLqiZlw==--+VxILB40odj6xe20--yTJftT2hdm2Vaq4uHql17g==
lpnNiUJsWjK503WygUtt48WyX/eLVVgYZM/51BlddBW+QUajmOH2HFTvBuSMMwlPeFhuLJNk+ofaYuNM6xaG8M5HdW6C5Cb6HbPlLUwQeycjnO8ihcQPCC92ERpOJhQ8FDe6f/tXRWLza3+Xx/u9w90A6IpxOPqetjs4TLuCoEcgDXBx/NgSX5WC9JahKkNjZUlkpYk1XlDZRgGBxj5/drbUM0tPSTjEUYx+vgbvE5RYHSGCdcyxyuLYfpZp1U7ZuEVokgI3y8ORg7Hedh6pphW6JaqDMuJnRXOW/uRyYv9iwTBPIR6ZtzBxLqNEt/ZfS/Jbu//tLJVbNmJct4y1I6HFciwkLp8evC812rZUTsAgEW73rN4brww/u+Ufg3eD1OvgF1pabp4X25aN4iQl/eN6DHGXidcGWq9bReEXwemb09hMJnMvup1N9wBW2chf0CtaNdejsOCNGFuj2wGmB1Jc--3rYQu+j+pgHcwd2f--RnvvVt2iE1o2J6VJTL6WZQ==
88 changes: 44 additions & 44 deletions spec/facades/movie_facade_spec.rb
Original file line number Diff line number Diff line change
@@ -1,84 +1,84 @@
require 'rails_helper'

describe MovieFacade do
describe "class methods" do
describe 'class methods' do
before(:each) do
@user = User.create(name: "Joseph", email: "jlee230@turing.edu")
@search_term = "Die+Hard"
@user = User.create(name: 'Joseph', email: 'jlee230@turing.edu')
@search_term = 'Die+Hard'
end

feature "#top_rated" do
scenario "Find Top Rated Movies button is clicked", :vcr do
visit "/users/#{@user.id}/discover"
feature '#top_rated' do
scenario 'Find Top Rated Movies button is clicked', :vcr do
visit "/users/#{@user.id}/discover"

expect(page).to have_button("Find Top Rated Movies")
click_on("Find Top Rated Movies")
expect(page).to have_button('Find Top Rated Movies')
click_on('Find Top Rated Movies')

expect(page.status_code).to eq(200)
expect(page).to have_link("The Godfather")
expect(page).to have_content("8.708")
expect(page.status_code).to eq(200)
expect(page).to have_link('The Godfather')
expect(page).to have_content('8.708')
end
end

feature "#search" do
scenario "Search bar is filled in and search button is clicked", :vcr do
feature '#search' do
scenario 'Search bar is filled in and search button is clicked', :vcr do
visit "/users/#{@user.id}/discover"

expect(page).to have_field(:search)
expect(page).to have_button("Find Movies")
fill_in(:search, with: 'Die Hard')
click_on("Find Movies")
expect(page).to have_button('Find Movies')
fill_in(:search, with: 'Die Hard')
click_on('Find Movies')

expect(page.status_code).to eq(200)
expect(page).to have_link("Die Hard")
expect(page).to have_content("7.78")
expect(page).to have_link('Die Hard')
expect(page).to have_content('7.78')
end
end

feature "#movie_details" do
scenario "the movie show page is loaded and a Movie PORO is created", :vcr do
feature '#movie_details' do
scenario 'the movie show page is loaded and a Movie PORO is created', :vcr do
visit "/users/#{@user.id}/movies?search=#{@search_term}&commit=Find+Movies"

expect(page).to have_link("Die Hard 2")
click_on("Die Hard 2")
expect(page).to have_link('Die Hard 2')
click_on('Die Hard 2')

expect(page.status_code).to eq(200)
expect(page).to have_content("Title: Die Hard 2")
expect(page).to have_content("Vote Average: 6.929")
expect(page).to have_content("Runtime: 2 hours and 4 minutes")
expect(page).to have_content("Genres:")
expect(page).to have_content("Action")
expect(page).to have_content("Thriller")
expect(page).to have_content("Overview: Off-duty cop John McClane is gripped with a feeling of déjà vu when, on a snowy Christmas Eve in the nation’s capital, terrorists seize a major international airport, holding thousands of holiday travelers hostage. Renegade military commandos led by a murderous rogue officer plot to rescue a drug lord from justice and are prepared for every contingency except one: McClane’s smart-mouthed heroics.")
expect(page).to have_content("Vote Count: 5347")
expect(page).to have_content('Title: Die Hard 2')
expect(page).to have_content('Vote Average: 6.929')
expect(page).to have_content('Runtime: 2 hours and 4 minutes')
expect(page).to have_content('Genres:')
expect(page).to have_content('Action')
expect(page).to have_content('Thriller')
expect(page).to have_content('Overview: Off-duty cop John McClane is gripped with a feeling of déjà vu when, on a snowy Christmas Eve in the nation’s capital, terrorists seize a major international airport, holding thousands of holiday travelers hostage. Renegade military commandos led by a murderous rogue officer plot to rescue a drug lord from justice and are prepared for every contingency except one: McClane’s smart-mouthed heroics.')
expect(page).to have_content('Vote Count: 5347')
end
end

feature "#cast" do
scenario "the movie show page is loaded and a Cast PORO is created", :vcr do
feature '#cast' do
scenario 'the movie show page is loaded and a Cast PORO is created', :vcr do
visit "/users/#{@user.id}/movies?search=#{@search_term}&commit=Find+Movies"

expect(page).to have_link("Die Hard 2")
click_on("Die Hard 2")
expect(page).to have_link('Die Hard 2')
click_on('Die Hard 2')

expect(page.status_code).to eq(200)
expect(page).to have_content('Bruce Willis plays the character of "John McClane"')
expect(page).to have_content('Bonnie Bedelia plays the character of "Holly McClane"')
expect(page).to have_content('William Sadler plays the character of "Stuart"')
expect(page).to have_content('Bruce Willis plays the character of "John McClane"')
expect(page).to have_content('Bonnie Bedelia plays the character of "Holly McClane"')
expect(page).to have_content('William Sadler plays the character of "Stuart"')
end
end

feature "#reviews" do
scenario "the movie show page is loaded and a Review PORO is created", :vcr do
feature '#reviews' do
scenario 'the movie show page is loaded and a Review PORO is created', :vcr do
visit "/users/#{@user.id}/movies?search=#{@search_term}&commit=Find+Movies"

expect(page).to have_link("Die Hard 2")
click_on("Die Hard 2")
expect(page).to have_link('Die Hard 2')
click_on('Die Hard 2')

expect(page.status_code).to eq(200)
expect(page).to have_content("Review Author: talisencrw")
expect(page).to have_content("Review Text: Great fun re-watching this after checking out the original for the first time. One of the very best filmic franchises out there, to be sure.")
expect(page).to have_content('Review Author: talisencrw')
expect(page).to have_content('Review Text: Great fun re-watching this after checking out the original for the first time. One of the very best filmic franchises out there, to be sure.')
end
end
end
end
end
8 changes: 8 additions & 0 deletions spec/factories/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require 'faker'

FactoryBot.define do
factory :user do
name { Faker::Name.name }
email { Faker::Internet.email }
end
end
10 changes: 10 additions & 0 deletions spec/factories/viewing_party.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
require 'faker'

FactoryBot.define do
factory :viewing_party do
party_duration { Faker::Number.number(digits: 3) }
start_time { '12:00' }
movie_title { Faker::Movie.title }
movie_id { Faker::Number.number(digits: 3) }
end
end
8 changes: 4 additions & 4 deletions spec/features/movies/index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
click_link('Viewing Party Landing Page')
expect(current_path).to eq(root_path)
end

it "tests the 'Find Top Rated Movies' function", :vcr do
VCR.use_cassette('top_rated_movies') do
visit user_discover_path(@user.id)
Expand Down Expand Up @@ -50,11 +50,11 @@

expect(current_path).to eq("/users/#{@user.id}/movies")
expect(page).to have_content('Die Hard')
expect(page).to have_content('7.8')
expect(page).to have_content('7.')
expect(page).to have_content('A Good Day to Die Hard')
expect(page).to have_content('5.3')
expect(page).to have_content('5.')
expect(page).to have_content('Die Hard 2')
expect(page).to have_content('6.929')
expect(page).to have_content('6.')

expect(page).to have_button('Discover')
click_on('Discover')
Expand Down
2 changes: 1 addition & 1 deletion spec/features/movies/show_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
click_link('Viewing Party Landing Page')
expect(current_path).to eq(root_path)
end

it 'shows the details of a movie' do
VCR.use_cassette('Pulp Fiction') do
visit("/users/#{@user_1.id}/movies/680")
Expand Down
2 changes: 1 addition & 1 deletion spec/features/users/new_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
click_link('Viewing Party Landing Page')
expect(current_path).to eq(root_path)
end

it 'shows the fields to enter new user information' do
visit register_path
expect(page).to have_content('Register an Account')
Expand Down
2 changes: 1 addition & 1 deletion spec/features/viewing_parties/new_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
click_link('Viewing Party Landing Page')
expect(current_path).to eq(root_path)
end

it 'has a form to create a new viewing party', :vcr do
visit user_discover_path(@user_1.id)
click_button 'Find Top Rated Movies'
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Loading