From bd311df1eedbfb061ebcbb23c92f148306f40fa2 Mon Sep 17 00:00:00 2001 From: Kam Kennedy Date: Wed, 29 Nov 2023 10:24:14 -0700 Subject: [PATCH 1/3] progress on landing page --- .rubocop.yml | 6 +++++ app/controllers/landing_controller.rb | 3 +++ app/controllers/users_controller.rb | 14 ++++++++++ app/views/users/index.html.erb | 3 +++ config/routes.rb | 6 ++--- spec/features/landing_spec.rb | 39 +++++++++++++++++++++++++++ spec/features/user_dashboard_spec.rb | 9 +++++++ 7 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 .rubocop.yml create mode 100644 app/controllers/landing_controller.rb create mode 100644 app/views/users/index.html.erb create mode 100644 spec/features/landing_spec.rb diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 000000000..2aca9d06e --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,6 @@ +Style/FrozenStringLiteralComment: + Enabled: false + +Metrics/BlockLength: + IgnoredMethods: + - RSpec.describe \ No newline at end of file diff --git a/app/controllers/landing_controller.rb b/app/controllers/landing_controller.rb new file mode 100644 index 000000000..875912fe2 --- /dev/null +++ b/app/controllers/landing_controller.rb @@ -0,0 +1,3 @@ +class LandingController < ApplicationController + +end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index b7fac1676..c3b7c05c9 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,5 +1,19 @@ class UsersController < ApplicationController + def index + @users = User.all + end + def show @user = User.find(params[:id]) end + + def new + @user = User.create(user_params) + end + + private + + def user_params + params.permit(:name, :email) + end end diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb new file mode 100644 index 000000000..ceb8bd09b --- /dev/null +++ b/app/views/users/index.html.erb @@ -0,0 +1,3 @@ +<%= link_to "Viewing Party Landing Page", root_path %> + +<%= button_to "New User", 'users/new' %> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index a99f5f4dc..0982296dc 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,10 +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 "users/:id", to: "users#show" + 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 diff --git a/spec/features/landing_spec.rb b/spec/features/landing_spec.rb new file mode 100644 index 000000000..f1208688c --- /dev/null +++ b/spec/features/landing_spec.rb @@ -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(user_path(user_1.id)) + end +end diff --git a/spec/features/user_dashboard_spec.rb b/spec/features/user_dashboard_spec.rb index c54d63e99..a90177f36 100644 --- a/spec/features/user_dashboard_spec.rb +++ b/spec/features/user_dashboard_spec.rb @@ -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') From 07a0f422449390fc0a11517f5876dc63781575a2 Mon Sep 17 00:00:00 2001 From: Kam Kennedy Date: Wed, 29 Nov 2023 10:27:39 -0700 Subject: [PATCH 2/3] all tests passing --- app/views/users/index.html.erb | 7 ++++++- spec/features/landing_spec.rb | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index ceb8bd09b..3dca6a83f 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -1,3 +1,8 @@ <%= link_to "Viewing Party Landing Page", root_path %> -<%= button_to "New User", 'users/new' %> \ No newline at end of file +<%= button_to "New User", 'users/new' %> + +

User Index

+<%@users.each do |user|%> + <%= link_to "#{user.name}", "users/#{user.id}"%> +<%end%> \ No newline at end of file diff --git a/spec/features/landing_spec.rb b/spec/features/landing_spec.rb index f1208688c..6043ddb06 100644 --- a/spec/features/landing_spec.rb +++ b/spec/features/landing_spec.rb @@ -9,7 +9,7 @@ click_link('Viewing Party Landing Page') expect(current_path).to eq(root_path) end - + it 'contains the name of the application' do visit '/' @@ -34,6 +34,6 @@ 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(user_path(user_1.id)) + expect(current_path).to eq("/users/#{user_1.id}") end end From f55ddb677775eebaa6bafc2df2bd0cf2f1153cfb Mon Sep 17 00:00:00 2001 From: Kam Kennedy Date: Wed, 29 Nov 2023 11:06:45 -0700 Subject: [PATCH 3/3] add partial for link to root --- app/views/shared/_nav.html.erb | 1 + app/views/users/discovers/index.html.erb | 1 + app/views/users/index.html.erb | 4 ++-- app/views/users/show.html.erb | 2 ++ spec/features/{user_dashboard_spec.rb => users/show_spec.rb} | 0 5 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 app/views/shared/_nav.html.erb rename spec/features/{user_dashboard_spec.rb => users/show_spec.rb} (100%) diff --git a/app/views/shared/_nav.html.erb b/app/views/shared/_nav.html.erb new file mode 100644 index 000000000..e680794f6 --- /dev/null +++ b/app/views/shared/_nav.html.erb @@ -0,0 +1 @@ +<%= link_to "Viewing Party Landing Page", root_path %> \ No newline at end of file diff --git a/app/views/users/discovers/index.html.erb b/app/views/users/discovers/index.html.erb index e69de29bb..154edd52b 100644 --- a/app/views/users/discovers/index.html.erb +++ b/app/views/users/discovers/index.html.erb @@ -0,0 +1 @@ +<%= render partial: "shared/nav" %> \ No newline at end of file diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index 3dca6a83f..528da404a 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -1,6 +1,6 @@ -<%= link_to "Viewing Party Landing Page", root_path %> +<%= render partial: "shared/nav" %> -<%= button_to "New User", 'users/new' %> +

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

User Index

<%@users.each do |user|%> diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 21f579081..d3c1acecc 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -1,3 +1,5 @@ +<%= render partial: "shared/nav" %> +

<%="#{@user.name}'s Dashboard"%>

<%= button_to "Discover Movies", user_discover_path(@user.id), method: :get, params: { enabled: false }, data: { turbo: false }, local: true %> diff --git a/spec/features/user_dashboard_spec.rb b/spec/features/users/show_spec.rb similarity index 100% rename from spec/features/user_dashboard_spec.rb rename to spec/features/users/show_spec.rb