From 805a184c11da030cf133515b9968d925af7fe517 Mon Sep 17 00:00:00 2001 From: Blaine Kennedy Date: Wed, 29 Nov 2023 12:54:00 -0600 Subject: [PATCH 1/3] add feature for discover movies dashboard --- app/controllers/discover_controller.rb | 2 +- app/views/users/discover/index.html.erb | 1 + app/views/users/show.html.erb | 2 +- spec/features/users/discover/index_spec.rb | 50 +++++++++++++++++----- 4 files changed, 42 insertions(+), 13 deletions(-) create mode 100644 app/views/users/discover/index.html.erb diff --git a/app/controllers/discover_controller.rb b/app/controllers/discover_controller.rb index 6ef137b41..cac480693 100644 --- a/app/controllers/discover_controller.rb +++ b/app/controllers/discover_controller.rb @@ -1,5 +1,5 @@ class DiscoverController < ApplicationController def index - + @user = User.find(params[:user_id]) end end \ No newline at end of file diff --git a/app/views/users/discover/index.html.erb b/app/views/users/discover/index.html.erb new file mode 100644 index 000000000..46a668283 --- /dev/null +++ b/app/views/users/discover/index.html.erb @@ -0,0 +1 @@ +

Discover Movies for <%= @user.name %>

diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 965da8b24..35f17bbf1 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -1,6 +1,6 @@

<%= @user.name %>'s Dashboard!

-<%= button_to 'Discover Movies', user_discover_index_path(@user), class: 'btn btn-primary' %> +<%= button_to 'Discover Movies', user_discover_index_path(@user), method: :get, class: 'btn btn-primary' %>

Viewing Parties

diff --git a/spec/features/users/discover/index_spec.rb b/spec/features/users/discover/index_spec.rb index f6b5b7ea8..22feb3247 100644 --- a/spec/features/users/discover/index_spec.rb +++ b/spec/features/users/discover/index_spec.rb @@ -1,32 +1,60 @@ require 'rails_helper' -RSpec.describe 'Discover Movies Page' do +RSpec.describe 'Discover Movies Page' do before(:each) do load_test_data end - it 'When a user can get to movie results through movie title search' do + it 'redirects to discover page when "Discover Movies" button is clicked' do + visit user_path(@user1) + click_button 'Discover Movies' + + expect(current_path).to eq(user_discover_path(@user1)) + end + + it 'displays "Discover Top Rated Movies" and "Search by Movie Title" buttons on discover page' do + visit user_discover_index_path(@user1) + expect(page).to have_button('Discover Top Rated Movies') + expect(page).to have_button('Search by Movie Title') + end + + it 'redirects to movie results page when "Search by Movie Title" button is clicked' do + visit user_discover_index_path(@user1) + + fill_in 'Movie_Title', with: 'Batman' + click_button 'Search by Movie Title' + + expect(current_path).to eq(user_movies_path(@user1)) + end + it 'redirects to movie results page when "Discover Top Rated Movies" button is clicked' do + visit user_discover_index_path(@user1) + + click_button 'Discover Top Rated Movies' + + expect(current_path).to eq(user_movies_path(@user1)) + end + + it 'When a user can get to movie results through movie title search' do visit "/users/#{@user1.id}/discover" - - expect(page).to have_button("Discover Top Rated Movies") - expect(page).to have_button("Search by Movie Title") - fill_in 'Movie_Title', with: "Batman" + expect(page).to have_button('Discover Top Rated Movies') + expect(page).to have_button('Search by Movie Title') + + fill_in 'Movie_Title', with: 'Batman' # click_button "Search by Movie Title" # expect(current_path).to eq("/users/#{@user1.id}/movies") end it 'When a user can get to movie results through top rated movies button' do - visit "/users/#{@user1.id}/discover" - - expect(page).to have_button("Discover Top Rated Movies") - expect(page).to have_button("Search by Movie Title") + + expect(page).to have_button('Discover Top Rated Movies') + expect(page).to have_button('Search by Movie Title') # click_button "Discover Top Rated Movies" # expect(current_path).to eq("/users/#{@user1.id}/movies") end -end \ No newline at end of file +end From 7e01c96ce461c98acc40282cb0a20c531921733c Mon Sep 17 00:00:00 2001 From: Blaine Kennedy Date: Wed, 29 Nov 2023 17:27:56 -0600 Subject: [PATCH 2/3] add tests for dashboard discover movies and edit rubocop to ignore specs --- .rubocop.yml | 6 +++ spec/features/users/discover/index_spec.rb | 30 ----------- spec/features/users/movies/show_spec.rb | 58 ++++++++++++++++++++++ 3 files changed, 64 insertions(+), 30 deletions(-) create mode 100644 .rubocop.yml diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 000000000..4ec05cdc7 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,6 @@ +Style/FrozenStringLiteralComment: + Enabled: false + +Metrics/BlockLength: + IgnoredMethods: + - RSpec.describe \ No newline at end of file diff --git a/spec/features/users/discover/index_spec.rb b/spec/features/users/discover/index_spec.rb index 22feb3247..591c73d75 100644 --- a/spec/features/users/discover/index_spec.rb +++ b/spec/features/users/discover/index_spec.rb @@ -5,36 +5,6 @@ load_test_data end - it 'redirects to discover page when "Discover Movies" button is clicked' do - visit user_path(@user1) - click_button 'Discover Movies' - - expect(current_path).to eq(user_discover_path(@user1)) - end - - it 'displays "Discover Top Rated Movies" and "Search by Movie Title" buttons on discover page' do - visit user_discover_index_path(@user1) - expect(page).to have_button('Discover Top Rated Movies') - expect(page).to have_button('Search by Movie Title') - end - - it 'redirects to movie results page when "Search by Movie Title" button is clicked' do - visit user_discover_index_path(@user1) - - fill_in 'Movie_Title', with: 'Batman' - click_button 'Search by Movie Title' - - expect(current_path).to eq(user_movies_path(@user1)) - end - - it 'redirects to movie results page when "Discover Top Rated Movies" button is clicked' do - visit user_discover_index_path(@user1) - - click_button 'Discover Top Rated Movies' - - expect(current_path).to eq(user_movies_path(@user1)) - end - it 'When a user can get to movie results through movie title search' do visit "/users/#{@user1.id}/discover" diff --git a/spec/features/users/movies/show_spec.rb b/spec/features/users/movies/show_spec.rb index e69de29bb..1baee5fce 100644 --- a/spec/features/users/movies/show_spec.rb +++ b/spec/features/users/movies/show_spec.rb @@ -0,0 +1,58 @@ +RSpec.describe 'Discover Movies Page' do + before(:each) do + load_test_data + end + + it 'redirects to discover page when "Discover Movies" button is clicked' do + visit user_path(@user1) + click_button 'Discover Movies' + + expect(current_path).to eq(user_discover_index_path(@user1)) + end + + it 'displays "Discover Top Rated Movies" and "Search by Movie Title" buttons on discover page' do + visit user_discover_index_path(@user1) + expect(page).to have_button('Discover Top Rated Movies') + expect(page).to have_button('Search by Movie Title') + end + + it 'redirects to movie results page when "Search by Movie Title" button is clicked' do + batman_movie_response = File.read('spec/fixtures/batman_movies.json') + + stub_request(:get, "https://api.themoviedb.org/3/search/movie?api_key=#{Rails.application.credentials.tmdb[:key]}&query=Batman") + .with( + headers: { + 'Accept' => '*/*', + 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', + 'User-Agent' => 'Faraday v2.7.12' + } + ) + .to_return(status: 200, body: batman_movie_response, headers: {}) + visit user_discover_index_path(@user1) + + fill_in 'Movie_Title', with: 'Batman' + click_button 'Search by Movie Title' + + expect(current_path).to eq(user_movies_path(@user1)) + end + + it 'redirects to movie results page when "Discover Top Rated Movies" button is clicked' do + popular_movie_response = File.read('spec/fixtures/batman_movies.json') + + stub_request(:get, "https://api.themoviedb.org/3/movie/popular?api_key=#{Rails.application.credentials.tmdb[:key]}") + .with( + headers: { + 'Accept' => '*/*', + 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', + 'User-Agent' => 'Faraday v2.7.12' + } + ) + .to_return(status: 200, body: popular_movie_response, headers: {}) + + visit user_discover_index_path(@user1) + + click_button 'Discover Top Rated Movies' + + expect(current_path).to eq(user_movies_path(@user1)) + end +end From a4c69dca3e0321f09006b9a0a0b34903bb45fa3f Mon Sep 17 00:00:00 2001 From: Blaine Kennedy Date: Wed, 29 Nov 2023 17:32:33 -0600 Subject: [PATCH 3/3] fix tests for dashboard discover movies --- spec/features/users/movies/show_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/features/users/movies/show_spec.rb b/spec/features/users/movies/show_spec.rb index 1baee5fce..3e4dfada6 100644 --- a/spec/features/users/movies/show_spec.rb +++ b/spec/features/users/movies/show_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe 'Discover Movies Page' do +RSpec.describe 'Discover Movies Show Page Page' do before(:each) do load_test_data end