├── .gitignore ├── .rspec ├── .rubocop.yml ├── .ruby-version ├── .stickler.yml ├── :environment ├── Gemfile ├── Gemfile.lock ├── LICENSE ├── Procfile ├── README.md ├── Rakefile ├── app ├── assets │ ├── config │ │ └── manifest.js │ ├── images │ │ ├── .keep │ │ ├── default_avatar.png │ │ ├── fb.png │ │ └── screenshot.png │ ├── javascripts │ │ ├── application.js │ │ ├── cable.js │ │ ├── channels │ │ │ └── .keep │ │ ├── likes.coffee │ │ └── users.coffee │ └── stylesheets │ │ ├── application.scss │ │ ├── likes.scss │ │ └── users.scss ├── channels │ └── application_cable │ │ ├── channel.rb │ │ └── connection.rb ├── controllers │ ├── application_controller.rb │ ├── comments_controller.rb │ ├── concerns │ │ └── .keep │ ├── friendships_controller.rb │ ├── likes_controller.rb │ ├── posts_controller.rb │ ├── users │ │ ├── confirmations_controller.rb │ │ ├── omniauth_callbacks_controller.rb │ │ ├── passwords_controller.rb │ │ ├── registrations_controller.rb │ │ ├── sessions_controller.rb │ │ └── unlocks_controller.rb │ └── users_controller.rb ├── helpers │ ├── application_helper.rb │ ├── comments_helper.rb │ ├── friendships_helper.rb │ ├── likes_helper.rb │ ├── posts_helper.rb │ └── users_helper.rb ├── jobs │ └── application_job.rb ├── mailers │ └── application_mailer.rb ├── models │ ├── application_record.rb │ ├── comment.rb │ ├── concerns │ │ └── .keep │ ├── friendship.rb │ ├── like.rb │ ├── post.rb │ └── user.rb └── views │ ├── comments │ ├── _comment_form.html.erb │ └── _comments.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 │ ├── friendships │ ├── _confirm.html.erb │ ├── _confirmed.html.erb │ └── index.html.erb │ ├── layouts │ ├── _bootstrap.html.erb │ ├── _default.html.erb │ ├── _flash_msg.html.erb │ ├── _footer.html.erb │ ├── _header.html.erb │ ├── application.html.erb │ ├── mailer.html.erb │ └── mailer.text.erb │ ├── posts │ ├── _posts.html.erb │ ├── edit.html.erb │ ├── index.html.erb │ ├── new.html.erb │ └── show.html.erb │ └── users │ ├── _add_friend.html.erb │ ├── _toggle_button.html.erb │ ├── friends.html.erb │ ├── index.html.erb │ └── show.html.erb ├── bin ├── bundle ├── rails ├── rake ├── setup ├── update └── yarn ├── config.ru ├── config ├── application.rb ├── boot.rb ├── cable.yml ├── credentials.yml.enc ├── database.yml ├── environment.rb ├── environments │ ├── development.rb │ ├── production.rb │ └── test.rb ├── initializers │ ├── application_controller_renderer.rb │ ├── assets.rb │ ├── backtrace_silencers.rb │ ├── content_security_policy.rb │ ├── cookies_serializer.rb │ ├── devise.rb │ ├── filter_parameter_logging.rb │ ├── inflections.rb │ ├── mime_types.rb │ └── wrap_parameters.rb ├── locales │ ├── devise.en.yml │ └── en.yml ├── puma.rb ├── routes.rb ├── spring.rb └── storage.yml ├── db ├── migrate │ ├── 20191218100616_devise_create_users.rb │ ├── 20191218101601_add_name_to_user.rb │ ├── 20191220094351_create_posts.rb │ ├── 20200110091652_create_comments.rb │ ├── 20200113135148_create_likes.rb │ ├── 20200116091354_create_friendships.rb │ └── 20200124103907_add_omniauth_to_users.rb ├── schema.rb └── seeds.rb ├── docs └── Milestone 1.pdf ├── lib ├── assets │ └── .keep └── tasks │ └── .keep ├── log └── .keep ├── package.json ├── public ├── 404.html ├── 422.html ├── 500.html ├── apple-touch-icon-precomposed.png ├── apple-touch-icon.png ├── favicon.ico └── robots.txt ├── spec ├── controllers │ └── likes_controller_spec.rb ├── features │ ├── comment_create_spec.rb │ ├── friendship_spec.rb │ ├── like_post_spec.rb │ ├── post_create_spec.rb │ └── user_actions_spec.rb ├── models │ ├── comment_spec.rb │ ├── friendship_spec.rb │ ├── like_spec.rb │ ├── post_spec.rb │ └── user_spec.rb ├── rails_helper.rb └── spec_helper.rb ├── storage └── .keep ├── test ├── application_system_test_case.rb ├── controllers │ ├── .keep │ └── users_controller_test.rb ├── fixtures │ ├── .keep │ ├── files │ │ └── .keep │ └── users.yml ├── helpers │ └── .keep ├── integration │ └── .keep ├── mailers │ └── .keep ├── models │ ├── .keep │ └── user_test.rb ├── system │ └── .keep └── test_helper.rb ├── tmp └── .keep └── vendor └── .keep /.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 uploaded files in development 17 | /storage/* 18 | !/storage/.keep 19 | 20 | /node_modules 21 | /yarn-error.log 22 | 23 | /public/assets 24 | .byebug_history 25 | 26 | # Ignore master key for decrypting credentials and more. 27 | /config/master.key 28 | -------------------------------------------------------------------------------- /.rspec: -------------------------------------------------------------------------------- 1 | --color 2 | 3 | -------------------------------------------------------------------------------- /.rubocop.yml: -------------------------------------------------------------------------------- 1 | AllCops: 2 | Exclude: 3 | - "bin/*" 4 | - "db/*" 5 | - "config/*" 6 | - "Guardfile" 7 | - "Rakefile" 8 | DisplayCopNames: true 9 | 10 | Layout/LineLength: 11 | Max: 120 12 | Metrics/MethodLength: 13 | Include: ["app/controllers/*"] 14 | Max: 20 15 | Metrics/AbcSize: 16 | Include: ["app/controllers/*"] 17 | Max: 30 18 | Metrics/ClassLength: 19 | Max: 150 20 | Metrics/BlockLength: 21 | ExcludedMethods: ["describe"] 22 | 23 | Style/Documentation: 24 | Enabled: false 25 | Style/ClassAndModuleChildren: 26 | Enabled: false 27 | 28 | Layout/HashAlignment: 29 | EnforcedColonStyle: key 30 | Layout/ExtraSpacing: 31 | AllowForAlignment: false 32 | Layout/MultilineMethodCallIndentation: 33 | Enabled: true 34 | EnforcedStyle: indented 35 | -------------------------------------------------------------------------------- /.ruby-version: -------------------------------------------------------------------------------- 1 | 2.6.4 -------------------------------------------------------------------------------- /.stickler.yml: -------------------------------------------------------------------------------- 1 | 2 | #frozen_string_literal 3 | 4 | linters: 5 | rubocop: 6 | display_cop_names: true 7 | files: 8 | ignore: 9 | - "bin/*" 10 | - "db/*" 11 | - "config/*" 12 | - "Guardfile" 13 | - "Rakefile" 14 | -------------------------------------------------------------------------------- /:environment: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/addod19/facebook-clone/69faa6903893947c3d024ace61377ba711575f4a/:environment -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source 'https://rubygems.org' 4 | git_source(:github) { |repo| "https://github.com/#{repo}.git" } 5 | 6 | ruby '2.6.4' 7 | gem 'activesupport', '~> 5.2.4.1' 8 | gem 'bootsnap', '>= 1.1.0', require: false 9 | gem 'bootstrap', '~> 4.3.1' 10 | gem 'bootstrap-will_paginate', '1.0.0' 11 | gem 'coffee-rails', '~> 4.2' 12 | gem 'devise', '~> 4.7', '>= 4.7.1' 13 | gem 'faker', '~> 1.6', '>= 1.6.6' 14 | gem 'font-awesome-rails', '~> 4.7', '>= 4.7.0.5' 15 | gem 'font-awesome-sass', '~> 5.11.2' 16 | gem 'hirb' 17 | gem 'jbuilder', '~> 2.5' 18 | gem 'omniauth-facebook', '~> 5.0' 19 | gem 'pg', '>= 0.18', '< 2.0' 20 | gem 'puma', '~> 3.11' 21 | gem 'rack', '~> 2.0', '>= 2.0.8' 22 | gem 'rails', '~> 5.2.3' 23 | gem 'sass-rails', '~> 5.0' 24 | gem 'turbolinks', '~> 5' 25 | gem 'uglifier', '>= 1.3.0' 26 | 27 | # Use Redis adapter to run Action Cable in production 28 | # gem 'redis', '~> 4.0' 29 | # Use ActiveModel has_secure_password 30 | # gem 'bcrypt', '~> 3.1.7' 31 | # Use ActiveStorage variant 32 | # gem 'mini_magick', '~> 4.8' 33 | 34 | # Use Capistrano for deployment 35 | # gem 'capistrano-rails', group: :development 36 | 37 | group :development, :test do 38 | gem 'byebug', platforms: %i[mri mingw x64_mingw] 39 | gem 'rspec-rails' 40 | end 41 | 42 | group :development do 43 | # Access an interactive console on exception pages or by calling 'console' anywhere in the code. 44 | gem 'listen', '>= 3.0.5', '< 3.2' 45 | gem 'spring' 46 | gem 'spring-watcher-listen', '~> 2.0.0' 47 | gem 'web-console', '>= 3.3.0' 48 | end 49 | 50 | group :test do 51 | gem 'capybara', '>= 3.30.0' 52 | gem 'selenium-webdriver' 53 | # Easy installation and use of chromedriver to run system tests with Chrome 54 | # gem 'chromedriver-helper' 55 | gem 'webdrivers', '~> 4.0' 56 | end 57 | 58 | # Windows does not include zoneinfo files, so bundle the tzinfo-data gem 59 | gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby] 60 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | actioncable (5.2.4.1) 5 | actionpack (= 5.2.4.1) 6 | nio4r (~> 2.0) 7 | websocket-driver (>= 0.6.1) 8 | actionmailer (5.2.4.1) 9 | actionpack (= 5.2.4.1) 10 | actionview (= 5.2.4.1) 11 | activejob (= 5.2.4.1) 12 | mail (~> 2.5, >= 2.5.4) 13 | rails-dom-testing (~> 2.0) 14 | actionpack (5.2.4.1) 15 | actionview (= 5.2.4.1) 16 | activesupport (= 5.2.4.1) 17 | rack (~> 2.0, >= 2.0.8) 18 | rack-test (>= 0.6.3) 19 | rails-dom-testing (~> 2.0) 20 | rails-html-sanitizer (~> 1.0, >= 1.0.2) 21 | actionview (5.2.4.1) 22 | activesupport (= 5.2.4.1) 23 | builder (~> 3.1) 24 | erubi (~> 1.4) 25 | rails-dom-testing (~> 2.0) 26 | rails-html-sanitizer (~> 1.0, >= 1.0.3) 27 | activejob (5.2.4.1) 28 | activesupport (= 5.2.4.1) 29 | globalid (>= 0.3.6) 30 | activemodel (5.2.4.1) 31 | activesupport (= 5.2.4.1) 32 | activerecord (5.2.4.1) 33 | activemodel (= 5.2.4.1) 34 | activesupport (= 5.2.4.1) 35 | arel (>= 9.0) 36 | activestorage (5.2.4.1) 37 | actionpack (= 5.2.4.1) 38 | activerecord (= 5.2.4.1) 39 | marcel (~> 0.3.1) 40 | activesupport (5.2.4.1) 41 | concurrent-ruby (~> 1.0, >= 1.0.2) 42 | i18n (>= 0.7, < 2) 43 | minitest (~> 5.1) 44 | tzinfo (~> 1.1) 45 | addressable (2.7.0) 46 | public_suffix (>= 2.0.2, < 5.0) 47 | arel (9.0.0) 48 | autoprefixer-rails (9.7.4) 49 | execjs 50 | bcrypt (3.1.13) 51 | bindex (0.8.1) 52 | bootsnap (1.4.5) 53 | msgpack (~> 1.0) 54 | bootstrap (4.3.1) 55 | autoprefixer-rails (>= 9.1.0) 56 | popper_js (>= 1.14.3, < 2) 57 | sassc-rails (>= 2.0.0) 58 | bootstrap-will_paginate (1.0.0) 59 | will_paginate 60 | builder (3.2.4) 61 | byebug (11.1.1) 62 | capybara (3.31.0) 63 | addressable 64 | mini_mime (>= 0.1.3) 65 | nokogiri (~> 1.8) 66 | rack (>= 1.6.0) 67 | rack-test (>= 0.6.3) 68 | regexp_parser (~> 1.5) 69 | xpath (~> 3.2) 70 | childprocess (3.0.0) 71 | coffee-rails (4.2.2) 72 | coffee-script (>= 2.2.0) 73 | railties (>= 4.0.0) 74 | coffee-script (2.4.1) 75 | coffee-script-source 76 | execjs 77 | coffee-script-source (1.12.2) 78 | concurrent-ruby (1.1.5) 79 | crass (1.0.6) 80 | devise (4.7.1) 81 | bcrypt (~> 3.0) 82 | orm_adapter (~> 0.1) 83 | railties (>= 4.1.0) 84 | responders 85 | warden (~> 1.2.3) 86 | diff-lcs (1.3) 87 | erubi (1.9.0) 88 | execjs (2.7.0) 89 | faker (1.9.6) 90 | i18n (>= 0.7) 91 | faraday (1.0.0) 92 | multipart-post (>= 1.2, < 3) 93 | ffi (1.12.1) 94 | font-awesome-rails (4.7.0.5) 95 | railties (>= 3.2, < 6.1) 96 | font-awesome-sass (5.11.2) 97 | sassc (>= 1.11) 98 | globalid (0.4.2) 99 | activesupport (>= 4.2.0) 100 | hashie (3.6.0) 101 | hirb (0.7.3) 102 | i18n (1.8.2) 103 | concurrent-ruby (~> 1.0) 104 | jbuilder (2.9.1) 105 | activesupport (>= 4.2.0) 106 | jwt (2.2.1) 107 | listen (3.1.5) 108 | rb-fsevent (~> 0.9, >= 0.9.4) 109 | rb-inotify (~> 0.9, >= 0.9.7) 110 | ruby_dep (~> 1.2) 111 | loofah (2.4.0) 112 | crass (~> 1.0.2) 113 | nokogiri (>= 1.5.9) 114 | mail (2.7.1) 115 | mini_mime (>= 0.1.1) 116 | marcel (0.3.3) 117 | mimemagic (~> 0.3.2) 118 | method_source (0.9.2) 119 | mimemagic (0.3.4) 120 | mini_mime (1.0.2) 121 | mini_portile2 (2.4.0) 122 | minitest (5.14.0) 123 | msgpack (1.3.1) 124 | multi_json (1.14.1) 125 | multi_xml (0.6.0) 126 | multipart-post (2.1.1) 127 | nio4r (2.5.2) 128 | nokogiri (1.10.7) 129 | mini_portile2 (~> 2.4.0) 130 | oauth2 (1.4.3) 131 | faraday (>= 0.8, < 2.0) 132 | jwt (>= 1.0, < 3.0) 133 | multi_json (~> 1.3) 134 | multi_xml (~> 0.5) 135 | rack (>= 1.2, < 3) 136 | omniauth (1.9.0) 137 | hashie (>= 3.4.6, < 3.7.0) 138 | rack (>= 1.6.2, < 3) 139 | omniauth-facebook (5.0.0) 140 | omniauth-oauth2 (~> 1.2) 141 | omniauth-oauth2 (1.6.0) 142 | oauth2 (~> 1.1) 143 | omniauth (~> 1.9) 144 | orm_adapter (0.5.0) 145 | pg (1.2.2) 146 | popper_js (1.16.0) 147 | public_suffix (4.0.3) 148 | puma (3.12.2) 149 | rack (2.1.2) 150 | rack-test (1.1.0) 151 | rack (>= 1.0, < 3) 152 | rails (5.2.4.1) 153 | actioncable (= 5.2.4.1) 154 | actionmailer (= 5.2.4.1) 155 | actionpack (= 5.2.4.1) 156 | actionview (= 5.2.4.1) 157 | activejob (= 5.2.4.1) 158 | activemodel (= 5.2.4.1) 159 | activerecord (= 5.2.4.1) 160 | activestorage (= 5.2.4.1) 161 | activesupport (= 5.2.4.1) 162 | bundler (>= 1.3.0) 163 | railties (= 5.2.4.1) 164 | sprockets-rails (>= 2.0.0) 165 | rails-dom-testing (2.0.3) 166 | activesupport (>= 4.2.0) 167 | nokogiri (>= 1.6) 168 | rails-html-sanitizer (1.3.0) 169 | loofah (~> 2.3) 170 | railties (5.2.4.1) 171 | actionpack (= 5.2.4.1) 172 | activesupport (= 5.2.4.1) 173 | method_source 174 | rake (>= 0.8.7) 175 | thor (>= 0.19.0, < 2.0) 176 | rake (13.0.1) 177 | rb-fsevent (0.10.3) 178 | rb-inotify (0.10.1) 179 | ffi (~> 1.0) 180 | regexp_parser (1.6.0) 181 | responders (3.0.0) 182 | actionpack (>= 5.0) 183 | railties (>= 5.0) 184 | rspec-core (3.9.1) 185 | rspec-support (~> 3.9.1) 186 | rspec-expectations (3.9.0) 187 | diff-lcs (>= 1.2.0, < 2.0) 188 | rspec-support (~> 3.9.0) 189 | rspec-mocks (3.9.1) 190 | diff-lcs (>= 1.2.0, < 2.0) 191 | rspec-support (~> 3.9.0) 192 | rspec-rails (3.9.0) 193 | actionpack (>= 3.0) 194 | activesupport (>= 3.0) 195 | railties (>= 3.0) 196 | rspec-core (~> 3.9.0) 197 | rspec-expectations (~> 3.9.0) 198 | rspec-mocks (~> 3.9.0) 199 | rspec-support (~> 3.9.0) 200 | rspec-support (3.9.2) 201 | ruby_dep (1.5.0) 202 | rubyzip (2.1.0) 203 | sass (3.7.4) 204 | sass-listen (~> 4.0.0) 205 | sass-listen (4.0.0) 206 | rb-fsevent (~> 0.9, >= 0.9.4) 207 | rb-inotify (~> 0.9, >= 0.9.7) 208 | sass-rails (5.1.0) 209 | railties (>= 5.2.0) 210 | sass (~> 3.1) 211 | sprockets (>= 2.8, < 4.0) 212 | sprockets-rails (>= 2.0, < 4.0) 213 | tilt (>= 1.1, < 3) 214 | sassc (2.2.1) 215 | ffi (~> 1.9) 216 | sassc-rails (2.1.2) 217 | railties (>= 4.0.0) 218 | sassc (>= 2.0) 219 | sprockets (> 3.0) 220 | sprockets-rails 221 | tilt 222 | selenium-webdriver (3.142.7) 223 | childprocess (>= 0.5, < 4.0) 224 | rubyzip (>= 1.2.2) 225 | spring (2.1.0) 226 | spring-watcher-listen (2.0.1) 227 | listen (>= 2.7, < 4.0) 228 | spring (>= 1.2, < 3.0) 229 | sprockets (3.7.2) 230 | concurrent-ruby (~> 1.0) 231 | rack (> 1, < 3) 232 | sprockets-rails (3.2.1) 233 | actionpack (>= 4.0) 234 | activesupport (>= 4.0) 235 | sprockets (>= 3.0.0) 236 | thor (1.0.1) 237 | thread_safe (0.3.6) 238 | tilt (2.0.10) 239 | turbolinks (5.2.1) 240 | turbolinks-source (~> 5.2) 241 | turbolinks-source (5.2.0) 242 | tzinfo (1.2.6) 243 | thread_safe (~> 0.1) 244 | uglifier (4.2.0) 245 | execjs (>= 0.3.0, < 3) 246 | warden (1.2.8) 247 | rack (>= 2.0.6) 248 | web-console (3.7.0) 249 | actionview (>= 5.0) 250 | activemodel (>= 5.0) 251 | bindex (>= 0.4.0) 252 | railties (>= 5.0) 253 | webdrivers (4.2.0) 254 | nokogiri (~> 1.6) 255 | rubyzip (>= 1.3.0) 256 | selenium-webdriver (>= 3.0, < 4.0) 257 | websocket-driver (0.7.1) 258 | websocket-extensions (>= 0.1.0) 259 | websocket-extensions (0.1.4) 260 | will_paginate (3.2.1) 261 | xpath (3.2.0) 262 | nokogiri (~> 1.8) 263 | 264 | PLATFORMS 265 | ruby 266 | 267 | DEPENDENCIES 268 | activesupport (~> 5.2.4.1) 269 | bootsnap (>= 1.1.0) 270 | bootstrap (~> 4.3.1) 271 | bootstrap-will_paginate (= 1.0.0) 272 | byebug 273 | capybara (>= 3.30.0) 274 | coffee-rails (~> 4.2) 275 | devise (~> 4.7, >= 4.7.1) 276 | faker (~> 1.6, >= 1.6.6) 277 | font-awesome-rails (~> 4.7, >= 4.7.0.5) 278 | font-awesome-sass (~> 5.11.2) 279 | hirb 280 | jbuilder (~> 2.5) 281 | listen (>= 3.0.5, < 3.2) 282 | omniauth-facebook (~> 5.0) 283 | pg (>= 0.18, < 2.0) 284 | puma (~> 3.11) 285 | rack (~> 2.0, >= 2.0.8) 286 | rails (~> 5.2.3) 287 | rspec-rails 288 | sass-rails (~> 5.0) 289 | selenium-webdriver 290 | spring 291 | spring-watcher-listen (~> 2.0.0) 292 | turbolinks (~> 5) 293 | tzinfo-data 294 | uglifier (>= 1.3.0) 295 | web-console (>= 3.3.0) 296 | webdrivers (~> 4.0) 297 | 298 | RUBY VERSION 299 | ruby 2.6.4p104 300 | 301 | BUNDLED WITH 302 | 2.0.2 303 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Nick Haras 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 | -------------------------------------------------------------------------------- /Procfile: -------------------------------------------------------------------------------- 1 | web: bundle exec puma -t 5:5 -p ${PORT:-3000} -e ${RACK_ENV:-development} -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Project Facebook Clone 2 | 3 | Welcome to Friendbook. In this project, we recreated the basic functionality of facebook. This is the last project of Microverse's Rails curriculum. 4 | 5 | ### Features 6 | 7 | - Users 8 | 9 | - Sign up using their # Project Facebook Clone 10 | 11 | Welcome to Friendbook. In this project, we recreated the basic functionality of Facebook. This is the last project of the Microverse's Rails curriculum. 12 | 13 | ### Features 14 | 15 | - Users 16 | 17 | - Sign up using their real facebook account 18 | - Create/delete posts 19 | - Like posts 20 | - Comment on posts 21 | - Send and accept friendship requests 22 | - Remove friends 23 | 24 | ### Future features 25 | - Create a post with images 26 | - Add emojis to comments 27 | - Upload profile photo 28 | - Chat with a friend 29 | 30 | ### Screenshot 31 | 32 | ![screenshot](app/assets/images/fb.png) 33 | 34 | ### Live link 35 | 36 | Follow the link to access [Friendbook](https://secret-sea-76381.herokuapp.com/) 37 | 38 | ### Requirements 39 | 40 | ``` 41 | - A Cloud Server running Linux (Ubuntu 18.04) or (Mac OS) 42 | - PostgreSQL installed and running. 43 | - Ruby 2.6.4 44 | - Rails 5.2.3 45 | - A basic familiarity with Ruby on Rails 46 | 47 | ``` 48 | 49 | ### Gems 50 | 51 | - gem 'devise', '~> 4.7', '>= 4.7.1' 52 | - gem 'faker', '~> 1.6', '>= 1.6.6' 53 | - gem 'font-awesome-sass' 54 | - gem 'omniauth-facebook', '~> 5.0' 55 | - gem 'pg', '>= 0.18', '< 2.0' 56 | - gem 'rails', '~> 5.2.3' 57 | 58 | ### To run on windows system we have to install the following gems 59 | 60 | - gem 'wdm', '>= 0.1.0' if Gem.win_platform? 61 | - gem 'autoprefixer-rails' 62 | 63 | Add this to ```ENV['EXECJS_RUNTIME'] = 'Node'``` ```boot.rb``` file 64 | 65 | Uncomment ``` #workers Integer(ENV['WEB_CONCURRENCY'] || 2) ``` in ```puma.rb``` file 66 | 67 | #### Optional 68 | 69 | - gem hirb 70 | 71 | ### Installation 72 | 73 | Clone or download this repository to your local machine. After cloning open your terminal on the repository folder and run : 74 | 75 | ``` 76 | bundle install 77 | rails db:create 78 | rails db:migrate 79 | rails db:seed 80 | ``` 81 | 82 | ## How to run the test 83 | 84 | For unit testing run 85 | ``` rspec spec/models ``` 86 | 87 | For a feature test run 88 | ``` rspec spec/features ``` 89 | 90 | Or run 91 | ``` rspec -fd ``` for all test 92 | 93 | 94 | 👤 **Nick Haralampopoulos** 95 | 96 | - Github: [@macnick](https://github.com/macnick) 97 | - Twitter: [@mac_experts](https://twitter.com/mac_experts) 98 | - Linkedin: [Nick Haralampopoulos](https://www.linkedin.com/in/nick-haralampopoulos-26a55412a/) 99 | - Email: [Nick Haralampopoulos](mac.expert.nick@gmail.com) 100 | 101 | 👤 **Daniel Larbi Addo** 102 | 103 | - Github: [@addod19](https://github.com/addod19) 104 | - Twitter: [@DanielLarbiAdd1](https://twitter.com/DanielLarbiAdd1) 105 | - Linkedin: [Daniel Larbi Addo](https://linkedin.com/in/daniel-larbi-addo-9738b0128/) 106 | - Email: (addodaniellarbi@gmail.com) 107 | 108 | ## Appreciation 109 | [Microverse](microverse.org) 110 | 111 | ## 🤝 Contributing 112 | 113 | Contributions, issues, and feature requests are welcome! 114 | 115 | Feel free to check the [issues page](https://github.com/macnick/facebook-clone/issues). 116 | 117 | 1. Fork it ( https://github.com/macnick/facebook-clone/fork ) 118 | 2. Create your feature branch (git checkout -b my-new-feature) 119 | 3. Commit your changes (git commit -am 'Add some feature') 120 | 4. Push to the branch (git push origin my-new-feature) 121 | 5. Create a new Pull Request 122 | 123 | ## Show your support 124 | 125 | Give us ⭐️ if you like this project! 126 | 127 | ## 📝 License 128 | 129 | This project is [MiT](LICENSE) licensed. 130 | 131 | ``` 132 | 133 | -------------------------------------------------------------------------------- /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 ../javascripts .js 3 | //= link_directory ../stylesheets .css 4 | -------------------------------------------------------------------------------- /app/assets/images/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/addod19/facebook-clone/69faa6903893947c3d024ace61377ba711575f4a/app/assets/images/.keep -------------------------------------------------------------------------------- /app/assets/images/default_avatar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/addod19/facebook-clone/69faa6903893947c3d024ace61377ba711575f4a/app/assets/images/default_avatar.png -------------------------------------------------------------------------------- /app/assets/images/fb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/addod19/facebook-clone/69faa6903893947c3d024ace61377ba711575f4a/app/assets/images/fb.png -------------------------------------------------------------------------------- /app/assets/images/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/addod19/facebook-clone/69faa6903893947c3d024ace61377ba711575f4a/app/assets/images/screenshot.png -------------------------------------------------------------------------------- /app/assets/javascripts/application.js: -------------------------------------------------------------------------------- 1 | // This is a manifest file that'll be compiled into application.js, which will include all the files 2 | // listed below. 3 | // 4 | // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, or any plugin's 5 | // vendor/assets/javascripts directory can be referenced here using a relative path. 6 | // 7 | // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the 8 | // compiled file. JavaScript code in this file should be added after the last require_* statement. 9 | // 10 | // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details 11 | // about supported directives. 12 | // 13 | //= require rails-ujs 14 | //= require activestorage 15 | //= require turbolinks 16 | //= require_tree . 17 | -------------------------------------------------------------------------------- /app/assets/javascripts/cable.js: -------------------------------------------------------------------------------- 1 | // Action Cable provides the framework to deal with WebSockets in Rails. 2 | // You can generate new channels where WebSocket features live using the `rails generate channel` command. 3 | // 4 | //= require action_cable 5 | //= require_self 6 | //= require_tree ./channels 7 | 8 | (function() { 9 | this.App || (this.App = {}); 10 | 11 | App.cable = ActionCable.createConsumer(); 12 | 13 | }).call(this); 14 | -------------------------------------------------------------------------------- /app/assets/javascripts/channels/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/addod19/facebook-clone/69faa6903893947c3d024ace61377ba711575f4a/app/assets/javascripts/channels/.keep -------------------------------------------------------------------------------- /app/assets/javascripts/likes.coffee: -------------------------------------------------------------------------------- 1 | # Place all the behaviors and hooks related to the matching controller here. 2 | # All this logic will automatically be available in application.js. 3 | # You can use CoffeeScript in this file: http://coffeescript.org/ 4 | -------------------------------------------------------------------------------- /app/assets/javascripts/users.coffee: -------------------------------------------------------------------------------- 1 | # Place all the behaviors and hooks related to the matching controller here. 2 | # All this logic will automatically be available in application.js. 3 | # You can use CoffeeScript in this file: http://coffeescript.org/ 4 | -------------------------------------------------------------------------------- /app/assets/stylesheets/application.scss: -------------------------------------------------------------------------------- 1 | /* 2 | * This is a manifest file that'll be compiled into application.css, which will include all the files 3 | * listed below. 4 | * 5 | * Any CSS and SCSS file within this directory, lib/assets/stylesheets, or any plugin's 6 | * vendor/assets/stylesheets directory can be referenced here using a relative path. 7 | * 8 | * You're free to add application-wide styles to this file and they'll appear at the bottom of the 9 | * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS 10 | * files in this directory. Styles in this file should be added after the last require_* statement. 11 | * It is generally better to create a new file per style scope. 12 | * 13 | *= require_tree . 14 | *= require_self 15 | */ 16 | 17 | @import "bootstrap"; 18 | @import "font-awesome"; 19 | .w-40 { 20 | width: 50%; 21 | text-align: center !important; 22 | } 23 | 24 | .img-pro-size { 25 | width: 20px; 26 | height: 20px; 27 | border-radius: 50%; 28 | } 29 | 30 | .white { 31 | color: white; 32 | font-weight: 300; 33 | } 34 | 35 | .fa-facebook-square { 36 | color: white; 37 | } -------------------------------------------------------------------------------- /app/assets/stylesheets/likes.scss: -------------------------------------------------------------------------------- 1 | // Place all the styles related to the Likes controller here. 2 | // They will automatically be included in application.css. 3 | // You can use Sass (SCSS) here: http://sass-lang.com/ 4 | -------------------------------------------------------------------------------- /app/assets/stylesheets/users.scss: -------------------------------------------------------------------------------- 1 | // Place all the styles related to the Users controller here. 2 | // They will automatically be included in application.css. 3 | // You can use Sass (SCSS) here: http://sass-lang.com/ -------------------------------------------------------------------------------- /app/channels/application_cable/channel.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module ApplicationCable 4 | class Channel < ActionCable::Channel::Base 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /app/channels/application_cable/connection.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module ApplicationCable 4 | class Connection < ActionCable::Connection::Base 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /app/controllers/application_controller.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class ApplicationController < ActionController::Base 4 | before_action :authenticate_user! 5 | protect_from_forgery with: :exception 6 | before_action :configure_permitted_parameters, if: :devise_controller? 7 | include ApplicationHelper 8 | 9 | protected 10 | 11 | def configure_permitted_parameters 12 | devise_parameter_sanitizer.permit(:sign_up, keys: %i[first_name last_name]) 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /app/controllers/comments_controller.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class CommentsController < ApplicationController 4 | def create 5 | post = Post.find(params[:post_id]) 6 | @comment = post.comments.build(comment_params) 7 | @comment.user = current_user 8 | @comment.save 9 | redirect_to posts_path 10 | end 11 | 12 | def index; end 13 | 14 | private 15 | 16 | def comment_params 17 | params.require(:comment).permit(:comment_text, :post_id) 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /app/controllers/concerns/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/addod19/facebook-clone/69faa6903893947c3d024ace61377ba711575f4a/app/controllers/concerns/.keep -------------------------------------------------------------------------------- /app/controllers/friendships_controller.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class FriendshipsController < ApplicationController 4 | def new 5 | @friendship = Friendship.new 6 | end 7 | 8 | def index 9 | @friendships = current_user.friendships 10 | @inverse_friendships = current_user.inverse_friendships 11 | end 12 | 13 | def create 14 | user = User.find(params[:friend_id]) 15 | @friendship = Friendship.create(user_id: current_user.id, friend_id: user.id, confirmed: false) 16 | if @friendship.save 17 | flash[:success] = 'Friend request sent successfully' 18 | else 19 | flash[:danger] = 'Can not send friend request' 20 | end 21 | redirect_to users_path 22 | end 23 | 24 | def update 25 | @friendship = Friendship.find(params[:id]) 26 | @friendship.update_attributes confirmed: true 27 | @fs = Friendship.create(user_id: current_user.id, friend_id: @friendship.user_id, confirmed: true) 28 | flash[:success] = 'Friendship confirmed' if @fs.save 29 | redirect_to friendships_path 30 | end 31 | 32 | def cancel 33 | request = current_user.friendships.where(friend_id: params[:friend_id]) 34 | flash[:success] = 'Friend request cancelled' if request[0].destroy 35 | redirect_to users_path 36 | end 37 | 38 | def destroy 39 | fs = current_user.friendships.where(friend_id: params[:friend_id]).ids 40 | .concat(current_user.inverse_friendships.where(user_id: params[:friend_id]).ids) 41 | Friendship.delete(fs) 42 | 43 | flash[:success] = 'Friend removed successfully' 44 | redirect_to friends_path 45 | end 46 | end 47 | -------------------------------------------------------------------------------- /app/controllers/likes_controller.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class LikesController < ApplicationController 4 | def create 5 | if already_liked? 6 | like = Like.find_by(user_id: current_user.id, post_id: params[:post_id]) 7 | like.destroy 8 | else 9 | post = Post.find(params[:post_id]) 10 | @like = post.likes.build(like_params) 11 | @like.save 12 | end 13 | redirect_to posts_path 14 | end 15 | 16 | private 17 | 18 | def like_params 19 | params.permit(:user_id, :post_id) 20 | end 21 | 22 | def already_liked? 23 | Like.where(user_id: current_user.id, post_id: params[:post_id]).exists? 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /app/controllers/posts_controller.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class PostsController < ApplicationController 4 | def index 5 | @post = Post.new 6 | ids = current_user.friends ? current_user.friends.pluck(:id) << current_user.id : current_user.id 7 | @user_posts = Post.where(user_id: ids).order(id: :desc) 8 | @comment = Comment.new 9 | @like = Like.new 10 | end 11 | 12 | def create 13 | @post = current_user.posts.build(post_params) 14 | @post.save 15 | redirect_to posts_path 16 | end 17 | 18 | def show; end 19 | 20 | def destroy 21 | @post = Post.find(params[:id]) 22 | @post.destroy 23 | redirect_to posts_path 24 | end 25 | 26 | def liked? 27 | Like.where(user_id: current_user.id, post_id: params[:post_id]).exists? 28 | end 29 | 30 | private 31 | 32 | def post_params 33 | params.require(:post).permit(:post_text) 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /app/controllers/users/confirmations_controller.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class Users::ConfirmationsController < Devise::ConfirmationsController 4 | # GET /resource/confirmation/new 5 | # def new 6 | # super 7 | # end 8 | 9 | # POST /resource/confirmation 10 | # def create 11 | # super 12 | # end 13 | 14 | # GET /resource/confirmation?confirmation_token=abcdef 15 | # def show 16 | # super 17 | # end 18 | 19 | # protected 20 | 21 | # The path used after resending confirmation instructions. 22 | # def after_resending_confirmation_instructions_path_for(resource_name) 23 | # super(resource_name) 24 | # end 25 | 26 | # The path used after confirmation. 27 | # def after_confirmation_path_for(resource_name, resource) 28 | # super(resource_name, resource) 29 | # end 30 | end 31 | -------------------------------------------------------------------------------- /app/controllers/users/omniauth_callbacks_controller.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController 4 | # More info at: 5 | # https://github.com/plataformatec/devise#omniauth 6 | 7 | # GET|POST /resource/auth/twitter 8 | # def passthru 9 | # super 10 | # end 11 | 12 | # GET|POST /users/auth/twitter/callback 13 | # def failure 14 | # super 15 | # end 16 | 17 | # protected 18 | 19 | # The path used when OmniAuth fails 20 | # def after_omniauth_failure_path_for(scope) 21 | # super(scope) 22 | # end 23 | def facebook 24 | # You need to implement the method below in your model (e.g. app/models/user.rb) 25 | @user = User.from_omniauth(request.env['omniauth.auth']) 26 | 27 | if @user.persisted? 28 | sign_in_and_redirect @user, event: :authentication # this will throw if @user is not activated 29 | set_flash_message(:notice, :success, kind: 'Facebook') if is_navigational_format? 30 | else 31 | session['devise.facebook_data'] = request.env['omniauth.auth'] 32 | redirect_to new_user_registration_url 33 | end 34 | end 35 | 36 | def failure 37 | redirect_to root_path 38 | end 39 | end 40 | -------------------------------------------------------------------------------- /app/controllers/users/passwords_controller.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class Users::PasswordsController < Devise::PasswordsController 4 | # GET /resource/password/new 5 | # def new 6 | # super 7 | # end 8 | 9 | # POST /resource/password 10 | # def create 11 | # super 12 | # end 13 | 14 | # GET /resource/password/edit?reset_password_token=abcdef 15 | # def edit 16 | # super 17 | # end 18 | 19 | # PUT /resource/password 20 | # def update 21 | # super 22 | # end 23 | 24 | # protected 25 | 26 | # def after_resetting_password_path_for(resource) 27 | # super(resource) 28 | # end 29 | 30 | # The path used after sending reset password instructions 31 | # def after_sending_reset_password_instructions_path_for(resource_name) 32 | # super(resource_name) 33 | # end 34 | end 35 | -------------------------------------------------------------------------------- /app/controllers/users/registrations_controller.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class Users::RegistrationsController < Devise::RegistrationsController 4 | # before_action :configure_sign_up_params, only: [:create] 5 | # before_action :configure_account_update_params, only: [:update] 6 | 7 | # GET /resource/sign_up 8 | # def new 9 | # super 10 | # end 11 | 12 | # POST /resource 13 | # def create 14 | # super 15 | # end 16 | 17 | # GET /resource/edit 18 | # def edit 19 | # super 20 | # end 21 | 22 | # PUT /resource 23 | # def update 24 | # super 25 | # end 26 | 27 | # DELETE /resource 28 | # def destroy 29 | # super 30 | # end 31 | 32 | # GET /resource/cancel 33 | # Forces the session data which is usually expired after sign 34 | # in to be expired now. This is useful if the user wants to 35 | # cancel oauth signing in/up in the middle of the process, 36 | # removing all OAuth session data. 37 | # def cancel 38 | # super 39 | # end 40 | 41 | # protected 42 | 43 | # If you have extra params to permit, append them to the sanitizer. 44 | # def configure_sign_up_params 45 | # devise_parameter_sanitizer.permit(:sign_up, keys: [:attribute]) 46 | # end 47 | 48 | # If you have extra params to permit, append them to the sanitizer. 49 | # def configure_account_update_params 50 | # devise_parameter_sanitizer.permit(:account_update, keys: [:attribute]) 51 | # end 52 | 53 | # The path used after sign up. 54 | # def after_sign_up_path_for(resource) 55 | # super(resource) 56 | # end 57 | 58 | # The path used after sign up for inactive accounts. 59 | # def after_inactive_sign_up_path_for(resource) 60 | # super(resource) 61 | # end 62 | end 63 | -------------------------------------------------------------------------------- /app/controllers/users/sessions_controller.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class Users::SessionsController < Devise::SessionsController 4 | # before_action :configure_sign_in_params, only: [:create] 5 | 6 | # GET /resource/sign_in 7 | # def new 8 | # super 9 | # end 10 | 11 | # POST /resource/sign_in 12 | # def create 13 | # super 14 | # end 15 | 16 | # DELETE /resource/sign_out 17 | # def destroy 18 | # super 19 | # end 20 | 21 | # protected 22 | 23 | # If you have extra params to permit, append them to the sanitizer. 24 | # def configure_sign_in_params 25 | # devise_parameter_sanitizer.permit(:sign_in, keys: [:attribute]) 26 | # end 27 | end 28 | -------------------------------------------------------------------------------- /app/controllers/users/unlocks_controller.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class Users::UnlocksController < Devise::UnlocksController 4 | # GET /resource/unlock/new 5 | # def new 6 | # super 7 | # end 8 | 9 | # POST /resource/unlock 10 | # def create 11 | # super 12 | # end 13 | 14 | # GET /resource/unlock?unlock_token=abcdef 15 | # def show 16 | # super 17 | # end 18 | 19 | # protected 20 | 21 | # The path used after sending unlock password instructions 22 | # def after_sending_unlock_instructions_path_for(resource) 23 | # super(resource) 24 | # end 25 | 26 | # The path used after unlocking the resource 27 | # def after_unlock_path_for(resource) 28 | # super(resource) 29 | # end 30 | end 31 | -------------------------------------------------------------------------------- /app/controllers/users_controller.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class UsersController < ApplicationController 4 | def index 5 | @users = User.all 6 | @friendship = Friendship.new 7 | end 8 | 9 | def show 10 | @user = User.find(current_user.id) 11 | end 12 | 13 | def friends; end 14 | end 15 | -------------------------------------------------------------------------------- /app/helpers/application_helper.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module ApplicationHelper 4 | def signup_path? 5 | return true if request.original_url.include?('users/sign_up') 6 | 7 | false 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /app/helpers/comments_helper.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module CommentsHelper 4 | def render_comment(user_post) 5 | render partial: 'comment_post', collection: @comments, locals: { user_post: user_post } 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /app/helpers/friendships_helper.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module FriendshipsHelper 4 | def delete_button(_friend) 5 | button_to 'delete', friendship, method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-danger btn-sm' 6 | end 7 | 8 | def unconfirmed_requests 9 | current_user.inverse_friendships.where(confirmed: false) 10 | end 11 | 12 | def all_friends 13 | return current_user.friends.size unless current_user.friends.nil? 14 | 15 | 0 16 | end 17 | 18 | def confirm_friend(fri) 19 | render partial: '/friendships/confirm', locals: { fri: fri } if fri.confirmed == false 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /app/helpers/likes_helper.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module LikesHelper 4 | end 5 | -------------------------------------------------------------------------------- /app/helpers/posts_helper.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module PostsHelper 4 | def delete_button(user_post) 5 | return unless current_user.id == user_post.user.id 6 | 7 | button_to 'delete', user_post, method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-danger btn-sm' 8 | end 9 | 10 | def post_comments(user_post) 11 | @comments = user_post.comments 12 | render partial: 'comments/comments' 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /app/helpers/users_helper.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module UsersHelper 4 | def friend_requests 5 | inverse_friendships.map { |f| f.user unless f.confirmed }.compact 6 | end 7 | 8 | def request_sent(user) 9 | render '/users/add_friend' if friendship.include?(user) && !friendship.confirmed 10 | end 11 | 12 | def toggle_button(user) 13 | return unless current_user != user 14 | 15 | if current_user.pending_friends.include?(user) 16 | button_to 'Cancel Request', { controller: 'friendships', action: 'cancel', friend_id: user.id }, 17 | method: :post, class: 'form-control btn btn-danger mt-1', 18 | id: "button-#{user.id}" 19 | elsif current_user.friendships.where(friend_id: user.id).empty? && 20 | current_user.inverse_friendships.where(user_id: user.id).empty? 21 | button_to 'Add Friend', { controller: 'friendships', action: 'create', friend_id: user }, 22 | method: :post, class: 'form-control btn btn-success mt-1', 23 | id: "button-#{user.id}" 24 | end 25 | end 26 | 27 | def delete_friend(user) 28 | button_to 'Remove Friend', { controller: 'friendships', action: 'destroy', friend_id: user }, 29 | method: :post, class: 'form-control btn btn-info mt-1', 30 | id: "button-#{user.id}" 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /app/jobs/application_job.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class ApplicationJob < ActiveJob::Base 4 | end 5 | -------------------------------------------------------------------------------- /app/mailers/application_mailer.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class ApplicationMailer < ActionMailer::Base 4 | default from: 'from@example.com' 5 | layout 'mailer' 6 | end 7 | -------------------------------------------------------------------------------- /app/models/application_record.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class ApplicationRecord < ActiveRecord::Base 4 | self.abstract_class = true 5 | end 6 | -------------------------------------------------------------------------------- /app/models/comment.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class Comment < ApplicationRecord 4 | belongs_to :user 5 | belongs_to :post 6 | validates :comment_text, presence: true, length: { maximum: 100 } 7 | end 8 | -------------------------------------------------------------------------------- /app/models/concerns/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/addod19/facebook-clone/69faa6903893947c3d024ace61377ba711575f4a/app/models/concerns/.keep -------------------------------------------------------------------------------- /app/models/friendship.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class Friendship < ApplicationRecord 4 | belongs_to :user 5 | belongs_to :friend, class_name: 'User' 6 | end 7 | -------------------------------------------------------------------------------- /app/models/like.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class Like < ApplicationRecord 4 | belongs_to :user 5 | belongs_to :post 6 | end 7 | -------------------------------------------------------------------------------- /app/models/post.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class Post < ApplicationRecord 4 | belongs_to :user 5 | has_many :comments, dependent: :destroy 6 | has_many :likes, dependent: :destroy 7 | validates :post_text, presence: true, length: { maximum: 100 } 8 | end 9 | -------------------------------------------------------------------------------- /app/models/user.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class User < ApplicationRecord 4 | has_many :posts, dependent: :destroy 5 | has_many :comments, dependent: :destroy 6 | has_many :likes, dependent: :destroy 7 | has_many :friendships 8 | has_many :inverse_friendships, class_name: 'Friendship', foreign_key: 'friend_id' 9 | validates :first_name, presence: true 10 | validates :last_name, presence: true 11 | # Include default devise modules. Others available are: 12 | # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable 13 | devise :database_authenticatable, :registerable, 14 | :recoverable, :rememberable, :validatable, :omniauthable, omniauth_providers: %i[facebook] 15 | 16 | def self.from_omniauth(auth) 17 | where(provider: auth.provider, uid: auth.uid).first_or_create do |user| 18 | user.email = auth.info.email 19 | user.password = Devise.friendly_token[0, 20] 20 | user.first_name = auth.info.name.split(' ')[0] # assuming the user model has a name 21 | user.last_name = auth.info.name.split(' ')[1] 22 | # user.image = auth.info.image # assuming the user model has an image 23 | # If you are using confirmable and the provider(s) you use validate emails, 24 | # uncomment the line below to skip the confirmation emails. 25 | # user.skip_confirmation! 26 | end 27 | end 28 | 29 | # called by the devise registrations controller 30 | def self.new_with_session(params, session) 31 | super.tap do |user| 32 | if (data = session['devise.facebook_data'] && session['devise.facebook_data']['extra']['raw_info']) 33 | user.email = data['email'] if user.email.blank? 34 | end 35 | end 36 | end 37 | 38 | def friends 39 | friends_array = friendships.map { |f| f.friend if f.confirmed } 40 | friends_array.concat(inverse_friendships.map { |f| f.user if f.confirmed }) 41 | friends_array.compact.uniq! 42 | end 43 | 44 | def pending_friends 45 | friendships.map { |f| f.friend unless f.confirmed }.compact 46 | end 47 | 48 | def confirm_friend(user) 49 | friendship = inverse_friendships.find { |f| f.user == user } 50 | friendship.confirmed = true 51 | friendship.save 52 | end 53 | 54 | def friend?(user) 55 | friendship.include? user 56 | end 57 | 58 | def unfriend(user) 59 | table = friendships.where(requested_id: user.id).or(inverse_friendships.where(requestor_id: user.id)).ids 60 | Friendship.delete(table.first) 61 | end 62 | end 63 | -------------------------------------------------------------------------------- /app/views/comments/_comment_form.html.erb: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /app/views/comments/_comments.html.erb: -------------------------------------------------------------------------------- 1 | <% if !@comments.nil? %> 2 | <% @comments.each do |c| %> 3 |
4 |
5 | <%= c.comment_text %> 6 |
7 |
8 | <% end %> 9 | <% end %> -------------------------------------------------------------------------------- /app/views/devise/confirmations/new.html.erb: -------------------------------------------------------------------------------- 1 |

Resend confirmation instructions

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

Change your password

2 | 3 | <%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :put }) do |f| %> 4 | <%= render "devise/shared/error_messages", resource: resource %> 5 | <%= f.hidden_field :reset_password_token %> 6 | 7 |
8 | <%= f.label :password, "New password" %>
9 | <% if @minimum_password_length %> 10 | (<%= @minimum_password_length %> characters minimum)
11 | <% end %> 12 | <%= f.password_field :password, autofocus: true, autocomplete: "new-password" %> 13 |
14 | 15 |
16 | <%= f.label :password_confirmation, "Confirm new password" %>
17 | <%= f.password_field :password_confirmation, autocomplete: "new-password" %> 18 |
19 | 20 |
21 | <%= f.submit "Change my password" %> 22 |
23 | <% end %> 24 | 25 | <%= render "devise/shared/links" %> 26 | -------------------------------------------------------------------------------- /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", class: "form-control" %> 10 |
11 | 12 |
13 | <%= f.submit "Send me reset password instructions", class: "btn btn-success mt-1" %> 14 |
15 | <% end %> 16 | 17 | <%= render "devise/shared/links" %> 18 |
-------------------------------------------------------------------------------- /app/views/devise/registrations/edit.html.erb: -------------------------------------------------------------------------------- 1 |

Edit <%= resource_name.to_s.humanize %>

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

Cancel my account

40 | 41 |

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

42 | 43 | <%= link_to "Back", :back %> 44 | -------------------------------------------------------------------------------- /app/views/devise/registrations/new.html.erb: -------------------------------------------------------------------------------- 1 |
2 |
3 |

Sign up

4 | 5 | <%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %> 6 | <%= render "devise/shared/error_messages", resource: resource %> 7 | 8 |
9 | <%= f.label :first_name %>
10 | <%= f.text_field :first_name, autocomplete: "first_name", class: "form-control" %> 11 |
12 | 13 |
14 | <%= f.label :last_name %>
15 | <%= f.text_field :last_name, autocomplete: "last_name", class: "form-control" %> 16 |
17 | 18 |
19 | <%= f.label :email %>
20 | <%= f.email_field :email, autocomplete: "email", class: "form-control" %> 21 |
22 | 23 |
24 | <%= f.label :password %> 25 | <% if @minimum_password_length %> 26 | (<%= @minimum_password_length %> characters minimum) 27 | <% end %>
28 | <%= f.password_field :password, autocomplete: "new-password", class: "form-control" %> 29 |
30 | 31 |
32 | <%= f.label :password_confirmation %>
33 | <%= f.password_field :password_confirmation, autocomplete: "new-password", class: "form-control" %> 34 |
35 | 36 |
37 | <%= f.submit "Sign up", class: "form-control btn btn-success mt-1" %> 38 |
39 | <% end %> 40 |
41 | <%= render "devise/shared/links" %> 42 |
43 |
44 |
-------------------------------------------------------------------------------- /app/views/devise/sessions/new.html.erb: -------------------------------------------------------------------------------- 1 |
2 |
3 |

Log in

4 | 5 | <%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %> 6 |
7 | <%= f.label :email %>
8 | <%= f.email_field :email, autocomplete: "email", class: "form-control" %> 9 |
10 | 11 |
12 | <%= f.label :password %>
13 | <%= f.password_field :password, autocomplete: "current-password", class: "form-control" %> 14 |
15 | 16 | <% if devise_mapping.rememberable? %> 17 |
18 | <%= f.check_box :remember_me %> 19 | <%= f.label :remember_me %> 20 |
21 | <% end %> 22 | 23 |
24 | <%= f.submit "Log in", class: "form-control btn btn-success" %> 25 |
26 | <% end %> 27 |
28 | <%= render "devise/shared/links" %> 29 |
30 |
31 |
-------------------------------------------------------------------------------- /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 | <%= link_to "Sign in with #{OmniAuth::Utils.camelize(provider)}", omniauth_authorize_path(resource_name, provider) %>
24 | <% end %> 25 | <% end %> 26 | -------------------------------------------------------------------------------- /app/views/devise/unlocks/new.html.erb: -------------------------------------------------------------------------------- 1 |

Resend unlock instructions

2 | 3 | <%= form_for(resource, as: resource_name, url: unlock_path(resource_name), html: { method: :post }) do |f| %> 4 | <%= render "devise/shared/error_messages", resource: resource %> 5 | 6 |
7 | <%= f.label :email %>
8 | <%= f.email_field :email, autofocus: true, autocomplete: "email" %> 9 |
10 | 11 |
12 | <%= f.submit "Resend unlock instructions" %> 13 |
14 | <% end %> 15 | 16 | <%= render "devise/shared/links" %> 17 | -------------------------------------------------------------------------------- /app/views/friendships/_confirm.html.erb: -------------------------------------------------------------------------------- 1 |
2 | User: <%= fri.user.first_name %> <%= fri.user.last_name %>
3 | <%= form_for fri do |friend| %> 4 | <%= hidden_field_tag "friend", fri %> 5 |
6 | <%= friend.submit "Confirm friend", class: "btn btn-success mt-1" %> 7 |
8 | <% end %> 9 |
-------------------------------------------------------------------------------- /app/views/friendships/_confirmed.html.erb: -------------------------------------------------------------------------------- 1 |
2 | User: <%= f.user.first_name %> <%= f.user.last_name %>
3 | <%= form_for f do |friend| %> 4 | <%= hidden_field_tag "friend", f %> 5 |
6 | <%= friend.submit "Confirm friend", class: "btn btn-success mt-1" %> 7 |
8 | <% end %> 9 |
-------------------------------------------------------------------------------- /app/views/friendships/index.html.erb: -------------------------------------------------------------------------------- 1 |

Friendship requests

2 | <% if unconfirmed_requests.size > 0 %> 3 | <% @inverse_friendships.each do |f| %> 4 | <%= confirm_friend(f) %> 5 | <% end %> 6 | <% else %> 7 |

You have no friendship requests

8 | <% end %> -------------------------------------------------------------------------------- /app/views/layouts/_bootstrap.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /app/views/layouts/_default.html.erb: -------------------------------------------------------------------------------- 1 | 2 | <%= csrf_meta_tags %> 3 | <%= csp_meta_tag %> 4 | 5 | <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> 6 | <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> 7 | 8 | -------------------------------------------------------------------------------- /app/views/layouts/_flash_msg.html.erb: -------------------------------------------------------------------------------- 1 | <% flash.each do |msg_type, msg| %> 2 | <%= content_tag(:div, msg, class: "alert alert-#{msg_type}")%> 3 | <% end %> 4 | <%#

<%= notice

%> 5 | <%#

<%= alert

%> -------------------------------------------------------------------------------- /app/views/layouts/_footer.html.erb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/addod19/facebook-clone/69faa6903893947c3d024ace61377ba711575f4a/app/views/layouts/_footer.html.erb -------------------------------------------------------------------------------- /app/views/layouts/_header.html.erb: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /app/views/layouts/application.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | FacebookClone 5 | <%= render 'layouts/bootstrap'%> 6 | <%= render 'layouts/default'%> 7 | 8 | 9 | 10 | <%= render 'layouts/header'%> 11 |
12 | <%= render 'layouts/flash_msg'%> 13 | <%= yield %> 14 | <%= render 'layouts/footer'%> 15 |
16 | <%#
%> 17 | <%#= debug(params) if Rails.env.development? %> 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/posts/_posts.html.erb: -------------------------------------------------------------------------------- 1 | <% @user_posts.each do |user_post| %> 2 |
3 | Author: <%= user_post.user.first_name %> <%= user_post.user.last_name %>
4 | <%= user_post.post_text %> 5 | <%= delete_button(user_post) %> 6 | 7 | <%= form_for @like do |f| %> 8 | <%= hidden_field_tag "user_id", "#{current_user.id}" %> 9 | <%= hidden_field_tag "post_id", "#{user_post.id}" %> 10 |
11 | <%= f.submit "Like", class: "form-control btn btn-success mt-1", id: "like-#{user_post.id}"%> 12 |
13 | <% end %> 14 | 15 | <%= user_post.likes.size %> 16 | 17 | <%= form_for [@comment] do |f| %> 18 | <%= hidden_field_tag "post_id", "#{user_post.id}" %> 19 |
20 | <%= f.label 'Comment' %>
21 | <%= f.text_area :comment_text, class: "form-control", placeholder: "Comment on this post...", id:"comment-#{user_post.id}" %> 22 |
23 |
24 | <%= f.submit "Create Comment", class: "form-control btn btn-success mt-1", id: "button-#{user_post.id}" %> 25 |
26 | <% end %> 27 |
28 | 29 | <%= post_comments(user_post)%> 30 | 31 | <% end %> -------------------------------------------------------------------------------- /app/views/posts/edit.html.erb: -------------------------------------------------------------------------------- 1 |

Edit post

-------------------------------------------------------------------------------- /app/views/posts/index.html.erb: -------------------------------------------------------------------------------- 1 | 2 |
3 |
4 |
5 |

Create Post

6 | <%= form_for(@post) do |f| %> 7 |
8 | 9 | <%= f.text_area :post_text, class: "form-control", placeholder: "What's on your mind, #{current_user.first_name}" %> 10 |
11 |
12 | <%= f.submit "Create Post", class: "form-control btn btn-success mt-1" %> 13 |
14 | <% end %> 15 |
16 |
17 |
18 | <%= render 'posts' %> 19 |
20 |
-------------------------------------------------------------------------------- /app/views/posts/new.html.erb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/addod19/facebook-clone/69faa6903893947c3d024ace61377ba711575f4a/app/views/posts/new.html.erb -------------------------------------------------------------------------------- /app/views/posts/show.html.erb: -------------------------------------------------------------------------------- 1 |

Showing post number #

2 | 3 | 4 |
5 | 6 |
7 |
8 |

Create Post

9 | <%= form_for(@post) do |f| %> 10 |
11 | <%= f.text_area :post_text, autofocus: true, class: "form-control", placeholder: "What's on your mind, #{current_user.first_name}" %> 12 |
13 |
14 | <%= f.submit "Create Post", class: "form-control btn btn-success mt-1" %> 15 |
16 | <% end %> 17 |
18 |
19 |
20 | <% @user_posts.each do |user_post| %> 21 |
22 | <%= user_post.user.first_name %>
23 | <%= user_post.post_text %> 24 | <%= button_to "delete", user_post, method: :delete, data: { confirm: "Are you sure?" }, class:"btn btn-danger btn-sm" %> 25 |
26 | <% end %> 27 |
-------------------------------------------------------------------------------- /app/views/users/_add_friend.html.erb: -------------------------------------------------------------------------------- 1 | <%= form_for @friendship do |f| %> 2 | <%= hidden_field_tag "friend_id", "#{user.id}" %> 3 | <%= hidden_field_tag "confirmed", "false" %> 4 |
5 | <%= f.submit "Add friend", class: "form-control btn btn-success mt-1" %> 6 |
7 | <% end %> -------------------------------------------------------------------------------- /app/views/users/_toggle_button.html.erb: -------------------------------------------------------------------------------- 1 | <%= form_for @friendship do |f| %> 2 | <%= hidden_field_tag "friend_id", "#{user.id}" %> 3 | <%= hidden_field_tag "confirmed", "false" %> 4 |
5 | <%= f.submit "Add friend", action: 'create', class: "form-control btn btn-success mt-1", id:"button-#{user.id}" %> 6 |
7 | <% end %> -------------------------------------------------------------------------------- /app/views/users/friends.html.erb: -------------------------------------------------------------------------------- 1 |

Friends

2 | 3 |
4 |
5 | <% if all_friends > 0 %> 6 | <% current_user.friends.each do |user| %> 7 |
8 | <%= user.first_name %> <%= user.last_name %> 9 | <%= delete_friend(user) %> 10 |
11 | <% end %> 12 | <% else %> 13 |

You have no friends yet

14 | <% end %> 15 |
16 |
-------------------------------------------------------------------------------- /app/views/users/index.html.erb: -------------------------------------------------------------------------------- 1 | 2 |
3 |
4 | <% @users.each do |user| %> 5 |
6 | <%= user.first_name %> <%= user.last_name %> 7 | <%= toggle_button(user) %> 8 |
9 | <% end %> 10 |
11 |
-------------------------------------------------------------------------------- /app/views/users/show.html.erb: -------------------------------------------------------------------------------- 1 | 2 |
3 |

Show page

4 |
5 | Username: <%= @user.first_name %> 6 |
7 | 8 |
-------------------------------------------------------------------------------- /bin/bundle: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) 3 | load Gem.bin_path('bundler', 'bundle') 4 | -------------------------------------------------------------------------------- /bin/rails: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 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 2 | require_relative '../config/boot' 3 | require 'rake' 4 | Rake.application.run 5 | -------------------------------------------------------------------------------- /bin/setup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require 'fileutils' 3 | include FileUtils 4 | 5 | # path to your application root. 6 | APP_ROOT = File.expand_path('..', __dir__) 7 | 8 | def system!(*args) 9 | system(*args) || abort("\n== Command #{args} failed ==") 10 | end 11 | 12 | chdir APP_ROOT do 13 | # This script is a starting point to setup your application. 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 | # Install JavaScript dependencies if using Yarn 21 | # system('bin/yarn') 22 | 23 | # puts "\n== Copying sample files ==" 24 | # unless File.exist?('config/database.yml') 25 | # cp 'config/database.yml.sample', 'config/database.yml' 26 | # end 27 | 28 | puts "\n== Preparing database ==" 29 | system! 'bin/rails db:setup' 30 | 31 | puts "\n== Removing old logs and tempfiles ==" 32 | system! 'bin/rails log:clear tmp:clear' 33 | 34 | puts "\n== Restarting application server ==" 35 | system! 'bin/rails restart' 36 | end 37 | -------------------------------------------------------------------------------- /bin/update: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require 'fileutils' 3 | include FileUtils 4 | 5 | # path to your application root. 6 | APP_ROOT = File.expand_path('..', __dir__) 7 | 8 | def system!(*args) 9 | system(*args) || abort("\n== Command #{args} failed ==") 10 | end 11 | 12 | chdir APP_ROOT do 13 | # This script is a way to update your development environment automatically. 14 | # Add necessary update steps to this file. 15 | 16 | puts '== Installing dependencies ==' 17 | system! 'gem install bundler --conservative' 18 | system('bundle check') || system!('bundle install') 19 | 20 | # Install JavaScript dependencies if using Yarn 21 | # system('bin/yarn') 22 | 23 | puts "\n== Updating database ==" 24 | system! 'bin/rails db:migrate' 25 | 26 | puts "\n== Removing old logs and tempfiles ==" 27 | system! 'bin/rails log:clear tmp:clear' 28 | 29 | puts "\n== Restarting application server ==" 30 | system! 'bin/rails restart' 31 | end 32 | -------------------------------------------------------------------------------- /bin/yarn: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | APP_ROOT = File.expand_path('..', __dir__) 3 | Dir.chdir(APP_ROOT) do 4 | begin 5 | exec "yarnpkg", *ARGV 6 | rescue Errno::ENOENT 7 | $stderr.puts "Yarn executable was not detected in the system." 8 | $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install" 9 | exit 1 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /config.ru: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # This file is used by Rack-based servers to start the application. 4 | 5 | require_relative 'config/environment' 6 | 7 | run Rails.application 8 | -------------------------------------------------------------------------------- /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 FacebookClone 10 | class Application < Rails::Application 11 | # Initialize configuration defaults for originally generated Rails version. 12 | config.load_defaults 5.2 13 | 14 | # Settings in config/environments/* take precedence over those specified here. 15 | # Application configuration can go into files in config/initializers 16 | # -- all .rb files in that directory are automatically loaded after loading 17 | # the framework and any gems in your application. 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /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: async 6 | 7 | production: 8 | adapter: redis 9 | url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %> 10 | channel_prefix: facebook-clone_production 11 | -------------------------------------------------------------------------------- /config/credentials.yml.enc: -------------------------------------------------------------------------------- 1 | sIwxYeG1hMmR5YGqfG/9Q+lX+PWlzKMHvjuihNpd9s9twwX6ochjJAtymwGoWyruoC8nyKYzPLQKPV3u/pnmzoelVif3037wDAFCTgTvq9BiOciFoYvndw+QPBTEvqf24ylbN50JN5V6VORj7pOnsiwoLEIPfEMKyOM2+PBm+vLmXUCgl7iKb+GwukiMC+ATZapwJumMbEC7vp4D6wNZSlo26UMgGg6yRVnNLETGnOnzFJoTa84qR3pxprvVlu2yzoMm3zOAzjl09Cz5rSCfwS+j/AilYP9pIsMIFJIw6xyRygvhjS6xlA1y+I5qRHqfWu6nrw1sm0r2xyN8gF9H9IkfiXumHw4w1udoY5723Ah02ceEGeC7sceAlD/e0J3Nx8ulpcb5QArZMF7I/8QZ3tESY4DG+AuPQvoR--/6kdJ92BziccxXc/--+yfrBD4U7ZhTHx9DgSXlmA== -------------------------------------------------------------------------------- /config/database.yml: -------------------------------------------------------------------------------- 1 | # PostgreSQL. Versions 9.1 and up are supported. 2 | # 3 | # Install the pg driver: 4 | # gem install pg 5 | # On OS X with Homebrew: 6 | # gem install pg -- --with-pg-config=/usr/local/bin/pg_config 7 | # On OS X 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 | # http://guides.rubyonrails.org/configuring.html#database-pooling 22 | pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> 23 | 24 | development: 25 | <<: *default 26 | database: fb_clone_development 27 | username: fb-clone 28 | password: foobar12345 29 | 30 | # The specified database role being used to connect to postgres. 31 | # To create additional roles in postgres see `$ createuser --help`. 32 | # When left blank, postgres will use the default role. This is 33 | # the same name as the operating system user that initialized the database. 34 | #username: facebook-clone 35 | # The password associated with the postgres role (username). 36 | #password: 37 | # Connect on a TCP socket. Omitted by default since the client uses a 38 | # domain socket that doesn't need configuration. Windows does not have 39 | # domain sockets, so uncomment these lines. 40 | #host: localhost 41 | # The TCP port the server listens on. Defaults to 5432. 42 | # If your server runs on a different port number, change accordingly. 43 | #port: 5432 44 | # Schema search path. The server defaults to $user,public 45 | #schema_search_path: myapp,sharedapp,public 46 | # Minimum log levels, in increasing order: 47 | # debug5, debug4, debug3, debug2, debug1, 48 | # log, notice, warning, error, fatal, and panic 49 | # Defaults to warning. 50 | #min_messages: notice 51 | 52 | # Warning: The database defined as "test" will be erased and 53 | # re-generated from your development database when you run "rake". 54 | # Do not set this db to the same as development or production. 55 | test: 56 | <<: *default 57 | database: fb_clone_test 58 | username: fb-clone 59 | password: foobar12345 60 | 61 | # As with config/secrets.yml, you never want to store sensitive information, 62 | # like your database password, in your source code. If your source code is 63 | # ever seen by anyone, they now have access to your database. 64 | # 65 | # Instead, provide the password as a unix environment variable when you boot 66 | # the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database 67 | # for a full rundown on how to provide these environment variables in a 68 | # production deployment. 69 | # 70 | # On Heroku and other platform providers, you may have a full connection URL 71 | # available as an environment variable. For example: 72 | # 73 | # DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase" 74 | # 75 | # You can use this database configuration with: 76 | # 77 | # production: 78 | # url: <%= ENV['DATABASE_URL'] %> 79 | # 80 | # production: 81 | # <<: *default 82 | # database: fb_clone_production 83 | # username: fb-clone 84 | # password: foobar12345 85 | production: 86 | <<: *default 87 | database: fb_production 88 | username: fb 89 | password: <%= ENV['FB_DATABASE_PASSWORD'] %> 90 | -------------------------------------------------------------------------------- /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 | # frozen_string_literal: true 2 | 3 | Rails.application.configure do 4 | # Settings specified here will take precedence over those in config/application.rb. 5 | 6 | # In the development environment your application's code is reloaded on 7 | # every request. This slows down response time but is perfect for development 8 | # since you don't have to restart the web server when you make code changes. 9 | config.cache_classes = false 10 | 11 | # Do not eager load code on boot. 12 | config.eager_load = false 13 | 14 | # Show full error reports. 15 | config.consider_all_requests_local = true 16 | 17 | # Enable/disable caching. By default caching is disabled. 18 | # Run rails dev:cache to toggle caching. 19 | if Rails.root.join('tmp', 'caching-dev.txt').exist? 20 | config.action_controller.perform_caching = true 21 | 22 | config.cache_store = :memory_store 23 | config.public_file_server.headers = { 24 | 'Cache-Control' => "public, max-age=#{2.days.to_i}" 25 | } 26 | else 27 | config.action_controller.perform_caching = false 28 | 29 | config.cache_store = :null_store 30 | end 31 | 32 | # Store uploaded files on the local file system (see config/storage.yml for options) 33 | config.active_storage.service = :local 34 | 35 | # Devise setup 36 | config.action_mailer.default_url_options = { host: 'localhost', port: 3000 } 37 | # Don't care if the mailer can't send. 38 | config.action_mailer.raise_delivery_errors = false 39 | 40 | config.action_mailer.perform_caching = false 41 | 42 | # Print deprecation notices to the Rails logger. 43 | config.active_support.deprecation = :log 44 | 45 | # Raise an error on page load if there are pending migrations. 46 | config.active_record.migration_error = :page_load 47 | 48 | # Highlight code that triggered database queries in logs. 49 | config.active_record.verbose_query_logs = true 50 | 51 | # Debug mode disables concatenation and preprocessing of assets. 52 | # This option may cause significant delays in view rendering with a large 53 | # number of complex assets. 54 | config.assets.debug = true 55 | 56 | # Suppress logger output for asset requests. 57 | config.assets.quiet = true 58 | 59 | # Raises error for missing translations 60 | # config.action_view.raise_on_missing_translations = true 61 | 62 | # Use an evented file watcher to asynchronously detect changes in source code, 63 | # routes, locales, etc. This feature depends on the listen gem. 64 | config.file_watcher = ActiveSupport::EventedFileUpdateChecker 65 | end 66 | -------------------------------------------------------------------------------- /config/environments/production.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 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 JavaScripts and CSS. 28 | config.assets.js_compressor = :uglifier 29 | # config.assets.css_compressor = :sass 30 | 31 | # Do not fallback to assets pipeline if a precompiled asset is missed. 32 | config.assets.compile = false 33 | 34 | # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb 35 | 36 | # Enable serving of images, stylesheets, and JavaScripts from an asset server. 37 | # config.action_controller.asset_host = 'http://assets.example.com' 38 | 39 | # Specifies the header that your server uses for sending files. 40 | # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache 41 | # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX 42 | 43 | # Store uploaded files on the local file system (see config/storage.yml for options) 44 | config.active_storage.service = :local 45 | 46 | # Mount Action Cable outside main process or domain 47 | # config.action_cable.mount_path = nil 48 | # config.action_cable.url = 'wss://example.com/cable' 49 | # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ] 50 | 51 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. 52 | # config.force_ssl = true 53 | 54 | # Use the lowest log level to ensure availability of diagnostic information 55 | # when problems arise. 56 | config.log_level = :debug 57 | 58 | # Prepend all log lines with the following tags. 59 | config.log_tags = [:request_id] 60 | 61 | # Use a different cache store in production. 62 | # config.cache_store = :mem_cache_store 63 | 64 | # Use a real queuing backend for Active Job (and separate queues per environment) 65 | # config.active_job.queue_adapter = :resque 66 | # config.active_job.queue_name_prefix = "facebook-clone_#{Rails.env}" 67 | 68 | config.action_mailer.perform_caching = false 69 | 70 | # Ignore bad email addresses and do not raise email delivery errors. 71 | # Set this to true and configure the email server for immediate delivery to raise delivery errors. 72 | # config.action_mailer.raise_delivery_errors = false 73 | 74 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to 75 | # the I18n.default_locale when a translation cannot be found). 76 | config.i18n.fallbacks = true 77 | 78 | # Send deprecation notices to registered listeners. 79 | config.active_support.deprecation = :notify 80 | 81 | # Use default logging formatter so that PID and timestamp are not suppressed. 82 | config.log_formatter = ::Logger::Formatter.new 83 | 84 | # Use a different logger for distributed setups. 85 | # require 'syslog/logger' 86 | # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') 87 | 88 | if ENV['RAILS_LOG_TO_STDOUT'].present? 89 | logger = ActiveSupport::Logger.new(STDOUT) 90 | logger.formatter = config.log_formatter 91 | config.logger = ActiveSupport::TaggedLogging.new(logger) 92 | end 93 | 94 | # Do not dump schema after migrations. 95 | config.active_record.dump_schema_after_migration = false 96 | end 97 | -------------------------------------------------------------------------------- /config/environments/test.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | Rails.application.configure do 4 | # Settings specified here will take precedence over those in config/application.rb. 5 | 6 | # The test environment is used exclusively to run your application's 7 | # test suite. You never need to work with it otherwise. Remember that 8 | # your test database is "scratch space" for the test suite and is wiped 9 | # and recreated between test runs. Don't rely on the data there! 10 | config.cache_classes = true 11 | 12 | # Do not eager load code on boot. This avoids loading your whole application 13 | # just for the purpose of running a single test. If you are using a tool that 14 | # preloads Rails for running tests, you may have to set it to true. 15 | config.eager_load = false 16 | 17 | # Configure public file server for tests with Cache-Control for performance. 18 | config.public_file_server.enabled = true 19 | config.public_file_server.headers = { 20 | 'Cache-Control' => "public, max-age=#{1.hour.to_i}" 21 | } 22 | 23 | # Show full error reports and disable caching. 24 | config.consider_all_requests_local = true 25 | config.action_controller.perform_caching = false 26 | 27 | # Raise exceptions instead of rendering exception templates. 28 | config.action_dispatch.show_exceptions = false 29 | 30 | # Disable request forgery protection in test environment. 31 | config.action_controller.allow_forgery_protection = false 32 | 33 | # Store uploaded files on the local file system in a temporary directory 34 | config.active_storage.service = :test 35 | 36 | config.action_mailer.perform_caching = false 37 | 38 | # Tell Action Mailer not to deliver emails to the real world. 39 | # The :test delivery method accumulates sent emails in the 40 | # ActionMailer::Base.deliveries array. 41 | config.action_mailer.delivery_method = :test 42 | 43 | # Print deprecation notices to the stderr. 44 | config.active_support.deprecation = :stderr 45 | 46 | # Raises error for missing translations 47 | # config.action_view.raise_on_missing_translations = true 48 | end 49 | -------------------------------------------------------------------------------- /config/initializers/application_controller_renderer.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # Be sure to restart your server when you modify this file. 4 | 5 | # ActiveSupport::Reloader.to_prepare do 6 | # ApplicationController.renderer.defaults.merge!( 7 | # http_host: 'example.org', 8 | # https: false 9 | # ) 10 | # end 11 | -------------------------------------------------------------------------------- /config/initializers/assets.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # Be sure to restart your server when you modify this file. 4 | 5 | # Version of your assets, change this if you want to expire all your assets. 6 | Rails.application.config.assets.version = '1.0' 7 | 8 | # Add additional assets to the asset load path. 9 | # Rails.application.config.assets.paths << Emoji.images_path 10 | # Add Yarn node_modules folder to the asset load path. 11 | Rails.application.config.assets.paths << Rails.root.join('node_modules') 12 | 13 | # Precompile additional assets. 14 | # application.js, application.css, and all non-JS/CSS in the app/assets 15 | # folder are already added. 16 | # Rails.application.config.assets.precompile += %w( admin.js admin.css ) 17 | -------------------------------------------------------------------------------- /config/initializers/backtrace_silencers.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # Be sure to restart your server when you modify this file. 4 | 5 | # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. 6 | # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } 7 | 8 | # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. 9 | # Rails.backtrace_cleaner.remove_silencers! 10 | -------------------------------------------------------------------------------- /config/initializers/content_security_policy.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # Be sure to restart your server when you modify this file. 4 | 5 | # Define an application-wide content security policy 6 | # For further information see the following documentation 7 | # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy 8 | 9 | # Rails.application.config.content_security_policy do |policy| 10 | # policy.default_src :self, :https 11 | # policy.font_src :self, :https, :data 12 | # policy.img_src :self, :https, :data 13 | # policy.object_src :none 14 | # policy.script_src :self, :https 15 | # policy.style_src :self, :https 16 | 17 | # # Specify URI for violation reports 18 | # # policy.report_uri "/csp-violation-report-endpoint" 19 | # end 20 | 21 | # If you are using UJS then enable automatic nonce generation 22 | # Rails.application.config.content_security_policy_nonce_generator = -> request { SecureRandom.base64(16) } 23 | 24 | # Report CSP violations to a specified URI 25 | # For further information see the following documentation: 26 | # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only 27 | # Rails.application.config.content_security_policy_report_only = true 28 | -------------------------------------------------------------------------------- /config/initializers/cookies_serializer.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # Be sure to restart your server when you modify this file. 4 | 5 | # Specify a serializer for the signed and encrypted cookie jars. 6 | # Valid options are :json, :marshal, and :hybrid. 7 | Rails.application.config.action_dispatch.cookies_serializer = :json 8 | -------------------------------------------------------------------------------- /config/initializers/devise.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # Use this hook to configure devise mailer, warden hooks and so forth. 4 | # Many of these configuration options can be set straight in your model. 5 | Devise.setup do |config| 6 | # The secret key used by Devise. Devise uses this key to generate 7 | # random tokens. Changing this key will render invalid all existing 8 | # confirmation, reset password and unlock tokens in the database. 9 | # Devise will use the `secret_key_base` as its `secret_key` 10 | # by default. You can change it below and use your own secret key. 11 | # config.secret_key = 'a665e0b8559c28a3cd793e0d6aa36822780b941169d2d46a95d79bc76 12 | # c4d38b003c307dd601b679d8ae60510449e265244af73fd01202c69d8cb75692a60fedc' 13 | 14 | # ==> Controller configuration 15 | # Configure the parent class to the devise controllers. 16 | # config.parent_controller = 'DeviseController' 17 | 18 | # ==> Mailer Configuration 19 | # Configure the e-mail address which will be shown in Devise::Mailer, 20 | # note that it will be overwritten if you use your own mailer class 21 | # with default "from" parameter. 22 | config.mailer_sender = 'please-change-me-at-config-initializers-devise@example.com' 23 | 24 | # Configure the class responsible to send e-mails. 25 | # config.mailer = 'Devise::Mailer' 26 | 27 | # Configure the parent class responsible to send e-mails. 28 | # config.parent_mailer = 'ActionMailer::Base' 29 | 30 | # ==> ORM configuration 31 | # Load and configure the ORM. Supports :active_record (default) and 32 | # :mongoid (bson_ext recommended) by default. Other ORMs may be 33 | # available as additional gems. 34 | require 'devise/orm/active_record' 35 | 36 | # ==> Configuration for any authentication mechanism 37 | # Configure which keys are used when authenticating a user. The default is 38 | # just :email. You can configure it to use [:username, :subdomain], so for 39 | # authenticating a user, both parameters are required. Remember that those 40 | # parameters are used only when authenticating and not when retrieving from 41 | # session. If you need permissions, you should implement that in a before filter. 42 | # You can also supply a hash where the value is a boolean determining whether 43 | # or not authentication should be aborted when the value is not present. 44 | # config.authentication_keys = [:email] 45 | 46 | # Configure parameters from the request object used for authentication. Each entry 47 | # given should be a request method and it will automatically be passed to the 48 | # find_for_authentication method and considered in your model lookup. For instance, 49 | # if you set :request_keys to [:subdomain], :subdomain will be used on authentication. 50 | # The same considerations mentioned for authentication_keys also apply to request_keys. 51 | # config.request_keys = [] 52 | 53 | # Configure which authentication keys should be case-insensitive. 54 | # These keys will be downcased upon creating or modifying a user and when used 55 | # to authenticate or find a user. Default is :email. 56 | config.case_insensitive_keys = [:email] 57 | 58 | # Configure which authentication keys should have whitespace stripped. 59 | # These keys will have whitespace before and after removed upon creating or 60 | # modifying a user and when used to authenticate or find a user. Default is :email. 61 | config.strip_whitespace_keys = [:email] 62 | 63 | # Tell if authentication through request.params is enabled. True by default. 64 | # It can be set to an array that will enable params authentication only for the 65 | # given strategies, for example, `config.params_authenticatable = [:database]` will 66 | # enable it only for database (email + password) authentication. 67 | # config.params_authenticatable = true 68 | 69 | # Tell if authentication through HTTP Auth is enabled. False by default. 70 | # It can be set to an array that will enable http authentication only for the 71 | # given strategies, for example, `config.http_authenticatable = [:database]` will 72 | # enable it only for database authentication. The supported strategies are: 73 | # :database = Support basic authentication with authentication key + password 74 | # config.http_authenticatable = true 75 | # config.http_authenticatable = [:database] 76 | # If 401 status code should be returned for AJAX requests. True by default. 77 | # config.http_authenticatable_on_xhr = true 78 | 79 | # The realm used in Http Basic Authentication. 'Application' by default. 80 | # config.http_authentication_realm = 'Application' 81 | 82 | # It will change confirmation, password recovery and other workflows 83 | # to behave the same regardless if the e-mail provided was right or wrong. 84 | # Does not affect registerable. 85 | # config.paranoid = true 86 | 87 | # By default Devise will store the user in session. You can skip storage for 88 | # particular strategies by setting this option. 89 | # Notice that if you are skipping storage for all authentication paths, you 90 | # may want to disable generating routes to Devise's sessions controller by 91 | # passing skip: :sessions to `devise_for` in your config/routes.rb 92 | config.skip_session_storage = [:http_auth] 93 | 94 | # By default, Devise cleans up the CSRF token on authentication to 95 | # avoid CSRF token fixation attacks. This means that, when using AJAX 96 | # requests for sign in and sign up, you need to get a new CSRF token 97 | # from the server. You can disable this option at your own risk. 98 | # config.clean_up_csrf_token_on_authentication = true 99 | 100 | # When false, Devise will not attempt to reload routes on eager load. 101 | # This can reduce the time taken to boot the app but if your application 102 | # requires the Devise mappings to be loaded during boot time the application 103 | # won't boot properly. 104 | # config.reload_routes = true 105 | 106 | # ==> Configuration for :database_authenticatable 107 | # For bcrypt, this is the cost for hashing the password and defaults to 11. If 108 | # using other algorithms, it sets how many times you want the password to be hashed. 109 | # 110 | # Limiting the stretches to just one in testing will increase the performance of 111 | # your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use 112 | # a value less than 10 in other environments. Note that, for bcrypt (the default 113 | # algorithm), the cost increases exponentially with the number of stretches (e.g. 114 | # a value of 20 is already extremely slow: approx. 60 seconds for 1 calculation). 115 | config.stretches = Rails.env.test? ? 1 : 11 116 | 117 | # Set up a pepper to generate the hashed password. 118 | # config.pepper = 'ff4e3002573751ecb6f5362cfc272d895a4c71d12e68f9f1333a987f542d598c36416ac86ee2c 119 | # a6d8fe3132bbcd2509de4e3a445880e250b3584eac39573ce54' 120 | 121 | # Send a notification to the original email when the user's email is changed. 122 | # config.send_email_changed_notification = false 123 | 124 | # Send a notification email when the user's password is changed. 125 | # config.send_password_change_notification = false 126 | 127 | # ==> Configuration for :confirmable 128 | # A period that the user is allowed to access the website even without 129 | # confirming their account. For instance, if set to 2.days, the user will be 130 | # able to access the website for two days without confirming their account, 131 | # access will be blocked just in the third day. 132 | # You can also set it to nil, which will allow the user to access the website 133 | # without confirming their account. 134 | # Default is 0.days, meaning the user cannot access the website without 135 | # confirming their account. 136 | # config.allow_unconfirmed_access_for = 2.days 137 | 138 | # A period that the user is allowed to confirm their account before their 139 | # token becomes invalid. For example, if set to 3.days, the user can confirm 140 | # their account within 3 days after the mail was sent, but on the fourth day 141 | # their account can't be confirmed with the token any more. 142 | # Default is nil, meaning there is no restriction on how long a user can take 143 | # before confirming their account. 144 | # config.confirm_within = 3.days 145 | 146 | # If true, requires any email changes to be confirmed (exactly the same way as 147 | # initial account confirmation) to be applied. Requires additional unconfirmed_email 148 | # db field (see migrations). Until confirmed, new email is stored in 149 | # unconfirmed_email column, and copied to email column on successful confirmation. 150 | config.reconfirmable = true 151 | 152 | # Defines which key will be used when confirming an account 153 | # config.confirmation_keys = [:email] 154 | 155 | # ==> Configuration for :rememberable 156 | # The time the user will be remembered without asking for credentials again. 157 | # config.remember_for = 2.weeks 158 | 159 | # Invalidates all the remember me tokens when the user signs out. 160 | config.expire_all_remember_me_on_sign_out = true 161 | 162 | # If true, extends the user's remember period when remembered via cookie. 163 | # config.extend_remember_period = false 164 | 165 | # Options to be passed to the created cookie. For instance, you can set 166 | # secure: true in order to force SSL only cookies. 167 | # config.rememberable_options = {} 168 | 169 | # ==> Configuration for :validatable 170 | # Range for password length. 171 | config.password_length = 6..128 172 | 173 | # Email regex used to validate email formats. It simply asserts that 174 | # one (and only one) @ exists in the given string. This is mainly 175 | # to give user feedback and not to assert the e-mail validity. 176 | config.email_regexp = /\A[^@\s]+@[^@\s]+\z/ 177 | 178 | # ==> Configuration for :timeoutable 179 | # The time you want to timeout the user session without activity. After this 180 | # time the user will be asked for credentials again. Default is 30 minutes. 181 | # config.timeout_in = 30.minutes 182 | 183 | # ==> Configuration for :lockable 184 | # Defines which strategy will be used to lock an account. 185 | # :failed_attempts = Locks an account after a number of failed attempts to sign in. 186 | # :none = No lock strategy. You should handle locking by yourself. 187 | # config.lock_strategy = :failed_attempts 188 | 189 | # Defines which key will be used when locking and unlocking an account 190 | # config.unlock_keys = [:email] 191 | 192 | # Defines which strategy will be used to unlock an account. 193 | # :email = Sends an unlock link to the user email 194 | # :time = Re-enables login after a certain amount of time (see :unlock_in below) 195 | # :both = Enables both strategies 196 | # :none = No unlock strategy. You should handle unlocking by yourself. 197 | # config.unlock_strategy = :both 198 | 199 | # Number of authentication tries before locking an account if lock_strategy 200 | # is failed attempts. 201 | # config.maximum_attempts = 20 202 | 203 | # Time interval to unlock the account if :time is enabled as unlock_strategy. 204 | # config.unlock_in = 1.hour 205 | 206 | # Warn on the last attempt before the account is locked. 207 | # config.last_attempt_warning = true 208 | 209 | # ==> Configuration for :recoverable 210 | # 211 | # Defines which key will be used when recovering the password for an account 212 | # config.reset_password_keys = [:email] 213 | 214 | # Time interval you can reset your password with a reset password key. 215 | # Don't put a too small interval or your users won't have the time to 216 | # change their passwords. 217 | config.reset_password_within = 6.hours 218 | 219 | # When set to false, does not sign a user in automatically after their password is 220 | # reset. Defaults to true, so a user is signed in automatically after a reset. 221 | # config.sign_in_after_reset_password = true 222 | 223 | # ==> Configuration for :encryptable 224 | # Allow you to use another hashing or encryption algorithm besides bcrypt (default). 225 | # You can use :sha1, :sha512 or algorithms from others authentication tools as 226 | # :clearance_sha1, :authlogic_sha512 (then you should set stretches above to 20 227 | # for default behavior) and :restful_authentication_sha1 (then you should set 228 | # stretches to 10, and copy REST_AUTH_SITE_KEY to pepper). 229 | # 230 | # Require the `devise-encryptable` gem when using anything other than bcrypt 231 | # config.encryptor = :sha512 232 | 233 | # ==> Scopes configuration 234 | # Turn scoped views on. Before rendering "sessions/new", it will first check for 235 | # "users/sessions/new". It's turned off by default because it's slower if you 236 | # are using only default views. 237 | # config.scoped_views = false 238 | 239 | # Configure the default scope given to Warden. By default it's the first 240 | # devise role declared in your routes (usually :user). 241 | # config.default_scope = :user 242 | 243 | # Set this configuration to false if you want /users/sign_out to sign out 244 | # only the current scope. By default, Devise signs out all scopes. 245 | # config.sign_out_all_scopes = true 246 | 247 | # ==> Navigation configuration 248 | # Lists the formats that should be treated as navigational. Formats like 249 | # :html, should redirect to the sign in page when the user does not have 250 | # access, but formats like :xml or :json, should return 401. 251 | # 252 | # If you have any extra navigational formats, like :iphone or :mobile, you 253 | # should add them to the navigational formats lists. 254 | # 255 | # The "*/*" below is required to match Internet Explorer requests. 256 | # config.navigational_formats = ['*/*', :html] 257 | 258 | # The default HTTP method used to sign out a resource. Default is :delete. 259 | config.sign_out_via = :delete 260 | 261 | # ==> OmniAuth 262 | # Add a new OmniAuth provider. Check the wiki for more information on setting 263 | # up on your models and hooks. 264 | <<<<<<< HEAD 265 | config.omniauth :facebook, '3451859098219919', 'a640e7cb82ee1f48b88775ad4686525c', callback_url: 'https://secret-sea-76381.herokuapp.com/auth/facebook/callback' 266 | 267 | # ==> Warden configuration 268 | ======= 269 | # config.omniauth :facebook, '3451859098219919', 'a640e7cb82ee1f48b88775ad4686525c', callback_url: 'https://secret-sea-76381.herokuapp.com/auth/facebook/callback' 270 | config.omniauth :facebook, ENV['FACEBOOK_KEY'], ENV['FACEBOOK_SECRET'], callback_url: 'https://secret-sea-76381.herokuapp.com/users/auth/facebook/callback' 271 | # ==> Warden configuration 272 | >>>>>>> master 273 | # If you want to use other strategies, that are not supported by Devise, or 274 | # change the failure app, you can configure them inside the config.warden block. 275 | # 276 | # config.warden do |manager| 277 | # manager.intercept_401 = false 278 | # manager.default_strategies(scope: :user).unshift :some_external_strategy 279 | # end 280 | 281 | # ==> Mountable engine configurations 282 | # When using Devise inside an engine, let's call it `MyEngine`, and this engine 283 | # is mountable, there are some extra configurations to be taken into account. 284 | # The following options are available, assuming the engine is mounted as: 285 | # 286 | # mount MyEngine, at: '/my_engine' 287 | # 288 | # The router that invoked `devise_for`, in the example above, would be: 289 | # config.router_name = :my_engine 290 | # 291 | # When using OmniAuth, Devise cannot automatically set OmniAuth path, 292 | # so you need to do it manually. For the users scope, it would be: 293 | # config.omniauth_path_prefix = '/my_engine/users/auth' 294 | 295 | # ==> Turbolinks configuration 296 | # If your app is using Turbolinks, Turbolinks::Controller needs to be included to make redirection work correctly: 297 | # 298 | # ActiveSupport.on_load(:devise_failure_app) do 299 | # include Turbolinks::Controller 300 | # end 301 | 302 | # ==> Configuration for :registerable 303 | 304 | # When set to false, does not sign a user in automatically after their password is 305 | # changed. Defaults to true, so a user is signed in automatically after changing a password. 306 | # config.sign_in_after_change_password = true 307 | end 308 | -------------------------------------------------------------------------------- /config/initializers/filter_parameter_logging.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # Be sure to restart your server when you modify this file. 4 | 5 | # Configure sensitive parameters which will be filtered from the log file. 6 | Rails.application.config.filter_parameters += [:password] 7 | -------------------------------------------------------------------------------- /config/initializers/inflections.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # Be sure to restart your server when you modify this file. 4 | 5 | # Add new inflection rules using the following format. Inflections 6 | # are locale specific, and you may define rules for as many different 7 | # locales as you wish. All of these examples are active by default: 8 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 9 | # inflect.plural /^(ox)$/i, '\1en' 10 | # inflect.singular /^(ox)en/i, '\1' 11 | # inflect.irregular 'person', 'people' 12 | # inflect.uncountable %w( fish sheep ) 13 | # end 14 | 15 | # These inflection rules are supported but not enabled by default: 16 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 17 | # inflect.acronym 'RESTful' 18 | # end 19 | -------------------------------------------------------------------------------- /config/initializers/mime_types.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # Be sure to restart your server when you modify this file. 4 | 5 | # Add new mime types for use in respond_to blocks: 6 | # Mime::Type.register "text/richtext", :rtf 7 | -------------------------------------------------------------------------------- /config/initializers/wrap_parameters.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # Be sure to restart your server when you modify this file. 4 | 5 | # This file contains settings for ActionController::ParamsWrapper which 6 | # is enabled by default. 7 | 8 | # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. 9 | ActiveSupport.on_load(:action_controller) do 10 | wrap_parameters format: [:json] 11 | end 12 | 13 | # To enable root element in JSON for ActiveRecord objects. 14 | # ActiveSupport.on_load(:active_record) do 15 | # self.include_root_in_json = true 16 | # end 17 | -------------------------------------------------------------------------------- /config/locales/devise.en.yml: -------------------------------------------------------------------------------- 1 | # Additional translations at https://github.com/plataformatec/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 http://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 | workers Integer(ENV['WEB_CONCURRENCY'] || 2) 8 | threads_count = Integer(ENV['RAILS_MAX_THREADS'] || 5) 9 | threads threads_count, threads_count 10 | 11 | preload_app! 12 | 13 | rackup DefaultRackup 14 | port ENV['PORT'] || 3000 15 | environment ENV['RACK_ENV'] || 'development' 16 | 17 | on_worker_boot do 18 | # Worker specific setup for Rails 4.1+ 19 | # See: https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server#on-worker-boot 20 | ActiveRecord::Base.establish_connection 21 | end 22 | 23 | # threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } 24 | # threads threads_count, threads_count 25 | 26 | # Specifies the `port` that Puma will listen on to receive requests; default is 3000. 27 | # 28 | # port ENV.fetch("PORT") { 3000 } 29 | 30 | # Specifies the `environment` that Puma will run in. 31 | # 32 | # environment ENV.fetch("RAILS_ENV") { "development" } 33 | 34 | # Specifies the number of `workers` to boot in clustered mode. 35 | # Workers are forked webserver processes. If using threads and workers together 36 | # the concurrency of the application would be max `threads` * `workers`. 37 | # Workers do not work on JRuby or Windows (both of which do not support 38 | # processes). 39 | # 40 | # workers ENV.fetch("WEB_CONCURRENCY") { 2 } 41 | 42 | # Use the `preload_app!` method when specifying a `workers` number. 43 | # This directive tells Puma to first boot the application and load code 44 | # before forking the application. This takes advantage of Copy On Write 45 | # process behavior so workers use less memory. 46 | # 47 | # preload_app! 48 | 49 | # Allow puma to be restarted by `rails restart` command. 50 | plugin :tmp_restart 51 | -------------------------------------------------------------------------------- /config/routes.rb: -------------------------------------------------------------------------------- 1 | Rails.application.routes.draw do 2 | 3 | root to: 'users#index' 4 | # root to: "devise/registrations#new" 5 | devise_for :users, controllers: { omniauth_callbacks: 'users/omniauth_callbacks' } 6 | resources :users, only: [:index, :show] 7 | resources :posts 8 | resources :comments#, only: [:create, :show] 9 | resources :likes 10 | 11 | post '/cancelfriend', to: 'friendships#cancel', as: 'cancelfriend' 12 | post '/acceptfriend', to: 'friendships#create' 13 | post '/deletefriend', to: 'friendships#destroy' 14 | resources :friendships, only: [:index, :show, :update] 15 | get 'friends', to: 'users#friends' 16 | # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html 17 | end 18 | -------------------------------------------------------------------------------- /config/spring.rb: -------------------------------------------------------------------------------- 1 | %w[ 2 | .ruby-version 3 | .rbenv-vars 4 | tmp/restart.txt 5 | tmp/caching-dev.txt 6 | ].each { |path| Spring.watch(path) } 7 | -------------------------------------------------------------------------------- /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 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 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 23 | 24 | # Use 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 30 | 31 | # mirror: 32 | # service: Mirror 33 | # primary: local 34 | # mirrors: [ amazon, google, microsoft ] 35 | -------------------------------------------------------------------------------- /db/migrate/20191218100616_devise_create_users.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class DeviseCreateUsers < ActiveRecord::Migration[5.2] 4 | def change 5 | create_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.inet :current_sign_in_ip 22 | # t.inet :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 | t.timestamps null: false 36 | end 37 | 38 | add_index :users, :email, unique: true 39 | add_index :users, :reset_password_token, unique: true 40 | # add_index :users, :confirmation_token, unique: true 41 | # add_index :users, :unlock_token, unique: true 42 | end 43 | end 44 | -------------------------------------------------------------------------------- /db/migrate/20191218101601_add_name_to_user.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class AddNameToUser < ActiveRecord::Migration[5.2] 4 | def change 5 | add_column :users, :first_name, :string 6 | add_column :users, :last_name, :string 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /db/migrate/20191220094351_create_posts.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class CreatePosts < ActiveRecord::Migration[5.2] 4 | def change 5 | create_table :posts do |t| 6 | t.text :post_text 7 | t.integer :user_id 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /db/migrate/20200110091652_create_comments.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class CreateComments < ActiveRecord::Migration[5.2] 4 | def change 5 | create_table :comments do |t| 6 | t.references :user 7 | t.references :post 8 | t.text :comment_text 9 | 10 | t.timestamps 11 | end 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /db/migrate/20200113135148_create_likes.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class CreateLikes < ActiveRecord::Migration[5.2] 4 | def change 5 | create_table :likes do |t| 6 | t.references :user, foreign_key: true 7 | t.references :post, foreign_key: true 8 | 9 | t.timestamps 10 | end 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /db/migrate/20200116091354_create_friendships.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class CreateFriendships < ActiveRecord::Migration[5.2] 4 | def change 5 | create_table :friendships do |t| 6 | t.references :user, index: true, foreign_key: true 7 | t.references :friend, index: true 8 | t.boolean :confirmed 9 | 10 | t.timestamps 11 | end 12 | add_foreign_key :friendships, :users, column: :friend_id 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /db/migrate/20200124103907_add_omniauth_to_users.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class AddOmniauthToUsers < ActiveRecord::Migration[5.2] 4 | def change 5 | add_column :users, :provider, :string 6 | add_column :users, :uid, :string 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /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 | # Note that this schema.rb definition is the authoritative source for your 6 | # database schema. If you need to create the application database on another 7 | # system, you should be using db:schema:load, not running all the migrations 8 | # from scratch. The latter is a flawed and unsustainable approach (the more migrations 9 | # you'll amass, the slower it'll run and the greater likelihood for issues). 10 | # 11 | # It's strongly recommended that you check this file into your version control system. 12 | 13 | ActiveRecord::Schema.define(version: 2020_01_24_103907) do 14 | 15 | # These are extensions that must be enabled in order to support this database 16 | enable_extension "plpgsql" 17 | 18 | create_table "comments", force: :cascade do |t| 19 | t.bigint "user_id" 20 | t.bigint "post_id" 21 | t.text "comment_text" 22 | t.datetime "created_at", null: false 23 | t.datetime "updated_at", null: false 24 | t.index ["post_id"], name: "index_comments_on_post_id" 25 | t.index ["user_id"], name: "index_comments_on_user_id" 26 | end 27 | 28 | create_table "friendships", force: :cascade do |t| 29 | t.bigint "user_id" 30 | t.bigint "friend_id" 31 | t.boolean "confirmed" 32 | t.datetime "created_at", null: false 33 | t.datetime "updated_at", null: false 34 | t.index ["friend_id"], name: "index_friendships_on_friend_id" 35 | t.index ["user_id"], name: "index_friendships_on_user_id" 36 | end 37 | 38 | create_table "likes", force: :cascade do |t| 39 | t.bigint "user_id" 40 | t.bigint "post_id" 41 | t.datetime "created_at", null: false 42 | t.datetime "updated_at", null: false 43 | t.index ["post_id"], name: "index_likes_on_post_id" 44 | t.index ["user_id"], name: "index_likes_on_user_id" 45 | end 46 | 47 | create_table "posts", force: :cascade do |t| 48 | t.text "post_text" 49 | t.integer "user_id" 50 | end 51 | 52 | create_table "users", force: :cascade do |t| 53 | t.string "email", default: "", null: false 54 | t.string "encrypted_password", default: "", null: false 55 | t.string "reset_password_token" 56 | t.datetime "reset_password_sent_at" 57 | t.datetime "remember_created_at" 58 | t.datetime "created_at", null: false 59 | t.datetime "updated_at", null: false 60 | t.string "first_name" 61 | t.string "last_name" 62 | t.string "provider" 63 | t.string "uid" 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 "friendships", "users" 69 | add_foreign_key "friendships", "users", column: "friend_id" 70 | add_foreign_key "likes", "posts" 71 | add_foreign_key "likes", "users" 72 | end 73 | -------------------------------------------------------------------------------- /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 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 | User.create( 9 | first_name: "Nick", 10 | last_name: "Haras", 11 | email: 'nick@test.com' , 12 | password: '123456' , 13 | password_confirmation: '123456' 14 | ) 15 | 16 | User.create( 17 | first_name: "Daniel", 18 | last_name: "Addo", 19 | email: 'daniel@test.com' , 20 | password: '123456' , 21 | password_confirmation: '123456' 22 | ) 23 | 24 | User.create( 25 | first_name: "Michael", 26 | last_name: "Schumacher", 27 | email: 'michael@test.com' , 28 | password: '123456' , 29 | password_confirmation: '123456' 30 | ) 31 | 32 | Post.create( post_text: 'Seed first post' , 33 | user_id: 1 ) 34 | 35 | Post.create( post_text: 'Seed Second post' , 36 | user_id: 2) -------------------------------------------------------------------------------- /docs/Milestone 1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/addod19/facebook-clone/69faa6903893947c3d024ace61377ba711575f4a/docs/Milestone 1.pdf -------------------------------------------------------------------------------- /lib/assets/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/addod19/facebook-clone/69faa6903893947c3d024ace61377ba711575f4a/lib/assets/.keep -------------------------------------------------------------------------------- /lib/tasks/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/addod19/facebook-clone/69faa6903893947c3d024ace61377ba711575f4a/lib/tasks/.keep -------------------------------------------------------------------------------- /log/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/addod19/facebook-clone/69faa6903893947c3d024ace61377ba711575f4a/log/.keep -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "facebook-clone", 3 | "private": true, 4 | "dependencies": {} 5 | } 6 | -------------------------------------------------------------------------------- /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/addod19/facebook-clone/69faa6903893947c3d024ace61377ba711575f4a/public/apple-touch-icon-precomposed.png -------------------------------------------------------------------------------- /public/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/addod19/facebook-clone/69faa6903893947c3d024ace61377ba711575f4a/public/apple-touch-icon.png -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/addod19/facebook-clone/69faa6903893947c3d024ace61377ba711575f4a/public/favicon.ico -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file 2 | -------------------------------------------------------------------------------- /spec/controllers/likes_controller_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'rails_helper' 4 | 5 | RSpec.describe LikesController, type: :controller do 6 | end 7 | -------------------------------------------------------------------------------- /spec/features/comment_create_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'rails_helper' 4 | require 'spec_helper' 5 | 6 | feature 'Comments can be created' do 7 | scenario 'successfully' do 8 | visit '/users/sign_in' 9 | fill_in 'Email', with: 'nick@test.com' 10 | fill_in 'Password', with: '123456' 11 | click_button 'Log in' 12 | visit '/posts' 13 | fill_in 'comment-1', with: 'This is a test comment' 14 | click_button 'button-1' 15 | expect(page).to have_content('This is a test comment') 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /spec/features/friendship_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'rails_helper' 4 | require 'spec_helper' 5 | 6 | RSpec.describe 'Testing friend request send, confirm and remove' do 7 | feature 'User can' do 8 | scenario 'send friend request successfully' do 9 | visit '/users/sign_in' 10 | fill_in 'Email', with: 'nick@test.com' 11 | fill_in 'Password', with: '123456' 12 | click_button 'Log in' 13 | visit root_path 14 | click_button 'button-2' 15 | expect(page).to have_content('Friend request sent successfully') 16 | end 17 | 18 | scenario 'confirm friend request successfully' do 19 | visit '/users/sign_in' 20 | fill_in 'Email', with: 'daniel@test.com' 21 | fill_in 'Password', with: '123456' 22 | click_button 'Log in' 23 | visit friendships_path 24 | click_button 'Confirm friend' 25 | expect(page).to have_content('Friendship confirmed') 26 | end 27 | end 28 | 29 | feature 'User can' do 30 | scenario 'remove friend successfully' do 31 | visit '/users/sign_in' 32 | fill_in 'Email', with: 'daniel@test.com' 33 | fill_in 'Password', with: '123456' 34 | click_button 'Log in' 35 | visit '/friends' 36 | click_button 'button-1' 37 | expect(page).to have_content('Friend removed successfully') 38 | end 39 | end 40 | end 41 | -------------------------------------------------------------------------------- /spec/features/like_post_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'rails_helper' 4 | require 'spec_helper' 5 | 6 | feature 'User can like post' do 7 | scenario 'successfully' do 8 | visit '/users/sign_in' 9 | fill_in 'Email', with: 'nick@test.com' 10 | fill_in 'Password', with: '123456' 11 | click_button 'Log in' 12 | visit '/posts' 13 | click_button 'like-1' 14 | expect(page).to have_text('1') 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /spec/features/post_create_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # require 'rails_helper' 4 | # require 'spec_helper' 5 | 6 | # feature 'User can create a Post' do 7 | # scenario 'Successfully' do 8 | # visit '/posts/' 9 | # fill_in 'Post', with: 'This is a test post' 10 | # click_button 'Create Post' 11 | # expect(page).to have_content('This is a test post') 12 | # end 13 | 14 | # end 15 | -------------------------------------------------------------------------------- /spec/features/user_actions_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'rails_helper' 4 | require 'spec_helper' 5 | 6 | def rnd_str 7 | (0...8).map { rand(97..122).chr }.join.capitalize 8 | end 9 | 10 | fname = rnd_str 11 | 12 | feature 'User' do 13 | scenario 'can create an account using the signup form' do 14 | visit '/users/sign_up' 15 | fill_in 'First name', with: fname 16 | fill_in 'Last name', with: rnd_str 17 | fill_in 'Email', with: "#{fname}@test.com" 18 | fill_in 'Password', with: 'foobar' 19 | fill_in 'Password confirmation', with: 'foobar' 20 | click_button 'Sign up' 21 | expect(page).to have_content('Welcome! You have signed up successfully') 22 | end 23 | 24 | scenario 'can log in using the log in form' do 25 | visit '/users/sign_in' 26 | fill_in 'Email', with: "#{fname}@test.com" 27 | fill_in 'Password', with: 'foobar' 28 | click_button 'Log in' 29 | expect(page).to have_content('Signed in successfully.') 30 | end 31 | end 32 | 33 | feature 'User also' do 34 | scenario 'can create a post' do 35 | visit '/users/sign_in' 36 | fill_in 'Email', with: "#{fname}@test.com" 37 | fill_in 'Password', with: 'foobar' 38 | click_button 'Log in' 39 | visit '/posts' 40 | fill_in 'post_post_text', with: 'This is a test post' 41 | click_button 'Create Post' 42 | expect(page).to have_content('This is a test post') 43 | end 44 | end 45 | -------------------------------------------------------------------------------- /spec/models/comment_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'rails_helper' 4 | 5 | RSpec.describe Comment, type: :model do 6 | before(:all) do 7 | @comment = Comment.new(comment_text: 'this is a test', post_id: 1, user_id: 1) 8 | end 9 | 10 | context 'validates comment field' do 11 | it 'is not valid without a comment text' do 12 | @comment.comment_text = nil 13 | @comment.save 14 | expect(@comment.errors.full_messages).to include("Comment text can't be blank") 15 | @comment.comment_text = 'Some text for the comment' 16 | end 17 | 18 | it 'is not valid without a user_id' do 19 | @comment.user_id = nil 20 | @comment.save 21 | expect(@comment.errors.full_messages).to include('User must exist') 22 | end 23 | 24 | it 'is not valid without a post_id' do 25 | @comment.post_id = nil 26 | @comment.save 27 | expect(@comment.errors.full_messages).to include('Post must exist') 28 | end 29 | end 30 | end 31 | -------------------------------------------------------------------------------- /spec/models/friendship_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'rails_helper' 4 | 5 | RSpec.describe Friendship, type: :model do 6 | before :each do 7 | @user1 = User.create(first_name: 'daniel', last_name: 'addo', email: 'daniel@test.com', password: '123456') 8 | @user2 = User.create(first_name: 'nick', last_name: 'haras', email: 'nick@test.com', password: '123456') 9 | end 10 | 11 | describe '#sender' do 12 | it 'have receiver' do 13 | request = @user2.friendships.build 14 | request.valid? 15 | expect(request.errors.full_messages).to include('Friend must exist') 16 | 17 | request = Friendship.new(user_id: @user1.id, friend_id: @user2.id) 18 | expect(request.valid?).to be(true) 19 | expect(request.errors.full_messages).to be_empty 20 | end 21 | 22 | it 'creates friendship request' do 23 | request = Friendship.new(user_id: @user1.id, friend_id: @user2.id) 24 | expect(request.valid?).to be(true) 25 | expect(request.user_id).to be @user1.id 26 | end 27 | end 28 | end 29 | -------------------------------------------------------------------------------- /spec/models/like_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'rails_helper' 4 | 5 | RSpec.describe Like, type: :model do 6 | before(:all) do 7 | @like = Like.new(user_id: 1, post_id: 1) 8 | end 9 | 10 | context 'validates like record' do 11 | it 'is not valid without a user_id' do 12 | @like.user_id = nil 13 | @like.save 14 | expect(@like.errors.full_messages).to include('User must exist') 15 | end 16 | 17 | it 'is not valid without a post_id' do 18 | @like.post_id = nil 19 | @like.save 20 | expect(@like.errors.full_messages).to include('Post must exist') 21 | end 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /spec/models/post_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'rails_helper' 4 | 5 | RSpec.describe Post, type: :model do 6 | before(:all) do 7 | @post = Post.new(post_text: 'Some text for the post', user_id: 4) 8 | end 9 | 10 | context 'validates post fields' do 11 | it 'is not valid without a post text' do 12 | @post.post_text = nil 13 | @post.save 14 | expect(@post.errors.full_messages).to include("Post text can't be blank") 15 | @post.post_text = 'Some text for the post' 16 | end 17 | 18 | it 'is not valid without a user_id' do 19 | @post.user_id = nil 20 | @post.save 21 | expect(@post.errors.full_messages).to include('User must exist') 22 | @post.user_id = 1 23 | end 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /spec/models/user_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'rails_helper' 4 | 5 | RSpec.describe User, type: :model do 6 | before(:all) do 7 | @user1 = User.new(first_name: 'Daniel', last_name: 'Addo', email: 'nick@gmail.com', password: 'foobar') 8 | end 9 | 10 | context 'validates user fields' do 11 | it 'is not valid without a first_name' do 12 | @user1.first_name = nil 13 | @user1.save 14 | expect(@user1.errors.full_messages).to include("First name can't be blank") 15 | @user1.first_name = 'Daniel' 16 | end 17 | 18 | it 'is not valid without a last_name' do 19 | @user1.last_name = nil 20 | @user1.save 21 | expect(@user1.errors.full_messages).to include("Last name can't be blank") 22 | @user1.last_name = 'Addo' 23 | end 24 | 25 | it 'is not valid without an email' do 26 | @user1.email = nil 27 | @user1.save 28 | expect(@user1.errors.full_messages).to include("Email can't be blank") 29 | @user1.email = 'test@test.com' 30 | end 31 | 32 | it 'is not valid without an password' do 33 | @user1.password = nil 34 | @user1.save 35 | expect(@user1.errors.full_messages).to include("Password can't be blank") 36 | @user1.password = 'foobar' 37 | end 38 | end 39 | end 40 | -------------------------------------------------------------------------------- /spec/rails_helper.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # This file is copied to spec/ when you run 'rails generate rspec:install' 4 | require 'spec_helper' 5 | require 'capybara/rspec' 6 | require 'database_cleaner' 7 | ENV['RAILS_ENV'] ||= 'test' 8 | 9 | require File.expand_path('../config/environment', __dir__) 10 | 11 | # Prevent database truncation if the environment is production 12 | abort('The Rails environment is running in production mode!') if Rails.env.production? 13 | require 'rspec/rails' 14 | # Add additional requires below this line. Rails is not loaded until this point! 15 | 16 | # Requires supporting ruby files with custom matchers and macros, etc, in 17 | # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are 18 | # run as spec files by default. This means that files in spec/support that end 19 | # in _spec.rb will both be required and run as specs, causing the specs to be 20 | # run twice. It is recommended that you do not name files matching this glob to 21 | # end with _spec.rb. You can configure this pattern with the --pattern 22 | # option on the command line or in ~/.rspec, .rspec or `.rspec-local`. 23 | # 24 | # The following line is provided for convenience purposes. It has the downside 25 | # of increasing the boot-up time by auto-requiring all files in the support 26 | # directory. Alternatively, in the individual `*_spec.rb` files, manually 27 | # require only the support files necessary. 28 | # 29 | # Dir[Rails.root.join('spec', 'support', '**', '*.rb')].each { |f| require f } 30 | 31 | # Checks for pending migrations and applies them before tests are run. 32 | # If you are not using ActiveRecord, you can remove these lines. 33 | begin 34 | ActiveRecord::Migration.maintain_test_schema! 35 | rescue ActiveRecord::PendingMigrationError => e 36 | puts e.to_s.strip 37 | exit 1 38 | end 39 | RSpec.configure do |config| 40 | # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures 41 | 42 | config.fixture_path = "#{::Rails.root}/spec/fixtures" 43 | 44 | # If you're not using ActiveRecord, or you'd prefer not to run each of your 45 | # examples within a transaction, remove the following line or assign false 46 | # instead of true. 47 | config.use_transactional_fixtures = true 48 | 49 | # RSpec Rails can automatically mix in different behaviours to your tests 50 | # based on their file location, for example enabling you to call `get` and 51 | # `post` in specs under `spec/controllers`. 52 | # 53 | # You can disable this behaviour by removing the line below, and instead 54 | # explicitly tag your specs with their type, e.g.: 55 | # 56 | # RSpec.describe UsersController, :type => :controller do 57 | # # ... 58 | # end 59 | # 60 | # The different available types are documented in the features, such as in 61 | # https://relishapp.com/rspec/rspec-rails/docs 62 | config.infer_spec_type_from_file_location! 63 | 64 | # Filter lines from Rails gems in backtraces. 65 | config.filter_rails_from_backtrace! 66 | # arbitrary gems may also be filtered via: 67 | # config.filter_gems_from_backtrace("gem name") 68 | end 69 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'capybara/rspec' 4 | require 'selenium/webdriver' 5 | 6 | # This file was generated by the `rails generate rspec:install` command. Conventionally, all 7 | # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. 8 | # The generated `.rspec` file contains `--require spec_helper` which will cause 9 | # this file to always be loaded, without a need to explicitly require it in any 10 | # files. 11 | 12 | # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration 13 | RSpec.configure do |config| 14 | # rspec-expectations config goes here. You can use an alternate 15 | # assertion/expectation library such as wrong or the stdlib/minitest 16 | # assertions if you prefer. 17 | config.expect_with :rspec do |expectations| 18 | # This option will default to `true` in RSpec 4. It makes the `description` 19 | # and `failure_message` of custom matchers include text for helper methods 20 | # defined using `chain`, e.g.: 21 | # be_bigger_than(2).and_smaller_than(4).description 22 | # # => "be bigger than 2 and smaller than 4" 23 | # ...rather than: 24 | # # => "be bigger than 2" 25 | expectations.include_chain_clauses_in_custom_matcher_descriptions = true 26 | end 27 | 28 | # rspec-mocks config goes here. You can use an alternate test double 29 | # library (such as bogus or mocha) by changing the `mock_with` option here. 30 | config.mock_with :rspec do |mocks| 31 | # Prevents you from mocking or stubbing a method that does not exist on 32 | # a real object. This is generally recommended, and will default to 33 | # `true` in RSpec 4. 34 | mocks.verify_partial_doubles = true 35 | end 36 | 37 | # This option will default to `:apply_to_host_groups` in RSpec 4 (and will 38 | # have no way to turn it off -- the option exists only for backwards 39 | # compatibility in RSpec 3). It causes shared context metadata to be 40 | # inherited by the metadata hash of host groups and examples, rather than 41 | # triggering implicit auto-inclusion in groups with matching metadata. 42 | config.shared_context_metadata_behavior = :apply_to_host_groups 43 | config.disable_monkey_patching = false 44 | # The settings below are suggested to provide a good initial experience 45 | # with RSpec, but feel free to customize to your heart's content. 46 | # # This allows you to limit a spec run to individual examples or groups 47 | # # you care about by tagging them with `:focus` metadata. When nothing 48 | # # is tagged with `:focus`, all examples get run. RSpec also provides 49 | # # aliases for `it`, `describe`, and `context` that include `:focus` 50 | # # metadata: `fit`, `fdescribe` and `fcontext`, respectively. 51 | # config.filter_run_when_matching :focus 52 | # 53 | # # Allows RSpec to persist some state between runs in order to support 54 | # # the `--only-failures` and `--next-failure` CLI options. We recommend 55 | # # you configure your source control system to ignore this file. 56 | # config.example_status_persistence_file_path = "spec/examples.txt" 57 | # 58 | # # Limits the available syntax to the non-monkey patched syntax that is 59 | # # recommended. For more details, see: 60 | # # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/ 61 | # # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ 62 | # # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode 63 | # config.disable_monkey_patching! 64 | # 65 | # # Many RSpec users commonly either run the entire suite or an individual 66 | # # file, and it's useful to allow more verbose output when running an 67 | # # individual spec file. 68 | # if config.files_to_run.one? 69 | # # Use the documentation formatter for detailed output, 70 | # # unless a formatter has already been configured 71 | # # (e.g. via a command-line flag). 72 | # config.default_formatter = "doc" 73 | # end 74 | # 75 | # # Print the 10 slowest examples and example groups at the 76 | # # end of the spec run, to help surface which specs are running 77 | # # particularly slow. 78 | # config.profile_examples = 10 79 | # 80 | # # Run specs in random order to surface order dependencies. If you find an 81 | # # order dependency and want to debug it, you can fix the order by providing 82 | # # the seed, which is printed after each run. 83 | # # --seed 1234 84 | # config.order = :random 85 | # 86 | # # Seed global randomization in this process using the `--seed` CLI option. 87 | # # Setting this allows you to use `--seed` to deterministically reproduce 88 | # # test failures related to randomization by passing the same `--seed` value 89 | # # as the one that triggered the failure. 90 | # Kernel.srand config.seed 91 | end 92 | 93 | Capybara.register_driver :selenium do |app| 94 | Capybara::Selenium::Driver.new(app, browser: :chrome) 95 | end 96 | 97 | Capybara.configure do |config| 98 | config.run_server = false 99 | config.default_driver = :selenium 100 | config.app_host = 'localhost:3000' # change url 101 | end 102 | -------------------------------------------------------------------------------- /storage/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/addod19/facebook-clone/69faa6903893947c3d024ace61377ba711575f4a/storage/.keep -------------------------------------------------------------------------------- /test/application_system_test_case.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'test_helper' 4 | 5 | class ApplicationSystemTestCase < ActionDispatch::SystemTestCase 6 | driven_by :selenium, using: :chrome, screen_size: [1400, 1400] 7 | end 8 | -------------------------------------------------------------------------------- /test/controllers/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/addod19/facebook-clone/69faa6903893947c3d024ace61377ba711575f4a/test/controllers/.keep -------------------------------------------------------------------------------- /test/controllers/users_controller_test.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'test_helper' 4 | 5 | class UsersControllerTest < ActionDispatch::IntegrationTest 6 | # test "the truth" do 7 | # assert true 8 | # end 9 | end 10 | -------------------------------------------------------------------------------- /test/fixtures/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/addod19/facebook-clone/69faa6903893947c3d024ace61377ba711575f4a/test/fixtures/.keep -------------------------------------------------------------------------------- /test/fixtures/files/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/addod19/facebook-clone/69faa6903893947c3d024ace61377ba711575f4a/test/fixtures/files/.keep -------------------------------------------------------------------------------- /test/fixtures/users.yml: -------------------------------------------------------------------------------- 1 | # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html 2 | 3 | # This model initially had no columns defined. If you add columns to the 4 | # model remove the '{}' from the fixture names and add the columns immediately 5 | # below each fixture, per the syntax in the comments below 6 | # 7 | one: {} 8 | # column: value 9 | # 10 | two: {} 11 | # column: value 12 | -------------------------------------------------------------------------------- /test/helpers/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/addod19/facebook-clone/69faa6903893947c3d024ace61377ba711575f4a/test/helpers/.keep -------------------------------------------------------------------------------- /test/integration/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/addod19/facebook-clone/69faa6903893947c3d024ace61377ba711575f4a/test/integration/.keep -------------------------------------------------------------------------------- /test/mailers/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/addod19/facebook-clone/69faa6903893947c3d024ace61377ba711575f4a/test/mailers/.keep -------------------------------------------------------------------------------- /test/models/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/addod19/facebook-clone/69faa6903893947c3d024ace61377ba711575f4a/test/models/.keep -------------------------------------------------------------------------------- /test/models/user_test.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'test_helper' 4 | 5 | class UserTest < ActiveSupport::TestCase 6 | # test "the truth" do 7 | # assert true 8 | # end 9 | end 10 | -------------------------------------------------------------------------------- /test/system/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/addod19/facebook-clone/69faa6903893947c3d024ace61377ba711575f4a/test/system/.keep -------------------------------------------------------------------------------- /test/test_helper.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | ENV['RAILS_ENV'] ||= 'test' 4 | require_relative '../config/environment' 5 | require 'rails/test_help' 6 | 7 | class ActiveSupport::TestCase 8 | # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. 9 | fixtures :all 10 | 11 | # Add more helper methods to be used by all tests here... 12 | end 13 | -------------------------------------------------------------------------------- /tmp/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/addod19/facebook-clone/69faa6903893947c3d024ace61377ba711575f4a/tmp/.keep -------------------------------------------------------------------------------- /vendor/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/addod19/facebook-clone/69faa6903893947c3d024ace61377ba711575f4a/vendor/.keep --------------------------------------------------------------------------------