From cf5d5a78e413e549784dca4b7c5de65e8df27d82 Mon Sep 17 00:00:00 2001 From: Allan Evans Date: Wed, 29 Nov 2023 16:54:02 -0700 Subject: [PATCH] Add creation of viewing parties and add the flag that shows which user is the host and which is the guest/attendee --- app/views/layouts/application.html.erb | 1 - app/views/viewing_parties/new.html.erb | 15 +++++++ config/routes.rb | 1 + spec/features/users/movies/show_spec.rb | 2 +- .../users/movies/viewing-party/new_spec.rb | 43 +++++++++++++++++++ 5 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 spec/features/users/movies/viewing-party/new_spec.rb diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 2ce9eb1c1..4810cad91 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -2,7 +2,6 @@ ViewingPartyLite7 - <%= link_to "Go to Landing Page", root_path, class: 'btn btn-primary' %> <%= csrf_meta_tags %> <%= csp_meta_tag %> diff --git a/app/views/viewing_parties/new.html.erb b/app/views/viewing_parties/new.html.erb index e69de29bb..3cc79764f 100644 --- a/app/views/viewing_parties/new.html.erb +++ b/app/views/viewing_parties/new.html.erb @@ -0,0 +1,15 @@ +

<%= @movie[:title] %>

+ +<%= form_with url: "/users/#{@user.id}/movies/#{@movie[:id]}/viewing-party/create", method: :post, local: true do |form| %> + <%= form.number_field :duration, value: @movie[:runtime], min: @movie[:runtime] %> + <%= form.label "Duration of Party in minutes" %> + <%= form.date_field :date, data: {provide: "datepicker"} %> + <%= form.label :date, "Date of Party" %> + <%= form.time_field :start_time %> + <%= form.label :start_time, "Start of Party" %> + <%= form.hidden_field :status, value: "host" %> + <% @users.each do |user| %> +

<%= check_box_tag(user.id, hidden_field: :status, value: "attending #{user.id}") %> <%= form.label "#{user.id}", "#{user.name} (#{user.email})" %>

+ <% end %>
+ <%= form.submit "Create Party" %> +<% end%> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 2272f6201..9a0cf2ab7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -12,4 +12,5 @@ end get "/users/:user_id/movies/:movid_id/viewing-party/new", to: "viewing_parties#new" + post "/users/:user_id/movies/:movid_id/viewing-party/create", to: "viewing_parties#create" end diff --git a/spec/features/users/movies/show_spec.rb b/spec/features/users/movies/show_spec.rb index ac0b1cf12..012cd362e 100644 --- a/spec/features/users/movies/show_spec.rb +++ b/spec/features/users/movies/show_spec.rb @@ -37,7 +37,7 @@ to_return(status: 200, body: reviews_response, headers: {}) visit "/users/#{@user1.id}/movies/268" - click_link "Go to Landing Page" + click_link "Go back to Landing Page" expect(current_path).to eq("/") visit "/users/#{@user1.id}/movies/268" diff --git a/spec/features/users/movies/viewing-party/new_spec.rb b/spec/features/users/movies/viewing-party/new_spec.rb new file mode 100644 index 000000000..805c949d7 --- /dev/null +++ b/spec/features/users/movies/viewing-party/new_spec.rb @@ -0,0 +1,43 @@ +require 'rails_helper' + +RSpec.describe 'New Viewing Party Page' do + before(:each) do + load_test_data + end + + it 'When I visit the new viewing party page it contains movie title, duration of party, when date, start time, checkboxes next to each user' do + specific_movie_response = File.read('spec/fixtures/specific_movie.json') + stub_request(:get, "https://api.themoviedb.org/3/movie/268?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: specific_movie_response, headers: {}) + + visit "/users/#{@user1.id}/movies/268/viewing-party/new" + expect(page).to have_field(:duration, with:126) + expect(page).to have_field(:date) + expect(page).to have_field(:start_time) + expect(page).to have_button('Create Party') + expect(page).to have_content('Batman') + + expect(@user2.user_parties.count).to eq(3) + expect(@user3.user_parties.count).to eq(2) + + fill_in :duration, with: 180 + fill_in :start_time, with: '10:00' + fill_in :date, with: '2023/08/01' + check "#{@user2.name} (#{@user2.email})" + check "#{@user3.name} (#{@user3.email})" + click_button 'Create Party' + + expect(current_path).to eq(user_path(@user1.id)) + # save_and_open_page + # expect(page).to have_content('Batman') + + # expect(@user2.user_parties.count).to eq(4) + # expect(@user3.user_parties.count).to eq(3) + end +end \ No newline at end of file