├── .gitattributes ├── .github └── workflows │ └── linters.yml ├── .gitignore ├── .rspec ├── .rubocop.yml ├── .ruby-version ├── .stylelintrc.json ├── Gemfile ├── Gemfile.lock ├── LICENSE ├── README.md ├── Rakefile ├── app ├── assets │ ├── config │ │ └── manifest.js │ ├── images │ │ └── .keep │ └── stylesheets │ │ └── application.css.scss ├── channels │ └── application_cable │ │ ├── channel.rb │ │ └── connection.rb ├── controllers │ ├── api │ │ ├── api_controller.rb │ │ ├── comments_controller.rb │ │ └── posts_controller.rb │ ├── application_controller.rb │ ├── comments_controller.rb │ ├── concerns │ │ └── .keep │ ├── likes_controller.rb │ ├── posts_controller.rb │ └── users_controller.rb ├── helpers │ ├── api │ │ ├── api_helper.rb │ │ ├── comments_helper.rb │ │ └── posts_helper.rb │ ├── application_helper.rb │ ├── comments_helper.rb │ ├── likes_helper.rb │ ├── posts_helper.rb │ └── users_helper.rb ├── javascript │ ├── application.js │ └── controllers │ │ ├── application.js │ │ ├── hello_controller.js │ │ └── index.js ├── jobs │ └── application_job.rb ├── mailers │ └── application_mailer.rb ├── models │ ├── ability.rb │ ├── application_record.rb │ ├── comment.rb │ ├── concerns │ │ └── .keep │ ├── like.rb │ ├── post.rb │ └── user.rb └── views │ ├── comments │ └── new.html.erb │ ├── devise │ ├── confirmations │ │ └── new.html.erb │ ├── mailer │ │ ├── confirmation_instructions.html.erb │ │ ├── email_changed.html.erb │ │ ├── password_change.html.erb │ │ ├── reset_password_instructions.html.erb │ │ └── unlock_instructions.html.erb │ ├── passwords │ │ ├── edit.html.erb │ │ └── new.html.erb │ ├── registrations │ │ ├── edit.html.erb │ │ └── new.html.erb │ ├── sessions │ │ └── new.html.erb │ ├── shared │ │ ├── _error_messages.html.erb │ │ └── _links.html.erb │ └── unlocks │ │ └── new.html.erb │ ├── layouts │ ├── application.html.erb │ ├── mailer.html.erb │ └── mailer.text.erb │ ├── likes │ └── new.html.erb │ ├── posts │ ├── index.html.erb │ ├── new.html.erb │ └── show.html.erb │ └── users │ ├── index.html.erb │ └── show.html.erb ├── bin ├── bundle ├── bundle.cmd ├── importmap ├── rails ├── rake └── setup ├── config.ru ├── config ├── application.rb ├── boot.rb ├── cable.yml ├── database.yml ├── environment.rb ├── environments │ ├── development.rb │ ├── production.rb │ └── test.rb ├── importmap.rb ├── initializers │ ├── assets.rb │ ├── content_security_policy.rb │ ├── devise.rb │ ├── filter_parameter_logging.rb │ ├── inflections.rb │ └── permissions_policy.rb ├── locales │ ├── devise.en.yml │ └── en.yml ├── puma.rb ├── routes.rb └── storage.yml ├── db ├── migrate │ ├── 20230608114107_create_users.rb │ ├── 20230608114150_create_posts.rb │ ├── 20230608114218_create_comments.rb │ ├── 20230608114243_create_likes.rb │ ├── 20230608114426_add_post_ref_to_comments.rb │ ├── 20230608114447_add_user_ref_to_comments.rb │ ├── 20230608114520_add_user_ref_to_posts.rb │ ├── 20230608114546_add_user_ref_to_likes.rb │ ├── 20230608114604_add_post_ref_to_likes.rb │ ├── 20230620134255_add_devise_to_users.rb │ └── 20230621132536_add_role_to_users.rb ├── schema.rb └── seeds.rb ├── lib ├── assets │ └── .keep └── tasks │ └── .keep ├── log └── .keep ├── package-lock.json ├── package.json ├── public ├── 404.html ├── 422.html ├── 500.html ├── apple-touch-icon-precomposed.png ├── apple-touch-icon.png ├── favicon.ico └── robots.txt ├── spec ├── helpers │ ├── api │ │ ├── api_helper_spec.rb │ │ ├── comments_helper_spec.rb │ │ └── posts_helper_spec.rb │ ├── comment_helper_spec.rb │ ├── likes_helper_spec.rb │ └── posts_helper_spec.rb ├── models │ ├── comment_spec.rb │ ├── like_spec.rb │ ├── post_spec.rb │ └── user_spec.rb ├── rails_helper.rb ├── requests │ ├── api │ │ ├── api_spec.rb │ │ ├── comments_spec.rb │ │ └── posts_spec.rb │ ├── posts_spec.rb │ └── users_spec.rb ├── spec_helper.rb └── views_integration │ ├── post_spec.rb │ └── user_spec.rb ├── storage └── .keep ├── test ├── application_system_test_case.rb ├── channels │ └── application_cable │ │ └── connection_test.rb ├── controllers │ └── .keep ├── fixtures │ └── files │ │ └── .keep ├── helpers │ └── .keep ├── integration │ └── .keep ├── mailers │ └── .keep ├── models │ └── .keep ├── system │ └── .keep └── test_helper.rb ├── tmp ├── .keep ├── pids │ └── .keep └── storage │ └── .keep └── vendor ├── .keep └── javascript └── .keep /.gitattributes: -------------------------------------------------------------------------------- 1 | # See https://git-scm.com/docs/gitattributes for more about git attribute files. 2 | 3 | # Mark the database schema as having been generated. 4 | db/schema.rb linguist-generated 5 | 6 | # Mark any vendored files as having been vendored. 7 | vendor/* linguist-vendored 8 | -------------------------------------------------------------------------------- /.github/workflows/linters.yml: -------------------------------------------------------------------------------- 1 | name: Linters 2 | 3 | on: pull_request 4 | 5 | env: 6 | FORCE_COLOR: 1 7 | 8 | jobs: 9 | rubocop: 10 | name: Rubocop 11 | runs-on: ubuntu-22.04 12 | steps: 13 | - uses: actions/checkout@v3 14 | - uses: actions/setup-ruby@v1 15 | with: 16 | ruby-version: 3.1.x 17 | - name: Setup Rubocop 18 | run: | 19 | gem install --no-document rubocop -v '>= 1.0, < 2.0' # https://docs.rubocop.org/en/stable/installation/ 20 | [ -f .rubocop.yml ] || wget https://raw.githubusercontent.com/microverseinc/linters-config/master/ror/.rubocop.yml 21 | - name: Rubocop Report 22 | run: rubocop --color 23 | stylelint: 24 | name: Stylelint 25 | runs-on: ubuntu-22.04 26 | steps: 27 | - uses: actions/checkout@v3 28 | - uses: actions/setup-node@v3 29 | with: 30 | node-version: "18.x" 31 | - name: Setup Stylelint 32 | run: | 33 | npm install --save-dev stylelint@13.x stylelint-scss@3.x stylelint-config-standard@21.x stylelint-csstree-validator@1.x 34 | [ -f .stylelintrc.json ] || wget https://raw.githubusercontent.com/microverseinc/linters-config/master/ror/.stylelintrc.json 35 | - name: Stylelint Report 36 | run: npx stylelint "**/*.{css,scss}" 37 | nodechecker: 38 | name: node_modules checker 39 | runs-on: ubuntu-22.04 40 | steps: 41 | - uses: actions/checkout@v3 42 | - name: Check node_modules existence 43 | run: | 44 | if [ -d "node_modules/" ]; then echo -e "\e[1;31mThe node_modules/ folder was pushed to the repo. Please remove it from the GitHub repository and try again."; echo -e "\e[1;32mYou can set up a .gitignore file with this folder included on it to prevent this from happening in the future." && exit 1; fi 45 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files for more about ignoring files. 2 | # 3 | # If you find yourself ignoring temporary files generated by your text editor 4 | # or operating system, you probably want to add a global ignore instead: 5 | # git config --global core.excludesfile '~/.gitignore_global' 6 | 7 | # Ignore bundler config. 8 | /.bundle 9 | 10 | # Ignore all logfiles and tempfiles. 11 | /log/* 12 | /tmp/* 13 | !/log/.keep 14 | !/tmp/.keep 15 | 16 | # Ignore pidfiles, but keep the directory. 17 | /tmp/pids/* 18 | !/tmp/pids/ 19 | !/tmp/pids/.keep 20 | 21 | # Ignore uploaded files in development. 22 | /storage/* 23 | !/storage/.keep 24 | /tmp/storage/* 25 | !/tmp/storage/ 26 | !/tmp/storage/.keep 27 | 28 | /public/assets 29 | 30 | # Ignore master key for decrypting credentials and more. 31 | /config/master.key 32 | 33 | node_modules/ -------------------------------------------------------------------------------- /.rspec: -------------------------------------------------------------------------------- 1 | --require spec_helper 2 | -------------------------------------------------------------------------------- /.rubocop.yml: -------------------------------------------------------------------------------- 1 | AllCops: 2 | NewCops: enable 3 | Exclude: 4 | - "db/**/*" 5 | - "bin/*" 6 | - "config/**/*" 7 | - "Guardfile" 8 | - "Rakefile" 9 | - "node_modules/**/*" 10 | 11 | DisplayCopNames: true 12 | 13 | Layout/LineLength: 14 | Max: 120 15 | Metrics/MethodLength: 16 | Include: 17 | - "app/controllers/*" 18 | - "app/models/*" 19 | Max: 20 20 | Metrics/AbcSize: 21 | Include: 22 | - "app/controllers/*" 23 | - "app/models/*" 24 | Max: 50 25 | Metrics/ClassLength: 26 | Max: 150 27 | Metrics/BlockLength: 28 | AllowedMethods: ['describe'] 29 | Max: 30 30 | 31 | Style/Documentation: 32 | Enabled: false 33 | Style/ClassAndModuleChildren: 34 | Enabled: false 35 | Style/EachForSimpleLoop: 36 | Enabled: false 37 | Style/AndOr: 38 | Enabled: false 39 | Style/DefWithParentheses: 40 | Enabled: false 41 | Style/FrozenStringLiteralComment: 42 | EnforcedStyle: never 43 | 44 | Layout/HashAlignment: 45 | EnforcedColonStyle: key 46 | Layout/ExtraSpacing: 47 | AllowForAlignment: false 48 | Layout/MultilineMethodCallIndentation: 49 | Enabled: true 50 | EnforcedStyle: indented 51 | Lint/RaiseException: 52 | Enabled: false 53 | Lint/StructNewOverride: 54 | Enabled: false 55 | Style/HashEachMethods: 56 | Enabled: false 57 | Style/HashTransformKeys: 58 | Enabled: false 59 | Style/HashTransformValues: 60 | Enabled: false -------------------------------------------------------------------------------- /.ruby-version: -------------------------------------------------------------------------------- 1 | ruby-3.2.2 2 | -------------------------------------------------------------------------------- /.stylelintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["stylelint-config-standard"], 3 | "plugins": ["stylelint-scss", "stylelint-csstree-validator"], 4 | "rules": { 5 | "at-rule-no-unknown": [ 6 | true, 7 | { 8 | "ignoreAtRules": [ 9 | "tailwind", 10 | "apply", 11 | "variants", 12 | "responsive", 13 | "screen" 14 | ] 15 | } 16 | ], 17 | "scss/at-rule-no-unknown": [ 18 | true, 19 | { 20 | "ignoreAtRules": [ 21 | "tailwind", 22 | "apply", 23 | "variants", 24 | "responsive", 25 | "screen" 26 | ] 27 | } 28 | ], 29 | "csstree/validator": true 30 | }, 31 | "ignoreFiles": ["build/**", "dist/**", "**/reset*.css", "**/bootstrap*.css"] 32 | } -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | git_source(:github) { |repo| "https://github.com/#{repo}.git" } 3 | 4 | ruby '3.2.2' 5 | 6 | gem 'rubocop', '>= 1.0', '< 2.0' 7 | 8 | # Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main" 9 | gem 'rails', '~> 7.0.5' 10 | 11 | # The original asset pipeline for Rails [https://github.com/rails/sprockets-rails] 12 | gem 'sprockets-rails' 13 | 14 | # Use sqlite3 as the database for Active Record 15 | # gem 'sqlite3', '~> 1.4' 16 | gem 'pg' 17 | 18 | # Use the devise gem as the session and account manager for the application 19 | gem 'devise' 20 | 21 | # Use the Puma web server [https://github.com/puma/puma] 22 | gem 'puma', '~> 5.0' 23 | 24 | # Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails] 25 | gem 'importmap-rails' 26 | 27 | # Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev] 28 | gem 'turbo-rails' 29 | 30 | # Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev] 31 | gem 'stimulus-rails' 32 | 33 | # Build JSON APIs with ease [https://github.com/rails/jbuilder] 34 | gem 'jbuilder' 35 | 36 | # Use Redis adapter to run Action Cable in production 37 | # gem "redis", "~> 4.0" 38 | 39 | # Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis] 40 | # gem "kredis" 41 | 42 | # Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword] 43 | # gem "bcrypt", "~> 3.1.7" 44 | 45 | # Windows does not include zoneinfo files, so bundle the tzinfo-data gem 46 | gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby] 47 | 48 | # Reduces boot times through caching; required in config/boot.rb 49 | gem 'bootsnap', require: false 50 | 51 | # Use Sass to process CSS 52 | # gem "sassc-rails" 53 | 54 | # Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images] 55 | # gem "image_processing", "~> 1.2" 56 | 57 | group :development, :test do 58 | gem 'rspec-rails' 59 | end 60 | 61 | group :development do 62 | # Use console on exceptions pages [https://github.com/rails/web-console] 63 | gem 'web-console' 64 | 65 | # Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler] 66 | # gem "rack-mini-profiler" 67 | 68 | # Speed up commands on slow machines / big apps [https://github.com/rails/spring] 69 | # gem "spring" 70 | end 71 | 72 | group :test do 73 | # Use system testing [https://guides.rubyonrails.org/testing.html#system-testing] 74 | gem 'capybara' 75 | gem 'selenium-webdriver' 76 | gem 'webdrivers' 77 | end 78 | 79 | # Used in testing to check if a specific template is rendered 80 | gem 'rails-controller-testing' 81 | 82 | gem 'cancancan', '~> 1.9' 83 | 84 | gem 'font-awesome-sass', '~> 6.4.0' 85 | 86 | gem 'sassc' 87 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | actioncable (7.0.5.1) 5 | actionpack (= 7.0.5.1) 6 | activesupport (= 7.0.5.1) 7 | nio4r (~> 2.0) 8 | websocket-driver (>= 0.6.1) 9 | actionmailbox (7.0.5.1) 10 | actionpack (= 7.0.5.1) 11 | activejob (= 7.0.5.1) 12 | activerecord (= 7.0.5.1) 13 | activestorage (= 7.0.5.1) 14 | activesupport (= 7.0.5.1) 15 | mail (>= 2.7.1) 16 | net-imap 17 | net-pop 18 | net-smtp 19 | actionmailer (7.0.5.1) 20 | actionpack (= 7.0.5.1) 21 | actionview (= 7.0.5.1) 22 | activejob (= 7.0.5.1) 23 | activesupport (= 7.0.5.1) 24 | mail (~> 2.5, >= 2.5.4) 25 | net-imap 26 | net-pop 27 | net-smtp 28 | rails-dom-testing (~> 2.0) 29 | actionpack (7.0.5.1) 30 | actionview (= 7.0.5.1) 31 | activesupport (= 7.0.5.1) 32 | rack (~> 2.0, >= 2.2.4) 33 | rack-test (>= 0.6.3) 34 | rails-dom-testing (~> 2.0) 35 | rails-html-sanitizer (~> 1.0, >= 1.2.0) 36 | actiontext (7.0.5.1) 37 | actionpack (= 7.0.5.1) 38 | activerecord (= 7.0.5.1) 39 | activestorage (= 7.0.5.1) 40 | activesupport (= 7.0.5.1) 41 | globalid (>= 0.6.0) 42 | nokogiri (>= 1.8.5) 43 | actionview (7.0.5.1) 44 | activesupport (= 7.0.5.1) 45 | builder (~> 3.1) 46 | erubi (~> 1.4) 47 | rails-dom-testing (~> 2.0) 48 | rails-html-sanitizer (~> 1.1, >= 1.2.0) 49 | activejob (7.0.5.1) 50 | activesupport (= 7.0.5.1) 51 | globalid (>= 0.3.6) 52 | activemodel (7.0.5.1) 53 | activesupport (= 7.0.5.1) 54 | activerecord (7.0.5.1) 55 | activemodel (= 7.0.5.1) 56 | activesupport (= 7.0.5.1) 57 | activestorage (7.0.5.1) 58 | actionpack (= 7.0.5.1) 59 | activejob (= 7.0.5.1) 60 | activerecord (= 7.0.5.1) 61 | activesupport (= 7.0.5.1) 62 | marcel (~> 1.0) 63 | mini_mime (>= 1.1.0) 64 | activesupport (7.0.5.1) 65 | concurrent-ruby (~> 1.0, >= 1.0.2) 66 | i18n (>= 1.6, < 2) 67 | minitest (>= 5.1) 68 | tzinfo (~> 2.0) 69 | addressable (2.8.4) 70 | public_suffix (>= 2.0.2, < 6.0) 71 | ast (2.4.2) 72 | bcrypt (3.1.19) 73 | bindex (0.8.1) 74 | bootsnap (1.16.0) 75 | msgpack (~> 1.2) 76 | builder (3.2.4) 77 | cancancan (1.17.0) 78 | capybara (3.39.2) 79 | addressable 80 | matrix 81 | mini_mime (>= 0.1.3) 82 | nokogiri (~> 1.8) 83 | rack (>= 1.6.0) 84 | rack-test (>= 0.6.3) 85 | regexp_parser (>= 1.5, < 3.0) 86 | xpath (~> 3.2) 87 | concurrent-ruby (1.2.2) 88 | crass (1.0.6) 89 | date (3.3.3) 90 | devise (4.9.2) 91 | bcrypt (~> 3.0) 92 | orm_adapter (~> 0.1) 93 | railties (>= 4.1.0) 94 | responders 95 | warden (~> 1.2.3) 96 | diff-lcs (1.5.0) 97 | erubi (1.12.0) 98 | ffi (1.15.5) 99 | font-awesome-sass (6.4.0) 100 | sassc (~> 2.0) 101 | globalid (1.1.0) 102 | activesupport (>= 5.0) 103 | i18n (1.14.1) 104 | concurrent-ruby (~> 1.0) 105 | importmap-rails (1.2.1) 106 | actionpack (>= 6.0.0) 107 | railties (>= 6.0.0) 108 | jbuilder (2.11.5) 109 | actionview (>= 5.0.0) 110 | activesupport (>= 5.0.0) 111 | json (2.6.3) 112 | language_server-protocol (3.17.0.3) 113 | loofah (2.21.3) 114 | crass (~> 1.0.2) 115 | nokogiri (>= 1.12.0) 116 | mail (2.8.1) 117 | mini_mime (>= 0.1.1) 118 | net-imap 119 | net-pop 120 | net-smtp 121 | marcel (1.0.2) 122 | matrix (0.4.2) 123 | method_source (1.0.0) 124 | mini_mime (1.1.2) 125 | minitest (5.18.1) 126 | msgpack (1.7.1) 127 | net-imap (0.3.6) 128 | date 129 | net-protocol 130 | net-pop (0.1.2) 131 | net-protocol 132 | net-protocol (0.2.1) 133 | timeout 134 | net-smtp (0.3.3) 135 | net-protocol 136 | nio4r (2.5.9) 137 | nokogiri (1.15.2-x64-mingw-ucrt) 138 | racc (~> 1.4) 139 | orm_adapter (0.5.0) 140 | parallel (1.23.0) 141 | parser (3.2.2.3) 142 | ast (~> 2.4.1) 143 | racc 144 | pg (1.5.3-x64-mingw-ucrt) 145 | public_suffix (5.0.1) 146 | puma (5.6.6) 147 | nio4r (~> 2.0) 148 | racc (1.7.1) 149 | rack (2.2.7) 150 | rack-test (2.1.0) 151 | rack (>= 1.3) 152 | rails (7.0.5.1) 153 | actioncable (= 7.0.5.1) 154 | actionmailbox (= 7.0.5.1) 155 | actionmailer (= 7.0.5.1) 156 | actionpack (= 7.0.5.1) 157 | actiontext (= 7.0.5.1) 158 | actionview (= 7.0.5.1) 159 | activejob (= 7.0.5.1) 160 | activemodel (= 7.0.5.1) 161 | activerecord (= 7.0.5.1) 162 | activestorage (= 7.0.5.1) 163 | activesupport (= 7.0.5.1) 164 | bundler (>= 1.15.0) 165 | railties (= 7.0.5.1) 166 | rails-controller-testing (1.0.5) 167 | actionpack (>= 5.0.1.rc1) 168 | actionview (>= 5.0.1.rc1) 169 | activesupport (>= 5.0.1.rc1) 170 | rails-dom-testing (2.0.3) 171 | activesupport (>= 4.2.0) 172 | nokogiri (>= 1.6) 173 | rails-html-sanitizer (1.6.0) 174 | loofah (~> 2.21) 175 | nokogiri (~> 1.14) 176 | railties (7.0.5.1) 177 | actionpack (= 7.0.5.1) 178 | activesupport (= 7.0.5.1) 179 | method_source 180 | rake (>= 12.2) 181 | thor (~> 1.0) 182 | zeitwerk (~> 2.5) 183 | rainbow (3.1.1) 184 | rake (13.0.6) 185 | regexp_parser (2.8.1) 186 | responders (3.1.0) 187 | actionpack (>= 5.2) 188 | railties (>= 5.2) 189 | rexml (3.2.5) 190 | rspec-core (3.12.2) 191 | rspec-support (~> 3.12.0) 192 | rspec-expectations (3.12.3) 193 | diff-lcs (>= 1.2.0, < 2.0) 194 | rspec-support (~> 3.12.0) 195 | rspec-mocks (3.12.5) 196 | diff-lcs (>= 1.2.0, < 2.0) 197 | rspec-support (~> 3.12.0) 198 | rspec-rails (6.0.3) 199 | actionpack (>= 6.1) 200 | activesupport (>= 6.1) 201 | railties (>= 6.1) 202 | rspec-core (~> 3.12) 203 | rspec-expectations (~> 3.12) 204 | rspec-mocks (~> 3.12) 205 | rspec-support (~> 3.12) 206 | rspec-support (3.12.1) 207 | rubocop (1.53.1) 208 | json (~> 2.3) 209 | language_server-protocol (>= 3.17.0) 210 | parallel (~> 1.10) 211 | parser (>= 3.2.2.3) 212 | rainbow (>= 2.2.2, < 4.0) 213 | regexp_parser (>= 1.8, < 3.0) 214 | rexml (>= 3.2.5, < 4.0) 215 | rubocop-ast (>= 1.28.0, < 2.0) 216 | ruby-progressbar (~> 1.7) 217 | unicode-display_width (>= 2.4.0, < 3.0) 218 | rubocop-ast (1.29.0) 219 | parser (>= 3.2.1.0) 220 | ruby-progressbar (1.13.0) 221 | rubyzip (2.3.2) 222 | sassc (2.4.0) 223 | ffi (~> 1.9) 224 | selenium-webdriver (4.10.0) 225 | rexml (~> 3.2, >= 3.2.5) 226 | rubyzip (>= 1.2.2, < 3.0) 227 | websocket (~> 1.0) 228 | sprockets (4.2.0) 229 | concurrent-ruby (~> 1.0) 230 | rack (>= 2.2.4, < 4) 231 | sprockets-rails (3.4.2) 232 | actionpack (>= 5.2) 233 | activesupport (>= 5.2) 234 | sprockets (>= 3.0.0) 235 | stimulus-rails (1.2.1) 236 | railties (>= 6.0.0) 237 | thor (1.2.2) 238 | timeout (0.4.0) 239 | turbo-rails (1.4.0) 240 | actionpack (>= 6.0.0) 241 | activejob (>= 6.0.0) 242 | railties (>= 6.0.0) 243 | tzinfo (2.0.6) 244 | concurrent-ruby (~> 1.0) 245 | tzinfo-data (1.2023.3) 246 | tzinfo (>= 1.0.0) 247 | unicode-display_width (2.4.2) 248 | warden (1.2.9) 249 | rack (>= 2.0.9) 250 | web-console (4.2.0) 251 | actionview (>= 6.0.0) 252 | activemodel (>= 6.0.0) 253 | bindex (>= 0.4.0) 254 | railties (>= 6.0.0) 255 | webdrivers (5.2.0) 256 | nokogiri (~> 1.6) 257 | rubyzip (>= 1.3.0) 258 | selenium-webdriver (~> 4.0) 259 | websocket (1.2.9) 260 | websocket-driver (0.7.5) 261 | websocket-extensions (>= 0.1.0) 262 | websocket-extensions (0.1.5) 263 | xpath (3.2.0) 264 | nokogiri (~> 1.8) 265 | zeitwerk (2.6.8) 266 | 267 | PLATFORMS 268 | x64-mingw-ucrt 269 | 270 | DEPENDENCIES 271 | bootsnap 272 | cancancan (~> 1.9) 273 | capybara 274 | devise 275 | font-awesome-sass (~> 6.4.0) 276 | importmap-rails 277 | jbuilder 278 | pg 279 | puma (~> 5.0) 280 | rails (~> 7.0.5) 281 | rails-controller-testing 282 | rspec-rails 283 | rubocop (>= 1.0, < 2.0) 284 | sassc 285 | selenium-webdriver 286 | sprockets-rails 287 | stimulus-rails 288 | turbo-rails 289 | tzinfo-data 290 | web-console 291 | webdrivers 292 | 293 | RUBY VERSION 294 | ruby 3.2.2p53 295 | 296 | BUNDLED WITH 297 | 2.4.14 298 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | ### Copyright (c) 2023 Lucas David Erkana 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 |

Blog App

3 | 4 | 5 | # 📗 Table of Contents 6 | 7 | - [📗 Table of Contents](#-table-of-contents) 8 | - [📖 Rails Blog App ](#-My-Blog-App-) 9 | - [🛠 Built With ](#-built-with-) 10 | - [Tech Stack ](#tech-stack-) 11 | - [Key Features ](#key-features-) 12 | - [🚀 Live Demo ](#-live-demo-) 13 | - [💻 Getting Started ](#-getting-started-) 14 | - [Prerequisites](#prerequisites) 15 | - [Setup](#setup) 16 | - [Install](#install) 17 | - [Usage](#usage) 18 | - [👥 Authors ](#-authors-) 19 | - [🔭 Future Features ](#-future-features-) 20 | - [🤝 Contributing ](#-contributing-) 21 | - [⭐️ Show your support ](#️-show-your-support-) 22 | - [🙏 Acknowledgments ](#-acknowledgments-) 23 | - [❓ FAQ ](#-faq-) 24 | - [📝 License ](#-license-) 25 | 26 | 27 | 28 | # 📖 Blog App 29 | 30 | > The Blog app will be a classic example of a blog website. It is a Microverse project where they required me to create a fully functional website that will show the list of posts and empower readers to interact with them by adding comments and liking posts. 31 | 32 | ## 🛠 Built With 33 | ### Tech Stack 34 | 35 |
36 | Ruby On Rails 37 | 40 |
41 | 42 | 43 | 44 | ### Key Features 45 | 46 | - **Add User, Post, Like & Comment** 47 | - **List all Users, Posts, Likes & Comments** 48 | - **Sign up** 49 | - **Log in** 50 | - **Reset Password** 51 | 52 |

(back to top)

53 | 54 | 55 | 56 | 57 | ## 💻 Getting Started 58 | 59 | To get a local copy up and running, follow these steps. 60 | 61 | ### Prerequisites 62 | 63 | In order to run this project you need: 64 | 65 | - Mac or PC 66 | - Code Editor (Vs Code) 67 | - Terminal 68 | - Install [ruby 3.2.2](https://www.ruby-lang.org/en/documentation/installation/) on your computer 69 | - Install [rails](https://www.tutorialspoint.com/ruby-on-rails/rails-installation.htm#) on your computer 70 | - Install [postgreSQL](https://www.postgresql.org/download/) on your computer 71 | 72 | ### Setup 73 | 74 | Clone this repository to your desired folder: 75 | 76 | ```sh 77 | cd your-folder 78 | https://github.com/Lucash2022/Blog_App.git 79 | ``` 80 | 81 | ### Install 82 | 83 | Install this project with: 84 | 85 | - GitHub Actions 86 | - Linters 87 | - Rubocop 88 | - Ruby On Rails 89 | 90 | ### Usage 91 | 92 | - Run `bundle install` in the terminal from the root folder of the project. 93 | - Run `rails db:create` in the terminal from the root folder of the project. 94 | - Run `rails db:migrate` in the terminal from the root folder of the project. 95 | - Run the app with `rails c` in the terminal from the root folder of the project. 96 | - Create a new user 97 | ```sh 98 | User.create(name: 'Lucas', bio: 'Full stack developer from Namibia', photo: 'https://ca.slack-edge.com/T47CT8XPG-U03PBVD9PAS-26c072588661-512', posts_counter: 0) 99 | ``` 100 | - Run the server with `rails s` in the terminal from the root folder of the project. 101 | 102 | 103 | ### Test 104 | 105 | ```sh 106 | rspec 107 | ``` 108 | 109 |

(back to top)

110 | 111 | 112 | 113 | ## 👥 Authors 114 | 115 | 👤 **Lucas Erkana** 116 | 117 | - GitHub: [@Lucash2022](https://github.com/Lucash2022) 118 | - Twitter: [@Lucas_David_22](https://twitter.com/@Lucas_David_22) 119 | - LinkedIn: [Lucas Erkana](https://www.linkedin.com/in/lucas-erkana/) 120 | - Frontend Mentor - [@Lucash2022](https://www.frontendmentor.io/profile/Lucash2022) 121 | 122 | 👤 **Saba Ahmad** 123 | 124 | - GitHub: [@SabaAhmad404](https://github.com/SabaAhmad404) 125 | - LinkedIn: [Saba Ahmad](https://www.linkedin.com/in/saba-ahmad-97b938244/) 126 | 127 |

(back to top)

128 | 129 | 130 | 131 | ## 🔭 Future Features 132 | 133 | - [ ] **Create Users** 134 | 135 |

(back to top)

136 | 137 | 138 | 139 | ## 🤝 Contributing 140 | 141 | Contributions, issues, and feature requests are welcome! 142 | 143 | Feel free to check the [issues page](https://github.com/lucash2022/Blog-app/issues). 144 | 145 |

(back to top)

146 | 147 | 148 | 149 | ## ⭐️ Show your support 150 | 151 | If you like this project, please leave a ⭐️ 152 | 153 |

(back to top)

154 | 155 | 156 | 157 | ## 🙏 Acknowledgments 158 | 159 | I would like to thank Microverse for providing the reading materials that aided me during the project development 160 | 161 |

(back to top)

162 | 163 | 164 | 165 | ## ❓ FAQ 166 | 167 | - **Can I use this code?** 168 | 169 | - yes, it is open source. Feel free to fork it. 170 | 171 | - **Can I contribute to this project?** 172 | 173 | - Contact me so I can add you as a collaborator. Alternatively you can leave an issue, it will be well appreciated. 174 | 175 |

(back to top)

176 | 177 | 178 | 179 | ## 📝 License 180 | 181 | This project is [MIT](./LICENSE) licensed. 182 | 183 |

(back to top)

184 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | # Add your own tasks in files placed in lib/tasks ending in .rake, 2 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. 3 | 4 | require_relative "config/application" 5 | 6 | Rails.application.load_tasks 7 | -------------------------------------------------------------------------------- /app/assets/config/manifest.js: -------------------------------------------------------------------------------- 1 | //= link_tree ../images 2 | //= link_directory ../stylesheets .css 3 | //= link_tree ../../javascript .js 4 | //= link_tree ../../../vendor/javascript .js 5 | -------------------------------------------------------------------------------- /app/assets/images/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lucas-Erkana/Blog_App/bb775c1c27eceb7b8a7dc2aba773a74dc3c49efe/app/assets/images/.keep -------------------------------------------------------------------------------- /app/assets/stylesheets/application.css.scss: -------------------------------------------------------------------------------- 1 | * { 2 | background-color: azure; 3 | box-sizing: border-box; 4 | font-family: sans-serif; 5 | margin: 0; 6 | padding: 0; 7 | overflow-x: hidden; 8 | transition: all 0.2s linear; 9 | } 10 | 11 | @import "font-awesome"; 12 | 13 | body { 14 | display: flex; 15 | } 16 | 17 | h1 { 18 | font-size: 30px; 19 | line-height: 2rem; 20 | text-align: center; 21 | margin: 30px auto; 22 | font-weight: bolder; 23 | text-decoration: underline; 24 | } 25 | 26 | a { 27 | text-decoration: none; 28 | color: black; 29 | } 30 | 31 | img[alt] { 32 | font-weight: normal; 33 | font-size: 13px; 34 | } 35 | 36 | main { 37 | width: 90%; 38 | min-height: 90vh; 39 | margin: auto; 40 | margin-bottom: 30px; 41 | margin-top: 20px; 42 | } 43 | 44 | .users-list { 45 | display: flex; 46 | flex-direction: column; 47 | gap: 15px; 48 | } 49 | 50 | .user-container { 51 | display: flex; 52 | gap: 15px; 53 | } 54 | 55 | .user-container, 56 | .post-container { 57 | border-bottom: 1px solid gray; 58 | padding-bottom: 20px; 59 | } 60 | 61 | .user-profile-pic { 62 | width: 100px; 63 | height: 100px; 64 | overflow: hidden; 65 | } 66 | 67 | .user-profile-pic img { 68 | width: 100%; 69 | height: 100%; 70 | } 71 | 72 | .user-info { 73 | width: 80%; 74 | display: flex; 75 | flex-direction: column; 76 | justify-content: space-between; 77 | padding: 15px 0; 78 | } 79 | 80 | .posts-counter, 81 | .coment-likes-data { 82 | font-size: 15px; 83 | font-weight: normal; 84 | display: flex; 85 | justify-content: end; 86 | color: gray; 87 | } 88 | 89 | .btn-container a { 90 | display: inline-block; 91 | color: #1f628d; 92 | padding: 3px; 93 | margin: 20px 0; 94 | font-size: 22px; 95 | text-decoration: underline; 96 | } 97 | 98 | article.user-bio { 99 | border: 1px dotted gray; 100 | margin: 20px 0 40px; 101 | padding: 12px 10px; 102 | text-align: left; 103 | line-height: 1.3; 104 | } 105 | 106 | .user-bio h3 { 107 | font-size: 18px; 108 | margin-bottom: 20px; 109 | } 110 | 111 | .user-bio .bio { 112 | font-size: 19px; 113 | } 114 | 115 | .post-container { 116 | margin-bottom: 20px; 117 | } 118 | 119 | .post-title { 120 | font-size: 20px; 121 | margin-bottom: 20px; 122 | } 123 | 124 | .post-details .details { 125 | font-size: 18px; 126 | margin-bottom: 5px; 127 | } 128 | 129 | .btn-container.see-posts { 130 | display: flex; 131 | justify-content: center; 132 | } 133 | 134 | .user-container.posts { 135 | margin-bottom: 20px; 136 | } 137 | 138 | h2.title { 139 | font-size: 30px; 140 | } 141 | 142 | .user-name { 143 | font-size: 19px; 144 | margin-bottom: 10px; 145 | color: #1f628d; 146 | font-style: italic; 147 | } 148 | 149 | .post-body { 150 | margin-top: 20px; 151 | } 152 | 153 | .post-body p { 154 | line-height: 1.5; 155 | font-size: 20px; 156 | } 157 | 158 | .comments-container, 159 | .post-comments-container { 160 | display: flex; 161 | flex-direction: column; 162 | gap: 5px; 163 | border: 1px dashed rgba(0, 0, 0, 0.3); 164 | margin-top: 15px; 165 | padding: 8px 0; 166 | } 167 | 168 | .posts-container { 169 | display: flex; 170 | flex-direction: column; 171 | gap: 45px; 172 | } 173 | 174 | .coment-likes-data.container { 175 | border-bottom: 1px solid gray; 176 | padding-bottom: 8px; 177 | } 178 | 179 | .post-comments-container li, 180 | .comments-container li { 181 | font-size: 18px; 182 | line-height: 1.5; 183 | padding: 0 15px; 184 | } 185 | 186 | .post-comments-container li:nth-child(even) p { 187 | border-top: 1px dotted rgba(0, 0, 0, 0.1); 188 | } 189 | 190 | /* like and comment styles */ 191 | 192 | .interaction { 193 | display: flex; 194 | justify-content: space-between; 195 | } 196 | 197 | textarea#comment_text, 198 | textarea#post_text { 199 | display: block; 200 | width: 100%; 201 | height: 200px; 202 | padding: 10px 5px; 203 | resize: none; 204 | overflow: hidden; 205 | outline: none; 206 | -webkit-box-shadow: none; 207 | -moz-box-shadow: none; 208 | background-color: rgba(0, 0, 0, 0.1); 209 | border-radius: 15px; 210 | } 211 | 212 | .actions { 213 | text-align: center; 214 | } 215 | 216 | input[type="submit"]:not([value="delete post"]) { 217 | background: #3498db; 218 | background-image: -webkit-linear-gradient(top, #db3434, #ab1212); 219 | background-image: -o-linear-gradient(top, #db3434, #b92929); 220 | background-image: linear-gradient(to bottom, #db3455, #b92929); 221 | border-radius: 9px; 222 | -webkit-box-shadow: 0 1px 3px #666; 223 | -moz-box-shadow: 0 1px 3px #666; 224 | box-shadow: 0 1px 3px #666; 225 | font-family: Courier, sans-serif; 226 | font-weight: bolder; 227 | color: #fff; 228 | font-size: 20px; 229 | padding: 10px 20px 10px 20px; 230 | border: solid #1f628d 4px; 231 | text-decoration: none; 232 | cursor: pointer; 233 | margin-top: 20px; 234 | } 235 | 236 | #dell-post-btn { 237 | border: none; 238 | display: flex; 239 | justify-content: flex-end; 240 | } 241 | 242 | #dell-post-btn input { 243 | border: none; 244 | color: red; 245 | font-weight: normal; 246 | cursor: pointer; 247 | font-style: italic; 248 | transition: all 0.2s ease-in; 249 | font-size: 15px; 250 | } 251 | 252 | #dell-post-btn input:hover { 253 | text-decoration: underline; 254 | letter-spacing: 1px; 255 | } 256 | 257 | input[type="submit"]:not([value="delete post"]):hover { 258 | background: #5c3cfd; 259 | text-decoration: none; 260 | } 261 | 262 | .post-inputs { 263 | display: flex; 264 | flex-direction: column; 265 | } 266 | 267 | label:not([for^="user_remember_me"]) { 268 | display: none; 269 | } 270 | 271 | label[for="user_remember_me"] { 272 | font-size: 18px; 273 | } 274 | 275 | em.info { 276 | font-size: 15px; 277 | } 278 | 279 | input[type="text"], 280 | input[type="email"], 281 | input[type="password"] { 282 | padding: 8px 5px 12px; 283 | resize: none; 284 | overflow: hidden; 285 | outline: none; 286 | border: none; 287 | border-bottom: 2px solid #666; 288 | width: 100%; 289 | } 290 | 291 | input[type="checkbox"] { 292 | background-color: #3498db; 293 | cursor: pointer; 294 | } 295 | 296 | input[type="text"]:focus, 297 | input[type="email"]:focus, 298 | input[type="password"]:focus { 299 | border-bottom: 3px solid #3498db; 300 | } 301 | 302 | .notice, 303 | .alert { 304 | font-size: 16px; 305 | font-weight: normal; 306 | color: #3498db; 307 | } 308 | 309 | form, 310 | #form-page form, 311 | #post-form-page { 312 | display: flex; 313 | flex-direction: column; 314 | justify-content: center; 315 | gap: 20px; 316 | } 317 | 318 | #form-page { 319 | max-width: 400px; 320 | } 321 | 322 | #post-form-page { 323 | max-width: 600px; 324 | } 325 | 326 | h2.form-title { 327 | text-align: center; 328 | margin: 10px 0 20px; 329 | } 330 | 331 | .shared-links a { 332 | display: block; 333 | color: #666; 334 | text-decoration: underline; 335 | font-weight: normal; 336 | } 337 | 338 | .shared-links { 339 | display: flex; 340 | width: 100%; 341 | flex-direction: row-reverse; 342 | justify-content: center; 343 | margin-top: 50px; 344 | gap: 12px; 345 | } 346 | 347 | .signout-container a { 348 | color: #1f628d; 349 | text-decoration: none; 350 | font-size: 20px; 351 | } 352 | 353 | .shared-links a:hover { 354 | color: #3498db; 355 | letter-spacing: 2px; 356 | text-decoration: underline; 357 | } 358 | 359 | /* sign out button */ 360 | .signout-container { 361 | text-align: center; 362 | margin-top: 20px; 363 | border-color: gray; 364 | border-style: solid; 365 | border-width: 2px 2px 2px 2px; 366 | margin-left: 92%; 367 | border-radius: 25px; 368 | } 369 | 370 | .signout-container a:hover { 371 | text-decoration: underline; 372 | background-color: #435059; 373 | color: whitesmoke; 374 | } 375 | 376 | /* sign out button ends */ 377 | .current-user { 378 | color: green; /* Replace with your desired color */ 379 | } 380 | 381 | #log-in-page a { 382 | color: rgb(10, 21, 81); 383 | font-size: 16px; 384 | text-decoration: none; 385 | display: block; 386 | flex: 1; 387 | letter-spacing: normal; 388 | } 389 | 390 | #log-in-page a:hover { 391 | text-decoration: underline; 392 | background-color: #435059; 393 | color: whitesmoke; 394 | } 395 | 396 | .shared-links.sign-up { 397 | display: block; 398 | } 399 | 400 | section.flex { 401 | display: flex; 402 | justify-content: space-between; 403 | height: 4rem; 404 | overflow: hidden; 405 | } 406 | 407 | section.flex div:nth-child(odd) { 408 | position: relative; 409 | top: 10px; 410 | } 411 | 412 | li.comment-box { 413 | gap: 30px; 414 | align-items: center; 415 | } 416 | 417 | li.comment-box form button { 418 | border: none; 419 | } 420 | 421 | li.comment-box form .del-post-btn #delete { 422 | border: none; 423 | background: none; 424 | background-image: inherit; 425 | background-color: inherit; 426 | color: rgb(250, 158, 158); 427 | font-weight: normal; 428 | letter-spacing: 2px; 429 | padding: 0; 430 | margin: 0; 431 | font-size: 12px; 432 | outline: none; 433 | border-radius: 0; 434 | -webkit-box-shadow: none; 435 | -moz-box-shadow: none; 436 | box-shadow: none; 437 | position: relative; 438 | left: 3.5rem; 439 | bottom: 5px; 440 | } 441 | 442 | li.comment-box form .del-post-btn #delete:hover { 443 | color: red; 444 | font-weight: bolder; 445 | } 446 | 447 | /* like and comment styles end */ 448 | 449 | .form-size { 450 | width: 100%; 451 | max-width: 600px; /* Adjust the width as needed */ 452 | } 453 | 454 | @media (min-width: 765px) { 455 | main { 456 | width: 70%; 457 | margin: auto; 458 | margin-bottom: 30px; 459 | margin-top: 30px; 460 | display: flex; 461 | justify-content: center; 462 | align-items: center; 463 | flex-direction: column; 464 | } 465 | 466 | main div.page { 467 | width: 100%; 468 | } 469 | 470 | h3 a:hover { 471 | text-decoration: underline; 472 | } 473 | 474 | article.user-bio { 475 | max-width: 80%; 476 | } 477 | 478 | #log-in-page { 479 | width: 410px; 480 | } 481 | 482 | input[type="text"], 483 | input[type="email"], 484 | input[type="password"] { 485 | padding: 8px 10px 12px; 486 | resize: none; 487 | overflow: hidden; 488 | outline: none; 489 | border: none; 490 | border-bottom: 2px solid #666; 491 | width: 100%; 492 | } 493 | 494 | li.comment-box { 495 | display: flex; 496 | } 497 | 498 | li.comment-box form .del-post-btn #delete { 499 | position: relative; 500 | left: 0; 501 | bottom: 0; 502 | } 503 | 504 | .post-body p { 505 | line-height: 1.5; 506 | } 507 | } 508 | -------------------------------------------------------------------------------- /app/channels/application_cable/channel.rb: -------------------------------------------------------------------------------- 1 | module ApplicationCable 2 | class Channel < ActionCable::Channel::Base 3 | end 4 | end 5 | -------------------------------------------------------------------------------- /app/channels/application_cable/connection.rb: -------------------------------------------------------------------------------- 1 | module ApplicationCable 2 | class Connection < ActionCable::Connection::Base 3 | end 4 | end 5 | -------------------------------------------------------------------------------- /app/controllers/api/api_controller.rb: -------------------------------------------------------------------------------- 1 | class Api::ApiController < ApplicationController 2 | end 3 | -------------------------------------------------------------------------------- /app/controllers/api/comments_controller.rb: -------------------------------------------------------------------------------- 1 | module Api 2 | class Api::CommentsController < ApiController 3 | def index 4 | @user = User.find(params[:user_id]) 5 | @post = Post.find(params[:post_id]) 6 | @comments = Comment.where(post: @post) 7 | 8 | render json: @comments 9 | end 10 | 11 | def create 12 | @comment = Comment.new(comment_params) 13 | 14 | if @comment.save 15 | render json: @comment, status: :created 16 | else 17 | render json: @comment.errors, status: :unprocessable_entity 18 | end 19 | render json: :head 20 | end 21 | 22 | private 23 | 24 | def comment_params 25 | params.require(:comment).permit(:author_id, :post_id, :text) 26 | end 27 | end 28 | end 29 | -------------------------------------------------------------------------------- /app/controllers/api/posts_controller.rb: -------------------------------------------------------------------------------- 1 | module Api 2 | class Api::PostsController < ApiController 3 | def index 4 | @user = User.find(params[:user_id]) 5 | @posts = Post.where(user_id: @user.id).includes(:comments) 6 | render json: @posts 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /app/controllers/application_controller.rb: -------------------------------------------------------------------------------- 1 | class ApplicationController < ActionController::Base 2 | protect_from_forgery with: :exception 3 | 4 | before_action :update_allowed_parameters, if: :devise_controller? 5 | 6 | protected 7 | 8 | def update_allowed_parameters 9 | devise_parameter_sanitizer.permit(:sign_up) do |user_params| 10 | user_params.permit(:name, :email, :password, :password_confirmation, :bio, :photo) 11 | end 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /app/controllers/comments_controller.rb: -------------------------------------------------------------------------------- 1 | class CommentsController < ApplicationController 2 | load_and_authorize_resource 3 | 4 | def index 5 | @user = User.includes(:posts).find(params[:user_id]) 6 | @post = @user.posts 7 | @comments = Comment.where(posts: @post) 8 | 9 | respond_to do |format| 10 | format.html 11 | format.json { render json: @comments } 12 | end 13 | end 14 | 15 | def new 16 | @comment = Comment.new 17 | end 18 | 19 | def create 20 | @comment = Comment.new(text: comment_params[:text], post_id: params[:post_id], user_id: current_user[:id]) 21 | 22 | if @comment.save 23 | redirect_to user_post_path(user_id: params[:user_id], id: params[:post_id]), 24 | notice: 'Comment added successfully' 25 | else 26 | render :new, status: :unprocessable_entity 27 | end 28 | end 29 | 30 | def destroy 31 | @comment = Comment.find(params[:id]) 32 | @comment.destroy 33 | redirect_to user_post_path(user_id: params[:user_id], id: params[:post_id]), 34 | notice: 'Comment deleted successfully' 35 | end 36 | 37 | private 38 | 39 | def comment_params 40 | params.require(:comment).permit(:text) 41 | end 42 | end 43 | -------------------------------------------------------------------------------- /app/controllers/concerns/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lucas-Erkana/Blog_App/bb775c1c27eceb7b8a7dc2aba773a74dc3c49efe/app/controllers/concerns/.keep -------------------------------------------------------------------------------- /app/controllers/likes_controller.rb: -------------------------------------------------------------------------------- 1 | class LikesController < ApplicationController 2 | def create 3 | @user = User.find(params[:user_id]) 4 | @post = Post.find(params[:post_id]) 5 | 6 | if @user.user_has_liked?(@post, @user) 7 | @user.remove_user_like(@post, @user) 8 | puts 'Unlike' 9 | else 10 | @user.add_user_like(@post, @user) 11 | puts 'Like' 12 | end 13 | redirect_to request.path 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /app/controllers/posts_controller.rb: -------------------------------------------------------------------------------- 1 | class PostsController < ApplicationController 2 | load_and_authorize_resource 3 | 4 | def index 5 | @user = User.find(params[:user_id]) 6 | @posts = @user.posts 7 | 8 | respond_to do |format| 9 | format.html 10 | format.json { render json: @posts } 11 | end 12 | end 13 | 14 | def new 15 | @current_user = current_user 16 | @post = Post.new 17 | end 18 | 19 | def create 20 | @post = Post.new(title: post_params[:title], text: post_params[:text], user_id: current_user[:id], 21 | comment_counter: 0, likes_counter: 0) 22 | 23 | if @post.save 24 | redirect_to user_post_path(current_user, @post), notice: 'Post created successfully.' 25 | else 26 | render :new, status: :unprocessable_entity 27 | end 28 | end 29 | 30 | def show 31 | @post = Post.find(params[:id]) 32 | @user = User.find(params[:user_id]) 33 | @comments = Comment.where(post_id: params[:id]) 34 | end 35 | 36 | def destroy 37 | @post = current_user.posts.find(params[:id]) 38 | @post.destroy 39 | redirect_to user_posts_path(current_user, @post), notice: 'Post was successfully destroyed.' 40 | end 41 | 42 | def include_user 43 | @user = User.includes(:posts, posts: [:comments, { comments: [:author] }]).find(params[:user_id]) 44 | end 45 | 46 | private 47 | 48 | def set_post 49 | @post = Post.find(params[:id]) 50 | end 51 | 52 | def post_params 53 | params.require(:post).permit(:title, :text) 54 | end 55 | end 56 | -------------------------------------------------------------------------------- /app/controllers/users_controller.rb: -------------------------------------------------------------------------------- 1 | class UsersController < ApplicationController 2 | before_action :authenticate_user! 3 | def show 4 | @user = User.includes(:posts).find(params[:id]) 5 | @posts = @user.recent_post 6 | @post_counter = @user.posts.length 7 | end 8 | 9 | def index 10 | @users = User.all 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /app/helpers/api/api_helper.rb: -------------------------------------------------------------------------------- 1 | module Api::ApiHelper 2 | end 3 | -------------------------------------------------------------------------------- /app/helpers/api/comments_helper.rb: -------------------------------------------------------------------------------- 1 | module Api::CommentsHelper 2 | end 3 | -------------------------------------------------------------------------------- /app/helpers/api/posts_helper.rb: -------------------------------------------------------------------------------- 1 | module Api::PostsHelper 2 | end 3 | -------------------------------------------------------------------------------- /app/helpers/application_helper.rb: -------------------------------------------------------------------------------- 1 | module ApplicationHelper 2 | end 3 | -------------------------------------------------------------------------------- /app/helpers/comments_helper.rb: -------------------------------------------------------------------------------- 1 | module CommentsHelper 2 | end 3 | -------------------------------------------------------------------------------- /app/helpers/likes_helper.rb: -------------------------------------------------------------------------------- 1 | module LikesHelper 2 | end 3 | -------------------------------------------------------------------------------- /app/helpers/posts_helper.rb: -------------------------------------------------------------------------------- 1 | module PostsHelper 2 | def render_comment_delete_button(user, post, comment) 3 | button_to user_post_comment_path(user, post, comment), 4 | method: :delete, 5 | data: { confirm: 'Are you sure?' }, 6 | class: 'del-post-btn' do 7 | submit_tag '|Delete', title: 'delete comment', id: 'delete' 8 | end 9 | end 10 | 11 | def render_few_comment(post, user) 12 | content_tag(:ul, class: 'post-comments-container') do 13 | if post.recent_comments.any? 14 | post.recent_comments.each do |comment| 15 | concat(content_tag(:li, class: 'comment-box') do 16 | concat(content_tag(:p) do 17 | user_name = comment.user.name 18 | user_comment = truncate(comment.text, length: 60, omission: '...') 19 | comment_content = "#{user_name}: #{user_comment}".html_safe 20 | concat(comment_content) 21 | concat(render_comment_delete_button(user, post, comment)) if can? :destroy, comment 22 | end) 23 | end) 24 | end 25 | else 26 | content_tag(:li, 'No comments added yet') 27 | end 28 | end 29 | end 30 | 31 | def render_posts(user, post) 32 | link_to(user_post_path(user, post)) do 33 | content_tag(:div, class: 'post-containe') do 34 | concat(content_tag(:h3, post.title, class: 'post-title')) 35 | concat(content_tag(:div, class: 'post-details') do 36 | content_tag(:p, truncate(post.text, length: 100, omission: '...'), class: 'details') 37 | end) 38 | concat(content_tag(:div, class: 'comment-like-container') do 39 | content_tag(:p, class: 'coment-likes-data container') do 40 | comment = post.comment_counter || 0 41 | likes = post.likes_counter || 0 42 | "Comments: #{comment}, Likes: #{likes}" 43 | end 44 | end) 45 | concat(render_few_comment(post, user)) 46 | end 47 | end 48 | end 49 | 50 | def render_all_comment(user, post, comments) 51 | if comments.any? 52 | safe_join(comments.map do |comment| 53 | content_tag(:li, class: 'comment-box') do 54 | content_tag(:p) do 55 | user_name = User.find_by(id: comment.user_id)&.name 56 | user_comment = comment.text 57 | comment_content = "#{user_name}: #{user_comment}".html_safe 58 | concat(comment_content) 59 | concat(render_comment_delete_button(user, post, comment)) if can? :destroy, comment 60 | end 61 | end 62 | end) 63 | else 64 | content_tag(:li, 'No comments added yet..') 65 | end 66 | end 67 | end 68 | -------------------------------------------------------------------------------- /app/helpers/users_helper.rb: -------------------------------------------------------------------------------- 1 | module UsersHelper 2 | def render_user(user) 3 | content_tag(:li, class: 'user-container') do 4 | concat(content_tag(:div, class: 'user-profile-pic') do 5 | link_to(user_path(user)) do 6 | image_tag(user.photo || '', alt: 'profile-picture') 7 | end 8 | end) 9 | concat(content_tag(:div, class: 'user-info') do 10 | concat(content_tag(:h3) do 11 | link_to(user.name, user_path(user)) 12 | end) 13 | concat(content_tag(:p, class: 'posts-counter') do 14 | "Number of posts: #{user.posts_counter || 0}" 15 | end) 16 | end) 17 | end 18 | end 19 | 20 | def render_post(user, post) 21 | link_to(user_post_path(user, post)) do 22 | content_tag(:div, class: 'post-container') do 23 | concat(content_tag(:h3, post.title, class: 'post-title')) 24 | concat(content_tag(:div, class: 'post-details') do 25 | content_tag(:p, truncate(post.text, length: 100, omission: '...'), class: 'details') 26 | end) 27 | concat(content_tag(:div, class: 'comment-like-container') do 28 | content_tag(:p, class: 'coment-likes-data') do 29 | "Comments: #{post.comment_counter || 0}, Likes #{post.likes_counter || 0}" 30 | end 31 | end) 32 | end 33 | end 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /app/javascript/application.js: -------------------------------------------------------------------------------- 1 | // Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails 2 | import "@hotwired/turbo-rails" 3 | import "controllers" 4 | -------------------------------------------------------------------------------- /app/javascript/controllers/application.js: -------------------------------------------------------------------------------- 1 | import { Application } from "@hotwired/stimulus" 2 | 3 | const application = Application.start() 4 | 5 | // Configure Stimulus development experience 6 | application.debug = false 7 | window.Stimulus = application 8 | 9 | export { application } 10 | -------------------------------------------------------------------------------- /app/javascript/controllers/hello_controller.js: -------------------------------------------------------------------------------- 1 | import { Controller } from "@hotwired/stimulus" 2 | 3 | export default class extends Controller { 4 | connect() { 5 | this.element.textContent = "Hello World!" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /app/javascript/controllers/index.js: -------------------------------------------------------------------------------- 1 | // Import and register all your controllers from the importmap under controllers/* 2 | 3 | import { application } from "controllers/application" 4 | 5 | // Eager load all controllers defined in the import map under controllers/**/*_controller 6 | import { eagerLoadControllersFrom } from "@hotwired/stimulus-loading" 7 | eagerLoadControllersFrom("controllers", application) 8 | 9 | // Lazy load controllers as they appear in the DOM (remember not to preload controllers in import map!) 10 | // import { lazyLoadControllersFrom } from "@hotwired/stimulus-loading" 11 | // lazyLoadControllersFrom("controllers", application) 12 | -------------------------------------------------------------------------------- /app/jobs/application_job.rb: -------------------------------------------------------------------------------- 1 | class ApplicationJob < ActiveJob::Base 2 | # Automatically retry jobs that encountered a deadlock 3 | # retry_on ActiveRecord::Deadlocked 4 | 5 | # Most jobs are safe to ignore if the underlying records are no longer available 6 | # discard_on ActiveJob::DeserializationError 7 | end 8 | -------------------------------------------------------------------------------- /app/mailers/application_mailer.rb: -------------------------------------------------------------------------------- 1 | class ApplicationMailer < ActionMailer::Base 2 | default from: 'from@example.com' 3 | layout 'mailer' 4 | end 5 | -------------------------------------------------------------------------------- /app/models/ability.rb: -------------------------------------------------------------------------------- 1 | class Ability 2 | include CanCan::Ability 3 | 4 | def initialize(user) 5 | user ||= User.new # guest user (not logged in) 6 | 7 | # Define abilities for the different user roles 8 | can :manage, :all if user.role == 'admin' 9 | 10 | can :destroy, Post, user_id: user.id 11 | can :destroy, Comment, user_id: user.id 12 | 13 | can :create, Post 14 | can :create, Comment 15 | 16 | can :read, Post 17 | can :read, Comment 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /app/models/application_record.rb: -------------------------------------------------------------------------------- 1 | class ApplicationRecord < ActiveRecord::Base 2 | primary_abstract_class 3 | end 4 | -------------------------------------------------------------------------------- /app/models/comment.rb: -------------------------------------------------------------------------------- 1 | class Comment < ApplicationRecord 2 | belongs_to :user, foreign_key: 'user_id' 3 | belongs_to :post 4 | validates_presence_of :text 5 | after_create :update_comment_counter 6 | after_destroy :update_comment_counter 7 | 8 | def update_comment_counter 9 | post.update(comment_counter: post.comments.count) 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /app/models/concerns/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lucas-Erkana/Blog_App/bb775c1c27eceb7b8a7dc2aba773a74dc3c49efe/app/models/concerns/.keep -------------------------------------------------------------------------------- /app/models/like.rb: -------------------------------------------------------------------------------- 1 | class Like < ApplicationRecord 2 | belongs_to :user, foreign_key: 'user_id' 3 | belongs_to :post 4 | after_create :update_like_counter 5 | 6 | private 7 | 8 | def update_like_counter 9 | post.update(likes_counter: post.likes.count) 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /app/models/post.rb: -------------------------------------------------------------------------------- 1 | class Post < ApplicationRecord 2 | belongs_to :user, foreign_key: 'user_id' 3 | has_many :comments, dependent: :destroy 4 | has_many :likes, dependent: :destroy 5 | 6 | validates :title, presence: true, length: { minimum: 3, maximum: 250 } 7 | validates :comment_counter, numericality: { greater_than_or_equal_to: 0, only_integer: true } 8 | validates :likes_counter, numericality: { greater_than_or_equal_to: 0, only_integer: true } 9 | validates :text, presence: true, length: { minimum: 3, maximum: 250 } 10 | after_create :post_count_updater 11 | after_destroy :post_count_updater 12 | 13 | def post_count_updater 14 | user.update(posts_counter: user.posts.count) 15 | end 16 | 17 | def recent_comments 18 | comments.includes(:user).order(created_at: :desc).limit(5) 19 | end 20 | end 21 | -------------------------------------------------------------------------------- /app/models/user.rb: -------------------------------------------------------------------------------- 1 | class User < ApplicationRecord 2 | # Include default devise modules. Others available are: 3 | # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable 4 | devise :database_authenticatable, :registerable, 5 | :recoverable, :rememberable, :validatable, :confirmable 6 | 7 | has_many :comments 8 | has_many :posts 9 | has_many :likes 10 | 11 | validates :name, presence: true 12 | 13 | # has_one_attached :photo # Add this line to handle the photo attachment 14 | 15 | def recent_post 16 | posts.order(created_at: :desc).limit(3) 17 | end 18 | 19 | def user_has_liked?(post, user) 20 | likes.exists?(post:, user:) 21 | end 22 | 23 | def remove_user_like(post, user) 24 | likes.find_by(post:, user:).destroy 25 | end 26 | 27 | def add_user_like(post, user) 28 | likes.create(post:, user:) 29 | end 30 | end 31 | -------------------------------------------------------------------------------- /app/views/comments/new.html.erb: -------------------------------------------------------------------------------- 1 |
2 |
3 |

Add a comment

4 | <%= form_with(model: @comment, url: user_post_comments_path, method: :post) do |f| %> 5 | <%= f.label :text %> 6 | <%= f.text_area :text, autofocus: true, resize: "none", required: true, placeholder: "Enter comment" %> 7 | <%= f.submit "Add" %> 8 | <% end %> 9 |
10 |
11 | -------------------------------------------------------------------------------- /app/views/devise/confirmations/new.html.erb: -------------------------------------------------------------------------------- 1 |
2 |

Resend confirmation instructions

3 | 4 | <%= form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { method: :post }) do |f| %> 5 | <%= render "devise/shared/error_messages", resource: resource %> 6 | 7 |
8 | <%= f.label :email %>
9 | <%= f.email_field :email, placeholder: "Enter email address", autofocus: true, autocomplete: "email", value: (resource.pending_reconfirmation? ? resource.unconfirmed_email : resource.email) %> 10 |
11 | 12 |
13 | <%= f.submit "Resend confirmation instructions" %> 14 |
15 | <% end %> 16 | 17 | <%= render "devise/shared/links" %> 18 |
19 | -------------------------------------------------------------------------------- /app/views/devise/mailer/confirmation_instructions.html.erb: -------------------------------------------------------------------------------- 1 |

Welcome <%= @email %>!

2 | 3 |

You can confirm your account email through the link below:

4 | 5 |

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

6 | -------------------------------------------------------------------------------- /app/views/devise/mailer/email_changed.html.erb: -------------------------------------------------------------------------------- 1 |

Hello <%= @email %>!

2 | 3 | <% if @resource.try(:unconfirmed_email?) %> 4 |

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

5 | <% else %> 6 |

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

7 | <% end %> 8 | -------------------------------------------------------------------------------- /app/views/devise/mailer/password_change.html.erb: -------------------------------------------------------------------------------- 1 |

Hello <%= @resource.email %>!

2 | 3 |

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

4 | -------------------------------------------------------------------------------- /app/views/devise/mailer/reset_password_instructions.html.erb: -------------------------------------------------------------------------------- 1 |

Hello <%= @resource.email %>!

2 | 3 |

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

4 | 5 |

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

6 | 7 |

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

8 |

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

9 | -------------------------------------------------------------------------------- /app/views/devise/mailer/unlock_instructions.html.erb: -------------------------------------------------------------------------------- 1 |

Hello <%= @resource.email %>!

2 | 3 |

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

4 | 5 |

Click the link below to unlock your account:

6 | 7 |

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

8 | -------------------------------------------------------------------------------- /app/views/devise/passwords/edit.html.erb: -------------------------------------------------------------------------------- 1 |
2 |

Change your password

3 | 4 | <%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :put }) do |f| %> 5 | <%= render "devise/shared/error_messages", resource: resource %> 6 | <%= f.hidden_field :reset_password_token %> 7 | 8 |
9 | <%= f.label :password, "New password" %>
10 | <% if @minimum_password_length %> 11 | (<%= @minimum_password_length %> characters minimum)
12 | <% end %> 13 | <%= f.password_field :password, autofocus: true, autocomplete: "new-password", placeholder: "Password" %> 14 |
15 | 16 |
17 | <%= f.label :password_confirmation, "Confirm new password" %>
18 | <%= f.password_field :password_confirmation, autocomplete: "new-password", placeholder: "Confirm password" %> 19 |
20 | 21 |
22 | <%= f.submit "Change my password" %> 23 |
24 | <% end %> 25 | 26 | 27 | 28 |
-------------------------------------------------------------------------------- /app/views/devise/passwords/new.html.erb: -------------------------------------------------------------------------------- 1 |
2 |

Forgot your password?

3 | 4 | <%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| %> 5 | <%= render "devise/shared/error_messages", resource: resource %> 6 | 7 |
8 | <%= f.label :email %>
9 | <%= f.email_field :email, autofocus: true, autocomplete: "email", placeholder: "Enter email address" %> 10 |
11 | 12 |
13 | <%= f.submit "Send me reset password instructions" %> 14 |
15 | <% end %> 16 | 17 | 18 | 19 |
-------------------------------------------------------------------------------- /app/views/devise/registrations/edit.html.erb: -------------------------------------------------------------------------------- 1 |
2 |

Edit <%= resource_name.to_s.humanize %>

3 | 4 | <%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %> 5 | <%= render "devise/shared/error_messages", resource: resource %> 6 | 7 |
8 | <%= f.label :name %>
9 | <%= f.text_field :name, autofocus: true, placeholder: "Name" %> 10 |
11 | 12 |
13 | <%= f.label :email %>
14 | <%= f.email_field :email, autocomplete: "email", placeholder: "Email Address" %> 15 |
16 | 17 | <% if devise_mapping.confirmable? && resource.pending_reconfirmation? %> 18 |
Currently waiting confirmation for: <%= resource.unconfirmed_email %>
19 | <% end %> 20 | 21 |
22 | <%= f.label :password %> (leave blank if you don't want to change it)
23 | <%= f.password_field :password, autocomplete: "new-password", placeholder: "Password" %> 24 | <% if @minimum_password_length %> 25 |
26 | <%= @minimum_password_length %> characters minimum 27 | <% end %> 28 |
29 | 30 |
31 | <%= f.label :password_confirmation %>
32 | <%= f.password_field :password_confirmation, autocomplete: "new-password", placeholder: "Confirm password" %> 33 |
34 | 35 |
36 | <%= f.label :current_password %> (we need your current password to confirm your changes)
37 | <%= f.password_field :current_password, autocomplete: "current-password", placeholder: "Current_password" %> 38 |
39 | 40 |
41 | <%= f.submit "Update" %> 42 |
43 | <% end %> 44 | 45 |

Cancel my account

46 | 47 |
Unhappy? <%= button_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?", turbo_confirm: "Are you sure?" }, method: :delete %>
48 | 49 | <%= link_to "Back", :back %> 50 | 51 |
-------------------------------------------------------------------------------- /app/views/devise/registrations/new.html.erb: -------------------------------------------------------------------------------- 1 |
2 |

Sign up

3 | 4 | <%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %> 5 | <%= render "devise/shared/error_messages", resource: resource %> 6 | 7 |
8 | <%= f.label :name %>
9 | <%= f.text_field :name, autofocus: true, placeholder: "Name", class: "long-textbox" %> 10 |
11 | 12 |
13 | <%= f.label :bio %>
14 | <%= f.text_field :bio, autofocus: true, placeholder: "Bio", class: "long-textbox" %> 15 |
16 | 17 |
18 | <%= f.label :photo %>
19 | <%= f.text_field :photo, autofocus: true, autocomplete: "photo", placeholder: "Paste image address (URL) here", class: "long-textbox" %> 20 |
21 | 22 |
23 | <%= f.label :email %>
24 | <%= f.email_field :email, autocomplete: "email", placeholder: "Email Address", class: "long-textbox" %> 25 |
26 | 27 |
28 | <%= f.label :password %> 29 | <%= f.password_field :password, autocomplete: "new-password", placeholder: "Password", class: "long-textbox" %> 30 | <% if @minimum_password_length %> 31 | (<%= @minimum_password_length %> characters minimum) 32 | <% end %>
33 |
34 | 35 |
36 | <%= f.label :password_confirmation %>
37 | <%= f.password_field :password_confirmation, autocomplete: "new-password", placeholder: "Confirm password", class: "long-textbox" %> 38 |
39 | 40 |
41 | <%= f.submit "Sign up" %> 42 |
43 | <% end %> 44 | 45 | 46 |
47 | -------------------------------------------------------------------------------- /app/views/devise/sessions/new.html.erb: -------------------------------------------------------------------------------- 1 |
2 |

Log in

3 | 4 | <%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %> 5 |
6 | <%= f.label :email %>
7 | <%= f.email_field :email, autofocus: true, autocomplete: "email", placeholder: "Email Address" %> 8 |
9 | 10 |
11 | <%= f.label :password %>
12 | <%= f.password_field :password, autocomplete: "current-password", placeholder: "Password" %> 13 |
14 | 15 | <% if devise_mapping.rememberable? %> 16 |
17 | <%= f.check_box :remember_me %> 18 | <%= f.label :remember_me %> 19 |
20 | <% end %> 21 | 22 |
23 | <%= f.submit "Log in" %> 24 |
25 | <% end %> 26 | 27 | 28 |
29 | -------------------------------------------------------------------------------- /app/views/devise/shared/_error_messages.html.erb: -------------------------------------------------------------------------------- 1 | <% if resource.errors.any? %> 2 |
3 |

4 | <%= I18n.t("errors.messages.not_saved", 5 | count: resource.errors.count, 6 | resource: resource.class.model_name.human.downcase) 7 | %> 8 |

9 | 14 |
15 | <% end %> 16 | -------------------------------------------------------------------------------- /app/views/devise/shared/_links.html.erb: -------------------------------------------------------------------------------- 1 | <%- if controller_name != 'sessions' %> 2 | <%= link_to "Log in", new_session_path(resource_name) %>
3 | <% end %> 4 | 5 | <%- if devise_mapping.registerable? && controller_name != 'registrations' %> 6 | <%= link_to "Sign up", new_registration_path(resource_name) %>
7 | <% end %> 8 | 9 | <%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %> 10 | <%= link_to "Forgot your password?", new_password_path(resource_name) %>
11 | <% end %> 12 | 13 | <%- if devise_mapping.confirmable? && controller_name != 'confirmations' %> 14 | <%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %>
15 | <% end %> 16 | 17 | <%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %> 18 | <%= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name) %>
19 | <% end %> 20 | 21 | <%- if devise_mapping.omniauthable? %> 22 | <%- resource_class.omniauth_providers.each do |provider| %> 23 | <%= button_to "Sign in with #{OmniAuth::Utils.camelize(provider)}", omniauth_authorize_path(resource_name, provider), data: { turbo: false } %>
24 | <% end %> 25 | <% end %> 26 | -------------------------------------------------------------------------------- /app/views/devise/unlocks/new.html.erb: -------------------------------------------------------------------------------- 1 |
2 |

Resend unlock instructions

3 | 4 | <%= form_for(resource, as: resource_name, url: unlock_path(resource_name), html: { method: :post }) do |f| %> 5 | <%= render "devise/shared/error_messages", resource: resource %> 6 | 7 |
8 | <%= f.label :email %>
9 | <%= f.email_field :email, autofocus: true, autocomplete: "email", placeholder: "Email Address" %> 10 |
11 | 12 |
13 | <%= f.submit "Resend unlock instructions" %> 14 |
15 | <% end %> 16 | 17 | <%= render "devise/shared/links" %> 18 |
19 | -------------------------------------------------------------------------------- /app/views/layouts/application.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | MyBlogApp 5 | 6 | <%= csrf_meta_tags %> 7 | <%= csp_meta_tag %> 8 | 9 | <%= stylesheet_link_tag "application", "data-turbo-track": "reload" %> 10 | <%= javascript_importmap_tags %> 11 | 12 | 13 | 14 |
15 |

<%= notice %>

16 |

<%= alert %>

17 | <%= yield %> 18 |
19 | 20 | 21 | -------------------------------------------------------------------------------- /app/views/layouts/mailer.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | 9 | 10 | 11 | <%= yield %> 12 | 13 | 14 | -------------------------------------------------------------------------------- /app/views/layouts/mailer.text.erb: -------------------------------------------------------------------------------- 1 | <%= yield %> 2 | -------------------------------------------------------------------------------- /app/views/likes/new.html.erb: -------------------------------------------------------------------------------- 1 | <%= form_with model: @like do |form| %> 2 | <%= form.hidden_field :post_id, value: @post.id %> 3 | 4 | <%= form.submit "Like" %> 5 | <% end %> 6 | -------------------------------------------------------------------------------- /app/views/posts/index.html.erb: -------------------------------------------------------------------------------- 1 |
2 | <%# Home button start %> 3 |
4 |
5 | <%= link_to raw(''), "../../" %> 6 |
7 |
8 | <%# End fo Home button %> 9 | <%# user profile start %> 10 |
11 | 14 | 18 |
19 | <%# End of user profile %> 20 |
21 | <% @posts.each do |post| %> 22 | <%= render_posts(@user, post) %> 23 | <% end %> 24 |
25 |
26 | 27 | 28 | -------------------------------------------------------------------------------- /app/views/posts/new.html.erb: -------------------------------------------------------------------------------- 1 |
2 |

Create New Post

3 | <%= form_with(model: @post, url: user_create_post_path, method: :post, remote: false ) do |f| %> 4 |
5 | <%= f.label :title %> 6 | <%= f.text_field :title, required: true, autofocus: true, pattern: ".{5,}", title: "Title must be at least 5 characters", placeholder: "Enter Post Title" %> 7 |
8 |
9 | <%= f.label :text %> 10 | <%= f.text_area :text, resize: "none", required: true, pattern: ".{5,}", title: "Please fill out this are", placeholder: "Enter Text" %> 11 |
12 | <%= f.submit "Create Post" %> 13 | <% end %> 14 |
15 | -------------------------------------------------------------------------------- /app/views/posts/show.html.erb: -------------------------------------------------------------------------------- 1 |
2 |
3 | <%# Home button start %> 4 |
5 | <%= link_to raw(''), "../../" %> 6 |
7 | <%# End fo Home button %> 8 |
9 | <%# user post start %> 10 |
11 |
12 |
13 |
14 |

<%= @post.title %>

15 |

by <%= @user.name %>

16 |
17 | <%# Delete post btn%> 18 |
19 | <% if can? :destroy, @post %> 20 | <%= button_to user_post_path(@user, @post), method: :delete, data: { confirm: 'Are you sure?' }, id: 'dell-post-btn' do %> 21 | <%= hidden_field_tag :id, @post.id %> 22 | <%= submit_tag 'delete post'%> 23 | <% end %> 24 | <% end %> 25 |
26 | <%# End of Delete post btn%> 27 |
28 |

29 | Comment: <%= @post.comment_counter || 0 %>, Likes: <%= @post.likes_counter || 0 %> 30 |

31 |
32 |

<%= @post.text %>

33 |
34 |
35 | <%# End of user post %> 36 |
37 | <%= form_with(model: @like, url: user_post_likes_path(@user, @post), method: :post) do |form| %> 38 |
39 | <%= form.hidden_field :post_id, value: @post.id %> 40 | <%= form.submit "Like" %> 41 |
42 | <% end %> 43 | 44 | 45 | <%# %> 46 | <%# Create comment button %> 47 |
48 | <%= link_to "Add comment", new_user_post_comment_path(@user, @post) %> 49 |
50 | <%# End of Create comment button %> 51 |
52 | 53 | <%# Comments container start %> 54 |
    55 | <%= render_all_comment(@user, @post, @post.comments) %> 56 |
57 | <%# End of Comments container %> 58 |
59 |
60 |
61 | -------------------------------------------------------------------------------- /app/views/users/index.html.erb: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 | <%= link_to raw(''), root_path %> 5 |
6 |
7 | <%= link_to "Sign out", destroy_user_session_path, method: :delete, class: "signout-link" %> 8 |
9 |

Welcome <%= current_user.name %>!

10 | 11 | 12 |
    13 | <%= @users.map { |user| render_user(user) }.join.html_safe %> 14 |
15 |
16 |
17 | -------------------------------------------------------------------------------- /app/views/users/show.html.erb: -------------------------------------------------------------------------------- 1 |
2 | <%# Home button start %> 3 |
4 |
5 | <%= link_to raw(''), "../../" %> 6 |
7 | <%# End fo Home button %> 8 | 9 | <%# display create post link if user is signed in %> 10 | <% if current_user == @user %> 11 |
12 | <%= link_to "Create post", new_user_post_path(@user) %> 13 |
14 | <% end %> 15 | 16 | <%# user info start %> 17 |
18 | 21 | 25 |
26 |
27 |

Bio

28 |
<%= @user.bio %>
29 |
30 | <%# end of user info %> 31 | <%# posts start %> 32 |
33 | <%= @posts.map { |post| render_post(@user, post) }.join.html_safe %> 34 |
35 | <%# end of post %> 36 | 37 | <% if @post_counter > 3 %> 38 |
39 | <%= link_to "See all posts", user_posts_path(@user) %> 40 |
41 | <%end%> 42 | 43 | <%# end of see all button %> 44 |
45 |
46 | -------------------------------------------------------------------------------- /bin/bundle: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | # 5 | # This file was generated by Bundler. 6 | # 7 | # The application 'bundle' is installed as part of a gem, and 8 | # this file is here to facilitate running it. 9 | # 10 | 11 | require "rubygems" 12 | 13 | m = Module.new do 14 | module_function 15 | 16 | def invoked_as_script? 17 | File.expand_path($0) == File.expand_path(__FILE__) 18 | end 19 | 20 | def env_var_version 21 | ENV["BUNDLER_VERSION"] 22 | end 23 | 24 | def cli_arg_version 25 | return unless invoked_as_script? # don't want to hijack other binstubs 26 | return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update` 27 | bundler_version = nil 28 | update_index = nil 29 | ARGV.each_with_index do |a, i| 30 | if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN 31 | bundler_version = a 32 | end 33 | next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/ 34 | bundler_version = $1 35 | update_index = i 36 | end 37 | bundler_version 38 | end 39 | 40 | def gemfile 41 | gemfile = ENV["BUNDLE_GEMFILE"] 42 | return gemfile if gemfile && !gemfile.empty? 43 | 44 | File.expand_path("../Gemfile", __dir__) 45 | end 46 | 47 | def lockfile 48 | lockfile = 49 | case File.basename(gemfile) 50 | when "gems.rb" then gemfile.sub(/\.rb$/, ".locked") 51 | else "#{gemfile}.lock" 52 | end 53 | File.expand_path(lockfile) 54 | end 55 | 56 | def lockfile_version 57 | return unless File.file?(lockfile) 58 | lockfile_contents = File.read(lockfile) 59 | return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/ 60 | Regexp.last_match(1) 61 | end 62 | 63 | def bundler_requirement 64 | @bundler_requirement ||= 65 | env_var_version || 66 | cli_arg_version || 67 | bundler_requirement_for(lockfile_version) 68 | end 69 | 70 | def bundler_requirement_for(version) 71 | return "#{Gem::Requirement.default}.a" unless version 72 | 73 | bundler_gem_version = Gem::Version.new(version) 74 | 75 | bundler_gem_version.approximate_recommendation 76 | end 77 | 78 | def load_bundler! 79 | ENV["BUNDLE_GEMFILE"] ||= gemfile 80 | 81 | activate_bundler 82 | end 83 | 84 | def activate_bundler 85 | gem_error = activation_error_handling do 86 | gem "bundler", bundler_requirement 87 | end 88 | return if gem_error.nil? 89 | require_error = activation_error_handling do 90 | require "bundler/version" 91 | end 92 | return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION)) 93 | warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`" 94 | exit 42 95 | end 96 | 97 | def activation_error_handling 98 | yield 99 | nil 100 | rescue StandardError, LoadError => e 101 | e 102 | end 103 | end 104 | 105 | m.load_bundler! 106 | 107 | if m.invoked_as_script? 108 | load Gem.bin_path("bundler", "bundle") 109 | end 110 | -------------------------------------------------------------------------------- /bin/bundle.cmd: -------------------------------------------------------------------------------- 1 | @ruby -x "%~f0" %* 2 | @exit /b %ERRORLEVEL% 3 | 4 | #!/usr/bin/env ruby 5 | # frozen_string_literal: true 6 | 7 | # 8 | # This file was generated by Bundler. 9 | # 10 | # The application 'bundle' is installed as part of a gem, and 11 | # this file is here to facilitate running it. 12 | # 13 | 14 | require "rubygems" 15 | 16 | m = Module.new do 17 | module_function 18 | 19 | def invoked_as_script? 20 | File.expand_path($0) == File.expand_path(__FILE__) 21 | end 22 | 23 | def env_var_version 24 | ENV["BUNDLER_VERSION"] 25 | end 26 | 27 | def cli_arg_version 28 | return unless invoked_as_script? # don't want to hijack other binstubs 29 | return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update` 30 | bundler_version = nil 31 | update_index = nil 32 | ARGV.each_with_index do |a, i| 33 | if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN 34 | bundler_version = a 35 | end 36 | next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/ 37 | bundler_version = $1 38 | update_index = i 39 | end 40 | bundler_version 41 | end 42 | 43 | def gemfile 44 | gemfile = ENV["BUNDLE_GEMFILE"] 45 | return gemfile if gemfile && !gemfile.empty? 46 | 47 | File.expand_path("../Gemfile", __dir__) 48 | end 49 | 50 | def lockfile 51 | lockfile = 52 | case File.basename(gemfile) 53 | when "gems.rb" then gemfile.sub(/\.rb$/, ".locked") 54 | else "#{gemfile}.lock" 55 | end 56 | File.expand_path(lockfile) 57 | end 58 | 59 | def lockfile_version 60 | return unless File.file?(lockfile) 61 | lockfile_contents = File.read(lockfile) 62 | return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/ 63 | Regexp.last_match(1) 64 | end 65 | 66 | def bundler_requirement 67 | @bundler_requirement ||= 68 | env_var_version || 69 | cli_arg_version || 70 | bundler_requirement_for(lockfile_version) 71 | end 72 | 73 | def bundler_requirement_for(version) 74 | return "#{Gem::Requirement.default}.a" unless version 75 | 76 | bundler_gem_version = Gem::Version.new(version) 77 | 78 | bundler_gem_version.approximate_recommendation 79 | end 80 | 81 | def load_bundler! 82 | ENV["BUNDLE_GEMFILE"] ||= gemfile 83 | 84 | activate_bundler 85 | end 86 | 87 | def activate_bundler 88 | gem_error = activation_error_handling do 89 | gem "bundler", bundler_requirement 90 | end 91 | return if gem_error.nil? 92 | require_error = activation_error_handling do 93 | require "bundler/version" 94 | end 95 | return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION)) 96 | warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`" 97 | exit 42 98 | end 99 | 100 | def activation_error_handling 101 | yield 102 | nil 103 | rescue StandardError, LoadError => e 104 | e 105 | end 106 | end 107 | 108 | m.load_bundler! 109 | 110 | if m.invoked_as_script? 111 | load Gem.bin_path("bundler", "bundle") 112 | end 113 | -------------------------------------------------------------------------------- /bin/importmap: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require_relative "../config/application" 4 | require "importmap/commands" 5 | -------------------------------------------------------------------------------- /bin/rails: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby.exe 2 | APP_PATH = File.expand_path("../config/application", __dir__) 3 | require_relative "../config/boot" 4 | require "rails/commands" 5 | -------------------------------------------------------------------------------- /bin/rake: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby.exe 2 | require_relative "../config/boot" 3 | require "rake" 4 | Rake.application.run 5 | -------------------------------------------------------------------------------- /bin/setup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby.exe 2 | require "fileutils" 3 | 4 | # path to your application root. 5 | APP_ROOT = File.expand_path("..", __dir__) 6 | 7 | def system!(*args) 8 | system(*args) || abort("\n== Command #{args} failed ==") 9 | end 10 | 11 | FileUtils.chdir APP_ROOT do 12 | # This script is a way to set up or update your development environment automatically. 13 | # This script is idempotent, so that you can run it at any time and get an expectable outcome. 14 | # Add necessary setup steps to this file. 15 | 16 | puts "== Installing dependencies ==" 17 | system! "gem install bundler --conservative" 18 | system("bundle check") || system!("bundle install") 19 | 20 | # puts "\n== Copying sample files ==" 21 | # unless File.exist?("config/database.yml") 22 | # FileUtils.cp "config/database.yml.sample", "config/database.yml" 23 | # end 24 | 25 | puts "\n== Preparing database ==" 26 | system! "bin/rails db:prepare" 27 | 28 | puts "\n== Removing old logs and tempfiles ==" 29 | system! "bin/rails log:clear tmp:clear" 30 | 31 | puts "\n== Restarting application server ==" 32 | system! "bin/rails restart" 33 | end 34 | -------------------------------------------------------------------------------- /config.ru: -------------------------------------------------------------------------------- 1 | # This file is used by Rack-based servers to start the application. 2 | 3 | require_relative 'config/environment' 4 | 5 | run Rails.application 6 | Rails.application.load_server 7 | -------------------------------------------------------------------------------- /config/application.rb: -------------------------------------------------------------------------------- 1 | require_relative "boot" 2 | 3 | require "rails/all" 4 | 5 | # Require the gems listed in Gemfile, including any gems 6 | # you've limited to :test, :development, or :production. 7 | Bundler.require(*Rails.groups) 8 | 9 | module BlogApp 10 | class Application < Rails::Application 11 | # Initialize configuration defaults for originally generated Rails version. 12 | config.load_defaults 7.0 13 | 14 | # Configuration for the application, engines, and railties goes here. 15 | # 16 | # These settings can be overridden in specific environments using the files 17 | # in config/environments, which are processed later. 18 | # 19 | # config.time_zone = "Central Time (US & Canada)" 20 | # config.eager_load_paths << Rails.root.join("extras") 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /config/boot.rb: -------------------------------------------------------------------------------- 1 | ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) 2 | 3 | require "bundler/setup" # Set up gems listed in the Gemfile. 4 | require "bootsnap/setup" # Speed up boot time by caching expensive operations. 5 | -------------------------------------------------------------------------------- /config/cable.yml: -------------------------------------------------------------------------------- 1 | development: 2 | adapter: async 3 | 4 | test: 5 | adapter: test 6 | 7 | production: 8 | adapter: redis 9 | url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %> 10 | channel_prefix: Blog_App_production 11 | -------------------------------------------------------------------------------- /config/database.yml: -------------------------------------------------------------------------------- 1 | # PostgreSQL. Versions 9.3 and up are supported. 2 | # 3 | # Install the pg driver: 4 | # gem install pg 5 | # On macOS with Homebrew: 6 | # gem install pg -- --with-pg-config=/usr/local/bin/pg_config 7 | # On macOS with MacPorts: 8 | # gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config 9 | # On Windows: 10 | # gem install pg 11 | # Choose the win32 build. 12 | # Install PostgreSQL and put its /bin directory on your path. 13 | # 14 | # Configure Using Gemfile 15 | # gem "pg" 16 | # 17 | default: &default 18 | adapter: postgresql 19 | encoding: unicode 20 | # For details on connection pooling, see Rails configuration guide 21 | # https://guides.rubyonrails.org/configuring.html#database-pooling 22 | pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> 23 | 24 | development: 25 | <<: *default 26 | database: Blog_Posts_development 27 | host: localhost 28 | port: 5432 29 | username: postgres 30 | password: password 31 | # The specified database role being used to connect to postgres. 32 | # To create additional roles in postgres see `$ createuser --help`. 33 | # When left blank, postgres will use the default role. This is 34 | # the same name as the operating system user running Rails. 35 | #username: Blog_Post 36 | 37 | # The password associated with the postgres role (username). 38 | #password: 39 | 40 | # Connect on a TCP socket. Omitted by default since the client uses a 41 | # domain socket that doesn't need configuration. Windows does not have 42 | # domain sockets, so uncomment these lines. 43 | #host: localhost 44 | 45 | # The TCP port the server listens on. Defaults to 5432. 46 | # If your server runs on a different port number, change accordingly. 47 | #port: 5432 48 | 49 | # Schema search path. The server defaults to $user,public 50 | #schema_search_path: myPost,sharedPost,public 51 | 52 | # Minimum log levels, in increasing order: 53 | # debug5, debug4, debug3, debug2, debug1, 54 | # log, notice, warning, error, fatal, and panic 55 | # Defaults to warning. 56 | #min_messages: notice 57 | 58 | # Warning: The database defined as "test" will be erased and 59 | # re-generated from your development database when you run "rake". 60 | # Do not set this db to the same as development or production. 61 | test: 62 | <<: *default 63 | database: Blog_Posts_test 64 | host: localhost 65 | port: 5432 66 | username: postgres 67 | password: password 68 | # As with config/credentials.yml, you never want to store sensitive information, 69 | # like your database password, in your source code. If your source code is 70 | # ever seen by anyone, they now have access to your database. 71 | # 72 | # Instead, provide the password or a full connection URL as an environment 73 | # variable when you boot the Post. For example: 74 | # 75 | # DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase" 76 | # 77 | # If the connection URL is provided in the special DATABASE_URL environment 78 | # variable, Rails will automatically merge its configuration values on top of 79 | # the values provided in this file. Alternatively, you can specify a connection 80 | # URL environment variable explicitly: 81 | # 82 | # production: 83 | # url: <%= ENV["MY_Post_DATABASE_URL"] %> 84 | # 85 | # Read https://guides.rubyonrails.org/configuring.html#configuring-a-database 86 | # for a full overview on how database connection configuration can be specified. 87 | # 88 | production: 89 | <<: *default 90 | database: Blog_Posts_production 91 | username: Blog_Post 92 | password: <%= ENV["BLOG_Post_DATABASE_PASSWORD"] %> 93 | -------------------------------------------------------------------------------- /config/environment.rb: -------------------------------------------------------------------------------- 1 | # Load the Rails application. 2 | require_relative "application" 3 | 4 | # Initialize the Rails application. 5 | Rails.application.initialize! 6 | -------------------------------------------------------------------------------- /config/environments/development.rb: -------------------------------------------------------------------------------- 1 | require "active_support/core_ext/integer/time" 2 | 3 | Rails.application.configure do 4 | # Settings specified here will take precedence over those in config/application.rb. 5 | 6 | config.action_mailer.default_url_options = { host: 'localhost', port: 3000 } 7 | 8 | # In the development environment your application's code is reloaded any time 9 | # it changes. This slows down response time but is perfect for development 10 | # since you don't have to restart the web server when you make code changes. 11 | config.cache_classes = false 12 | 13 | # Do not eager load code on boot. 14 | config.eager_load = false 15 | 16 | # Show full error reports. 17 | config.consider_all_requests_local = true 18 | 19 | # Enable server timing 20 | config.server_timing = true 21 | 22 | # Enable/disable caching. By default caching is disabled. 23 | # Run rails dev:cache to toggle caching. 24 | if Rails.root.join("tmp/caching-dev.txt").exist? 25 | config.action_controller.perform_caching = true 26 | config.action_controller.enable_fragment_cache_logging = true 27 | 28 | config.cache_store = :memory_store 29 | config.public_file_server.headers = { 30 | "Cache-Control" => "public, max-age=#{2.days.to_i}" 31 | } 32 | else 33 | config.action_controller.perform_caching = false 34 | 35 | config.cache_store = :null_store 36 | end 37 | 38 | # Store uploaded files on the local file system (see config/storage.yml for options). 39 | config.active_storage.service = :local 40 | 41 | # Don't care if the mailer can't send. 42 | config.action_mailer.raise_delivery_errors = false 43 | 44 | config.action_mailer.perform_caching = false 45 | 46 | # Print deprecation notices to the Rails logger. 47 | config.active_support.deprecation = :log 48 | 49 | # Raise exceptions for disallowed deprecations. 50 | config.active_support.disallowed_deprecation = :raise 51 | 52 | # Tell Active Support which deprecation messages to disallow. 53 | config.active_support.disallowed_deprecation_warnings = [] 54 | 55 | # Raise an error on page load if there are pending migrations. 56 | config.active_record.migration_error = :page_load 57 | 58 | # Highlight code that triggered database queries in logs. 59 | config.active_record.verbose_query_logs = true 60 | 61 | # Suppress logger output for asset requests. 62 | config.assets.quiet = true 63 | 64 | # Raises error for missing translations. 65 | # config.i18n.raise_on_missing_translations = true 66 | 67 | # Annotate rendered view with file names. 68 | # config.action_view.annotate_rendered_view_with_filenames = true 69 | 70 | # Uncomment if you wish to allow Action Cable access from any origin. 71 | # config.action_cable.disable_request_forgery_protection = true 72 | end 73 | -------------------------------------------------------------------------------- /config/environments/production.rb: -------------------------------------------------------------------------------- 1 | require "active_support/core_ext/integer/time" 2 | 3 | Rails.application.configure do 4 | # Settings specified here will take precedence over those in config/application.rb. 5 | 6 | # Code is not reloaded between requests. 7 | config.cache_classes = true 8 | 9 | # Eager load code on boot. This eager loads most of Rails and 10 | # your application in memory, allowing both threaded web servers 11 | # and those relying on copy on write to perform better. 12 | # Rake tasks automatically ignore this option for performance. 13 | config.eager_load = true 14 | 15 | # Full error reports are disabled and caching is turned on. 16 | config.consider_all_requests_local = false 17 | config.action_controller.perform_caching = true 18 | 19 | # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"] 20 | # or in config/master.key. This key is used to decrypt credentials (and other encrypted files). 21 | # config.require_master_key = true 22 | 23 | # Disable serving static files from the `/public` folder by default since 24 | # Apache or NGINX already handles this. 25 | config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present? 26 | 27 | # Compress CSS using a preprocessor. 28 | # config.assets.css_compressor = :sass 29 | 30 | # Do not fallback to assets pipeline if a precompiled asset is missed. 31 | config.assets.compile = false 32 | 33 | # Enable serving of images, stylesheets, and JavaScripts from an asset server. 34 | # config.asset_host = "http://assets.example.com" 35 | 36 | # Specifies the header that your server uses for sending files. 37 | # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for Apache 38 | # config.action_dispatch.x_sendfile_header = "X-Accel-Redirect" # for NGINX 39 | 40 | # Store uploaded files on the local file system (see config/storage.yml for options). 41 | config.active_storage.service = :local 42 | 43 | # Mount Action Cable outside main process or domain. 44 | # config.action_cable.mount_path = nil 45 | # config.action_cable.url = "wss://example.com/cable" 46 | # config.action_cable.allowed_request_origins = [ "http://example.com", /http:\/\/example.*/ ] 47 | 48 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. 49 | # config.force_ssl = true 50 | 51 | # Include generic and useful information about system operation, but avoid logging too much 52 | # information to avoid inadvertent exposure of personally identifiable information (PII). 53 | config.log_level = :info 54 | 55 | # Prepend all log lines with the following tags. 56 | config.log_tags = [ :request_id ] 57 | 58 | # Use a different cache store in production. 59 | # config.cache_store = :mem_cache_store 60 | 61 | # Use a real queuing backend for Active Job (and separate queues per environment). 62 | # config.active_job.queue_adapter = :resque 63 | # config.active_job.queue_name_prefix = "My_Blog_App_production" 64 | 65 | config.action_mailer.perform_caching = false 66 | 67 | # Ignore bad email addresses and do not raise email delivery errors. 68 | # Set this to true and configure the email server for immediate delivery to raise delivery errors. 69 | # config.action_mailer.raise_delivery_errors = false 70 | 71 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to 72 | # the I18n.default_locale when a translation cannot be found). 73 | config.i18n.fallbacks = true 74 | 75 | # Don't log any deprecations. 76 | config.active_support.report_deprecations = false 77 | 78 | # Use default logging formatter so that PID and timestamp are not suppressed. 79 | config.log_formatter = ::Logger::Formatter.new 80 | 81 | # Use a different logger for distributed setups. 82 | # require "syslog/logger" 83 | # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new "app-name") 84 | 85 | if ENV["RAILS_LOG_TO_STDOUT"].present? 86 | logger = ActiveSupport::Logger.new(STDOUT) 87 | logger.formatter = config.log_formatter 88 | config.logger = ActiveSupport::TaggedLogging.new(logger) 89 | end 90 | 91 | # Do not dump schema after migrations. 92 | config.active_record.dump_schema_after_migration = false 93 | end 94 | -------------------------------------------------------------------------------- /config/environments/test.rb: -------------------------------------------------------------------------------- 1 | require "active_support/core_ext/integer/time" 2 | 3 | # The test environment is used exclusively to run your application's 4 | # test suite. You never need to work with it otherwise. Remember that 5 | # your test database is "scratch space" for the test suite and is wiped 6 | # and recreated between test runs. Don't rely on the data there! 7 | 8 | Rails.application.configure do 9 | # Settings specified here will take precedence over those in config/application.rb. 10 | 11 | # Turn false under Spring and add config.action_view.cache_template_loading = true. 12 | config.cache_classes = true 13 | 14 | # Eager loading loads your whole application. When running a single test locally, 15 | # this probably isn't necessary. It's a good idea to do in a continuous integration 16 | # system, or in some way before deploying your code. 17 | config.eager_load = ENV["CI"].present? 18 | 19 | # Configure public file server for tests with Cache-Control for performance. 20 | config.public_file_server.enabled = true 21 | config.public_file_server.headers = { 22 | "Cache-Control" => "public, max-age=#{1.hour.to_i}" 23 | } 24 | 25 | # Show full error reports and disable caching. 26 | config.consider_all_requests_local = true 27 | config.action_controller.perform_caching = false 28 | config.cache_store = :null_store 29 | 30 | # Raise exceptions instead of rendering exception templates. 31 | config.action_dispatch.show_exceptions = false 32 | 33 | # Disable request forgery protection in test environment. 34 | config.action_controller.allow_forgery_protection = false 35 | 36 | # Store uploaded files on the local file system in a temporary directory. 37 | config.active_storage.service = :test 38 | 39 | config.action_mailer.perform_caching = false 40 | 41 | # Tell Action Mailer not to deliver emails to the real world. 42 | # The :test delivery method accumulates sent emails in the 43 | # ActionMailer::Base.deliveries array. 44 | config.action_mailer.delivery_method = :test 45 | 46 | # Print deprecation notices to the stderr. 47 | config.active_support.deprecation = :stderr 48 | 49 | # Raise exceptions for disallowed deprecations. 50 | config.active_support.disallowed_deprecation = :raise 51 | 52 | # Tell Active Support which deprecation messages to disallow. 53 | config.active_support.disallowed_deprecation_warnings = [] 54 | 55 | # Raises error for missing translations. 56 | # config.i18n.raise_on_missing_translations = true 57 | 58 | # Annotate rendered view with file names. 59 | # config.action_view.annotate_rendered_view_with_filenames = true 60 | end 61 | -------------------------------------------------------------------------------- /config/importmap.rb: -------------------------------------------------------------------------------- 1 | # Pin npm packages by running ./bin/importmap 2 | 3 | pin "application", preload: true 4 | pin "@hotwired/turbo-rails", to: "turbo.min.js", preload: true 5 | pin "@hotwired/stimulus", to: "stimulus.min.js", preload: true 6 | pin "@hotwired/stimulus-loading", to: "stimulus-loading.js", preload: true 7 | pin_all_from "app/javascript/controllers", under: "controllers" 8 | -------------------------------------------------------------------------------- /config/initializers/assets.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Version of your assets, change this if you want to expire all your assets. 4 | Rails.application.config.assets.version = "1.0" 5 | 6 | # Add additional assets to the asset load path. 7 | # Rails.application.config.assets.paths << Emoji.images_path 8 | 9 | # Precompile additional assets. 10 | # application.js, application.css, and all non-JS/CSS in the app/assets 11 | # folder are already added. 12 | # Rails.application.config.assets.precompile += %w( admin.js admin.css ) 13 | -------------------------------------------------------------------------------- /config/initializers/content_security_policy.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Define an application-wide content security policy. 4 | # See the Securing Rails Applications Guide for more information: 5 | # https://guides.rubyonrails.org/security.html#content-security-policy-header 6 | 7 | # Rails.application.configure do 8 | # config.content_security_policy do |policy| 9 | # policy.default_src :self, :https 10 | # policy.font_src :self, :https, :data 11 | # policy.img_src :self, :https, :data 12 | # policy.object_src :none 13 | # policy.script_src :self, :https 14 | # policy.style_src :self, :https 15 | # # Specify URI for violation reports 16 | # # policy.report_uri "/csp-violation-report-endpoint" 17 | # end 18 | # 19 | # # Generate session nonces for permitted importmap and inline scripts 20 | # config.content_security_policy_nonce_generator = ->(request) { request.session.id.to_s } 21 | # config.content_security_policy_nonce_directives = %w(script-src) 22 | # 23 | # # Report violations without enforcing the policy. 24 | # # config.content_security_policy_report_only = true 25 | # end 26 | -------------------------------------------------------------------------------- /config/initializers/devise.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # Assuming you have not yet modified this file, each configuration option below 4 | # is set to its default value. Note that some are commented out while others 5 | # are not: uncommented lines are intended to protect your configuration from 6 | # breaking changes in upgrades (i.e., in the event that future versions of 7 | # Devise change the default values for those options). 8 | # 9 | # Use this hook to configure devise mailer, warden hooks and so forth. 10 | # Many of these configuration options can be set straight in your model. 11 | Devise.setup do |config| 12 | # The secret key used by Devise. Devise uses this key to generate 13 | # random tokens. Changing this key will render invalid all existing 14 | # confirmation, reset password and unlock tokens in the database. 15 | # Devise will use the `secret_key_base` as its `secret_key` 16 | # by default. You can change it below and use your own secret key. 17 | # config.secret_key = 'bee8d6c68be3a3f8c2401921cd58c27b7cd7676e826a0883c41cabb28c16f82f2d1c23a7128cbf41f8871ffd4033be0b2b9d39a69810fb5738873501e11bd40d' 18 | 19 | # ==> Controller configuration 20 | # Configure the parent class to the devise controllers. 21 | # config.parent_controller = 'DeviseController' 22 | 23 | # ==> Mailer Configuration 24 | # Configure the e-mail address which will be shown in Devise::Mailer, 25 | # note that it will be overwritten if you use your own mailer class 26 | # with default "from" parameter. 27 | config.mailer_sender = 'please-change-me-at-config-initializers-devise@example.com' 28 | 29 | # Configure the class responsible to send e-mails. 30 | # config.mailer = 'Devise::Mailer' 31 | 32 | # Configure the parent class responsible to send e-mails. 33 | # config.parent_mailer = 'ActionMailer::Base' 34 | 35 | # ==> ORM configuration 36 | # Load and configure the ORM. Supports :active_record (default) and 37 | # :mongoid (bson_ext recommended) by default. Other ORMs may be 38 | # available as additional gems. 39 | require 'devise/orm/active_record' 40 | 41 | # ==> Configuration for any authentication mechanism 42 | # Configure which keys are used when authenticating a user. The default is 43 | # just :email. You can configure it to use [:username, :subdomain], so for 44 | # authenticating a user, both parameters are required. Remember that those 45 | # parameters are used only when authenticating and not when retrieving from 46 | # session. If you need permissions, you should implement that in a before filter. 47 | # You can also supply a hash where the value is a boolean determining whether 48 | # or not authentication should be aborted when the value is not present. 49 | # config.authentication_keys = [:email] 50 | 51 | # Configure parameters from the request object used for authentication. Each entry 52 | # given should be a request method and it will automatically be passed to the 53 | # find_for_authentication method and considered in your model lookup. For instance, 54 | # if you set :request_keys to [:subdomain], :subdomain will be used on authentication. 55 | # The same considerations mentioned for authentication_keys also apply to request_keys. 56 | # config.request_keys = [] 57 | 58 | # Configure which authentication keys should be case-insensitive. 59 | # These keys will be downcased upon creating or modifying a user and when used 60 | # to authenticate or find a user. Default is :email. 61 | config.case_insensitive_keys = [:email] 62 | 63 | # Configure which authentication keys should have whitespace stripped. 64 | # These keys will have whitespace before and after removed upon creating or 65 | # modifying a user and when used to authenticate or find a user. Default is :email. 66 | config.strip_whitespace_keys = [:email] 67 | 68 | # Tell if authentication through request.params is enabled. True by default. 69 | # It can be set to an array that will enable params authentication only for the 70 | # given strategies, for example, `config.params_authenticatable = [:database]` will 71 | # enable it only for database (email + password) authentication. 72 | # config.params_authenticatable = true 73 | 74 | # Tell if authentication through HTTP Auth is enabled. False by default. 75 | # It can be set to an array that will enable http authentication only for the 76 | # given strategies, for example, `config.http_authenticatable = [:database]` will 77 | # enable it only for database authentication. 78 | # For API-only applications to support authentication "out-of-the-box", you will likely want to 79 | # enable this with :database unless you are using a custom strategy. 80 | # The supported strategies are: 81 | # :database = Support basic authentication with authentication key + password 82 | # config.http_authenticatable = false 83 | 84 | # If 401 status code should be returned for AJAX requests. True by default. 85 | # config.http_authenticatable_on_xhr = true 86 | 87 | # The realm used in Http Basic Authentication. 'Application' by default. 88 | # config.http_authentication_realm = 'Application' 89 | 90 | # It will change confirmation, password recovery and other workflows 91 | # to behave the same regardless if the e-mail provided was right or wrong. 92 | # Does not affect registerable. 93 | # config.paranoid = true 94 | 95 | # By default Devise will store the user in session. You can skip storage for 96 | # particular strategies by setting this option. 97 | # Notice that if you are skipping storage for all authentication paths, you 98 | # may want to disable generating routes to Devise's sessions controller by 99 | # passing skip: :sessions to `devise_for` in your config/routes.rb 100 | config.skip_session_storage = [:http_auth] 101 | 102 | # By default, Devise cleans up the CSRF token on authentication to 103 | # avoid CSRF token fixation attacks. This means that, when using AJAX 104 | # requests for sign in and sign up, you need to get a new CSRF token 105 | # from the server. You can disable this option at your own risk. 106 | # config.clean_up_csrf_token_on_authentication = true 107 | 108 | # When false, Devise will not attempt to reload routes on eager load. 109 | # This can reduce the time taken to boot the app but if your application 110 | # requires the Devise mappings to be loaded during boot time the application 111 | # won't boot properly. 112 | # config.reload_routes = true 113 | 114 | # ==> Configuration for :database_authenticatable 115 | # For bcrypt, this is the cost for hashing the password and defaults to 12. If 116 | # using other algorithms, it sets how many times you want the password to be hashed. 117 | # The number of stretches used for generating the hashed password are stored 118 | # with the hashed password. This allows you to change the stretches without 119 | # invalidating existing passwords. 120 | # 121 | # Limiting the stretches to just one in testing will increase the performance of 122 | # your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use 123 | # a value less than 10 in other environments. Note that, for bcrypt (the default 124 | # algorithm), the cost increases exponentially with the number of stretches (e.g. 125 | # a value of 20 is already extremely slow: approx. 60 seconds for 1 calculation). 126 | config.stretches = Rails.env.test? ? 1 : 12 127 | 128 | # Set up a pepper to generate the hashed password. 129 | # config.pepper = 'ffa1700b557ce66c37844c11409a23f56dbcdc1bf9ba232222ca032f1e7f58fb5315dd1b8afa88c7ba934b20b577bd572bea30dc195c3ccce0bb1af4ef306c23' 130 | 131 | # Send a notification to the original email when the user's email is changed. 132 | # config.send_email_changed_notification = false 133 | 134 | # Send a notification email when the user's password is changed. 135 | # config.send_password_change_notification = false 136 | 137 | # ==> Configuration for :confirmable 138 | # A period that the user is allowed to access the website even without 139 | # confirming their account. For instance, if set to 2.days, the user will be 140 | # able to access the website for two days without confirming their account, 141 | # access will be blocked just in the third day. 142 | # You can also set it to nil, which will allow the user to access the website 143 | # without confirming their account. 144 | # Default is 0.days, meaning the user cannot access the website without 145 | # confirming their account. 146 | # config.allow_unconfirmed_access_for = 2.days 147 | 148 | # A period that the user is allowed to confirm their account before their 149 | # token becomes invalid. For example, if set to 3.days, the user can confirm 150 | # their account within 3 days after the mail was sent, but on the fourth day 151 | # their account can't be confirmed with the token any more. 152 | # Default is nil, meaning there is no restriction on how long a user can take 153 | # before confirming their account. 154 | # config.confirm_within = 3.days 155 | 156 | # If true, requires any email changes to be confirmed (exactly the same way as 157 | # initial account confirmation) to be applied. Requires additional unconfirmed_email 158 | # db field (see migrations). Until confirmed, new email is stored in 159 | # unconfirmed_email column, and copied to email column on successful confirmation. 160 | config.reconfirmable = true 161 | 162 | # Defines which key will be used when confirming an account 163 | # config.confirmation_keys = [:email] 164 | 165 | # ==> Configuration for :rememberable 166 | # The time the user will be remembered without asking for credentials again. 167 | # config.remember_for = 2.weeks 168 | 169 | # Invalidates all the remember me tokens when the user signs out. 170 | config.expire_all_remember_me_on_sign_out = true 171 | 172 | # If true, extends the user's remember period when remembered via cookie. 173 | # config.extend_remember_period = false 174 | 175 | # Options to be passed to the created cookie. For instance, you can set 176 | # secure: true in order to force SSL only cookies. 177 | # config.rememberable_options = {} 178 | 179 | # ==> Configuration for :validatable 180 | # Range for password length. 181 | config.password_length = 6..128 182 | 183 | # Email regex used to validate email formats. It simply asserts that 184 | # one (and only one) @ exists in the given string. This is mainly 185 | # to give user feedback and not to assert the e-mail validity. 186 | config.email_regexp = /\A[^@\s]+@[^@\s]+\z/ 187 | 188 | # ==> Configuration for :timeoutable 189 | # The time you want to timeout the user session without activity. After this 190 | # time the user will be asked for credentials again. Default is 30 minutes. 191 | # config.timeout_in = 30.minutes 192 | 193 | # ==> Configuration for :lockable 194 | # Defines which strategy will be used to lock an account. 195 | # :failed_attempts = Locks an account after a number of failed attempts to sign in. 196 | # :none = No lock strategy. You should handle locking by yourself. 197 | # config.lock_strategy = :failed_attempts 198 | 199 | # Defines which key will be used when locking and unlocking an account 200 | # config.unlock_keys = [:email] 201 | 202 | # Defines which strategy will be used to unlock an account. 203 | # :email = Sends an unlock link to the user email 204 | # :time = Re-enables login after a certain amount of time (see :unlock_in below) 205 | # :both = Enables both strategies 206 | # :none = No unlock strategy. You should handle unlocking by yourself. 207 | # config.unlock_strategy = :both 208 | 209 | # Number of authentication tries before locking an account if lock_strategy 210 | # is failed attempts. 211 | # config.maximum_attempts = 20 212 | 213 | # Time interval to unlock the account if :time is enabled as unlock_strategy. 214 | # config.unlock_in = 1.hour 215 | 216 | # Warn on the last attempt before the account is locked. 217 | # config.last_attempt_warning = true 218 | 219 | # ==> Configuration for :recoverable 220 | # 221 | # Defines which key will be used when recovering the password for an account 222 | # config.reset_password_keys = [:email] 223 | 224 | # Time interval you can reset your password with a reset password key. 225 | # Don't put a too small interval or your users won't have the time to 226 | # change their passwords. 227 | config.reset_password_within = 6.hours 228 | 229 | # When set to false, does not sign a user in automatically after their password is 230 | # reset. Defaults to true, so a user is signed in automatically after a reset. 231 | # config.sign_in_after_reset_password = true 232 | 233 | # ==> Configuration for :encryptable 234 | # Allow you to use another hashing or encryption algorithm besides bcrypt (default). 235 | # You can use :sha1, :sha512 or algorithms from others authentication tools as 236 | # :clearance_sha1, :authlogic_sha512 (then you should set stretches above to 20 237 | # for default behavior) and :restful_authentication_sha1 (then you should set 238 | # stretches to 10, and copy REST_AUTH_SITE_KEY to pepper). 239 | # 240 | # Require the `devise-encryptable` gem when using anything other than bcrypt 241 | # config.encryptor = :sha512 242 | 243 | # ==> Scopes configuration 244 | # Turn scoped views on. Before rendering "sessions/new", it will first check for 245 | # "users/sessions/new". It's turned off by default because it's slower if you 246 | # are using only default views. 247 | # config.scoped_views = false 248 | 249 | # Configure the default scope given to Warden. By default it's the first 250 | # devise role declared in your routes (usually :user). 251 | # config.default_scope = :user 252 | 253 | # Set this configuration to false if you want /users/sign_out to sign out 254 | # only the current scope. By default, Devise signs out all scopes. 255 | # config.sign_out_all_scopes = true 256 | 257 | # ==> Navigation configuration 258 | # Lists the formats that should be treated as navigational. Formats like 259 | # :html should redirect to the sign in page when the user does not have 260 | # access, but formats like :xml or :json, should return 401. 261 | # 262 | # If you have any extra navigational formats, like :iphone or :mobile, you 263 | # should add them to the navigational formats lists. 264 | # 265 | # The "*/*" below is required to match Internet Explorer requests. 266 | # config.navigational_formats = ['*/*', :html, :turbo_stream] 267 | 268 | # The default HTTP method used to sign out a resource. Default is :delete. 269 | config.sign_out_via = :delete 270 | 271 | # ==> OmniAuth 272 | # Add a new OmniAuth provider. Check the wiki for more information on setting 273 | # up on your models and hooks. 274 | # config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo' 275 | 276 | # ==> Warden configuration 277 | # If you want to use other strategies, that are not supported by Devise, or 278 | # change the failure app, you can configure them inside the config.warden block. 279 | # 280 | # config.warden do |manager| 281 | # manager.intercept_401 = false 282 | # manager.default_strategies(scope: :user).unshift :some_external_strategy 283 | # end 284 | 285 | # ==> Mountable engine configurations 286 | # When using Devise inside an engine, let's call it `MyEngine`, and this engine 287 | # is mountable, there are some extra configurations to be taken into account. 288 | # The following options are available, assuming the engine is mounted as: 289 | # 290 | # mount MyEngine, at: '/my_engine' 291 | # 292 | # The router that invoked `devise_for`, in the example above, would be: 293 | # config.router_name = :my_engine 294 | # 295 | # When using OmniAuth, Devise cannot automatically set OmniAuth path, 296 | # so you need to do it manually. For the users scope, it would be: 297 | # config.omniauth_path_prefix = '/my_engine/users/auth' 298 | 299 | # ==> Hotwire/Turbo configuration 300 | # When using Devise with Hotwire/Turbo, the http status for error responses 301 | # and some redirects must match the following. The default in Devise for existing 302 | # apps is `200 OK` and `302 Found respectively`, but new apps are generated with 303 | # these new defaults that match Hotwire/Turbo behavior. 304 | # Note: These might become the new default in future versions of Devise. 305 | config.responder.error_status = :unprocessable_entity 306 | config.responder.redirect_status = :see_other 307 | 308 | # ==> Configuration for :registerable 309 | 310 | # When set to false, does not sign a user in automatically after their password is 311 | # changed. Defaults to true, so a user is signed in automatically after changing a password. 312 | # config.sign_in_after_change_password = true 313 | end 314 | -------------------------------------------------------------------------------- /config/initializers/filter_parameter_logging.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Configure parameters to be filtered from the log file. Use this to limit dissemination of 4 | # sensitive information. See the ActiveSupport::ParameterFilter documentation for supported 5 | # notations and behaviors. 6 | Rails.application.config.filter_parameters += [ 7 | :passw, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn 8 | ] 9 | -------------------------------------------------------------------------------- /config/initializers/inflections.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new inflection rules using the following format. Inflections 4 | # are locale specific, and you may define rules for as many different 5 | # locales as you wish. All of these examples are active by default: 6 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 7 | # inflect.plural /^(ox)$/i, "\\1en" 8 | # inflect.singular /^(ox)en/i, "\\1" 9 | # inflect.irregular "person", "people" 10 | # inflect.uncountable %w( fish sheep ) 11 | # end 12 | 13 | # These inflection rules are supported but not enabled by default: 14 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 15 | # inflect.acronym "RESTful" 16 | # end 17 | -------------------------------------------------------------------------------- /config/initializers/permissions_policy.rb: -------------------------------------------------------------------------------- 1 | # Define an application-wide HTTP permissions policy. For further 2 | # information see https://developers.google.com/web/updates/2018/06/feature-policy 3 | # 4 | # Rails.application.config.permissions_policy do |f| 5 | # f.camera :none 6 | # f.gyroscope :none 7 | # f.microphone :none 8 | # f.usb :none 9 | # f.fullscreen :self 10 | # f.payment :self, "https://secure.example.com" 11 | # end 12 | -------------------------------------------------------------------------------- /config/locales/devise.en.yml: -------------------------------------------------------------------------------- 1 | # Additional translations at https://github.com/heartcombo/devise/wiki/I18n 2 | 3 | en: 4 | devise: 5 | confirmations: 6 | confirmed: "Your email address has been successfully confirmed." 7 | send_instructions: "You will receive an email with instructions for how to confirm your email address in a few minutes." 8 | 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." 9 | failure: 10 | already_authenticated: "You are already signed in." 11 | inactive: "Your account is not activated yet." 12 | invalid: "Invalid %{authentication_keys} or password." 13 | locked: "Your account is locked." 14 | last_attempt: "You have one more attempt before your account is locked." 15 | not_found_in_database: "Invalid %{authentication_keys} or password." 16 | timeout: "Your session expired. Please sign in again to continue." 17 | unauthenticated: "You need to sign in or sign up before continuing." 18 | unconfirmed: "You have to confirm your email address before continuing." 19 | mailer: 20 | confirmation_instructions: 21 | subject: "Confirmation instructions" 22 | reset_password_instructions: 23 | subject: "Reset password instructions" 24 | unlock_instructions: 25 | subject: "Unlock instructions" 26 | email_changed: 27 | subject: "Email Changed" 28 | password_change: 29 | subject: "Password Changed" 30 | omniauth_callbacks: 31 | failure: "Could not authenticate you from %{kind} because \"%{reason}\"." 32 | success: "Successfully authenticated from %{kind} account." 33 | passwords: 34 | 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." 35 | send_instructions: "You will receive an email with instructions on how to reset your password in a few minutes." 36 | 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." 37 | updated: "Your password has been changed successfully. You are now signed in." 38 | updated_not_active: "Your password has been changed successfully." 39 | registrations: 40 | destroyed: "Bye! Your account has been successfully cancelled. We hope to see you again soon." 41 | signed_up: "Welcome! You have signed up successfully." 42 | signed_up_but_inactive: "You have signed up successfully. However, we could not sign you in because your account is not yet activated." 43 | signed_up_but_locked: "You have signed up successfully. However, we could not sign you in because your account is locked." 44 | 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." 45 | 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." 46 | updated: "Your account has been updated successfully." 47 | updated_but_not_signed_in: "Your account has been updated successfully, but since your password was changed, you need to sign in again." 48 | sessions: 49 | signed_in: "Signed in successfully." 50 | signed_out: "Signed out successfully." 51 | already_signed_out: "Signed out successfully." 52 | unlocks: 53 | send_instructions: "You will receive an email with instructions for how to unlock your account in a few minutes." 54 | send_paranoid_instructions: "If your account exists, you will receive an email with instructions for how to unlock it in a few minutes." 55 | unlocked: "Your account has been unlocked successfully. Please sign in to continue." 56 | errors: 57 | messages: 58 | already_confirmed: "was already confirmed, please try signing in" 59 | confirmation_period_expired: "needs to be confirmed within %{period}, please request a new one" 60 | expired: "has expired, please request a new one" 61 | not_found: "not found" 62 | not_locked: "was not locked" 63 | not_saved: 64 | one: "1 error prohibited this %{resource} from being saved:" 65 | other: "%{count} errors prohibited this %{resource} from being saved:" 66 | -------------------------------------------------------------------------------- /config/locales/en.yml: -------------------------------------------------------------------------------- 1 | # Files in the config/locales directory are used for internationalization 2 | # and are automatically loaded by Rails. If you want to use locales other 3 | # than English, add the necessary files in this directory. 4 | # 5 | # To use the locales, use `I18n.t`: 6 | # 7 | # I18n.t "hello" 8 | # 9 | # In views, this is aliased to just `t`: 10 | # 11 | # <%= t("hello") %> 12 | # 13 | # To use a different locale, set it with `I18n.locale`: 14 | # 15 | # I18n.locale = :es 16 | # 17 | # This would use the information in config/locales/es.yml. 18 | # 19 | # The following keys must be escaped otherwise they will not be retrieved by 20 | # the default I18n backend: 21 | # 22 | # true, false, on, off, yes, no 23 | # 24 | # Instead, surround them with single quotes. 25 | # 26 | # en: 27 | # "true": "foo" 28 | # 29 | # To learn more, please read the Rails Internationalization guide 30 | # available at https://guides.rubyonrails.org/i18n.html. 31 | 32 | en: 33 | hello: "Hello world" 34 | -------------------------------------------------------------------------------- /config/puma.rb: -------------------------------------------------------------------------------- 1 | # Puma can serve each request in a thread from an internal thread pool. 2 | # The `threads` method setting takes two numbers: a minimum and maximum. 3 | # Any libraries that use thread pools should be configured to match 4 | # the maximum value specified for Puma. Default is set to 5 threads for minimum 5 | # and maximum; this matches the default thread size of Active Record. 6 | # 7 | max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } 8 | min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count } 9 | threads min_threads_count, max_threads_count 10 | 11 | # Specifies the `worker_timeout` threshold that Puma will use to wait before 12 | # terminating a worker in development environments. 13 | # 14 | worker_timeout 3600 if ENV.fetch("RAILS_ENV", "development") == "development" 15 | 16 | # Specifies the `port` that Puma will listen on to receive requests; default is 3000. 17 | # 18 | port ENV.fetch("PORT") { 3000 } 19 | 20 | # Specifies the `environment` that Puma will run in. 21 | # 22 | environment ENV.fetch("RAILS_ENV") { "development" } 23 | 24 | # Specifies the `pidfile` that Puma will use. 25 | pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" } 26 | 27 | # Specifies the number of `workers` to boot in clustered mode. 28 | # Workers are forked web server processes. If using threads and workers together 29 | # the concurrency of the application would be max `threads` * `workers`. 30 | # Workers do not work on JRuby or Windows (both of which do not support 31 | # processes). 32 | # 33 | # workers ENV.fetch("WEB_CONCURRENCY") { 2 } 34 | 35 | # Use the `preload_app!` method when specifying a `workers` number. 36 | # This directive tells Puma to first boot the application and load code 37 | # before forking the application. This takes advantage of Copy On Write 38 | # process behavior so workers use less memory. 39 | # 40 | # preload_app! 41 | 42 | # Allow puma to be restarted by `bin/rails restart` command. 43 | plugin :tmp_restart 44 | -------------------------------------------------------------------------------- /config/routes.rb: -------------------------------------------------------------------------------- 1 | Rails.application.routes.draw do 2 | devise_for :users 3 | 4 | namespace :api do 5 | get '/users/:user_id/posts', to: 'posts#index' 6 | post '/comments', to: 'comments#create' 7 | get '/users/:user_id/posts/:post_id/comments', to: 'comments#index' 8 | end 9 | 10 | devise_scope :user do 11 | get 'login', to: 'devise/sessions#new' 12 | get 'sign_up', to: 'devise/registrations#new' 13 | end 14 | 15 | devise_for :users, skip: :all 16 | root "users#index" 17 | resources :users, only: [:index, :show] do 18 | resources :posts, only: [:index, :new, :show, :destroy] do 19 | resources :comments, only: [:new, :create, :destroy] 20 | resources :likes, only: [:create] 21 | end 22 | end 23 | post "users/:user_id/posts", to: "posts#create", as: :user_create_post 24 | end 25 | -------------------------------------------------------------------------------- /config/storage.yml: -------------------------------------------------------------------------------- 1 | test: 2 | service: Disk 3 | root: <%= Rails.root.join("tmp/storage") %> 4 | 5 | local: 6 | service: Disk 7 | root: <%= Rails.root.join("storage") %> 8 | 9 | # Use bin/rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key) 10 | # amazon: 11 | # service: S3 12 | # access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %> 13 | # secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %> 14 | # region: us-east-1 15 | # bucket: your_own_bucket-<%= Rails.env %> 16 | 17 | # Remember not to checkin your GCS keyfile to a repository 18 | # google: 19 | # service: GCS 20 | # project: your_project 21 | # credentials: <%= Rails.root.join("path/to/gcs.keyfile") %> 22 | # bucket: your_own_bucket-<%= Rails.env %> 23 | 24 | # Use bin/rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key) 25 | # microsoft: 26 | # service: AzureStorage 27 | # storage_account_name: your_account_name 28 | # storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %> 29 | # container: your_container_name-<%= Rails.env %> 30 | 31 | # mirror: 32 | # service: Mirror 33 | # primary: local 34 | # mirrors: [ amazon, google, microsoft ] 35 | -------------------------------------------------------------------------------- /db/migrate/20230608114107_create_users.rb: -------------------------------------------------------------------------------- 1 | class CreateUsers < ActiveRecord::Migration[7.0] 2 | def change 3 | create_table :users do |t| 4 | t.string :name 5 | t.string :photo 6 | t.text :bio 7 | t.integer :posts_counter 8 | 9 | t.timestamps 10 | end 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /db/migrate/20230608114150_create_posts.rb: -------------------------------------------------------------------------------- 1 | class CreatePosts < ActiveRecord::Migration[7.0] 2 | def change 3 | create_table :posts do |t| 4 | t.string :title 5 | t.string :text 6 | t.integer :comment_counter 7 | t.integer :likes_counter 8 | 9 | t.timestamps 10 | end 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /db/migrate/20230608114218_create_comments.rb: -------------------------------------------------------------------------------- 1 | class CreateComments < ActiveRecord::Migration[7.0] 2 | def change 3 | create_table :comments do |t| 4 | t.string :text 5 | 6 | t.timestamps 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /db/migrate/20230608114243_create_likes.rb: -------------------------------------------------------------------------------- 1 | class CreateLikes < ActiveRecord::Migration[7.0] 2 | def change 3 | create_table :likes do |t| 4 | 5 | t.timestamps 6 | end 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /db/migrate/20230608114426_add_post_ref_to_comments.rb: -------------------------------------------------------------------------------- 1 | class AddPostRefToComments < ActiveRecord::Migration[7.0] 2 | def change 3 | add_reference :comments, :post, null: false, foreign_key: true 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /db/migrate/20230608114447_add_user_ref_to_comments.rb: -------------------------------------------------------------------------------- 1 | class AddUserRefToComments < ActiveRecord::Migration[7.0] 2 | def change 3 | add_reference :comments, :user, null: false, foreign_key: true 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /db/migrate/20230608114520_add_user_ref_to_posts.rb: -------------------------------------------------------------------------------- 1 | class AddUserRefToPosts < ActiveRecord::Migration[7.0] 2 | def change 3 | add_reference :posts, :user, null: false, foreign_key: true 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /db/migrate/20230608114546_add_user_ref_to_likes.rb: -------------------------------------------------------------------------------- 1 | class AddUserRefToLikes < ActiveRecord::Migration[7.0] 2 | def change 3 | add_reference :likes, :user, null: false, foreign_key: true 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /db/migrate/20230608114604_add_post_ref_to_likes.rb: -------------------------------------------------------------------------------- 1 | class AddPostRefToLikes < ActiveRecord::Migration[7.0] 2 | def change 3 | add_reference :likes, :post, null: false, foreign_key: true 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /db/migrate/20230620134255_add_devise_to_users.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class AddDeviseToUsers < ActiveRecord::Migration[7.0] 4 | def self.up 5 | change_table :users do |t| 6 | ## Database authenticatable 7 | t.string :email, null: false, default: "" 8 | t.string :encrypted_password, null: false, default: "" 9 | 10 | ## Recoverable 11 | t.string :reset_password_token 12 | t.datetime :reset_password_sent_at 13 | 14 | ## Rememberable 15 | t.datetime :remember_created_at 16 | 17 | ## Trackable 18 | # t.integer :sign_in_count, default: 0, null: false 19 | # t.datetime :current_sign_in_at 20 | # t.datetime :last_sign_in_at 21 | # t.string :current_sign_in_ip 22 | # t.string :last_sign_in_ip 23 | 24 | ## Confirmable 25 | t.string :confirmation_token 26 | t.datetime :confirmed_at 27 | t.datetime :confirmation_sent_at 28 | t.string :unconfirmed_email # Only if using reconfirmable 29 | 30 | ## Lockable 31 | # t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts 32 | # t.string :unlock_token # Only if unlock strategy is :email or :both 33 | # t.datetime :locked_at 34 | 35 | 36 | # Uncomment below if timestamps were not included in your original model. 37 | # t.timestamps null: false 38 | end 39 | 40 | add_index :users, :email, unique: true 41 | add_index :users, :reset_password_token, unique: true 42 | # add_index :users, :confirmation_token, unique: true 43 | # add_index :users, :unlock_token, unique: true 44 | end 45 | 46 | def self.down 47 | # By default, we don't want to make any assumption about how to roll back a migration when your 48 | # model already existed. Please edit below which fields you would like to remove in this migration. 49 | raise ActiveRecord::IrreversibleMigration 50 | end 51 | end 52 | -------------------------------------------------------------------------------- /db/migrate/20230621132536_add_role_to_users.rb: -------------------------------------------------------------------------------- 1 | class AddRoleToUsers < ActiveRecord::Migration[7.0] 2 | def change 3 | add_column :users, :role, :string 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /db/schema.rb: -------------------------------------------------------------------------------- 1 | # This file is auto-generated from the current state of the database. Instead 2 | # of editing this file, please use the migrations feature of Active Record to 3 | # incrementally modify your database, and then regenerate this schema definition. 4 | # 5 | # This file is the source Rails uses to define your schema when running `bin/rails 6 | # db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to 7 | # be faster and is potentially less error prone than running all of your 8 | # migrations from scratch. Old migrations may fail to apply correctly if those 9 | # migrations use external dependencies or application code. 10 | # 11 | # It's strongly recommended that you check this file into your version control system. 12 | 13 | ActiveRecord::Schema[7.0].define(version: 2023_06_21_132536) do 14 | # These are extensions that must be enabled in order to support this database 15 | enable_extension "plpgsql" 16 | 17 | create_table "comments", force: :cascade do |t| 18 | t.string "text" 19 | t.datetime "created_at", null: false 20 | t.datetime "updated_at", null: false 21 | t.bigint "post_id", null: false 22 | t.bigint "user_id", null: false 23 | t.index ["post_id"], name: "index_comments_on_post_id" 24 | t.index ["user_id"], name: "index_comments_on_user_id" 25 | end 26 | 27 | create_table "likes", force: :cascade do |t| 28 | t.datetime "created_at", null: false 29 | t.datetime "updated_at", null: false 30 | t.bigint "user_id", null: false 31 | t.bigint "post_id", null: false 32 | t.index ["post_id"], name: "index_likes_on_post_id" 33 | t.index ["user_id"], name: "index_likes_on_user_id" 34 | end 35 | 36 | create_table "posts", force: :cascade do |t| 37 | t.string "title" 38 | t.string "text" 39 | t.integer "comment_counter" 40 | t.integer "likes_counter" 41 | t.datetime "created_at", null: false 42 | t.datetime "updated_at", null: false 43 | t.bigint "user_id", null: false 44 | t.index ["user_id"], name: "index_posts_on_user_id" 45 | end 46 | 47 | create_table "users", force: :cascade do |t| 48 | t.string "name" 49 | t.string "photo" 50 | t.text "bio" 51 | t.integer "posts_counter" 52 | t.datetime "created_at", null: false 53 | t.datetime "updated_at", null: false 54 | t.string "email", default: "", null: false 55 | t.string "encrypted_password", default: "", null: false 56 | t.string "reset_password_token" 57 | t.datetime "reset_password_sent_at" 58 | t.datetime "remember_created_at" 59 | t.string "confirmation_token" 60 | t.datetime "confirmed_at" 61 | t.datetime "confirmation_sent_at" 62 | t.string "unconfirmed_email" 63 | t.string "role" 64 | t.index ["email"], name: "index_users_on_email", unique: true 65 | t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true 66 | end 67 | 68 | add_foreign_key "comments", "posts" 69 | add_foreign_key "comments", "users" 70 | add_foreign_key "likes", "posts" 71 | add_foreign_key "likes", "users" 72 | add_foreign_key "posts", "users" 73 | end 74 | -------------------------------------------------------------------------------- /db/seeds.rb: -------------------------------------------------------------------------------- 1 | # This file should contain all the record creation needed to seed the database with its default values. 2 | # The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup). 3 | # 4 | # Examples: 5 | # 6 | # movies = Movie.create([{ name: "Star Wars" }, { name: "Lord of the Rings" }]) 7 | # Character.create(name: "Luke", movie: movies.first) 8 | -------------------------------------------------------------------------------- /lib/assets/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lucas-Erkana/Blog_App/bb775c1c27eceb7b8a7dc2aba773a74dc3c49efe/lib/assets/.keep -------------------------------------------------------------------------------- /lib/tasks/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lucas-Erkana/Blog_App/bb775c1c27eceb7b8a7dc2aba773a74dc3c49efe/lib/tasks/.keep -------------------------------------------------------------------------------- /log/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lucas-Erkana/Blog_App/bb775c1c27eceb7b8a7dc2aba773a74dc3c49efe/log/.keep -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "devDependencies": { 3 | "stylelint": "^13.13.1", 4 | "stylelint-config-standard": "^21.0.0", 5 | "stylelint-csstree-validator": "^1.9.0", 6 | "stylelint-scss": "^3.21.0" 7 | }, 8 | "name": "blog_app", 9 | "description": "\r

Blog App

", 10 | "version": "1.0.0", 11 | "main": "index.js", 12 | "directories": { 13 | "lib": "lib", 14 | "test": "test" 15 | }, 16 | "dependencies": { 17 | "ajv": "^8.12.0", 18 | "ansi-regex": "^5.0.1", 19 | "ansi-styles": "^4.3.0", 20 | "array-union": "^2.1.0", 21 | "arrify": "^1.0.1", 22 | "astral-regex": "^2.0.0", 23 | "autoprefixer": "^9.8.8", 24 | "bail": "^1.0.5", 25 | "balanced-match": "^2.0.0", 26 | "brace-expansion": "^1.1.11", 27 | "braces": "^3.0.2", 28 | "browserslist": "^4.21.9", 29 | "callsites": "^3.1.0", 30 | "camelcase": "^5.3.1", 31 | "camelcase-keys": "^6.2.2", 32 | "caniuse-lite": "^1.0.30001503", 33 | "chalk": "^4.1.2", 34 | "character-entities": "^1.2.4", 35 | "character-entities-legacy": "^1.1.4", 36 | "character-reference-invalid": "^1.1.4", 37 | "clone-regexp": "^2.2.0", 38 | "color-convert": "^2.0.1", 39 | "color-name": "^1.1.4", 40 | "concat-map": "^0.0.1", 41 | "convert-source-map": "^1.9.0", 42 | "cosmiconfig": "^7.1.0", 43 | "css-tree": "^1.1.3", 44 | "cssesc": "^3.0.0", 45 | "debug": "^4.3.4", 46 | "decamelize": "^1.2.0", 47 | "decamelize-keys": "^1.1.1", 48 | "dir-glob": "^3.0.1", 49 | "dom-serializer": "^0.2.2", 50 | "domelementtype": "^1.3.1", 51 | "domhandler": "^2.4.2", 52 | "domutils": "^1.7.0", 53 | "electron-to-chromium": "^1.4.432", 54 | "emoji-regex": "^8.0.0", 55 | "entities": "^1.1.2", 56 | "error-ex": "^1.3.2", 57 | "escalade": "^3.1.1", 58 | "escape-string-regexp": "^1.0.5", 59 | "execall": "^2.0.0", 60 | "extend": "^3.0.2", 61 | "fast-deep-equal": "^3.1.3", 62 | "fast-glob": "^3.2.12", 63 | "fastest-levenshtein": "^1.0.16", 64 | "fastq": "^1.15.0", 65 | "file-entry-cache": "^6.0.1", 66 | "fill-range": "^7.0.1", 67 | "find-up": "^4.1.0", 68 | "flat-cache": "^3.0.4", 69 | "flatted": "^3.2.7", 70 | "fs.realpath": "^1.0.0", 71 | "function-bind": "^1.1.1", 72 | "gensync": "^1.0.0-beta.2", 73 | "get-stdin": "^8.0.0", 74 | "glob": "^7.2.3", 75 | "glob-parent": "^5.1.2", 76 | "global-modules": "^2.0.0", 77 | "global-prefix": "^3.0.0", 78 | "globals": "^11.12.0", 79 | "globby": "^11.1.0", 80 | "globjoin": "^0.1.4", 81 | "gonzales-pe": "^4.3.0", 82 | "hard-rejection": "^2.1.0", 83 | "has": "^1.0.3", 84 | "has-flag": "^4.0.0", 85 | "hosted-git-info": "^4.1.0", 86 | "html-tags": "^3.3.1", 87 | "htmlparser2": "^3.10.1", 88 | "ignore": "^5.2.4", 89 | "import-fresh": "^3.3.0", 90 | "import-lazy": "^4.0.0", 91 | "imurmurhash": "^0.1.4", 92 | "indent-string": "^4.0.0", 93 | "inflight": "^1.0.6", 94 | "inherits": "^2.0.4", 95 | "ini": "^1.3.8", 96 | "is-alphabetical": "^1.0.4", 97 | "is-alphanumerical": "^1.0.4", 98 | "is-arrayish": "^0.2.1", 99 | "is-buffer": "^2.0.5", 100 | "is-core-module": "^2.12.1", 101 | "is-decimal": "^1.0.4", 102 | "is-extglob": "^2.1.1", 103 | "is-fullwidth-code-point": "^3.0.0", 104 | "is-glob": "^4.0.3", 105 | "is-hexadecimal": "^1.0.4", 106 | "is-number": "^7.0.0", 107 | "is-plain-obj": "^1.1.0", 108 | "is-regexp": "^2.1.0", 109 | "is-typedarray": "^1.0.0", 110 | "is-unicode-supported": "^0.1.0", 111 | "isexe": "^2.0.0", 112 | "js-tokens": "^4.0.0", 113 | "jsesc": "^2.5.2", 114 | "json-parse-even-better-errors": "^2.3.1", 115 | "json-schema-traverse": "^1.0.0", 116 | "json5": "^2.2.3", 117 | "kind-of": "^6.0.3", 118 | "known-css-properties": "^0.21.0", 119 | "lines-and-columns": "^1.2.4", 120 | "locate-path": "^5.0.0", 121 | "lodash": "^4.17.21", 122 | "lodash.truncate": "^4.4.2", 123 | "log-symbols": "^4.1.0", 124 | "longest-streak": "^2.0.4", 125 | "lru-cache": "^5.1.1", 126 | "map-obj": "^4.3.0", 127 | "mathml-tag-names": "^2.1.3", 128 | "mdast-util-from-markdown": "^0.8.5", 129 | "mdast-util-to-markdown": "^0.6.5", 130 | "mdast-util-to-string": "^2.0.0", 131 | "mdn-data": "^2.0.14", 132 | "meow": "^9.0.0", 133 | "merge2": "^1.4.1", 134 | "micromark": "^2.11.4", 135 | "micromatch": "^4.0.5", 136 | "min-indent": "^1.0.1", 137 | "minimatch": "^3.1.2", 138 | "minimist": "^1.2.8", 139 | "minimist-options": "^4.1.0", 140 | "ms": "^2.1.2", 141 | "node-releases": "^2.0.12", 142 | "normalize-package-data": "^3.0.3", 143 | "normalize-range": "^0.1.2", 144 | "normalize-selector": "^0.2.0", 145 | "num2fraction": "^1.2.2", 146 | "once": "^1.4.0", 147 | "p-limit": "^2.3.0", 148 | "p-locate": "^4.1.0", 149 | "p-try": "^2.2.0", 150 | "parent-module": "^1.0.1", 151 | "parse-entities": "^2.0.0", 152 | "parse-json": "^5.2.0", 153 | "path-exists": "^4.0.0", 154 | "path-is-absolute": "^1.0.1", 155 | "path-parse": "^1.0.7", 156 | "path-type": "^4.0.0", 157 | "picocolors": "^0.2.1", 158 | "picomatch": "^2.3.1", 159 | "postcss": "^7.0.39", 160 | "postcss-html": "^0.36.0", 161 | "postcss-less": "^3.1.4", 162 | "postcss-media-query-parser": "^0.2.3", 163 | "postcss-resolve-nested-selector": "^0.1.1", 164 | "postcss-safe-parser": "^4.0.2", 165 | "postcss-sass": "^0.4.4", 166 | "postcss-scss": "^2.1.1", 167 | "postcss-selector-parser": "^6.0.13", 168 | "postcss-syntax": "^0.36.2", 169 | "postcss-value-parser": "^4.2.0", 170 | "punycode": "^2.3.0", 171 | "queue-microtask": "^1.2.3", 172 | "quick-lru": "^4.0.1", 173 | "read-pkg": "^5.2.0", 174 | "read-pkg-up": "^7.0.1", 175 | "readable-stream": "^3.6.2", 176 | "redent": "^3.0.0", 177 | "remark": "^13.0.0", 178 | "remark-parse": "^9.0.0", 179 | "remark-stringify": "^9.0.1", 180 | "repeat-string": "^1.6.1", 181 | "require-from-string": "^2.0.2", 182 | "resolve": "^1.22.2", 183 | "resolve-from": "^5.0.0", 184 | "reusify": "^1.0.4", 185 | "rimraf": "^3.0.2", 186 | "run-parallel": "^1.2.0", 187 | "safe-buffer": "^5.2.1", 188 | "semver": "^6.3.0", 189 | "signal-exit": "^3.0.7", 190 | "slash": "^3.0.0", 191 | "slice-ansi": "^4.0.0", 192 | "source-map": "^0.6.1", 193 | "spdx-correct": "^3.2.0", 194 | "spdx-exceptions": "^2.3.0", 195 | "spdx-expression-parse": "^3.0.1", 196 | "spdx-license-ids": "^3.0.13", 197 | "specificity": "^0.4.1", 198 | "string-width": "^4.2.3", 199 | "string_decoder": "^1.3.0", 200 | "strip-ansi": "^6.0.1", 201 | "strip-indent": "^3.0.0", 202 | "style-search": "^0.1.0", 203 | "stylelint-config-recommended": "^4.0.0", 204 | "sugarss": "^2.0.0", 205 | "supports-color": "^7.2.0", 206 | "supports-preserve-symlinks-flag": "^1.0.0", 207 | "svg-tags": "^1.0.0", 208 | "table": "^6.8.1", 209 | "to-fast-properties": "^2.0.0", 210 | "to-regex-range": "^5.0.1", 211 | "trim-newlines": "^3.0.1", 212 | "trough": "^1.0.5", 213 | "type-fest": "^0.18.1", 214 | "typedarray-to-buffer": "^3.1.5", 215 | "unified": "^9.2.2", 216 | "unist-util-find-all-after": "^3.0.2", 217 | "unist-util-is": "^4.1.0", 218 | "unist-util-stringify-position": "^2.0.3", 219 | "update-browserslist-db": "^1.0.11", 220 | "uri-js": "^4.4.1", 221 | "util-deprecate": "^1.0.2", 222 | "v8-compile-cache": "^2.3.0", 223 | "validate-npm-package-license": "^3.0.4", 224 | "vfile": "^4.2.1", 225 | "vfile-message": "^2.0.4", 226 | "which": "^1.3.1", 227 | "wrappy": "^1.0.2", 228 | "write-file-atomic": "^3.0.3", 229 | "yallist": "^3.1.1", 230 | "yaml": "^1.10.2", 231 | "yargs-parser": "^20.2.9", 232 | "zwitch": "^1.0.5" 233 | }, 234 | "scripts": { 235 | "test": "echo \"Error: no test specified\" && exit 1" 236 | }, 237 | "keywords": [], 238 | "author": "", 239 | "license": "ISC" 240 | } 241 | -------------------------------------------------------------------------------- /public/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The page you were looking for doesn't exist (404) 5 | 6 | 55 | 56 | 57 | 58 | 59 |
60 |
61 |

The page you were looking for doesn't exist.

62 |

You may have mistyped the address or the page may have moved.

63 |
64 |

If you are the application owner check the logs for more information.

65 |
66 | 67 | 68 | -------------------------------------------------------------------------------- /public/422.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The change you wanted was rejected (422) 5 | 6 | 55 | 56 | 57 | 58 | 59 |
60 |
61 |

The change you wanted was rejected.

62 |

Maybe you tried to change something you didn't have access to.

63 |
64 |

If you are the application owner check the logs for more information.

65 |
66 | 67 | 68 | -------------------------------------------------------------------------------- /public/500.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | We're sorry, but something went wrong (500) 5 | 6 | 55 | 56 | 57 | 58 | 59 |
60 |
61 |

We're sorry, but something went wrong.

62 |
63 |

If you are the application owner check the logs for more information.

64 |
65 | 66 | 67 | -------------------------------------------------------------------------------- /public/apple-touch-icon-precomposed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lucas-Erkana/Blog_App/bb775c1c27eceb7b8a7dc2aba773a74dc3c49efe/public/apple-touch-icon-precomposed.png -------------------------------------------------------------------------------- /public/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lucas-Erkana/Blog_App/bb775c1c27eceb7b8a7dc2aba773a74dc3c49efe/public/apple-touch-icon.png -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lucas-Erkana/Blog_App/bb775c1c27eceb7b8a7dc2aba773a74dc3c49efe/public/favicon.ico -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # See https://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file 2 | -------------------------------------------------------------------------------- /spec/helpers/api/api_helper_spec.rb: -------------------------------------------------------------------------------- 1 | require 'rails_helper' 2 | 3 | # Specs in this file have access to a helper object that includes 4 | # the Api::ApiHelper. For example: 5 | # 6 | # describe Api::ApiHelper do 7 | # describe "string concat" do 8 | # it "concats two strings with spaces" do 9 | # expect(helper.concat_strings("this","that")).to eq("this that") 10 | # end 11 | # end 12 | # end 13 | RSpec.describe Api::ApiHelper, type: :helper do 14 | pending "add some examples to (or delete) #{__FILE__}" 15 | end 16 | -------------------------------------------------------------------------------- /spec/helpers/api/comments_helper_spec.rb: -------------------------------------------------------------------------------- 1 | require 'rails_helper' 2 | 3 | # Specs in this file have access to a helper object that includes 4 | # the Api::CommentsHelper. For example: 5 | # 6 | # describe Api::CommentsHelper do 7 | # describe "string concat" do 8 | # it "concats two strings with spaces" do 9 | # expect(helper.concat_strings("this","that")).to eq("this that") 10 | # end 11 | # end 12 | # end 13 | RSpec.describe Api::CommentsHelper, type: :helper do 14 | pending "add some examples to (or delete) #{__FILE__}" 15 | end 16 | -------------------------------------------------------------------------------- /spec/helpers/api/posts_helper_spec.rb: -------------------------------------------------------------------------------- 1 | require 'rails_helper' 2 | 3 | # Specs in this file have access to a helper object that includes 4 | # the Api::PostsHelper. For example: 5 | # 6 | # describe Api::PostsHelper do 7 | # describe "string concat" do 8 | # it "concats two strings with spaces" do 9 | # expect(helper.concat_strings("this","that")).to eq("this that") 10 | # end 11 | # end 12 | # end 13 | RSpec.describe Api::PostsHelper, type: :helper do 14 | pending "add some examples to (or delete) #{__FILE__}" 15 | end 16 | -------------------------------------------------------------------------------- /spec/helpers/comment_helper_spec.rb: -------------------------------------------------------------------------------- 1 | require 'rails_helper' 2 | 3 | # Specs in this file have access to a helper object that includes 4 | # the CommentHelper. For example: 5 | # 6 | # describe CommentHelper do 7 | # describe "string concat" do 8 | # it "concats two strings with spaces" do 9 | # expect(helper.concat_strings("this","that")).to eq("this that") 10 | # end 11 | # end 12 | # end 13 | RSpec.describe CommentHelper, type: :helper do 14 | pending "add some examples to (or delete) #{__FILE__}" 15 | end 16 | -------------------------------------------------------------------------------- /spec/helpers/likes_helper_spec.rb: -------------------------------------------------------------------------------- 1 | require 'rails_helper' 2 | 3 | # Specs in this file have access to a helper object that includes 4 | # the LikesHelper. For example: 5 | # 6 | # describe LikesHelper do 7 | # describe "string concat" do 8 | # it "concats two strings with spaces" do 9 | # expect(helper.concat_strings("this","that")).to eq("this that") 10 | # end 11 | # end 12 | # end 13 | RSpec.describe LikesHelper, type: :helper do 14 | pending "add some examples to (or delete) #{__FILE__}" 15 | end 16 | -------------------------------------------------------------------------------- /spec/helpers/posts_helper_spec.rb: -------------------------------------------------------------------------------- 1 | require 'rails_helper' 2 | 3 | # Specs in this file have access to a helper object that includes 4 | # the PostsHelper. For example: 5 | # 6 | # describe PostsHelper do 7 | # describe "string concat" do 8 | # it "concats two strings with spaces" do 9 | # expect(helper.concat_strings("this","that")).to eq("this that") 10 | # end 11 | # end 12 | # end 13 | RSpec.describe PostsHelper, type: :helper do 14 | pending "add some examples to (or delete) #{__FILE__}" 15 | end 16 | -------------------------------------------------------------------------------- /spec/models/comment_spec.rb: -------------------------------------------------------------------------------- 1 | require 'rails_helper' 2 | 3 | RSpec.describe Comment, type: :model do 4 | describe 'validation' do 5 | subject { Comment.new(text: 'Nice') } 6 | 7 | before { subject.save } 8 | 9 | it 'Comments text should contain text' do 10 | subject.text = nil 11 | expect(subject).to_not be_valid 12 | end 13 | end 14 | 15 | describe 'Functionality' do 16 | let(:user) do 17 | User.create( 18 | name: 'John Doe', 19 | photo: 'https://upload.wikimedia.org/wikipedia/commons/a/ac/Default_pfp.jpg', 20 | bio: 'Hello I am a test user', 21 | posts_counter: 0 22 | ) 23 | end 24 | 25 | let(:post) do 26 | Post.create( 27 | title: 'Test Post', 28 | text: 'This is a test post', 29 | user:, 30 | comment_counter: 0, 31 | likes_counter: 0 32 | ) 33 | end 34 | 35 | subject do 36 | Comment.new( 37 | text: 'This is a test comment', 38 | user:, 39 | post: 40 | ) 41 | end 42 | 43 | describe 'Functionality' do 44 | it 'updates the comments_counter of the post after saving' do 45 | expect { subject.save }.to change { post.comment_counter }.by(1) 46 | end 47 | end 48 | end 49 | end 50 | -------------------------------------------------------------------------------- /spec/models/like_spec.rb: -------------------------------------------------------------------------------- 1 | require 'rails_helper' 2 | 3 | RSpec.describe Like, type: :model do 4 | describe 'validation' do 5 | subject { Like.new } 6 | 7 | before { subject.save } 8 | 9 | it 'likes text should contain text' do 10 | expect(subject).to_not be_valid 11 | end 12 | end 13 | 14 | describe 'Functionality' do 15 | let(:user) do 16 | User.create( 17 | name: 'John Doe', 18 | photo: 'https://upload.wikimedia.org/wikipedia/commons/a/ac/Default_pfp.jpg', 19 | bio: 'Hello I am a test user', 20 | posts_counter: 0 21 | ) 22 | end 23 | 24 | let(:post) do 25 | Post.create( 26 | title: 'Test Post', 27 | text: 'This is a test post', 28 | user:, 29 | comment_counter: 0, 30 | likes_counter: 0 31 | ) 32 | end 33 | 34 | subject do 35 | Like.new( 36 | user:, 37 | post: 38 | ) 39 | end 40 | 41 | it 'updates the likes_counter of the post after saving' do 42 | expect { subject.save }.to change { post.likes_counter }.by(1) 43 | end 44 | end 45 | end 46 | -------------------------------------------------------------------------------- /spec/models/post_spec.rb: -------------------------------------------------------------------------------- 1 | require_relative '../rails_helper' 2 | 3 | RSpec.describe Post, type: :model do 4 | let(:user) { User.create(name: 'Fuad', posts_counter: 0) } 5 | subject do 6 | Post.new(user_id: user.id, title: 'Hello', text: 'This is my post', comment_counter: 1, likes_counter: 1) 7 | end 8 | 9 | context 'Testing validation' do 10 | it 'Title should be invalid with nil value' do 11 | subject.title = nil 12 | expect(subject).to_not be_valid 13 | end 14 | 15 | it 'Title must not exceed 250 characters' do 16 | expect(subject.title.length).to be <= 250 17 | end 18 | 19 | it 'CommentsCounter must be an integer greater than or equal to zero.' do 20 | subject.comment_counter = -1 21 | expect(subject).to_not be_valid 22 | end 23 | 24 | it 'LikesCounter must be an integer greater than or equal to zero.' do 25 | subject.likes_counter = -1 26 | expect(subject).to_not be_valid 27 | end 28 | 29 | it 'Should update count of posts' do 30 | expect(subject.post_count_updater).to be true 31 | end 32 | end 33 | 34 | describe 'Functionality' do 35 | let(:user) do 36 | User.create( 37 | name: 'John Doe', 38 | photo: 'https://upload.wikimedia.org/wikipedia/commons/a/ac/Default_pfp.jpg', 39 | bio: 'Hello I am a test user', 40 | posts_counter: 0 41 | ) 42 | end 43 | 44 | subject do 45 | Post.new( 46 | title: 'Test Post', 47 | text: 'This is a test post', 48 | user:, 49 | comment_counter: 0, 50 | likes_counter: 0 51 | ) 52 | end 53 | 54 | it 'returns the five most recent comments' do 55 | 10.times do |i| 56 | Comment.create( 57 | text: "This is the text for comment #{i}", 58 | post: subject, 59 | user: 60 | ) 61 | end 62 | 63 | expect(subject.recent_comments.length).to eq(5) 64 | end 65 | 66 | it 'updates the posts_counter of the author after saving' do 67 | expect { subject.save }.to change { user.posts_counter }.by(1) 68 | end 69 | end 70 | end 71 | -------------------------------------------------------------------------------- /spec/models/user_spec.rb: -------------------------------------------------------------------------------- 1 | require_relative '../rails_helper' 2 | 3 | RSpec.describe User, type: :model do 4 | subject do 5 | User.new( 6 | name: 'John Doe', 7 | photo: 'https://upload.wikimedia.org/wikipedia/commons/a/ac/Default_pfp.jpg', 8 | bio: 'Hello I am a test user', 9 | posts_counter: 0 10 | ) 11 | end 12 | 13 | describe 'Validations' do 14 | it 'is valid with valid attributes' do 15 | expect(subject).to be_valid 16 | end 17 | 18 | it 'is not valid without a name' do 19 | subject.name = '' 20 | expect(subject).to_not be_valid 21 | end 22 | 23 | it 'is valid without a photo' do 24 | subject.photo = '' 25 | expect(subject).to be_valid 26 | end 27 | 28 | it 'is not valid when posts_counter is not an integer' do 29 | subject.posts_counter = 'a' 30 | expect(subject).to_not be_valid 31 | end 32 | 33 | it 'is not valid when posts_counter is less than 0' do 34 | subject.posts_counter = -1 35 | expect(subject).to_not be_valid 36 | end 37 | end 38 | end 39 | 40 | context 'Testing behavior' do 41 | subject do 42 | User.new( 43 | name: 'John Doe', 44 | photo: 'https://upload.wikimedia.org/wikipedia/commons/a/ac/Default_pfp.jpg', 45 | bio: 'Hello I am a test user', 46 | posts_counter: 0 47 | ) 48 | end 49 | 50 | before do 51 | 10.times do |i| 52 | Post.create( 53 | title: "Post #{i}", 54 | text: "This is the text for post #{i}", 55 | user: subject, # Assign the user instance to the user attribute 56 | comment_counter: 0, 57 | likes_counter: 0 58 | ) 59 | end 60 | end 61 | 62 | it 'lists the most recent 3 posts' do 63 | expect(subject.recent_post.length).to eq(3) 64 | end 65 | end 66 | -------------------------------------------------------------------------------- /spec/rails_helper.rb: -------------------------------------------------------------------------------- 1 | # This file is copied to spec/ when you run 'rails generate rspec:install' 2 | require 'spec_helper' 3 | ENV['RAILS_ENV'] ||= 'test' 4 | require_relative '../config/environment' 5 | # Prevent database truncation if the environment is production 6 | abort('The Rails environment is running in production mode!') if Rails.env.production? 7 | require 'rspec/rails' 8 | # Add additional requires below this line. Rails is not loaded until this point! 9 | 10 | # Requires supporting ruby files with custom matchers and macros, etc, in 11 | # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are 12 | # run as spec files by default. This means that files in spec/support that end 13 | # in _spec.rb will both be required and run as specs, causing the specs to be 14 | # run twice. It is recommended that you do not name files matching this glob to 15 | # end with _spec.rb. You can configure this pattern with the --pattern 16 | # option on the command line or in ~/.rspec, .rspec or `.rspec-local`. 17 | # 18 | # The following line is provided for convenience purposes. It has the downside 19 | # of increasing the boot-up time by auto-requiring all files in the support 20 | # directory. Alternatively, in the individual `*_spec.rb` files, manually 21 | # require only the support files necessary. 22 | # 23 | # Dir[Rails.root.join('spec', 'support', '**', '*.rb')].sort.each { |f| require f } 24 | 25 | # Checks for pending migrations and applies them before tests are run. 26 | # If you are not using ActiveRecord, you can remove these lines. 27 | begin 28 | ActiveRecord::Migration.maintain_test_schema! 29 | rescue ActiveRecord::PendingMigrationError => e 30 | abort e.to_s.strip 31 | end 32 | RSpec.configure do |config| 33 | # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures 34 | config.fixture_path = "#{Rails.root}/spec/fixtures" 35 | 36 | # If you're not using ActiveRecord, or you'd prefer not to run each of your 37 | # examples within a transaction, remove the following line or assign false 38 | # instead of true. 39 | config.use_transactional_fixtures = true 40 | 41 | # You can uncomment this line to turn off ActiveRecord support entirely. 42 | # config.use_active_record = false 43 | 44 | # RSpec Rails can automatically mix in different behaviours to your tests 45 | # based on their file location, for example enabling you to call `get` and 46 | # `post` in specs under `spec/controllers`. 47 | # 48 | # You can disable this behaviour by removing the line below, and instead 49 | # explicitly tag your specs with their type, e.g.: 50 | # 51 | # RSpec.describe UsersController, type: :controller do 52 | # # ... 53 | # end 54 | # 55 | # The different available types are documented in the features, such as in 56 | # https://rspec.info/features/6-0/rspec-rails 57 | config.infer_spec_type_from_file_location! 58 | 59 | # Filter lines from Rails gems in backtraces. 60 | config.filter_rails_from_backtrace! 61 | # arbitrary gems may also be filtered via: 62 | # config.filter_gems_from_backtrace("gem name") 63 | end 64 | -------------------------------------------------------------------------------- /spec/requests/api/api_spec.rb: -------------------------------------------------------------------------------- 1 | require 'rails_helper' 2 | 3 | RSpec.describe 'Api::Apis', type: :request do 4 | describe 'GET /index' do 5 | pending "add some examples (or delete) #{__FILE__}" 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /spec/requests/api/comments_spec.rb: -------------------------------------------------------------------------------- 1 | require 'rails_helper' 2 | 3 | RSpec.describe 'Api::Comments', type: :request do 4 | describe 'GET /index' do 5 | pending "add some examples (or delete) #{__FILE__}" 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /spec/requests/api/posts_spec.rb: -------------------------------------------------------------------------------- 1 | require 'rails_helper' 2 | 3 | RSpec.describe 'Api::Posts', type: :request do 4 | describe 'GET /index' do 5 | pending "add some examples (or delete) #{__FILE__}" 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /spec/requests/posts_spec.rb: -------------------------------------------------------------------------------- 1 | require 'rails_helper' 2 | 3 | RSpec.describe 'Posts', type: :request do 4 | describe 'GET /users/:user_id/posts' do 5 | let(:user) { User.create(name: 'Stella', photo: 'https://unsplash.com/photos/F_-0BxGuVvo', bio: 'Teacher from Rusia.', posts_counter: 0) } 6 | 7 | it 'returns a success response' do 8 | get user_posts_path(user) 9 | expect(response).to have_http_status(:success) 10 | end 11 | 12 | it 'renders the index template' do 13 | get user_posts_path(user) 14 | expect(response).to render_template(:index) 15 | end 16 | 17 | it 'includes correct placeholder text in the response body' do 18 | get user_posts_path(user) 19 | expect(response.body).to include('Here is a list of posts for a given user') 20 | end 21 | end 22 | 23 | describe 'GET /users/:user_id/posts/:id' do 24 | let(:user) { User.create(name: 'Stella', photo: 'https://unsplash.com/photos/F_-0BxGuVvo', bio: 'Teacher from Rusia.', posts_counter: 0) } 25 | let(:post) do 26 | Post.create(title: 'Sample Post', text: 'My first post', comment_counter: 0, likes_counter: 0, user:) 27 | end 28 | 29 | it 'returns a success response' do 30 | get user_post_path(user, post) 31 | expect(response).to have_http_status(:success) 32 | end 33 | 34 | it 'renders the show template' do 35 | get user_post_path(user, post) 36 | expect(response).to render_template(:show) 37 | end 38 | 39 | it 'includes correct placeholder text in the response body' do 40 | get user_post_path(user, post) 41 | expect(response.body).to include('Here is a given post for a specific user') 42 | end 43 | end 44 | end 45 | -------------------------------------------------------------------------------- /spec/requests/users_spec.rb: -------------------------------------------------------------------------------- 1 | require 'rails_helper' 2 | 3 | RSpec.describe 'Users', type: :request do 4 | describe 'GET /index' do 5 | it 'returns a success response' do 6 | get users_path 7 | expect(response).to have_http_status(:success) 8 | end 9 | 10 | it 'renders the index template' do 11 | get users_path 12 | expect(response).to render_template(:index) 13 | end 14 | 15 | it 'includes correct placeholder text in the response body' do 16 | get users_path 17 | expect(response.body).to include('List of all the users') 18 | end 19 | end 20 | 21 | describe 'GET /users/:id' do 22 | let(:user) { User.create(name: 'Stella', photo: 'https://unsplash.com/photos/F_-0BxGuVvo', bio: 'Teacher from Rusia.', posts_counter: 0) } 23 | 24 | it 'returns a success response' do 25 | get user_path(user) 26 | expect(response).to have_http_status(:success) 27 | end 28 | 29 | it 'renders the show template' do 30 | get user_path(user) 31 | expect(response).to render_template(:show) 32 | end 33 | 34 | it 'includes correct placeholder text in the response body' do 35 | get user_path(user) 36 | expect(response.body).to include('User details') 37 | end 38 | end 39 | end 40 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | # This file was generated by the `rails generate rspec:install` command. Conventionally, all 2 | # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. 3 | # The generated `.rspec` file contains `--require spec_helper` which will cause 4 | # this file to always be loaded, without a need to explicitly require it in any 5 | # files. 6 | # 7 | # Given that it is always loaded, you are encouraged to keep this file as 8 | # light-weight as possible. Requiring heavyweight dependencies from this file 9 | # will add to the boot time of your test suite on EVERY test run, even for an 10 | # individual file that may not need all of that loaded. Instead, consider making 11 | # a separate helper file that requires the additional dependencies and performs 12 | # the additional setup, and require it from the spec files that actually need 13 | # it. 14 | # 15 | # See https://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration 16 | RSpec.configure do |config| 17 | # rspec-expectations config goes here. You can use an alternate 18 | # assertion/expectation library such as wrong or the stdlib/minitest 19 | # assertions if you prefer. 20 | config.expect_with :rspec do |expectations| 21 | # This option will default to `true` in RSpec 4. It makes the `description` 22 | # and `failure_message` of custom matchers include text for helper methods 23 | # defined using `chain`, e.g.: 24 | # be_bigger_than(2).and_smaller_than(4).description 25 | # # => "be bigger than 2 and smaller than 4" 26 | # ...rather than: 27 | # # => "be bigger than 2" 28 | expectations.include_chain_clauses_in_custom_matcher_descriptions = true 29 | end 30 | 31 | # rspec-mocks config goes here. You can use an alternate test double 32 | # library (such as bogus or mocha) by changing the `mock_with` option here. 33 | config.mock_with :rspec do |mocks| 34 | # Prevents you from mocking or stubbing a method that does not exist on 35 | # a real object. This is generally recommended, and will default to 36 | # `true` in RSpec 4. 37 | mocks.verify_partial_doubles = true 38 | end 39 | 40 | # This option will default to `:apply_to_host_groups` in RSpec 4 (and will 41 | # have no way to turn it off -- the option exists only for backwards 42 | # compatibility in RSpec 3). It causes shared context metadata to be 43 | # inherited by the metadata hash of host groups and examples, rather than 44 | # triggering implicit auto-inclusion in groups with matching metadata. 45 | config.shared_context_metadata_behavior = :apply_to_host_groups 46 | 47 | # The settings below are suggested to provide a good initial experience 48 | # with RSpec, but feel free to customize to your heart's content. 49 | # # This allows you to limit a spec run to individual examples or groups 50 | # # you care about by tagging them with `:focus` metadata. When nothing 51 | # # is tagged with `:focus`, all examples get run. RSpec also provides 52 | # # aliases for `it`, `describe`, and `context` that include `:focus` 53 | # # metadata: `fit`, `fdescribe` and `fcontext`, respectively. 54 | # config.filter_run_when_matching :focus 55 | # 56 | # # Allows RSpec to persist some state between runs in order to support 57 | # # the `--only-failures` and `--next-failure` CLI options. We recommend 58 | # # you configure your source control system to ignore this file. 59 | # config.example_status_persistence_file_path = "spec/examples.txt" 60 | # 61 | # # Limits the available syntax to the non-monkey patched syntax that is 62 | # # recommended. For more details, see: 63 | # # https://rspec.info/features/3-12/rspec-core/configuration/zero-monkey-patching-mode/ 64 | # config.disable_monkey_patching! 65 | # 66 | # # This setting enables warnings. It's recommended, but in some cases may 67 | # # be too noisy due to issues in dependencies. 68 | # config.warnings = true 69 | # 70 | # # Many RSpec users commonly either run the entire suite or an individual 71 | # # file, and it's useful to allow more verbose output when running an 72 | # # individual spec file. 73 | # if config.files_to_run.one? 74 | # # Use the documentation formatter for detailed output, 75 | # # unless a formatter has already been configured 76 | # # (e.g. via a command-line flag). 77 | # config.default_formatter = "doc" 78 | # end 79 | # 80 | # # Print the 10 slowest examples and example groups at the 81 | # # end of the spec run, to help surface which specs are running 82 | # # particularly slow. 83 | # config.profile_examples = 10 84 | # 85 | # # Run specs in random order to surface order dependencies. If you find an 86 | # # order dependency and want to debug it, you can fix the order by providing 87 | # # the seed, which is printed after each run. 88 | # # --seed 1234 89 | # config.order = :random 90 | # 91 | # # Seed global randomization in this process using the `--seed` CLI option. 92 | # # Setting this allows you to use `--seed` to deterministically reproduce 93 | # # test failures related to randomization by passing the same `--seed` value 94 | # # as the one that triggered the failure. 95 | # Kernel.srand config.seed 96 | end 97 | -------------------------------------------------------------------------------- /spec/views_integration/post_spec.rb: -------------------------------------------------------------------------------- 1 | require 'rails_helper' 2 | RSpec.describe Post, type: :system do 3 | user = User.create(name: 'Anna', posts_counter: 3, photo: 'https://randomuser.me/api/portraits/women/67.jpg', 4 | bio: 'Project manager') 5 | subject do 6 | Post.new(user_id: user.id, title: 'First post', text: 'First post', comment_counter: 2, likes_counter: 2) 7 | end 8 | before { subject.save } 9 | describe 'Post index page' do 10 | it "I can see the user's profile picture." do 11 | visit user_posts_path(user.id) 12 | page.has_css?('.img-fluid') 13 | end 14 | it "I can see the user's username." do 15 | visit user_posts_path(user.id) 16 | page.has_content?(user.name) 17 | end 18 | it 'I can see the number of posts the user has written.' do 19 | visit user_posts_path(user.id) 20 | page.has_content?(user.posts_counter) 21 | end 22 | it "I can see a post's title." do 23 | visit user_posts_path(user.id) 24 | page.has_content?(subject.title) 25 | end 26 | it "I can see some of the post's body." do 27 | visit user_posts_path(user.id) 28 | page.has_content?(subject.text) 29 | end 30 | it 'I can see the first comments on a post.' do 31 | comment = Comment.new(user_id: user.id, post_id: subject.id, text: 'I like it') 32 | visit user_posts_path(user.id) 33 | page.has_content?(comment.text) 34 | end 35 | it 'I can see how many comments a post has.' do 36 | visit user_posts_path(user.id) 37 | page.has_content?(subject.comment_counter) 38 | end 39 | it 'When I click on a post, it redirects me to that posts show page.' do 40 | visit user_posts_path(user.id) 41 | click_on 'First post' 42 | visit user_post_path(user.id, subject.id) 43 | page.has_content?(subject.title) 44 | end 45 | end 46 | describe 'Post show page' do 47 | it "I can see a post's title." do 48 | visit user_post_path(user.id, subject.id) 49 | page.has_content?(subject.title) 50 | end 51 | it 'I can see who wrote the post.' do 52 | visit user_post_path(user.id, subject.id) 53 | page.has_content?(user.name) 54 | end 55 | it 'I can see how many comments it has.' do 56 | visit user_post_path(user.id, subject.id) 57 | page.has_content?(subject.comment_counter) 58 | end 59 | it 'I can see how many likes it has.' do 60 | visit user_post_path(user.id, subject.id) 61 | page.has_content?(subject.likes_counter) 62 | end 63 | it 'I can see the post body.' do 64 | visit user_post_path(user.id, subject.id) 65 | page.has_content?(subject.text) 66 | end 67 | it 'I can see the username of each commentor.' do 68 | comment = Comment.new(user_id: user.id, post_id: subject.id, text: 'I like it') 69 | visit user_post_path(user.id, subject.id) 70 | page.has_content?(comment.user.name) 71 | end 72 | it 'I can see the comment each commentor left. ' do 73 | comment = Comment.new(user_id: user.id, post_id: subject.id, text: 'I like it') 74 | visit user_post_path(user.id, subject.id) 75 | page.has_content?(comment.text) 76 | end 77 | end 78 | end 79 | -------------------------------------------------------------------------------- /spec/views_integration/user_spec.rb: -------------------------------------------------------------------------------- 1 | require 'rails_helper' 2 | RSpec.describe User, type: :system do 3 | subject { User.new(name: 'Anna', posts_counter: 3, photo: 'https://randomuser.me/api/portraits/women/67.jpg', bio: 'Project manager') } 4 | before { subject.save } 5 | describe 'index page' do 6 | it 'I can see the username of all other users.' do 7 | visit root_path(subject) 8 | page.has_content?(subject.name) 9 | end 10 | it 'I can see the profile picture for each user' do 11 | visit root_path(subject) 12 | page.has_content?(subject.photo) 13 | end 14 | it 'I can see the number of posts each user has written.' do 15 | visit root_path(subject) 16 | page.has_content?(subject.posts_counter) 17 | end 18 | it "When I click on a user, I am redirected to that user's show page." do 19 | user2 = User.create(name: 'Lilly', posts_counter: 2, photo: 'https://randomuser.me/api/portraits/women/70.jpg', 20 | bio: 'Teacher from Poland.') 21 | visit root_path(user2) 22 | click_on 'Lilly' 23 | expect(page).to have_current_path("/users/#{user2.id}") 24 | end 25 | end 26 | describe 'User show page' do 27 | it "I can see the user's profile picture." do 28 | visit user_path(subject.id) 29 | page.has_css?('.img-fluid') 30 | end 31 | it "I can see the user's username." do 32 | visit user_path(subject.id) 33 | page.has_content?(subject.name) 34 | end 35 | it 'I can see the number of posts the user has written.' do 36 | visit user_path(subject.id) 37 | page.has_content?(subject.posts_counter) 38 | end 39 | it "I can see the user's bio." do 40 | visit user_path(subject.id) 41 | page.has_content?(subject.bio) 42 | end 43 | it "I can see the user's first 3 posts." do 44 | Post.create( 45 | [ 46 | { 47 | user: subject, title: 'First Post', text: 'My first post' 48 | }, 49 | { 50 | user: subject, title: 'Second Post', text: 'My Second post' 51 | }, 52 | { 53 | user: subject, title: 'Third Post', text: 'My Third post' 54 | } 55 | ] 56 | ) 57 | visit user_path(subject.id) 58 | page.has_content?(subject.posts) 59 | end 60 | it "I can see a button that lets me view all of a user's posts." do 61 | visit user_path(subject.id) 62 | page.has_button?('See all posts') 63 | end 64 | it "When I click to see all posts, it redirects me to the user's post's index page." do 65 | visit user_path(subject.id) 66 | click_on 'See all posts' 67 | expect(page).to have_current_path("/users/#{subject.id}/posts") 68 | end 69 | end 70 | end 71 | -------------------------------------------------------------------------------- /storage/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lucas-Erkana/Blog_App/bb775c1c27eceb7b8a7dc2aba773a74dc3c49efe/storage/.keep -------------------------------------------------------------------------------- /test/application_system_test_case.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class ApplicationSystemTestCase < ActionDispatch::SystemTestCase 4 | driven_by :selenium, using: :chrome, screen_size: [1400, 1400] 5 | end 6 | -------------------------------------------------------------------------------- /test/channels/application_cable/connection_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class ApplicationCable::ConnectionTest < ActionCable::Connection::TestCase 4 | # test "connects with cookies" do 5 | # cookies.signed[:user_id] = 42 6 | # 7 | # connect 8 | # 9 | # assert_equal connection.user_id, "42" 10 | # end 11 | end 12 | -------------------------------------------------------------------------------- /test/controllers/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lucas-Erkana/Blog_App/bb775c1c27eceb7b8a7dc2aba773a74dc3c49efe/test/controllers/.keep -------------------------------------------------------------------------------- /test/fixtures/files/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lucas-Erkana/Blog_App/bb775c1c27eceb7b8a7dc2aba773a74dc3c49efe/test/fixtures/files/.keep -------------------------------------------------------------------------------- /test/helpers/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lucas-Erkana/Blog_App/bb775c1c27eceb7b8a7dc2aba773a74dc3c49efe/test/helpers/.keep -------------------------------------------------------------------------------- /test/integration/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lucas-Erkana/Blog_App/bb775c1c27eceb7b8a7dc2aba773a74dc3c49efe/test/integration/.keep -------------------------------------------------------------------------------- /test/mailers/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lucas-Erkana/Blog_App/bb775c1c27eceb7b8a7dc2aba773a74dc3c49efe/test/mailers/.keep -------------------------------------------------------------------------------- /test/models/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lucas-Erkana/Blog_App/bb775c1c27eceb7b8a7dc2aba773a74dc3c49efe/test/models/.keep -------------------------------------------------------------------------------- /test/system/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lucas-Erkana/Blog_App/bb775c1c27eceb7b8a7dc2aba773a74dc3c49efe/test/system/.keep -------------------------------------------------------------------------------- /test/test_helper.rb: -------------------------------------------------------------------------------- 1 | ENV['RAILS_ENV'] ||= 'test' 2 | require_relative '../config/environment' 3 | require 'rails/test_help' 4 | 5 | class ActiveSupport::TestCase 6 | # Run tests in parallel with specified workers 7 | parallelize(workers: :number_of_processors, with: :threads) 8 | 9 | # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. 10 | fixtures :all 11 | 12 | # Add more helper methods to be used by all tests here... 13 | end 14 | -------------------------------------------------------------------------------- /tmp/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lucas-Erkana/Blog_App/bb775c1c27eceb7b8a7dc2aba773a74dc3c49efe/tmp/.keep -------------------------------------------------------------------------------- /tmp/pids/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lucas-Erkana/Blog_App/bb775c1c27eceb7b8a7dc2aba773a74dc3c49efe/tmp/pids/.keep -------------------------------------------------------------------------------- /tmp/storage/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lucas-Erkana/Blog_App/bb775c1c27eceb7b8a7dc2aba773a74dc3c49efe/tmp/storage/.keep -------------------------------------------------------------------------------- /vendor/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lucas-Erkana/Blog_App/bb775c1c27eceb7b8a7dc2aba773a74dc3c49efe/vendor/.keep -------------------------------------------------------------------------------- /vendor/javascript/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lucas-Erkana/Blog_App/bb775c1c27eceb7b8a7dc2aba773a74dc3c49efe/vendor/javascript/.keep --------------------------------------------------------------------------------