From a626c004edffa98c32e3a7e4c6c4bf5172b7772f Mon Sep 17 00:00:00 2001 From: Alexander Jamshidi Date: Mon, 7 Feb 2022 13:02:28 +0000 Subject: [PATCH 01/56] deleted gem lock file and updated rails version in gemfile to 6.1 --- Gemfile | 2 +- Gemfile.lock | 204 ++++++++++++++++++++++++++------------------------- 2 files changed, 105 insertions(+), 101 deletions(-) diff --git a/Gemfile b/Gemfile index cc33a496eb..7538b9b25a 100644 --- a/Gemfile +++ b/Gemfile @@ -7,7 +7,7 @@ end # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' -gem 'rails', '~> 6.0.0' +gem 'rails', '~> 6.1.0' # Use postgresql as the database for Active Record gem 'pg' # Use Puma as the app server diff --git a/Gemfile.lock b/Gemfile.lock index d68ece3372..142d8f4925 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,62 +1,66 @@ GEM remote: https://rubygems.org/ specs: - actioncable (6.0.3.4) - actionpack (= 6.0.3.4) + actioncable (6.1.4.4) + actionpack (= 6.1.4.4) + activesupport (= 6.1.4.4) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailbox (6.0.3.4) - actionpack (= 6.0.3.4) - activejob (= 6.0.3.4) - activerecord (= 6.0.3.4) - activestorage (= 6.0.3.4) - activesupport (= 6.0.3.4) + actionmailbox (6.1.4.4) + actionpack (= 6.1.4.4) + activejob (= 6.1.4.4) + activerecord (= 6.1.4.4) + activestorage (= 6.1.4.4) + activesupport (= 6.1.4.4) mail (>= 2.7.1) - actionmailer (6.0.3.4) - actionpack (= 6.0.3.4) - actionview (= 6.0.3.4) - activejob (= 6.0.3.4) + actionmailer (6.1.4.4) + actionpack (= 6.1.4.4) + actionview (= 6.1.4.4) + activejob (= 6.1.4.4) + activesupport (= 6.1.4.4) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (6.0.3.4) - actionview (= 6.0.3.4) - activesupport (= 6.0.3.4) - rack (~> 2.0, >= 2.0.8) + actionpack (6.1.4.4) + actionview (= 6.1.4.4) + activesupport (= 6.1.4.4) + rack (~> 2.0, >= 2.0.9) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.2.0) - actiontext (6.0.3.4) - actionpack (= 6.0.3.4) - activerecord (= 6.0.3.4) - activestorage (= 6.0.3.4) - activesupport (= 6.0.3.4) + actiontext (6.1.4.4) + actionpack (= 6.1.4.4) + activerecord (= 6.1.4.4) + activestorage (= 6.1.4.4) + activesupport (= 6.1.4.4) nokogiri (>= 1.8.5) - actionview (6.0.3.4) - activesupport (= 6.0.3.4) + actionview (6.1.4.4) + activesupport (= 6.1.4.4) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.1, >= 1.2.0) - activejob (6.0.3.4) - activesupport (= 6.0.3.4) + activejob (6.1.4.4) + activesupport (= 6.1.4.4) globalid (>= 0.3.6) - activemodel (6.0.3.4) - activesupport (= 6.0.3.4) - activerecord (6.0.3.4) - activemodel (= 6.0.3.4) - activesupport (= 6.0.3.4) - activestorage (6.0.3.4) - actionpack (= 6.0.3.4) - activejob (= 6.0.3.4) - activerecord (= 6.0.3.4) - marcel (~> 0.3.1) - activesupport (6.0.3.4) + activemodel (6.1.4.4) + activesupport (= 6.1.4.4) + activerecord (6.1.4.4) + activemodel (= 6.1.4.4) + activesupport (= 6.1.4.4) + activestorage (6.1.4.4) + actionpack (= 6.1.4.4) + activejob (= 6.1.4.4) + activerecord (= 6.1.4.4) + activesupport (= 6.1.4.4) + marcel (~> 1.0.0) + mini_mime (>= 1.1.0) + activesupport (6.1.4.4) concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (>= 0.7, < 2) - minitest (~> 5.1) - tzinfo (~> 1.1) - zeitwerk (~> 2.2, >= 2.2.2) - addressable (2.7.0) + i18n (>= 1.6, < 2) + minitest (>= 5.1) + tzinfo (~> 2.0) + zeitwerk (~> 2.3) + addressable (2.8.0) public_suffix (>= 2.0.2, < 5.0) bindex (0.8.1) builder (3.2.4) @@ -68,82 +72,82 @@ GEM rack (>= 1.0.0) rack-test (>= 0.5.4) xpath (>= 2.0, < 4.0) - childprocess (3.0.0) + childprocess (4.1.0) concurrent-ruby (1.1.9) crass (1.0.6) - diff-lcs (1.4.4) + diff-lcs (1.5.0) erubi (1.10.0) - execjs (2.7.0) - ffi (1.14.2) - globalid (0.4.2) - activesupport (>= 4.2.0) - i18n (1.8.10) + execjs (2.8.1) + ffi (1.15.5) + globalid (1.0.0) + activesupport (>= 5.0) + i18n (1.9.1) concurrent-ruby (~> 1.0) - jbuilder (2.11.2) + jbuilder (2.11.5) + actionview (>= 5.0.0) activesupport (>= 5.0.0) listen (3.1.5) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) ruby_dep (~> 1.2) - loofah (2.10.0) + loofah (2.13.0) crass (~> 1.0.2) nokogiri (>= 1.5.9) mail (2.7.1) mini_mime (>= 0.1.1) - marcel (0.3.3) - mimemagic (~> 0.3.2) + marcel (1.0.2) method_source (1.0.0) - mimemagic (0.3.5) - mini_mime (1.0.2) - mini_portile2 (2.5.3) - minitest (5.14.4) - nio4r (2.5.5) - nokogiri (1.11.7) - mini_portile2 (~> 2.5.0) + mini_mime (1.1.2) + mini_portile2 (2.7.1) + minitest (5.15.0) + nio4r (2.5.8) + nokogiri (1.13.1) + mini_portile2 (~> 2.7.0) racc (~> 1.4) - pg (1.2.3) + pg (1.3.1) public_suffix (4.0.6) puma (3.12.6) - racc (1.5.2) + racc (1.6.0) rack (2.2.3) rack-test (1.1.0) rack (>= 1.0, < 3) - rails (6.0.3.4) - actioncable (= 6.0.3.4) - actionmailbox (= 6.0.3.4) - actionmailer (= 6.0.3.4) - actionpack (= 6.0.3.4) - actiontext (= 6.0.3.4) - actionview (= 6.0.3.4) - activejob (= 6.0.3.4) - activemodel (= 6.0.3.4) - activerecord (= 6.0.3.4) - activestorage (= 6.0.3.4) - activesupport (= 6.0.3.4) - bundler (>= 1.3.0) - railties (= 6.0.3.4) + rails (6.1.4.4) + actioncable (= 6.1.4.4) + actionmailbox (= 6.1.4.4) + actionmailer (= 6.1.4.4) + actionpack (= 6.1.4.4) + actiontext (= 6.1.4.4) + actionview (= 6.1.4.4) + activejob (= 6.1.4.4) + activemodel (= 6.1.4.4) + activerecord (= 6.1.4.4) + activestorage (= 6.1.4.4) + activesupport (= 6.1.4.4) + bundler (>= 1.15.0) + railties (= 6.1.4.4) sprockets-rails (>= 2.0.0) rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) - rails-html-sanitizer (1.3.0) + rails-html-sanitizer (1.4.2) loofah (~> 2.3) - railties (6.0.3.4) - actionpack (= 6.0.3.4) - activesupport (= 6.0.3.4) + railties (6.1.4.4) + actionpack (= 6.1.4.4) + activesupport (= 6.1.4.4) method_source - rake (>= 0.8.7) - thor (>= 0.20.3, < 2.0) + rake (>= 0.13) + thor (~> 1.0) rake (13.0.6) - rb-fsevent (0.10.4) + rb-fsevent (0.11.1) rb-inotify (0.10.1) ffi (~> 1.0) - rspec-core (3.10.1) + rexml (3.2.5) + rspec-core (3.10.2) rspec-support (~> 3.10.0) - rspec-expectations (3.10.1) + rspec-expectations (3.10.2) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.10.0) - rspec-mocks (3.10.2) + rspec-mocks (3.10.3) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.10.0) rspec-rails (4.1.2) @@ -154,9 +158,9 @@ GEM rspec-expectations (~> 3.10) rspec-mocks (~> 3.10) rspec-support (~> 3.10) - rspec-support (3.10.2) + rspec-support (3.10.3) ruby_dep (1.5.0) - rubyzip (2.3.0) + rubyzip (2.3.2) sass-rails (6.0.0) sassc-rails (~> 2.1, >= 2.1.1) sassc (2.4.0) @@ -167,34 +171,34 @@ GEM sprockets (> 3.0) sprockets-rails tilt - selenium-webdriver (3.142.7) - childprocess (>= 0.5, < 4.0) + selenium-webdriver (4.1.0) + childprocess (>= 0.5, < 5.0) + rexml (~> 3.2, >= 3.2.5) rubyzip (>= 1.2.2) sprockets (4.0.2) concurrent-ruby (~> 1.0) rack (> 1, < 3) - sprockets-rails (3.2.2) - actionpack (>= 4.0) - activesupport (>= 4.0) + sprockets-rails (3.4.2) + actionpack (>= 5.2) + activesupport (>= 5.2) sprockets (>= 3.0.0) - thor (1.1.0) - thread_safe (0.3.6) + thor (1.2.1) tilt (2.0.10) - tzinfo (1.2.9) - thread_safe (~> 0.1) + tzinfo (2.0.4) + concurrent-ruby (~> 1.0) uglifier (4.2.0) execjs (>= 0.3.0, < 3) - web-console (4.1.0) + web-console (4.2.0) actionview (>= 6.0.0) activemodel (>= 6.0.0) bindex (>= 0.4.0) railties (>= 6.0.0) - websocket-driver (0.7.3) + websocket-driver (0.7.5) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) xpath (3.2.0) nokogiri (~> 1.8) - zeitwerk (2.4.2) + zeitwerk (2.5.4) PLATFORMS ruby @@ -206,7 +210,7 @@ DEPENDENCIES listen (>= 3.0.5, < 3.2) pg puma (~> 3.12.6) - rails (~> 6.0.0) + rails (~> 6.1.0) rspec-rails (~> 4) sass-rails (~> 6.0) selenium-webdriver From f7cc75ec8a594ff04595836b1083b82808b6d492 Mon Sep 17 00:00:00 2001 From: samir Date: Mon, 7 Feb 2022 14:34:49 +0000 Subject: [PATCH 02/56] File set-up --- db/schema.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/db/schema.rb b/db/schema.rb index 01b88ac7d0..540f5781a6 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -2,15 +2,15 @@ # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. # -# Note that this schema.rb definition is the authoritative source for your -# database schema. If you need to create the application database on another -# system, you should be using db:schema:load, not running all the migrations -# from scratch. The latter is a flawed and unsustainable approach (the more migrations -# you'll amass, the slower it'll run and the greater likelihood for issues). +# This file is the source Rails uses to define your schema when running `bin/rails +# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to +# be faster and is potentially less error prone than running all of your +# migrations from scratch. Old migrations may fail to apply correctly if those +# migrations use external dependencies or application code. # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170526114520) do +ActiveRecord::Schema.define(version: 2017_05_26_114520) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" From 207b3282272d3bff832fad08c5e47b24cc2f715c Mon Sep 17 00:00:00 2001 From: Hannah Desmond Date: Tue, 8 Feb 2022 12:26:18 +0000 Subject: [PATCH 03/56] Heroku setup --- app/assets/stylesheets/welcome.scss | 3 +++ app/controllers/welcome_controller.rb | 2 ++ app/helpers/welcome_helper.rb | 2 ++ app/views/welcome/index.html.erb | 4 ++++ config/routes.rb | 1 + spec/helpers/welcome_helper_spec.rb | 15 +++++++++++++++ spec/requests/welcome_spec.rb | 7 +++++++ 7 files changed, 34 insertions(+) create mode 100644 app/assets/stylesheets/welcome.scss create mode 100644 app/controllers/welcome_controller.rb create mode 100644 app/helpers/welcome_helper.rb create mode 100644 app/views/welcome/index.html.erb create mode 100644 spec/helpers/welcome_helper_spec.rb create mode 100644 spec/requests/welcome_spec.rb diff --git a/app/assets/stylesheets/welcome.scss b/app/assets/stylesheets/welcome.scss new file mode 100644 index 0000000000..5042f7d146 --- /dev/null +++ b/app/assets/stylesheets/welcome.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the welcome controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: https://sass-lang.com/ diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb new file mode 100644 index 0000000000..d8c85ab84b --- /dev/null +++ b/app/controllers/welcome_controller.rb @@ -0,0 +1,2 @@ +class WelcomeController < ApplicationController +end diff --git a/app/helpers/welcome_helper.rb b/app/helpers/welcome_helper.rb new file mode 100644 index 0000000000..eeead45fc9 --- /dev/null +++ b/app/helpers/welcome_helper.rb @@ -0,0 +1,2 @@ +module WelcomeHelper +end diff --git a/app/views/welcome/index.html.erb b/app/views/welcome/index.html.erb new file mode 100644 index 0000000000..d1441cea3f --- /dev/null +++ b/app/views/welcome/index.html.erb @@ -0,0 +1,4 @@ +

Hello World

+

+ The time is now: <%= Time.now %> +

\ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 7a3fe16c4c..a9149862f5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,5 @@ Rails.application.routes.draw do + root 'welcome#index' # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html resources :posts diff --git a/spec/helpers/welcome_helper_spec.rb b/spec/helpers/welcome_helper_spec.rb new file mode 100644 index 0000000000..a899852950 --- /dev/null +++ b/spec/helpers/welcome_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the WelcomeHelper. For example: +# +# describe WelcomeHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe WelcomeHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/requests/welcome_spec.rb b/spec/requests/welcome_spec.rb new file mode 100644 index 0000000000..36343d0420 --- /dev/null +++ b/spec/requests/welcome_spec.rb @@ -0,0 +1,7 @@ +require 'rails_helper' + +RSpec.describe "Welcomes", type: :request do + describe "GET /index" do + pending "add some examples (or delete) #{__FILE__}" + end +end From 5c200ee6b0f69d44f15529b7c03af0b7f3759099 Mon Sep 17 00:00:00 2001 From: Hannah Desmond Date: Tue, 8 Feb 2022 17:22:48 +0000 Subject: [PATCH 04/56] Update for Heroku --- .gitignore | 1 + Procfile | 1 + config/routes.rb | 2 +- config/storage.yml | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 Procfile create mode 100644 config/storage.yml diff --git a/.gitignore b/.gitignore index dcc5b36f34..f6013e7ae2 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ /yarn-error.log .byebug_history +.env diff --git a/Procfile b/Procfile new file mode 100644 index 0000000000..9e10c0c7eb --- /dev/null +++ b/Procfile @@ -0,0 +1 @@ +web: bundle exec puma -t 5:5 -p ${PORT:-3000} -e ${RACK_ENV:-development} \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index a9149862f5..fa9ed98071 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,5 @@ Rails.application.routes.draw do - root 'welcome#index' + root 'posts#index' # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html resources :posts diff --git a/config/storage.yml b/config/storage.yml new file mode 100644 index 0000000000..0b723b3163 --- /dev/null +++ b/config/storage.yml @@ -0,0 +1,34 @@ +test: + service: Disk + root: <%= Rails.root.join("tmp/storage") %> + +local: + service: Disk + root: <%= Rails.root.join("storage") %> + +# Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key) +# amazon: +# service: S3 +# access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %> +# secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %> +# region: us-east-1 +# bucket: your_own_bucket + +# Remember not to checkin your GCS keyfile to a repository +# google: +# service: GCS +# project: your_project +# credentials: <%= Rails.root.join("path/to/gcs.keyfile") %> +# bucket: your_own_bucket + +# Use rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key) +# microsoft: +# service: AzureStorage +# storage_account_name: your_account_name +# storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %> +# container: your_container_name + +# mirror: +# service: Mirror +# primary: local +# mirrors: [ amazon, google, microsoft ] \ No newline at end of file From 262ff0aaf56de366cdd0cbbf0829d061cbae95dd Mon Sep 17 00:00:00 2001 From: Alexander Jamshidi Date: Wed, 9 Feb 2022 12:07:36 +0000 Subject: [PATCH 05/56] installed devise --- Gemfile | 2 + Gemfile.lock | 26 +- README.md | 33 ++ app/models/user.rb | 6 + app/views/devise/confirmations/new.html.erb | 16 + .../mailer/confirmation_instructions.html.erb | 5 + .../devise/mailer/email_changed.html.erb | 7 + .../devise/mailer/password_change.html.erb | 3 + .../reset_password_instructions.html.erb | 8 + .../mailer/unlock_instructions.html.erb | 7 + app/views/devise/passwords/edit.html.erb | 25 ++ app/views/devise/passwords/new.html.erb | 16 + app/views/devise/registrations/edit.html.erb | 43 +++ app/views/devise/registrations/new.html.erb | 29 ++ app/views/devise/sessions/new.html.erb | 26 ++ .../devise/shared/_error_messages.html.erb | 15 + app/views/devise/shared/_links.html.erb | 25 ++ app/views/devise/unlocks/new.html.erb | 16 + app/views/layouts/application.html.erb | 2 + app/views/posts/index.html.erb | 14 +- config/environments/development.rb | 2 + config/environments/production.rb | 2 + config/initializers/devise.rb | 311 ++++++++++++++++++ config/locales/devise.en.yml | 65 ++++ config/routes.rb | 2 + .../20220209111804_devise_create_users.rb | 44 +++ db/schema.rb | 14 +- spec/models/user_spec.rb | 5 + 28 files changed, 757 insertions(+), 12 deletions(-) create mode 100644 app/models/user.rb create mode 100644 app/views/devise/confirmations/new.html.erb create mode 100644 app/views/devise/mailer/confirmation_instructions.html.erb create mode 100644 app/views/devise/mailer/email_changed.html.erb create mode 100644 app/views/devise/mailer/password_change.html.erb create mode 100644 app/views/devise/mailer/reset_password_instructions.html.erb create mode 100644 app/views/devise/mailer/unlock_instructions.html.erb create mode 100644 app/views/devise/passwords/edit.html.erb create mode 100644 app/views/devise/passwords/new.html.erb create mode 100644 app/views/devise/registrations/edit.html.erb create mode 100644 app/views/devise/registrations/new.html.erb create mode 100644 app/views/devise/sessions/new.html.erb create mode 100644 app/views/devise/shared/_error_messages.html.erb create mode 100644 app/views/devise/shared/_links.html.erb create mode 100644 app/views/devise/unlocks/new.html.erb create mode 100644 config/initializers/devise.rb create mode 100644 config/locales/devise.en.yml create mode 100644 db/migrate/20220209111804_devise_create_users.rb create mode 100644 spec/models/user_spec.rb diff --git a/Gemfile b/Gemfile index d90bbcec23..1076c40009 100644 --- a/Gemfile +++ b/Gemfile @@ -28,6 +28,8 @@ gem 'jbuilder', '~> 2.5' # Use Capistrano for deployment # gem 'capistrano-rails', group: :development +gem 'devise', '~> 4.8', '>= 4.8.1' + group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] diff --git a/Gemfile.lock b/Gemfile.lock index ef46afbc44..b715c532a4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -62,6 +62,7 @@ GEM zeitwerk (~> 2.3) addressable (2.8.0) public_suffix (>= 2.0.2, < 5.0) + bcrypt (3.1.16) bindex (0.8.1) builder (3.2.4) byebug (11.1.3) @@ -75,6 +76,12 @@ GEM childprocess (4.1.0) concurrent-ruby (1.1.9) crass (1.0.6) + devise (4.8.1) + bcrypt (~> 3.0) + orm_adapter (~> 0.1) + railties (>= 4.1.0) + responders + warden (~> 1.2.3) diff-lcs (1.5.0) erubi (1.10.0) execjs (2.8.1) @@ -86,10 +93,9 @@ GEM jbuilder (2.11.5) actionview (>= 5.0.0) activesupport (>= 5.0.0) - listen (3.1.5) + listen (3.0.8) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) - ruby_dep (~> 1.2) loofah (2.13.0) crass (~> 1.0.2) nokogiri (>= 1.5.9) @@ -98,12 +104,11 @@ GEM marcel (1.0.2) method_source (1.0.0) mini_mime (1.1.2) - mini_portile2 (2.7.1) minitest (5.15.0) nio4r (2.5.8) - nokogiri (1.13.1) - mini_portile2 (~> 2.7.0) + nokogiri (1.13.1-arm64-darwin) racc (~> 1.4) + orm_adapter (0.5.0) pg (1.3.1) public_suffix (4.0.6) puma (3.12.6) @@ -141,6 +146,9 @@ GEM rb-fsevent (0.11.1) rb-inotify (0.10.1) ffi (~> 1.0) + responders (3.0.1) + actionpack (>= 5.0) + railties (>= 5.0) rexml (3.2.5) rspec-core (3.10.2) rspec-support (~> 3.10.0) @@ -159,7 +167,6 @@ GEM rspec-mocks (~> 3.10) rspec-support (~> 3.10) rspec-support (3.10.3) - ruby_dep (1.5.0) rubyzip (2.3.2) sass-rails (6.0.0) sassc-rails (~> 2.1, >= 2.1.1) @@ -188,6 +195,8 @@ GEM concurrent-ruby (~> 1.0) uglifier (4.2.0) execjs (>= 0.3.0, < 3) + warden (1.2.9) + rack (>= 2.0.9) web-console (4.2.0) actionview (>= 6.0.0) activemodel (>= 6.0.0) @@ -201,11 +210,12 @@ GEM zeitwerk (2.5.4) PLATFORMS - ruby + arm64-darwin-21 DEPENDENCIES byebug capybara (~> 2.13) + devise (~> 4.8, >= 4.8.1) jbuilder (~> 2.5) listen (>= 3.0.5, < 3.2) pg @@ -219,4 +229,4 @@ DEPENDENCIES web-console (>= 3.3.0) BUNDLED WITH - 2.3.6 + 2.2.33 diff --git a/README.md b/README.md index 6ee1b4364c..71aad634b8 100644 --- a/README.md +++ b/README.md @@ -34,3 +34,36 @@ ExecJS::RuntimeUnavailable: ``` That is because Rails will use a Javascript runtime (such as Node) under the hood. The easiest way is to install Node by running `brew install node` - and then run `bundle exec rspec` again + + + + +=== Adding Devise === +gem 'devise', '~> 4.8', '>= 4.8.1' (added to gemfile) +ran: bundle install + +Follow instructions here: https://github.com/heartcombo/devise + +ran: $ rails generate devise:install (and follow steps in terminal) + +- pasted into config/envrionments/development.rb: + config.action_mailer.default_url_options = { host: 'localhost', port: 3000 } + +- pasted into config/envrionments/production.rb: + config.action_mailer.default_url_options = { host: 'https://acebook--chats.herokuapp.com/', port: 8080 } + +- pasted into app/views/layouts/application.html.erb: +

<%= notice %>

+

<%= alert %>

+ +- ran: rails g devise:views (added a lot of app/views files) + +Setup database (user table): +ran: rails generate devise user +and migrate it, ran: rails db:migrate + +ran: rails routes (to see new routes added) + +commented out line: 'devise_for :users' in config/routes.rb (to get website working again) + + diff --git a/app/models/user.rb b/app/models/user.rb new file mode 100644 index 0000000000..47567994e9 --- /dev/null +++ b/app/models/user.rb @@ -0,0 +1,6 @@ +class User < ApplicationRecord + # Include default devise modules. Others available are: + # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable + devise :database_authenticatable, :registerable, + :recoverable, :rememberable, :validatable +end diff --git a/app/views/devise/confirmations/new.html.erb b/app/views/devise/confirmations/new.html.erb new file mode 100644 index 0000000000..b12dd0cbeb --- /dev/null +++ b/app/views/devise/confirmations/new.html.erb @@ -0,0 +1,16 @@ +

Resend confirmation instructions

+ +<%= form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { method: :post }) do |f| %> + <%= render "devise/shared/error_messages", resource: resource %> + +
+ <%= f.label :email %>
+ <%= f.email_field :email, autofocus: true, autocomplete: "email", value: (resource.pending_reconfirmation? ? resource.unconfirmed_email : resource.email) %> +
+ +
+ <%= f.submit "Resend confirmation instructions" %> +
+<% end %> + +<%= render "devise/shared/links" %> diff --git a/app/views/devise/mailer/confirmation_instructions.html.erb b/app/views/devise/mailer/confirmation_instructions.html.erb new file mode 100644 index 0000000000..dc55f64f69 --- /dev/null +++ b/app/views/devise/mailer/confirmation_instructions.html.erb @@ -0,0 +1,5 @@ +

Welcome <%= @email %>!

+ +

You can confirm your account email through the link below:

+ +

<%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token) %>

diff --git a/app/views/devise/mailer/email_changed.html.erb b/app/views/devise/mailer/email_changed.html.erb new file mode 100644 index 0000000000..32f4ba8038 --- /dev/null +++ b/app/views/devise/mailer/email_changed.html.erb @@ -0,0 +1,7 @@ +

Hello <%= @email %>!

+ +<% if @resource.try(:unconfirmed_email?) %> +

We're contacting you to notify you that your email is being changed to <%= @resource.unconfirmed_email %>.

+<% else %> +

We're contacting you to notify you that your email has been changed to <%= @resource.email %>.

+<% end %> diff --git a/app/views/devise/mailer/password_change.html.erb b/app/views/devise/mailer/password_change.html.erb new file mode 100644 index 0000000000..b41daf476a --- /dev/null +++ b/app/views/devise/mailer/password_change.html.erb @@ -0,0 +1,3 @@ +

Hello <%= @resource.email %>!

+ +

We're contacting you to notify you that your password has been changed.

diff --git a/app/views/devise/mailer/reset_password_instructions.html.erb b/app/views/devise/mailer/reset_password_instructions.html.erb new file mode 100644 index 0000000000..f667dc12fe --- /dev/null +++ b/app/views/devise/mailer/reset_password_instructions.html.erb @@ -0,0 +1,8 @@ +

Hello <%= @resource.email %>!

+ +

Someone has requested a link to change your password. You can do this through the link below.

+ +

<%= link_to 'Change my password', edit_password_url(@resource, reset_password_token: @token) %>

+ +

If you didn't request this, please ignore this email.

+

Your password won't change until you access the link above and create a new one.

diff --git a/app/views/devise/mailer/unlock_instructions.html.erb b/app/views/devise/mailer/unlock_instructions.html.erb new file mode 100644 index 0000000000..41e148bf2a --- /dev/null +++ b/app/views/devise/mailer/unlock_instructions.html.erb @@ -0,0 +1,7 @@ +

Hello <%= @resource.email %>!

+ +

Your account has been locked due to an excessive number of unsuccessful sign in attempts.

+ +

Click the link below to unlock your account:

+ +

<%= link_to 'Unlock my account', unlock_url(@resource, unlock_token: @token) %>

diff --git a/app/views/devise/passwords/edit.html.erb b/app/views/devise/passwords/edit.html.erb new file mode 100644 index 0000000000..5fbb9ff0a7 --- /dev/null +++ b/app/views/devise/passwords/edit.html.erb @@ -0,0 +1,25 @@ +

Change your password

+ +<%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :put }) do |f| %> + <%= render "devise/shared/error_messages", resource: resource %> + <%= f.hidden_field :reset_password_token %> + +
+ <%= f.label :password, "New password" %>
+ <% if @minimum_password_length %> + (<%= @minimum_password_length %> characters minimum)
+ <% end %> + <%= f.password_field :password, autofocus: true, autocomplete: "new-password" %> +
+ +
+ <%= f.label :password_confirmation, "Confirm new password" %>
+ <%= f.password_field :password_confirmation, autocomplete: "new-password" %> +
+ +
+ <%= f.submit "Change my password" %> +
+<% end %> + +<%= render "devise/shared/links" %> diff --git a/app/views/devise/passwords/new.html.erb b/app/views/devise/passwords/new.html.erb new file mode 100644 index 0000000000..9b486b81b9 --- /dev/null +++ b/app/views/devise/passwords/new.html.erb @@ -0,0 +1,16 @@ +

Forgot your password?

+ +<%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| %> + <%= render "devise/shared/error_messages", resource: resource %> + +
+ <%= f.label :email %>
+ <%= f.email_field :email, autofocus: true, autocomplete: "email" %> +
+ +
+ <%= f.submit "Send me reset password instructions" %> +
+<% end %> + +<%= render "devise/shared/links" %> diff --git a/app/views/devise/registrations/edit.html.erb b/app/views/devise/registrations/edit.html.erb new file mode 100644 index 0000000000..38d95b85a8 --- /dev/null +++ b/app/views/devise/registrations/edit.html.erb @@ -0,0 +1,43 @@ +

Edit <%= resource_name.to_s.humanize %>

+ +<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %> + <%= render "devise/shared/error_messages", resource: resource %> + +
+ <%= f.label :email %>
+ <%= f.email_field :email, autofocus: true, autocomplete: "email" %> +
+ + <% if devise_mapping.confirmable? && resource.pending_reconfirmation? %> +
Currently waiting confirmation for: <%= resource.unconfirmed_email %>
+ <% end %> + +
+ <%= f.label :password %> (leave blank if you don't want to change it)
+ <%= f.password_field :password, autocomplete: "new-password" %> + <% if @minimum_password_length %> +
+ <%= @minimum_password_length %> characters minimum + <% end %> +
+ +
+ <%= f.label :password_confirmation %>
+ <%= f.password_field :password_confirmation, autocomplete: "new-password" %> +
+ +
+ <%= f.label :current_password %> (we need your current password to confirm your changes)
+ <%= f.password_field :current_password, autocomplete: "current-password" %> +
+ +
+ <%= f.submit "Update" %> +
+<% end %> + +

Cancel my account

+ +

Unhappy? <%= button_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?" }, method: :delete %>

+ +<%= link_to "Back", :back %> diff --git a/app/views/devise/registrations/new.html.erb b/app/views/devise/registrations/new.html.erb new file mode 100644 index 0000000000..d655b66f6f --- /dev/null +++ b/app/views/devise/registrations/new.html.erb @@ -0,0 +1,29 @@ +

Sign up

+ +<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %> + <%= render "devise/shared/error_messages", resource: resource %> + +
+ <%= f.label :email %>
+ <%= f.email_field :email, autofocus: true, autocomplete: "email" %> +
+ +
+ <%= f.label :password %> + <% if @minimum_password_length %> + (<%= @minimum_password_length %> characters minimum) + <% end %>
+ <%= f.password_field :password, autocomplete: "new-password" %> +
+ +
+ <%= f.label :password_confirmation %>
+ <%= f.password_field :password_confirmation, autocomplete: "new-password" %> +
+ +
+ <%= f.submit "Sign up" %> +
+<% end %> + +<%= render "devise/shared/links" %> diff --git a/app/views/devise/sessions/new.html.erb b/app/views/devise/sessions/new.html.erb new file mode 100644 index 0000000000..5ede96489d --- /dev/null +++ b/app/views/devise/sessions/new.html.erb @@ -0,0 +1,26 @@ +

Log in

+ +<%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %> +
+ <%= f.label :email %>
+ <%= f.email_field :email, autofocus: true, autocomplete: "email" %> +
+ +
+ <%= f.label :password %>
+ <%= f.password_field :password, autocomplete: "current-password" %> +
+ + <% if devise_mapping.rememberable? %> +
+ <%= f.check_box :remember_me %> + <%= f.label :remember_me %> +
+ <% end %> + +
+ <%= f.submit "Log in" %> +
+<% end %> + +<%= render "devise/shared/links" %> diff --git a/app/views/devise/shared/_error_messages.html.erb b/app/views/devise/shared/_error_messages.html.erb new file mode 100644 index 0000000000..ba7ab88701 --- /dev/null +++ b/app/views/devise/shared/_error_messages.html.erb @@ -0,0 +1,15 @@ +<% if resource.errors.any? %> +
+

+ <%= I18n.t("errors.messages.not_saved", + count: resource.errors.count, + resource: resource.class.model_name.human.downcase) + %> +

+
    + <% resource.errors.full_messages.each do |message| %> +
  • <%= message %>
  • + <% end %> +
+
+<% end %> diff --git a/app/views/devise/shared/_links.html.erb b/app/views/devise/shared/_links.html.erb new file mode 100644 index 0000000000..96a9412417 --- /dev/null +++ b/app/views/devise/shared/_links.html.erb @@ -0,0 +1,25 @@ +<%- if controller_name != 'sessions' %> + <%= link_to "Log in", new_session_path(resource_name) %>
+<% end %> + +<%- if devise_mapping.registerable? && controller_name != 'registrations' %> + <%= link_to "Sign up", new_registration_path(resource_name) %>
+<% end %> + +<%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %> + <%= link_to "Forgot your password?", new_password_path(resource_name) %>
+<% end %> + +<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %> + <%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %>
+<% end %> + +<%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %> + <%= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name) %>
+<% end %> + +<%- if devise_mapping.omniauthable? %> + <%- resource_class.omniauth_providers.each do |provider| %> + <%= link_to "Sign in with #{OmniAuth::Utils.camelize(provider)}", omniauth_authorize_path(resource_name, provider), method: :post %>
+ <% end %> +<% end %> diff --git a/app/views/devise/unlocks/new.html.erb b/app/views/devise/unlocks/new.html.erb new file mode 100644 index 0000000000..ffc34de8d1 --- /dev/null +++ b/app/views/devise/unlocks/new.html.erb @@ -0,0 +1,16 @@ +

Resend unlock instructions

+ +<%= form_for(resource, as: resource_name, url: unlock_path(resource_name), html: { method: :post }) do |f| %> + <%= render "devise/shared/error_messages", resource: resource %> + +
+ <%= f.label :email %>
+ <%= f.email_field :email, autofocus: true, autocomplete: "email" %> +
+ +
+ <%= f.submit "Resend unlock instructions" %> +
+<% end %> + +<%= render "devise/shared/links" %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 1d2a9c14f9..423bd2ac4f 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -10,5 +10,7 @@ <%= yield %> +

<%= notice %>

+

<%= alert %>

diff --git a/app/views/posts/index.html.erb b/app/views/posts/index.html.erb index 03f9487ccd..8c1a345bff 100644 --- a/app/views/posts/index.html.erb +++ b/app/views/posts/index.html.erb @@ -1,7 +1,15 @@ -<% @posts.each do |post| %> -

<%= post.message %>

-<% end %> +

+ The time is now: <%= Time.now %> +

+ +The Gospel
<%= link_to new_post_path do %> New post <% end %> + +<% @posts.each do |post| %> +

<%= post.message %>

+<% end %> + diff --git a/config/environments/development.rb b/config/environments/development.rb index 5187e22186..1b0c4b389f 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -51,4 +51,6 @@ # Use an evented file watcher to asynchronously detect changes in source code, # routes, locales, etc. This feature depends on the listen gem. config.file_watcher = ActiveSupport::EventedFileUpdateChecker + + config.action_mailer.default_url_options = { host: 'localhost', port: 3000 } end diff --git a/config/environments/production.rb b/config/environments/production.rb index 9e1a94961d..4a41bf9e38 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -88,4 +88,6 @@ # Do not dump schema after migrations. config.active_record.dump_schema_after_migration = false + + config.action_mailer.default_url_options = { host: 'https://acebook--chats.herokuapp.com/', port: 8080 } end diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb new file mode 100644 index 0000000000..ad6c64d95e --- /dev/null +++ b/config/initializers/devise.rb @@ -0,0 +1,311 @@ +# frozen_string_literal: true + +# Assuming you have not yet modified this file, each configuration option below +# is set to its default value. Note that some are commented out while others +# are not: uncommented lines are intended to protect your configuration from +# breaking changes in upgrades (i.e., in the event that future versions of +# Devise change the default values for those options). +# +# Use this hook to configure devise mailer, warden hooks and so forth. +# Many of these configuration options can be set straight in your model. +Devise.setup do |config| + # The secret key used by Devise. Devise uses this key to generate + # random tokens. Changing this key will render invalid all existing + # confirmation, reset password and unlock tokens in the database. + # Devise will use the `secret_key_base` as its `secret_key` + # by default. You can change it below and use your own secret key. + # config.secret_key = '34c7028b49e597021fa10958488b053a8fd45426c9322cd33f297f983595107a395d5efdd7cbc9562988e0592c3b7b61618fb586934a51dffa87794ee6a7316a' + + # ==> Controller configuration + # Configure the parent class to the devise controllers. + # config.parent_controller = 'DeviseController' + + # ==> Mailer Configuration + # Configure the e-mail address which will be shown in Devise::Mailer, + # note that it will be overwritten if you use your own mailer class + # with default "from" parameter. + config.mailer_sender = 'please-change-me-at-config-initializers-devise@example.com' + + # Configure the class responsible to send e-mails. + # config.mailer = 'Devise::Mailer' + + # Configure the parent class responsible to send e-mails. + # config.parent_mailer = 'ActionMailer::Base' + + # ==> ORM configuration + # Load and configure the ORM. Supports :active_record (default) and + # :mongoid (bson_ext recommended) by default. Other ORMs may be + # available as additional gems. + require 'devise/orm/active_record' + + # ==> Configuration for any authentication mechanism + # Configure which keys are used when authenticating a user. The default is + # just :email. You can configure it to use [:username, :subdomain], so for + # authenticating a user, both parameters are required. Remember that those + # parameters are used only when authenticating and not when retrieving from + # session. If you need permissions, you should implement that in a before filter. + # You can also supply a hash where the value is a boolean determining whether + # or not authentication should be aborted when the value is not present. + # config.authentication_keys = [:email] + + # Configure parameters from the request object used for authentication. Each entry + # given should be a request method and it will automatically be passed to the + # find_for_authentication method and considered in your model lookup. For instance, + # if you set :request_keys to [:subdomain], :subdomain will be used on authentication. + # The same considerations mentioned for authentication_keys also apply to request_keys. + # config.request_keys = [] + + # Configure which authentication keys should be case-insensitive. + # These keys will be downcased upon creating or modifying a user and when used + # to authenticate or find a user. Default is :email. + config.case_insensitive_keys = [:email] + + # Configure which authentication keys should have whitespace stripped. + # These keys will have whitespace before and after removed upon creating or + # modifying a user and when used to authenticate or find a user. Default is :email. + config.strip_whitespace_keys = [:email] + + # Tell if authentication through request.params is enabled. True by default. + # It can be set to an array that will enable params authentication only for the + # given strategies, for example, `config.params_authenticatable = [:database]` will + # enable it only for database (email + password) authentication. + # config.params_authenticatable = true + + # Tell if authentication through HTTP Auth is enabled. False by default. + # It can be set to an array that will enable http authentication only for the + # given strategies, for example, `config.http_authenticatable = [:database]` will + # enable it only for database authentication. + # For API-only applications to support authentication "out-of-the-box", you will likely want to + # enable this with :database unless you are using a custom strategy. + # The supported strategies are: + # :database = Support basic authentication with authentication key + password + # config.http_authenticatable = false + + # If 401 status code should be returned for AJAX requests. True by default. + # config.http_authenticatable_on_xhr = true + + # The realm used in Http Basic Authentication. 'Application' by default. + # config.http_authentication_realm = 'Application' + + # It will change confirmation, password recovery and other workflows + # to behave the same regardless if the e-mail provided was right or wrong. + # Does not affect registerable. + # config.paranoid = true + + # By default Devise will store the user in session. You can skip storage for + # particular strategies by setting this option. + # Notice that if you are skipping storage for all authentication paths, you + # may want to disable generating routes to Devise's sessions controller by + # passing skip: :sessions to `devise_for` in your config/routes.rb + config.skip_session_storage = [:http_auth] + + # By default, Devise cleans up the CSRF token on authentication to + # avoid CSRF token fixation attacks. This means that, when using AJAX + # requests for sign in and sign up, you need to get a new CSRF token + # from the server. You can disable this option at your own risk. + # config.clean_up_csrf_token_on_authentication = true + + # When false, Devise will not attempt to reload routes on eager load. + # This can reduce the time taken to boot the app but if your application + # requires the Devise mappings to be loaded during boot time the application + # won't boot properly. + # config.reload_routes = true + + # ==> Configuration for :database_authenticatable + # For bcrypt, this is the cost for hashing the password and defaults to 12. If + # using other algorithms, it sets how many times you want the password to be hashed. + # The number of stretches used for generating the hashed password are stored + # with the hashed password. This allows you to change the stretches without + # invalidating existing passwords. + # + # Limiting the stretches to just one in testing will increase the performance of + # your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use + # a value less than 10 in other environments. Note that, for bcrypt (the default + # algorithm), the cost increases exponentially with the number of stretches (e.g. + # a value of 20 is already extremely slow: approx. 60 seconds for 1 calculation). + config.stretches = Rails.env.test? ? 1 : 12 + + # Set up a pepper to generate the hashed password. + # config.pepper = '793e378cacd79babe58c81752745beae55e5970ce4d2d57317c72ada62c9075174d83d30f0c0a3cbf3dc0ada2f709d03e7453488ee201c0cab86420015693700' + + # Send a notification to the original email when the user's email is changed. + # config.send_email_changed_notification = false + + # Send a notification email when the user's password is changed. + # config.send_password_change_notification = false + + # ==> Configuration for :confirmable + # A period that the user is allowed to access the website even without + # confirming their account. For instance, if set to 2.days, the user will be + # able to access the website for two days without confirming their account, + # access will be blocked just in the third day. + # You can also set it to nil, which will allow the user to access the website + # without confirming their account. + # Default is 0.days, meaning the user cannot access the website without + # confirming their account. + # config.allow_unconfirmed_access_for = 2.days + + # A period that the user is allowed to confirm their account before their + # token becomes invalid. For example, if set to 3.days, the user can confirm + # their account within 3 days after the mail was sent, but on the fourth day + # their account can't be confirmed with the token any more. + # Default is nil, meaning there is no restriction on how long a user can take + # before confirming their account. + # config.confirm_within = 3.days + + # If true, requires any email changes to be confirmed (exactly the same way as + # initial account confirmation) to be applied. Requires additional unconfirmed_email + # db field (see migrations). Until confirmed, new email is stored in + # unconfirmed_email column, and copied to email column on successful confirmation. + config.reconfirmable = true + + # Defines which key will be used when confirming an account + # config.confirmation_keys = [:email] + + # ==> Configuration for :rememberable + # The time the user will be remembered without asking for credentials again. + # config.remember_for = 2.weeks + + # Invalidates all the remember me tokens when the user signs out. + config.expire_all_remember_me_on_sign_out = true + + # If true, extends the user's remember period when remembered via cookie. + # config.extend_remember_period = false + + # Options to be passed to the created cookie. For instance, you can set + # secure: true in order to force SSL only cookies. + # config.rememberable_options = {} + + # ==> Configuration for :validatable + # Range for password length. + config.password_length = 6..128 + + # Email regex used to validate email formats. It simply asserts that + # one (and only one) @ exists in the given string. This is mainly + # to give user feedback and not to assert the e-mail validity. + config.email_regexp = /\A[^@\s]+@[^@\s]+\z/ + + # ==> Configuration for :timeoutable + # The time you want to timeout the user session without activity. After this + # time the user will be asked for credentials again. Default is 30 minutes. + # config.timeout_in = 30.minutes + + # ==> Configuration for :lockable + # Defines which strategy will be used to lock an account. + # :failed_attempts = Locks an account after a number of failed attempts to sign in. + # :none = No lock strategy. You should handle locking by yourself. + # config.lock_strategy = :failed_attempts + + # Defines which key will be used when locking and unlocking an account + # config.unlock_keys = [:email] + + # Defines which strategy will be used to unlock an account. + # :email = Sends an unlock link to the user email + # :time = Re-enables login after a certain amount of time (see :unlock_in below) + # :both = Enables both strategies + # :none = No unlock strategy. You should handle unlocking by yourself. + # config.unlock_strategy = :both + + # Number of authentication tries before locking an account if lock_strategy + # is failed attempts. + # config.maximum_attempts = 20 + + # Time interval to unlock the account if :time is enabled as unlock_strategy. + # config.unlock_in = 1.hour + + # Warn on the last attempt before the account is locked. + # config.last_attempt_warning = true + + # ==> Configuration for :recoverable + # + # Defines which key will be used when recovering the password for an account + # config.reset_password_keys = [:email] + + # Time interval you can reset your password with a reset password key. + # Don't put a too small interval or your users won't have the time to + # change their passwords. + config.reset_password_within = 6.hours + + # When set to false, does not sign a user in automatically after their password is + # reset. Defaults to true, so a user is signed in automatically after a reset. + # config.sign_in_after_reset_password = true + + # ==> Configuration for :encryptable + # Allow you to use another hashing or encryption algorithm besides bcrypt (default). + # You can use :sha1, :sha512 or algorithms from others authentication tools as + # :clearance_sha1, :authlogic_sha512 (then you should set stretches above to 20 + # for default behavior) and :restful_authentication_sha1 (then you should set + # stretches to 10, and copy REST_AUTH_SITE_KEY to pepper). + # + # Require the `devise-encryptable` gem when using anything other than bcrypt + # config.encryptor = :sha512 + + # ==> Scopes configuration + # Turn scoped views on. Before rendering "sessions/new", it will first check for + # "users/sessions/new". It's turned off by default because it's slower if you + # are using only default views. + # config.scoped_views = false + + # Configure the default scope given to Warden. By default it's the first + # devise role declared in your routes (usually :user). + # config.default_scope = :user + + # Set this configuration to false if you want /users/sign_out to sign out + # only the current scope. By default, Devise signs out all scopes. + # config.sign_out_all_scopes = true + + # ==> Navigation configuration + # Lists the formats that should be treated as navigational. Formats like + # :html, should redirect to the sign in page when the user does not have + # access, but formats like :xml or :json, should return 401. + # + # If you have any extra navigational formats, like :iphone or :mobile, you + # should add them to the navigational formats lists. + # + # The "*/*" below is required to match Internet Explorer requests. + # config.navigational_formats = ['*/*', :html] + + # The default HTTP method used to sign out a resource. Default is :delete. + config.sign_out_via = :delete + + # ==> OmniAuth + # Add a new OmniAuth provider. Check the wiki for more information on setting + # up on your models and hooks. + # config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo' + + # ==> Warden configuration + # If you want to use other strategies, that are not supported by Devise, or + # change the failure app, you can configure them inside the config.warden block. + # + # config.warden do |manager| + # manager.intercept_401 = false + # manager.default_strategies(scope: :user).unshift :some_external_strategy + # end + + # ==> Mountable engine configurations + # When using Devise inside an engine, let's call it `MyEngine`, and this engine + # is mountable, there are some extra configurations to be taken into account. + # The following options are available, assuming the engine is mounted as: + # + # mount MyEngine, at: '/my_engine' + # + # The router that invoked `devise_for`, in the example above, would be: + # config.router_name = :my_engine + # + # When using OmniAuth, Devise cannot automatically set OmniAuth path, + # so you need to do it manually. For the users scope, it would be: + # config.omniauth_path_prefix = '/my_engine/users/auth' + + # ==> Turbolinks configuration + # If your app is using Turbolinks, Turbolinks::Controller needs to be included to make redirection work correctly: + # + # ActiveSupport.on_load(:devise_failure_app) do + # include Turbolinks::Controller + # end + + # ==> Configuration for :registerable + + # When set to false, does not sign a user in automatically after their password is + # changed. Defaults to true, so a user is signed in automatically after changing a password. + # config.sign_in_after_change_password = true +end diff --git a/config/locales/devise.en.yml b/config/locales/devise.en.yml new file mode 100644 index 0000000000..260e1c4ba6 --- /dev/null +++ b/config/locales/devise.en.yml @@ -0,0 +1,65 @@ +# Additional translations at https://github.com/heartcombo/devise/wiki/I18n + +en: + devise: + confirmations: + confirmed: "Your email address has been successfully confirmed." + send_instructions: "You will receive an email with instructions for how to confirm your email address in a few minutes." + send_paranoid_instructions: "If your email address exists in our database, you will receive an email with instructions for how to confirm your email address in a few minutes." + failure: + already_authenticated: "You are already signed in." + inactive: "Your account is not activated yet." + invalid: "Invalid %{authentication_keys} or password." + locked: "Your account is locked." + last_attempt: "You have one more attempt before your account is locked." + not_found_in_database: "Invalid %{authentication_keys} or password." + timeout: "Your session expired. Please sign in again to continue." + unauthenticated: "You need to sign in or sign up before continuing." + unconfirmed: "You have to confirm your email address before continuing." + mailer: + confirmation_instructions: + subject: "Confirmation instructions" + reset_password_instructions: + subject: "Reset password instructions" + unlock_instructions: + subject: "Unlock instructions" + email_changed: + subject: "Email Changed" + password_change: + subject: "Password Changed" + omniauth_callbacks: + failure: "Could not authenticate you from %{kind} because \"%{reason}\"." + success: "Successfully authenticated from %{kind} account." + passwords: + no_token: "You can't access this page without coming from a password reset email. If you do come from a password reset email, please make sure you used the full URL provided." + send_instructions: "You will receive an email with instructions on how to reset your password in a few minutes." + send_paranoid_instructions: "If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes." + updated: "Your password has been changed successfully. You are now signed in." + updated_not_active: "Your password has been changed successfully." + registrations: + destroyed: "Bye! Your account has been successfully cancelled. We hope to see you again soon." + signed_up: "Welcome! You have signed up successfully." + signed_up_but_inactive: "You have signed up successfully. However, we could not sign you in because your account is not yet activated." + signed_up_but_locked: "You have signed up successfully. However, we could not sign you in because your account is locked." + signed_up_but_unconfirmed: "A message with a confirmation link has been sent to your email address. Please follow the link to activate your account." + update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and follow the confirmation link to confirm your new email address." + updated: "Your account has been updated successfully." + updated_but_not_signed_in: "Your account has been updated successfully, but since your password was changed, you need to sign in again." + sessions: + signed_in: "Signed in successfully." + signed_out: "Signed out successfully." + already_signed_out: "Signed out successfully." + unlocks: + send_instructions: "You will receive an email with instructions for how to unlock your account in a few minutes." + send_paranoid_instructions: "If your account exists, you will receive an email with instructions for how to unlock it in a few minutes." + unlocked: "Your account has been unlocked successfully. Please sign in to continue." + errors: + messages: + already_confirmed: "was already confirmed, please try signing in" + confirmation_period_expired: "needs to be confirmed within %{period}, please request a new one" + expired: "has expired, please request a new one" + not_found: "not found" + not_locked: "was not locked" + not_saved: + one: "1 error prohibited this %{resource} from being saved:" + other: "%{count} errors prohibited this %{resource} from being saved:" diff --git a/config/routes.rb b/config/routes.rb index fa9ed98071..f96e9e41d1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,8 @@ Rails.application.routes.draw do + # devise_for :users root 'posts#index' # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html resources :posts + end diff --git a/db/migrate/20220209111804_devise_create_users.rb b/db/migrate/20220209111804_devise_create_users.rb new file mode 100644 index 0000000000..cc0991d9b7 --- /dev/null +++ b/db/migrate/20220209111804_devise_create_users.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +class DeviseCreateUsers < ActiveRecord::Migration[6.1] + def change + create_table :users do |t| + ## Database authenticatable + t.string :email, null: false, default: "" + t.string :encrypted_password, null: false, default: "" + + ## Recoverable + t.string :reset_password_token + t.datetime :reset_password_sent_at + + ## Rememberable + t.datetime :remember_created_at + + ## Trackable + # t.integer :sign_in_count, default: 0, null: false + # t.datetime :current_sign_in_at + # t.datetime :last_sign_in_at + # t.string :current_sign_in_ip + # t.string :last_sign_in_ip + + ## Confirmable + # t.string :confirmation_token + # t.datetime :confirmed_at + # t.datetime :confirmation_sent_at + # t.string :unconfirmed_email # Only if using reconfirmable + + ## Lockable + # t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts + # t.string :unlock_token # Only if unlock strategy is :email or :both + # t.datetime :locked_at + + + t.timestamps null: false + end + + add_index :users, :email, unique: true + add_index :users, :reset_password_token, unique: true + # add_index :users, :confirmation_token, unique: true + # add_index :users, :unlock_token, unique: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 540f5781a6..f0106302c3 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2017_05_26_114520) do +ActiveRecord::Schema.define(version: 2022_02_09_111804) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -21,4 +21,16 @@ t.datetime "updated_at", null: false end + create_table "users", force: :cascade do |t| + t.string "email", default: "", null: false + t.string "encrypted_password", default: "", null: false + t.string "reset_password_token" + t.datetime "reset_password_sent_at" + t.datetime "remember_created_at" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["email"], name: "index_users_on_email", unique: true + t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true + end + end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb new file mode 100644 index 0000000000..47a31bb435 --- /dev/null +++ b/spec/models/user_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe User, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end From fa27c54850f699aa18465639bd9d3454cc872ea0 Mon Sep 17 00:00:00 2001 From: Alexander Jamshidi Date: Wed, 9 Feb 2022 12:40:16 +0000 Subject: [PATCH 06/56] devise working --- README.md | 2 -- config/routes.rb | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index 71aad634b8..072e9e48cb 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,4 @@ and migrate it, ran: rails db:migrate ran: rails routes (to see new routes added) -commented out line: 'devise_for :users' in config/routes.rb (to get website working again) - diff --git a/config/routes.rb b/config/routes.rb index f96e9e41d1..05632d5a25 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,5 @@ Rails.application.routes.draw do - # devise_for :users + devise_for :users root 'posts#index' # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html From 461bc3e3cc1178c3340844481c2ef97d3c064842 Mon Sep 17 00:00:00 2001 From: Alexander Jamshidi Date: Thu, 10 Feb 2022 11:54:12 +0000 Subject: [PATCH 07/56] added temporary links to webpage layout html.erb --- app/views/layouts/application.html.erb | 39 +++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 423bd2ac4f..ccd815b3f7 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -9,8 +9,45 @@ - <%= yield %>

<%= notice %>

<%= alert %>

+ + I am a header + + + <%if user_signed_in? %> + Edit User
+ <% end %> + + Sign In
+ Forgot Password
+ Edit User Password
+ Cancel User Registration
+ Sign Up
+ + + <%= yield %> + + + I am a footer + + \ No newline at end of file From 817b1e47898073225f4de3e24b6c65989c360f07 Mon Sep 17 00:00:00 2001 From: Samir Malik <87937468+smm3000@users.noreply.github.com> Date: Thu, 10 Feb 2022 14:47:57 +0000 Subject: [PATCH 08/56] Update README.md --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 072e9e48cb..d5843e2f47 100644 --- a/README.md +++ b/README.md @@ -63,5 +63,10 @@ ran: rails generate devise user and migrate it, ran: rails db:migrate ran: rails routes (to see new routes added) + +## Mock up design + + +![Welcome!](https://user-images.githubusercontent.com/87937468/153431859-d29a5428-1171-44a5-8850-7afec1a5cd4d.png) From 0de3b499303975c52c53c80f367dea521c01f939 Mon Sep 17 00:00:00 2001 From: Samir Malik <87937468+smm3000@users.noreply.github.com> Date: Thu, 10 Feb 2022 14:48:13 +0000 Subject: [PATCH 09/56] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d5843e2f47..5368edfce4 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ and migrate it, ran: rails db:migrate ran: rails routes (to see new routes added) -## Mock up design +## Mockup Design ![Welcome!](https://user-images.githubusercontent.com/87937468/153431859-d29a5428-1171-44a5-8850-7afec1a5cd4d.png) From 929cdf86c73734f581d3fe2d858bf452e1089727 Mon Sep 17 00:00:00 2001 From: Hannah Desmond Date: Thu, 10 Feb 2022 15:43:48 +0000 Subject: [PATCH 10/56] Add feature tests for welcome page and sign in --- Gemfile.lock | 1 + app/views/posts/index.html.erb | 2 + railsroutes.txt | 51 +++++++++++++++++++++++++ spec/features/users_can_sign_in_spec.rb | 10 +++++ spec/features/welcome_page_spec.rb | 11 ++++++ 5 files changed, 75 insertions(+) create mode 100644 railsroutes.txt create mode 100644 spec/features/users_can_sign_in_spec.rb create mode 100644 spec/features/welcome_page_spec.rb diff --git a/Gemfile.lock b/Gemfile.lock index b715c532a4..079d5374bf 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -211,6 +211,7 @@ GEM PLATFORMS arm64-darwin-21 + ruby DEPENDENCIES byebug diff --git a/app/views/posts/index.html.erb b/app/views/posts/index.html.erb index 8c1a345bff..cdaff521d7 100644 --- a/app/views/posts/index.html.erb +++ b/app/views/posts/index.html.erb @@ -9,6 +9,8 @@ New post <% end %> +<%= link_to "Sign In", new_user_session_path %> + <% @posts.each do |post| %>

<%= post.message %>

<% end %> diff --git a/railsroutes.txt b/railsroutes.txt new file mode 100644 index 0000000000..cff2a3a31f --- /dev/null +++ b/railsroutes.txt @@ -0,0 +1,51 @@ +Prefix Verb URI Pattern Controller#Action + new_user_session GET /users/sign_in(.:format) devise/sessions#new + user_session POST /users/sign_in(.:format) devise/sessions#create + destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy + new_user_password GET /users/password/new(.:format) devise/passwords#new + edit_user_password GET /users/password/edit(.:format) devise/passwords#edit + user_password PATCH /users/password(.:format) devise/passwords#update + PUT /users/password(.:format) devise/passwords#update + POST /users/password(.:format) devise/passwords#create + cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel + new_user_registration GET /users/sign_up(.:format) devise/registrations#new + edit_user_registration GET /users/edit(.:format) devise/registrations#edit + user_registration PATCH /users(.:format) devise/registrations#update + PUT /users(.:format) devise/registrations#update + DELETE /users(.:format) devise/registrations#destroy + POST /users(.:format) devise/registrations#create + root GET / posts#index + posts GET /posts(.:format) posts#index + POST /posts(.:format) posts#create + new_post GET /posts/new(.:format) posts#new + edit_post GET /posts/:id/edit(.:format) posts#edit + post GET /posts/:id(.:format) posts#show + PATCH /posts/:id(.:format) posts#update + PUT /posts/:id(.:format) posts#update + DELETE /posts/:id(.:format) posts#destroy + rails_postmark_inbound_emails POST /rails/action_mailbox/postmark/inbound_emails(.:format) action_mailbox/ingresses/postmark/inbound_emails#create + rails_relay_inbound_emails POST /rails/action_mailbox/relay/inbound_emails(.:format) action_mailbox/ingresses/relay/inbound_emails#create + rails_sendgrid_inbound_emails POST /rails/action_mailbox/sendgrid/inbound_emails(.:format) action_mailbox/ingresses/sendgrid/inbound_emails#create + rails_mandrill_inbound_health_check GET /rails/action_mailbox/mandrill/inbound_emails(.:format) action_mailbox/ingresses/mandrill/inbound_emails#health_check + rails_mandrill_inbound_emails POST /rails/action_mailbox/mandrill/inbound_emails(.:format) action_mailbox/ingresses/mandrill/inbound_emails#create + rails_mailgun_inbound_emails POST /rails/action_mailbox/mailgun/inbound_emails/mime(.:format) action_mailbox/ingresses/mailgun/inbound_emails#create + rails_conductor_inbound_emails GET /rails/conductor/action_mailbox/inbound_emails(.:format) rails/conductor/action_mailbox/inbound_emails#index + POST /rails/conductor/action_mailbox/inbound_emails(.:format) rails/conductor/action_mailbox/inbound_emails#create + new_rails_conductor_inbound_email GET /rails/conductor/action_mailbox/inbound_emails/new(.:format) rails/conductor/action_mailbox/inbound_emails#new + edit_rails_conductor_inbound_email GET /rails/conductor/action_mailbox/inbound_emails/:id/edit(.:format) rails/conductor/action_mailbox/inbound_emails#edit + rails_conductor_inbound_email GET /rails/conductor/action_mailbox/inbound_emails/:id(.:format) rails/conductor/action_mailbox/inbound_emails#show + PATCH /rails/conductor/action_mailbox/inbound_emails/:id(.:format) rails/conductor/action_mailbox/inbound_emails#update + PUT /rails/conductor/action_mailbox/inbound_emails/:id(.:format) rails/conductor/action_mailbox/inbound_emails#update + DELETE /rails/conductor/action_mailbox/inbound_emails/:id(.:format) rails/conductor/action_mailbox/inbound_emails#destroy +new_rails_conductor_inbound_email_source GET /rails/conductor/action_mailbox/inbound_emails/sources/new(.:format) rails/conductor/action_mailbox/inbound_emails/sources#new + rails_conductor_inbound_email_sources POST /rails/conductor/action_mailbox/inbound_emails/sources(.:format) rails/conductor/action_mailbox/inbound_emails/sources#create + rails_conductor_inbound_email_reroute POST /rails/conductor/action_mailbox/:inbound_email_id/reroute(.:format) rails/conductor/action_mailbox/reroutes#create + rails_service_blob GET /rails/active_storage/blobs/redirect/:signed_id/*filename(.:format) active_storage/blobs/redirect#show + rails_service_blob_proxy GET /rails/active_storage/blobs/proxy/:signed_id/*filename(.:format) active_storage/blobs/proxy#show + GET /rails/active_storage/blobs/:signed_id/*filename(.:format) active_storage/blobs/redirect#show + rails_blob_representation GET /rails/active_storage/representations/redirect/:signed_blob_id/:variation_key/*filename(.:format) active_storage/representations/redirect#show + rails_blob_representation_proxy GET /rails/active_storage/representations/proxy/:signed_blob_id/:variation_key/*filename(.:format) active_storage/representations/proxy#show + GET /rails/active_storage/representations/:signed_blob_id/:variation_key/*filename(.:format) active_storage/representations/redirect#show + rails_disk_service GET /rails/active_storage/disk/:encoded_key/*filename(.:format) active_storage/disk#show + update_rails_disk_service PUT /rails/active_storage/disk/:encoded_token(.:format) active_storage/disk#update + rails_direct_uploads POST /rails/active_storage/direct_uploads(.:format) active_storage/direct_uploads#create \ No newline at end of file diff --git a/spec/features/users_can_sign_in_spec.rb b/spec/features/users_can_sign_in_spec.rb new file mode 100644 index 0000000000..5045cf00a4 --- /dev/null +++ b/spec/features/users_can_sign_in_spec.rb @@ -0,0 +1,10 @@ +require 'rails_helper' + +feature 'sign in' do + scenario 'users get to a sign in page' do + visit('/') + click_button("Sign In") + expect(page).to have_content("Email address") + expect(page).to have_content("Remember me") + end +end \ No newline at end of file diff --git a/spec/features/welcome_page_spec.rb b/spec/features/welcome_page_spec.rb new file mode 100644 index 0000000000..4ca833d629 --- /dev/null +++ b/spec/features/welcome_page_spec.rb @@ -0,0 +1,11 @@ +require 'rails_helper' + +feature 'welcome page' do + scenario 'welcome page, not signed in' do + visit('/') + expect(page).to have_content("Sign In") + expect(page).to have_content("Sign Up") + expect(page).to_not have_content("Email address") + expect(page).to_not have_content("Post") + end +end \ No newline at end of file From 1aa5122ab54026fcc3c75251705471921e2c9bb4 Mon Sep 17 00:00:00 2001 From: samir Date: Thu, 10 Feb 2022 16:37:48 +0000 Subject: [PATCH 11/56] Routing Testing --- spec/features/user_can_sign_out_spec.rb | 0 spec/features/users_can_sign_in_spec.rb | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 spec/features/user_can_sign_out_spec.rb diff --git a/spec/features/user_can_sign_out_spec.rb b/spec/features/user_can_sign_out_spec.rb new file mode 100644 index 0000000000..e69de29bb2 diff --git a/spec/features/users_can_sign_in_spec.rb b/spec/features/users_can_sign_in_spec.rb index 5045cf00a4..ca3d5f3e4c 100644 --- a/spec/features/users_can_sign_in_spec.rb +++ b/spec/features/users_can_sign_in_spec.rb @@ -3,7 +3,7 @@ feature 'sign in' do scenario 'users get to a sign in page' do visit('/') - click_button("Sign In") + click_link("Sign In") expect(page).to have_content("Email address") expect(page).to have_content("Remember me") end From 0533acf029a5bb97967451e99ee7835681b9c646 Mon Sep 17 00:00:00 2001 From: Hannah Desmond Date: Fri, 11 Feb 2022 10:33:28 +0000 Subject: [PATCH 12/56] Add if/else statement to application.html.erb --- app/views/layouts/application.html.erb | 7 +++++++ app/views/posts/index.html.erb | 2 +- spec/features/user_can_sign_out_spec.rb | 14 ++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 423bd2ac4f..a1c6f3858f 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -8,6 +8,13 @@ <%= javascript_include_tag 'application' %> + <% if user_signed_in? %> + + <% else %> + <%= link_to "Sign In", new_user_session_path %> + <%= link_to "Sign Up", new_user_registration_path %> + <% end %> + <%= yield %>

<%= notice %>

diff --git a/app/views/posts/index.html.erb b/app/views/posts/index.html.erb index cdaff521d7..c14a3715dc 100644 --- a/app/views/posts/index.html.erb +++ b/app/views/posts/index.html.erb @@ -9,7 +9,7 @@ New post <% end %> -<%= link_to "Sign In", new_user_session_path %> + <% @posts.each do |post| %>

<%= post.message %>

diff --git a/spec/features/user_can_sign_out_spec.rb b/spec/features/user_can_sign_out_spec.rb index e69de29bb2..45bc14d410 100644 --- a/spec/features/user_can_sign_out_spec.rb +++ b/spec/features/user_can_sign_out_spec.rb @@ -0,0 +1,14 @@ +require 'rails_helper' + +feature 'sign out' do + scenario 'signed in users can sign out' do + visit('/') + click_link("Sign In") + sign_in users(:bob) + click_link("Sign Out") + expect(page).to have_content("Sign In") + expect(page).to have_content("Sign Up") + expect(page).to_not have_content("Email address") + expect(page).to_not have_content("Post") + end +end \ No newline at end of file From a290b7360c9511e19bb8e47afcd1a6b30a4001dc Mon Sep 17 00:00:00 2001 From: Alexander Jamshidi Date: Fri, 11 Feb 2022 10:53:45 +0000 Subject: [PATCH 13/56] pre-scaffold (alex) --- app/controllers/posts_controller.rb | 4 ++++ app/controllers/welcome_controller.rb | 2 ++ app/views/layouts/application.html.erb | 1 + app/views/posts/index.html.erb | 1 + app/views/posts/new.html.erb | 2 ++ config/routes.rb | 3 +++ 6 files changed, 13 insertions(+) diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index eac69f98ba..709f7154a4 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -12,6 +12,10 @@ def index @posts = Post.all end + def delete + @post = Post.delete + end + private def post_params diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index d8c85ab84b..f9b859b9c9 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -1,2 +1,4 @@ class WelcomeController < ApplicationController + def index + end end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index ccd815b3f7..08895ac3f9 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -13,6 +13,7 @@

<%= alert %>

I am a header + <%if user_signed_in? %> diff --git a/app/views/posts/index.html.erb b/app/views/posts/index.html.erb index 8c1a345bff..6dd49ab7f6 100644 --- a/app/views/posts/index.html.erb +++ b/app/views/posts/index.html.erb @@ -11,5 +11,6 @@ <% @posts.each do |post| %>

<%= post.message %>

+ <%= post.id %> <% end %> diff --git a/app/views/posts/new.html.erb b/app/views/posts/new.html.erb index 9df305da40..66c44d4ab2 100644 --- a/app/views/posts/new.html.erb +++ b/app/views/posts/new.html.erb @@ -4,3 +4,5 @@ <%= form.submit "Submit" %> <% end %> + + diff --git a/config/routes.rb b/config/routes.rb index 05632d5a25..ec58ff126c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -4,5 +4,8 @@ # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html resources :posts + + get '/welcome/index' + end From e586d06fa6f8ad265bcf104bda0fd87b5e78db5f Mon Sep 17 00:00:00 2001 From: Alexander Jamshidi Date: Fri, 11 Feb 2022 11:14:21 +0000 Subject: [PATCH 14/56] immediately after adding CRUD scaffold (alex) --- app/assets/stylesheets/posts.scss | 3 + app/assets/stylesheets/scaffolds.scss | 65 +++++++++ app/controllers/posts_controller.rb | 64 +++++++-- app/helpers/posts_helper.rb | 2 + app/views/posts/_form.html.erb | 22 +++ app/views/posts/_post.json.jbuilder | 2 + app/views/posts/edit.html.erb | 6 + app/views/posts/index.html.erb | 35 +++-- app/views/posts/index.json.jbuilder | 1 + app/views/posts/new.html.erb | 9 +- app/views/posts/show.html.erb | 9 ++ app/views/posts/show.json.jbuilder | 1 + ...osts.rb => 20220211110733_create_posts.rb} | 2 +- db/schema.rb | 6 +- spec/helpers/posts_helper_spec.rb | 15 ++ spec/models/post_spec.rb | 2 +- spec/requests/posts_spec.rb | 130 ++++++++++++++++++ spec/routing/posts_routing_spec.rb | 38 +++++ spec/views/posts/edit.html.erb_spec.rb | 18 +++ spec/views/posts/index.html.erb_spec.rb | 19 +++ spec/views/posts/new.html.erb_spec.rb | 18 +++ spec/views/posts/show.html.erb_spec.rb | 14 ++ 22 files changed, 449 insertions(+), 32 deletions(-) create mode 100644 app/assets/stylesheets/posts.scss create mode 100644 app/assets/stylesheets/scaffolds.scss create mode 100644 app/helpers/posts_helper.rb create mode 100644 app/views/posts/_form.html.erb create mode 100644 app/views/posts/_post.json.jbuilder create mode 100644 app/views/posts/edit.html.erb create mode 100644 app/views/posts/index.json.jbuilder create mode 100644 app/views/posts/show.html.erb create mode 100644 app/views/posts/show.json.jbuilder rename db/migrate/{20170526114520_create_posts.rb => 20220211110733_create_posts.rb} (68%) create mode 100644 spec/helpers/posts_helper_spec.rb create mode 100644 spec/requests/posts_spec.rb create mode 100644 spec/routing/posts_routing_spec.rb create mode 100644 spec/views/posts/edit.html.erb_spec.rb create mode 100644 spec/views/posts/index.html.erb_spec.rb create mode 100644 spec/views/posts/new.html.erb_spec.rb create mode 100644 spec/views/posts/show.html.erb_spec.rb diff --git a/app/assets/stylesheets/posts.scss b/app/assets/stylesheets/posts.scss new file mode 100644 index 0000000000..92891f7864 --- /dev/null +++ b/app/assets/stylesheets/posts.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the posts controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: https://sass-lang.com/ diff --git a/app/assets/stylesheets/scaffolds.scss b/app/assets/stylesheets/scaffolds.scss new file mode 100644 index 0000000000..bb2597f3fd --- /dev/null +++ b/app/assets/stylesheets/scaffolds.scss @@ -0,0 +1,65 @@ +body { + background-color: #fff; + color: #333; + margin: 33px; } + +body, p, ol, ul, td { + font-family: verdana, arial, helvetica, sans-serif; + font-size: 13px; + line-height: 18px; } + +pre { + background-color: #eee; + padding: 10px; + font-size: 11px; } + +a { + color: #000; } + +a:visited { + color: #666; } + +a:hover { + color: #fff; + background-color: #000; } + +th { + padding-bottom: 5px; } + +td { + padding: 0 5px 7px; } + +div.field, +div.actions { + margin-bottom: 10px; } + +#notice { + color: green; } + +.field_with_errors { + padding: 2px; + background-color: red; + display: table; } + +#error_explanation { + width: 450px; + border: 2px solid red; + padding: 7px 7px 0; + margin-bottom: 20px; + background-color: #f0f0f0; } + +#error_explanation h2 { + text-align: left; + font-weight: bold; + padding: 5px 5px 5px 15px; + font-size: 12px; + margin: -7px -7px 0; + background-color: #c00; + color: #fff; } + +#error_explanation ul li { + font-size: 12px; + list-style: square; } + +label { + display: block; } diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 709f7154a4..985fed72d9 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -1,24 +1,70 @@ class PostsController < ApplicationController + before_action :set_post, only: %i[ show edit update destroy ] + + # GET /posts or /posts.json + def index + @posts = Post.all + end + + # GET /posts/1 or /posts/1.json + def show + end + + # GET /posts/new def new @post = Post.new end + # GET /posts/1/edit + def edit + end + + # POST /posts or /posts.json def create - @post = Post.create(post_params) - redirect_to posts_url + @post = Post.new(post_params) + + respond_to do |format| + if @post.save + format.html { redirect_to post_url(@post), notice: "Post was successfully created." } + format.json { render :show, status: :created, location: @post } + else + format.html { render :new, status: :unprocessable_entity } + format.json { render json: @post.errors, status: :unprocessable_entity } + end + end end - def index - @posts = Post.all + # PATCH/PUT /posts/1 or /posts/1.json + def update + respond_to do |format| + if @post.update(post_params) + format.html { redirect_to post_url(@post), notice: "Post was successfully updated." } + format.json { render :show, status: :ok, location: @post } + else + format.html { render :edit, status: :unprocessable_entity } + format.json { render json: @post.errors, status: :unprocessable_entity } + end + end end - def delete - @post = Post.delete + # DELETE /posts/1 or /posts/1.json + def destroy + @post.destroy + + respond_to do |format| + format.html { redirect_to posts_url, notice: "Post was successfully destroyed." } + format.json { head :no_content } + end end private + # Use callbacks to share common setup or constraints between actions. + def set_post + @post = Post.find(params[:id]) + end - def post_params - params.require(:post).permit(:message) - end + # Only allow a list of trusted parameters through. + def post_params + params.require(:post).permit(:message) + end end diff --git a/app/helpers/posts_helper.rb b/app/helpers/posts_helper.rb new file mode 100644 index 0000000000..a7b8cec898 --- /dev/null +++ b/app/helpers/posts_helper.rb @@ -0,0 +1,2 @@ +module PostsHelper +end diff --git a/app/views/posts/_form.html.erb b/app/views/posts/_form.html.erb new file mode 100644 index 0000000000..5b13927fb1 --- /dev/null +++ b/app/views/posts/_form.html.erb @@ -0,0 +1,22 @@ +<%= form_with(model: post) do |form| %> + <% if post.errors.any? %> +
+

<%= pluralize(post.errors.count, "error") %> prohibited this post from being saved:

+ +
    + <% post.errors.each do |error| %> +
  • <%= error.full_message %>
  • + <% end %> +
+
+ <% end %> + +
+ <%= form.label :message %> + <%= form.text_field :message %> +
+ +
+ <%= form.submit %> +
+<% end %> diff --git a/app/views/posts/_post.json.jbuilder b/app/views/posts/_post.json.jbuilder new file mode 100644 index 0000000000..ebf0978b3a --- /dev/null +++ b/app/views/posts/_post.json.jbuilder @@ -0,0 +1,2 @@ +json.extract! post, :id, :message, :created_at, :updated_at +json.url post_url(post, format: :json) diff --git a/app/views/posts/edit.html.erb b/app/views/posts/edit.html.erb new file mode 100644 index 0000000000..ded33f77ac --- /dev/null +++ b/app/views/posts/edit.html.erb @@ -0,0 +1,6 @@ +

Editing Post

+ +<%= render 'form', post: @post %> + +<%= link_to 'Show', @post %> | +<%= link_to 'Back', posts_path %> diff --git a/app/views/posts/index.html.erb b/app/views/posts/index.html.erb index 6dd49ab7f6..c4a6776cd5 100644 --- a/app/views/posts/index.html.erb +++ b/app/views/posts/index.html.erb @@ -1,16 +1,27 @@ -

- The time is now: <%= Time.now %> -

+

<%= notice %>

-The Gospel
+

Posts

-<%= link_to new_post_path do %> - New post -<% end %> + + + + + + + -<% @posts.each do |post| %> -

<%= post.message %>

- <%= post.id %> -<% end %> + + <% @posts.each do |post| %> + + + + + + + <% end %> + +
Message
<%= post.message %><%= link_to 'Show', post %><%= link_to 'Edit', edit_post_path(post) %><%= link_to 'Destroy', post, method: :delete, data: { confirm: 'Are you sure?' } %>
+
+ +<%= link_to 'New Post', new_post_path %> diff --git a/app/views/posts/index.json.jbuilder b/app/views/posts/index.json.jbuilder new file mode 100644 index 0000000000..a3c6f4a0b0 --- /dev/null +++ b/app/views/posts/index.json.jbuilder @@ -0,0 +1 @@ +json.array! @posts, partial: "posts/post", as: :post diff --git a/app/views/posts/new.html.erb b/app/views/posts/new.html.erb index 66c44d4ab2..fb1e2a1283 100644 --- a/app/views/posts/new.html.erb +++ b/app/views/posts/new.html.erb @@ -1,8 +1,5 @@ -<%= form_for @post do |form| %> - <%= form.label :message %> - <%= form.text_field :message %> - - <%= form.submit "Submit" %> -<% end %> +

New Post

+<%= render 'form', post: @post %> +<%= link_to 'Back', posts_path %> diff --git a/app/views/posts/show.html.erb b/app/views/posts/show.html.erb new file mode 100644 index 0000000000..e1940e1eab --- /dev/null +++ b/app/views/posts/show.html.erb @@ -0,0 +1,9 @@ +

<%= notice %>

+ +

+ Message: + <%= @post.message %> +

+ +<%= link_to 'Edit', edit_post_path(@post) %> | +<%= link_to 'Back', posts_path %> diff --git a/app/views/posts/show.json.jbuilder b/app/views/posts/show.json.jbuilder new file mode 100644 index 0000000000..52744820e6 --- /dev/null +++ b/app/views/posts/show.json.jbuilder @@ -0,0 +1 @@ +json.partial! "posts/post", post: @post diff --git a/db/migrate/20170526114520_create_posts.rb b/db/migrate/20220211110733_create_posts.rb similarity index 68% rename from db/migrate/20170526114520_create_posts.rb rename to db/migrate/20220211110733_create_posts.rb index 9396f2c8b4..1631998827 100644 --- a/db/migrate/20170526114520_create_posts.rb +++ b/db/migrate/20220211110733_create_posts.rb @@ -1,4 +1,4 @@ -class CreatePosts < ActiveRecord::Migration[5.1] +class CreatePosts < ActiveRecord::Migration[6.1] def change create_table :posts do |t| t.string :message diff --git a/db/schema.rb b/db/schema.rb index f0106302c3..292f45ec07 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,15 +10,15 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2022_02_09_111804) do +ActiveRecord::Schema.define(version: 2022_02_11_110733) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" create_table "posts", force: :cascade do |t| t.string "message" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false end create_table "users", force: :cascade do |t| diff --git a/spec/helpers/posts_helper_spec.rb b/spec/helpers/posts_helper_spec.rb new file mode 100644 index 0000000000..f3d00cbcbe --- /dev/null +++ b/spec/helpers/posts_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the PostsHelper. For example: +# +# describe PostsHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe PostsHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index 6220df96ad..f41774c065 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -1,5 +1,5 @@ require 'rails_helper' RSpec.describe Post, type: :model do - it { is_expected.to be } + pending "add some examples to (or delete) #{__FILE__}" end diff --git a/spec/requests/posts_spec.rb b/spec/requests/posts_spec.rb new file mode 100644 index 0000000000..22fc805228 --- /dev/null +++ b/spec/requests/posts_spec.rb @@ -0,0 +1,130 @@ + 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 "/posts", type: :request do + + # Post. As you add validations to Post, be sure to + # adjust the attributes here as well. + let(:valid_attributes) { + skip("Add a hash of attributes valid for your model") + } + + let(:invalid_attributes) { + skip("Add a hash of attributes invalid for your model") + } + + describe "GET /index" do + it "renders a successful response" do + Post.create! valid_attributes + get posts_url + expect(response).to be_successful + end + end + + describe "GET /show" do + it "renders a successful response" do + post = Post.create! valid_attributes + get post_url(post) + expect(response).to be_successful + end + end + + describe "GET /new" do + it "renders a successful response" do + get new_post_url + expect(response).to be_successful + end + end + + describe "GET /edit" do + it "render a successful response" do + post = Post.create! valid_attributes + get edit_post_url(post) + expect(response).to be_successful + end + end + + describe "POST /create" do + context "with valid parameters" do + it "creates a new Post" do + expect { + post posts_url, params: { post: valid_attributes } + }.to change(Post, :count).by(1) + end + + it "redirects to the created post" do + post posts_url, params: { post: valid_attributes } + expect(response).to redirect_to(post_url(Post.last)) + end + end + + context "with invalid parameters" do + it "does not create a new Post" do + expect { + post posts_url, params: { post: invalid_attributes } + }.to change(Post, :count).by(0) + end + + it "renders a successful response (i.e. to display the 'new' template)" do + post posts_url, params: { post: invalid_attributes } + expect(response).to be_successful + end + end + end + + describe "PATCH /update" do + context "with valid parameters" do + let(:new_attributes) { + skip("Add a hash of attributes valid for your model") + } + + it "updates the requested post" do + post = Post.create! valid_attributes + patch post_url(post), params: { post: new_attributes } + post.reload + skip("Add assertions for updated state") + end + + it "redirects to the post" do + post = Post.create! valid_attributes + patch post_url(post), params: { post: new_attributes } + post.reload + expect(response).to redirect_to(post_url(post)) + end + end + + context "with invalid parameters" do + it "renders a successful response (i.e. to display the 'edit' template)" do + post = Post.create! valid_attributes + patch post_url(post), params: { post: invalid_attributes } + expect(response).to be_successful + end + end + end + + describe "DELETE /destroy" do + it "destroys the requested post" do + post = Post.create! valid_attributes + expect { + delete post_url(post) + }.to change(Post, :count).by(-1) + end + + it "redirects to the posts list" do + post = Post.create! valid_attributes + delete post_url(post) + expect(response).to redirect_to(posts_url) + end + end +end diff --git a/spec/routing/posts_routing_spec.rb b/spec/routing/posts_routing_spec.rb new file mode 100644 index 0000000000..a76fa57521 --- /dev/null +++ b/spec/routing/posts_routing_spec.rb @@ -0,0 +1,38 @@ +require "rails_helper" + +RSpec.describe PostsController, type: :routing do + describe "routing" do + it "routes to #index" do + expect(get: "/posts").to route_to("posts#index") + end + + it "routes to #new" do + expect(get: "/posts/new").to route_to("posts#new") + end + + it "routes to #show" do + expect(get: "/posts/1").to route_to("posts#show", id: "1") + end + + it "routes to #edit" do + expect(get: "/posts/1/edit").to route_to("posts#edit", id: "1") + end + + + it "routes to #create" do + expect(post: "/posts").to route_to("posts#create") + end + + it "routes to #update via PUT" do + expect(put: "/posts/1").to route_to("posts#update", id: "1") + end + + it "routes to #update via PATCH" do + expect(patch: "/posts/1").to route_to("posts#update", id: "1") + end + + it "routes to #destroy" do + expect(delete: "/posts/1").to route_to("posts#destroy", id: "1") + end + end +end diff --git a/spec/views/posts/edit.html.erb_spec.rb b/spec/views/posts/edit.html.erb_spec.rb new file mode 100644 index 0000000000..7717735166 --- /dev/null +++ b/spec/views/posts/edit.html.erb_spec.rb @@ -0,0 +1,18 @@ +require 'rails_helper' + +RSpec.describe "posts/edit", type: :view do + before(:each) do + @post = assign(:post, Post.create!( + message: "MyString" + )) + end + + it "renders the edit post form" do + render + + assert_select "form[action=?][method=?]", post_path(@post), "post" do + + assert_select "input[name=?]", "post[message]" + end + end +end diff --git a/spec/views/posts/index.html.erb_spec.rb b/spec/views/posts/index.html.erb_spec.rb new file mode 100644 index 0000000000..817e835ff0 --- /dev/null +++ b/spec/views/posts/index.html.erb_spec.rb @@ -0,0 +1,19 @@ +require 'rails_helper' + +RSpec.describe "posts/index", type: :view do + before(:each) do + assign(:posts, [ + Post.create!( + message: "Message" + ), + Post.create!( + message: "Message" + ) + ]) + end + + it "renders a list of posts" do + render + assert_select "tr>td", text: "Message".to_s, count: 2 + end +end diff --git a/spec/views/posts/new.html.erb_spec.rb b/spec/views/posts/new.html.erb_spec.rb new file mode 100644 index 0000000000..516ee5cb03 --- /dev/null +++ b/spec/views/posts/new.html.erb_spec.rb @@ -0,0 +1,18 @@ +require 'rails_helper' + +RSpec.describe "posts/new", type: :view do + before(:each) do + assign(:post, Post.new( + message: "MyString" + )) + end + + it "renders new post form" do + render + + assert_select "form[action=?][method=?]", posts_path, "post" do + + assert_select "input[name=?]", "post[message]" + end + end +end diff --git a/spec/views/posts/show.html.erb_spec.rb b/spec/views/posts/show.html.erb_spec.rb new file mode 100644 index 0000000000..863cc104ad --- /dev/null +++ b/spec/views/posts/show.html.erb_spec.rb @@ -0,0 +1,14 @@ +require 'rails_helper' + +RSpec.describe "posts/show", type: :view do + before(:each) do + @post = assign(:post, Post.create!( + message: "Message" + )) + end + + it "renders attributes in

" do + render + expect(rendered).to match(/Message/) + end +end From 56ebe778eb411e80981a7b6632e054149acfaf3f Mon Sep 17 00:00:00 2001 From: Hannah Desmond Date: Fri, 11 Feb 2022 12:20:47 +0000 Subject: [PATCH 15/56] Add sign up, sign in, and sign out links --- app/views/layouts/application.html.erb | 3 ++- spec/features/user_can_sign_out_spec.rb | 12 ++++++------ spec/features/users_can_sign_in_spec.rb | 12 +++++++++++- spec/spec_helper.rb | 8 ++++++++ 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index a1c6f3858f..9e66042df7 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -9,7 +9,8 @@ <% if user_signed_in? %> - + <%= link_to "Sign Out", destroy_user_session_path, method: :delete %> + <% else %> <%= link_to "Sign In", new_user_session_path %> <%= link_to "Sign Up", new_user_registration_path %> diff --git a/spec/features/user_can_sign_out_spec.rb b/spec/features/user_can_sign_out_spec.rb index 45bc14d410..d89f55ca58 100644 --- a/spec/features/user_can_sign_out_spec.rb +++ b/spec/features/user_can_sign_out_spec.rb @@ -3,12 +3,12 @@ feature 'sign out' do scenario 'signed in users can sign out' do visit('/') - click_link("Sign In") - sign_in users(:bob) + click_link("Sign Up") + fill_in("user_email", with: "hello@hello.com") + fill_in("user_password", with: "123456") + fill_in("user_password_confirmation", with: "123456") + click_button("Sign up") click_link("Sign Out") - expect(page).to have_content("Sign In") - expect(page).to have_content("Sign Up") - expect(page).to_not have_content("Email address") - expect(page).to_not have_content("Post") + expect("Signed out successfully.") end end \ No newline at end of file diff --git a/spec/features/users_can_sign_in_spec.rb b/spec/features/users_can_sign_in_spec.rb index ca3d5f3e4c..882bb917a9 100644 --- a/spec/features/users_can_sign_in_spec.rb +++ b/spec/features/users_can_sign_in_spec.rb @@ -4,7 +4,17 @@ scenario 'users get to a sign in page' do visit('/') click_link("Sign In") - expect(page).to have_content("Email address") + # expect to see the form + expect(page).to have_content("Email") expect(page).to have_content("Remember me") end + scenario 'user is signed in after filling in form' do + sign_up + click_link("Sign Out") + click_link("Sign In") + fill_in("user_email", with: "hello@hello.com") + fill_in("user_password", with: "123456") + click_button("Log in") + expect(page).to have_content("Signed in successfully.") + end end \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 8f698be460..f085ce40e5 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -97,3 +97,11 @@ Kernel.srand config.seed =end end +def sign_up + visit('/') + click_link("Sign Up") + fill_in("user_email", with: "hello@hello.com") + fill_in("user_password", with: "123456") + fill_in("user_password_confirmation", with: "123456") + click_button("Sign up") +end From b28066b73ff20cdccf8694ef1b4f240fe0b0fdea Mon Sep 17 00:00:00 2001 From: samir Date: Fri, 11 Feb 2022 16:36:25 +0000 Subject: [PATCH 16/56] Draft Navbar added --- Gemfile | 5 +++ Gemfile.lock | 35 +++++++++++++++---- app/assets/config/manifest.js | 1 + app/assets/javascripts/application.js | 3 ++ .../{application.css => application.scss} | 4 +-- app/views/layouts/application.html.erb | 27 ++++++++++++-- spec/rails_helper.rb | 5 ++- 7 files changed, 68 insertions(+), 12 deletions(-) rename app/assets/stylesheets/{application.css => application.scss} (94%) diff --git a/Gemfile b/Gemfile index 1076c40009..a3bf6df1c7 100644 --- a/Gemfile +++ b/Gemfile @@ -30,6 +30,11 @@ gem 'jbuilder', '~> 2.5' gem 'devise', '~> 4.8', '>= 4.8.1' +gem 'bootstrap', '~> 5.1.3' + +gem 'jquery-rails' +gem 'turbolinks' + group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] diff --git a/Gemfile.lock b/Gemfile.lock index 079d5374bf..df04436037 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -62,8 +62,14 @@ GEM zeitwerk (~> 2.3) addressable (2.8.0) public_suffix (>= 2.0.2, < 5.0) + autoprefixer-rails (10.4.2.0) + execjs (~> 2) bcrypt (3.1.16) bindex (0.8.1) + bootstrap (5.1.3) + autoprefixer-rails (>= 9.1.0) + popper_js (>= 2.9.3, < 3) + sassc-rails (>= 2.0.0) builder (3.2.4) byebug (11.1.3) capybara (2.18.0) @@ -93,6 +99,10 @@ GEM jbuilder (2.11.5) actionview (>= 5.0.0) activesupport (>= 5.0.0) + jquery-rails (4.4.0) + rails-dom-testing (>= 1, < 3) + railties (>= 4.2.0) + thor (>= 0.14, < 2.0) listen (3.0.8) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) @@ -104,12 +114,17 @@ GEM marcel (1.0.2) method_source (1.0.0) mini_mime (1.1.2) + mini_portile2 (2.7.1) minitest (5.15.0) nio4r (2.5.8) + nokogiri (1.13.1) + mini_portile2 (~> 2.7.0) + racc (~> 1.4) nokogiri (1.13.1-arm64-darwin) racc (~> 1.4) orm_adapter (0.5.0) pg (1.3.1) + popper_js (2.9.3) public_suffix (4.0.6) puma (3.12.6) racc (1.6.0) @@ -150,14 +165,14 @@ GEM actionpack (>= 5.0) railties (>= 5.0) rexml (3.2.5) - rspec-core (3.10.2) - rspec-support (~> 3.10.0) - rspec-expectations (3.10.2) + rspec-core (3.11.0) + rspec-support (~> 3.11.0) + rspec-expectations (3.11.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.10.0) - rspec-mocks (3.10.3) + rspec-support (~> 3.11.0) + rspec-mocks (3.11.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.10.0) + rspec-support (~> 3.11.0) rspec-rails (4.1.2) actionpack (>= 4.2) activesupport (>= 4.2) @@ -166,7 +181,7 @@ GEM rspec-expectations (~> 3.10) rspec-mocks (~> 3.10) rspec-support (~> 3.10) - rspec-support (3.10.3) + rspec-support (3.11.0) rubyzip (2.3.2) sass-rails (6.0.0) sassc-rails (~> 2.1, >= 2.1.1) @@ -191,6 +206,9 @@ GEM sprockets (>= 3.0.0) thor (1.2.1) tilt (2.0.10) + turbolinks (5.2.1) + turbolinks-source (~> 5.2) + turbolinks-source (5.2.0) tzinfo (2.0.4) concurrent-ruby (~> 1.0) uglifier (4.2.0) @@ -214,10 +232,12 @@ PLATFORMS ruby DEPENDENCIES + bootstrap (~> 5.1.3) byebug capybara (~> 2.13) devise (~> 4.8, >= 4.8.1) jbuilder (~> 2.5) + jquery-rails listen (>= 3.0.5, < 3.2) pg puma (~> 3.12.6) @@ -225,6 +245,7 @@ DEPENDENCIES rspec-rails (~> 4) sass-rails (~> 6.0) selenium-webdriver + turbolinks tzinfo-data uglifier (>= 1.3.0) web-console (>= 3.3.0) diff --git a/app/assets/config/manifest.js b/app/assets/config/manifest.js index b16e53d6d5..fce40d66c2 100644 --- a/app/assets/config/manifest.js +++ b/app/assets/config/manifest.js @@ -1,3 +1,4 @@ //= link_tree ../images //= link_directory ../javascripts .js //= link_directory ../stylesheets .css + //= link application.css diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 504211ea69..e4ccf16808 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -12,3 +12,6 @@ // //= require rails-ujs //= require_tree . +//= require jquery3 +//= require popper +//= require bootstrap-sprockets \ No newline at end of file diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.scss similarity index 94% rename from app/assets/stylesheets/application.css rename to app/assets/stylesheets/application.scss index d05ea0f511..97d3731a2c 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.scss @@ -10,6 +10,6 @@ * files in this directory. Styles in this file should be added after the last require_* statement. * It is generally better to create a new file per style scope. * - *= require_tree . - *= require_self */ + + @import "bootstrap"; diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 9e66042df7..31149f0b8f 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -4,8 +4,31 @@ Acebook <%= csrf_meta_tags %> - <%= stylesheet_link_tag 'application', media: 'all' %> - <%= javascript_include_tag 'application' %> + <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> + <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> + +

<% if user_signed_in? %> diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 6f1ab14638..4f62f6b814 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -34,6 +34,9 @@ # examples within a transaction, remove the following line or assign false # instead of true. config.use_transactional_fixtures = true + config.include Devise::Test::ControllerHelpers, type: :controller + config.include Devise::Test::ControllerHelpers, type: :view + config.include Devise::Test::IntegrationHelpers, type: :feature # RSpec Rails can automatically mix in different behaviours to your tests # based on their file location, for example enabling you to call `get` and @@ -54,4 +57,4 @@ config.filter_rails_from_backtrace! # arbitrary gems may also be filtered via: # config.filter_gems_from_backtrace("gem name") -end +end \ No newline at end of file From a0a7a06fbcf904f185a454f75079d9c05c789523 Mon Sep 17 00:00:00 2001 From: Alexander Jamshidi Date: Fri, 11 Feb 2022 17:11:25 +0000 Subject: [PATCH 17/56] if not signed in, users will be redirected to sign-in page. and added temporary signout link to layout view --- app/controllers/posts_controller.rb | 1 + app/views/layouts/application.html.erb | 5 +++-- app/views/posts/index.html.erb | 2 +- config/database.yml | 2 +- config/routes.rb | 8 +++----- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 985fed72d9..2f1582526c 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -1,5 +1,6 @@ class PostsController < ApplicationController before_action :set_post, only: %i[ show edit update destroy ] + before_action :authenticate_user! # GET /posts or /posts.json def index diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 08895ac3f9..dd9c18746e 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -14,12 +14,13 @@ I am a header - - + <%if user_signed_in? %> + <%= link_to 'sign out', destroy_user_session_path, method: :delete %>
Edit User
<% end %> + Sign In
Forgot Password
Edit User Password
diff --git a/app/views/posts/index.html.erb b/app/views/posts/index.html.erb index c4a6776cd5..dedcee24b4 100644 --- a/app/views/posts/index.html.erb +++ b/app/views/posts/index.html.erb @@ -11,7 +11,7 @@ - <% @posts.each do |post| %> + <% @posts.reverse.each do |post| %> <%= post.message %> <%= link_to 'Show', post %> diff --git a/config/database.yml b/config/database.yml index d56e9768d5..ea90643c33 100644 --- a/config/database.yml +++ b/config/database.yml @@ -80,6 +80,6 @@ test: # production: <<: *default - database: pgapp_production + database: _production username: pgapp password: <%= ENV['PGAPP_DATABASE_PASSWORD'] %> diff --git a/config/routes.rb b/config/routes.rb index ec58ff126c..0d08e975e2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,11 +1,9 @@ Rails.application.routes.draw do - devise_for :users + root 'posts#index' # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html - - resources :posts - get '/welcome/index' - + resources :posts + devise_for :users end From f80247e9bd847ea90868419ab07403f0296a7f64 Mon Sep 17 00:00:00 2001 From: Alexander Jamshidi Date: Fri, 11 Feb 2022 17:28:20 +0000 Subject: [PATCH 18/56] rubocop and simplecov added --- .gitignore | 2 +- Gemfile | 8 + Gemfile.lock | 41 ++ coverage/.resultset.json | 1081 +++++++++++++++++++++++++++++++++ coverage/.resultset.json.lock | 0 spec/spec_helper.rb | 18 + 6 files changed, 1149 insertions(+), 1 deletion(-) create mode 100644 coverage/.resultset.json create mode 100644 coverage/.resultset.json.lock diff --git a/.gitignore b/.gitignore index f6013e7ae2..515d1fbdc9 100644 --- a/.gitignore +++ b/.gitignore @@ -21,4 +21,4 @@ /yarn-error.log .byebug_history -.env +.env \ No newline at end of file diff --git a/Gemfile b/Gemfile index 1076c40009..2a2b55f340 100644 --- a/Gemfile +++ b/Gemfile @@ -43,7 +43,15 @@ group :development do # Access an IRB console on exception pages or by using <%= console %> anywhere in the code. gem 'web-console', '>= 3.3.0' gem 'listen', '>= 3.0.5', '< 3.2' + gem 'rubocop', '1.20' +end + +group :test do + gem 'rspec' + gem 'simplecov', require: false + gem 'simplecov-console', require: false end # Windows does not include zoneinfo files, so bundle the tzinfo-data gem gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] + diff --git a/Gemfile.lock b/Gemfile.lock index b715c532a4..74b43990f5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -62,6 +62,8 @@ GEM zeitwerk (~> 2.3) addressable (2.8.0) public_suffix (>= 2.0.2, < 5.0) + ansi (1.5.0) + ast (2.4.2) bcrypt (3.1.16) bindex (0.8.1) builder (3.2.4) @@ -83,6 +85,7 @@ GEM responders warden (~> 1.2.3) diff-lcs (1.5.0) + docile (1.4.0) erubi (1.10.0) execjs (2.8.1) ffi (1.15.5) @@ -109,6 +112,9 @@ GEM nokogiri (1.13.1-arm64-darwin) racc (~> 1.4) orm_adapter (0.5.0) + parallel (1.21.0) + parser (3.1.0.0) + ast (~> 2.4.1) pg (1.3.1) public_suffix (4.0.6) puma (3.12.6) @@ -142,14 +148,20 @@ GEM method_source rake (>= 0.13) thor (~> 1.0) + rainbow (3.1.1) rake (13.0.6) rb-fsevent (0.11.1) rb-inotify (0.10.1) ffi (~> 1.0) + regexp_parser (2.2.0) responders (3.0.1) actionpack (>= 5.0) railties (>= 5.0) rexml (3.2.5) + rspec (3.10.0) + rspec-core (~> 3.10.0) + rspec-expectations (~> 3.10.0) + rspec-mocks (~> 3.10.0) rspec-core (3.10.2) rspec-support (~> 3.10.0) rspec-expectations (3.10.2) @@ -167,6 +179,18 @@ GEM rspec-mocks (~> 3.10) rspec-support (~> 3.10) rspec-support (3.10.3) + rubocop (1.20.0) + parallel (~> 1.10) + parser (>= 3.0.0.0) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8, < 3.0) + rexml + rubocop-ast (>= 1.9.1, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 1.4.0, < 3.0) + rubocop-ast (1.15.1) + parser (>= 3.0.1.1) + ruby-progressbar (1.11.0) rubyzip (2.3.2) sass-rails (6.0.0) sassc-rails (~> 2.1, >= 2.1.1) @@ -182,6 +206,16 @@ GEM childprocess (>= 0.5, < 5.0) rexml (~> 3.2, >= 3.2.5) rubyzip (>= 1.2.2) + simplecov (0.21.2) + docile (~> 1.1) + simplecov-html (~> 0.11) + simplecov_json_formatter (~> 0.1) + simplecov-console (0.9.1) + ansi + simplecov + terminal-table + simplecov-html (0.12.3) + simplecov_json_formatter (0.1.3) sprockets (4.0.2) concurrent-ruby (~> 1.0) rack (> 1, < 3) @@ -189,12 +223,15 @@ GEM actionpack (>= 5.2) activesupport (>= 5.2) sprockets (>= 3.0.0) + terminal-table (3.0.2) + unicode-display_width (>= 1.1.1, < 3) thor (1.2.1) tilt (2.0.10) tzinfo (2.0.4) concurrent-ruby (~> 1.0) uglifier (4.2.0) execjs (>= 0.3.0, < 3) + unicode-display_width (2.1.0) warden (1.2.9) rack (>= 2.0.9) web-console (4.2.0) @@ -221,9 +258,13 @@ DEPENDENCIES pg puma (~> 3.12.6) rails (~> 6.1.0) + rspec rspec-rails (~> 4) + rubocop (= 1.20) sass-rails (~> 6.0) selenium-webdriver + simplecov + simplecov-console tzinfo-data uglifier (>= 1.3.0) web-console (>= 3.3.0) diff --git a/coverage/.resultset.json b/coverage/.resultset.json new file mode 100644 index 0000000000..71af53a0fd --- /dev/null +++ b/coverage/.resultset.json @@ -0,0 +1,1081 @@ +{ + "RSpec": { + "coverage": { + "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/spec/controllers/posts_controller_spec.rb": { + "lines": [ + 1, + null, + 1, + 1, + 1, + 1, + 0, + null, + null, + null, + 1, + 1, + 1, + 0, + null, + null, + 1, + 1, + 0, + null, + null, + null, + 1, + 1, + 1, + 0, + null, + null, + null + ] + }, + "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/spec/rails_helper.rb": { + "lines": [ + null, + 1, + 1, + null, + 1, + 1, + 1, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + 1, + null, + 1, + null, + 1, + null, + null, + null, + null, + 1, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + 1, + null, + null, + 1, + null, + null, + null + ] + }, + "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/config/environment.rb": { + "lines": [ + null, + 1, + null, + null, + 1 + ] + }, + "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/config/application.rb": { + "lines": [ + 1, + null, + 1, + null, + null, + null, + 1, + null, + 1, + 1, + null, + 1, + null, + null, + null, + null, + null, + null + ] + }, + "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/config/boot.rb": { + "lines": [ + 1, + null, + 1 + ] + }, + "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/config/environments/test.rb": { + "lines": [ + 1, + null, + null, + null, + null, + null, + null, + 1, + null, + null, + null, + null, + 1, + null, + null, + 1, + 1, + null, + null, + null, + null, + 1, + 1, + null, + null, + 1, + null, + null, + 1, + 1, + null, + null, + null, + null, + 1, + null, + null, + 1, + null, + null, + null, + null + ] + }, + "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/config/initializers/application_controller_renderer.rb": { + "lines": [ + null, + null, + null, + null, + null, + null + ] + }, + "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/config/initializers/assets.rb": { + "lines": [ + null, + null, + null, + 1, + null, + null, + null, + null, + 1, + null, + null, + null, + null, + null + ] + }, + "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/config/initializers/backtrace_silencers.rb": { + "lines": [ + null, + null, + null, + null, + null, + null, + null + ] + }, + "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/config/initializers/cookies_serializer.rb": { + "lines": [ + null, + null, + null, + null, + 1 + ] + }, + "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/config/initializers/devise.rb": { + "lines": [ + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + 1, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + 1, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + 1, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + 1, + null, + null, + null, + null, + 1, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + 1, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + 1, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + 1, + null, + null, + null, + null, + null, + null, + null, + null, + null, + 1, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + 1, + null, + null, + null, + null, + 1, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + 1, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + 1, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null + ] + }, + "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/config/initializers/filter_parameter_logging.rb": { + "lines": [ + null, + null, + null, + 1 + ] + }, + "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/config/initializers/inflections.rb": { + "lines": [ + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null + ] + }, + "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/config/initializers/mime_types.rb": { + "lines": [ + null, + null, + null, + null + ] + }, + "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/config/initializers/wrap_parameters.rb": { + "lines": [ + null, + null, + null, + null, + null, + null, + 1, + 2, + null, + null, + null, + null, + null, + null + ] + }, + "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/config/routes.rb": { + "lines": [ + 1, + null, + 1, + null, + 1, + null, + 1, + 1, + null + ] + }, + "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/app/models/user.rb": { + "lines": [ + 1, + null, + null, + 1, + null, + null + ] + }, + "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/app/models/application_record.rb": { + "lines": [ + 1, + 1, + null + ] + }, + "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/app/helpers/application_helper.rb": { + "lines": [ + 1, + null + ] + }, + "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/app/helpers/posts_helper.rb": { + "lines": [ + 1, + null + ] + }, + "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/app/helpers/welcome_helper.rb": { + "lines": [ + 1, + null + ] + }, + "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/app/controllers/posts_controller.rb": { + "lines": [ + 1, + 1, + 1, + null, + null, + 1, + 0, + null, + null, + null, + 1, + null, + null, + null, + 1, + 0, + null, + null, + null, + 1, + null, + null, + null, + 1, + 0, + null, + 0, + 0, + 0, + 0, + null, + 0, + 0, + null, + null, + null, + null, + null, + 1, + 0, + 0, + 0, + 0, + null, + 0, + 0, + null, + null, + null, + null, + null, + 1, + 0, + null, + 0, + 0, + 0, + null, + null, + null, + 1, + null, + 1, + 0, + null, + null, + null, + 1, + 0, + null, + null + ] + }, + "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/app/controllers/application_controller.rb": { + "lines": [ + 1, + 1, + null + ] + }, + "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/spec/features/user_can_submit_posts_spec.rb": { + "lines": [ + 1, + null, + 1, + 1, + 1, + 1, + 0, + 0, + 0, + null, + null + ] + }, + "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/spec/helpers/posts_helper_spec.rb": { + "lines": [ + 1, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + 1, + 1, + null + ] + }, + "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/spec/helpers/welcome_helper_spec.rb": { + "lines": [ + 1, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + 1, + 1, + null + ] + }, + "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/spec/models/post_spec.rb": { + "lines": [ + 1, + null, + 1, + 1, + null + ] + }, + "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/app/models/post.rb": { + "lines": [ + 1, + null + ] + }, + "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/spec/models/user_spec.rb": { + "lines": [ + 1, + null, + 1, + 1, + null + ] + }, + "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/spec/requests/posts_spec.rb": { + "lines": [ + 1, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + 1, + null, + null, + null, + 1, + 10, + null, + null, + 1, + 2, + null, + null, + 1, + 1, + 1, + 0, + 0, + null, + null, + null, + 1, + 1, + 1, + 0, + 0, + null, + null, + null, + 1, + 1, + 1, + 1, + null, + null, + null, + 1, + 1, + 1, + 0, + 0, + null, + null, + null, + 1, + 1, + 1, + 1, + 1, + null, + null, + null, + 1, + 1, + 0, + null, + null, + null, + 1, + 1, + 1, + 1, + null, + null, + null, + 1, + 1, + 0, + null, + null, + null, + null, + 1, + 1, + 1, + 0, + null, + null, + 1, + 1, + 0, + 0, + 0, + null, + null, + 1, + 1, + 0, + 0, + 0, + null, + null, + null, + 1, + 1, + 1, + 0, + 0, + null, + null, + null, + null, + 1, + 1, + 1, + 0, + 0, + null, + null, + null, + 1, + 1, + 0, + 0, + null, + null, + null + ] + }, + "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/spec/requests/welcome_spec.rb": { + "lines": [ + 1, + null, + 1, + 1, + 1, + null, + null + ] + }, + "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/spec/routing/posts_routing_spec.rb": { + "lines": [ + 1, + null, + 1, + 1, + 1, + 1, + null, + null, + 1, + 1, + null, + null, + 1, + 1, + null, + null, + 1, + 1, + null, + null, + null, + 1, + 1, + null, + null, + 1, + 1, + null, + null, + 1, + 1, + null, + null, + 1, + 1, + null, + null, + null + ] + }, + "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/spec/views/posts/edit.html.erb_spec.rb": { + "lines": [ + 1, + null, + 1, + 1, + 1, + null, + null, + null, + null, + 1, + 1, + null, + 1, + null, + 1, + null, + null, + null + ] + }, + "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/spec/views/posts/index.html.erb_spec.rb": { + "lines": [ + 1, + null, + 1, + 1, + 1, + null, + null, + null, + null, + null, + null, + null, + null, + null, + 1, + 1, + 1, + null, + null + ] + }, + "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/spec/views/posts/new.html.erb_spec.rb": { + "lines": [ + 1, + null, + 1, + 1, + 1, + null, + null, + null, + null, + 1, + 1, + null, + 1, + null, + 1, + null, + null, + null + ] + }, + "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/spec/views/posts/show.html.erb_spec.rb": { + "lines": [ + 1, + null, + 1, + 1, + 1, + null, + null, + null, + null, + 1, + 1, + 1, + null, + null + ] + } + }, + "timestamp": 1644600425 + } +} diff --git a/coverage/.resultset.json.lock b/coverage/.resultset.json.lock new file mode 100644 index 0000000000..e69de29bb2 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 8f698be460..fbf985bcff 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,21 @@ +require 'simplecov' +require 'simplecov-console' + +SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([ + SimpleCov::Formatter::Console, + # Want a nice code coverage website? Uncomment this next line! + # SimpleCov::Formatter::HTMLFormatter +]) +SimpleCov.start + +RSpec.configure do |config| + config.after(:suite) do + puts + puts "\e[33mHave you considered running rubocop? It will help you improve your code!\e[0m" + puts "\e[33mTry it now! Just run: rubocop\e[0m" + end +end + # This file was generated by the `rails generate rspec:install` command. Conventionally, all # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. # The generated `.rspec` file contains `--require spec_helper` which will cause From 3af36451e41b9ace877a15a344484aa9709e1f17 Mon Sep 17 00:00:00 2001 From: Hannah Desmond Date: Fri, 11 Feb 2022 17:28:25 +0000 Subject: [PATCH 19/56] Add Nav bar with sign up, sign in and sign out --- Gemfile.lock | 10 ++---- app/views/layouts/application.html.erb | 50 ++++++++++++++------------ app/views/welcome/index.html.erb | 3 +- config/routes.rb | 2 +- 4 files changed, 33 insertions(+), 32 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index df04436037..5dcaad0691 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -114,13 +114,9 @@ GEM marcel (1.0.2) method_source (1.0.0) mini_mime (1.1.2) - mini_portile2 (2.7.1) minitest (5.15.0) nio4r (2.5.8) - nokogiri (1.13.1) - mini_portile2 (~> 2.7.0) - racc (~> 1.4) - nokogiri (1.13.1-arm64-darwin) + nokogiri (1.13.1-x86_64-darwin) racc (~> 1.4) orm_adapter (0.5.0) pg (1.3.1) @@ -228,8 +224,8 @@ GEM zeitwerk (2.5.4) PLATFORMS - arm64-darwin-21 ruby + x86_64-darwin-19 DEPENDENCIES bootstrap (~> 5.1.3) @@ -251,4 +247,4 @@ DEPENDENCIES web-console (>= 3.3.0) BUNDLED WITH - 2.2.33 + 2.2.3 diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 31149f0b8f..4ff6cae001 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -4,42 +4,46 @@ Acebook <%= csrf_meta_tags %> - <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> - <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> + <%= stylesheet_link_tag 'application', media: 'all' %> + <%= javascript_include_tag 'application' %> + + + + + + + + + + + + - - - <% if user_signed_in? %> - <%= link_to "Sign Out", destroy_user_session_path, method: :delete %> - - <% else %> - <%= link_to "Sign In", new_user_session_path %> - <%= link_to "Sign Up", new_user_registration_path %> - <% end %> - - <%= yield %>

<%= notice %>

<%= alert %>

diff --git a/app/views/welcome/index.html.erb b/app/views/welcome/index.html.erb index d1441cea3f..b0f7999b2a 100644 --- a/app/views/welcome/index.html.erb +++ b/app/views/welcome/index.html.erb @@ -1,4 +1,5 @@ -

Hello World

+

Welcome to Acebook

+

Sign up or Sign in so we can harvest your precious data

The time is now: <%= Time.now %>

\ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 05632d5a25..85687dbe8c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,6 @@ Rails.application.routes.draw do devise_for :users - root 'posts#index' + root 'welcome#index' # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html resources :posts From c2c9367e1a2fbc6e48e204a7b85de90a7f795248 Mon Sep 17 00:00:00 2001 From: Alexander Jamshidi Date: Fri, 11 Feb 2022 17:29:51 +0000 Subject: [PATCH 20/56] ran rubocop, fixed 250ish offences --- Gemfile | 11 +- Rakefile | 2 + app/channels/application_cable/channel.rb | 2 + app/channels/application_cable/connection.rb | 2 + app/controllers/application_controller.rb | 2 + app/controllers/posts_controller.rb | 33 +++--- app/controllers/welcome_controller.rb | 5 +- app/helpers/application_helper.rb | 2 + app/helpers/posts_helper.rb | 2 + app/helpers/welcome_helper.rb | 2 + app/jobs/application_job.rb | 2 + app/mailers/application_mailer.rb | 2 + app/models/application_record.rb | 2 + app/models/post.rb | 2 + app/models/user.rb | 2 + app/views/posts/_post.json.jbuilder | 2 + app/views/posts/index.json.jbuilder | 4 +- app/views/posts/show.json.jbuilder | 4 +- bin/bundle | 4 +- bin/rails | 2 + bin/rake | 2 + bin/setup | 5 +- bin/update | 4 +- bin/yarn | 14 +-- config.ru | 2 + config/application.rb | 2 + config/boot.rb | 2 + config/environment.rb | 2 + config/environments/development.rb | 2 + config/environments/production.rb | 8 +- config/environments/test.rb | 2 + .../application_controller_renderer.rb | 1 + config/initializers/assets.rb | 2 + config/initializers/backtrace_silencers.rb | 1 + config/initializers/cookies_serializer.rb | 2 + .../initializers/filter_parameter_logging.rb | 2 + config/initializers/inflections.rb | 1 + config/initializers/mime_types.rb | 1 + config/initializers/wrap_parameters.rb | 2 + config/puma.rb | 8 +- config/routes.rb | 5 +- coverage/.resultset.json | 76 +++++++++++-- .../20220209111804_devise_create_users.rb | 5 +- db/migrate/20220211110733_create_posts.rb | 2 + db/schema.rb | 36 +++--- db/seeds.rb | 1 + spec/controllers/posts_controller_spec.rb | 22 ++-- spec/features/user_can_submit_posts_spec.rb | 16 +-- spec/helpers/posts_helper_spec.rb | 2 + spec/helpers/welcome_helper_spec.rb | 2 + spec/models/post_spec.rb | 2 + spec/models/user_spec.rb | 2 + spec/rails_helper.rb | 6 +- spec/requests/posts_spec.rb | 83 +++++++------- spec/requests/welcome_spec.rb | 6 +- spec/routing/posts_routing_spec.rb | 39 +++---- spec/spec_helper.rb | 106 +++++++++--------- spec/views/posts/edit.html.erb_spec.rb | 15 +-- spec/views/posts/index.html.erb_spec.rb | 22 ++-- spec/views/posts/new.html.erb_spec.rb | 15 +-- spec/views/posts/show.html.erb_spec.rb | 10 +- 61 files changed, 392 insertions(+), 235 deletions(-) diff --git a/Gemfile b/Gemfile index 2a2b55f340..35d01fe1bd 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source 'https://rubygems.org' git_source(:github) do |repo_name| @@ -32,18 +34,18 @@ gem 'devise', '~> 4.8', '>= 4.8.1' group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console - gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] + gem 'byebug', platforms: %i[mri mingw x64_mingw] # Adds support for Capybara system testing and selenium driver gem 'capybara', '~> 2.13' - gem 'selenium-webdriver' gem 'rspec-rails', '~> 4' + gem 'selenium-webdriver' end group :development do # Access an IRB console on exception pages or by using <%= console %> anywhere in the code. - gem 'web-console', '>= 3.3.0' gem 'listen', '>= 3.0.5', '< 3.2' gem 'rubocop', '1.20' + gem 'web-console', '>= 3.3.0' end group :test do @@ -53,5 +55,4 @@ group :test do end # Windows does not include zoneinfo files, so bundle the tzinfo-data gem -gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] - +gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby] diff --git a/Rakefile b/Rakefile index e85f913914..488c551fee 100644 --- a/Rakefile +++ b/Rakefile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. diff --git a/app/channels/application_cable/channel.rb b/app/channels/application_cable/channel.rb index d672697283..9aec230539 100644 --- a/app/channels/application_cable/channel.rb +++ b/app/channels/application_cable/channel.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module ApplicationCable class Channel < ActionCable::Channel::Base end diff --git a/app/channels/application_cable/connection.rb b/app/channels/application_cable/connection.rb index 0ff5442f47..8d6c2a1bf4 100644 --- a/app/channels/application_cable/connection.rb +++ b/app/channels/application_cable/connection.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module ApplicationCable class Connection < ActionCable::Connection::Base end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 1c07694e9d..280cc28ce2 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ApplicationController < ActionController::Base protect_from_forgery with: :exception end diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 2f1582526c..ec624ef776 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -1,5 +1,7 @@ +# frozen_string_literal: true + class PostsController < ApplicationController - before_action :set_post, only: %i[ show edit update destroy ] + before_action :set_post, only: %i[show edit update destroy] before_action :authenticate_user! # GET /posts or /posts.json @@ -8,8 +10,7 @@ def index end # GET /posts/1 or /posts/1.json - def show - end + def show; end # GET /posts/new def new @@ -17,8 +18,7 @@ def new end # GET /posts/1/edit - def edit - end + def edit; end # POST /posts or /posts.json def create @@ -26,7 +26,7 @@ def create respond_to do |format| if @post.save - format.html { redirect_to post_url(@post), notice: "Post was successfully created." } + format.html { redirect_to post_url(@post), notice: 'Post was successfully created.' } format.json { render :show, status: :created, location: @post } else format.html { render :new, status: :unprocessable_entity } @@ -39,7 +39,7 @@ def create def update respond_to do |format| if @post.update(post_params) - format.html { redirect_to post_url(@post), notice: "Post was successfully updated." } + format.html { redirect_to post_url(@post), notice: 'Post was successfully updated.' } format.json { render :show, status: :ok, location: @post } else format.html { render :edit, status: :unprocessable_entity } @@ -53,19 +53,20 @@ def destroy @post.destroy respond_to do |format| - format.html { redirect_to posts_url, notice: "Post was successfully destroyed." } + format.html { redirect_to posts_url, notice: 'Post was successfully destroyed.' } format.json { head :no_content } end end private - # Use callbacks to share common setup or constraints between actions. - def set_post - @post = Post.find(params[:id]) - end - # Only allow a list of trusted parameters through. - def post_params - params.require(:post).permit(:message) - end + # Use callbacks to share common setup or constraints between actions. + def set_post + @post = Post.find(params[:id]) + end + + # Only allow a list of trusted parameters through. + def post_params + params.require(:post).permit(:message) + end end diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index f9b859b9c9..8b9d7868e7 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -1,4 +1,5 @@ +# frozen_string_literal: true + class WelcomeController < ApplicationController - def index - end + def index; end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index de6be7945c..15b06f0f67 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + module ApplicationHelper end diff --git a/app/helpers/posts_helper.rb b/app/helpers/posts_helper.rb index a7b8cec898..f7f46979d1 100644 --- a/app/helpers/posts_helper.rb +++ b/app/helpers/posts_helper.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + module PostsHelper end diff --git a/app/helpers/welcome_helper.rb b/app/helpers/welcome_helper.rb index eeead45fc9..4ada0f472a 100644 --- a/app/helpers/welcome_helper.rb +++ b/app/helpers/welcome_helper.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + module WelcomeHelper end diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb index a009ace51c..d92ffddcb5 100644 --- a/app/jobs/application_job.rb +++ b/app/jobs/application_job.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + class ApplicationJob < ActiveJob::Base end diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index 286b2239d1..d84cb6e71e 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ApplicationMailer < ActionMailer::Base default from: 'from@example.com' layout 'mailer' diff --git a/app/models/application_record.rb b/app/models/application_record.rb index 10a4cba84d..71fbba5b32 100644 --- a/app/models/application_record.rb +++ b/app/models/application_record.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ApplicationRecord < ActiveRecord::Base self.abstract_class = true end diff --git a/app/models/post.rb b/app/models/post.rb index b2a8b4630f..a9c55bd6fe 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + class Post < ApplicationRecord end diff --git a/app/models/user.rb b/app/models/user.rb index 47567994e9..66651f6c22 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class User < ApplicationRecord # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable diff --git a/app/views/posts/_post.json.jbuilder b/app/views/posts/_post.json.jbuilder index ebf0978b3a..6f4aba9186 100644 --- a/app/views/posts/_post.json.jbuilder +++ b/app/views/posts/_post.json.jbuilder @@ -1,2 +1,4 @@ +# frozen_string_literal: true + json.extract! post, :id, :message, :created_at, :updated_at json.url post_url(post, format: :json) diff --git a/app/views/posts/index.json.jbuilder b/app/views/posts/index.json.jbuilder index a3c6f4a0b0..a28fc5221d 100644 --- a/app/views/posts/index.json.jbuilder +++ b/app/views/posts/index.json.jbuilder @@ -1 +1,3 @@ -json.array! @posts, partial: "posts/post", as: :post +# frozen_string_literal: true + +json.array! @posts, partial: 'posts/post', as: :post diff --git a/app/views/posts/show.json.jbuilder b/app/views/posts/show.json.jbuilder index 52744820e6..9cfa53b02f 100644 --- a/app/views/posts/show.json.jbuilder +++ b/app/views/posts/show.json.jbuilder @@ -1 +1,3 @@ -json.partial! "posts/post", post: @post +# frozen_string_literal: true + +json.partial! 'posts/post', post: @post diff --git a/bin/bundle b/bin/bundle index 66e9889e8b..2dbb71769e 100755 --- a/bin/bundle +++ b/bin/bundle @@ -1,3 +1,5 @@ #!/usr/bin/env ruby -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) +# frozen_string_literal: true + +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) load Gem.bin_path('bundler', 'bundle') diff --git a/bin/rails b/bin/rails index 0739660237..a31728ab97 100755 --- a/bin/rails +++ b/bin/rails @@ -1,4 +1,6 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + APP_PATH = File.expand_path('../config/application', __dir__) require_relative '../config/boot' require 'rails/commands' diff --git a/bin/rake b/bin/rake index 17240489f6..c199955006 100755 --- a/bin/rake +++ b/bin/rake @@ -1,4 +1,6 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + require_relative '../config/boot' require 'rake' Rake.application.run diff --git a/bin/setup b/bin/setup index 78c4e861dc..3b7333ed98 100755 --- a/bin/setup +++ b/bin/setup @@ -1,10 +1,12 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + require 'pathname' require 'fileutils' include FileUtils # path to your application root. -APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) +APP_ROOT = Pathname.new File.expand_path('..', __dir__) def system!(*args) system(*args) || abort("\n== Command #{args} failed ==") @@ -21,7 +23,6 @@ chdir APP_ROOT do # Install JavaScript dependencies if using Yarn # system('bin/yarn') - # puts "\n== Copying sample files ==" # unless File.exist?('config/database.yml') # cp 'config/database.yml.sample', 'config/database.yml' diff --git a/bin/update b/bin/update index a8e4462f20..1d6aa6a5c9 100755 --- a/bin/update +++ b/bin/update @@ -1,10 +1,12 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + require 'pathname' require 'fileutils' include FileUtils # path to your application root. -APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) +APP_ROOT = Pathname.new File.expand_path('..', __dir__) def system!(*args) system(*args) || abort("\n== Command #{args} failed ==") diff --git a/bin/yarn b/bin/yarn index c2bacef836..80b670de1a 100755 --- a/bin/yarn +++ b/bin/yarn @@ -1,11 +1,11 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + VENDOR_PATH = File.expand_path('..', __dir__) Dir.chdir(VENDOR_PATH) do - begin - exec "yarnpkg #{ARGV.join(" ")}" - rescue Errno::ENOENT - $stderr.puts "Yarn executable was not detected in the system." - $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install" - exit 1 - end + exec "yarnpkg #{ARGV.join(' ')}" +rescue Errno::ENOENT + warn 'Yarn executable was not detected in the system.' + warn 'Download Yarn at https://yarnpkg.com/en/docs/install' + exit 1 end diff --git a/config.ru b/config.ru index f7ba0b527b..842bccc340 100644 --- a/config.ru +++ b/config.ru @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This file is used by Rack-based servers to start the application. require_relative 'config/environment' diff --git a/config/application.rb b/config/application.rb index cb5c6cdb10..5f05186ffd 100644 --- a/config/application.rb +++ b/config/application.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative 'boot' require 'rails/all' diff --git a/config/boot.rb b/config/boot.rb index 30f5120df6..30e594e23c 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) require 'bundler/setup' # Set up gems listed in the Gemfile. diff --git a/config/environment.rb b/config/environment.rb index 426333bb46..d5abe55806 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Load the Rails application. require_relative 'application' diff --git a/config/environments/development.rb b/config/environments/development.rb index 1b0c4b389f..986f1437f4 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. diff --git a/config/environments/production.rb b/config/environments/production.rb index 4a41bf9e38..28f4c2f7fd 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. @@ -52,7 +54,7 @@ config.log_level = :debug # Prepend all log lines with the following tags. - config.log_tags = [ :request_id ] + config.log_tags = [:request_id] # Use a different cache store in production. # config.cache_store = :mem_cache_store @@ -80,8 +82,8 @@ # require 'syslog/logger' # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') - if ENV["RAILS_LOG_TO_STDOUT"].present? - logger = ActiveSupport::Logger.new(STDOUT) + if ENV['RAILS_LOG_TO_STDOUT'].present? + logger = ActiveSupport::Logger.new($stdout) logger.formatter = config.log_formatter config.logger = ActiveSupport::TaggedLogging.new(logger) end diff --git a/config/environments/test.rb b/config/environments/test.rb index 8e5cbde533..669350ab7c 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. diff --git a/config/initializers/application_controller_renderer.rb b/config/initializers/application_controller_renderer.rb index 51639b67a0..315ac48a9a 100644 --- a/config/initializers/application_controller_renderer.rb +++ b/config/initializers/application_controller_renderer.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Be sure to restart your server when you modify this file. # ApplicationController.renderer.defaults.merge!( diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index 4b828e80cb..a9b0d0f108 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Version of your assets, change this if you want to expire all your assets. diff --git a/config/initializers/backtrace_silencers.rb b/config/initializers/backtrace_silencers.rb index 59385cdf37..d0f0d3b5df 100644 --- a/config/initializers/backtrace_silencers.rb +++ b/config/initializers/backtrace_silencers.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Be sure to restart your server when you modify this file. # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. diff --git a/config/initializers/cookies_serializer.rb b/config/initializers/cookies_serializer.rb index 5a6a32d371..ee8dff9c99 100644 --- a/config/initializers/cookies_serializer.rb +++ b/config/initializers/cookies_serializer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Specify a serializer for the signed and encrypted cookie jars. diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb index 4a994e1e7b..7a4f47b4c2 100644 --- a/config/initializers/filter_parameter_logging.rb +++ b/config/initializers/filter_parameter_logging.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Configure sensitive parameters which will be filtered from the log file. diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb index ac033bf9dc..aa7435fbc9 100644 --- a/config/initializers/inflections.rb +++ b/config/initializers/inflections.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Be sure to restart your server when you modify this file. # Add new inflection rules using the following format. Inflections diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb index dc1899682b..6e1d16f027 100644 --- a/config/initializers/mime_types.rb +++ b/config/initializers/mime_types.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Be sure to restart your server when you modify this file. # Add new mime types for use in respond_to blocks: diff --git a/config/initializers/wrap_parameters.rb b/config/initializers/wrap_parameters.rb index bbfc3961bf..2f3c0db471 100644 --- a/config/initializers/wrap_parameters.rb +++ b/config/initializers/wrap_parameters.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # This file contains settings for ActionController::ParamsWrapper which diff --git a/config/puma.rb b/config/puma.rb index 1e19380dcb..ea3ca621c5 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -1,19 +1,21 @@ +# frozen_string_literal: true + # Puma can serve each request in a thread from an internal thread pool. # The `threads` method setting takes two numbers: a minimum and maximum. # Any libraries that use thread pools should be configured to match # the maximum value specified for Puma. Default is set to 5 threads for minimum # and maximum; this matches the default thread size of Active Record. # -threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } +threads_count = ENV.fetch('RAILS_MAX_THREADS', 5) threads threads_count, threads_count # Specifies the `port` that Puma will listen on to receive requests; default is 3000. # -port ENV.fetch("PORT") { 3000 } +port ENV.fetch('PORT', 3000) # Specifies the `environment` that Puma will run in. # -environment ENV.fetch("RAILS_ENV") { "development" } +environment ENV.fetch('RAILS_ENV', 'development') # Specifies the number of `workers` to boot in clustered mode. # Workers are forked webserver processes. If using threads and workers together diff --git a/config/routes.rb b/config/routes.rb index 0d08e975e2..f31737fd59 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,9 +1,10 @@ +# frozen_string_literal: true + Rails.application.routes.draw do - root 'posts#index' # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html get '/welcome/index' - + resources :posts devise_for :users end diff --git a/coverage/.resultset.json b/coverage/.resultset.json index 71af53a0fd..1048c1a6c4 100644 --- a/coverage/.resultset.json +++ b/coverage/.resultset.json @@ -3,6 +3,8 @@ "coverage": { "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/spec/controllers/posts_controller_spec.rb": { "lines": [ + null, + null, 1, null, 1, @@ -36,6 +38,8 @@ }, "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/spec/rails_helper.rb": { "lines": [ + null, + null, null, 1, 1, @@ -97,6 +101,8 @@ }, "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/config/environment.rb": { "lines": [ + null, + null, null, 1, null, @@ -106,6 +112,8 @@ }, "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/config/application.rb": { "lines": [ + null, + null, 1, null, 1, @@ -128,6 +136,8 @@ }, "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/config/boot.rb": { "lines": [ + null, + null, 1, null, 1 @@ -135,6 +145,8 @@ }, "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/config/environments/test.rb": { "lines": [ + null, + null, 1, null, null, @@ -186,11 +198,14 @@ null, null, null, + null, null ] }, "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/config/initializers/assets.rb": { "lines": [ + null, + null, null, null, null, @@ -215,6 +230,7 @@ null, null, null, + null, null ] }, @@ -224,6 +240,8 @@ null, null, null, + null, + null, 1 ] }, @@ -544,6 +562,8 @@ }, "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/config/initializers/filter_parameter_logging.rb": { "lines": [ + null, + null, null, null, null, @@ -567,6 +587,7 @@ null, null, null, + null, null ] }, @@ -575,6 +596,7 @@ null, null, null, + null, null ] }, @@ -586,6 +608,8 @@ null, null, null, + null, + null, 1, 2, null, @@ -598,9 +622,10 @@ }, "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/config/routes.rb": { "lines": [ - 1, + null, null, 1, + 1, null, 1, null, @@ -611,6 +636,8 @@ }, "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/app/models/user.rb": { "lines": [ + null, + null, 1, null, null, @@ -621,6 +648,8 @@ }, "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/app/models/application_record.rb": { "lines": [ + null, + null, 1, 1, null @@ -628,24 +657,32 @@ }, "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/app/helpers/application_helper.rb": { "lines": [ + null, + null, 1, null ] }, "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/app/helpers/posts_helper.rb": { "lines": [ + null, + null, 1, null ] }, "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/app/helpers/welcome_helper.rb": { "lines": [ + null, + null, 1, null ] }, "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/app/controllers/posts_controller.rb": { "lines": [ + null, + null, 1, 1, 1, @@ -659,7 +696,6 @@ 1, null, null, - null, 1, 0, null, @@ -668,7 +704,6 @@ 1, null, null, - null, 1, 0, null, @@ -708,6 +743,7 @@ null, 1, null, + null, 1, 0, null, @@ -721,6 +757,8 @@ }, "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/app/controllers/application_controller.rb": { "lines": [ + null, + null, 1, 1, null @@ -728,6 +766,8 @@ }, "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/spec/features/user_can_submit_posts_spec.rb": { "lines": [ + null, + null, 1, null, 1, @@ -743,6 +783,8 @@ }, "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/spec/helpers/posts_helper_spec.rb": { "lines": [ + null, + null, 1, null, null, @@ -762,6 +804,8 @@ }, "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/spec/helpers/welcome_helper_spec.rb": { "lines": [ + null, + null, 1, null, null, @@ -781,6 +825,8 @@ }, "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/spec/models/post_spec.rb": { "lines": [ + null, + null, 1, null, 1, @@ -790,12 +836,16 @@ }, "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/app/models/post.rb": { "lines": [ + null, + null, 1, null ] }, "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/spec/models/user_spec.rb": { "lines": [ + null, + null, 1, null, 1, @@ -805,6 +855,8 @@ }, "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/spec/requests/posts_spec.rb": { "lines": [ + null, + null, 1, null, null, @@ -822,7 +874,6 @@ 1, null, null, - null, 1, 10, null, @@ -939,6 +990,8 @@ }, "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/spec/requests/welcome_spec.rb": { "lines": [ + null, + null, 1, null, 1, @@ -950,6 +1003,8 @@ }, "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/spec/routing/posts_routing_spec.rb": { "lines": [ + null, + null, 1, null, 1, @@ -970,7 +1025,6 @@ 1, null, null, - null, 1, 1, null, @@ -992,6 +1046,8 @@ }, "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/spec/views/posts/edit.html.erb_spec.rb": { "lines": [ + null, + null, 1, null, 1, @@ -1005,7 +1061,6 @@ 1, null, 1, - null, 1, null, null, @@ -1014,6 +1069,8 @@ }, "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/spec/views/posts/index.html.erb_spec.rb": { "lines": [ + null, + null, 1, null, 1, @@ -1037,6 +1094,8 @@ }, "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/spec/views/posts/new.html.erb_spec.rb": { "lines": [ + null, + null, 1, null, 1, @@ -1050,7 +1109,6 @@ 1, null, 1, - null, 1, null, null, @@ -1059,6 +1117,8 @@ }, "/Users/alexanderjamshidi/Documents/Projects/acebook-CHATS/spec/views/posts/show.html.erb_spec.rb": { "lines": [ + null, + null, 1, null, 1, @@ -1076,6 +1136,6 @@ ] } }, - "timestamp": 1644600425 + "timestamp": 1644600539 } } diff --git a/db/migrate/20220209111804_devise_create_users.rb b/db/migrate/20220209111804_devise_create_users.rb index cc0991d9b7..d359edfe73 100644 --- a/db/migrate/20220209111804_devise_create_users.rb +++ b/db/migrate/20220209111804_devise_create_users.rb @@ -4,8 +4,8 @@ class DeviseCreateUsers < ActiveRecord::Migration[6.1] def change create_table :users do |t| ## Database authenticatable - t.string :email, null: false, default: "" - t.string :encrypted_password, null: false, default: "" + t.string :email, null: false, default: '' + t.string :encrypted_password, null: false, default: '' ## Recoverable t.string :reset_password_token @@ -32,7 +32,6 @@ def change # t.string :unlock_token # Only if unlock strategy is :email or :both # t.datetime :locked_at - t.timestamps null: false end diff --git a/db/migrate/20220211110733_create_posts.rb b/db/migrate/20220211110733_create_posts.rb index 1631998827..04bcd9fcf1 100644 --- a/db/migrate/20220211110733_create_posts.rb +++ b/db/migrate/20220211110733_create_posts.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreatePosts < ActiveRecord::Migration[6.1] def change create_table :posts do |t| diff --git a/db/schema.rb b/db/schema.rb index 292f45ec07..d5b7a78805 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. @@ -10,27 +12,25 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2022_02_11_110733) do - +ActiveRecord::Schema.define(version: 20_220_211_110_733) do # These are extensions that must be enabled in order to support this database - enable_extension "plpgsql" + enable_extension 'plpgsql' - create_table "posts", force: :cascade do |t| - t.string "message" - t.datetime "created_at", precision: 6, null: false - t.datetime "updated_at", precision: 6, null: false + create_table 'posts', force: :cascade do |t| + t.string 'message' + t.datetime 'created_at', precision: 6, null: false + t.datetime 'updated_at', precision: 6, null: false end - create_table "users", force: :cascade do |t| - t.string "email", default: "", null: false - t.string "encrypted_password", default: "", null: false - t.string "reset_password_token" - t.datetime "reset_password_sent_at" - t.datetime "remember_created_at" - t.datetime "created_at", precision: 6, null: false - t.datetime "updated_at", precision: 6, null: false - t.index ["email"], name: "index_users_on_email", unique: true - t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true + create_table 'users', force: :cascade do |t| + t.string 'email', default: '', null: false + t.string 'encrypted_password', default: '', null: false + t.string 'reset_password_token' + t.datetime 'reset_password_sent_at' + t.datetime 'remember_created_at' + t.datetime 'created_at', precision: 6, null: false + t.datetime 'updated_at', precision: 6, null: false + t.index ['email'], name: 'index_users_on_email', unique: true + t.index ['reset_password_token'], name: 'index_users_on_reset_password_token', unique: true end - end diff --git a/db/seeds.rb b/db/seeds.rb index 1beea2accd..8744e3c59b 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # This file should contain all the record creation needed to seed the database with its default values. # The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup). # diff --git a/spec/controllers/posts_controller_spec.rb b/spec/controllers/posts_controller_spec.rb index 630d9e8814..97e892c1b4 100644 --- a/spec/controllers/posts_controller_spec.rb +++ b/spec/controllers/posts_controller_spec.rb @@ -1,27 +1,29 @@ +# frozen_string_literal: true + require 'rails_helper' RSpec.describe PostsController, type: :controller do - describe "GET /new " do - it "responds with 200" do + describe 'GET /new ' do + it 'responds with 200' do get :new expect(response).to have_http_status(200) end end - describe "POST /" do - it "responds with 200" do - post :create, params: { post: { message: "Hello, world!" } } + describe 'POST /' do + it 'responds with 200' do + post :create, params: { post: { message: 'Hello, world!' } } expect(response).to redirect_to(posts_url) end - it "creates a post" do - post :create, params: { post: { message: "Hello, world!" } } - expect(Post.find_by(message: "Hello, world!")).to be + it 'creates a post' do + post :create, params: { post: { message: 'Hello, world!' } } + expect(Post.find_by(message: 'Hello, world!')).to be end end - describe "GET /" do - it "responds with 200" do + describe 'GET /' do + it 'responds with 200' do get :index expect(response).to have_http_status(200) end diff --git a/spec/features/user_can_submit_posts_spec.rb b/spec/features/user_can_submit_posts_spec.rb index f9acc9e3d9..cbb409d632 100644 --- a/spec/features/user_can_submit_posts_spec.rb +++ b/spec/features/user_can_submit_posts_spec.rb @@ -1,11 +1,13 @@ +# frozen_string_literal: true + require 'rails_helper' -RSpec.feature "Timeline", type: :feature do - scenario "Can submit posts and view them" do - visit "/posts" - click_link "New post" - fill_in "Message", with: "Hello, world!" - click_button "Submit" - expect(page).to have_content("Hello, world!") +RSpec.feature 'Timeline', type: :feature do + scenario 'Can submit posts and view them' do + visit '/posts' + click_link 'New post' + fill_in 'Message', with: 'Hello, world!' + click_button 'Submit' + expect(page).to have_content('Hello, world!') end end diff --git a/spec/helpers/posts_helper_spec.rb b/spec/helpers/posts_helper_spec.rb index f3d00cbcbe..a3fc4be57b 100644 --- a/spec/helpers/posts_helper_spec.rb +++ b/spec/helpers/posts_helper_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' # Specs in this file have access to a helper object that includes diff --git a/spec/helpers/welcome_helper_spec.rb b/spec/helpers/welcome_helper_spec.rb index a899852950..32f7485a54 100644 --- a/spec/helpers/welcome_helper_spec.rb +++ b/spec/helpers/welcome_helper_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' # Specs in this file have access to a helper object that includes diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index f41774c065..4f3ea1d727 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' RSpec.describe Post, type: :model do diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 47a31bb435..7da47d1322 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' RSpec.describe User, type: :model do diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 6f1ab14638..7434d1120d 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # This file is copied to spec/ when you run 'rails generate rspec:install' ENV['RAILS_ENV'] ||= 'test' -require File.expand_path('../../config/environment', __FILE__) +require File.expand_path('../config/environment', __dir__) # Prevent database truncation if the environment is production -abort("The Rails environment is running in production mode!") if Rails.env.production? +abort('The Rails environment is running in production mode!') if Rails.env.production? require 'spec_helper' require 'rspec/rails' # Add additional requires below this line. Rails is not loaded until this point! diff --git a/spec/requests/posts_spec.rb b/spec/requests/posts_spec.rb index 22fc805228..065780e31c 100644 --- a/spec/requests/posts_spec.rb +++ b/spec/requests/posts_spec.rb @@ -1,4 +1,6 @@ - require 'rails_helper' +# frozen_string_literal: true + +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 @@ -12,68 +14,67 @@ # 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 "/posts", type: :request do - +RSpec.describe '/posts', type: :request do # Post. As you add validations to Post, be sure to # adjust the attributes here as well. - let(:valid_attributes) { - skip("Add a hash of attributes valid for your model") - } + let(:valid_attributes) do + skip('Add a hash of attributes valid for your model') + end - let(:invalid_attributes) { - skip("Add a hash of attributes invalid for your model") - } + let(:invalid_attributes) do + skip('Add a hash of attributes invalid for your model') + end - describe "GET /index" do - it "renders a successful response" do + describe 'GET /index' do + it 'renders a successful response' do Post.create! valid_attributes get posts_url expect(response).to be_successful end end - describe "GET /show" do - it "renders a successful response" do + describe 'GET /show' do + it 'renders a successful response' do post = Post.create! valid_attributes get post_url(post) expect(response).to be_successful end end - describe "GET /new" do - it "renders a successful response" do + describe 'GET /new' do + it 'renders a successful response' do get new_post_url expect(response).to be_successful end end - describe "GET /edit" do - it "render a successful response" do + describe 'GET /edit' do + it 'render a successful response' do post = Post.create! valid_attributes get edit_post_url(post) expect(response).to be_successful end end - describe "POST /create" do - context "with valid parameters" do - it "creates a new Post" do - expect { + describe 'POST /create' do + context 'with valid parameters' do + it 'creates a new Post' do + expect do post posts_url, params: { post: valid_attributes } - }.to change(Post, :count).by(1) + end.to change(Post, :count).by(1) end - it "redirects to the created post" do + it 'redirects to the created post' do post posts_url, params: { post: valid_attributes } expect(response).to redirect_to(post_url(Post.last)) end end - context "with invalid parameters" do - it "does not create a new Post" do - expect { + context 'with invalid parameters' do + it 'does not create a new Post' do + expect do post posts_url, params: { post: invalid_attributes } - }.to change(Post, :count).by(0) + end.to change(Post, :count).by(0) end it "renders a successful response (i.e. to display the 'new' template)" do @@ -83,20 +84,20 @@ end end - describe "PATCH /update" do - context "with valid parameters" do - let(:new_attributes) { - skip("Add a hash of attributes valid for your model") - } + describe 'PATCH /update' do + context 'with valid parameters' do + let(:new_attributes) do + skip('Add a hash of attributes valid for your model') + end - it "updates the requested post" do + it 'updates the requested post' do post = Post.create! valid_attributes patch post_url(post), params: { post: new_attributes } post.reload - skip("Add assertions for updated state") + skip('Add assertions for updated state') end - it "redirects to the post" do + it 'redirects to the post' do post = Post.create! valid_attributes patch post_url(post), params: { post: new_attributes } post.reload @@ -104,7 +105,7 @@ end end - context "with invalid parameters" do + context 'with invalid parameters' do it "renders a successful response (i.e. to display the 'edit' template)" do post = Post.create! valid_attributes patch post_url(post), params: { post: invalid_attributes } @@ -113,15 +114,15 @@ end end - describe "DELETE /destroy" do - it "destroys the requested post" do + describe 'DELETE /destroy' do + it 'destroys the requested post' do post = Post.create! valid_attributes - expect { + expect do delete post_url(post) - }.to change(Post, :count).by(-1) + end.to change(Post, :count).by(-1) end - it "redirects to the posts list" do + it 'redirects to the posts list' do post = Post.create! valid_attributes delete post_url(post) expect(response).to redirect_to(posts_url) diff --git a/spec/requests/welcome_spec.rb b/spec/requests/welcome_spec.rb index 36343d0420..b5b8d80c7e 100644 --- a/spec/requests/welcome_spec.rb +++ b/spec/requests/welcome_spec.rb @@ -1,7 +1,9 @@ +# frozen_string_literal: true + require 'rails_helper' -RSpec.describe "Welcomes", type: :request do - describe "GET /index" do +RSpec.describe 'Welcomes', type: :request do + describe 'GET /index' do pending "add some examples (or delete) #{__FILE__}" end end diff --git a/spec/routing/posts_routing_spec.rb b/spec/routing/posts_routing_spec.rb index a76fa57521..42a56fbbe2 100644 --- a/spec/routing/posts_routing_spec.rb +++ b/spec/routing/posts_routing_spec.rb @@ -1,38 +1,39 @@ -require "rails_helper" +# frozen_string_literal: true + +require 'rails_helper' RSpec.describe PostsController, type: :routing do - describe "routing" do - it "routes to #index" do - expect(get: "/posts").to route_to("posts#index") + describe 'routing' do + it 'routes to #index' do + expect(get: '/posts').to route_to('posts#index') end - it "routes to #new" do - expect(get: "/posts/new").to route_to("posts#new") + it 'routes to #new' do + expect(get: '/posts/new').to route_to('posts#new') end - it "routes to #show" do - expect(get: "/posts/1").to route_to("posts#show", id: "1") + it 'routes to #show' do + expect(get: '/posts/1').to route_to('posts#show', id: '1') end - it "routes to #edit" do - expect(get: "/posts/1/edit").to route_to("posts#edit", id: "1") + it 'routes to #edit' do + expect(get: '/posts/1/edit').to route_to('posts#edit', id: '1') end - - it "routes to #create" do - expect(post: "/posts").to route_to("posts#create") + it 'routes to #create' do + expect(post: '/posts').to route_to('posts#create') end - it "routes to #update via PUT" do - expect(put: "/posts/1").to route_to("posts#update", id: "1") + it 'routes to #update via PUT' do + expect(put: '/posts/1').to route_to('posts#update', id: '1') end - it "routes to #update via PATCH" do - expect(patch: "/posts/1").to route_to("posts#update", id: "1") + it 'routes to #update via PATCH' do + expect(patch: '/posts/1').to route_to('posts#update', id: '1') end - it "routes to #destroy" do - expect(delete: "/posts/1").to route_to("posts#destroy", id: "1") + it 'routes to #destroy' do + expect(delete: '/posts/1').to route_to('posts#destroy', id: '1') end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index fbf985bcff..f7b5465881 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,11 +1,13 @@ +# frozen_string_literal: true + require 'simplecov' require 'simplecov-console' SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([ - SimpleCov::Formatter::Console, - # Want a nice code coverage website? Uncomment this next line! - # SimpleCov::Formatter::HTMLFormatter -]) + SimpleCov::Formatter::Console + # Want a nice code coverage website? Uncomment this next line! + # SimpleCov::Formatter::HTMLFormatter + ]) SimpleCov.start RSpec.configure do |config| @@ -65,53 +67,51 @@ # triggering implicit auto-inclusion in groups with matching metadata. config.shared_context_metadata_behavior = :apply_to_host_groups -# The settings below are suggested to provide a good initial experience -# with RSpec, but feel free to customize to your heart's content. -=begin - # This allows you to limit a spec run to individual examples or groups - # you care about by tagging them with `:focus` metadata. When nothing - # is tagged with `:focus`, all examples get run. RSpec also provides - # aliases for `it`, `describe`, and `context` that include `:focus` - # metadata: `fit`, `fdescribe` and `fcontext`, respectively. - config.filter_run_when_matching :focus - - # Allows RSpec to persist some state between runs in order to support - # the `--only-failures` and `--next-failure` CLI options. We recommend - # you configure your source control system to ignore this file. - config.example_status_persistence_file_path = "spec/examples.txt" - - # Limits the available syntax to the non-monkey patched syntax that is - # recommended. For more details, see: - # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/ - # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ - # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode - config.disable_monkey_patching! - - # Many RSpec users commonly either run the entire suite or an individual - # file, and it's useful to allow more verbose output when running an - # individual spec file. - if config.files_to_run.one? - # Use the documentation formatter for detailed output, - # unless a formatter has already been configured - # (e.g. via a command-line flag). - config.default_formatter = 'doc' - end - - # Print the 10 slowest examples and example groups at the - # end of the spec run, to help surface which specs are running - # particularly slow. - config.profile_examples = 10 - - # Run specs in random order to surface order dependencies. If you find an - # order dependency and want to debug it, you can fix the order by providing - # the seed, which is printed after each run. - # --seed 1234 - config.order = :random - - # Seed global randomization in this process using the `--seed` CLI option. - # Setting this allows you to use `--seed` to deterministically reproduce - # test failures related to randomization by passing the same `--seed` value - # as the one that triggered the failure. - Kernel.srand config.seed -=end + # The settings below are suggested to provide a good initial experience + # with RSpec, but feel free to customize to your heart's content. + # # This allows you to limit a spec run to individual examples or groups + # # you care about by tagging them with `:focus` metadata. When nothing + # # is tagged with `:focus`, all examples get run. RSpec also provides + # # aliases for `it`, `describe`, and `context` that include `:focus` + # # metadata: `fit`, `fdescribe` and `fcontext`, respectively. + # config.filter_run_when_matching :focus + # + # # Allows RSpec to persist some state between runs in order to support + # # the `--only-failures` and `--next-failure` CLI options. We recommend + # # you configure your source control system to ignore this file. + # config.example_status_persistence_file_path = "spec/examples.txt" + # + # # Limits the available syntax to the non-monkey patched syntax that is + # # recommended. For more details, see: + # # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/ + # # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ + # # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode + # config.disable_monkey_patching! + # + # # Many RSpec users commonly either run the entire suite or an individual + # # file, and it's useful to allow more verbose output when running an + # # individual spec file. + # if config.files_to_run.one? + # # Use the documentation formatter for detailed output, + # # unless a formatter has already been configured + # # (e.g. via a command-line flag). + # config.default_formatter = 'doc' + # end + # + # # Print the 10 slowest examples and example groups at the + # # end of the spec run, to help surface which specs are running + # # particularly slow. + # config.profile_examples = 10 + # + # # Run specs in random order to surface order dependencies. If you find an + # # order dependency and want to debug it, you can fix the order by providing + # # the seed, which is printed after each run. + # # --seed 1234 + # config.order = :random + # + # # Seed global randomization in this process using the `--seed` CLI option. + # # Setting this allows you to use `--seed` to deterministically reproduce + # # test failures related to randomization by passing the same `--seed` value + # # as the one that triggered the failure. + # Kernel.srand config.seed end diff --git a/spec/views/posts/edit.html.erb_spec.rb b/spec/views/posts/edit.html.erb_spec.rb index 7717735166..27638ec33f 100644 --- a/spec/views/posts/edit.html.erb_spec.rb +++ b/spec/views/posts/edit.html.erb_spec.rb @@ -1,18 +1,19 @@ +# frozen_string_literal: true + require 'rails_helper' -RSpec.describe "posts/edit", type: :view do +RSpec.describe 'posts/edit', type: :view do before(:each) do @post = assign(:post, Post.create!( - message: "MyString" - )) + message: 'MyString' + )) end - it "renders the edit post form" do + it 'renders the edit post form' do render - assert_select "form[action=?][method=?]", post_path(@post), "post" do - - assert_select "input[name=?]", "post[message]" + assert_select 'form[action=?][method=?]', post_path(@post), 'post' do + assert_select 'input[name=?]', 'post[message]' end end end diff --git a/spec/views/posts/index.html.erb_spec.rb b/spec/views/posts/index.html.erb_spec.rb index 817e835ff0..782ac7acd3 100644 --- a/spec/views/posts/index.html.erb_spec.rb +++ b/spec/views/posts/index.html.erb_spec.rb @@ -1,19 +1,21 @@ +# frozen_string_literal: true + require 'rails_helper' -RSpec.describe "posts/index", type: :view do +RSpec.describe 'posts/index', type: :view do before(:each) do assign(:posts, [ - Post.create!( - message: "Message" - ), - Post.create!( - message: "Message" - ) - ]) + Post.create!( + message: 'Message' + ), + Post.create!( + message: 'Message' + ) + ]) end - it "renders a list of posts" do + it 'renders a list of posts' do render - assert_select "tr>td", text: "Message".to_s, count: 2 + assert_select 'tr>td', text: 'Message'.to_s, count: 2 end end diff --git a/spec/views/posts/new.html.erb_spec.rb b/spec/views/posts/new.html.erb_spec.rb index 516ee5cb03..64d0e07e27 100644 --- a/spec/views/posts/new.html.erb_spec.rb +++ b/spec/views/posts/new.html.erb_spec.rb @@ -1,18 +1,19 @@ +# frozen_string_literal: true + require 'rails_helper' -RSpec.describe "posts/new", type: :view do +RSpec.describe 'posts/new', type: :view do before(:each) do assign(:post, Post.new( - message: "MyString" - )) + message: 'MyString' + )) end - it "renders new post form" do + it 'renders new post form' do render - assert_select "form[action=?][method=?]", posts_path, "post" do - - assert_select "input[name=?]", "post[message]" + assert_select 'form[action=?][method=?]', posts_path, 'post' do + assert_select 'input[name=?]', 'post[message]' end end end diff --git a/spec/views/posts/show.html.erb_spec.rb b/spec/views/posts/show.html.erb_spec.rb index 863cc104ad..bcd1474a03 100644 --- a/spec/views/posts/show.html.erb_spec.rb +++ b/spec/views/posts/show.html.erb_spec.rb @@ -1,13 +1,15 @@ +# frozen_string_literal: true + require 'rails_helper' -RSpec.describe "posts/show", type: :view do +RSpec.describe 'posts/show', type: :view do before(:each) do @post = assign(:post, Post.create!( - message: "Message" - )) + message: 'Message' + )) end - it "renders attributes in

" do + it 'renders attributes in

' do render expect(rendered).to match(/Message/) end From 5bb68b71ab9ed255a7fe5cf7963f2530da2d2022 Mon Sep 17 00:00:00 2001 From: Hannah Desmond Date: Sun, 13 Feb 2022 14:07:07 +0000 Subject: [PATCH 21/56] Add feature tests for edit password and delete account --- app/views/layouts/application.html.erb | 15 +++----------- .../users_can_edit_or delete_account_spec.rb | 20 +++++++++++++++++++ spec/spec_helper.rb | 8 ++++++++ 3 files changed, 31 insertions(+), 12 deletions(-) create mode 100644 spec/features/users_can_edit_or delete_account_spec.rb diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 4ff6cae001..9030561cba 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -7,19 +7,7 @@ <%= stylesheet_link_tag 'application', media: 'all' %> <%= javascript_include_tag 'application' %> - - - - - - - - - - - -

+

<%= notice %>

+

<%= alert %>

<%= yield %> -

<%= notice %>

-

<%= alert %>

+ diff --git a/app/views/posts/index.html.erb b/app/views/posts/index.html.erb index cd95bf7a0e..be8a18fdc4 100644 --- a/app/views/posts/index.html.erb +++ b/app/views/posts/index.html.erb @@ -1,5 +1,3 @@ -

<%= notice %>

-

Posts

diff --git a/coverage/.resultset.json b/coverage/.resultset.json index 33d099dfba..fb9336a292 100644 --- a/coverage/.resultset.json +++ b/coverage/.resultset.json @@ -764,7 +764,7 @@ null, null, 1, - 1, + 2, null, null, null, @@ -772,7 +772,7 @@ null, null, 1, - 1, + 2, null, null, null, @@ -780,12 +780,12 @@ null, null, 1, - 2, + 3, null, - 2, - 2, - 4, - 2, + 3, + 3, + 6, + 3, null, 0, 0, @@ -820,12 +820,12 @@ null, null, 1, - 0, + 1, null, null, null, 1, - 2, + 3, null, null ] @@ -867,14 +867,18 @@ null, null, 1, + 1, + null, null, 1, + null, + 1, + 1, + 1, + 1, 1, 1, 1, - 0, - 0, - 0, null, null ] @@ -1306,6 +1310,6 @@ ] } }, - "timestamp": 1644924924 + "timestamp": 1644935165 } } diff --git a/spec/features/user_can_submit_posts_spec.rb b/spec/features/user_can_submit_posts_spec.rb index cbb409d632..a3f3b217c6 100644 --- a/spec/features/user_can_submit_posts_spec.rb +++ b/spec/features/user_can_submit_posts_spec.rb @@ -1,13 +1,17 @@ # frozen_string_literal: true require 'rails_helper' +require_relative '../support/devise' + RSpec.feature 'Timeline', type: :feature do + scenario 'Can submit posts and view them' do + sign_up visit '/posts' - click_link 'New post' - fill_in 'Message', with: 'Hello, world!' - click_button 'Submit' + click_link 'New Post' + fill_in 'post[message]', with: 'Hello, world!' + click_button 'Create Post' expect(page).to have_content('Hello, world!') - end -end + end +end \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 311baf2371..9696462026 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -3,6 +3,7 @@ require 'simplecov' require 'simplecov-console' + SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([ SimpleCov::Formatter::Console # Want a nice code coverage website? Uncomment this next line! @@ -132,5 +133,4 @@ def sign_in fill_in("user_email", with: "hello@hello.com") fill_in("user_password", with: "123456") click_button("Log in") -end - +end \ No newline at end of file From 9115d71fc549fda43ea1232a0480143b6a2f899d Mon Sep 17 00:00:00 2001 From: Hannah Desmond Date: Tue, 15 Feb 2022 15:19:55 +0000 Subject: [PATCH 29/56] Add redirect to show posts after creating new posts --- Gemfile.lock | 1 + app/assets/javascripts/application.js | 1 + app/controllers/posts_controller.rb | 2 +- config/routes.rb | 1 + coverage/.resultset.json | 154 +++++++++++----------- spec/controllers/posts_controller_spec.rb | 2 +- spec/requests/posts_spec.rb | 1 + 7 files changed, 84 insertions(+), 78 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index b8ec9ecb76..d3293914f3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -267,6 +267,7 @@ GEM PLATFORMS arm64-darwin-20 + ruby DEPENDENCIES bootstrap (~> 5.1.3) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index e4ccf16808..ae9ad500e1 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -13,5 +13,6 @@ //= require rails-ujs //= require_tree . //= require jquery3 +//= require turbolinks //= require popper //= require bootstrap-sprockets \ No newline at end of file diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index ec624ef776..28751b5aeb 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -26,7 +26,7 @@ def create respond_to do |format| if @post.save - format.html { redirect_to post_url(@post), notice: 'Post was successfully created.' } + format.html { redirect_to posts_index_url, notice: 'Post was successfully created.' } format.json { render :show, status: :created, location: @post } else format.html { render :new, status: :unprocessable_entity } diff --git a/config/routes.rb b/config/routes.rb index 8cf905cb70..1f5c2b8798 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -7,6 +7,7 @@ # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html get '/welcome/index' get 'posts/index' + get 'posts/new' resources :posts end diff --git a/coverage/.resultset.json b/coverage/.resultset.json index fb9336a292..dd15c9be02 100644 --- a/coverage/.resultset.json +++ b/coverage/.resultset.json @@ -1,7 +1,7 @@ { "RSpec": { "coverage": { - "/Users/ckapihya/Projects/acebook-CHATS/spec/controllers/posts_controller_spec.rb": { + "/Users/hannah/Projects/makers-dec/acebook-CHATS/spec/controllers/posts_controller_spec.rb": { "lines": [ null, null, @@ -41,7 +41,7 @@ null ] }, - "/Users/ckapihya/Projects/acebook-CHATS/spec/rails_helper.rb": { + "/Users/hannah/Projects/makers-dec/acebook-CHATS/spec/rails_helper.rb": { "lines": [ null, null, @@ -129,7 +129,7 @@ null ] }, - "/Users/ckapihya/Projects/acebook-CHATS/config/environment.rb": { + "/Users/hannah/Projects/makers-dec/acebook-CHATS/config/environment.rb": { "lines": [ null, null, @@ -140,7 +140,7 @@ 1 ] }, - "/Users/ckapihya/Projects/acebook-CHATS/config/application.rb": { + "/Users/hannah/Projects/makers-dec/acebook-CHATS/config/application.rb": { "lines": [ null, null, @@ -164,7 +164,7 @@ null ] }, - "/Users/ckapihya/Projects/acebook-CHATS/config/boot.rb": { + "/Users/hannah/Projects/makers-dec/acebook-CHATS/config/boot.rb": { "lines": [ null, null, @@ -173,7 +173,7 @@ 1 ] }, - "/Users/ckapihya/Projects/acebook-CHATS/config/environments/test.rb": { + "/Users/hannah/Projects/makers-dec/acebook-CHATS/config/environments/test.rb": { "lines": [ null, null, @@ -221,7 +221,7 @@ null ] }, - "/Users/ckapihya/Projects/acebook-CHATS/config/initializers/application_controller_renderer.rb": { + "/Users/hannah/Projects/makers-dec/acebook-CHATS/config/initializers/application_controller_renderer.rb": { "lines": [ null, null, @@ -232,7 +232,7 @@ null ] }, - "/Users/ckapihya/Projects/acebook-CHATS/config/initializers/assets.rb": { + "/Users/hannah/Projects/makers-dec/acebook-CHATS/config/initializers/assets.rb": { "lines": [ null, null, @@ -252,7 +252,7 @@ null ] }, - "/Users/ckapihya/Projects/acebook-CHATS/config/initializers/backtrace_silencers.rb": { + "/Users/hannah/Projects/makers-dec/acebook-CHATS/config/initializers/backtrace_silencers.rb": { "lines": [ null, null, @@ -264,7 +264,7 @@ null ] }, - "/Users/ckapihya/Projects/acebook-CHATS/config/initializers/cookies_serializer.rb": { + "/Users/hannah/Projects/makers-dec/acebook-CHATS/config/initializers/cookies_serializer.rb": { "lines": [ null, null, @@ -275,7 +275,7 @@ 1 ] }, - "/Users/ckapihya/Projects/acebook-CHATS/config/initializers/devise.rb": { + "/Users/hannah/Projects/makers-dec/acebook-CHATS/config/initializers/devise.rb": { "lines": [ null, null, @@ -590,7 +590,7 @@ null ] }, - "/Users/ckapihya/Projects/acebook-CHATS/config/initializers/filter_parameter_logging.rb": { + "/Users/hannah/Projects/makers-dec/acebook-CHATS/config/initializers/filter_parameter_logging.rb": { "lines": [ null, null, @@ -600,7 +600,7 @@ 1 ] }, - "/Users/ckapihya/Projects/acebook-CHATS/config/initializers/inflections.rb": { + "/Users/hannah/Projects/makers-dec/acebook-CHATS/config/initializers/inflections.rb": { "lines": [ null, null, @@ -621,7 +621,7 @@ null ] }, - "/Users/ckapihya/Projects/acebook-CHATS/config/initializers/mime_types.rb": { + "/Users/hannah/Projects/makers-dec/acebook-CHATS/config/initializers/mime_types.rb": { "lines": [ null, null, @@ -630,7 +630,7 @@ null ] }, - "/Users/ckapihya/Projects/acebook-CHATS/config/initializers/wrap_parameters.rb": { + "/Users/hannah/Projects/makers-dec/acebook-CHATS/config/initializers/wrap_parameters.rb": { "lines": [ null, null, @@ -650,7 +650,7 @@ null ] }, - "/Users/ckapihya/Projects/acebook-CHATS/spec/factories/factories.rb": { + "/Users/hannah/Projects/makers-dec/acebook-CHATS/spec/factories/factories.rb": { "lines": [ 1, 1, @@ -660,7 +660,7 @@ null ] }, - "/Users/ckapihya/Projects/acebook-CHATS/config/routes.rb": { + "/Users/hannah/Projects/makers-dec/acebook-CHATS/config/routes.rb": { "lines": [ null, null, @@ -671,12 +671,13 @@ null, 1, 1, + 1, null, 1, null ] }, - "/Users/ckapihya/Projects/acebook-CHATS/app/models/user.rb": { + "/Users/hannah/Projects/makers-dec/acebook-CHATS/app/models/user.rb": { "lines": [ null, null, @@ -688,7 +689,7 @@ null ] }, - "/Users/ckapihya/Projects/acebook-CHATS/app/models/application_record.rb": { + "/Users/hannah/Projects/makers-dec/acebook-CHATS/app/models/application_record.rb": { "lines": [ null, null, @@ -697,7 +698,7 @@ null ] }, - "/Users/ckapihya/Projects/acebook-CHATS/app/helpers/application_helper.rb": { + "/Users/hannah/Projects/makers-dec/acebook-CHATS/app/helpers/application_helper.rb": { "lines": [ null, null, @@ -705,7 +706,7 @@ null ] }, - "/Users/ckapihya/Projects/acebook-CHATS/app/helpers/posts_helper.rb": { + "/Users/hannah/Projects/makers-dec/acebook-CHATS/app/helpers/posts_helper.rb": { "lines": [ null, null, @@ -713,7 +714,7 @@ null ] }, - "/Users/ckapihya/Projects/acebook-CHATS/app/helpers/welcome_helper.rb": { + "/Users/hannah/Projects/makers-dec/acebook-CHATS/app/helpers/welcome_helper.rb": { "lines": [ null, null, @@ -721,7 +722,7 @@ null ] }, - "/Users/ckapihya/Projects/acebook-CHATS/spec/support/controller_macros.rb": { + "/Users/hannah/Projects/makers-dec/acebook-CHATS/spec/support/controller_macros.rb": { "lines": [ 1, 1, @@ -742,7 +743,7 @@ null ] }, - "/Users/ckapihya/Projects/acebook-CHATS/spec/support/devise.rb": { + "/Users/hannah/Projects/makers-dec/acebook-CHATS/spec/support/devise.rb": { "lines": [ 1, null, @@ -754,7 +755,7 @@ null ] }, - "/Users/ckapihya/Projects/acebook-CHATS/app/controllers/posts_controller.rb": { + "/Users/hannah/Projects/makers-dec/acebook-CHATS/app/controllers/posts_controller.rb": { "lines": [ null, null, @@ -764,7 +765,7 @@ null, null, 1, - 2, + 1, null, null, null, @@ -772,7 +773,7 @@ null, null, 1, - 2, + 1, null, null, null, @@ -780,12 +781,12 @@ null, null, 1, - 3, + 2, null, - 3, - 3, - 6, - 3, + 2, + 2, + 4, + 2, null, 0, 0, @@ -820,17 +821,17 @@ null, null, 1, - 1, + 0, null, null, null, 1, - 3, + 2, null, null ] }, - "/Users/ckapihya/Projects/acebook-CHATS/app/controllers/application_controller.rb": { + "/Users/hannah/Projects/makers-dec/acebook-CHATS/app/controllers/application_controller.rb": { "lines": [ null, null, @@ -839,12 +840,12 @@ null ] }, - "/Users/ckapihya/Projects/acebook-CHATS/spec/features/signed_in_users_see_posts_spec.rb": { + "/Users/hannah/Projects/makers-dec/acebook-CHATS/spec/features/signed_in_users_see_posts_spec.rb": { "lines": [ ] }, - "/Users/ckapihya/Projects/acebook-CHATS/spec/features/user_can_sign_out_spec.rb": { + "/Users/hannah/Projects/makers-dec/acebook-CHATS/spec/features/user_can_sign_out_spec.rb": { "lines": [ 1, null, @@ -862,7 +863,7 @@ null ] }, - "/Users/ckapihya/Projects/acebook-CHATS/spec/features/user_can_submit_posts_spec.rb": { + "/Users/hannah/Projects/makers-dec/acebook-CHATS/spec/features/user_can_submit_posts_spec.rb": { "lines": [ null, null, @@ -874,40 +875,40 @@ null, 1, 1, - 1, - 1, - 1, - 1, - 1, + 0, + 0, + 0, + 0, + 0, null, null ] }, - "/Users/ckapihya/Projects/acebook-CHATS/spec/features/users_can_edit_or delete_account_spec.rb": { + "/Users/hannah/Projects/makers-dec/acebook-CHATS/spec/features/users_can_edit_or delete_account_spec.rb": { "lines": [ 1, null, 1, 1, 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, + 0, + 0, + 0, + 0, + 0, + 0, + 0, null, 1, 1, - 1, - 1, - 1, + 0, + 0, + 0, null, null ] }, - "/Users/ckapihya/Projects/acebook-CHATS/spec/features/users_can_sign_in_spec.rb": { + "/Users/hannah/Projects/makers-dec/acebook-CHATS/spec/features/users_can_sign_in_spec.rb": { "lines": [ 1, null, @@ -921,17 +922,17 @@ null, 1, 1, - 1, - 1, - 1, - 1, - 1, - 1, + 0, + 0, + 0, + 0, + 0, + 0, null, null ] }, - "/Users/ckapihya/Projects/acebook-CHATS/spec/features/welcome_page_spec.rb": { + "/Users/hannah/Projects/makers-dec/acebook-CHATS/spec/features/welcome_page_spec.rb": { "lines": [ 1, null, @@ -946,7 +947,7 @@ null ] }, - "/Users/ckapihya/Projects/acebook-CHATS/spec/helpers/posts_helper_spec.rb": { + "/Users/hannah/Projects/makers-dec/acebook-CHATS/spec/helpers/posts_helper_spec.rb": { "lines": [ null, null, @@ -967,7 +968,7 @@ null ] }, - "/Users/ckapihya/Projects/acebook-CHATS/spec/helpers/welcome_helper_spec.rb": { + "/Users/hannah/Projects/makers-dec/acebook-CHATS/spec/helpers/welcome_helper_spec.rb": { "lines": [ null, null, @@ -988,7 +989,7 @@ null ] }, - "/Users/ckapihya/Projects/acebook-CHATS/spec/models/post_spec.rb": { + "/Users/hannah/Projects/makers-dec/acebook-CHATS/spec/models/post_spec.rb": { "lines": [ null, null, @@ -999,7 +1000,7 @@ null ] }, - "/Users/ckapihya/Projects/acebook-CHATS/app/models/post.rb": { + "/Users/hannah/Projects/makers-dec/acebook-CHATS/app/models/post.rb": { "lines": [ null, null, @@ -1007,7 +1008,7 @@ null ] }, - "/Users/ckapihya/Projects/acebook-CHATS/spec/models/user_spec.rb": { + "/Users/hannah/Projects/makers-dec/acebook-CHATS/spec/models/user_spec.rb": { "lines": [ null, null, @@ -1018,7 +1019,7 @@ null ] }, - "/Users/ckapihya/Projects/acebook-CHATS/spec/requests/posts_spec.rb": { + "/Users/hannah/Projects/makers-dec/acebook-CHATS/spec/requests/posts_spec.rb": { "lines": [ null, null, @@ -1067,6 +1068,7 @@ 1, 1, 1, + 1, null, null, null, @@ -1153,7 +1155,7 @@ null ] }, - "/Users/ckapihya/Projects/acebook-CHATS/spec/requests/welcome_spec.rb": { + "/Users/hannah/Projects/makers-dec/acebook-CHATS/spec/requests/welcome_spec.rb": { "lines": [ null, null, @@ -1166,7 +1168,7 @@ null ] }, - "/Users/ckapihya/Projects/acebook-CHATS/spec/routing/posts_routing_spec.rb": { + "/Users/hannah/Projects/makers-dec/acebook-CHATS/spec/routing/posts_routing_spec.rb": { "lines": [ null, null, @@ -1209,7 +1211,7 @@ null ] }, - "/Users/ckapihya/Projects/acebook-CHATS/spec/views/posts/edit.html.erb_spec.rb": { + "/Users/hannah/Projects/makers-dec/acebook-CHATS/spec/views/posts/edit.html.erb_spec.rb": { "lines": [ null, null, @@ -1232,7 +1234,7 @@ null ] }, - "/Users/ckapihya/Projects/acebook-CHATS/spec/views/posts/index.html.erb_spec.rb": { + "/Users/hannah/Projects/makers-dec/acebook-CHATS/spec/views/posts/index.html.erb_spec.rb": { "lines": [ null, null, @@ -1257,7 +1259,7 @@ null ] }, - "/Users/ckapihya/Projects/acebook-CHATS/spec/views/posts/new.html.erb_spec.rb": { + "/Users/hannah/Projects/makers-dec/acebook-CHATS/spec/views/posts/new.html.erb_spec.rb": { "lines": [ null, null, @@ -1280,7 +1282,7 @@ null ] }, - "/Users/ckapihya/Projects/acebook-CHATS/spec/views/posts/show.html.erb_spec.rb": { + "/Users/hannah/Projects/makers-dec/acebook-CHATS/spec/views/posts/show.html.erb_spec.rb": { "lines": [ null, null, @@ -1300,7 +1302,7 @@ null ] }, - "/Users/ckapihya/Projects/acebook-CHATS/app/controllers/welcome_controller.rb": { + "/Users/hannah/Projects/makers-dec/acebook-CHATS/app/controllers/welcome_controller.rb": { "lines": [ null, null, @@ -1310,6 +1312,6 @@ ] } }, - "timestamp": 1644935165 + "timestamp": 1644938264 } } diff --git a/spec/controllers/posts_controller_spec.rb b/spec/controllers/posts_controller_spec.rb index bd6fc524ba..d4a4631f49 100644 --- a/spec/controllers/posts_controller_spec.rb +++ b/spec/controllers/posts_controller_spec.rb @@ -18,7 +18,7 @@ describe 'POST /' do it 'responds with 200' do post :create, params: { post: { message: 'Hello, world!' } } - expect(response).to redirect_to(posts_url) + expect(response).to redirect_to(posts_index_url) end it 'creates a post' do diff --git a/spec/requests/posts_spec.rb b/spec/requests/posts_spec.rb index 065780e31c..f445b956d9 100644 --- a/spec/requests/posts_spec.rb +++ b/spec/requests/posts_spec.rb @@ -44,6 +44,7 @@ describe 'GET /new' do it 'renders a successful response' do get new_post_url + # this test sucks :( expect(response).to be_successful end end From f71b916cdd9c29e7fcb9a026cca558cb0449baa9 Mon Sep 17 00:00:00 2001 From: chisambwe Date: Tue, 15 Feb 2022 15:55:21 +0000 Subject: [PATCH 30/56] turbo links enabled --- coverage/.last_run.json | 5 ++ coverage/.resultset.json | 157 ++++++++++++++++++------------------ spec/requests/posts_spec.rb | 1 + 3 files changed, 85 insertions(+), 78 deletions(-) create mode 100644 coverage/.last_run.json diff --git a/coverage/.last_run.json b/coverage/.last_run.json new file mode 100644 index 0000000000..1f2b0cabf7 --- /dev/null +++ b/coverage/.last_run.json @@ -0,0 +1,5 @@ +{ + "result": { + "line": 88.72 + } +} diff --git a/coverage/.resultset.json b/coverage/.resultset.json index dd15c9be02..4cbae188a9 100644 --- a/coverage/.resultset.json +++ b/coverage/.resultset.json @@ -1,7 +1,7 @@ { "RSpec": { "coverage": { - "/Users/hannah/Projects/makers-dec/acebook-CHATS/spec/controllers/posts_controller_spec.rb": { + "/Users/ckapihya/Projects/acebook-CHATS/spec/controllers/posts_controller_spec.rb": { "lines": [ null, null, @@ -41,7 +41,7 @@ null ] }, - "/Users/hannah/Projects/makers-dec/acebook-CHATS/spec/rails_helper.rb": { + "/Users/ckapihya/Projects/acebook-CHATS/spec/rails_helper.rb": { "lines": [ null, null, @@ -129,7 +129,7 @@ null ] }, - "/Users/hannah/Projects/makers-dec/acebook-CHATS/config/environment.rb": { + "/Users/ckapihya/Projects/acebook-CHATS/config/environment.rb": { "lines": [ null, null, @@ -140,7 +140,7 @@ 1 ] }, - "/Users/hannah/Projects/makers-dec/acebook-CHATS/config/application.rb": { + "/Users/ckapihya/Projects/acebook-CHATS/config/application.rb": { "lines": [ null, null, @@ -164,7 +164,7 @@ null ] }, - "/Users/hannah/Projects/makers-dec/acebook-CHATS/config/boot.rb": { + "/Users/ckapihya/Projects/acebook-CHATS/config/boot.rb": { "lines": [ null, null, @@ -173,7 +173,7 @@ 1 ] }, - "/Users/hannah/Projects/makers-dec/acebook-CHATS/config/environments/test.rb": { + "/Users/ckapihya/Projects/acebook-CHATS/config/environments/test.rb": { "lines": [ null, null, @@ -221,7 +221,7 @@ null ] }, - "/Users/hannah/Projects/makers-dec/acebook-CHATS/config/initializers/application_controller_renderer.rb": { + "/Users/ckapihya/Projects/acebook-CHATS/config/initializers/application_controller_renderer.rb": { "lines": [ null, null, @@ -232,7 +232,7 @@ null ] }, - "/Users/hannah/Projects/makers-dec/acebook-CHATS/config/initializers/assets.rb": { + "/Users/ckapihya/Projects/acebook-CHATS/config/initializers/assets.rb": { "lines": [ null, null, @@ -252,7 +252,7 @@ null ] }, - "/Users/hannah/Projects/makers-dec/acebook-CHATS/config/initializers/backtrace_silencers.rb": { + "/Users/ckapihya/Projects/acebook-CHATS/config/initializers/backtrace_silencers.rb": { "lines": [ null, null, @@ -264,7 +264,7 @@ null ] }, - "/Users/hannah/Projects/makers-dec/acebook-CHATS/config/initializers/cookies_serializer.rb": { + "/Users/ckapihya/Projects/acebook-CHATS/config/initializers/cookies_serializer.rb": { "lines": [ null, null, @@ -275,7 +275,7 @@ 1 ] }, - "/Users/hannah/Projects/makers-dec/acebook-CHATS/config/initializers/devise.rb": { + "/Users/ckapihya/Projects/acebook-CHATS/config/initializers/devise.rb": { "lines": [ null, null, @@ -590,7 +590,7 @@ null ] }, - "/Users/hannah/Projects/makers-dec/acebook-CHATS/config/initializers/filter_parameter_logging.rb": { + "/Users/ckapihya/Projects/acebook-CHATS/config/initializers/filter_parameter_logging.rb": { "lines": [ null, null, @@ -600,7 +600,7 @@ 1 ] }, - "/Users/hannah/Projects/makers-dec/acebook-CHATS/config/initializers/inflections.rb": { + "/Users/ckapihya/Projects/acebook-CHATS/config/initializers/inflections.rb": { "lines": [ null, null, @@ -621,7 +621,7 @@ null ] }, - "/Users/hannah/Projects/makers-dec/acebook-CHATS/config/initializers/mime_types.rb": { + "/Users/ckapihya/Projects/acebook-CHATS/config/initializers/mime_types.rb": { "lines": [ null, null, @@ -630,7 +630,7 @@ null ] }, - "/Users/hannah/Projects/makers-dec/acebook-CHATS/config/initializers/wrap_parameters.rb": { + "/Users/ckapihya/Projects/acebook-CHATS/config/initializers/wrap_parameters.rb": { "lines": [ null, null, @@ -650,7 +650,7 @@ null ] }, - "/Users/hannah/Projects/makers-dec/acebook-CHATS/spec/factories/factories.rb": { + "/Users/ckapihya/Projects/acebook-CHATS/spec/factories/factories.rb": { "lines": [ 1, 1, @@ -660,7 +660,7 @@ null ] }, - "/Users/hannah/Projects/makers-dec/acebook-CHATS/config/routes.rb": { + "/Users/ckapihya/Projects/acebook-CHATS/config/routes.rb": { "lines": [ null, null, @@ -677,7 +677,7 @@ null ] }, - "/Users/hannah/Projects/makers-dec/acebook-CHATS/app/models/user.rb": { + "/Users/ckapihya/Projects/acebook-CHATS/app/models/user.rb": { "lines": [ null, null, @@ -689,7 +689,7 @@ null ] }, - "/Users/hannah/Projects/makers-dec/acebook-CHATS/app/models/application_record.rb": { + "/Users/ckapihya/Projects/acebook-CHATS/app/models/application_record.rb": { "lines": [ null, null, @@ -698,7 +698,7 @@ null ] }, - "/Users/hannah/Projects/makers-dec/acebook-CHATS/app/helpers/application_helper.rb": { + "/Users/ckapihya/Projects/acebook-CHATS/app/helpers/application_helper.rb": { "lines": [ null, null, @@ -706,7 +706,7 @@ null ] }, - "/Users/hannah/Projects/makers-dec/acebook-CHATS/app/helpers/posts_helper.rb": { + "/Users/ckapihya/Projects/acebook-CHATS/app/helpers/posts_helper.rb": { "lines": [ null, null, @@ -714,7 +714,7 @@ null ] }, - "/Users/hannah/Projects/makers-dec/acebook-CHATS/app/helpers/welcome_helper.rb": { + "/Users/ckapihya/Projects/acebook-CHATS/app/helpers/welcome_helper.rb": { "lines": [ null, null, @@ -722,7 +722,7 @@ null ] }, - "/Users/hannah/Projects/makers-dec/acebook-CHATS/spec/support/controller_macros.rb": { + "/Users/ckapihya/Projects/acebook-CHATS/spec/support/controller_macros.rb": { "lines": [ 1, 1, @@ -743,7 +743,7 @@ null ] }, - "/Users/hannah/Projects/makers-dec/acebook-CHATS/spec/support/devise.rb": { + "/Users/ckapihya/Projects/acebook-CHATS/spec/support/devise.rb": { "lines": [ 1, null, @@ -755,7 +755,7 @@ null ] }, - "/Users/hannah/Projects/makers-dec/acebook-CHATS/app/controllers/posts_controller.rb": { + "/Users/ckapihya/Projects/acebook-CHATS/app/controllers/posts_controller.rb": { "lines": [ null, null, @@ -765,7 +765,7 @@ null, null, 1, - 1, + 3, null, null, null, @@ -773,7 +773,7 @@ null, null, 1, - 1, + 2, null, null, null, @@ -781,12 +781,12 @@ null, null, 1, - 2, + 3, null, - 2, - 2, - 4, - 2, + 3, + 3, + 6, + 3, null, 0, 0, @@ -826,12 +826,12 @@ null, null, 1, - 2, + 3, null, null ] }, - "/Users/hannah/Projects/makers-dec/acebook-CHATS/app/controllers/application_controller.rb": { + "/Users/ckapihya/Projects/acebook-CHATS/app/controllers/application_controller.rb": { "lines": [ null, null, @@ -840,12 +840,12 @@ null ] }, - "/Users/hannah/Projects/makers-dec/acebook-CHATS/spec/features/signed_in_users_see_posts_spec.rb": { + "/Users/ckapihya/Projects/acebook-CHATS/spec/features/signed_in_users_see_posts_spec.rb": { "lines": [ ] }, - "/Users/hannah/Projects/makers-dec/acebook-CHATS/spec/features/user_can_sign_out_spec.rb": { + "/Users/ckapihya/Projects/acebook-CHATS/spec/features/user_can_sign_out_spec.rb": { "lines": [ 1, null, @@ -863,7 +863,7 @@ null ] }, - "/Users/hannah/Projects/makers-dec/acebook-CHATS/spec/features/user_can_submit_posts_spec.rb": { + "/Users/ckapihya/Projects/acebook-CHATS/spec/features/user_can_submit_posts_spec.rb": { "lines": [ null, null, @@ -875,40 +875,40 @@ null, 1, 1, - 0, - 0, - 0, - 0, - 0, + 1, + 1, + 1, + 1, + 1, null, null ] }, - "/Users/hannah/Projects/makers-dec/acebook-CHATS/spec/features/users_can_edit_or delete_account_spec.rb": { + "/Users/ckapihya/Projects/acebook-CHATS/spec/features/users_can_edit_or delete_account_spec.rb": { "lines": [ 1, null, 1, 1, 1, - 0, - 0, - 0, - 0, - 0, - 0, - 0, + 1, + 1, + 1, + 1, + 1, + 1, + 1, null, 1, 1, - 0, - 0, - 0, + 1, + 1, + 1, null, null ] }, - "/Users/hannah/Projects/makers-dec/acebook-CHATS/spec/features/users_can_sign_in_spec.rb": { + "/Users/ckapihya/Projects/acebook-CHATS/spec/features/users_can_sign_in_spec.rb": { "lines": [ 1, null, @@ -922,17 +922,17 @@ null, 1, 1, - 0, - 0, - 0, - 0, - 0, - 0, + 1, + 1, + 1, + 1, + 1, + 1, null, null ] }, - "/Users/hannah/Projects/makers-dec/acebook-CHATS/spec/features/welcome_page_spec.rb": { + "/Users/ckapihya/Projects/acebook-CHATS/spec/features/welcome_page_spec.rb": { "lines": [ 1, null, @@ -947,7 +947,7 @@ null ] }, - "/Users/hannah/Projects/makers-dec/acebook-CHATS/spec/helpers/posts_helper_spec.rb": { + "/Users/ckapihya/Projects/acebook-CHATS/spec/helpers/posts_helper_spec.rb": { "lines": [ null, null, @@ -968,7 +968,7 @@ null ] }, - "/Users/hannah/Projects/makers-dec/acebook-CHATS/spec/helpers/welcome_helper_spec.rb": { + "/Users/ckapihya/Projects/acebook-CHATS/spec/helpers/welcome_helper_spec.rb": { "lines": [ null, null, @@ -989,7 +989,7 @@ null ] }, - "/Users/hannah/Projects/makers-dec/acebook-CHATS/spec/models/post_spec.rb": { + "/Users/ckapihya/Projects/acebook-CHATS/spec/models/post_spec.rb": { "lines": [ null, null, @@ -1000,7 +1000,7 @@ null ] }, - "/Users/hannah/Projects/makers-dec/acebook-CHATS/app/models/post.rb": { + "/Users/ckapihya/Projects/acebook-CHATS/app/models/post.rb": { "lines": [ null, null, @@ -1008,7 +1008,7 @@ null ] }, - "/Users/hannah/Projects/makers-dec/acebook-CHATS/spec/models/user_spec.rb": { + "/Users/ckapihya/Projects/acebook-CHATS/spec/models/user_spec.rb": { "lines": [ null, null, @@ -1019,7 +1019,7 @@ null ] }, - "/Users/hannah/Projects/makers-dec/acebook-CHATS/spec/requests/posts_spec.rb": { + "/Users/ckapihya/Projects/acebook-CHATS/spec/requests/posts_spec.rb": { "lines": [ null, null, @@ -1041,7 +1041,7 @@ null, null, 1, - 10, + 11, null, null, 1, @@ -1067,8 +1067,9 @@ 1, 1, 1, - 1, - 1, + 0, + null, + 0, null, null, null, @@ -1155,7 +1156,7 @@ null ] }, - "/Users/hannah/Projects/makers-dec/acebook-CHATS/spec/requests/welcome_spec.rb": { + "/Users/ckapihya/Projects/acebook-CHATS/spec/requests/welcome_spec.rb": { "lines": [ null, null, @@ -1168,7 +1169,7 @@ null ] }, - "/Users/hannah/Projects/makers-dec/acebook-CHATS/spec/routing/posts_routing_spec.rb": { + "/Users/ckapihya/Projects/acebook-CHATS/spec/routing/posts_routing_spec.rb": { "lines": [ null, null, @@ -1211,7 +1212,7 @@ null ] }, - "/Users/hannah/Projects/makers-dec/acebook-CHATS/spec/views/posts/edit.html.erb_spec.rb": { + "/Users/ckapihya/Projects/acebook-CHATS/spec/views/posts/edit.html.erb_spec.rb": { "lines": [ null, null, @@ -1234,7 +1235,7 @@ null ] }, - "/Users/hannah/Projects/makers-dec/acebook-CHATS/spec/views/posts/index.html.erb_spec.rb": { + "/Users/ckapihya/Projects/acebook-CHATS/spec/views/posts/index.html.erb_spec.rb": { "lines": [ null, null, @@ -1259,7 +1260,7 @@ null ] }, - "/Users/hannah/Projects/makers-dec/acebook-CHATS/spec/views/posts/new.html.erb_spec.rb": { + "/Users/ckapihya/Projects/acebook-CHATS/spec/views/posts/new.html.erb_spec.rb": { "lines": [ null, null, @@ -1282,7 +1283,7 @@ null ] }, - "/Users/hannah/Projects/makers-dec/acebook-CHATS/spec/views/posts/show.html.erb_spec.rb": { + "/Users/ckapihya/Projects/acebook-CHATS/spec/views/posts/show.html.erb_spec.rb": { "lines": [ null, null, @@ -1302,7 +1303,7 @@ null ] }, - "/Users/hannah/Projects/makers-dec/acebook-CHATS/app/controllers/welcome_controller.rb": { + "/Users/ckapihya/Projects/acebook-CHATS/app/controllers/welcome_controller.rb": { "lines": [ null, null, @@ -1312,6 +1313,6 @@ ] } }, - "timestamp": 1644938264 + "timestamp": 1644940404 } } diff --git a/spec/requests/posts_spec.rb b/spec/requests/posts_spec.rb index f445b956d9..2267a3a258 100644 --- a/spec/requests/posts_spec.rb +++ b/spec/requests/posts_spec.rb @@ -43,6 +43,7 @@ describe 'GET /new' do it 'renders a successful response' do + post = Post.create! valid_attributes get new_post_url # this test sucks :( expect(response).to be_successful From 7e40e013d5dc9408f434e80bcec34163aca82bc2 Mon Sep 17 00:00:00 2001 From: chisambwe Date: Tue, 15 Feb 2022 16:37:36 +0000 Subject: [PATCH 31/56] Redirects to posts if signed in --- app/controllers/welcome_controller.rb | 14 +++++++- coverage/.last_run.json | 2 +- coverage/.resultset.json | 32 +++++++++++++++++-- .../signed_in_users_see_posts_spec.rb | 15 +++++++++ spec/requests/posts_spec.rb | 2 +- 5 files changed, 59 insertions(+), 6 deletions(-) diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index 8b9d7868e7..a2f2c12432 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -1,5 +1,17 @@ # frozen_string_literal: true class WelcomeController < ApplicationController - def index; end + before_action :check_signed_in + + def check_signed_in + redirect_to posts_index_url if signed_in? + end + + def index + # respond_to do |format| + # if user_signed_in? + # format.html { redirect_to posts_index_url } + # end + # end + end end diff --git a/coverage/.last_run.json b/coverage/.last_run.json index 1f2b0cabf7..03d6a532ed 100644 --- a/coverage/.last_run.json +++ b/coverage/.last_run.json @@ -1,5 +1,5 @@ { "result": { - "line": 88.72 + "line": 89.16 } } diff --git a/coverage/.resultset.json b/coverage/.resultset.json index 4cbae188a9..39ae0c4ebc 100644 --- a/coverage/.resultset.json +++ b/coverage/.resultset.json @@ -765,7 +765,7 @@ null, null, 1, - 3, + 11, null, null, null, @@ -842,7 +842,21 @@ }, "/Users/ckapihya/Projects/acebook-CHATS/spec/features/signed_in_users_see_posts_spec.rb": { "lines": [ - + 1, + null, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + null, + 1, + 1, + null, + null ] }, "/Users/ckapihya/Projects/acebook-CHATS/spec/features/user_can_sign_out_spec.rb": { @@ -1309,10 +1323,22 @@ null, 1, 1, + null, + 1, + 19, + null, + null, + 1, + null, + null, + null, + null, + null, + null, null ] } }, - "timestamp": 1644940404 + "timestamp": 1644942919 } } diff --git a/spec/features/signed_in_users_see_posts_spec.rb b/spec/features/signed_in_users_see_posts_spec.rb index e69de29bb2..394fafb019 100644 --- a/spec/features/signed_in_users_see_posts_spec.rb +++ b/spec/features/signed_in_users_see_posts_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +feature 'index page for signed in users' do + scenario 'signed in users can see posts' do + visit('/') + click_link("Sign Up") + fill_in("user_email", with: "hello@hello.com") + fill_in("user_password", with: "123456") + fill_in("user_password_confirmation", with: "123456") + click_button("Sign up") + + expect(page).to have_content("Posts") + expect(page).not_to have_content("Welcome to Acebook") + end +end \ No newline at end of file diff --git a/spec/requests/posts_spec.rb b/spec/requests/posts_spec.rb index 2267a3a258..f2a85b6f1c 100644 --- a/spec/requests/posts_spec.rb +++ b/spec/requests/posts_spec.rb @@ -45,7 +45,7 @@ it 'renders a successful response' do post = Post.create! valid_attributes get new_post_url - # this test sucks :( + # this test sucks :( but it passes :) expect(response).to be_successful end end From 7bb7dc9021f938649d5977ee6252542c20b35243 Mon Sep 17 00:00:00 2001 From: Hannah Desmond Date: Tue, 15 Feb 2022 17:13:23 +0000 Subject: [PATCH 32/56] Re-routing so clicking logo sends user to home page --- app/views/layouts/application.html.erb | 7 +- coverage/.last_run.json | 2 +- coverage/.resultset.json | 115 ++++++++++-------- .../signed_in_users_see_posts_spec.rb | 12 ++ spec/features/welcome_page_spec.rb | 7 ++ 5 files changed, 93 insertions(+), 50 deletions(-) diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index d510145bbe..6d88d68258 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -10,7 +10,11 @@ - + + @@ -14,7 +15,9 @@ <% @posts.reverse.each do |post| %> - + + + From bdabb675607bb4a973c6ce3c7eba9c2dff504250 Mon Sep 17 00:00:00 2001 From: samir Date: Wed, 16 Feb 2022 15:31:26 +0000 Subject: [PATCH 35/56] Added username functionality to code --- app/controllers/application_controller.rb | 8 +++ .../users/confirmations_controller.rb | 30 +++++++++ .../users/omniauth_callbacks_controller.rb | 30 +++++++++ app/controllers/users/passwords_controller.rb | 34 ++++++++++ .../users/registrations_controller.rb | 62 +++++++++++++++++++ app/controllers/users/sessions_controller.rb | 27 ++++++++ app/controllers/users/unlocks_controller.rb | 30 +++++++++ app/views/devise/registrations/new.html.erb | 12 ++++ app/views/posts/index.html.erb | 6 +- .../20220216145107_add_name_to_users.rb | 6 ++ db/schema.rb | 4 +- 11 files changed, 245 insertions(+), 4 deletions(-) create mode 100644 app/controllers/users/confirmations_controller.rb create mode 100644 app/controllers/users/omniauth_callbacks_controller.rb create mode 100644 app/controllers/users/passwords_controller.rb create mode 100644 app/controllers/users/registrations_controller.rb create mode 100644 app/controllers/users/sessions_controller.rb create mode 100644 app/controllers/users/unlocks_controller.rb create mode 100644 db/migrate/20220216145107_add_name_to_users.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 280cc28ce2..ccb5b0f259 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,4 +2,12 @@ class ApplicationController < ActionController::Base protect_from_forgery with: :exception + before_action :configure_permitted_parameters, if: :devise_controller? + +protected + + def configure_permitted_parameters + devise_parameter_sanitizer.permit(:sign_up, keys: [:first_name, :surname]) + end + end diff --git a/app/controllers/users/confirmations_controller.rb b/app/controllers/users/confirmations_controller.rb new file mode 100644 index 0000000000..fa535c0ae4 --- /dev/null +++ b/app/controllers/users/confirmations_controller.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +class Users::ConfirmationsController < Devise::ConfirmationsController + # GET /resource/confirmation/new + # def new + # super + # end + + # POST /resource/confirmation + # def create + # super + # end + + # GET /resource/confirmation?confirmation_token=abcdef + # def show + # super + # end + + # protected + + # The path used after resending confirmation instructions. + # def after_resending_confirmation_instructions_path_for(resource_name) + # super(resource_name) + # end + + # The path used after confirmation. + # def after_confirmation_path_for(resource_name, resource) + # super(resource_name, resource) + # end +end diff --git a/app/controllers/users/omniauth_callbacks_controller.rb b/app/controllers/users/omniauth_callbacks_controller.rb new file mode 100644 index 0000000000..593f547d1f --- /dev/null +++ b/app/controllers/users/omniauth_callbacks_controller.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController + # You should configure your model like this: + # devise :omniauthable, omniauth_providers: [:twitter] + + # You should also create an action method in this controller like this: + # def twitter + # end + + # More info at: + # https://github.com/heartcombo/devise#omniauth + + # GET|POST /resource/auth/twitter + # def passthru + # super + # end + + # GET|POST /users/auth/twitter/callback + # def failure + # super + # end + + # protected + + # The path used when OmniAuth fails + # def after_omniauth_failure_path_for(scope) + # super(scope) + # end +end diff --git a/app/controllers/users/passwords_controller.rb b/app/controllers/users/passwords_controller.rb new file mode 100644 index 0000000000..259dbb0845 --- /dev/null +++ b/app/controllers/users/passwords_controller.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +class Users::PasswordsController < Devise::PasswordsController + # GET /resource/password/new + # def new + # super + # end + + # POST /resource/password + # def create + # super + # end + + # GET /resource/password/edit?reset_password_token=abcdef + # def edit + # super + # end + + # PUT /resource/password + # def update + # super + # end + + # protected + + # def after_resetting_password_path_for(resource) + # super(resource) + # end + + # The path used after sending reset password instructions + # def after_sending_reset_password_instructions_path_for(resource_name) + # super(resource_name) + # end +end diff --git a/app/controllers/users/registrations_controller.rb b/app/controllers/users/registrations_controller.rb new file mode 100644 index 0000000000..b9e664fe33 --- /dev/null +++ b/app/controllers/users/registrations_controller.rb @@ -0,0 +1,62 @@ +# frozen_string_literal: true + +class Users::RegistrationsController < Devise::RegistrationsController + # before_action :configure_sign_up_params, only: [:create] + # before_action :configure_account_update_params, only: [:update] + + # GET /resource/sign_up + # def new + # super + # end + + # POST /resource + # def create + # super + # end + + # GET /resource/edit + # def edit + # super + # end + + # PUT /resource + # def update + # super + # end + + # DELETE /resource + # def destroy + # super + # end + + # GET /resource/cancel + # Forces the session data which is usually expired after sign + # in to be expired now. This is useful if the user wants to + # cancel oauth signing in/up in the middle of the process, + # removing all OAuth session data. + # def cancel + # super + # end + + # protected + + # If you have extra params to permit, append them to the sanitizer. + # def configure_sign_up_params + # devise_parameter_sanitizer.permit(:sign_up, keys: [:attribute]) + # end + + # If you have extra params to permit, append them to the sanitizer. + # def configure_account_update_params + # devise_parameter_sanitizer.permit(:account_update, keys: [:attribute]) + # end + + # The path used after sign up. + # def after_sign_up_path_for(resource) + # super(resource) + # end + + # The path used after sign up for inactive accounts. + # def after_inactive_sign_up_path_for(resource) + # super(resource) + # end +end diff --git a/app/controllers/users/sessions_controller.rb b/app/controllers/users/sessions_controller.rb new file mode 100644 index 0000000000..a0f9b48e74 --- /dev/null +++ b/app/controllers/users/sessions_controller.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +class Users::SessionsController < Devise::SessionsController + # before_action :configure_sign_in_params, only: [:create] + + # GET /resource/sign_in + # def new + # super + # end + + # POST /resource/sign_in + # def create + # super + # end + + # DELETE /resource/sign_out + # def destroy + # super + # end + + # protected + + # If you have extra params to permit, append them to the sanitizer. + # def configure_sign_in_params + # devise_parameter_sanitizer.permit(:sign_in, keys: [:attribute]) + # end +end diff --git a/app/controllers/users/unlocks_controller.rb b/app/controllers/users/unlocks_controller.rb new file mode 100644 index 0000000000..2c410dc015 --- /dev/null +++ b/app/controllers/users/unlocks_controller.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +class Users::UnlocksController < Devise::UnlocksController + # GET /resource/unlock/new + # def new + # super + # end + + # POST /resource/unlock + # def create + # super + # end + + # GET /resource/unlock?unlock_token=abcdef + # def show + # super + # end + + # protected + + # The path used after sending unlock password instructions + # def after_sending_unlock_instructions_path_for(resource) + # super(resource) + # end + + # The path used after unlocking the resource + # def after_unlock_path_for(resource) + # super(resource) + # end +end diff --git a/app/views/devise/registrations/new.html.erb b/app/views/devise/registrations/new.html.erb index d655b66f6f..6862529d4c 100644 --- a/app/views/devise/registrations/new.html.erb +++ b/app/views/devise/registrations/new.html.erb @@ -3,6 +3,18 @@ <%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %> <%= render "devise/shared/error_messages", resource: resource %> +
+
MessageUser_idUser_id
Created at
<%= post.message %><%= post.user_id %><%= post.user_id %><%= post.created_at.strftime("%d/%m/%y") %><%= post.created_at.strftime("%H:%M") %> <%= link_to 'Show', post %> <%= link_to 'Edit', edit_post_path(post) %> <%= link_to 'Destroy', post, method: :delete, data: { confirm: 'Are you sure?' } %>
+ + + + + + +
<%= f.label :first_name %> <%= f.label :surname %>
<%= f.text_field :first_name, autofocus: true %><%= f.text_field :surname, autofocus: true %>
+ + +
<%= f.label :email %>
<%= f.email_field :email, autofocus: true, autocomplete: "email" %> diff --git a/app/views/posts/index.html.erb b/app/views/posts/index.html.erb index 7ec599a316..9c4819e373 100644 --- a/app/views/posts/index.html.erb +++ b/app/views/posts/index.html.erb @@ -4,8 +4,8 @@ Message - User_id - + Name + Options @@ -14,7 +14,7 @@ <% @posts.reverse.each do |post| %> <%= post.message %> - <%= post.user_id %> + <%= " #{current_user.first_name} #{current_user.surname} " %> <%= link_to 'Show', post %> <%= link_to 'Edit', edit_post_path(post) %> <%= link_to 'Destroy', post, method: :delete, data: { confirm: 'Are you sure?' } %> diff --git a/db/migrate/20220216145107_add_name_to_users.rb b/db/migrate/20220216145107_add_name_to_users.rb new file mode 100644 index 0000000000..3508ac1362 --- /dev/null +++ b/db/migrate/20220216145107_add_name_to_users.rb @@ -0,0 +1,6 @@ +class AddNameToUsers < ActiveRecord::Migration[6.1] + def change + add_column :users, :first_name, :string, null: false, default: '' + add_column :users, :surname, :string, null: false, default: '' + end +end diff --git a/db/schema.rb b/db/schema.rb index 3d3578f64f..490954d501 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2022_02_15_112327) do +ActiveRecord::Schema.define(version: 2022_02_16_145107) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -41,6 +41,8 @@ t.datetime "remember_created_at" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false + t.string "first_name", default: "", null: false + t.string "surname", default: "", null: false t.index ["email"], name: "index_users_on_email", unique: true t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true end From d9250e8c477d0e80eb362bffd5e8c9e0f470f9e2 Mon Sep 17 00:00:00 2001 From: chisambwe Date: Wed, 16 Feb 2022 17:07:24 +0000 Subject: [PATCH 36/56] text-area and line break added --- app/views/posts/_form.html.erb | 2 +- app/views/posts/index.html.erb | 2 +- app/views/posts/show.html.erb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views/posts/_form.html.erb b/app/views/posts/_form.html.erb index 213372ede2..e78b1d9f1d 100644 --- a/app/views/posts/_form.html.erb +++ b/app/views/posts/_form.html.erb @@ -13,7 +13,7 @@
<%= form.label :message %> - <%= form.text_field :message %> + <%= form.text_area :message %>
diff --git a/app/views/posts/index.html.erb b/app/views/posts/index.html.erb index 7ec599a316..cd6e54f409 100644 --- a/app/views/posts/index.html.erb +++ b/app/views/posts/index.html.erb @@ -13,7 +13,7 @@ <% @posts.reverse.each do |post| %> - <%= post.message %> + <%= simple_format(post.message) %> <%= post.user_id %> <%= link_to 'Show', post %> <%= link_to 'Edit', edit_post_path(post) %> diff --git a/app/views/posts/show.html.erb b/app/views/posts/show.html.erb index e1940e1eab..1a93bf49eb 100644 --- a/app/views/posts/show.html.erb +++ b/app/views/posts/show.html.erb @@ -2,7 +2,7 @@

Message: - <%= @post.message %> + <%= simple_format(@post.message) %>

<%= link_to 'Edit', edit_post_path(@post) %> | From 9e1b1170ad6e245604e38b8aba8bdc713766a101 Mon Sep 17 00:00:00 2001 From: samir Date: Wed, 16 Feb 2022 18:00:14 +0000 Subject: [PATCH 37/56] Added comment functionality --- app/assets/stylesheets/comments.scss | 3 +++ app/controllers/comments_controller.rb | 2 ++ app/controllers/posts_controller.rb | 2 +- app/helpers/comments_helper.rb | 2 ++ app/models/comment.rb | 4 ++++ app/models/post.rb | 2 ++ app/models/user.rb | 2 ++ app/views/posts/index.html.erb | 1 + app/views/posts/show.html.erb | 15 +++++++++++++++ config/routes.rb | 4 +++- db/migrate/20220216170353_create_comments.rb | 11 +++++++++++ db/schema.rb | 14 +++++++++++++- spec/factories/comments.rb | 7 +++++++ spec/helpers/comments_helper_spec.rb | 15 +++++++++++++++ spec/models/comment_spec.rb | 5 +++++ spec/requests/comments_spec.rb | 7 +++++++ 16 files changed, 93 insertions(+), 3 deletions(-) create mode 100644 app/assets/stylesheets/comments.scss create mode 100644 app/controllers/comments_controller.rb create mode 100644 app/helpers/comments_helper.rb create mode 100644 app/models/comment.rb create mode 100644 db/migrate/20220216170353_create_comments.rb create mode 100644 spec/factories/comments.rb create mode 100644 spec/helpers/comments_helper_spec.rb create mode 100644 spec/models/comment_spec.rb create mode 100644 spec/requests/comments_spec.rb diff --git a/app/assets/stylesheets/comments.scss b/app/assets/stylesheets/comments.scss new file mode 100644 index 0000000000..69088e8c44 --- /dev/null +++ b/app/assets/stylesheets/comments.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Comments controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: https://sass-lang.com/ diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb new file mode 100644 index 0000000000..7669955155 --- /dev/null +++ b/app/controllers/comments_controller.rb @@ -0,0 +1,2 @@ +class CommentsController < ApplicationController +end diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index aef23db56e..f1fd39fa44 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -2,7 +2,7 @@ class PostsController < ApplicationController before_action :set_post, only: %i[show edit update destroy] - before_action :authenticate_user!, except: [:index, :show] + before_action :authenticate_user!, except: [:show] before_action :correct_user, only: [:edit, :update, :destroy] # GET /posts or /posts.json def index diff --git a/app/helpers/comments_helper.rb b/app/helpers/comments_helper.rb new file mode 100644 index 0000000000..0ec9ca5f2d --- /dev/null +++ b/app/helpers/comments_helper.rb @@ -0,0 +1,2 @@ +module CommentsHelper +end diff --git a/app/models/comment.rb b/app/models/comment.rb new file mode 100644 index 0000000000..add428589d --- /dev/null +++ b/app/models/comment.rb @@ -0,0 +1,4 @@ +class Comment < ApplicationRecord + belongs_to :user + belongs_to :post +end diff --git a/app/models/post.rb b/app/models/post.rb index f2d5974966..8bb8e6c890 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -2,7 +2,9 @@ class Post < ApplicationRecord belongs_to :user + has_many :comments validate :is_editable, unless: :new_record? + def is_editable if Time.now.to_i < created_at.since(600).to_i diff --git a/app/models/user.rb b/app/models/user.rb index 05ee0b157f..c15cf496ed 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -6,4 +6,6 @@ class User < ApplicationRecord devise :database_authenticatable, :registerable, :recoverable, :rememberable, :validatable has_many :posts + + has_many :comments end diff --git a/app/views/posts/index.html.erb b/app/views/posts/index.html.erb index c438890ab0..4b4a40fcbf 100644 --- a/app/views/posts/index.html.erb +++ b/app/views/posts/index.html.erb @@ -25,6 +25,7 @@ <%= link_to 'Edit', edit_post_path(post) %> <%= link_to 'Destroy', post, method: :delete, data: { confirm: 'Are you sure?' } %> + <% post.comments %> <% end %> diff --git a/app/views/posts/show.html.erb b/app/views/posts/show.html.erb index e1940e1eab..f480df239c 100644 --- a/app/views/posts/show.html.erb +++ b/app/views/posts/show.html.erb @@ -7,3 +7,18 @@ <%= link_to 'Edit', edit_post_path(@post) %> | <%= link_to 'Back', posts_path %> + + +

Add a comment:

+<%= form_with model: [@post, @post.comments.build] do + |form| %> +

+ <%= form.text_field :user_id, value: current_user.id, type: hidden %> +

+

+ <%= form.text_area :body %> +

+

+ <%= form.submit %> +

+ <% end %> diff --git a/config/routes.rb b/config/routes.rb index 1f5c2b8798..3c955bdc0a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -9,5 +9,7 @@ get 'posts/index' get 'posts/new' - resources :posts + resources :posts do + resources :comments + end end diff --git a/db/migrate/20220216170353_create_comments.rb b/db/migrate/20220216170353_create_comments.rb new file mode 100644 index 0000000000..cb4d474ee7 --- /dev/null +++ b/db/migrate/20220216170353_create_comments.rb @@ -0,0 +1,11 @@ +class CreateComments < ActiveRecord::Migration[6.1] + def change + create_table :comments do |t| + t.references :user, null: false, foreign_key: true + t.text :body + t.references :post, null: false, foreign_key: true + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 490954d501..29b91ccb9a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2022_02_16_145107) do +ActiveRecord::Schema.define(version: 2022_02_16_170353) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -25,6 +25,16 @@ t.datetime "updated_at", precision: 6, null: false end + create_table "comments", force: :cascade do |t| + t.bigint "user_id", null: false + t.text "body" + t.bigint "post_id", null: false + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["post_id"], name: "index_comments_on_post_id" + t.index ["user_id"], name: "index_comments_on_user_id" + end + create_table "posts", force: :cascade do |t| t.string "message" t.datetime "created_at", precision: 6, null: false @@ -47,4 +57,6 @@ t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true end + add_foreign_key "comments", "posts" + add_foreign_key "comments", "users" end diff --git a/spec/factories/comments.rb b/spec/factories/comments.rb new file mode 100644 index 0000000000..b9661e0918 --- /dev/null +++ b/spec/factories/comments.rb @@ -0,0 +1,7 @@ +FactoryBot.define do + factory :comment do + user { nil } + body { "MyText" } + post { nil } + end +end diff --git a/spec/helpers/comments_helper_spec.rb b/spec/helpers/comments_helper_spec.rb new file mode 100644 index 0000000000..729cd87bf3 --- /dev/null +++ b/spec/helpers/comments_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the CommentsHelper. For example: +# +# describe CommentsHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe CommentsHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/comment_spec.rb b/spec/models/comment_spec.rb new file mode 100644 index 0000000000..c10688d91d --- /dev/null +++ b/spec/models/comment_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Comment, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/requests/comments_spec.rb b/spec/requests/comments_spec.rb new file mode 100644 index 0000000000..3161a1cc01 --- /dev/null +++ b/spec/requests/comments_spec.rb @@ -0,0 +1,7 @@ +require 'rails_helper' + +RSpec.describe "Comments", type: :request do + describe "GET /index" do + pending "add some examples (or delete) #{__FILE__}" + end +end From 4e8d18c2ef7250e1de8cda648a5ac1922fb74b34 Mon Sep 17 00:00:00 2001 From: samir Date: Thu, 17 Feb 2022 11:24:11 +0000 Subject: [PATCH 38/56] Comments functionality and user name working --- app/controllers/comments_controller.rb | 11 +++++++++++ app/models/post.rb | 2 +- app/views/posts/show.html.erb | 9 ++++++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 7669955155..f49c028faa 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -1,2 +1,13 @@ class CommentsController < ApplicationController + def create + @post = Post.find(params[:post_id]) + @comment = @post.comments.create(comment_params) + redirect_to post_path(@post) + end + + private + + def comment_params + params.require(:comment).permit(:body, :user_id) + end end diff --git a/app/models/post.rb b/app/models/post.rb index 8bb8e6c890..08fdb40561 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -4,7 +4,7 @@ class Post < ApplicationRecord belongs_to :user has_many :comments validate :is_editable, unless: :new_record? - + def is_editable if Time.now.to_i < created_at.since(600).to_i diff --git a/app/views/posts/show.html.erb b/app/views/posts/show.html.erb index f480df239c..fa7ac21c5d 100644 --- a/app/views/posts/show.html.erb +++ b/app/views/posts/show.html.erb @@ -8,12 +8,19 @@ <%= link_to 'Edit', edit_post_path(@post) %> | <%= link_to 'Back', posts_path %> +

Comments

+<% @post.comments.each do |comment| %> +

+ <%= "#{User.find(comment.user_id).first_name} #{User.find(comment.user_id).surname}:" %> + <%= comment.body %> +

+ <% end %>

Add a comment:

<%= form_with model: [@post, @post.comments.build] do |form| %>

- <%= form.text_field :user_id, value: current_user.id, type: hidden %> + <%= form.text_field :user_id, value: current_user.id, type: :hidden %>

<%= form.text_area :body %> From 504d2d26081753f7d6b3bdd7a69e77483e0db93d Mon Sep 17 00:00:00 2001 From: samir Date: Thu, 17 Feb 2022 11:39:03 +0000 Subject: [PATCH 39/56] Added time/date to comments and styling. Changed name to reflect actual poster not logged in user --- app/views/posts/index.html.erb | 2 +- app/views/posts/show.html.erb | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/views/posts/index.html.erb b/app/views/posts/index.html.erb index 4b4a40fcbf..b7d5c6c3b5 100644 --- a/app/views/posts/index.html.erb +++ b/app/views/posts/index.html.erb @@ -16,7 +16,7 @@ <% @posts.reverse.each do |post| %> <%= post.message %> - <%= " #{current_user.first_name} #{current_user.surname} " %> + <%= " #{User.find(post.user_id).first_name} #{User.find(post.user_id).surname} " %> <%= post.created_at.strftime("%d/%m/%y") %> <%= post.created_at.strftime("%H:%M") %> diff --git a/app/views/posts/show.html.erb b/app/views/posts/show.html.erb index fa7ac21c5d..1f0137508e 100644 --- a/app/views/posts/show.html.erb +++ b/app/views/posts/show.html.erb @@ -11,8 +11,14 @@

Comments

<% @post.comments.each do |comment| %>

- <%= "#{User.find(comment.user_id).first_name} #{User.find(comment.user_id).surname}:" %> + +

<% end %> From 4c79fea78420c07153311ca54172773da79b82e6 Mon Sep 17 00:00:00 2001 From: chisambwe Date: Thu, 17 Feb 2022 12:16:22 +0000 Subject: [PATCH 40/56] comments added and post link removed --- app/assets/stylesheets/application.scss | 90 +++++++++++++++++++++++++ app/views/layouts/application.html.erb | 2 - app/views/posts/index.html.erb | 2 +- db/schema.rb | 40 +++++++++++ 4 files changed, 131 insertions(+), 3 deletions(-) diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 97d3731a2c..f77aeaf4e7 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -13,3 +13,93 @@ */ @import "bootstrap"; + + @import url("https://fonts.googleapis.com/css2?family=Poppins:wght@100;200;300;400;500;600;700;800&display=swap"); + +body { + background-color: #eee; + font-family: "Poppins", sans-serif; + font-weight: 300 +} + +.card { + border: none +} + +.ellipsis { + color: #a09c9c +} + +hr { + color: #a09c9c; + margin-top: 4px; + margin-bottom: 8px +} + +.muted-color { + color: #a09c9c; + font-size: 13px +} + +.ellipsis i { + margin-top: 3px; + cursor: pointer +} + +.icons i { + font-size: 25px +} + +.icons .fa-heart { + color: red +} + +.icons .fa-smile-o { + color: yellow; + font-size: 29px +} + +.rounded-image { + border-radius: 50% !important; + display: flex; + justify-content: center; + align-items: center; + height: 50px; + width: 50px +} + +.name { + font-weight: 600 +} + +.comment-text { + font-size: 12px +} + +.status small { + margin-right: 10px; + color: blue +} + +.form-control { + border-radius: 26px +} + +.comment-input { + position: relative +} + +.fonts { + position: absolute; + right: 13px; + top: 8px; + color: #a09c9c +} + +.form-control:focus { + color: #495057; + background-color: #fff; + border-color: #8bbafe; + outline: 0; + box-shadow: none +} diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 06fe30237b..6d88d68258 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -28,8 +28,6 @@ <% else %> - + diff --git a/db/schema.rb b/db/schema.rb index 29b91ccb9a..b0171de99a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -25,6 +25,44 @@ t.datetime "updated_at", precision: 6, null: false end + create_table "action_text_rich_texts", force: :cascade do |t| + t.string "name", null: false + t.text "body" + t.string "record_type", null: false + t.bigint "record_id", null: false + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["record_type", "record_id", "name"], name: "index_action_text_rich_texts_uniqueness", unique: true + end + + create_table "active_storage_attachments", force: :cascade do |t| + t.string "name", null: false + t.string "record_type", null: false + t.bigint "record_id", null: false + t.bigint "blob_id", null: false + t.datetime "created_at", null: false + t.index ["blob_id"], name: "index_active_storage_attachments_on_blob_id" + t.index ["record_type", "record_id", "name", "blob_id"], name: "index_active_storage_attachments_uniqueness", unique: true + end + + create_table "active_storage_blobs", force: :cascade do |t| + t.string "key", null: false + t.string "filename", null: false + t.string "content_type" + t.text "metadata" + t.string "service_name", null: false + t.bigint "byte_size", null: false + t.string "checksum", null: false + t.datetime "created_at", null: false + t.index ["key"], name: "index_active_storage_blobs_on_key", unique: true + end + + create_table "active_storage_variant_records", force: :cascade do |t| + t.bigint "blob_id", null: false + t.string "variation_digest", null: false + t.index ["blob_id", "variation_digest"], name: "index_active_storage_variant_records_uniqueness", unique: true + end + create_table "comments", force: :cascade do |t| t.bigint "user_id", null: false t.text "body" @@ -57,6 +95,8 @@ t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true end + add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id" + add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id" add_foreign_key "comments", "posts" add_foreign_key "comments", "users" end From 792b365c181b7226a660374409c84c6bdd67a22b Mon Sep 17 00:00:00 2001 From: samir Date: Thu, 17 Feb 2022 14:29:52 +0000 Subject: [PATCH 41/56] Continuous Development - Github Actions --- .github/workflows/main.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000000..cf375a29f2 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,17 @@ +name: Deploy + +on: + push: + branches: + - main + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: akhileshns/heroku-deploy@v3.12.12 # This is the action + with: + heroku_api_key: ${{secrets.HEROKU_API_KEY}} + heroku_app_name: "Acebook-chats" #Must be unique in Heroku + heroku_email: "alexjamshidi@gmail.com" \ No newline at end of file From fb0a8c708474c769bfc15ac90a0ef53192462986 Mon Sep 17 00:00:00 2001 From: Alexander Jamshidi Date: Thu, 17 Feb 2022 15:02:28 +0000 Subject: [PATCH 42/56] bundle install ran to test CI through github/heroku integration --- Gemfile.lock | 1 + app/models/assignment.rb | 4 ++++ db/migrate/20220211173710_create_assignments.rb | 10 ++++++++++ spec/models/assignment_spec.rb | 5 +++++ 4 files changed, 20 insertions(+) create mode 100644 app/models/assignment.rb create mode 100644 db/migrate/20220211173710_create_assignments.rb create mode 100644 spec/models/assignment_spec.rb diff --git a/Gemfile.lock b/Gemfile.lock index 2b89bca310..d27371d52d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -267,6 +267,7 @@ GEM PLATFORMS arm64-darwin-20 + arm64-darwin-21 DEPENDENCIES bootstrap (~> 5.1.3) diff --git a/app/models/assignment.rb b/app/models/assignment.rb new file mode 100644 index 0000000000..9436434a0e --- /dev/null +++ b/app/models/assignment.rb @@ -0,0 +1,4 @@ +class Assignment < ApplicationRecord + belongs_to :user + belongs_to :post +end diff --git a/db/migrate/20220211173710_create_assignments.rb b/db/migrate/20220211173710_create_assignments.rb new file mode 100644 index 0000000000..b0b8d7c3fb --- /dev/null +++ b/db/migrate/20220211173710_create_assignments.rb @@ -0,0 +1,10 @@ +class CreateAssignments < ActiveRecord::Migration[6.1] + def change + create_table :assignments do |t| + t.references :user, null: false, foreign_key: true + t.references :post, null: false, foreign_key: true + + t.timestamps + end + end +end diff --git a/spec/models/assignment_spec.rb b/spec/models/assignment_spec.rb new file mode 100644 index 0000000000..a7f4f25eed --- /dev/null +++ b/spec/models/assignment_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Assignment, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end From 1342089deec72236411828254aed5ffe91ef8c76 Mon Sep 17 00:00:00 2001 From: Alexander Jamshidi Date: Thu, 17 Feb 2022 15:05:21 +0000 Subject: [PATCH 43/56] bundle install ran to test CI through github/heroku integration 2 --- db/schema.rb | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/db/schema.rb b/db/schema.rb index 29b91ccb9a..8c2fb86d42 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -15,14 +15,13 @@ # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" - create_table "acebooks", force: :cascade do |t| - t.string "first_name" - t.string "last_name" - t.string "email" - t.string "phone_number" - t.string "password" + create_table "assignments", force: :cascade do |t| + t.bigint "user_id", null: false + t.bigint "post_id", null: false t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false + t.index ["post_id"], name: "index_assignments_on_post_id" + t.index ["user_id"], name: "index_assignments_on_user_id" end create_table "comments", force: :cascade do |t| @@ -57,6 +56,8 @@ t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true end + add_foreign_key "assignments", "posts" + add_foreign_key "assignments", "users" add_foreign_key "comments", "posts" add_foreign_key "comments", "users" end From f2d79b5fd787d1aaecc620005149d37a03aaeab6 Mon Sep 17 00:00:00 2001 From: Tyrone Williams Date: Thu, 17 Feb 2022 15:11:19 +0000 Subject: [PATCH 44/56] sign up, sign in css --- app/views/devise/registrations/edit.html.erb | 6 +-- app/views/devise/registrations/new.html.erb | 48 ++++++++------------ app/views/devise/sessions/new.html.erb | 24 ++++++---- app/views/devise/shared/_links.html.erb | 7 +-- app/views/layouts/application.html.erb | 11 +++++ 5 files changed, 54 insertions(+), 42 deletions(-) diff --git a/app/views/devise/registrations/edit.html.erb b/app/views/devise/registrations/edit.html.erb index 38d95b85a8..7efa59bb5e 100644 --- a/app/views/devise/registrations/edit.html.erb +++ b/app/views/devise/registrations/edit.html.erb @@ -1,4 +1,4 @@ -

Edit <%= resource_name.to_s.humanize %>

+

Change password

<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %> <%= render "devise/shared/error_messages", resource: resource %> @@ -13,7 +13,7 @@ <% end %>
- <%= f.label :password %> (leave blank if you don't want to change it)
+ <%= f.label :password %>
<%= f.password_field :password, autocomplete: "new-password" %> <% if @minimum_password_length %>
@@ -27,7 +27,7 @@
- <%= f.label :current_password %> (we need your current password to confirm your changes)
+ <%= f.label :current_password %>
(we need your current password to confirm your changes)
<%= f.password_field :current_password, autocomplete: "current-password" %>
diff --git a/app/views/devise/registrations/new.html.erb b/app/views/devise/registrations/new.html.erb index 6862529d4c..c5d34f3f6f 100644 --- a/app/views/devise/registrations/new.html.erb +++ b/app/views/devise/registrations/new.html.erb @@ -1,41 +1,33 @@ -

Sign up

- +

Sign up to

+

Acebook

+
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %> <%= render "devise/shared/error_messages", resource: resource %> - -
-
+ <%= "#{User.find(comment.user_id).first_name} #{User.find(comment.user_id).surname}:" %> + <%= comment.body %> +
+ <%= " (#{comment.created_at.strftime("%d/%m/%y")} #{comment.created_at.strftime("%H:%M")})" %> + <%= post.created_at.strftime("%d/%m/%y") %> <%= post.created_at.strftime("%H:%M") %><%= link_to 'Show', post %><%= link_to 'Comments', post %> <%= link_to 'Edit', edit_post_path(post) %> <%= link_to 'Destroy', post, method: :delete, data: { confirm: 'Are you sure?' } %>
- - - - - - -
<%= f.label :first_name %> <%= f.label :surname %>
<%= f.text_field :first_name, autofocus: true %><%= f.text_field :surname, autofocus: true %>
+
+

+ <%= f.text_field :surname, autofocus: true, autocomplete: "name", placeholder: "name", class: "form-control" %>
- - +
- <%= f.label :email %>
- <%= f.email_field :email, autofocus: true, autocomplete: "email" %> + <%= f.text_field :surname, autofocus: true, autocomplete: "surname", placeholder: "surname", class: "form-control" %>
- +
+
+ <%= f.email_field :email, autofocus: true, autocomplete: "email", placeholder: "email", class: "form-control" %> +
+
- <%= f.label :password %> - <% if @minimum_password_length %> - (<%= @minimum_password_length %> characters minimum) - <% end %>
- <%= f.password_field :password, autocomplete: "new-password" %> + <%= f.password_field :password, autocomplete: "new-password", placeholder: "password", class: "form-control" %>
- +
- <%= f.label :password_confirmation %>
- <%= f.password_field :password_confirmation, autocomplete: "new-password" %> + <%= f.password_field :password_confirmation, autocomplete: "new-password", placeholder: "password confirmation", class: "form-control" %>
-
- <%= f.submit "Sign up" %> +
+ <%= f.submit "Sign up", class: 'btn btn-primary'%>
<% end %> +
-<%= render "devise/shared/links" %> +<%# <%= render "devise/shared/links" %> diff --git a/app/views/devise/sessions/new.html.erb b/app/views/devise/sessions/new.html.erb index 5ede96489d..12d9f65bd5 100644 --- a/app/views/devise/sessions/new.html.erb +++ b/app/views/devise/sessions/new.html.erb @@ -1,14 +1,18 @@ -

Log in

+

Log in to

+

Acebook

+<%#
%> +
+
<%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
- <%= f.label :email %>
- <%= f.email_field :email, autofocus: true, autocomplete: "email" %> + <%= f.email_field :email, autofocus: true, autocomplete: "email", placeholder: "email", class: "form-control" %>
+
+
- <%= f.label :password %>
- <%= f.password_field :password, autocomplete: "current-password" %> + <%= f.password_field :password, autocomplete: "current-password", placeholder: "Password", class: "form-control" %>
<% if devise_mapping.rememberable? %> @@ -17,10 +21,14 @@ <%= f.label :remember_me %>
<% end %> - -
- <%= f.submit "Log in" %> +
+
+ <%# #mx-auto %> + <%= f.submit "Log in", class: 'btn btn-primary' %>
<% end %> +
+ <%= render "devise/shared/links" %> +
\ No newline at end of file diff --git a/app/views/devise/shared/_links.html.erb b/app/views/devise/shared/_links.html.erb index 96a9412417..d17d565f09 100644 --- a/app/views/devise/shared/_links.html.erb +++ b/app/views/devise/shared/_links.html.erb @@ -2,14 +2,15 @@ <%= link_to "Log in", new_session_path(resource_name) %>
<% end %> +<%#
<%- if devise_mapping.registerable? && controller_name != 'registrations' %> - <%= link_to "Sign up", new_registration_path(resource_name) %>
-<% end %> + <%# <%= link_to "Sign up", new_registration_path(resource_name) %> +
<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %> <%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %>
<% end %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 6d88d68258..b40e341ff7 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -10,8 +10,12 @@
+

<%= notice %>

<%= alert %>

From 01975768d67d7937005a8d12b4b12668bce08e1b Mon Sep 17 00:00:00 2001 From: Alexander Jamshidi Date: Thu, 17 Feb 2022 15:11:51 +0000 Subject: [PATCH 45/56] bundle install ran to test CI through github/heroku integration 3 --- .ruby-version | 2 +- Gemfile | 1 + Gemfile.lock | 6 ++++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.ruby-version b/.ruby-version index 24ba9a38de..4a36342fca 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.7.0 +3.0.0 diff --git a/Gemfile b/Gemfile index 300be9982e..4a4b5dc5f1 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,7 @@ # frozen_string_literal: true source 'https://rubygems.org' +ruby "3.0.0" git_source(:github) do |repo_name| repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?('/') diff --git a/Gemfile.lock b/Gemfile.lock index d27371d52d..dc29db46af 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -266,7 +266,6 @@ GEM zeitwerk (2.5.4) PLATFORMS - arm64-darwin-20 arm64-darwin-21 DEPENDENCIES @@ -294,5 +293,8 @@ DEPENDENCIES uglifier (>= 1.3.0) web-console (>= 3.3.0) +RUBY VERSION + ruby 3.0.0p0 + BUNDLED WITH - 2.3.4 + 2.2.33 From 7ca650ed5402d5ebaed2da08a36ebc3c0532f5dc Mon Sep 17 00:00:00 2001 From: Alexander Jamshidi Date: Thu, 17 Feb 2022 15:13:27 +0000 Subject: [PATCH 46/56] bundle install ran to test CI through github/heroku integration 4 --- Gemfile.lock | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Gemfile.lock b/Gemfile.lock index dc29db46af..86ea17390c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -126,6 +126,8 @@ GEM nio4r (2.5.8) nokogiri (1.13.1-arm64-darwin) racc (~> 1.4) + nokogiri (1.13.1-x86_64-linux) + racc (~> 1.4) orm_adapter (0.5.0) parallel (1.21.0) parser (3.1.0.0) @@ -267,6 +269,7 @@ GEM PLATFORMS arm64-darwin-21 + x86_64-linux DEPENDENCIES bootstrap (~> 5.1.3) From 9a37583d3e748fab99bdd5430677b727b7618277 Mon Sep 17 00:00:00 2001 From: Alexander Jamshidi Date: Thu, 17 Feb 2022 15:19:19 +0000 Subject: [PATCH 47/56] bundle install ran to test CI through github/heroku integration 5 --- package-lock.json | 33 +++++++++++++++++++++++++++++++++ package.json | 4 +++- 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 package-lock.json diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000000..84bdf21246 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,33 @@ +{ + "name": "acebook", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "name": "acebook", + "dependencies": { + "yarn": "^1.22.17" + } + }, + "node_modules/yarn": { + "version": "1.22.17", + "resolved": "https://registry.npmjs.org/yarn/-/yarn-1.22.17.tgz", + "integrity": "sha512-H0p241BXaH0UN9IeH//RT82tl5PfNraVpSpEoW+ET7lmopNC61eZ+A+IDvU8FM6Go5vx162SncDL8J1ZjRBriQ==", + "hasInstallScript": true, + "bin": { + "yarn": "bin/yarn.js", + "yarnpkg": "bin/yarn.js" + }, + "engines": { + "node": ">=4.0.0" + } + } + }, + "dependencies": { + "yarn": { + "version": "1.22.17", + "resolved": "https://registry.npmjs.org/yarn/-/yarn-1.22.17.tgz", + "integrity": "sha512-H0p241BXaH0UN9IeH//RT82tl5PfNraVpSpEoW+ET7lmopNC61eZ+A+IDvU8FM6Go5vx162SncDL8J1ZjRBriQ==" + } + } +} diff --git a/package.json b/package.json index 29198729cd..2857badd84 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,7 @@ { "name": "acebook", "private": true, - "dependencies": {} + "dependencies": { + "yarn": "^1.22.17" + } } From 39129c7fafec02c0370b0d3712af0f7ab96f788a Mon Sep 17 00:00:00 2001 From: Alexander Jamshidi Date: Thu, 17 Feb 2022 15:31:21 +0000 Subject: [PATCH 48/56] changed uglifier thing --- config/environments/production.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/environments/production.rb b/config/environments/production.rb index 28f4c2f7fd..ce19b19789 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -26,7 +26,7 @@ config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? # Compress JavaScripts and CSS. - config.assets.js_compressor = :uglifier + config.assets.js_compressor = Uglifier.new(harmony: true) # config.assets.css_compressor = :sass # Do not fallback to assets pipeline if a precompiled asset is missed. From f0f28dad1c90cc622dc8a1ab02022c60bbd62aa8 Mon Sep 17 00:00:00 2001 From: chisambwe Date: Thu, 17 Feb 2022 15:33:32 +0000 Subject: [PATCH 49/56] index css added --- app/views/posts/_form.html.erb | 1 - app/views/posts/index.html.erb | 41 ++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/app/views/posts/_form.html.erb b/app/views/posts/_form.html.erb index e78b1d9f1d..a045d88770 100644 --- a/app/views/posts/_form.html.erb +++ b/app/views/posts/_form.html.erb @@ -17,7 +17,6 @@
- <%= form.label :user_id %> <%= form.number_field :user_id, class:"form_control", id: :post_user_id, value: current_user.id, type: :hidden %>
diff --git a/app/views/posts/index.html.erb b/app/views/posts/index.html.erb index b77021473d..1562f054a5 100644 --- a/app/views/posts/index.html.erb +++ b/app/views/posts/index.html.erb @@ -34,3 +34,44 @@
<%= link_to 'New Post', new_post_path %> + +<% @posts.reverse.each do |post| %> +
+
+
+
+
+
+
<%= " #{User.find(post.user_id).first_name} #{User.find(post.user_id).surname} " %> Collegues
+
+
<%= post.created_at.strftime("%H:%M") %>
+
+
+

<%= simple_format(post.message) %>

+
+
+
+
<%= link_to 'Comments', post %> <%= link_to 'Edit', edit_post_path(post) %> <%= link_to 'Destroy', post, method: :delete, data: { confirm: 'Are you sure?' } %>
+
+
+
+
+
Daniel Frozer I like this alot! thanks alot +
Like Reply Translate 18 mins
+
+
+
+
Elizabeth goodmen Thanks for sharing! +
Like Reply Translate 8 mins
+
+
+
+
+
+
+
+
+
+
+
+<% end %> \ No newline at end of file From 9e4f30e6a62c983ddd12378494be6e6370ba0307 Mon Sep 17 00:00:00 2001 From: Alexander Jamshidi Date: Thu, 17 Feb 2022 15:48:03 +0000 Subject: [PATCH 50/56] edited posts controller to check huroku --- app/controllers/posts_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index f1fd39fa44..aef23db56e 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -2,7 +2,7 @@ class PostsController < ApplicationController before_action :set_post, only: %i[show edit update destroy] - before_action :authenticate_user!, except: [:show] + before_action :authenticate_user!, except: [:index, :show] before_action :correct_user, only: [:edit, :update, :destroy] # GET /posts or /posts.json def index From 17e0ad2e02b11d6e5c0ad5e9d23c6e66360d1f84 Mon Sep 17 00:00:00 2001 From: Alexander Jamshidi Date: Thu, 17 Feb 2022 16:14:21 +0000 Subject: [PATCH 51/56] removed ability to see psots index page unless signed in --- app/controllers/posts_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index aef23db56e..f1fd39fa44 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -2,7 +2,7 @@ class PostsController < ApplicationController before_action :set_post, only: %i[show edit update destroy] - before_action :authenticate_user!, except: [:index, :show] + before_action :authenticate_user!, except: [:show] before_action :correct_user, only: [:edit, :update, :destroy] # GET /posts or /posts.json def index From 37dff45b6205ee2637bfc0baee312d77b9659a28 Mon Sep 17 00:00:00 2001 From: chisambwe Date: Thu, 17 Feb 2022 17:01:29 +0000 Subject: [PATCH 52/56] added user names to posts --- app/views/posts/index.html.erb | 4 ++-- app/views/posts/show.html.erb | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/views/posts/index.html.erb b/app/views/posts/index.html.erb index 1562f054a5..a70834cc1e 100644 --- a/app/views/posts/index.html.erb +++ b/app/views/posts/index.html.erb @@ -56,12 +56,12 @@
-
Daniel Frozer I like this alot! thanks alot +
<%= " #{User.find(post.user_id).first_name} #{User.find(post.user_id).surname} " %> <% post.comments %>
Like Reply Translate 18 mins
-
Elizabeth goodmen Thanks for sharing! +
<%= " #{User.find(post.user_id).first_name} #{User.find(post.user_id).surname} " %> Thanks for sharing!
Like Reply Translate 8 mins
diff --git a/app/views/posts/show.html.erb b/app/views/posts/show.html.erb index 79fb3c85aa..7ddca2ce7a 100644 --- a/app/views/posts/show.html.erb +++ b/app/views/posts/show.html.erb @@ -1,4 +1,3 @@ -

<%= notice %>

Message: From 65ccbc69d65fe7efc2cb6baff6a4d4c6967634c0 Mon Sep 17 00:00:00 2001 From: chisambwe Date: Thu, 17 Feb 2022 17:14:57 +0000 Subject: [PATCH 53/56] Read me update --- db/schema.rb | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/db/schema.rb b/db/schema.rb index 241ec8d6d7..3077ceaf2b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -15,13 +15,14 @@ # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" - create_table "assignments", force: :cascade do |t| - t.bigint "user_id", null: false - t.bigint "post_id", null: false + create_table "acebooks", force: :cascade do |t| + t.string "first_name" + t.string "last_name" + t.string "email" + t.string "phone_number" + t.string "password" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false - t.index ["post_id"], name: "index_assignments_on_post_id" - t.index ["user_id"], name: "index_assignments_on_user_id" end create_table "action_text_rich_texts", force: :cascade do |t| @@ -62,6 +63,15 @@ t.index ["blob_id", "variation_digest"], name: "index_active_storage_variant_records_uniqueness", unique: true end + create_table "assignments", force: :cascade do |t| + t.bigint "user_id", null: false + t.bigint "post_id", null: false + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["post_id"], name: "index_assignments_on_post_id" + t.index ["user_id"], name: "index_assignments_on_user_id" + end + create_table "comments", force: :cascade do |t| t.bigint "user_id", null: false t.text "body" @@ -94,9 +104,10 @@ t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true end - add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id" add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id" + add_foreign_key "assignments", "posts" + add_foreign_key "assignments", "users" add_foreign_key "comments", "posts" add_foreign_key "comments", "users" end From 9c94e5a2d92ff30e7978df768dacde9686e319b5 Mon Sep 17 00:00:00 2001 From: chisambwe Date: Thu, 17 Feb 2022 17:16:16 +0000 Subject: [PATCH 54/56] Read me update2 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5368edfce4..2d97bf4f09 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ and migrate it, ran: rails db:migrate ran: rails routes (to see new routes added) -## Mockup Design +## Mockup Design ![Welcome!](https://user-images.githubusercontent.com/87937468/153431859-d29a5428-1171-44a5-8850-7afec1a5cd4d.png) From 9ce00c69ee894b01a1186e85e2e723f0a175fbc2 Mon Sep 17 00:00:00 2001 From: chisambwe Date: Thu, 17 Feb 2022 18:50:14 +0000 Subject: [PATCH 55/56] index css --- Gemfile.lock | 1 + app/assets/stylesheets/application.scss | 4 ++ app/controllers/comments_controller.rb | 2 +- app/controllers/posts_controller.rb | 2 +- app/views/layouts/application.html.erb | 8 +-- app/views/posts/index.html.erb | 77 +++++++++---------------- 6 files changed, 36 insertions(+), 58 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 86ea17390c..f0ee3d7935 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -268,6 +268,7 @@ GEM zeitwerk (2.5.4) PLATFORMS + arm64-darwin-20 arm64-darwin-21 x86_64-linux diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index f77aeaf4e7..826c3be3b1 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -103,3 +103,7 @@ hr { outline: 0; box-shadow: none } + +.comment-font { + font-size: 10px; +} diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index f49c028faa..0e5bdb7725 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -2,7 +2,7 @@ class CommentsController < ApplicationController def create @post = Post.find(params[:post_id]) @comment = @post.comments.create(comment_params) - redirect_to post_path(@post) + redirect_to post_index_path end private diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index f1fd39fa44..97ced89060 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -55,7 +55,7 @@ def destroy @post.destroy respond_to do |format| - format.html { redirect_to posts_url, notice: 'Post was successfully destroyed.' } + format.html { redirect_to posts_index_url, notice: 'Post was successfully destroyed.' } format.json { head :no_content } end end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index b40e341ff7..63b7abaf8a 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -50,13 +50,9 @@

- -

<%= notice %>

-

<%= alert %>

- +

<%= notice %>

+

<%= alert %>

<%= yield %> - - diff --git a/app/views/posts/index.html.erb b/app/views/posts/index.html.erb index a70834cc1e..0e2b89cdc2 100644 --- a/app/views/posts/index.html.erb +++ b/app/views/posts/index.html.erb @@ -1,38 +1,4 @@

Posts

- - - - - - - - - - - - - - - <% @posts.reverse.each do |post| %> - - - - - - - - - - - - <% post.comments %> - <% end %> - -
MessageNameDate/Time
Created at
Options
<%= simple_format(post.message) %><%= " #{User.find(post.user_id).first_name} #{User.find(post.user_id).surname} " %><%= post.created_at.strftime("%d/%m/%y") %><%= post.created_at.strftime("%H:%M") %><%= link_to 'Comments', post %><%= link_to 'Edit', edit_post_path(post) %><%= link_to 'Destroy', post, method: :delete, data: { confirm: 'Are you sure?' } %>
- - -
- <%= link_to 'New Post', new_post_path %> <% @posts.reverse.each do |post| %> @@ -41,33 +7,44 @@
-
-
<%= " #{User.find(post.user_id).first_name} #{User.find(post.user_id).surname} " %> Collegues
+
+
<%= " #{User.find(post.user_id).first_name} #{User.find(post.user_id).surname} " %>
-
<%= post.created_at.strftime("%H:%M") %>
-
+
<%= "#{post.created_at.strftime("%d/%m/%y")}  #{post.created_at.strftime("%H:%M")}" %>
+

<%= simple_format(post.message) %>


-
<%= link_to 'Comments', post %> <%= link_to 'Edit', edit_post_path(post) %> <%= link_to 'Destroy', post, method: :delete, data: { confirm: 'Are you sure?' } %>
+ <%= "#{post.comments.length} Comments" %> +
<%= link_to 'Edit', edit_post_path(post) %> - <%= link_to 'Destroy', post, method: :delete, data: { confirm: 'Are you sure?' } %>

-
-
<%= " #{User.find(post.user_id).first_name} #{User.find(post.user_id).surname} " %> <% post.comments %> -
Like Reply Translate 18 mins
+ <% post.comments.each do |comment| %> +
+
<%= " #{User.find(comment.user_id).first_name} #{User.find(comment.user_id).surname} " %> <%= comment.body %> +
+
+                                  

<%= post.created_at.strftime("%d/%m/%y") %> <%= comment.created_at.strftime("%H:%M") %>

+
+
-
-
<%= " #{User.find(post.user_id).first_name} #{User.find(post.user_id).surname} " %> Thanks for sharing! -
Like Reply Translate 8 mins
-
-
-
-
-
+ <% end %> + <%= form_with model: [post, post.comments.build] do + |form| %> +

+ <%= form.text_field :user_id, value: current_user.id, type: :hidden %> +

+

+ <%= form.text_area :body, class: 'form-control'%> +

+

+ <%= form.submit class: 'form-control' %> +

+ <% end %>
From 8f1c1d05156b487f46a2565f0ff0d1815b8188af Mon Sep 17 00:00:00 2001 From: chisambwe Date: Thu, 17 Feb 2022 20:03:58 +0000 Subject: [PATCH 56/56] css improvements --- app/controllers/posts_controller.rb | 3 ++- app/views/devise/registrations/new.html.erb | 2 +- app/views/layouts/application.html.erb | 13 +++++++++-- app/views/posts/_form.html.erb | 5 ++--- app/views/posts/edit.html.erb | 11 +++++---- app/views/posts/index.html.erb | 25 ++++++++++++--------- 6 files changed, 38 insertions(+), 21 deletions(-) diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 97ced89060..1d733735c2 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -7,6 +7,7 @@ class PostsController < ApplicationController # GET /posts or /posts.json def index @posts = Post.all + @post = current_user.posts.build end # GET /posts/1 or /posts/1.json @@ -41,7 +42,7 @@ def create def update respond_to do |format| if @post.update(post_params) - format.html { redirect_to post_url(@post), notice: 'Post was successfully updated.' } + format.html { redirect_to posts_index_url, notice: 'Post was successfully updated.' } format.json { render :show, status: :ok, location: @post } else format.html { render :edit, status: :unprocessable_entity } diff --git a/app/views/devise/registrations/new.html.erb b/app/views/devise/registrations/new.html.erb index c5d34f3f6f..41a71500d0 100644 --- a/app/views/devise/registrations/new.html.erb +++ b/app/views/devise/registrations/new.html.erb @@ -5,7 +5,7 @@ <%= render "devise/shared/error_messages", resource: resource %>
- <%= f.text_field :surname, autofocus: true, autocomplete: "name", placeholder: "name", class: "form-control" %> + <%= f.text_field :first_name, autofocus: true, autocomplete: "first_name", placeholder: "first name", class: "form-control" %>

diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 63b7abaf8a..db7c3fb7f7 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -15,7 +15,6 @@ <% if user_signed_in? %> - <% else %> <% end %> @@ -50,8 +49,18 @@
-

<%= notice %>

+
+ <% if user_signed_in? %> + <%= "Signed in as: " %> + <%= "#{current_user.first_name} #{current_user.surname}" %> + <%= "(#{current_user.email})" %> + + <% end %> +
+ +

<%= notice %>

<%= alert %>

+ <%= yield %> diff --git a/app/views/posts/_form.html.erb b/app/views/posts/_form.html.erb index a045d88770..bf3c4382bb 100644 --- a/app/views/posts/_form.html.erb +++ b/app/views/posts/_form.html.erb @@ -12,8 +12,7 @@ <% end %>
- <%= form.label :message %> - <%= form.text_area :message %> + <%= form.text_area :message, class: 'form-control', placeholder: "Write a new post..." %>
@@ -21,6 +20,6 @@
- <%= form.submit %> + <%= form.submit class: 'form-control' %>
<% end %> diff --git a/app/views/posts/edit.html.erb b/app/views/posts/edit.html.erb index ded33f77ac..1ed65b2abf 100644 --- a/app/views/posts/edit.html.erb +++ b/app/views/posts/edit.html.erb @@ -1,6 +1,9 @@ -

Editing Post

+
+
-<%= render 'form', post: @post %> +

Editing Post

+ <%= render 'form', post: @post %> + <%= link_to 'Back', posts_path %> -<%= link_to 'Show', @post %> | -<%= link_to 'Back', posts_path %> +
+
diff --git a/app/views/posts/index.html.erb b/app/views/posts/index.html.erb index 0e2b89cdc2..2eeb26e250 100644 --- a/app/views/posts/index.html.erb +++ b/app/views/posts/index.html.erb @@ -1,6 +1,12 @@ -

Posts

-<%= link_to 'New Post', new_post_path %> - +
+
+ + + <%= render 'form', post: @post %> + + +
+
<% @posts.reverse.each do |post| %>
@@ -15,8 +21,7 @@

<%= simple_format(post.message) %>


-
-
+
<%= "#{post.comments.length} Comments" %>
<%= link_to 'Edit', edit_post_path(post) %> - <%= link_to 'Destroy', post, method: :delete, data: { confirm: 'Are you sure?' } %>
@@ -24,22 +29,22 @@
<% post.comments.each do |comment| %>
-
<%= " #{User.find(comment.user_id).first_name} #{User.find(comment.user_id).surname} " %> <%= comment.body %> +
<%= " #{User.find(comment.user_id).first_name} " " #{User.find(comment.user_id).surname} " %> <%= comment.body %>
-
+                                  
                                   

<%= post.created_at.strftime("%d/%m/%y") %> <%= comment.created_at.strftime("%H:%M") %>

-
+
<% end %> - <%= form_with model: [post, post.comments.build] do + <%= form_with model: [post, post.comments.build] do |form| %>

<%= form.text_field :user_id, value: current_user.id, type: :hidden %>

- <%= form.text_area :body, class: 'form-control'%> + <%= form.text_area :body, class: 'form-control', placeholder: "Add a new commen..."%>

<%= form.submit class: 'form-control' %>