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

Feat/user registration #20

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
20 changes: 20 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
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)
end
end
11 changes: 11 additions & 0 deletions app/views/users/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<h1><u>Register an Account</u></h1>

<%= 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 %>
4 changes: 4 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
29 changes: 29 additions & 0 deletions spec/features/users/new_spec.rb
Original file line number Diff line number Diff line change
@@ -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")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work on this! I have received feedback not to use single character variables like x, but this is a really simple instance so I think we're ok.


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