From 4639e8aaa711df02b1c004ccbe87bded2c38f49d Mon Sep 17 00:00:00 2001 From: Joseph Lee Date: Wed, 29 Nov 2023 09:20:09 -0700 Subject: [PATCH 1/2] add seed data --- app/controllers/users_controller.rb | 4 ++++ db/seeds.rb | 2 ++ 2 files changed, 6 insertions(+) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index b7fac1676..667a02086 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,5 +1,9 @@ class UsersController < ApplicationController + def index + end + def show + require 'pry'; binding.pry @user = User.find(params[:id]) end end diff --git a/db/seeds.rb b/db/seeds.rb index 0664d1be6..18700bda3 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -6,3 +6,5 @@ # # movies = Movie.create([{ name: "Star Wars" }, { name: "Lord of the Rings" }]) # Character.create(name: "Luke", movie: movies.first) + +user1 = User.create!(name: "Joseph Lee", email: "jlee230@turing.edu") \ No newline at end of file From cc75ba2f4649bbf8f22676c6b17561f0218e8aee Mon Sep 17 00:00:00 2001 From: Joseph Lee Date: Wed, 29 Nov 2023 10:38:41 -0700 Subject: [PATCH 2/2] write tests and finish user reg page --- app/controllers/users_controller.rb | 20 ++++++++++++++++++-- app/views/users/new.html.erb | 11 +++++++++++ config/routes.rb | 4 ++++ spec/features/users/new_spec.rb | 29 +++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 app/views/users/new.html.erb create mode 100644 spec/features/users/new_spec.rb diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 667a02086..3927ebebf 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,9 +1,25 @@ class UsersController < ApplicationController - def index + 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 - require 'pry'; binding.pry @user = User.find(params[:id]) end + + private + + def user_params + params.require(:user).permit(:name, :email) + end end diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb new file mode 100644 index 000000000..2b9690a91 --- /dev/null +++ b/app/views/users/new.html.erb @@ -0,0 +1,11 @@ +

Register an Account

+ +<%= form_with(model: @user, url: register_path, method: :post) do |form| %> + <%= form.label :name %> + <%= form.text_field :name %> + + <%= form.label :email %> + <%= form.email_field :email %> + + <%= form.submit 'Register' %> +<% end %> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 974358082..6d9e22a96 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -5,6 +5,10 @@ # 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 diff --git a/spec/features/users/new_spec.rb b/spec/features/users/new_spec.rb new file mode 100644 index 000000000..5bcf13b68 --- /dev/null +++ b/spec/features/users/new_spec.rb @@ -0,0 +1,29 @@ +require "rails_helper" + +describe "the User Registration Page" do + before(:each) do + + end + + it "shows the fields to enter new user information" do + visit register_path + expect(page).to have_content("Register an Account") + expect(page).to have_field("user[name]", type: "text") + expect(page).to have_field("user[email]", type: "email") + expect(page).to have_button("Register") + + fill_in "user[name]", with: "Thomas Smith" + fill_in "user[email]", with: "tsmith11@turing.edu" + + click_on("Register") + + x = User.find_by(name: "Thomas Smith") + + require 'pry'; binding.pry + expect(current_path).to eq(user_path(x.id)) + expect(page).to have_content("Thomas Smith's Dashboard") + expect(page).to have_content("Parties I'm Hosting") + expect(page).to have_content("Parties I'm Invited To") + expect(page).to have_button("Discover Movies") + end +end