From d4933a93376ff7227ab08067ff26e870b0d608d8 Mon Sep 17 00:00:00 2001 From: Dalyl Feddal Date: Mon, 3 Feb 2025 15:26:09 +0100 Subject: [PATCH 01/14] condition in file mazer for login page, new route for connexion, design for session/new, session controler : layout -> mazer --- app/controllers/sessions_controller.rb | 2 +- app/views/layouts/mazer.html.erb | 53 ++++++++++++++++++++++++++ app/views/sessions/new.html.erb | 39 ++++++++++++++----- config/routes.rb | 7 ++++ 4 files changed, 90 insertions(+), 11 deletions(-) create mode 100644 app/views/layouts/mazer.html.erb diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 0112caaa..14e0984f 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -1,7 +1,7 @@ class SessionsController < ApplicationController allow_unauthenticated_access only: %i[ new create ] rate_limit to: 10, within: 3.minutes, only: :create, with: -> { redirect_to new_session_url, alert: "Try again later." } - + layout "mazer" def new end diff --git a/app/views/layouts/mazer.html.erb b/app/views/layouts/mazer.html.erb new file mode 100644 index 00000000..60e886c5 --- /dev/null +++ b/app/views/layouts/mazer.html.erb @@ -0,0 +1,53 @@ + + + + + + <%= content_for(:title) || "Skillrx" %> + + + + + <%= csrf_meta_tags %> + <%= csp_meta_tag %> + + <%= yield :head %> + + <%# Enable PWA manifest for installable apps (make sure to enable in config/routes.rb too!) %> + <%#= tag.link rel: "manifest", href: pwa_manifest_path(format: :json) %> + + + + + + + <%# Includes all stylesheet files in app/assets/stylesheets %> + <%= stylesheet_link_tag :app, "data-turbo-track": "reload" %> + <%= javascript_importmap_tags %> + + + + <% unless current_page?('/connexion') %> + <%= render "layouts/sidebar" %> + + <% end %> + <%= yield %> + + + + + <%= render "layouts/sidebar" %> + +
<%= yield %>
+ + + + + + + + + + + + diff --git a/app/views/sessions/new.html.erb b/app/views/sessions/new.html.erb index ce39e53b..3c464cc5 100644 --- a/app/views/sessions/new.html.erb +++ b/app/views/sessions/new.html.erb @@ -1,11 +1,30 @@ <%= tag.div(flash[:alert], style: "color:red") if flash[:alert] %> -<%= tag.div(flash[:notice], style: "color:green") if flash[:notice] %> - -<%= form_with url: session_path do |form| %> - <%= form.email_field :email, required: true, autofocus: true, autocomplete: "username", placeholder: "Enter your email address", value: params[:email] %>
- <%= form.password_field :password, required: true, autocomplete: "current-password", placeholder: "Enter your password", maxlength: 72 %>
- <%= form.submit "Sign in" %> -<% end %> -
- -<%= link_to "Forgot password?", new_password_path %> +<%= tag.div(flash[:notice], style: "color:green") if flash[:notice] %> +
+
+
+ +

Log in.

+

Log in with your data that you entered during registration.

+ <%= form_with url: session_path do |form| %> +
+ <%= form.email_field :email, required: true, class:'form-control form-control-xl', autofocus: true, autocomplete: "username", placeholder: "Enter your email address", value: params[:email] %>
+
+ +
+
+
+ <%= form.password_field :password, required: true, class:'form-control form-control-xl', autocomplete: "current-password", placeholder: "Enter your password", maxlength: 72 %>
+
+ +
+
+ <%= form.submit "Sign in", class:'btn btn-primary btn-block btn-lg shadow-lg mt-5'%> + <% end %> +
+

<%= link_to "Forgot password?",new_password_path, class:'font-bold'%>

+
+
+
+
\ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 525253cf..cbfa34dd 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -17,6 +17,13 @@ # Can be used by load balancers and uptime monitors to verify that the app is live. get "up" => "rails/health#show", as: :rails_health_check + # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html + get "connexion", to: "sessions#new" + + # Render dynamic PWA files from app/views/pwa/* (remember to link manifest in application.html.erb) + # get "manifest" => "rails/pwa#manifest", as: :pwa_manifest + # get "service-worker" => "rails/pwa#service_worker", as: :pwa_service_worker + resources :users # Defines the root path route ("/") root "home#index" end From 967e8098e251dcdc2349d6019c0a8e921bec2c9b Mon Sep 17 00:00:00 2001 From: Dalyl Feddal Date: Mon, 3 Feb 2025 15:45:37 +0100 Subject: [PATCH 02/14] add design for password, add route for reset password, add layout for password, condition in layout mazer --- app/controllers/passwords_controller.rb | 2 +- app/views/layouts/mazer.html.erb | 2 +- app/views/passwords/new.html.erb | 39 +++++++++++++++++++++---- app/views/sessions/new.html.erb | 2 +- config/routes.rb | 9 +++--- 5 files changed, 40 insertions(+), 14 deletions(-) diff --git a/app/controllers/passwords_controller.rb b/app/controllers/passwords_controller.rb index 189232cb..a3d77ad3 100644 --- a/app/controllers/passwords_controller.rb +++ b/app/controllers/passwords_controller.rb @@ -1,7 +1,7 @@ class PasswordsController < ApplicationController allow_unauthenticated_access before_action :set_user_by_token, only: %i[ edit update ] - + layout "mazer" def new end diff --git a/app/views/layouts/mazer.html.erb b/app/views/layouts/mazer.html.erb index 60e886c5..7360c631 100644 --- a/app/views/layouts/mazer.html.erb +++ b/app/views/layouts/mazer.html.erb @@ -27,7 +27,7 @@ - <% unless current_page?('/connexion') %> + <% unless current_page?('/connexion') || current_page?('/reset_password') %> <%= render "layouts/sidebar" %> <% end %> diff --git a/app/views/passwords/new.html.erb b/app/views/passwords/new.html.erb index ca121e04..bc830350 100644 --- a/app/views/passwords/new.html.erb +++ b/app/views/passwords/new.html.erb @@ -1,8 +1,35 @@ -

Forgot your password?

- <%= tag.div(flash[:alert], style: "color:red") if flash[:alert] %> -<%= form_with url: passwords_path do |form| %> - <%= form.email_field :email, required: true, autofocus: true, autocomplete: "username", placeholder: "Enter your email address", value: params[:email] %>
- <%= form.submit "Email reset instructions" %> -<% end %> +
+
+
+ +

Forgot Password

+

Input your email and we will send you reset password link.

+ + <%= form_with url: passwords_path do |form| %> +
+ <%= form.email_field :email, required: true, class:'form-control form-control-xl', autofocus: true, autocomplete: "username", placeholder: "Enter your email address", value: params[:email] %>
+ +
+ +
+
+ + <%= form.submit "Email reset instructions", class:'btn btn-primary btn-block btn-lg shadow-lg mt-5'%> + <%end%> + +
+

Remember your account? <%= link_to "Login",connexion_path, class:'font-bold'%> +

+
+
+
+
+
+ +
+
+
\ No newline at end of file diff --git a/app/views/sessions/new.html.erb b/app/views/sessions/new.html.erb index 3c464cc5..a725a936 100644 --- a/app/views/sessions/new.html.erb +++ b/app/views/sessions/new.html.erb @@ -23,7 +23,7 @@ <%= form.submit "Sign in", class:'btn btn-primary btn-block btn-lg shadow-lg mt-5'%> <% end %>
-

<%= link_to "Forgot password?",new_password_path, class:'font-bold'%>

+

<%= link_to "Forgot password?",reset_password_path, class:'font-bold'%>

diff --git a/config/routes.rb b/config/routes.rb index cbfa34dd..a0967d65 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,7 +1,7 @@ Rails.application.routes.draw do # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html resource :session - resources :passwords, param: :token + resources :passwords, except: [:new], param: :token resources :users, only: :create resource :registration, only: %i[new create] resources :regions @@ -12,14 +12,13 @@ # get "manifest" => "rails/pwa#manifest", as: :pwa_manifest # get "service-worker" => "rails/pwa#service_worker", as: :pwa_service_worker get "home/index", as: :home - + # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html + get "connexion", to: "sessions#new" + get 'reset_password', to:"passwords#new" # Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500. # Can be used by load balancers and uptime monitors to verify that the app is live. get "up" => "rails/health#show", as: :rails_health_check - # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html - get "connexion", to: "sessions#new" - # Render dynamic PWA files from app/views/pwa/* (remember to link manifest in application.html.erb) # get "manifest" => "rails/pwa#manifest", as: :pwa_manifest # get "service-worker" => "rails/pwa#service_worker", as: :pwa_service_worker From f3f9cb5e89dbf5fc7e21e0e61ce522e580e2decc Mon Sep 17 00:00:00 2001 From: Dalyl F Date: Mon, 3 Feb 2025 16:57:09 +0100 Subject: [PATCH 03/14] view user and method crud, not finished --- app/controllers/users_controller.rb | 14 ++++++++++++ app/views/users/index.html.erb | 35 +++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 3004a556..ffc403b6 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,4 +1,18 @@ class UsersController < ApplicationController + layout "mazer" def index + @users = User.all + #users = User.all + end + + def create + end + def new + end + def edit + end + def destroy + end + end diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index e69de29b..d98cbce5 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -0,0 +1,35 @@ +

User list

+ +
+
+
+
+
+ Simple Datatable +
+
+
+ + + + + + + + + + <% @users.each do |user| %> + + + + + + <% end %> + +
EmailAdministrator
<%= user.email %> <%= user.is_admin %>
+
+
+
+
+ + From 413e1c223376e7a41af645cbe8c0319d977d9d71 Mon Sep 17 00:00:00 2001 From: Dalyl F Date: Mon, 3 Feb 2025 17:08:47 +0100 Subject: [PATCH 04/14] removed local config, removed layout, fix design user list --- app/controllers/users_controller.rb | 4 ++-- app/views/users/index.html.erb | 5 ----- config/database.yml | 1 - 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index ffc403b6..50036ea1 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,12 +1,12 @@ class UsersController < ApplicationController - layout "mazer" def index @users = User.all #users = User.all - + end def create + end def new end diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index d98cbce5..88407089 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -3,11 +3,6 @@
-
-
- Simple Datatable -
-
diff --git a/config/database.yml b/config/database.yml index 5e0be171..ea0714dc 100644 --- a/config/database.yml +++ b/config/database.yml @@ -19,7 +19,6 @@ default: &default # https://guides.rubyonrails.org/configuring.html#database-pooling pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> - development: <<: *default database: skillrx_development From b34134ceef292bbe309c49219ea076545931abec Mon Sep 17 00:00:00 2001 From: Dalyl F Date: Tue, 4 Feb 2025 10:57:39 +0100 Subject: [PATCH 05/14] add user crud action --- app/controllers/sessions_controller.rb | 4 +-- app/controllers/users_controller.rb | 36 ++++++++++++++++++++++++ app/views/layouts/_sidebar.html.erb | 5 ++++ app/views/layouts/mazer.html.erb | 5 ++-- app/views/users/_form.html.erb | 38 ++++++++++++++++++++++++++ app/views/users/edit.html.erb | 10 +++++++ app/views/users/index.html.erb | 12 +++++++- app/views/users/new.html.erb | 23 ++++++++++++++++ config/routes.rb | 8 ++++-- spec/models/user_spec.rb | 8 ++++++ 10 files changed, 140 insertions(+), 9 deletions(-) create mode 100644 app/views/users/_form.html.erb create mode 100644 app/views/users/edit.html.erb create mode 100644 app/views/users/new.html.erb create mode 100644 spec/models/user_spec.rb diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 14e0984f..8f383f08 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -10,12 +10,12 @@ def create start_new_session_for user redirect_to after_authentication_url else - redirect_to new_session_path, alert: "Try another email address or password." + redirect_to connexion_path, alert: "Try another email address or password." end end def destroy terminate_session - redirect_to new_session_path + redirect_to connexion_path end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 50036ea1..33a6dc77 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,4 +1,6 @@ class UsersController < ApplicationController + before_action :set_user, only: %i[ edit update destroy ] + def index @users = User.all #users = User.all @@ -6,13 +8,47 @@ def index end def create + @user = User.new(user_params) + respond_to do |format| + if @user.save + format.html { redirect_to users_path, notice: "User was successfully created." } + else + format.html { render :new, status: :unprocessable_entity } + end + end end + + def new + @user = User.new end def edit end + + def update + respond_to do |format| + if @user.update(user_params) + format.html { redirect_to users_path, notice: "User was successfully updated." } + else + format.html { render :edit, status: :unprocessable_entity } + end + end + end def destroy + @user.destroy! + + respond_to do |format| + format.html { redirect_to users_path, status: :see_other, notice: "User was successfully destroyed." } + end + end + + private + def set_user + @user = User.find(params.expect(:id)) end + def user_params + params.expect(user: [:email, :password, :is_admin]) + end end diff --git a/app/views/layouts/_sidebar.html.erb b/app/views/layouts/_sidebar.html.erb index 47f5728a..c3dae704 100644 --- a/app/views/layouts/_sidebar.html.erb +++ b/app/views/layouts/_sidebar.html.erb @@ -72,8 +72,13 @@ <% end %> +<<<<<<< HEAD
- + @@ -18,6 +20,14 @@ + <% end %> diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb new file mode 100644 index 00000000..f4b76e71 --- /dev/null +++ b/app/views/users/new.html.erb @@ -0,0 +1,23 @@ +<% content_for :title, "New user" %> + +
+
+
+
+
+

Create New User

+
+
+
+

User should ... Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut + labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip + ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla + pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est + laborum.

+ <%= render "form", user: @user %> +
+
+
+
+
+
diff --git a/config/routes.rb b/config/routes.rb index a0967d65..31bc3918 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,8 +1,10 @@ Rails.application.routes.draw do - # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html - resource :session + resources :providers + resources :regions + root "home#index" + get "home/index", as: :home + resource :session, except:[:new] resources :passwords, except: [:new], param: :token - resources :users, only: :create resource :registration, only: %i[new create] resources :regions resources :providers diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb new file mode 100644 index 00000000..931bb04f --- /dev/null +++ b/spec/models/user_spec.rb @@ -0,0 +1,8 @@ +require 'rails_helper' + +RSpec.describe User, type: :model do + subject { create(:user) } + it { should validate_presence_of(:email) } + it { should validate_presence_of(:password) } + it { should validate_uniqueness_of(:email).ignoring_case_sensitivity } +end From c1bee51307d8b6e1c3775d53148832850b5fb906 Mon Sep 17 00:00:00 2001 From: Dalyl F Date: Tue, 4 Feb 2025 11:26:08 +0100 Subject: [PATCH 06/14] add faker, add faker email, add test users --- app/models/user.rb | 2 +- spec/requests/users_spec.rb | 124 ++++++++++++++++++++++++++++++++++++ 2 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 spec/requests/users_spec.rb diff --git a/app/models/user.rb b/app/models/user.rb index a4cd542f..03cda4bc 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -4,6 +4,6 @@ class User < ApplicationRecord normalizes :email, with: ->(e) { e.strip.downcase } - validates :email, presence: true, uniqueness: true + validates :email, presence: true, uniqueness: true,format: URI::MailTo::EMAIL_REGEXP validates :password_digest, presence: true end diff --git a/spec/requests/users_spec.rb b/spec/requests/users_spec.rb new file mode 100644 index 00000000..0d5c391b --- /dev/null +++ b/spec/requests/users_spec.rb @@ -0,0 +1,124 @@ +require 'rails_helper' + +# This spec was generated by rspec-rails when you ran the scaffold generator. +# It demonstrates how one might use RSpec to test the controller code that +# was generated by Rails when you ran the scaffold generator. +# +# It assumes that the implementation code is generated by the rails scaffold +# generator. If you are using any extension libraries to generate different +# controller code, this generated spec may or may not pass. +# +# It only uses APIs available in rails and/or rspec-rails. There are a number +# of tools you can use to make these specs even more expressive, but we're +# sticking to rails and rspec-rails APIs to keep things simple and stable. + +RSpec.describe "/users", type: :request do + let(:user) { create(:user) } + + include AuthHelper + + before do + sign_in(user) + end + + # This should return the minimal set of attributes required to create a valid + # User. As you add validations to User, be sure to + # adjust the attributes here as well. + let(:valid_attributes) { { email: "john@doe.com" , password:"123"} } + + let(:invalid_attributes) { { email: "" } } + + describe "GET /index" do + it "renders a successful response" do + user = FactoryBot.create(:user) + get users_url + expect(response).to be_successful + end + end + + describe "GET /new" do + it "renders a successful response" do + get new_user_url + expect(response).to be_successful + end + end + + describe "GET /edit" do + it "renders a successful response" do + user = FactoryBot.create(:user) + get edit_user_url(user) + expect(response).to be_successful + end + end + + describe "POST /create" do + context "with valid parameters" do + it "creates a new user" do + expect { + post users_url, params: { user: valid_attributes } + }.to change(User, :count).by(1) + end + + it "redirects to the user index" do + post users_url, params: { user: valid_attributes } + expect(response).to redirect_to(users_path) + end + end + + context "with invalid parameters" do + it "does not create a new User" do + expect { + post users_url, params: { user: invalid_attributes } + }.to change(User, :count).by(0) + end + + it "renders a response with 422 status (i.e. to display the 'new' template)" do + post users_url, params: { user: invalid_attributes } + expect(response).to have_http_status(:unprocessable_entity) + end + end + end + + describe "PATCH /update" do + context "with valid parameters" do + let(:new_attributes) { { email: "john@doe.com" } } + + it "updates the requested user" do + user = User.create! valid_attributes + patch user_url(user), params: { user: new_attributes } + user.reload + expect(user.email).to eq("john@doe.com") + end + + it "redirects to the user" do + user = User.create! valid_attributes + patch user_url(user), params: { user: new_attributes } + user.reload + expect(response).to redirect_to(users_url) + end + end + + context "with invalid parameters" do + it "renders a response with 422 status (i.e. to display the 'edit' template)" do + user = User.create! valid_attributes + patch user_url(user), params: { user: invalid_attributes } + expect(response).to have_http_status(:unprocessable_entity) + end + end + end + + describe "DELETE /destroy" do + it "destroys the requested user" do + user = User.create! valid_attributes + expect { + delete user_url(user) + }.to change(User, :count).by(-1) + end + + it "redirects to the users list" do + user = User.create! valid_attributes + delete user_url(user) + expect(response).to redirect_to(users_url) + end + end +end From 4c57f487d14e86fe840c39b3bb65a644385acf28 Mon Sep 17 00:00:00 2001 From: Dalyl F Date: Tue, 4 Feb 2025 11:45:19 +0100 Subject: [PATCH 07/14] fix design button edit and delete --- app/views/users/index.html.erb | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index d923b57e..3c15aa7a 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -20,16 +20,17 @@ - <% end %> +
Email Administrator Users actions
<%= user.email %> <%= user.is_admin %> + + <%= link_to edit_user_path(user), class: "btn btn-secondary btn-sm" do %> + Edit + <% end %> + <%= button_to user, data: { confirm: "Are you sure?" }, method: :delete, class: "btn btn-danger btn-sm" do %> + Delete + <% end %>
<%= user.email %> <%= user.is_admin %> - - <%= link_to edit_user_path(user), class: "btn btn-secondary btn-sm" do %> - Edit - <% end %> - <%= button_to user, data: { confirm: "Are you sure?" }, method: :delete, class: "btn btn-danger btn-sm" do %> - Delete - <% end %> + + <%= link_to edit_user_path(user), class: "btn btn-secondary btn-sm pr-2" do %> + Edit + <% end %> + <%= button_to user, data: { confirm: "Are you sure?" }, method: :delete,form_class:"d-inline", class: "btn btn-danger btn-sm " do %> + Delete + <% end %> +
From 7279012cf28d428db0f13c5e62d03df5c6bd9c4f Mon Sep 17 00:00:00 2001 From: Dalyl F Date: Tue, 4 Feb 2025 11:52:07 +0100 Subject: [PATCH 08/14] fix rubocop --- app/controllers/users_controller.rb | 4 +--- app/models/user.rb | 2 +- config/routes.rb | 6 +++--- spec/requests/users_spec.rb | 2 +- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 33a6dc77..f5758f0b 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -3,8 +3,6 @@ class UsersController < ApplicationController def index @users = User.all - #users = User.all - end def create @@ -49,6 +47,6 @@ def set_user end def user_params - params.expect(user: [:email, :password, :is_admin]) + params.expect(user: [ :email, :password, :is_admin ]) end end diff --git a/app/models/user.rb b/app/models/user.rb index 03cda4bc..bd0f7a58 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -4,6 +4,6 @@ class User < ApplicationRecord normalizes :email, with: ->(e) { e.strip.downcase } - validates :email, presence: true, uniqueness: true,format: URI::MailTo::EMAIL_REGEXP + validates :email, presence: true, uniqueness: true, format: URI::MailTo::EMAIL_REGEXP validates :password_digest, presence: true end diff --git a/config/routes.rb b/config/routes.rb index 31bc3918..c2a06b19 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,8 +3,8 @@ resources :regions root "home#index" get "home/index", as: :home - resource :session, except:[:new] - resources :passwords, except: [:new], param: :token + resource :session, except: [ :new ] + resources :passwords, except: [ :new ], param: :token resource :registration, only: %i[new create] resources :regions resources :providers @@ -16,7 +16,7 @@ get "home/index", as: :home # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html get "connexion", to: "sessions#new" - get 'reset_password', to:"passwords#new" + get "reset_password", to: "passwords#new" # Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500. # Can be used by load balancers and uptime monitors to verify that the app is live. get "up" => "rails/health#show", as: :rails_health_check diff --git a/spec/requests/users_spec.rb b/spec/requests/users_spec.rb index 0d5c391b..2da58957 100644 --- a/spec/requests/users_spec.rb +++ b/spec/requests/users_spec.rb @@ -24,7 +24,7 @@ # This should return the minimal set of attributes required to create a valid # User. As you add validations to User, be sure to # adjust the attributes here as well. - let(:valid_attributes) { { email: "john@doe.com" , password:"123"} } + let(:valid_attributes) { { email: "john@doe.com", password: "123" } } let(:invalid_attributes) { { email: "" } } From d5a0b87a4ebc2ed2c7b20cdd16ce17953d0e68df Mon Sep 17 00:00:00 2001 From: Dalyl F Date: Tue, 4 Feb 2025 12:00:52 +0100 Subject: [PATCH 09/14] fix rubocop --- spec/models/user_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 931bb04f..8da5f374 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe User, type: :model do subject { create(:user) } From 610511759e4838e6cbbe4bfaa9a0da60be570977 Mon Sep 17 00:00:00 2001 From: Dalyl F Date: Tue, 4 Feb 2025 12:04:50 +0100 Subject: [PATCH 10/14] remove AuthHelper --- spec/requests/users_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/requests/users_spec.rb b/spec/requests/users_spec.rb index 2da58957..f3b3e6cb 100644 --- a/spec/requests/users_spec.rb +++ b/spec/requests/users_spec.rb @@ -15,7 +15,6 @@ RSpec.describe "/users", type: :request do let(:user) { create(:user) } - include AuthHelper before do sign_in(user) From 488517e9362a3b64ce69156bdebf2733aefefd87 Mon Sep 17 00:00:00 2001 From: Dalyl F Date: Tue, 4 Feb 2025 12:06:07 +0100 Subject: [PATCH 11/14] fix rubocop --- spec/requests/users_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/requests/users_spec.rb b/spec/requests/users_spec.rb index f3b3e6cb..6982c335 100644 --- a/spec/requests/users_spec.rb +++ b/spec/requests/users_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require "rails_helper" # This spec was generated by rspec-rails when you ran the scaffold generator. # It demonstrates how one might use RSpec to test the controller code that From 0251abc5bb4f25986b959756325509365b7d1370 Mon Sep 17 00:00:00 2001 From: Olivia Bonnal Date: Tue, 4 Feb 2025 12:49:50 +0000 Subject: [PATCH 12/14] Implement style changes This commit removes/adds spaces where needed, removes unnecessary comments and changes to link_to in the sidebar. There are still some other in the sidebar that I haven't changed yet as other people are in the process of adding routes to these pages (Topics and Languages). --- app/controllers/users_controller.rb | 10 ++++++---- app/views/layouts/_sidebar.html.erb | 11 +++-------- spec/requests/users_spec.rb | 22 ++-------------------- 3 files changed, 11 insertions(+), 32 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index f5758f0b..16aed061 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -5,6 +5,10 @@ def index @users = User.all end + def new + @user = User.new + end + def create @user = User.new(user_params) @@ -17,10 +21,6 @@ def create end end - - def new - @user = User.new - end def edit end @@ -33,6 +33,7 @@ def update end end end + def destroy @user.destroy! @@ -42,6 +43,7 @@ def destroy end private + def set_user @user = User.find(params.expect(:id)) end diff --git a/app/views/layouts/_sidebar.html.erb b/app/views/layouts/_sidebar.html.erb index c3dae704..89ac0ea1 100644 --- a/app/views/layouts/_sidebar.html.erb +++ b/app/views/layouts/_sidebar.html.erb @@ -1,4 +1,4 @@ - +