diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 000000000..da07aa685 Binary files /dev/null and b/.DS_Store differ diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb new file mode 100644 index 000000000..575ed1ddf --- /dev/null +++ b/app/controllers/users_controller.rb @@ -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 diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb new file mode 100644 index 000000000..e2ca715cc --- /dev/null +++ b/app/views/users/new.html.erb @@ -0,0 +1,17 @@ +

Register

+ +<%= form_for @user do |f| %> +
+ <%= f.label :name %> + <%= f.text_field :name, class: 'form-control' %> +
+
+ <%= f.label :email %> + <%= f.email_field :email, class: 'form-control' %> +
+
+ <%= f.label :password %> + <%= f.password_field :password, class: 'form-control' %> +
+ <%= f.submit 'Register', class: 'btn btn-primary' %> + <%end%> \ No newline at end of file diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb new file mode 100644 index 000000000..965da8b24 --- /dev/null +++ b/app/views/users/show.html.erb @@ -0,0 +1,8 @@ +

<%= @user.name %>'s Dashboard!

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

Viewing Parties

+ +
\ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index ea8474b5a..6cdc14541 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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] diff --git a/spec/features/users/new_spec.rb b/spec/features/users/new_spec.rb new file mode 100644 index 000000000..16d89c415 --- /dev/null +++ b/spec/features/users/new_spec.rb @@ -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 \ No newline at end of file diff --git a/spec/features/users/show_spec.rb b/spec/features/users/show_spec.rb new file mode 100644 index 000000000..93807d688 --- /dev/null +++ b/spec/features/users/show_spec.rb @@ -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