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

User dashboard page #5

Merged
merged 2 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
Binary file added .DS_Store
Binary file not shown.
24 changes: 24 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class UsersController < ApplicationController
def new
@user = User.new
end

def create
@user = User.new(user_params)
if @user.save
redirect_to user_path(@user)
else
render :new
end
end

def show
@user = User.find(params[:id])
end

private

def user_params
params.require(:user).permit(:name, :email, :password)
end
end
17 changes: 17 additions & 0 deletions app/views/users/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<h1>Register</h1>

<%= form_for @user do |f| %>
<div class="form-group">
<%= f.label :name %>
<%= f.text_field :name, class: 'form-control' %>
</div>
<div class="form-group">
<%= f.label :email %>
<%= f.email_field :email, class: 'form-control' %>
</div>
<div class="form-group">
<%= f.label :password %>
<%= f.password_field :password, class: 'form-control' %>
</div>
<%= f.submit 'Register', class: 'btn btn-primary' %>
<%end%>
8 changes: 8 additions & 0 deletions app/views/users/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<h1><%= @user.name %>'s Dashboard!</h1>

<%= button_to 'Discover Movies', user_discover_index_path(@user), class: 'btn btn-primary' %>

<section class="viewing-parties">
<h2>Viewing Parties</h2>

</section>
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# Defines the root path route ("/")
# root "articles#index"
root 'home#index'
get '/register', to: 'users#new'

resources :users, only: [:new, :create, :show] do
resources :discover, only: [:index]
resources :movies, only: [:index, :show]
Expand Down
25 changes: 25 additions & 0 deletions spec/features/users/new_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require 'rails_helper'

RSpec.describe 'User Registration', type: :feature do
before(:each) do
load_test_data
end

it 'displays a registration form when visiting the "/register" path' do
visit '/register'
expect(page).to have_field('Name')
expect(page).to have_field('Email')
expect(page).to have_field('Password')
expect(page).to have_button('Register')
end

it 'redirects to the user dashboard page after successful registration' do
visit '/register'
fill_in 'Name', with: 'John Doe'
fill_in 'Email', with: 'john@example.com'
fill_in 'Password', with: 'Sooners!2022'
click_button 'Register'
user = User.find_by(email: 'john@example.com')
expect(current_path).to eq("/users/#{user.id}")
end
end
23 changes: 23 additions & 0 deletions spec/features/users/show_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require 'rails_helper'

RSpec.describe 'User show page', type: :feature do

before(:each) do
load_test_data
visit "/users/#{@user1.id}"
end

it "displays the user's name and 'Dashboard' at the top of the page" do
expect(page).to have_content("#{@user1.name}'s Dashboard")
end

it "displays a 'Discover Movies' button" do
expect(page).to have_button('Discover Movies')
end

it 'displays a section that lists viewing parties' do
within('section.viewing-parties') do
expect(page).to have_css('h2', text: 'Viewing Parties')
end
end
end