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/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