Skip to content

Commit

Permalink
Merge pull request #12 from aevans27/dashboard-viewing-parties-allan
Browse files Browse the repository at this point in the history
  • Loading branch information
bkchilidawg authored Dec 1, 2023
2 parents d94df44 + b6bb0b7 commit 331e27c
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 17 deletions.
25 changes: 15 additions & 10 deletions app/controllers/viewing_parties_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,23 @@ def create
@user = User.find(params[:user_id])
@users = User.where("id != #{params[:user_id]}")
@movie = facade.movie_details(params[:movid_id])
@party = @user.parties.new(movie_id: @movie[:id], movie_title: @movie[:title], duration: params[:duration], date: params[:date], start_time: params[:start_time])
if @party.save
@user.user_parties.create!(user_id: @user.id, party_id: @party.id, is_host: true)
@users.each do |other_user|
if params[:"#{other_user.id}"].present?
other_user.user_parties.create!(party_id: @party.id)
if @movie[:runtime].to_i > params[:duration].to_i
flash[:alert] = "Error: duration cannot be less that movie runtime"
redirect_to "/users/#{@user.id}/movies/#{@movie[:id]}/viewing-party/new"
else
@party = @user.parties.new(movie_id: @movie[:id], movie_title: @movie[:title], duration: params[:duration], date: params[:date], start_time: params[:start_time])
if @party.save
@user.user_parties.create!(user_id: @user.id, party_id: @party.id, is_host: true)
@users.each do |other_user|
if params[:"#{other_user.id}"].present?
other_user.user_parties.create!(party_id: @party.id)
end
end
redirect_to user_path(@user.id)
else
flash[:alert] = "Error: something is wrong with credentials"
redirect_to "/users/#{@user.id}/movies/#{@movie[:id]}/viewing-party/new"
end
redirect_to user_path(@user.id)
else
flash[:alert] = "Error: something is wrong with credentials"
redirect_to "/users/#{@user.id}/movies/#{@movie.id}/viewing-party/new"
end
end
end
50 changes: 43 additions & 7 deletions spec/features/users/movies/viewing-party/new_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
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')
starwars_response = File.read('spec/fixtures/starwars_collection.json')
lotr_response = File.read('spec/fixtures/lotr_collection.json')
Expand Down Expand Up @@ -36,7 +33,9 @@
'User-Agent'=>'Faraday v2.7.12'
}).
to_return(status: 200, body: specific_movie_response, headers: {})
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
visit "/users/#{@user1.id}/movies/268/viewing-party/new"
expect(page).to have_field(:duration, with:126)
expect(page).to have_field(:date)
Expand All @@ -55,10 +54,47 @@
click_button 'Create Party'

expect(current_path).to eq(user_path(@user1.id))
# save_and_open_page
# expect(page).to have_content('Batman')
end

it 'sad path for creating a party: Empty duration' do
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: ""
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("/users/#{@user1.id}/movies/268/viewing-party/new")
end

it 'sad path for creating a party: Bad duration' do
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: "2"
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(@user2.user_parties.count).to eq(4)
# expect(@user3.user_parties.count).to eq(3)
expect(current_path).to eq("/users/#{@user1.id}/movies/268/viewing-party/new")
end
end

0 comments on commit 331e27c

Please sign in to comment.