forked from turingschool-examples/viewing_party_lite_7
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from elizakeating/api_user_stories
Api user stories
- Loading branch information
Showing
21 changed files
with
837 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,39 @@ | ||
class MoviesController < ApplicationController | ||
def index | ||
|
||
end | ||
|
||
def search | ||
conn = Faraday.new(url: "https://api.themoviedb.org") do |faraday| | ||
faraday.params["api_key"] = Rails.application.credentials.tmdb[:key] | ||
end | ||
|
||
if params[:q] == "top20rated" | ||
response = conn.get("/3/movie/top_rated") | ||
|
||
json = JSON.parse(response.body, symbolize_names: true) | ||
@movies = json[:results][0..19] | ||
else | ||
response = conn.get("3/search/movie?query=#{params[:q]}") | ||
|
||
json = JSON.parse(response.body, symbolize_names: true) | ||
@movies = json[:results][0..19] | ||
end | ||
end | ||
|
||
def show | ||
conn = Faraday.new(url: "https://api.themoviedb.org") do |faraday| | ||
faraday.params["api_key"] = Rails.application.credentials.tmdb[:key] | ||
end | ||
|
||
response = conn.get("3/movie/#{params[:movie_id]}") | ||
@movie = JSON.parse(response.body, symbolize_names: true) | ||
|
||
response = conn.get("3/movie/#{params[:movie_id]}/credits") | ||
json = JSON.parse(response.body, symbolize_names: true) | ||
@movie_cast = json[:cast][0..9] | ||
|
||
response = conn.get("3/movie/#{params[:movie_id]}/reviews") | ||
json = JSON.parse(response.body, symbolize_names: true) | ||
@movie_reviews = json[:results] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class ViewingPartiesController < ApplicationController | ||
def new | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<h1>Discover Movies</h1> | ||
|
||
<%= button_to "Find Top Rated Movies", "/users/#{params[:id]}/movies", params: { q: "top20rated" }, method: :get %> | ||
|
||
<%= form_with url: "/users/#{params[:id]}/movies", method: :get, data: { turbo: false } do |form| %> | ||
<%= form.text_field :q, placeholder: "search" %> | ||
<%= form.submit "Find Movies" %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<%= button_to "Discover Page", "/users/#{params[:id]}/discover", method: :get %><br> | ||
|
||
<% if params[:q] != "top20rated" %> | ||
<h3>Movie results for: <%= params[:q] %></h3> | ||
<% end %> | ||
|
||
<% if @movies %> | ||
<% @movies.each do |movie| %> | ||
<section id=<%= movie[:id] %>> | ||
<%= link_to "#{movie[:title]}", "/users/#{params[:id]}/movies/#{movie[:id]}" %> | ||
<p>Vote Average: <%= movie[:vote_average] %></p> | ||
</section> | ||
<% end %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<h3><%= @movie[:original_title] %></h3> | ||
|
||
<%= button_to "Discover Page", "/users/#{params[:id]}/discover", method: :get %> | ||
|
||
<%= button_to "Create Viewing Party for #{@movie[:original_title]}", "/users/#{params[:id]}/movies/#{@movie[:id]}/viewing_party/new", method: :get %> | ||
|
||
<p>Vote: <%= @movie[:vote_average] %></p> | ||
<p>Runtime: <% if @movie[:runtime] > 60 %> | ||
<%= "#{@movie[:runtime]/60}h #{@movie[:runtime]-60}min" %> | ||
<% else %> | ||
<%= "#{@movie[:runtime]}min" %> | ||
<% end %> | ||
</p> | ||
<p>Genre: <% @movie[:genres].each do |genre| %> | ||
<% if genre != @movie[:genres].last %> | ||
<%= "#{genre[:name]}, " %> | ||
<% else %> | ||
<%= genre[:name] %> | ||
<% end %> | ||
<% end %> | ||
</p> | ||
|
||
<section id="summary"> | ||
<p>Summary</p> | ||
<p><%= @movie[:overview] %></p> | ||
</section> | ||
|
||
<section id="cast"> | ||
<p>Cast</p> | ||
<p> | ||
<% @movie_cast.each do |member| %> | ||
<p><%= member[:name] %> - <%= member[:character] %></p> | ||
<% end %> | ||
</p> | ||
</section> | ||
|
||
<p id="review-count"><%= @movie_reviews.count %> Reviews</p> | ||
<section id="reviews"> | ||
<p> | ||
<% @movie_reviews.each do |review| %> | ||
<p><%= review[:author] %> - <%= review[:content] %></p> | ||
<% end %> | ||
</p> | ||
</section> |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
IdUl8TW1RuV/hrFBOw2ofbe8+xWVzpTQtF36N+5vBKyWgaq4Juryc86xLP3lLDmJ8pVNpg/g8TYSAWeu+JUTlE4iCq31IZTknkB4BPLpz4ULj3UpYkEFRSB9ZdDufx9ccU4l+4GGtdv5KRqc105s0v09MDWYT+X6NHHUrFlSGepCEXzG7JuQziJCcYxDZccsb0qlsdcUnpWspc6GBBo451lm0YviUcWx3kNsSNqApQqtQENrruynV3UoKipateylgTlrUlOMbYyHIkY1daxdV4EcxSIF1mUy6UwciNIC9xa0WnAGb+oaki6mPvs+FpWz+o548lWRrz91opxNIBv8Zrh+ZwfnQVxByuI2Uqj4fYbETjhbRfu2IbjTk1sQGqZlgougYXtMmCTxe8PNP29bmaxa2s7r4i2dAb9P--jqBTwrKsjHULkBor--z3IhADU0xjCYptFz4QGfyw== | ||
+owmBR3rF4P0621XqrD/iFBz2sK+7l5bXHgBGAyYnDT46sUGU0LilI52AXhgQOh5vqfPItyNuq53hXXnWfIY9CVYu+3brUU0PJY3dCXuDF8YoWR8dMyXEjCk9ZMb5i0u/C9IB0WW8gNFUHDFz/k2yjVdcJ7PpdUcNOCrNUxGCOCJ2mrBcUZ2WmR0/SpYoDcdSnrZlK9uzLF6kfmHJ+L5qFhOOVdUx+2mCU/xnG+jDRX9tnExayneabKaUCLe4MaSIW92yI7+jZGKzEX7OtuclGitoAexLvva7pPlhUznPTwr4qo/0UB7/Ro4BThgJ/qOY20Xxz26Wu4WbXoRsXMu6etrSoOziYQv55ISthQdWl0jsViiH5W+TaTIRQZdb6w9oFb1dNOHlyO9fBgxoxRN1enBwJqdB2/uUCsH1tZyjLzzl+zlAaE74JY46tFzR4CTXTOnVtfEAnLbBCeIuFb8MgDxLNs=--Px4DqD+ikPBVl58Y--xFezR2XEGw59Uj9boaEZXw== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe "Movie Details Page", type: :feature do | ||
before(:each) do | ||
@user = User.create(name: "Brad", email: "bradsmith@gmail.com") | ||
end | ||
|
||
describe "when I visit a movie's detail page '/users/:id/movies/:movie_id'" do | ||
it "I should see a button to create a viewing party that takes me to '/users/:id/movies/:movie_id/viewing_party/new'" do | ||
VCR.use_cassette("barbie_details") do | ||
visit "/users/#{@user.id}/movies/346698" | ||
|
||
expect(page).to have_button("Create Viewing Party for Barbie") | ||
|
||
click_button "Create Viewing Party for Barbie" | ||
|
||
expect(current_path).to eq("/users/#{@user.id}/movies/346698/viewing_party/new") | ||
end | ||
end | ||
|
||
it "I should see a button to return to the discover page" do | ||
VCR.use_cassette("barbie_details") do | ||
visit "/users/#{@user.id}/movies/346698" | ||
|
||
expect(page).to have_button("Discover Page") | ||
|
||
click_button "Discover Page" | ||
|
||
expect(current_path).to eq("/users/#{@user.id}/discover") | ||
end | ||
end | ||
|
||
it "should have the move information including the title, vote average, runtime in hours and minutes, genre(s) associated to the movie, and a summary description" do | ||
VCR.use_cassette("barbie_details") do | ||
visit "/users/#{@user.id}/movies/346698" | ||
|
||
expect(page).to have_content("Barbie") | ||
expect(page).to have_content("Vote: 7.254") | ||
expect(page).to have_content("Runtime: 1h 54min") | ||
expect(page).to have_content("Genre: Comedy, Adventure, Fantasy") | ||
|
||
within("#summary") do | ||
expect(page).to have_content("Summary") | ||
expect(page).to have_content("Barbie and Ken are having the time of their lives in the colorful and seemingly perfect world of Barbie Land. However, when they get a chance to go to the real world, they soon discover the joys and perils of living among humans.") | ||
end | ||
end | ||
end | ||
|
||
it "should have a list of the first 10 cast members (characters&actress/actors)" do | ||
VCR.use_cassette("barbie_details") do | ||
visit "/users/#{@user.id}/movies/346698" | ||
within("#cast") do | ||
expect(page).to have_content("Cast") | ||
expect(page).to have_content("Margot Robbie - Barbie") | ||
expect(page).to have_content("Ryan Gosling - Ken") | ||
expect(page).to have_content("Issa Rae - Barbie") | ||
end | ||
end | ||
end | ||
|
||
it "should have a count of total reviews, and each review's author and information" do | ||
VCR.use_cassette("barbie_details") do | ||
visit "/users/#{@user.id}/movies/346698" | ||
|
||
within("#review-count") do | ||
expect(page).to have_content("11 Reviews") | ||
end | ||
|
||
within("#reviews") do | ||
expect(page).to have_content("Chris Sawin - _Barbie_ reels you in with its silly humor and fantastical ideas. The war of Kens during the last half hour of the film is an all-timer because a battle full of handsome maneuvers, like showing off their naked chest and manly noogies, turns into a full on dance off between Ryan Gosling and Simu Liu.\r \r But the second half of the film leaves a thought-provoking message in your brain regarding both men and women. The Kens gaining respect little by little mirrors how women eventually earned their rights to be respected individuals — after being considered as only being useful in the kitchen or for making babies — except with the gender roles reversed and nude blobs instead of genitalia.\r \r **Full review:** https://bit.ly/beachoff\n") | ||
|
||
expect(page).to have_content("Thulan Perera - Barbie presents a captivating cinematic journey, deftly utilizing an iconic doll to explore intricate gender dynamics. Guided by Greta Gerwig’s direction, Margot Robbie and Ryan Gosling offer standout performances, complemented by memorable songs and stunning set designs, creating an immersive and humorous experience. This thought-provoking film seamlessly weaves a commentary on equality into its dazzling visuals and catchy tunes, harmoniously blending humour and insight. The result is an unforgettable viewing adventure that engages, entertains, and resonates long after the credits roll.") | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe "Discover Movies Page" do | ||
before(:each) do | ||
@user = User.create(name: "Brad", email: "bradsmith@gmail.com") | ||
visit "/users/#{@user.id}/discover" | ||
end | ||
|
||
describe "when I visit '/users/:id/discover'" do | ||
it "should see a button to discover top rated movies that routes to `/users.:id/movies?q=top%20rated" do | ||
VCR.use_cassette("top_20_rated_movies") do | ||
expect(page).to have_content("Discover Movies") | ||
|
||
expect(page).to have_button "Find Top Rated Movies" | ||
|
||
click_button "Find Top Rated Movies" | ||
expect(current_path).to eq("/users/#{@user.id}/movies") | ||
end | ||
end | ||
|
||
it "should see a text field to enter keyword(s) to search by movie title and a button to submit that takes you to '/users/:user_id/movies?q=keyword" do | ||
VCR.use_cassette("barbie_movie_search") do | ||
expect(page).to have_field "search" | ||
|
||
expect(page).to have_button "Find Movies" | ||
|
||
fill_in "search", with: "barbie" | ||
click_button "Find Movies" | ||
|
||
expect(current_path).to eq("/users/#{@user.id}/movies") | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.