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

Feat/dashboard discover movies #8

Merged
merged 4 commits into from
Nov 29, 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
6 changes: 6 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Style/FrozenStringLiteralComment:
Enabled: false

Metrics/BlockLength:
IgnoredMethods:
- RSpec.describe
2 changes: 1 addition & 1 deletion app/controllers/discover_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class DiscoverController < ApplicationController
def index

@user = User.find(params[:user_id])
end
end
1 change: 1 addition & 0 deletions app/views/users/discover/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>Discover Movies for <%= @user.name %></h1>
2 changes: 1 addition & 1 deletion app/views/users/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<h1><%= @user.name %>'s Dashboard!</h1>

<%= 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' %>

<section class="viewing-parties">
<h2>Viewing Parties</h2>
Expand Down
20 changes: 9 additions & 11 deletions spec/features/users/discover/index_spec.rb
Original file line number Diff line number Diff line change
@@ -1,32 +1,30 @@
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

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
end
60 changes: 56 additions & 4 deletions spec/features/users/movies/show_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,61 @@
require 'rails_helper'

RSpec.describe 'Movie Results' do
RSpec.describe 'Discover Movies Show 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

it 'When I go to a user dashbaord, and click "Discover Movies" button, I am redirected to a discover page /users/:id/discover' do
specific_movie_response = File.read('spec/fixtures/specific_movie.json')
credits_response = File.read('spec/fixtures/specific_movie_credits.json')
Expand Down Expand Up @@ -77,4 +129,4 @@
expect(page).to have_content("Name: Albert")
expect(page).to have_content("Rating: 4.0")
end
end
end