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/landing #22

Merged
merged 5 commits into from
Nov 30, 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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@

# Ignore master key for decrypting credentials and more.
/config/master.key


# Ignore coverage
/coverage
6 changes: 6 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Style/FrozenStringLiteralComment:
Enabled: false

Metrics/BlockLength:
IgnoredMethods:
- RSpec.describe
3 changes: 3 additions & 0 deletions app/controllers/landing_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class LandingController < ApplicationController

end
21 changes: 7 additions & 14 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
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 index
@users = User.all

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

def new
@user = User.create(user_params)
end

private

def user_params
params.require(:user).permit(:name, :email)
params.permit(:name, :email)
end
end
1 change: 1 addition & 0 deletions app/views/shared/_nav.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= link_to "Viewing Party Landing Page", root_path %>
1 change: 1 addition & 0 deletions app/views/users/discovers/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= render partial: "shared/nav" %>
8 changes: 8 additions & 0 deletions app/views/users/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<%= render partial: "shared/nav" %>

<p><%= button_to "New User", 'users/new' %></p>

<h3>User Index</h3>
<%@users.each do |user|%>
<%= link_to "#{user.name}", "users/#{user.id}"%>
<%end%>
2 changes: 2 additions & 0 deletions app/views/users/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<%= render partial: "shared/nav" %>

<h1><%="#{@user.name}'s Dashboard"%></h1>
<%= button_to "Discover Movies", user_discover_index_path(@user.id), method: :get, params: { enabled: false }, data: { turbo: false }, local: true %>

Expand Down
13 changes: 4 additions & 9 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
# frozen_string_literal: true

Rails.application.routes.draw do
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html

# Defines the root path route ("/")
# root "articles#index"

get '/register', to: 'users#new'
post '/register', to: 'users#create'

resources :users, only: [:index, :show] do
resources :discover, only: [:index], controller: 'users/discover'
end
get '/', to: 'users#index', as: :root
get 'users/:id', to: 'users#show'
post '/users/new', to: 'users#new', as: :new_user_path
get '/users/:id/discover', to: 'users/discovers#index', as: :user_discover
end
39 changes: 39 additions & 0 deletions spec/features/landing_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
require 'rails_helper'

RSpec.describe 'landing page', type: :feature do
# this test applies to all pages
it 'has a link to the landing page' do
visit '/'

expect(page).to have_link('Viewing Party Landing Page')
click_link('Viewing Party Landing Page')
expect(current_path).to eq(root_path)
end

it 'contains the name of the application' do
visit '/'

expect(page).to have_content('Viewing Party')
end

it 'has a button to create a new user' do
visit '/'

expect(page).to have_button('New User')
click_button('New User')
expect(current_path).to eq('/users/new')
end

it 'has a list of existing users' do
user_1 = User.create(name: 'Kam', email: 'kameron@turing.edu')
user_2 = User.create(name: 'Joseph', email: 'joseph@turing.edu')

visit '/'

expect(page).to have_content(user_1.name)
expect(page).to have_content(user_2.name)
expect(page).to have_link(user_1.name)
click_link(user_1.name)
expect(current_path).to eq("/users/#{user_1.id}")
end
end
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
require 'rails_helper'

RSpec.describe 'user dashboard page', type: :feature do
# this test applies to all pages
it 'has a link to the landing page' do
visit '/'

expect(page).to have_link('Viewing Party Landing Page')
click_link('Viewing Party Landing Page')
expect(current_path).to eq(root_path)
end

it 'lists the users name' do
user = User.create(name: 'Kam', email: 'kameronk013@gmail.com')

Expand Down