├── log └── .keep ├── storage └── .keep ├── tmp └── .keep ├── vendor └── .keep ├── lib ├── assets │ └── .keep └── tasks │ ├── .keep │ └── cucumber.rake ├── public ├── favicon.ico ├── apple-touch-icon.png ├── apple-touch-icon-precomposed.png ├── robots.txt ├── 500.html ├── 422.html └── 404.html ├── .ruby-version ├── app ├── assets │ ├── images │ │ ├── .keep │ │ ├── user-bio.png │ │ ├── icon-like.png │ │ ├── icon-smile.png │ │ ├── icon-user-tag.png │ │ ├── user-friends.png │ │ ├── fb-landing-image.png │ │ └── icon-photo-video.png │ ├── javascripts │ │ ├── channels │ │ │ └── .keep │ │ ├── likes.coffee │ │ ├── posts.coffee │ │ ├── users.coffee │ │ ├── comments.coffee │ │ ├── friendships.coffee │ │ ├── omniauth_callbacks.coffee │ │ ├── cable.js │ │ └── application.js │ ├── config │ │ └── manifest.js │ └── stylesheets │ │ ├── likes.scss │ │ ├── comments.scss │ │ ├── friendships.scss │ │ ├── omniauth_callbacks.scss │ │ ├── fb_custom.scss │ │ ├── users.scss │ │ ├── application.scss │ │ └── posts.scss ├── models │ ├── concerns │ │ └── .keep │ ├── application_record.rb │ ├── comment.rb │ ├── like.rb │ ├── post.rb │ ├── friendship.rb │ └── user.rb ├── controllers │ ├── concerns │ │ └── .keep │ ├── users_controller.rb │ ├── omniauth_callbacks_controller.rb │ ├── application_controller.rb │ ├── likes_controller.rb │ ├── comments_controller.rb │ ├── friendships_controller.rb │ └── posts_controller.rb ├── views │ ├── layouts │ │ ├── mailer.text.erb │ │ ├── mailer.html.erb │ │ └── application.html.erb │ ├── application │ │ ├── _visitor_top_menu.html.erb │ │ ├── _comments.html.erb │ │ ├── _flash_notice.html.erb │ │ ├── _footer.html.erb │ │ ├── _header.html.erb │ │ ├── _post_actions.html.erb │ │ ├── _homepage_shortcuts_left.html.erb │ │ ├── _comment_form.html.erb │ │ ├── _navbar_login_form.html.erb │ │ ├── _edit_post_form.html.erb │ │ ├── _post_form.html.erb │ │ ├── _user_top_menu.html.erb │ │ └── _homepage_shortcuts_right.html.erb │ ├── posts │ │ ├── show.html.erb │ │ ├── edit.html.erb │ │ ├── index.html.erb │ │ └── _post.html.erb │ ├── devise │ │ ├── mailer │ │ │ ├── password_change.html.erb │ │ │ ├── confirmation_instructions.html.erb │ │ │ ├── unlock_instructions.html.erb │ │ │ ├── email_changed.html.erb │ │ │ └── reset_password_instructions.html.erb │ │ ├── sessions │ │ │ ├── new.html.erb │ │ │ └── _login_form.html.erb │ │ ├── registrations │ │ │ ├── new.html.erb │ │ │ ├── edit.html.erb │ │ │ └── _signup_form.html.erb │ │ ├── shared │ │ │ ├── _error_messages.html.erb │ │ │ └── _links.html.erb │ │ ├── unlocks │ │ │ └── new.html.erb │ │ ├── passwords │ │ │ ├── new.html.erb │ │ │ └── edit.html.erb │ │ └── confirmations │ │ │ └── new.html.erb │ ├── users │ │ ├── _bio.html.erb │ │ ├── index.html.erb │ │ ├── _user.html.erb │ │ ├── show.html.erb │ │ ├── _user_timeline_banner.html.erb │ │ └── _user_friend.html.erb │ ├── comments │ │ └── _comment.html.erb │ └── friendships │ │ └── friends.html.erb ├── helpers │ ├── likes_helper.rb │ ├── friendships_helper.rb │ ├── omniauth_callbacks_helper.rb │ ├── comments_helper.rb │ ├── application_helper.rb │ ├── posts_helper.rb │ └── users_helper.rb ├── jobs │ └── application_job.rb ├── channels │ └── application_cable │ │ ├── channel.rb │ │ └── connection.rb └── mailers │ └── application_mailer.rb ├── .rspec ├── features ├── step_definitions │ ├── .gitkeep │ ├── user_remove_comments_steps.rb │ ├── user_add_comments_steps.rb │ ├── user_can_view_friends_steps.rb │ ├── user_logout_steps.rb │ ├── user_signup_steps.rb │ ├── user_and_mutual_friends_steps.rb │ ├── user_manage_posts_steps.rb │ ├── user_and_friendship_request_steps.rb │ ├── user_and_likes_steps.rb │ └── user_login_steps.rb ├── user_logout.feature ├── user_signup.feature ├── user_add_comments.feature ├── user_remove_comments.feature ├── user_and_mutual_friends.feature ├── user_can_view_friends.feature ├── user_manage_posts.feature ├── user_and_friendship_request.feature ├── user_and_likes.feature ├── user_login.feature └── support │ └── env.rb ├── .rubocop.yml ├── docs ├── fb-timeline.PNG ├── profile-page-1.PNG └── facebook-clone ERD.png ├── package.json ├── spec ├── factories │ ├── likes.rb │ ├── friendships.rb │ ├── post.rb │ ├── comments.rb │ └── user.rb ├── helpers │ ├── likes_helper_spec.rb │ ├── posts_helper_spec.rb │ ├── users_helper_spec.rb │ ├── comments_helper_spec.rb │ ├── friendships_helper_spec.rb │ └── omniauth_callbacks_helper_spec.rb ├── controllers │ ├── omniauth_callbacks_controller_spec.rb │ ├── comments_controller_spec.rb │ ├── users_controller_spec.rb │ ├── likes_controller_spec.rb │ ├── application_controller_spec.rb │ ├── posts_controller_spec.rb │ └── friendships_controller_spec.rb ├── models │ ├── like_spec.rb │ ├── post_spec.rb │ ├── comment_spec.rb │ ├── user_spec.rb │ └── friendship_spec.rb ├── rails_helper.rb └── spec_helper.rb ├── bin ├── rake ├── bundle ├── rails ├── yarn ├── update └── setup ├── config ├── spring.rb ├── environment.rb ├── initializers │ ├── mime_types.rb │ ├── filter_parameter_logging.rb │ ├── application_controller_renderer.rb │ ├── cookies_serializer.rb │ ├── backtrace_silencers.rb │ ├── wrap_parameters.rb │ ├── assets.rb │ ├── inflections.rb │ ├── content_security_policy.rb │ └── devise.rb ├── cable.yml ├── boot.rb ├── credentials.yml.enc ├── cucumber.yml ├── routes.rb ├── locales │ ├── en.yml │ └── devise.en.yml ├── storage.yml ├── application.rb ├── puma.rb ├── environments │ ├── test.rb │ ├── development.rb │ └── production.rb └── database.yml ├── config.ru ├── .stickler.yml ├── db ├── migrate │ ├── 20191118172624_add_omniauth_to_users.rb │ ├── 20191027212546_create_posts.rb │ ├── 20191102165159_create_likes.rb │ ├── 20191102123836_create_comments.rb │ ├── 20191113152429_create_friendships.rb │ └── 20191027154938_devise_create_users.rb ├── seeds.rb └── schema.rb ├── Rakefile ├── script └── cucumber ├── goorm.manifest ├── .gitignore ├── LICENSE ├── Gemfile ├── Guardfile ├── README.md ├── .rubocop_todo.yml └── Gemfile.lock /log/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /storage/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tmp/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /vendor/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /lib/assets/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /lib/tasks/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.ruby-version: -------------------------------------------------------------------------------- 1 | ruby-2.4.0 -------------------------------------------------------------------------------- /app/assets/images/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /app/models/concerns/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /public/apple-touch-icon.png: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.rspec: -------------------------------------------------------------------------------- 1 | --require spec_helper 2 | -------------------------------------------------------------------------------- /app/controllers/concerns/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /app/assets/javascripts/channels/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /features/step_definitions/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /public/apple-touch-icon-precomposed.png: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.rubocop.yml: -------------------------------------------------------------------------------- 1 | inherit_from: .rubocop_todo.yml 2 | -------------------------------------------------------------------------------- /app/views/layouts/mailer.text.erb: -------------------------------------------------------------------------------- 1 | <%= yield %> 2 | -------------------------------------------------------------------------------- /app/views/application/_visitor_top_menu.html.erb: -------------------------------------------------------------------------------- 1 | <%= render "navbar_login_form" %> 2 | -------------------------------------------------------------------------------- /app/helpers/likes_helper.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module LikesHelper 4 | end 5 | -------------------------------------------------------------------------------- /docs/fb-timeline.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/johnsonsirv/facebook-clone/HEAD/docs/fb-timeline.PNG -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "fbreplica", 3 | "private": true, 4 | "dependencies": {} 5 | } 6 | -------------------------------------------------------------------------------- /app/views/posts/show.html.erb: -------------------------------------------------------------------------------- 1 |

Posts#show

2 |

Find me in app/views/posts/show.html.erb

3 | -------------------------------------------------------------------------------- /docs/profile-page-1.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/johnsonsirv/facebook-clone/HEAD/docs/profile-page-1.PNG -------------------------------------------------------------------------------- /app/helpers/friendships_helper.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module FriendshipsHelper 4 | end 5 | -------------------------------------------------------------------------------- /app/jobs/application_job.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class ApplicationJob < ActiveJob::Base 4 | end 5 | -------------------------------------------------------------------------------- /docs/facebook-clone ERD.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/johnsonsirv/facebook-clone/HEAD/docs/facebook-clone ERD.png -------------------------------------------------------------------------------- /app/assets/images/user-bio.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/johnsonsirv/facebook-clone/HEAD/app/assets/images/user-bio.png -------------------------------------------------------------------------------- /app/helpers/omniauth_callbacks_helper.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module OmniauthCallbacksHelper 4 | end 5 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file 2 | -------------------------------------------------------------------------------- /app/assets/images/icon-like.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/johnsonsirv/facebook-clone/HEAD/app/assets/images/icon-like.png -------------------------------------------------------------------------------- /app/assets/images/icon-smile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/johnsonsirv/facebook-clone/HEAD/app/assets/images/icon-smile.png -------------------------------------------------------------------------------- /spec/factories/likes.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | FactoryBot.define do 4 | factory :like do 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /app/assets/images/icon-user-tag.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/johnsonsirv/facebook-clone/HEAD/app/assets/images/icon-user-tag.png -------------------------------------------------------------------------------- /app/assets/images/user-friends.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/johnsonsirv/facebook-clone/HEAD/app/assets/images/user-friends.png -------------------------------------------------------------------------------- /app/assets/images/fb-landing-image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/johnsonsirv/facebook-clone/HEAD/app/assets/images/fb-landing-image.png -------------------------------------------------------------------------------- /app/assets/images/icon-photo-video.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/johnsonsirv/facebook-clone/HEAD/app/assets/images/icon-photo-video.png -------------------------------------------------------------------------------- /app/assets/config/manifest.js: -------------------------------------------------------------------------------- 1 | //= link_tree ../images 2 | //= link_directory ../javascripts .js 3 | //= link_directory ../stylesheets .css 4 | -------------------------------------------------------------------------------- /spec/factories/friendships.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | FactoryBot.define do 4 | factory :friendship do 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /bin/rake: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | require_relative '../config/boot' 5 | require 'rake' 6 | Rake.application.run 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 | -------------------------------------------------------------------------------- /spec/helpers/likes_helper_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'rails_helper' 4 | 5 | RSpec.describe LikesHelper, type: :helper do 6 | end 7 | -------------------------------------------------------------------------------- /spec/helpers/posts_helper_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'rails_helper' 4 | 5 | RSpec.describe PostsHelper, type: :helper do 6 | end 7 | -------------------------------------------------------------------------------- /spec/helpers/users_helper_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'rails_helper' 4 | 5 | RSpec.describe UsersHelper, type: :helper do 6 | end 7 | -------------------------------------------------------------------------------- /spec/helpers/comments_helper_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'rails_helper' 4 | 5 | RSpec.describe CommentsHelper, type: :helper do 6 | end 7 | -------------------------------------------------------------------------------- /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/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/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 | -------------------------------------------------------------------------------- /bin/bundle: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) 5 | load Gem.bin_path('bundler', 'bundle') 6 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /config/spring.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | %w[ 4 | .ruby-version 5 | .rbenv-vars 6 | tmp/restart.txt 7 | tmp/caching-dev.txt 8 | ].each { |path| Spring.watch(path) } 9 | -------------------------------------------------------------------------------- /app/views/application/_comments.html.erb: -------------------------------------------------------------------------------- 1 |
2 | <%= render 'comment', post: post %> 3 |
<%= render 'comment_form' %>
4 |
-------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /spec/factories/post.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | FactoryBot.define do 4 | factory :post do 5 | user 6 | 7 | content { Faker::Lorem.paragraph } 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /.stickler.yml: -------------------------------------------------------------------------------- 1 | linters: 2 | rubocop: 3 | display_cop_names: true 4 | files: 5 | ignore: 6 | - "bin/*" 7 | - "db/*" 8 | - "config/*" 9 | - "Guardfile" 10 | - "Rakefile" -------------------------------------------------------------------------------- /spec/controllers/omniauth_callbacks_controller_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'rails_helper' 4 | 5 | RSpec.describe OmniauthCallbacksController, type: :controller do 6 | end 7 | -------------------------------------------------------------------------------- /app/views/posts/edit.html.erb: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 | <%= render 'edit_post_form' %> 5 |
6 |
7 |
8 | -------------------------------------------------------------------------------- /bin/rails: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | APP_PATH = File.expand_path('../config/application', __dir__) 5 | require_relative '../config/boot' 6 | require 'rails/commands' 7 | -------------------------------------------------------------------------------- /config/environment.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # Load the Rails application. 4 | require_relative 'application' 5 | 6 | # Initialize the Rails application. 7 | Rails.application.initialize! 8 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /spec/factories/comments.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | FactoryBot.define do 4 | factory :comment do 5 | user 6 | post 7 | 8 | content { 'This is a test comment' } 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /spec/models/like_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'rails_helper' 4 | 5 | RSpec.describe Like, type: :model do 6 | it { should belong_to(:user) } 7 | it { should belong_to(:likeable) } 8 | end 9 | -------------------------------------------------------------------------------- /app/assets/stylesheets/comments.scss: -------------------------------------------------------------------------------- 1 | // Place all the styles related to the comments 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/friendships.scss: -------------------------------------------------------------------------------- 1 | // Place all the styles related to the friendships controller here. 2 | // They will automatically be included in application.css. 3 | // You can use Sass (SCSS) here: http://sass-lang.com/ 4 | -------------------------------------------------------------------------------- /spec/controllers/comments_controller_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'rails_helper' 4 | 5 | RSpec.describe CommentsController, type: :controller do 6 | it { should use_before_action(:find_comment) } 7 | end 8 | -------------------------------------------------------------------------------- /spec/controllers/users_controller_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'rails_helper' 4 | 5 | RSpec.describe UsersController, type: :controller do 6 | it { should use_before_action(:get_created_posts) } 7 | end 8 | -------------------------------------------------------------------------------- /config/initializers/mime_types.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | # Be sure to restart your server when you modify this file. 3 | 4 | # Add new mime types for use in respond_to blocks: 5 | # Mime::Type.register "text/richtext", :rtf 6 | -------------------------------------------------------------------------------- /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 | it { should use_before_action(:find_resource_to_be_liked) } 7 | end 8 | -------------------------------------------------------------------------------- /app/assets/stylesheets/omniauth_callbacks.scss: -------------------------------------------------------------------------------- 1 | // Place all the styles related to the omniauth_callbacks controller here. 2 | // They will automatically be included in application.css. 3 | // You can use Sass (SCSS) here: http://sass-lang.com/ 4 | -------------------------------------------------------------------------------- /spec/controllers/application_controller_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'rails_helper' 4 | 5 | RSpec.describe ApplicationController, type: :controller do 6 | it { should use_before_action(:authenticate_user!) } 7 | end 8 | -------------------------------------------------------------------------------- /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/posts.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/views/application/_flash_notice.html.erb: -------------------------------------------------------------------------------- 1 | <% if notice %> 2 |

<%= notice %>

3 | <% end %> 4 | <% if alert %> 5 |

<%= alert %>

6 | <% end %> -------------------------------------------------------------------------------- /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: fbreplica_production 11 | -------------------------------------------------------------------------------- /app/assets/javascripts/comments.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/friendships.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/omniauth_callbacks.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 | -------------------------------------------------------------------------------- /db/migrate/20191118172624_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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /config/boot.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) 4 | 5 | require 'bundler/setup' # Set up gems listed in the Gemfile. 6 | require 'bootsnap/setup' # Speed up boot time by caching expensive operations. 7 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # Add your own tasks in files placed in lib/tasks ending in .rake, 4 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. 5 | 6 | require_relative 'config/application' 7 | 8 | Rails.application.load_tasks 9 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /app/views/layouts/mailer.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | 9 | 10 | 11 | <%= yield %> 12 | 13 | 14 | -------------------------------------------------------------------------------- /db/migrate/20191027212546_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 :content, null: false 7 | t.references :user 8 | 9 | t.timestamps 10 | end 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /app/views/users/_bio.html.erb: -------------------------------------------------------------------------------- 1 |
2 |
Intro
3 |

Fullname: <%= user.fullname %>

4 |

Email Address: <%= user.email %>

5 |

DOB: <%= user.dob %>

6 |

Gender: <%= user.sex %>

7 |
8 | -------------------------------------------------------------------------------- /db/migrate/20191102165159_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 :likeable, polymorphic: true 7 | t.references :user 8 | 9 | t.timestamps 10 | end 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /app/models/comment.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class Comment < ApplicationRecord 4 | belongs_to :user 5 | belongs_to :post 6 | has_many :likes, as: :likeable, dependent: :destroy 7 | 8 | default_scope -> { order(created_at: :desc).includes(:user) } 9 | 10 | validates :content, presence: true 11 | end 12 | -------------------------------------------------------------------------------- /app/views/application/_footer.html.erb: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /config/initializers/application_controller_renderer.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | # Be sure to restart your server when you modify this file. 3 | 4 | # ActiveSupport::Reloader.to_prepare do 5 | # ApplicationController.renderer.defaults.merge!( 6 | # http_host: 'example.org', 7 | # https: false 8 | # ) 9 | # end 10 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /app/views/application/_header.html.erb: -------------------------------------------------------------------------------- 1 | 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 | -------------------------------------------------------------------------------- /features/user_logout.feature: -------------------------------------------------------------------------------- 1 | Feature: Log current user out 2 | In order to quit the application 3 | As a user 4 | I want to log off from all current activities 5 | 6 | Background: 7 | Given a user with email "demouser@onet.com" is logged in 8 | 9 | Scenario: End my session 10 | When I click logout 11 | Then my current session should terminate -------------------------------------------------------------------------------- /features/user_signup.feature: -------------------------------------------------------------------------------- 1 | Feature: New User Signup 2 | In order to find friends, socialize, create posts, add comments and likes 3 | As a new user 4 | I want to create a new account 5 | 6 | Background: 7 | Given I am on the signup page 8 | 9 | Scenario: Submit valid credentials 10 | When I submit required fields 11 | Then I should see my bio -------------------------------------------------------------------------------- /spec/controllers/posts_controller_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'rails_helper' 4 | 5 | RSpec.describe PostsController, type: :controller do 6 | it { should use_before_action(:fetch_timeline_posts) } 7 | it { should use_before_action(:initialize_new_post_editor) } 8 | it { should use_before_action(:find_post) } 9 | end 10 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /db/migrate/20191102123836_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.text :content 7 | t.references :user, foreign_key: true 8 | t.references :post, foreign_key: true 9 | 10 | t.timestamps 11 | end 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /app/views/devise/sessions/new.html.erb: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 |
5 |
6 |
7 | <%= render "login_form" %> 8 |
9 |
10 |
11 |
12 |
13 |
-------------------------------------------------------------------------------- /app/views/users/index.html.erb: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 |
5 |
Find Friends
6 |
7 | <%= render @users, cached: true %> 8 |
9 |
10 |
11 |
12 |
-------------------------------------------------------------------------------- /bin/yarn: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | APP_ROOT = File.expand_path('..', __dir__) 5 | Dir.chdir(APP_ROOT) do 6 | begin 7 | exec 'yarnpkg', *ARGV 8 | rescue Errno::ENOENT 9 | warn 'Yarn executable was not detected in the system.' 10 | warn 'Download Yarn at https://yarnpkg.com/en/docs/install' 11 | exit 1 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /script/cucumber: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | vendored_cucumber_bin = Dir["#{File.dirname(__FILE__)}/../vendor/{gems,plugins}/cucumber*/bin/cucumber"].first 5 | if vendored_cucumber_bin 6 | load File.expand_path(vendored_cucumber_bin) 7 | else 8 | require 'rubygems' unless ENV['NO_RUBYGEMS'] 9 | require 'cucumber' 10 | load Cucumber::BINARY 11 | end 12 | -------------------------------------------------------------------------------- /app/models/like.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class Like < ApplicationRecord 4 | belongs_to :likeable, polymorphic: true 5 | belongs_to :user 6 | 7 | def self.add_like_to_resource(type, user) 8 | type.likes.create(user: user) 9 | end 10 | 11 | def self.unlike_resource(type, user) 12 | like = type.likes.find_by(user: user) 13 | like.destroy 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /spec/factories/user.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | FactoryBot.define do 4 | factory :user do 5 | firstname { Faker::Name.first_name } 6 | lastname { Faker::Name.last_name } 7 | email { Faker::Internet.email } 8 | password { Faker::Internet.password } 9 | dob { Faker::Date.birthday(min_age: 18) } 10 | sex { %w[Female Male Custom].sample } 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /app/views/posts/index.html.erb: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 | <%= render 'homepage_shortcuts_left' %> 5 |
6 |
7 | <%= render 'post_form' %> 8 | <%= render @posts, cached: true %> 9 |
10 |
11 | <%= render 'homepage_shortcuts_right' %> 12 |
13 |
14 |
15 | -------------------------------------------------------------------------------- /app/views/devise/registrations/new.html.erb: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 | 5 |

m-Facebook helps you connect and share with the people in your life.

6 | <%= image_tag "fb-landing-image.png", class: "mt-2" %> 7 |
8 | 9 |
10 |
-------------------------------------------------------------------------------- /app/views/users/_user.html.erb: -------------------------------------------------------------------------------- 1 |
2 |
<%= gravatar_for(user) %>
3 |
<%= link_to user.fullname, user %>
4 |
5 | <%= show_banner_call_to_action_for(user, 'btn-sm custom-default-btn', 'btn-sm btn-secondary') %> 6 |
7 |
-------------------------------------------------------------------------------- /db/migrate/20191113152429_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 7 | t.references :friend 8 | t.boolean :confirmed, default: false 9 | 10 | t.timestamps 11 | end 12 | add_index :friendships, %i[user_id friend_id] 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /features/user_add_comments.feature: -------------------------------------------------------------------------------- 1 | Feature: User manage comments 2 | In order to add my reactions to posts 3 | As a user 4 | I want to add or remove comments 5 | 6 | Background: 7 | Given a user with email "demouser@onet.com" is already logged in 8 | And I can see the first post in my timeline 9 | 10 | Scenario: Add new Comment 11 | When I submit new comment using comment form 12 | Then I should see my comment for first post in timeline -------------------------------------------------------------------------------- /features/user_remove_comments.feature: -------------------------------------------------------------------------------- 1 | Feature: User manage comments 2 | In order to add my reactions to posts 3 | As a user 4 | I want to add or remove comments 5 | 6 | Background: 7 | Given a user with email "demouser@onet.com" is already logged in 8 | And I can see the second post in my timeline 9 | 10 | Scenario: Remove my comment 11 | Given I have added a coment 12 | When I delete comment 13 | Then post comment should no longer exist -------------------------------------------------------------------------------- /app/views/application/_post_actions.html.erb: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /config/credentials.yml.enc: -------------------------------------------------------------------------------- 1 | W3awN+RhnrUQ6qUCS+IVkWxJeIvvL1vCXzDMFbIiidx4Jf8desPDxYKVTlnKY6kHlqZEMIIRHaFiB9j4OM9X1DpwAwIh6id9x/ltAwQxO2sRKvD+kNwJajwG8ZCv0gCumyg2CNGXZ40zyCLaFBqxo83mKGs21eDdWiI20AY3Q5r/KbBlUb+4cHM9zocZgzmo0QQBJKUoF5vtU88kbktWZ3YjHj0ta3JBukXMJ8V4Il8h8kDUh7ENnXjxc0lIxc4fz7IME8JQnHyXoGnpUj5TUd+0Ktfu7v75BX5Jhfg+frGmneutJwXMrHT/vuQpvq81UtC52sYyATGObUW6Vy33Pts1Ooe00tuNzH/NKwflFEkFg33qDgM3MD1FhndzmTvJSI2SJ/5pOKukezORkU5JgqPj8f/i1mKXdFNe--W89s/O+12Bjwom8C--OV5zHDtcd5PCU33s1C2zAw== -------------------------------------------------------------------------------- /config/initializers/backtrace_silencers.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | # Be sure to restart your server when you modify this file. 3 | 4 | # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. 5 | # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } 6 | 7 | # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. 8 | # Rails.backtrace_cleaner.remove_silencers! 9 | -------------------------------------------------------------------------------- /spec/controllers/friendships_controller_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'rails_helper' 4 | 5 | RSpec.describe FriendshipsController, type: :controller do 6 | it { 7 | should route(:get, '/friends') 8 | .to(action: :index) 9 | } 10 | 11 | it { 12 | should route(:get, '/friend_requests') 13 | .to(action: :friend_requests) 14 | } 15 | 16 | it { 17 | should route(:get, '/mutual_friends') 18 | .to(action: :mutual_friends) 19 | } 20 | end 21 | -------------------------------------------------------------------------------- /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/layouts/application.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Fbreplica 5 | <%= csrf_meta_tags %> 6 | <%= csp_meta_tag %> 7 | 8 | <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> 9 | <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> 10 | 11 | 12 | 13 | <%= render 'header' %> 14 | <%= render 'flash_notice' %> 15 | <%= yield %> 16 | 17 | 18 | -------------------------------------------------------------------------------- /features/user_and_mutual_friends.feature: -------------------------------------------------------------------------------- 1 | Feature: User and Mutual Friendship 2 | In order to expand my network 3 | As a user 4 | I want to see my mutual friends 5 | 6 | Background: 7 | Given the following users are friends: 8 | | email | 9 | | "demouser1@onet.com" | 10 | | "user2demo@carry.com" | 11 | | "user3test@loki.io" | 12 | 13 | Scenario: Send a friend request 14 | When the user "demouser1@onet.com" view mutual friends 15 | Then "user2demo@carry.com" should be mutual friends with "user3test@loki.io" -------------------------------------------------------------------------------- /spec/helpers/friendships_helper_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'rails_helper' 4 | 5 | # Specs in this file have access to a helper object that includes 6 | # the FriendshipsHelper. For example: 7 | # 8 | # describe FriendshipsHelper do 9 | # describe "string concat" do 10 | # it "concats two strings with spaces" do 11 | # expect(helper.concat_strings("this","that")).to eq("this that") 12 | # end 13 | # end 14 | # end 15 | RSpec.describe FriendshipsHelper, type: :helper do 16 | end 17 | -------------------------------------------------------------------------------- /config/cucumber.yml: -------------------------------------------------------------------------------- 1 | <% 2 | rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : "" 3 | rerun = rerun.strip.gsub /\s/, ' ' 4 | rerun_opts = rerun.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}" 5 | std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --strict --tags 'not @wip'" 6 | %> 7 | default: <%= std_opts %> features 8 | wip: --tags @wip:3 --wip features 9 | rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags 'not @wip' 10 | -------------------------------------------------------------------------------- /features/user_can_view_friends.feature: -------------------------------------------------------------------------------- 1 | Feature: User can see list of friends 2 | In order find friends and send friend requests 3 | As a user 4 | I want see list of users 5 | 6 | Background: 7 | Given a user with email "demouser@onet.com" is already logged in 8 | 9 | Scenario: View users 10 | Given the following users exist in database: 11 | | email | 12 | | user1@test.io | 13 | | user2@conrad.ca.co | 14 | | user3@prodo.com | 15 | When I find friends 16 | Then I should see a list of users 17 | And I should not see my profile -------------------------------------------------------------------------------- /app/controllers/users_controller.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class UsersController < ApplicationController 4 | before_action :get_created_posts, only: [:show] 5 | 6 | def index 7 | @users = User.all_except current_user 8 | end 9 | 10 | def show 11 | @user = find_user 12 | end 13 | 14 | private 15 | 16 | def find_user 17 | User.find_by(id: params[:id]) 18 | end 19 | 20 | def get_created_posts 21 | initialize_new_post_editor 22 | @posts = Post.authored_by find_user 23 | end 24 | end 25 | -------------------------------------------------------------------------------- /spec/helpers/omniauth_callbacks_helper_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'rails_helper' 4 | 5 | # Specs in this file have access to a helper object that includes 6 | # the OmniauthCallbacksHelper. For example: 7 | # 8 | # describe OmniauthCallbacksHelper do 9 | # describe "string concat" do 10 | # it "concats two strings with spaces" do 11 | # expect(helper.concat_strings("this","that")).to eq("this that") 12 | # end 13 | # end 14 | # end 15 | RSpec.describe OmniauthCallbacksHelper, type: :helper do 16 | end 17 | -------------------------------------------------------------------------------- /features/step_definitions/user_remove_comments_steps.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | Given('I can see the second post in my timeline') do 4 | @post = FactoryBot.create(:post, content: '2nd Post') 5 | end 6 | 7 | Given('I have added a coment') do 8 | @comment = @post.comments.create(content: '2nd Comment') 9 | end 10 | 11 | When('I delete comment') do 12 | @comment.destroy 13 | end 14 | 15 | Then('post comment should no longer exist') do 16 | deleted_comment = Comment.find_by(id: @comment) 17 | expect(deleted_comment).to be_nil 18 | end 19 | -------------------------------------------------------------------------------- /app/views/application/_homepage_shortcuts_left.html.erb: -------------------------------------------------------------------------------- 1 |
2 | 6 | 10 |
-------------------------------------------------------------------------------- /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/devise/passwords/new.html.erb: -------------------------------------------------------------------------------- 1 |

Forgot your password?

2 | 3 | <%= form_for(resource, as: resource_name, url: password_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 "Send me reset password instructions" %> 13 |
14 | <% end %> 15 | 16 | <%= render "devise/shared/links" %> 17 | -------------------------------------------------------------------------------- /app/views/application/_comment_form.html.erb: -------------------------------------------------------------------------------- 1 | <%= form_for Comment.new do |f| %> 2 |
3 |
4 |
<%= gravatar_for(current_user, size: 30) %>
5 |
6 | <%= f.hidden_field :post_id, value: post.id %> 7 | <%= f.text_area :content, class: "p-2", placeholder: 'Write a comment' %> 8 |
9 |
10 |
11 |
12 | <%= f.submit 'Comment', class: "btn btn-sm btn-comment mr-2" %> 13 |
14 | <% end %> -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /app/views/users/show.html.erb: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 | <%= render 'user_timeline_banner', user: @user %> 5 |
6 |
7 |
8 | <%= render 'bio', user: @user %> 9 | <%= render 'user_friend', user: @user %> 10 |
11 |
12 | <%= render 'post_form' %> 13 | <%= render @posts, cached: true %> 14 |
15 |
16 |
17 |
18 |
19 |
20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /features/user_manage_posts.feature: -------------------------------------------------------------------------------- 1 | Feature: User manage posts 2 | In order to share my posts with friends 3 | As a user 4 | I want to add, edit, remove posts 5 | 6 | Background: 7 | Given a user with email "demouser@onet.com" is already logged in 8 | 9 | Scenario: Add new Post 10 | When I submit new post using post form 11 | Then I should see post in timeline 12 | 13 | Scenario: Edit my Post 14 | When I choose edit post from dropdown menu 15 | And I submit post update 16 | Then post content should be updated 17 | 18 | Scenario: Remove my Post 19 | When I choose delete post from dropdown menu 20 | Then post should no longer exist -------------------------------------------------------------------------------- /app/views/comments/_comment.html.erb: -------------------------------------------------------------------------------- 1 |
2 |
3 |
<%= gravatar_for(comment.user, size: 30) %>
4 |
5 | <%= link_to comment.user.fullname, comment.user, class: "" %> 6 | <%= comment.content %> 7 |
8 |
9 |
10 | <%= show_comment_actions_for(comment) %> 11 | <%= time_ago_in_words(comment.created_at, include_seconds: true) %> 12 |
13 |
-------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /features/step_definitions/user_add_comments_steps.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | Given('I can see the first post in my timeline') do 4 | @post = FactoryBot.build(:post) 5 | within '.new-post' do 6 | fill_in 'post[content]', with: @post.content 7 | click_button 'Post' 8 | end 9 | end 10 | 11 | When('I submit new comment using comment form') do 12 | @comment = FactoryBot.build(:comment) 13 | within '.comment-editor' do 14 | fill_in 'comment[content]', with: @comment.content 15 | click_button 'Comment' 16 | end 17 | end 18 | 19 | Then('I should see my comment for first post in timeline') do 20 | expect(page).to have_content(@comment.content) 21 | end 22 | -------------------------------------------------------------------------------- /db/seeds.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | users = [ 4 | { firstname: 'Nahuel', lastname: 'Castro', email: 'nahukas@gmail.com', dob: 'Sep 26 1984', sex: 'Male' }, 5 | { firstname: 'Miguel', lastname: 'Prada', email: 'mapra99@gmail.com', dob: 'Sep 26 2001', sex: 'Male' }, 6 | { firstname: 'Tiago', lastname: 'Ferreira', email: 'tiferreira12@gmail.com', dob: 'Dec 12 1987', sex: 'Male' }, 7 | { firstname: 'Binary', lastname: 'Shloch', email: 'shloch2007@yahoo.fr', dob: 'Sep 27 1999', sex: 'Custom' }, 8 | { firstname: 'Marvelous', lastname: 'Ubani', email: 'marvellousubani@gmail.com', dob: 'Sep 30 1999', sex: 'Custom' } 9 | ] 10 | 11 | users.each do |u| 12 | User.create(u) 13 | end 14 | -------------------------------------------------------------------------------- /app/controllers/omniauth_callbacks_controller.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class OmniauthCallbacksController < Devise::OmniauthCallbacksController 4 | def facebook 5 | @user = User.from_omniauth(request.env['omniauth.auth']) 6 | 7 | if @user.persisted? 8 | sign_in_and_redirect @user, event: :authentication # this will throw if @user is not activated 9 | set_flash_message(:notice, :success, kind: 'Facebook') if is_navigational_format? 10 | else 11 | session['devise.facebook_data'] = request.env['omniauth.auth'] 12 | redirect_to new_user_registration_url 13 | end 14 | end 15 | 16 | def failure 17 | redirect_to root_path 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /features/step_definitions/user_can_view_friends_steps.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | Given('the following users exist in database:') do |acc| 4 | acc.hashes.each do |a| 5 | FactoryBot.create(:user, email: a['email']) 6 | end 7 | end 8 | 9 | When('I find friends') do 10 | click_link 'Find Friends' 11 | end 12 | 13 | Then('I should see a list of users') do 14 | @user2 = User.second 15 | @user3 = User.third 16 | expect(page).to have_content("#{@user2.firstname} #{@user2.lastname}") 17 | expect(page).to have_content("#{@user3.firstname} #{@user3.lastname}") 18 | end 19 | 20 | Then('I should not see my profile') do 21 | expect(page).to_not have_content(@user.email) 22 | end 23 | -------------------------------------------------------------------------------- /features/step_definitions/user_logout_steps.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | Given('a user with email {string} is logged in') do |current_user_email| 4 | @user = FactoryBot.create(:user, email: current_user_email) 5 | visit new_user_session_path 6 | within '.default-user-login' do 7 | fill_in 'user[email]', with: @user.email 8 | fill_in 'user[password]', with: @user.password 9 | click_button 'Log In' 10 | end 11 | end 12 | 13 | When('I click logout') do 14 | within '.dropdown-menu' do 15 | click_link 'Logout' 16 | end 17 | end 18 | 19 | Then('my current session should terminate') do 20 | visit user_path @user 21 | expect(page).not_to have_current_path user_path @user 22 | end 23 | -------------------------------------------------------------------------------- /features/user_and_friendship_request.feature: -------------------------------------------------------------------------------- 1 | Feature: User and Friendship Requests 2 | In order to make friends 3 | As a user 4 | I want to send or accept friend requests 5 | 6 | Background: 7 | Given the following users exists: 8 | | email | 9 | | "demouser1@onet.com" | 10 | | "user2demo@carry.com" | 11 | 12 | Scenario: Send a friend request 13 | Given "demouser1@onet.com" is logged in 14 | When I send request to "user2demo@carry.com" 15 | Then I should have pending request 16 | 17 | Scenario: Accept friend request 18 | Given the user "user2demo@carry.com" logs in 19 | And I have pending request from "demouser1@onet.com" 20 | When I accept request from "demouser1@onet.com" 21 | Then we should be friends -------------------------------------------------------------------------------- /spec/models/post_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'rails_helper' 4 | 5 | RSpec.describe Post, type: :model do 6 | context 'Associations' do 7 | it { should belong_to(:user) } 8 | it { should have_many(:comments).dependent(:destroy) } 9 | it { should have_many(:likes).dependent(:destroy) } 10 | end 11 | 12 | context 'validations' do 13 | before do 14 | @post = FactoryBot.create(:post) 15 | end 16 | it 'invalid when post content is null or empty' do 17 | post2 = FactoryBot.build(:post, content: nil) 18 | expect(post2).to_not be_valid 19 | end 20 | 21 | it 'is valid when post content has value' do 22 | expect(@post).to be_valid 23 | end 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /app/controllers/application_controller.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class ApplicationController < ActionController::Base 4 | before_action :authenticate_user! 5 | before_action :configure_permitted_parameters, if: :devise_controller? 6 | include PostsHelper 7 | 8 | def set_flash_notice(type, message) 9 | flash[type.to_sym] = message 10 | end 11 | 12 | def initialize_new_post_editor 13 | @post = Post.new 14 | end 15 | 16 | def back_with_anchored_resource(anchor: '') 17 | "#{request.referrer}##{anchor}" 18 | end 19 | 20 | protected 21 | 22 | def configure_permitted_parameters 23 | devise_parameter_sanitizer 24 | .permit(:sign_up, keys: %i[firstname lastname dob sex]) 25 | end 26 | end 27 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /spec/models/comment_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'rails_helper' 4 | 5 | RSpec.describe Comment, type: :model do 6 | context 'Associations' do 7 | it { should belong_to(:user) } 8 | it { should belong_to(:post) } 9 | it { should have_many(:likes).dependent(:destroy) } 10 | end 11 | 12 | context 'validations' do 13 | before do 14 | @comment = FactoryBot.create(:comment) 15 | end 16 | it 'is invalid when comment content is null or empty' do 17 | comment2 = FactoryBot.build(:comment, content: nil) 18 | expect(comment2).to_not be_valid 19 | end 20 | 21 | it 'is valid when comment content has value' do 22 | expect(@comment).to be_valid 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 | context 'Associations' do 7 | it { should have_many(:posts).dependent(:destroy) } 8 | it { should have_many(:comments).dependent(:destroy) } 9 | it { should have_many(:likes).dependent(:destroy) } 10 | it { should have_many(:friendships).dependent(:destroy) } 11 | it { 12 | should have_many(:friends) 13 | .through(:friendships) 14 | } 15 | end 16 | 17 | it 'callbacks generate_gravatar_for_user before create' do 18 | @user = FactoryBot.build(:user) 19 | expect(@user.image_link).to be_nil 20 | 21 | @user.save 22 | expect(@user.image_link).to_not be_nil 23 | end 24 | end 25 | -------------------------------------------------------------------------------- /config/initializers/inflections.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | # Be sure to restart your server when you modify this file. 3 | 4 | # Add new inflection rules using the following format. Inflections 5 | # are locale specific, and you may define rules for as many different 6 | # locales as you wish. All of these examples are active by default: 7 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 8 | # inflect.plural /^(ox)$/i, '\1en' 9 | # inflect.singular /^(ox)en/i, '\1' 10 | # inflect.irregular 'person', 'people' 11 | # inflect.uncountable %w( fish sheep ) 12 | # end 13 | 14 | # These inflection rules are supported but not enabled by default: 15 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 16 | # inflect.acronym 'RESTful' 17 | # end 18 | -------------------------------------------------------------------------------- /goorm.manifest: -------------------------------------------------------------------------------- 1 | {"author":"101357057702460288589_d9ri5_google","name":"fbreplica","type":"ruby","detailedtype":"rubyonrails","description":" A managed container to practise, Ruby on Rails, Heroku deployment, AWS deployment, CI using Docker / Kubernetes, APIs design, hosted database (SQL, NoSQL)","date":"2019-07-02T14:46:30.000Z","plugins":{"goorm.plugin.ruby":[{"plugin.ruby.main":"index","plugin.ruby.source_path":"","plugin.ruby.run_on":"server","plugin.ruby.run_option":"s -b 0.0.0.0 -p $USER_PORT","plugin.ruby.log_path":"./server.log","name":"ruby"}]},"is_user_plugin":false,"storage":"container","project_domain":[{"id":"101357057702460288589_d9ri5_google","url":"devise-auth-saas.run.goorm.io","port":"3000"}],"author_email":"johnsonsirv@gmail.com","author_name":"Victor Okeugo","ignore_patterns":[]} -------------------------------------------------------------------------------- /.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 | 29 | # Ignore application configuration 30 | /config/application.yml 31 | -------------------------------------------------------------------------------- /features/user_and_likes.feature: -------------------------------------------------------------------------------- 1 | Feature: User and likes 2 | In order to add my reactions to posts and comments 3 | As a user 4 | I want to like and unlike posts or comments 5 | 6 | Background: 7 | Given a user with email "demouser@onet.com" is already logged in 8 | And I can see a post in my timeline 9 | And I can see a comment for this post 10 | 11 | Scenario: Like a Post 12 | When I like post 13 | Then post likes should contain user 14 | 15 | Scenario: Unlike a Post 16 | Given I have liked post 17 | When I unlike post 18 | Then post likes should not contain user 19 | 20 | Scenario: Like a Comment 21 | When I like post comment 22 | Then comment likes should contain user 23 | 24 | Scenario: Unlike a Comment 25 | Given I have liked comment 26 | When I unlike comment 27 | Then comment likes should not contain user -------------------------------------------------------------------------------- /app/views/users/_user_timeline_banner.html.erb: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 |
5 |
6 |
<%= gravatar_for(user, size: 175) %>
7 |
<%= user.fullname %> 8 | <%= show_banner_call_to_action_for user %> 9 |
10 |
11 |
12 |
    13 |
  • Timeline
  • 14 |
  • About
  • 15 |
  • Friends <%= count_friends_for user %>
  • 16 |
  • About
  • 17 |
18 |
19 |
20 |
21 |
22 |
-------------------------------------------------------------------------------- /app/views/users/_user_friend.html.erb: -------------------------------------------------------------------------------- 1 |
2 |
Friends
3 | <% if friends?(user) %> 4 |
5 | <% friends_for(user).each do |f| %> 6 |
7 |
<%= gravatar_for(f, size: 30) %>
8 | <%= link_to f.fullname, f %> 9 |
10 | <% end %> 11 |
12 | <% else %> 13 |

No friends yet

14 | <% end %> 15 |
16 | 17 |
18 | <% if mutual_friends_with?(user) %> 19 | <% mutual_friends_with(user).each do |f| %> 20 | <%= link_to f.fullname, f %> 21 | <% end %> 22 | <% else %> 23 |

No mutual friends

24 | <% end %> 25 |
-------------------------------------------------------------------------------- /config/routes.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | Rails.application.routes.draw do 4 | devise_for :users, path_names: { 5 | sign_in: 'login', sign_out: 'logout', sign_up: 'signup' 6 | }, controllers: { omniauth_callbacks: 'omniauth_callbacks' } 7 | 8 | resources :users, only: %i[index show] 9 | resources :posts, only: %i[index create edit update destroy] 10 | resources :comments, only: %i[create destroy] 11 | resources :likes, only: %i[create destroy] 12 | resources :friendships, only: %i[create update destroy] 13 | 14 | get '/friends', to: 'friendships#index' 15 | get '/friend_requests', to: 'friendships#friend_requests' 16 | get '/mutual_friends', to: 'friendships#mutual_friends' 17 | 18 | unauthenticated do 19 | as :user do 20 | root to: 'devise/registrations#new' 21 | end 22 | end 23 | 24 | root to: 'posts#index' 25 | end 26 | -------------------------------------------------------------------------------- /app/views/application/_navbar_login_form.html.erb: -------------------------------------------------------------------------------- 1 | 2 | <%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %> 3 |
4 |
5 | <%= f.label :email %> 6 | <%= f.email_field :email, autofocus: true, placeholder: 'Email', autocomplete: "email", class: "custom-control" %> 7 | <%= link_to "Forgot account?", '#' %> 8 |
9 |
10 | <%= f.label :password %> 11 | <%= f.password_field :password, placeholder: 'Password', autocomplete: "current-password", class: "custom-control" %> 12 | <%= link_to "Sign in with Facebook", user_facebook_omniauth_authorize_path %> 13 |
14 |
15 | <%= f.submit "Log In", class: "btn mt-2 btn-sm navbar-login-btn ml-1" %> 16 |
17 |
18 | <% end %> 19 | -------------------------------------------------------------------------------- /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 jquery3 14 | //= require popper 15 | //= require bootstrap-sprockets 16 | //= require rails-ujs 17 | //= require activestorage 18 | //= require turbolinks 19 | //= require_tree . 20 | -------------------------------------------------------------------------------- /spec/models/friendship_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'rails_helper' 4 | 5 | RSpec.describe Friendship, type: :model do 6 | it { should belong_to(:user) } 7 | it { should belong_to(:friend).class_name('User') } 8 | 9 | context 'validations' do 10 | before do 11 | @user1 = FactoryBot.create(:user) 12 | @user2 = FactoryBot.create(:user) 13 | end 14 | 15 | it 'is invalid without a user or friend' do 16 | @friendship = Friendship.create(user: @user1) 17 | expect(@friendship).to_not be_valid 18 | end 19 | 20 | it 'is valid with a user and friend' do 21 | @friendship = Friendship.create(user: @user1, friend: @user2) 22 | expect(@friendship).to be_valid 23 | end 24 | 25 | it 'is invalid when a user is the same as friend' do 26 | @friendship = Friendship.create(user: @user1, friend: @user1) 27 | expect(@friendship).to_not be_valid 28 | end 29 | end 30 | end 31 | -------------------------------------------------------------------------------- /features/step_definitions/user_signup_steps.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | Given('I am on the signup page') do 4 | visit new_user_registration_path 5 | end 6 | 7 | When('I submit required fields') do 8 | within '.user-signup-main' do 9 | @params = FactoryBot.build(:user) 10 | fill_in 'user[firstname]', with: @params.firstname 11 | fill_in 'user[lastname]', with: @params.lastname 12 | fill_in 'user[email]', with: @params.email 13 | fill_in 'user[password]', with: @params.password 14 | select @params.dob.day, from: 'user[dob(3i)]' 15 | select Date::MONTHNAMES[@params.dob.month], from: 'user[dob(2i)]' 16 | select @params.dob.year, from: 'user[dob(1i)]' 17 | choose @params.sex 18 | 19 | click_button 'Sign Up' 20 | end 21 | end 22 | 23 | Then('I should see my bio') do 24 | fullname = "#{@params.firstname.capitalize!} #{@params.lastname.capitalize!}" 25 | expect(page).to have_content @params.firstname 26 | end 27 | -------------------------------------------------------------------------------- /app/controllers/likes_controller.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class LikesController < ApplicationController 4 | before_action :find_resource_to_be_liked 5 | 6 | def create 7 | return like_resource(@likeable) unless liked?(@likeable) 8 | destroy 9 | end 10 | 11 | def destroy 12 | Like.unlike_resource(@likeable, current_user) 13 | redirect_to back_with_anchored_resource anchor: @likeable.id 14 | end 15 | 16 | private 17 | 18 | def find_resource_to_be_liked 19 | if params[:post_id] 20 | @likeable = Post.find_by_id(params[:post_id]) 21 | elsif params[:comment_id] 22 | @likeable = Comment.find_by_id(params[:comment_id]) 23 | end 24 | end 25 | 26 | def like_resource(resource) 27 | Like.add_like_to_resource(resource, current_user) 28 | redirect_to back_with_anchored_resource anchor: resource.id 29 | end 30 | 31 | def liked?(resource) 32 | resource.likes.find_by(user: current_user) 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /bin/update: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | require 'fileutils' 5 | include FileUtils 6 | 7 | # path to your application root. 8 | APP_ROOT = File.expand_path('..', __dir__) 9 | 10 | def system!(*args) 11 | system(*args) || abort("\n== Command #{args} failed ==") 12 | end 13 | 14 | chdir APP_ROOT do 15 | # This script is a way to update your development environment automatically. 16 | # Add necessary update steps to this file. 17 | 18 | puts '== Installing dependencies ==' 19 | system! 'gem install bundler --conservative' 20 | system('bundle check') || system!('bundle install') 21 | 22 | # Install JavaScript dependencies if using Yarn 23 | # system('bin/yarn') 24 | 25 | puts "\n== Updating database ==" 26 | system! 'bin/rails db:migrate' 27 | 28 | puts "\n== Removing old logs and tempfiles ==" 29 | system! 'bin/rails log:clear tmp:clear' 30 | 31 | puts "\n== Restarting application server ==" 32 | system! 'bin/rails restart' 33 | end 34 | -------------------------------------------------------------------------------- /config/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 | -------------------------------------------------------------------------------- /features/user_login.feature: -------------------------------------------------------------------------------- 1 | Feature: Login as an existing User 2 | In order to view, add posts, comments and likes 3 | As a user 4 | I want to log in with my email 5 | 6 | Background: 7 | Given a user with email "demouser@onet.com" exists in database 8 | And I access the login form 9 | 10 | Scenario: Valid Login Credentials 11 | When I submit correct login credentials 12 | Then I should see my timeline 13 | 14 | Scenario: Incorrect Login Credentials 15 | When I submit incorrect login credentials 16 | Then I should see login error 17 | 18 | Scenario: Login through the navigation form 19 | When I access navbar login form 20 | And I submit correct credentials through the navbar form 21 | Then I should also see my timeline 22 | 23 | Scenario: Access Restricted pages 24 | When I access post timeline 25 | Then I should be redirected to login 26 | 27 | @omniauth_test 28 | Scenario: Sign in with facebook 29 | Given I am signed in with facebook 30 | Then I should see user firstname "omniauthfirstname" 31 | 32 | -------------------------------------------------------------------------------- /app/controllers/comments_controller.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class CommentsController < ApplicationController 4 | before_action :find_comment, only: [:destroy] 5 | 6 | def create 7 | save_comment comment_params 8 | end 9 | 10 | def destroy 11 | @comment.destroy 12 | set_flash_notice 'notice', 'Comment deleted' 13 | redirect_to back_with_anchored_resource anchor: @comment.id 14 | end 15 | 16 | private 17 | 18 | def save_comment(comment_params) 19 | @comment = current_user.add_new_comment(comment_params) 20 | if @comment.errors.any? 21 | set_flash_notice 'alert', 'Comment could not be saved. Did you forget to write something?' 22 | else 23 | set_flash_notice 'notice', 'Comment added successfully' 24 | end 25 | 26 | redirect_back fallback_location: root_path 27 | end 28 | 29 | def comment_params 30 | params.require(:comment).permit(:content, :post_id) 31 | end 32 | 33 | def find_comment 34 | @comment = Comment.find(params[:id]) 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /app/views/devise/sessions/_login_form.html.erb: -------------------------------------------------------------------------------- 1 |
Log into facebook
2 | 3 | <%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %> 4 |
5 | <%= f.email_field :email, autofocus: true, autocomplete: "email", class: 'form-control', placeholder: "Email" %> 6 |
7 | 8 |
9 | <%= f.password_field :password, autocomplete: "current-password", class: 'form-control', placeholder: "Password" %> 10 |
11 | 12 | 13 |
14 | <%= f.submit "Log In", class: "btn btn-lg btn-block custom-default-btn", title: "Log in" %> 15 |

16 | <%= link_to "Forgot account?", '#', class: "text text-primary" %> 17 | <%= link_to "Sign in with Facebook", user_facebook_omniauth_authorize_path, class: "text text-primary disabled", id: "omniauth-btn" %>
18 | <%= link_to 'Create new Account', new_user_registration_path, class: "text text-primary" %> 19 |

20 |
21 | <% end %> -------------------------------------------------------------------------------- /features/step_definitions/user_and_mutual_friends_steps.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | Given('the following users are friends:') do |table| 4 | i = 0 5 | list = [] 6 | table.hashes.each do |record| 7 | list[i] = FactoryBot.create(:user, email: record['email'].to_s) 8 | i += 1 9 | end 10 | @user1 = list[0] 11 | @user2 = list[1] 12 | @user3 = list[2] 13 | 14 | Friendship.create(user: @user1, friend: @user2, confirmed: true) 15 | Friendship.create(user: @user2, friend: @user1, confirmed: true) 16 | 17 | Friendship.create(user: @user1, friend: @user3, confirmed: true) 18 | Friendship.create(user: @user3, friend: @user1, confirmed: true) 19 | 20 | Friendship.create(user: @user2, friend: @user3, confirmed: true) 21 | Friendship.create(user: @user3, friend: @user2, confirmed: true) 22 | end 23 | 24 | When('the user {string} view mutual friends') do |_string| 25 | @mutual_friend = Friendship.mutual_friends_between(@user1, @user3) 26 | end 27 | 28 | Then('{string} should be mutual friends with {string}') do |_string, _string2| 29 | expect(@mutual_friend.first).to eq(@user2) 30 | end 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Victor Okeugo 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 | -------------------------------------------------------------------------------- /app/helpers/comments_helper.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module CommentsHelper 4 | def show_comment_actions_for(resource) 5 | "#{show_likeable_link_for(resource)} - 6 | #{reply_comment} - 7 | #{delete_comment_for(resource)} -".html_safe 8 | end 9 | 10 | def show_likeable_link_for(resource) 11 | return unlike_comment_link(resource) if liked_by_user?(resource) 12 | 13 | like_comment_link(resource) 14 | end 15 | 16 | def like_comment_link(resource) 17 | link_to 'Like', likes_path(comment_id: resource.id), 18 | method: :post, class: 'pr-1' 19 | end 20 | 21 | def unlike_comment_link(resource) 22 | link_to 'Unlike', likes_path(comment_id: resource.id), 23 | method: :post, class: 'pr-1 text unlike-link' 24 | end 25 | 26 | def delete_comment_for(resource) 27 | return link_to 'Delete', comment_path(resource), 28 | method: :delete, class: 'pr-1' if user_can_modify?(resource) 29 | end 30 | 31 | def user_can_modify?(comment) 32 | comment.user == current_user 33 | end 34 | 35 | def reply_comment 36 | link_to 'Reply', '#', class: 'pr-1' 37 | end 38 | end 39 | -------------------------------------------------------------------------------- /bin/setup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | require 'fileutils' 5 | include FileUtils 6 | 7 | # path to your application root. 8 | APP_ROOT = File.expand_path('..', __dir__) 9 | 10 | def system!(*args) 11 | system(*args) || abort("\n== Command #{args} failed ==") 12 | end 13 | 14 | chdir APP_ROOT do 15 | # This script is a starting point to setup your application. 16 | # Add necessary setup steps to this file. 17 | 18 | puts '== Installing dependencies ==' 19 | system! 'gem install bundler --conservative' 20 | system('bundle check') || system!('bundle install') 21 | 22 | # Install JavaScript dependencies if using Yarn 23 | # system('bin/yarn') 24 | 25 | # puts "\n== Copying sample files ==" 26 | # unless File.exist?('config/database.yml') 27 | # cp 'config/database.yml.sample', 'config/database.yml' 28 | # end 29 | 30 | puts "\n== Preparing database ==" 31 | system! 'bin/rails db:setup' 32 | 33 | puts "\n== Removing old logs and tempfiles ==" 34 | system! 'bin/rails log:clear tmp:clear' 35 | 36 | puts "\n== Restarting application server ==" 37 | system! 'bin/rails restart' 38 | end 39 | -------------------------------------------------------------------------------- /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, as: :likeable, dependent: :destroy 7 | 8 | scope :authored_by, lambda { |user| 9 | where(user_id: user).includes(:user) 10 | .order(updated_at: :desc) 11 | .includes(:comments).includes(:likes) 12 | } 13 | scope :authored_by_user_or_friends, lambda { |user| 14 | where(user_id: user) 15 | .or(where(user_id: Friendship.confirmed_friends_for(user))) 16 | .includes(:user).order(updated_at: :desc) 17 | .includes(:comments).includes(:likes) 18 | } 19 | 20 | validates :content, presence: true 21 | 22 | def self.timeline_posts_for(user) 23 | authored_by_user_or_friends(user) 24 | end 25 | 26 | def update_post(post_params) 27 | if update_attributes post_params 28 | 'Post updated' 29 | else 30 | 'Post update failed' 31 | end 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /app/controllers/friendships_controller.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class FriendshipsController < ApplicationController 4 | def create 5 | new_request = current_user.request_new_friendship_with(params[:other_user]) 6 | set_flash_notice 'notice', new_request 7 | redirect_back fallback_location: root_path 8 | end 9 | 10 | def update 11 | other_user = User.find_by(id: params[:id]) 12 | confirmed = Friendship.confirm_friend_request_for(current_user, other_user) 13 | set_flash_notice 'notice', 'Friendship confirmed' if confirmed 14 | redirect_back fallback_location: root_path 15 | end 16 | 17 | def destroy 18 | friend = User.find_by(id: params[:id]) 19 | Friendship.remove_friendship_between(current_user, friend) 20 | set_flash_notice 'notice', 'Friendship Removed' 21 | redirect_back fallback_location: root_path 22 | end 23 | 24 | def friend_requests 25 | @friends = Friendship.unconfirmed_friends_for current_user 26 | render 'friends' 27 | end 28 | 29 | def mutual_friends 30 | other_user = User.find_by(id: params[:id]) 31 | return if current_user == other_user 32 | 33 | @mutual_friends = Friendship.mutual_friends_between(user, other_user) 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /config/initializers/content_security_policy.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | # Be sure to restart your server when you modify this file. 3 | 4 | # Define an application-wide content security policy 5 | # For further information see the following documentation 6 | # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy 7 | 8 | # Rails.application.config.content_security_policy do |policy| 9 | # policy.default_src :self, :https 10 | # policy.font_src :self, :https, :data 11 | # policy.img_src :self, :https, :data 12 | # policy.object_src :none 13 | # policy.script_src :self, :https 14 | # policy.style_src :self, :https 15 | 16 | # # Specify URI for violation reports 17 | # # policy.report_uri "/csp-violation-report-endpoint" 18 | # end 19 | 20 | # If you are using UJS then enable automatic nonce generation 21 | # Rails.application.config.content_security_policy_nonce_generator = -> request { SecureRandom.base64(16) } 22 | 23 | # Report CSP violations to a specified URI 24 | # For further information see the following documentation: 25 | # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only 26 | # Rails.application.config.content_security_policy_report_only = true 27 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /config/application.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require_relative 'boot' 4 | 5 | require 'rails' 6 | # Pick the frameworks you want: 7 | require 'active_model/railtie' 8 | require 'active_job/railtie' 9 | require 'active_record/railtie' 10 | require 'active_storage/engine' 11 | require 'action_controller/railtie' 12 | require 'action_mailer/railtie' 13 | require 'action_view/railtie' 14 | require 'action_cable/engine' 15 | require 'sprockets/railtie' 16 | # require "rails/test_unit/railtie" 17 | 18 | # Require the gems listed in Gemfile, including any gems 19 | # you've limited to :test, :development, or :production. 20 | Bundler.require(*Rails.groups) 21 | 22 | module Fbreplica 23 | class Application < Rails::Application 24 | # Initialize configuration defaults for originally generated Rails version. 25 | config.load_defaults 5.2 26 | 27 | # Settings in config/environments/* take precedence over those specified here. 28 | # Application configuration can go into files in config/initializers 29 | # -- all .rb files in that directory are automatically loaded after loading 30 | # the framework and any gems in your application. 31 | 32 | # Don't generate system test files. 33 | config.generators.system_tests = nil 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /app/assets/stylesheets/fb_custom.scss: -------------------------------------------------------------------------------- 1 | .custom-default-btn { background-color: $default-button-bg; color: #fff; font-weight: bold; 2 | &:hover { background-color: $default-button-hover-bg; color: #fff; font-weight: bold;} 3 | } 4 | 5 | .fb-signup-btn { 6 | background: linear-gradient(#67ae55, #578843); 7 | background-color: #69a74e; 8 | box-shadow: inset 0 1px 1px #a4e388; 9 | border-color: #3b6e22 #3b6e22 #2c5115; 10 | border-radius: 5px; 11 | color: #fff; 12 | letter-spacing: 1px; 13 | position: relative; 14 | text-shadow: 0 1px 2px rgba(0,0,0,.5); 15 | min-width: 194px; 16 | font-family: 'Freight Sans Bold', Helvetica, Arial, sans-serif !important; 17 | font-weight: bold !important; 18 | letter-spacing: normal; 19 | &:hover{ 20 | background: linear-gradient(#578843, #578843); 21 | background-color: #69a74e; 22 | box-shadow: inset 0 1px 1px #a4e388; 23 | border-color: #3b6e22 #3b6e22 #2c5115; 24 | border-radius: 5px; 25 | color: #fff; 26 | letter-spacing: 1px; 27 | position: relative; 28 | text-shadow: 0 1px 2px rgba(0,0,0,.5); 29 | min-width: 194px; 30 | font-family: 'Freight Sans Bold', Helvetica, Arial, sans-serif !important; 31 | font-weight: bold !important; 32 | letter-spacing: normal; 33 | } 34 | } -------------------------------------------------------------------------------- /app/views/application/_edit_post_form.html.erb: -------------------------------------------------------------------------------- 1 | <%= form_for(@post) do |f| %> 2 |
3 |
Edit Post
4 |
5 | <%= f.text_area :content, placeholder: "What's on your mind, #{current_user.fullname}?", 6 | class: "form-control", rows:"3" %> 7 |
8 | 20 |
21 | <% end %> -------------------------------------------------------------------------------- /app/views/application/_post_form.html.erb: -------------------------------------------------------------------------------- 1 | <%= form_for(@post) do |f| %> 2 |
3 |
Create Post
4 |
5 | <%= f.text_area :content, placeholder: "What's on your mind, #{current_user.fullname}?", 6 | class: "form-control", rows:"3" %> 7 |
8 | 20 |
21 | <% end %> -------------------------------------------------------------------------------- /app/views/application/_user_top_menu.html.erb: -------------------------------------------------------------------------------- 1 | <%= gravatar_for(current_user, size: 30) %> 2 | 5 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /features/step_definitions/user_manage_posts_steps.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | Given('a user with email {string} is already logged in') do |current_user_email| 4 | @user = FactoryBot.create(:user, email: current_user_email) 5 | visit new_user_session_path 6 | within '.default-user-login' do 7 | fill_in 'user[email]', with: @user.email 8 | fill_in 'user[password]', with: @user.password 9 | click_button 'Log In' 10 | end 11 | end 12 | 13 | When('I submit new post using post form') do 14 | @post = FactoryBot.build(:post) 15 | within '.new-post' do 16 | fill_in 'post[content]', with: @post.content 17 | click_button 'Post' 18 | end 19 | end 20 | 21 | Then('I should see post in timeline') do 22 | expect(page).to have_content(@post.content) 23 | end 24 | 25 | When('I choose edit post from dropdown menu') do 26 | @post = FactoryBot.create(:post, user: @user) 27 | visit edit_post_path @post 28 | end 29 | 30 | When('I submit post update') do 31 | @post_update = FactoryBot.build(:post, content: 'Updated Post Content') 32 | fill_in 'post[content]', with: @post_update.content 33 | click_button 'Update' 34 | end 35 | 36 | Then('post content should be updated') do 37 | expect(page).to have_content(@post_update.content) 38 | end 39 | 40 | When('I choose delete post from dropdown menu') do 41 | @post = FactoryBot.create(:post, user: @user) 42 | @post.destroy 43 | end 44 | 45 | Then('post should no longer exist') do 46 | deleted_post = Post.find_by(id: @post) 47 | expect(deleted_post).to be_nil 48 | end 49 | -------------------------------------------------------------------------------- /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/ 4 | 5 | .find-friends { 6 | .find-friends-gravatar {width: 120px; height: 120px; } 7 | a { color: $default-link-color; font-weight: bold; font-size: 1.2em; } 8 | } 9 | 10 | .user-bio-friends { font-size: 12px; 11 | .user-profile-icons{ 12 | img{border-radius: 50%; } 13 | } 14 | } 15 | 16 | .timeline-banner-section { 17 | height:350px; 18 | .cover-image{ 19 | background-color: #000; 20 | height: 85%; 21 | } 22 | .timeline-menu { 23 | background-color: #fff; 24 | width: 100%; height: 15%; 25 | color: $default-link-color; 26 | ul{ 27 | list-style: none; 28 | padding-left: 14em; 29 | li { 30 | display:inline-block; 31 | font-size: 14px; 32 | font-weight: bold; 33 | padding: 0.8em; 34 | margin: 0; 35 | span {font-size: 11px; color: #1c1e21; font-weight: normal;} 36 | 37 | } 38 | } 39 | } 40 | .photo-name{ 41 | margin-left: 220px; 42 | margin-top: 52px; 43 | font-weight: bold; 44 | font-size: 1.8em; 45 | color: #fff; 46 | padding-right: 2.5em; 47 | .btn-timeline-friend { background-color: #fff; 48 | font-size: 12px; color: #1c1e21; font-weight: bold; 49 | } 50 | } 51 | .user-timeline-photo { 52 | img { height: 175px; width: 175px; 53 | position: relative; 54 | top: 150px; 55 | left: 24px; 56 | border-radius: 50%; border: solid 4px #fff; 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /config/puma.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # Puma can serve each request in a thread from an internal thread pool. 4 | # The `threads` method setting takes two numbers: a minimum and maximum. 5 | # Any libraries that use thread pools should be configured to match 6 | # the maximum value specified for Puma. Default is set to 5 threads for minimum 7 | # and maximum; this matches the default thread size of Active Record. 8 | # 9 | threads_count = ENV.fetch('RAILS_MAX_THREADS') { 5 } 10 | threads threads_count, threads_count 11 | 12 | # Specifies the `port` that Puma will listen on to receive requests; default is 3000. 13 | # 14 | port ENV.fetch('PORT') { 3000 } 15 | 16 | # Specifies the `environment` that Puma will run in. 17 | # 18 | environment ENV.fetch('RAILS_ENV') { 'development' } 19 | 20 | # Specifies the number of `workers` to boot in clustered mode. 21 | # Workers are forked webserver processes. If using threads and workers together 22 | # the concurrency of the application would be max `threads` * `workers`. 23 | # Workers do not work on JRuby or Windows (both of which do not support 24 | # processes). 25 | # 26 | # workers ENV.fetch("WEB_CONCURRENCY") { 2 } 27 | 28 | # Use the `preload_app!` method when specifying a `workers` number. 29 | # This directive tells Puma to first boot the application and load code 30 | # before forking the application. This takes advantage of Copy On Write 31 | # process behavior so workers use less memory. 32 | # 33 | # preload_app! 34 | 35 | # Allow puma to be restarted by `rails restart` command. 36 | plugin :tmp_restart 37 | -------------------------------------------------------------------------------- /features/step_definitions/user_and_friendship_request_steps.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | Given('the following users exists:') do |table| 4 | i = 0 5 | list = [] 6 | table.hashes.each do |record| 7 | list[i] = FactoryBot.create(:user, email: record['email'].to_s) 8 | i += 1 9 | end 10 | @user1 = list[0] 11 | @user2 = list[1] 12 | end 13 | 14 | Given('{string} is logged in') do |_current_user_email| 15 | visit new_user_session_path 16 | within '.default-user-login' do 17 | fill_in 'user[email]', with: @user1.email 18 | fill_in 'user[password]', with: @user1.password 19 | click_button 'Log In' 20 | end 21 | end 22 | 23 | When('I send request to {string}') do |_string| 24 | visit user_path @user2 25 | click_link 'Add Friend' 26 | end 27 | 28 | Then('I should have pending request') do 29 | expect(page).to have_content(/Friend Request sent/) 30 | end 31 | 32 | Given('the user {string} logs in') do |_string| 33 | visit new_user_session_path 34 | within '.default-user-login' do 35 | fill_in 'user[email]', with: @user2.email 36 | fill_in 'user[password]', with: @user2.password 37 | click_button 'Log In' 38 | end 39 | end 40 | 41 | Given('I have pending request from {string}') do |_string| 42 | @friendship = Friendship.create(user: @user1, friend: @user2, confirmed: false) 43 | end 44 | 45 | When('I accept request from {string}') do |_string| 46 | @friendship.update(confirmed: true) 47 | end 48 | 49 | Then('we should be friends') do 50 | visit user_path @user1 51 | expect(page).to have_content(/Friends/) 52 | end 53 | -------------------------------------------------------------------------------- /app/views/posts/_post.html.erb: -------------------------------------------------------------------------------- 1 |
2 |
3 |
<%= gravatar_for(post.user, size: 44) %>
4 | 10 |
<%= render 'post_actions', post: post %>
11 |
12 |
13 |

<%= post.content %>

14 |

15 | <%= show_total_post_likes_for(post) %> 16 | <%= show_total_post_comments_for post %> 17 |

18 |
19 |
20 | 21 | <%= show_likeable_button_for_resource(post) %> 22 | 23 | 24 | <%= link_to content_tag(:i, "Comments", class:"fa fa-comments pr-2"), '#', class:"btn btn-sm social-btn" %> 25 | 26 | 27 | <%= link_to content_tag(:i, "Share", class:"fa fa-share pr-2"), '#', class:"btn btn-sm social-btn" %> 28 | 29 |
30 | 31 |
32 | <%= render post.comments %> 33 |
<%= render 'comment_form', post: post %>
34 |
35 |
36 | 37 | 38 | -------------------------------------------------------------------------------- /app/controllers/posts_controller.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class PostsController < ApplicationController 4 | before_action :fetch_timeline_posts, only: [:index] 5 | before_action :initialize_new_post_editor, only: [:index] 6 | before_action :find_post, only: %i[edit update destroy] 7 | 8 | def index; end 9 | 10 | def create 11 | save_post post_params 12 | end 13 | 14 | def edit; end 15 | 16 | def update 17 | post_update post_params 18 | end 19 | 20 | def destroy 21 | @post.destroy 22 | set_flash_notice 'notice', 'Post deleted' 23 | redirect_to root_path 24 | end 25 | 26 | private 27 | 28 | def fetch_timeline_posts 29 | @posts = Post.timeline_posts_for current_user 30 | end 31 | 32 | def save_post(post_params) 33 | @post = current_user.add_new_post(post_params) 34 | if @post.errors.any? 35 | set_flash_notice 'alert', 'Post could not be saved. Did you forget to write something?' 36 | else 37 | set_flash_notice 'notice', 'Post added successfully' 38 | initialize_new_post_editor 39 | end 40 | redirect_back fallback_location: root_path 41 | end 42 | 43 | def post_update(post_params) 44 | if @post.user.eql?(current_user) 45 | set_flash_notice 'notice', @post.update_post(post_params) 46 | else 47 | set_flash_notice 'alert', 'Permission denied for resource' 48 | end 49 | redirect_to root_path 50 | end 51 | 52 | def find_post 53 | @post = Post.find(params[:id]) 54 | end 55 | 56 | def post_params 57 | params.require(:post).permit(:content) 58 | end 59 | end 60 | -------------------------------------------------------------------------------- /app/views/friendships/friends.html.erb: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 |
5 |
Friend Requests
6 |
7 | <% @friends.each do |friend| %> 8 |
9 |
10 |
11 | <%= gravatar_for(friend) %> 12 |
13 |
14 |
15 |
<%= link_to friend.fullname, friend %>
16 |
17 |
18 | 19 | <%= link_to 'Confirm Friend', friendship_path(friend), 20 | method: :patch, class: "btn btn-sm custom-default-btn", 21 | title: "Confirm friend request" %> 22 |
23 |
24 | 25 | <%= link_to 'Remove Request', friendship_path(friend), 26 | method: :delete, 27 | data: { confirm: 'Are you sure you want to remove this request?' }, 28 | class: "btn btn-sm btn-secondary", 29 | title: "Delete friend request" %> 30 |
31 |
32 | <% end %> 33 |
34 |
35 |
36 |
37 |
-------------------------------------------------------------------------------- /app/helpers/application_helper.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module ApplicationHelper 4 | def visible_top_menu 5 | return user_top_menu if user_signed_in? 6 | 7 | visitor_top_menu 8 | end 9 | 10 | def user_top_menu 11 | 'user_top_menu' 12 | end 13 | 14 | def visitor_top_menu 15 | 'visitor_top_menu' 16 | end 17 | 18 | def gravatar_for(user, size: 120) 19 | gravatar_url = "#{user.image_link}?s=#{size}" 20 | image_tag(gravatar_url, alt: user.fullname) 21 | end 22 | 23 | def liked_by_user?(resource) 24 | resource.likes 25 | .find_by(user: current_user) 26 | end 27 | 28 | def count_friend_request(user) 29 | if request?(user) 30 | return Friendship 31 | .unconfirmed_friends_for(user).size 32 | end 33 | 34 | '' 35 | end 36 | 37 | def request?(user) 38 | Friendship 39 | .unconfirmed_friends_for(user).any? 40 | end 41 | 42 | def friend_requests_for(user) 43 | Friendship.pending_requests.where(friend: user) 44 | .order(created_at: :desc) 45 | .limit(5).map(&:user) 46 | end 47 | 48 | def show_friend_request_icon(user) 49 | if request?(user) 50 | return link_to content_tag(:i, content_tag(:b, count_friend_request(user)), 51 | class: 'fa fa-users has-request'), friend_requests_path, 52 | title: pluralize(count_friend_request(user), 'Friend request').to_s, 53 | class: 'nav-link' 54 | end 55 | 56 | link_to content_tag(:i, '', class: 'fa fa-users'), 57 | friend_requests_path, 58 | title: 'No Friend request', 59 | class: 'nav-link' 60 | end 61 | end 62 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /db/migrate/20191027154938_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 | # Registrable 11 | t.string :firstname 12 | t.string :lastname 13 | t.string :sex 14 | t.date :dob 15 | t.string :image_link, null: false 16 | 17 | ## Recoverable 18 | t.string :reset_password_token 19 | t.datetime :reset_password_sent_at 20 | 21 | ## Rememberable 22 | t.datetime :remember_created_at 23 | 24 | ## Trackable 25 | # t.integer :sign_in_count, default: 0, null: false 26 | # t.datetime :current_sign_in_at 27 | # t.datetime :last_sign_in_at 28 | # t.inet :current_sign_in_ip 29 | # t.inet :last_sign_in_ip 30 | 31 | ## Confirmable 32 | # t.string :confirmation_token 33 | # t.datetime :confirmed_at 34 | # t.datetime :confirmation_sent_at 35 | # t.string :unconfirmed_email # Only if using reconfirmable 36 | 37 | ## Lockable 38 | # t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts 39 | # t.string :unlock_token # Only if unlock strategy is :email or :both 40 | # t.datetime :locked_at 41 | 42 | t.timestamps null: false 43 | end 44 | 45 | add_index :users, :email, unique: true 46 | add_index :users, :reset_password_token, unique: true 47 | # add_index :users, :confirmation_token, unique: true 48 | # add_index :users, :unlock_token, unique: true 49 | end 50 | end 51 | -------------------------------------------------------------------------------- /features/step_definitions/user_and_likes_steps.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | Given('I can see a post in my timeline') do 4 | @post = FactoryBot.create(:post) 5 | within '.new-post' do 6 | fill_in 'post[content]', with: @post.content 7 | click_button 'Post' 8 | end 9 | end 10 | 11 | Given('I can see a comment for this post') do 12 | @comment = FactoryBot.build(:comment) 13 | within '.comment-editor' do 14 | fill_in 'comment[content]', with: @comment.content 15 | click_button 'Comment' 16 | end 17 | end 18 | 19 | When('I like post') do 20 | within '.post-social-actions' do 21 | click_link 'Like' 22 | end 23 | end 24 | 25 | Then('post likes should contain user') do 26 | liker = Post.last.likes.find_by(user_id: @user) 27 | expect(liker).to be_valid 28 | end 29 | 30 | Given('I have liked post') do 31 | within '.post-social-actions' do 32 | click_link 'Like' 33 | end 34 | end 35 | 36 | When('I unlike post') do 37 | within '.post-social-actions' do 38 | click_link 'Unlike' 39 | end 40 | end 41 | 42 | Then('post likes should not contain user') do 43 | liker = Post.last.likes.find_by(user_id: @user) 44 | expect(liker).to be_nil 45 | end 46 | 47 | When('I like post comment') do 48 | within '.comment-actions' do 49 | click_link 'Like' 50 | end 51 | end 52 | 53 | Then('comment likes should contain user') do 54 | liker = Comment.last.likes.find_by(user_id: @user) 55 | expect(liker).to be_valid 56 | end 57 | 58 | Given('I have liked comment') do 59 | within '.comment-actions' do 60 | click_link 'Like' 61 | end 62 | end 63 | 64 | When('I unlike comment') do 65 | within '.comment-actions' do 66 | click_link 'Unlike' 67 | end 68 | end 69 | 70 | Then('comment likes should not contain user') do 71 | liker = Comment.last.likes.find_by(user_id: @user) 72 | expect(liker).to be_nil 73 | end 74 | -------------------------------------------------------------------------------- /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 | 7 | scope :pending_requests, -> { where(confirmed: false) } 8 | scope :confirmed, -> { where(confirmed: true) } 9 | 10 | default_scope -> { includes(:user) } 11 | 12 | validate :self_irreflexive 13 | validates :user, presence: true 14 | validates :friend, presence: true, uniqueness: { scope: :user } 15 | 16 | def self.confirm_friend_request_for(user, friend) 17 | friendship = where(user: user, friend: friend) 18 | .or(where(user: friend, friend: user)) 19 | 20 | transaction do 21 | friendship.update(confirmed: true) 22 | user.friendships.create(friend: friendship.first.user, confirmed: true) 23 | end 24 | end 25 | 26 | def self.remove_friendship_between(user, friend) 27 | friendship = where(user: user, friend: friend) 28 | .or(where(user: friend, friend: user)) 29 | 30 | friendship.destroy_all 31 | end 32 | 33 | def self.unconfirmed_friends_for(user) 34 | pending_requests.where(friend: user).map(&:user) 35 | end 36 | 37 | def self.confirmed_friends_for(user) 38 | confirmed.where(user: user).map(&:friend) 39 | end 40 | 41 | def self.mutual_friends_between(user, other_user) 42 | find_by_sql(["SELECT friendships.* 43 | FROM friendships 44 | WHERE friendships.user_id = ? 45 | AND friendships.friend_id 46 | IN ( SELECT friendships.friend_id 47 | FROM friendships 48 | WHERE friendships.user_id = ? 49 | AND confirmed = ? 50 | );", user.id, other_user.id, true]).map(&:friend) 51 | end 52 | 53 | private 54 | 55 | def self_irreflexive 56 | msg = "can't be friends with self" 57 | errors.add(:friendship_is_irreflexive!, msg) if user == friend 58 | end 59 | end 60 | -------------------------------------------------------------------------------- /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.4.0' 7 | 8 | gem 'rails', '~> 5.2.3' 9 | gem 'pg', '>= 0.18', '< 2.0' 10 | gem 'puma', '~> 3.12' 11 | 12 | # UI 13 | gem 'bootstrap', '~> 4.3.1' 14 | gem 'font-awesome-rails' 15 | gem 'jquery-rails' 16 | gem 'sass-rails', '~> 5.0' 17 | gem 'uglifier', '>= 1.3.0' 18 | 19 | gem 'mini_racer', platforms: :ruby 20 | gem 'coffee-rails', '~> 4.2' 21 | 22 | gem 'turbolinks', '~> 5' 23 | 24 | gem 'jbuilder', '~> 2.5' 25 | # Use Redis adapter to run Action Cable in production 26 | # gem 'redis', '~> 4.0' 27 | # Use ActiveModel has_secure_password 28 | # gem 'bcrypt', '~> 3.1.7' 29 | 30 | # Use ActiveStorage variant 31 | # gem 'mini_magick', '~> 4.8' 32 | 33 | # Use Capistrano for deployment 34 | # gem 'capistrano-rails', group: :development 35 | 36 | gem 'bootsnap', '>= 1.1.0', require: false 37 | 38 | # Authenticaion and Configuration 39 | gem 'devise' 40 | gem 'figaro' 41 | gem 'omniauth-facebook' 42 | 43 | # util 44 | gem 'faker' 45 | gem 'hirb' 46 | 47 | group :development, :test do 48 | gem 'byebug', platforms: %i[mri mingw x64_mingw] 49 | gem 'factory_bot_rails' 50 | gem 'rspec-rails' 51 | end 52 | 53 | group :development do 54 | gem 'listen', '>= 3.0.5', '< 3.2' 55 | gem 'web-console', '>= 3.3.0' 56 | gem 'bullet', '~> 5.7', '>= 5.7.5' 57 | gem 'guard' 58 | gem 'guard-cucumber' 59 | gem 'guard-rspec', require: false 60 | gem 'spring' 61 | gem 'spring-watcher-listen', '~> 2.0.0' 62 | end 63 | 64 | group :test do 65 | gem 'cucumber-rails', require: false 66 | gem 'capybara', '>= 2.15' 67 | gem 'database_cleaner' 68 | gem 'selenium-webdriver' 69 | gem 'shoulda-callback-matchers', '~> 1.1.1' 70 | gem 'shoulda-matchers' 71 | gem 'webdrivers', '~> 4.0' 72 | end 73 | 74 | gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby] 75 | -------------------------------------------------------------------------------- /app/views/application/_homepage_shortcuts_right.html.erb: -------------------------------------------------------------------------------- 1 |
2 |
3 | Friend Requests 4 | 36 |
37 | 38 |
39 | Sponsored 40 |
41 | Sponsored Ads will appear here 42 |
43 |
44 |
45 | English (US) 46 |
47 | 48 | <%= render 'footer' %> 49 |
50 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /features/step_definitions/user_login_steps.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | Given('a user with email {string} exists in database') do |valid_email| 4 | @user = FactoryBot.create(:user, email: valid_email) 5 | end 6 | 7 | Given('I access the login form') do 8 | visit new_user_session_path 9 | end 10 | 11 | When('I submit correct login credentials') do 12 | within '.default-user-login' do 13 | fill_in 'user[email]', with: @user.email 14 | fill_in 'user[password]', with: @user.password 15 | click_button 'Log In' 16 | end 17 | end 18 | 19 | Then('I should see my timeline') do 20 | expect(page).to have_current_path root_path 21 | end 22 | 23 | When('I submit incorrect login credentials') do 24 | within '.default-user-login' do 25 | fill_in 'user[email]', with: 'incorrect@email.com' 26 | fill_in 'user[password]', with: 'incorrectpassword' 27 | click_button 'Log In' 28 | end 29 | end 30 | 31 | Then('I should see login error') do 32 | expect(page).to have_current_path new_user_session_path 33 | end 34 | 35 | When('I access navbar login form') do 36 | visit new_user_registration_path 37 | end 38 | 39 | When('I submit correct credentials through the navbar form') do 40 | within '.navbar' do 41 | fill_in 'user[email]', with: @user.email 42 | fill_in 'user[password]', with: @user.password 43 | click_button 'Log In' 44 | end 45 | end 46 | 47 | Then('I should also see my timeline') do 48 | expect(page).to have_current_path root_path 49 | end 50 | 51 | When('I access post timeline') do 52 | visit posts_path 53 | end 54 | 55 | Then('I should be redirected to login') do 56 | expect(page).to have_current_path new_user_session_path 57 | end 58 | 59 | Given('I am signed in with facebook') do 60 | visit user_facebook_omniauth_authorize_path 61 | end 62 | 63 | Then('I should see user firstname {string}') do |firstname| 64 | expect(page).to have_text(firstname.titlecase) 65 | end 66 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /config/environments/test.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | Rails.application.configure do 4 | # The test environment is used exclusively to run your application's 5 | # test suite. You never need to work with it otherwise. Remember that 6 | # your test database is "scratch space" for the test suite and is wiped 7 | # and recreated between test runs. Don't rely on the data there! 8 | config.cache_classes = true 9 | 10 | # Do not eager load code on boot. This avoids loading your whole application 11 | # just for the purpose of running a single test. If you are using a tool that 12 | # preloads Rails for running tests, you may have to set it to true. 13 | config.eager_load = false 14 | 15 | # Configure public file server for tests with Cache-Control for performance. 16 | config.public_file_server.enabled = true 17 | config.public_file_server.headers = { 18 | 'Cache-Control' => "public, max-age=#{1.hour.to_i}" 19 | } 20 | 21 | # Show full error reports and disable caching. 22 | config.consider_all_requests_local = true 23 | config.action_controller.perform_caching = false 24 | 25 | # Raise exceptions instead of rendering exception templates. 26 | config.action_dispatch.show_exceptions = false 27 | 28 | # Disable request forgery protection in test environment. 29 | config.action_controller.allow_forgery_protection = false 30 | 31 | # Store uploaded files on the local file system in a temporary directory 32 | config.active_storage.service = :test 33 | 34 | config.action_mailer.perform_caching = false 35 | 36 | # Tell Action Mailer not to deliver emails to the real world. 37 | # The :test delivery method accumulates sent emails in the 38 | # ActionMailer::Base.deliveries array. 39 | config.action_mailer.delivery_method = :test 40 | 41 | # Print deprecation notices to the stderr. 42 | config.active_support.deprecation = :stderr 43 | 44 | # Raises error for missing translations 45 | # config.action_view.raise_on_missing_translations = true 46 | end 47 | -------------------------------------------------------------------------------- /app/views/devise/registrations/_signup_form.html.erb: -------------------------------------------------------------------------------- 1 |

Create a new account

2 |
It’s quick and easy.
3 | 4 | <%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %> 5 | <%= render "devise/shared/error_messages", resource: resource %> 6 | 7 |
8 | <%= f.text_field :firstname, autofocus: true, autocomplete: "firstname", class: "form-control", placeholder: "First name" %> 9 |
10 | 11 |
12 | <%= f.text_field :lastname, autofocus: true, autocomplete: "lastname", class: "form-control", placeholder: "Last name" %> 13 |
14 | 15 |
16 | <%= f.email_field :email, autofocus: true, autocomplete: "email", class: "form-control", placeholder: "Email" %> 17 |
18 | 19 |
20 | <%= f.password_field :password, autocomplete: "new-password",class: "form-control", placeholder: "New password" %> 21 |
22 | 23 |
24 | <%= f.label :dob, "Birthday" %> 25 |
26 | <%= f.date_select :dob, { class: 'form-control', order: [:day, :month, :year], 27 | start_year: Date.today.year - 18, end_year: Date.today.year - 100}, {required: true} %> 28 |
29 |
30 | 31 |
32 |
33 | <%= f.label :sex, "Gender" %> 34 |
35 |
36 | <%= f.radio_button :sex, 'Female', checked: false %> 37 | <%= f.label :sex_female, "Female", class: 'ml-2 mt-2' %> 38 |
39 |
40 | <%= f.radio_button :sex, 'Male', checked: false %> 41 | <%= f.label :sex_male, "Male", class: 'ml-2 mt-2' %> 42 |
43 |
44 | <%= f.radio_button :sex, 'Custom', checked: false %> 45 | <%= f.label :sex_custom, "Custom", class: 'ml-2 mt-2' %> 46 |
47 |
48 | 49 |

50 | By clicking Sign Up, you agree to our fictious Terms and Conditions. 51 | We understand about Data or Cookie Policy, but this is just a demo app. 52 |

53 | 54 |
55 | <%= f.submit "Sign Up", class: "btn fb-signup-btn btn-md" %> 56 |
57 | <% end %> -------------------------------------------------------------------------------- /app/helpers/posts_helper.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module PostsHelper 4 | def show_post_actions_for(post) 5 | return "#{edit_button_for post} 6 | #{change_post_date_for post} 7 | #{dropdown_item_divider} 8 | #{hide_from_timeline_for post} 9 | #{delete_button_for post}".html_safe if user_can_modify?(post) 10 | end 11 | 12 | def user_can_modify?(post) 13 | post.user == current_user 14 | end 15 | 16 | def edit_button_for(resource) 17 | link_to 'Edit post', edit_post_path(resource), 18 | class: 'dropdown-item' 19 | end 20 | 21 | def delete_button_for(resource) 22 | link_to 'Delete', resource, 23 | method: :delete, 24 | data: { confirm: 'You are about to delete this post. Do you want to continue?' }, 25 | class: 'dropdown-item text-danger' 26 | end 27 | 28 | def hide_from_timeline_for(_resource) 29 | link_to 'Hide from timeline', '#', 30 | class: 'dropdown-item' 31 | end 32 | 33 | def change_post_date_for(_resource) 34 | link_to 'Change date', '#', 35 | class: 'dropdown-item' 36 | end 37 | 38 | def dropdown_item_divider 39 | content_tag(:div, '', class: 'dropdown-divider') 40 | end 41 | 42 | def unauthenticated_post_actions 43 | content_tag(:a, 'No actions', href: '#', class: 'dropdown-item') 44 | end 45 | 46 | def show_total_post_comments_for(post) 47 | return pluralize(post.comments.count, 'Comment') if post.comments.any? 48 | 49 | '' 50 | end 51 | 52 | def show_total_post_likes_for(post) 53 | return "#{image_tag 'icon-like.png'} 54 | #{post.likes.count}".html_safe if post.likes.any? 55 | 56 | '' 57 | end 58 | 59 | def show_likeable_button_for_resource(resource) 60 | return unlike_button_for(resource) if liked_by_user?(resource) 61 | 62 | like_button_for(resource) 63 | end 64 | 65 | def like_button_for(resource) 66 | link_to content_tag(:i, 'Like', class: 'fa fa-thumbs-up pr-2'), 67 | likes_path(post_id: resource.id), method: :post, 68 | class: 'btn btn-sm social-btn' 69 | end 70 | 71 | def unlike_button_for(resource) 72 | link_to content_tag(:i, 'Unlike', class: 'fa fa-thumbs-up pr-2'), 73 | likes_path(post_id: resource.id), method: :post, 74 | class: 'btn btn-sm unlike-btn' 75 | end 76 | end 77 | -------------------------------------------------------------------------------- /app/models/user.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class User < ApplicationRecord 4 | before_create { email.strip.downcase! } 5 | before_create { generate_gravatar_for_user } 6 | 7 | has_many :posts, dependent: :destroy 8 | has_many :comments, dependent: :destroy 9 | has_many :likes, dependent: :destroy 10 | has_many :friendships, dependent: :destroy 11 | has_many :friends, through: :friendships 12 | 13 | scope :all_except, ->(user) { where.not(id: user) } 14 | 15 | devise :database_authenticatable, :registerable, 16 | :recoverable, :rememberable, :validatable 17 | devise :omniauthable, omniauth_providers: %i[facebook] 18 | 19 | def fullname 20 | "#{firstname} #{lastname}" 21 | end 22 | 23 | def add_new_post(post_params) 24 | posts.create(post_params) 25 | end 26 | 27 | def add_new_comment(comment_params) 28 | comments.create(comment_params) 29 | end 30 | 31 | def request_new_friendship_with(other_user) 32 | new_friend = User.find_by(id: other_user) 33 | return 'Friend request sent' if friendships.create(friend: new_friend) 34 | end 35 | 36 | def pending_friend_request_from?(other_user) 37 | Friendship.pending_requests 38 | .where(friend: self) 39 | .where(user: other_user).exists? 40 | end 41 | 42 | def pending_friend_request_to?(other_user) 43 | Friendship.pending_requests 44 | .where(user: self) 45 | .where(friend: other_user).exists? 46 | end 47 | 48 | def friends_with?(other_user) 49 | Friendship.confirmed 50 | .where(user: self) 51 | .where(friend: other_user).exists? 52 | end 53 | 54 | def self.from_omniauth(auth) 55 | where(provider: auth.provider, uid: auth.uid).first_or_create do |user| 56 | names = auth.info.name.split 57 | user.firstname = names.first 58 | user.lastname = names.last 59 | user.email = auth.info.email 60 | user.password = Devise.friendly_token[0, 20] 61 | user.sex = 'Custom' 62 | user.dob = 18.years.ago 63 | end 64 | end 65 | 66 | def self.new_with_session(params, session) 67 | super.tap do |user| 68 | if data = session['devise.facebook_data'] && session['devise.facebook_data']['extra']['raw_info'] 69 | user.email = data['email'] if user.email.blank? 70 | end 71 | end 72 | end 73 | 74 | private 75 | 76 | def generate_gravatar_for_user 77 | self.image_link = "https://gravatar.com/avatar/#{Digest::MD5.hexdigest(email)}" 78 | end 79 | end 80 | -------------------------------------------------------------------------------- /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 | */ 14 | 15 | @import "bootstrap"; 16 | @import "font-awesome"; 17 | 18 | $blue-navbar-bg: #3b5998; 19 | $default-theme-bg: #e9ebee; 20 | $default-banner-bg: #e9ebee; 21 | $default-button-bg: #4267b2; 22 | $default-button-hover-bg: #2851A3; 23 | $default-link-color: #4267b2; 24 | 25 | body { background: $default-theme-bg; font-family: 'Freight Sans Bold', Helvetica, Arial, sans-serif !important; } 26 | nav { 27 | background-color: $blue-navbar-bg; 28 | background-image: linear-gradient(#4e69a2, #3b5998 50%); 29 | border-bottom: 1px solid #133783; 30 | color: #fff; 31 | 32 | .navbar-brand {font-weight: bold; color: #fff; font-size: 2em;} 33 | 34 | li a { 35 | color: #fff; 36 | font-weight: bold; 37 | font-size: 13px; 38 | i { 39 | color: #000; 40 | } 41 | .has-request { 42 | color: #fff; 43 | font-size: 15px; 44 | b { color: #e50000; font-size: 18px; } 45 | } 46 | } 47 | a:hover{ 48 | color: #eee; 49 | } 50 | #navbarDropdown{ 51 | color: #000; 52 | } 53 | 54 | .navbar-login-btn { 55 | background-color: #4267b2; 56 | border-color: #29487d; 57 | color: #fff; 58 | font-weight: bold; 59 | font-size: 12px; 60 | &:hover{ 61 | background-color: $default-button-hover-bg; 62 | border-color: #29487d; 63 | color: #fff; 64 | font-weight: bold; 65 | } 66 | } 67 | 68 | .custom-form {width: 23em; height:5em; } 69 | .custom-group { width: 60%; 70 | label {font-size: 11px; padding: 0; margin:0; } 71 | a { font-size: 11px; color: #9cb4d8; } 72 | .custom-control {outline: none; 73 | border: solid 1px; 74 | height: 2em; 75 | width: 100%; 76 | font-size: 11px; 77 | padding: 2px; 78 | margin:0; 79 | } 80 | } 81 | 82 | .navbar-gravatar { img{ width: 30px; height: 30px; border-radius: 50%; } width: 30px; height: 30px;} 83 | } 84 | // color: #999; form-text 85 | .terms-condition { color: #777; font-size: 11px; } 86 | 87 | @import "fb_custom"; 88 | @import "posts"; 89 | @import "users"; -------------------------------------------------------------------------------- /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: fbreplica_development 27 | username: pg_dev_user 28 | password: <%= Figaro.env.pg_dev_password %> 29 | host: localhost 30 | port: 5432 31 | 32 | # Schema search path. The server defaults to $user,public 33 | #schema_search_path: myapp,sharedapp,public 34 | 35 | # Minimum log levels, in increasing order: 36 | # debug5, debug4, debug3, debug2, debug1, 37 | # log, notice, warning, error, fatal, and panic 38 | # Defaults to warning. 39 | #min_messages: notice 40 | 41 | # Warning: The database defined as "test" will be erased and 42 | # re-generated from your development database when you run "rake". 43 | # Do not set this db to the same as development or production. 44 | test: 45 | <<: *default 46 | database: fbreplica_test 47 | username: pg_dev_user 48 | password: <%= Figaro.env.pg_dev_password %> 49 | host: localhost 50 | port: 5432 51 | 52 | # As with config/secrets.yml, you never want to store sensitive information, 53 | # like your database password, in your source code. If your source code is 54 | # ever seen by anyone, they now have access to your database. 55 | # 56 | # Instead, provide the password as a unix environment variable when you boot 57 | # the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database 58 | # for a full rundown on how to provide these environment variables in a 59 | # production deployment. 60 | # 61 | # On Heroku and other platform providers, you may have a full connection URL 62 | # available as an environment variable. For example: 63 | # 64 | # DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase" 65 | # 66 | # You can use this database configuration with: 67 | # 68 | # production: 69 | # url: <%= ENV['DATABASE_URL'] %> 70 | # 71 | production: 72 | <<: *default 73 | database: fbreplica_production 74 | username: fbreplica 75 | password: <%= ENV['FBREPLICA_DATABASE_PASSWORD'] %> 76 | -------------------------------------------------------------------------------- /config/environments/development.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | Rails.application.configure do 4 | config.after_initialize do 5 | Bullet.enable = true 6 | Bullet.alert = true 7 | Bullet.bullet_logger = true 8 | Bullet.console = true 9 | # Bullet.growl = true 10 | Bullet.rails_logger = true 11 | Bullet.add_footer = true 12 | Bullet.add_whitelist type: :unused_eager_loading, class_name: 'Friendship', association: :user 13 | end 14 | # Settings specified here will take precedence over those in config/application.rb. 15 | 16 | # In the development environment your application's code is reloaded on 17 | # every request. This slows down response time but is perfect for development 18 | # since you don't have to restart the web server when you make code changes. 19 | config.cache_classes = false 20 | 21 | # Do not eager load code on boot. 22 | config.eager_load = false 23 | 24 | # Show full error reports. 25 | config.consider_all_requests_local = true 26 | 27 | # Enable/disable caching. By default caching is disabled. 28 | # Run rails dev:cache to toggle caching. 29 | if Rails.root.join('tmp', 'caching-dev.txt').exist? 30 | config.action_controller.perform_caching = true 31 | 32 | config.cache_store = :memory_store 33 | config.public_file_server.headers = { 34 | 'Cache-Control' => "public, max-age=#{2.days.to_i}" 35 | } 36 | else 37 | config.action_controller.perform_caching = false 38 | 39 | config.cache_store = :null_store 40 | end 41 | 42 | # Store uploaded files on the local file system 43 | #(see config/storage.yml for options) 44 | config.active_storage.service = :local 45 | 46 | # Don't care if the mailer can't send. 47 | config.action_mailer.raise_delivery_errors = false 48 | 49 | config.action_mailer.perform_caching = false 50 | 51 | # Print deprecation notices to the Rails logger. 52 | config.active_support.deprecation = :log 53 | 54 | # Raise an error on page load if there are pending migrations. 55 | config.active_record.migration_error = :page_load 56 | 57 | # Highlight code that triggered database queries in logs. 58 | config.active_record.verbose_query_logs = true 59 | 60 | # Debug mode disables concatenation and preprocessing of assets. 61 | # This option may cause significant delays in view rendering with a large 62 | # number of complex assets. 63 | config.assets.debug = true 64 | 65 | # Suppress logger output for asset requests. 66 | config.assets.quiet = true 67 | 68 | # Raises error for missing translations 69 | # config.action_view.raise_on_missing_translations = true 70 | 71 | # Use an evented file watcher to asynchronously detect changes in source code, 72 | # routes, locales, etc. This feature depends on the listen gem. 73 | config.file_watcher = ActiveSupport::EventedFileUpdateChecker 74 | end 75 | -------------------------------------------------------------------------------- /Guardfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # A sample Guardfile 4 | # More info at https://github.com/guard/guard#readme 5 | 6 | ## Uncomment and set this to only include directories you want to watch 7 | # directories %w(app lib config test spec features) \ 8 | # .select{|d| Dir.exist?(d) ? d : UI.warning("Directory #{d} does not exist")} 9 | 10 | ## Note: if you are using the `directories` clause above and you are not 11 | ## watching the project directory ('.'), then you will want to move 12 | ## the Guardfile to a watched dir and symlink it back, e.g. 13 | # 14 | # $ mkdir config 15 | # $ mv Guardfile config/ 16 | # $ ln -s config/Guardfile . 17 | # 18 | # and, you'll have to watch "config/Guardfile" instead of "Guardfile" 19 | 20 | guard 'cucumber' do 21 | watch(%r{^features/.+\.feature$}) 22 | watch(%r{^features/support/.+$}) { 'features' } 23 | 24 | watch(%r{^features/step_definitions/(.+)_steps\.rb$}) do |m| 25 | Dir[File.join("**/#{m[1]}.feature")][0] || 'features' 26 | end 27 | end 28 | 29 | # Note: The cmd option is now required due to the increasing number of ways 30 | # rspec may be run, below are examples of the most common uses. 31 | # * bundler: 'bundle exec rspec' 32 | # * bundler binstubs: 'bin/rspec' 33 | # * spring: 'bin/rspec' (This will use spring if running and you have 34 | # installed the spring binstubs per the docs) 35 | # * zeus: 'zeus rspec' (requires the server to be started separately) 36 | # * 'just' rspec: 'rspec' 37 | 38 | guard :rspec, cmd: 'bundle exec rspec' do 39 | require 'guard/rspec/dsl' 40 | dsl = Guard::RSpec::Dsl.new(self) 41 | 42 | # Feel free to open issues for suggestions and improvements 43 | 44 | # RSpec files 45 | rspec = dsl.rspec 46 | watch(rspec.spec_helper) { rspec.spec_dir } 47 | watch(rspec.spec_support) { rspec.spec_dir } 48 | watch(rspec.spec_files) 49 | 50 | # Ruby files 51 | ruby = dsl.ruby 52 | dsl.watch_spec_files_for(ruby.lib_files) 53 | 54 | # Rails files 55 | rails = dsl.rails(view_extensions: %w[erb haml slim]) 56 | dsl.watch_spec_files_for(rails.app_files) 57 | dsl.watch_spec_files_for(rails.views) 58 | 59 | watch(rails.controllers) do |m| 60 | [ 61 | rspec.spec.call("routing/#{m[1]}_routing"), 62 | rspec.spec.call("controllers/#{m[1]}_controller"), 63 | rspec.spec.call("acceptance/#{m[1]}") 64 | ] 65 | end 66 | 67 | # Rails config changes 68 | watch(rails.spec_helper) { rspec.spec_dir } 69 | watch(rails.routes) { "#{rspec.spec_dir}/routing" } 70 | watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" } 71 | 72 | # Capybara features specs 73 | watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") } 74 | watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") } 75 | 76 | # Turnip features and steps 77 | watch(%r{^spec/acceptance/(.+)\.feature$}) 78 | watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m| 79 | Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' 80 | end 81 | end 82 | -------------------------------------------------------------------------------- /lib/tasks/cucumber.rake: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # IMPORTANT: This file is generated by cucumber-rails - edit at your own peril. 4 | # It is recommended to regenerate this file in the future when you upgrade to a 5 | # newer version of cucumber-rails. Consider adding your own code to a new file 6 | # instead of editing this one. Cucumber will automatically load all features/**/*.rb 7 | # files. 8 | 9 | unless ARGV.any? { |a| a =~ /^gems/ } # Don't load anything when running the gems:* tasks 10 | 11 | vendored_cucumber_bin = Dir["#{Rails.root}/vendor/{gems,plugins}/cucumber*/bin/cucumber"].first 12 | unless vendored_cucumber_bin.nil? 13 | $LOAD_PATH.unshift(File.dirname(vendored_cucumber_bin) + '/../lib') 14 | end 15 | 16 | begin 17 | require 'cucumber/rake/task' 18 | 19 | namespace :cucumber do 20 | Cucumber::Rake::Task.new({ ok: 'test:prepare' }, 'Run features that should pass') do |t| 21 | t.binary = vendored_cucumber_bin # If nil, the gem's binary is used. 22 | t.fork = true # You may get faster startup if you set this to false 23 | t.profile = 'default' 24 | end 25 | 26 | Cucumber::Rake::Task.new({ wip: 'test:prepare' }, 'Run features that are being worked on') do |t| 27 | t.binary = vendored_cucumber_bin 28 | t.fork = true # You may get faster startup if you set this to false 29 | t.profile = 'wip' 30 | end 31 | 32 | Cucumber::Rake::Task.new({ rerun: 'test:prepare' }, 'Record failing features and run only them if any exist') do |t| 33 | t.binary = vendored_cucumber_bin 34 | t.fork = true # You may get faster startup if you set this to false 35 | t.profile = 'rerun' 36 | end 37 | 38 | desc 'Run all features' 39 | task all: %i[ok wip] 40 | 41 | task :statsetup do 42 | require 'rails/code_statistics' 43 | if File.exist?('features') 44 | ::STATS_DIRECTORIES << %w[Cucumber\ features features] 45 | end 46 | if File.exist?('features') 47 | ::CodeStatistics::TEST_TYPES << 'Cucumber features' 48 | end 49 | end 50 | 51 | task :annotations_setup do 52 | Rails.application.configure do 53 | if config.respond_to?(:annotations) 54 | config.annotations.directories << 'features' 55 | config.annotations.register_extensions('feature') { |tag| /#\s*(#{tag}):?\s*(.*)$/ } 56 | end 57 | end 58 | end 59 | end 60 | desc 'Alias for cucumber:ok' 61 | task cucumber: 'cucumber:ok' 62 | 63 | task default: :cucumber 64 | 65 | task features: :cucumber do 66 | warn "*** The 'features' task is deprecated. See rake -T cucumber ***" 67 | end 68 | 69 | # In case we don't have the generic Rails test:prepare hook, append a no-op task that we can depend upon. 70 | task 'test:prepare' do 71 | end 72 | 73 | task stats: 'cucumber:statsetup' 74 | 75 | task notes: 'cucumber:annotations_setup' 76 | rescue LoadError 77 | desc 'cucumber rake task not available (cucumber not installed)' 78 | task :cucumber do 79 | abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin' 80 | end 81 | end 82 | 83 | end 84 | -------------------------------------------------------------------------------- /db/schema.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # This file is auto-generated from the current state of the database. Instead 4 | # of editing this file, please use the migrations feature of Active Record to 5 | # incrementally modify your database, and then regenerate this schema definition. 6 | # 7 | # Note that this schema.rb definition is the authoritative source for your 8 | # database schema. If you need to create the application database on another 9 | # system, you should be using db:schema:load, not running all the migrations 10 | # from scratch. The latter is a flawed and unsustainable approach (the more migrations 11 | # you'll amass, the slower it'll run and the greater likelihood for issues). 12 | # 13 | # It's strongly recommended that you check this file into your version control system. 14 | 15 | ActiveRecord::Schema.define(version: 20_191_118_172_624) do 16 | # These are extensions that must be enabled in order to support this database 17 | enable_extension 'plpgsql' 18 | 19 | create_table 'comments', force: :cascade do |t| 20 | t.text 'content' 21 | t.bigint 'user_id' 22 | t.bigint 'post_id' 23 | t.datetime 'created_at', null: false 24 | t.datetime 'updated_at', null: false 25 | t.index ['post_id'], name: 'index_comments_on_post_id' 26 | t.index ['user_id'], name: 'index_comments_on_user_id' 27 | end 28 | 29 | create_table 'friendships', force: :cascade do |t| 30 | t.bigint 'user_id' 31 | t.bigint 'friend_id' 32 | t.boolean 'confirmed', default: false 33 | t.datetime 'created_at', null: false 34 | t.datetime 'updated_at', null: false 35 | t.index ['friend_id'], name: 'index_friendships_on_friend_id' 36 | t.index %w[user_id friend_id], name: 'index_friendships_on_user_id_and_friend_id' 37 | t.index ['user_id'], name: 'index_friendships_on_user_id' 38 | end 39 | 40 | create_table 'likes', force: :cascade do |t| 41 | t.string 'likeable_type' 42 | t.bigint 'likeable_id' 43 | t.bigint 'user_id' 44 | t.datetime 'created_at', null: false 45 | t.datetime 'updated_at', null: false 46 | t.index %w[likeable_type likeable_id], name: 'index_likes_on_likeable_type_and_likeable_id' 47 | t.index ['user_id'], name: 'index_likes_on_user_id' 48 | end 49 | 50 | create_table 'posts', force: :cascade do |t| 51 | t.text 'content', null: false 52 | t.bigint 'user_id' 53 | t.datetime 'created_at', null: false 54 | t.datetime 'updated_at', null: false 55 | t.index ['user_id'], name: 'index_posts_on_user_id' 56 | end 57 | 58 | create_table 'users', force: :cascade do |t| 59 | t.string 'email', default: '', null: false 60 | t.string 'encrypted_password', default: '', null: false 61 | t.string 'firstname' 62 | t.string 'lastname' 63 | t.string 'sex' 64 | t.date 'dob' 65 | t.string 'image_link', null: false 66 | t.string 'reset_password_token' 67 | t.datetime 'reset_password_sent_at' 68 | t.datetime 'remember_created_at' 69 | t.datetime 'created_at', null: false 70 | t.datetime 'updated_at', null: false 71 | t.string 'provider' 72 | t.string 'uid' 73 | t.index ['email'], name: 'index_users_on_email', unique: true 74 | t.index ['reset_password_token'], name: 'index_users_on_reset_password_token', unique: true 75 | end 76 | 77 | add_foreign_key 'comments', 'posts' 78 | add_foreign_key 'comments', 'users' 79 | end 80 | -------------------------------------------------------------------------------- /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 'shoulda/matchers' 6 | 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 | if Rails.env.production? 13 | abort('The Rails environment is running in production mode!') 14 | end 15 | require 'rspec/rails' 16 | # Add additional requires below this line. Rails is not loaded until this point! 17 | 18 | # Requires supporting ruby files with custom matchers and macros, etc, in 19 | # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are 20 | # run as spec files by default. This means that files in spec/support that end 21 | # in _spec.rb will both be required and run as specs, causing the specs to be 22 | # run twice. It is recommended that you do not name files matching this glob to 23 | # end with _spec.rb. You can configure this pattern with the --pattern 24 | # option on the command line or in ~/.rspec, .rspec or `.rspec-local`. 25 | # 26 | # The following line is provided for convenience purposes. It has the downside 27 | # of increasing the boot-up time by auto-requiring all files in the support 28 | # directory. Alternatively, in the individual `*_spec.rb` files, manually 29 | # require only the support files necessary. 30 | # 31 | # Dir[Rails.root.join('spec', 'support', '**', '*.rb')].each { |f| require f } 32 | 33 | # Checks for pending migrations and applies them before tests are run. 34 | # If you are not using ActiveRecord, you can remove these lines. 35 | begin 36 | ActiveRecord::Migration.maintain_test_schema! 37 | rescue ActiveRecord::PendingMigrationError => e 38 | puts e.to_s.strip 39 | exit 1 40 | end 41 | RSpec.configure do |config| 42 | # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures 43 | config.fixture_path = "#{::Rails.root}/spec/fixtures" 44 | 45 | # If you're not using ActiveRecord, or you'd prefer not to run each of your 46 | # examples within a transaction, remove the following line or assign false 47 | # instead of true. 48 | config.use_transactional_fixtures = true 49 | 50 | # RSpec Rails can automatically mix in different behaviours to your tests 51 | # based on their file location, for example enabling you to call `get` and 52 | # `post` in specs under `spec/controllers`. 53 | # 54 | # You can disable this behaviour by removing the line below, and instead 55 | # explicitly tag your specs with their type, e.g.: 56 | # 57 | # RSpec.describe UsersController, :type => :controller do 58 | # # ... 59 | # end 60 | # 61 | # The different available types are documented in the features, such as in 62 | # https://relishapp.com/rspec/rspec-rails/docs 63 | config.infer_spec_type_from_file_location! 64 | 65 | # Filter lines from Rails gems in backtraces. 66 | config.filter_rails_from_backtrace! 67 | # arbitrary gems may also be filtered via: 68 | # config.filter_gems_from_backtrace("gem name") 69 | end 70 | 71 | Shoulda::Matchers.configure do |config| 72 | config.integrate do |with| 73 | with.test_framework :rspec 74 | with.library :rails 75 | end 76 | end 77 | 78 | RSpec.configure do |config| 79 | config.include(Shoulda::Callback::Matchers::ActiveModel) 80 | end 81 | -------------------------------------------------------------------------------- /app/helpers/users_helper.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module UsersHelper 4 | def show_banner_call_to_action_for(user, btn1 = 'btn-timeline-friend', btn2 = 'btn-timeline-friend') 5 | return update_info_btn if current_user == user 6 | 7 | return pending_friendship_btn(user, btn2) if current_user 8 | .pending_friend_request_to?(user) 9 | 10 | return accept_friend_request_btns(user, btn1, btn2) if current_user 11 | .pending_friend_request_from?(user) 12 | 13 | return unfriend_btn(user, btn2) if current_user.friends_with?(user) 14 | 15 | friendship_btn(user, btn1) 16 | end 17 | 18 | def update_info_btn 19 | link_to 'Update Info', '#', class: 'btn btn-timeline-friend', title: 'Update Info' 20 | end 21 | 22 | def friendship_btn(user, btn1) 23 | link_to 'Add Friend', friendships_path(other_user: user), 24 | method: :post, 25 | class: "btn #{btn1}", 26 | title: 'Send friend Request' 27 | end 28 | 29 | def pending_friendship_btn(user, btn2) 30 | link_to 'Friend Request sent', friendship_path(user), 31 | method: :delete, 32 | data: { confirm: 'Are you sure you want to remove this request?' }, 33 | class: "btn #{btn2}", 34 | title: 'Delete friend request' 35 | end 36 | 37 | def accept_friend_request_btns(user, btn1, btn2) 38 | "#{confirm_friendship_btn(user, btn1)} 39 | #{delete_friendship_btn(user, btn2)}".html_safe 40 | end 41 | 42 | def confirm_friendship_btn(user, btn1) 43 | link_to 'Confirm Friend', friendship_path(user), 44 | method: :patch, 45 | class: "btn #{btn1}", 46 | title: 'Confirm friend request' 47 | end 48 | 49 | def delete_friendship_btn(user, btn2) 50 | link_to 'Remove Request', friendship_path(user), 51 | method: :delete, 52 | data: { confirm: 'Are you sure you want to remove this request?' }, 53 | class: "btn #{btn2}", 54 | title: 'Delete friend request' 55 | end 56 | 57 | def unfriend_btn(user, btn2) 58 | link_to 'Friends', friendship_path(user), 59 | method: :delete, 60 | data: { confirm: 'You are about to unfriend this friend?' }, 61 | class: "btn #{btn2}", 62 | title: 'Click to Unfriend' 63 | end 64 | 65 | def count_friends_for(user) 66 | if friends?(user) 67 | return Friendship 68 | .confirmed_friends_for(user).size 69 | end 70 | 71 | 'no friends yet' 72 | end 73 | 74 | def friends?(user) 75 | Friendship 76 | .confirmed_friends_for(user).any? 77 | end 78 | 79 | def friends_for(user) 80 | Friendship 81 | .confirmed.where(user: user) 82 | .limit(5).map(&:friend) 83 | 84 | end 85 | 86 | def mutual_friends_with?(user) 87 | Friendship 88 | .mutual_friends_between(current_user, user) 89 | .any? && current_user != user 90 | end 91 | 92 | def mutual_friends_with(user) 93 | Friendship 94 | .find_by_sql(["SELECT friendships.* 95 | FROM friendships 96 | WHERE friendships.user_id = ? 97 | AND friendships.friend_id 98 | IN ( SELECT friendships.friend_id 99 | FROM friendships 100 | WHERE friendships.user_id = ? 101 | AND confirmed = ? 102 | ) LIMIT ?;", user.id, other_user.id, true, 5]).map(&:friend) 103 | end 104 | end 105 | -------------------------------------------------------------------------------- /features/support/env.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # IMPORTANT: This file is generated by cucumber-rails - edit at your own peril. 4 | # It is recommended to regenerate this file in the future when you upgrade to a 5 | # newer version of cucumber-rails. Consider adding your own code to a new file 6 | # instead of editing this one. Cucumber will automatically load all features/**/*.rb 7 | # files. 8 | 9 | require 'cucumber/rails' 10 | 11 | # frozen_string_literal: true 12 | 13 | # Capybara defaults to CSS3 selectors rather than XPath. 14 | # If you'd prefer to use XPath, just uncomment this line and adjust any 15 | # selectors in your step definitions to use the XPath syntax. 16 | # Capybara.default_selector = :xpath 17 | 18 | # By default, any exception happening in your Rails application will bubble up 19 | # to Cucumber so that your scenario will fail. This is a different from how 20 | # your application behaves in the production environment, where an error page will 21 | # be rendered instead. 22 | # 23 | # Sometimes we want to override this default behaviour and allow Rails to rescue 24 | # exceptions and display an error page (just like when the app is running in production). 25 | # Typical scenarios where you want to do this is when you test your error pages. 26 | # There are two ways to allow Rails to rescue exceptions: 27 | # 28 | # 1) Tag your scenario (or feature) with @allow-rescue 29 | # 30 | # 2) Set the value below to true. Beware that doing this globally is not 31 | # recommended as it will mask a lot of errors for you! 32 | # 33 | ActionController::Base.allow_rescue = false 34 | 35 | # Remove/comment out the lines below if your app doesn't have a database. 36 | # For some databases (like MongoDB and CouchDB) you may need to use :truncation instead. 37 | begin 38 | DatabaseCleaner.strategy = :transaction 39 | rescue NameError 40 | raise 'You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it.' 41 | end 42 | 43 | # You may also want to configure DatabaseCleaner to use different strategies for certain features and scenarios. 44 | # See the DatabaseCleaner documentation for details. Example: 45 | # 46 | # Before('@no-txn,@selenium,@culerity,@celerity,@javascript') do 47 | # # { except: [:widgets] } may not do what you expect here 48 | # # as Cucumber::Rails::Database.javascript_strategy overrides 49 | # # this setting. 50 | # DatabaseCleaner.strategy = :truncation 51 | # end 52 | # 53 | # Before('not @no-txn', 'not @selenium', 'not @culerity', 'not @celerity', 'not @javascript') do 54 | # DatabaseCleaner.strategy = :transaction 55 | # end 56 | # 57 | 58 | # Possible values are :truncation and :transaction 59 | # The :transaction strategy is faster, but might give you threading problems. 60 | # See https://github.com/cucumber/cucumber-rails/blob/master/features/choose_javascript_database_strategy.feature 61 | Cucumber::Rails::Database.javascript_strategy = :truncation 62 | 63 | Before('@omniauth_test') do 64 | OmniAuth.config.test_mode = true 65 | 66 | OmniAuth.config.add_mock(:facebook, 67 | uid: '123456789', 68 | info: { email: 'test@xxxx.com', 69 | first_name: 'omniauthfirstname', 70 | last_name: 'omniauthlastname', 71 | name: 'omniauthfirstname omniauthlastname', 72 | image: 'http://graph.facebook.com/123456789/picture?type=square' }) 73 | end 74 | 75 | After('@omniauth_test') do 76 | OmniAuth.config.test_mode = false 77 | end 78 | -------------------------------------------------------------------------------- /app/assets/stylesheets/posts.scss: -------------------------------------------------------------------------------- 1 | // Place all the styles related to the posts controller here. 2 | // They will automatically be included in application.css. 3 | // You can use Sass (SCSS) here: http://sass-lang.com/ 4 | 5 | .card { 6 | color: #1d2129; 7 | .card-header, .card-footer{ background-color: #f5f6f7; font-size: 12px; font-weight: bold; } 8 | .card-footer{font-size: 12px; 9 | a { 10 | color: #1d2129; 11 | } 12 | .social-btn{background-color: #f5f6f7; color: #1d2129; 13 | &:hover{ background-color: #dadde1;} 14 | i {letter-spacing: 2px; font-weight: bold;} 15 | } 16 | 17 | .unlike-btn{background-color: $default-button-bg; color: #fff; 18 | &:hover{background-color: $default-button-hover-bg; color: #fff; } 19 | i {letter-spacing: 2px; font-weight: bold;} 20 | } 21 | } 22 | textarea { outline: none; resize: none; 23 | &:focus { 24 | border-outline: none; 25 | } 26 | } 27 | .post-like {img {border-radius: 50%; } } 28 | } 29 | 30 | .gravatar-44 { img{width: 44px; height: 44px; border-radius: 50%;} } 31 | .post-author { width: 75%; height: 52px; font-weight: bold; font-size: 1.1em; 32 | a { color: $default-link-color} 33 | p {font-size: 12px; font-weight: normal;} 34 | } 35 | .post-body {text-align: justify; 36 | font-size: 14px; 37 | font-weight: normal; 38 | line-height: 1.38; 39 | color: #1d2129; 40 | } 41 | .post-actions { width: 44px; height: 44px; 42 | .toggle-btn { 43 | font-weight: normal; font-size: 1.99em; line-height: 0px; padding: 0; height: 24px; display: inline-block; 44 | } 45 | &:hover {cursor: pointer; color: #dadde1; } 46 | .dropdown-item { font-size: 12px; color: #1d2129; } 47 | .dropdown-menu {width: 40%;} 48 | } 49 | 50 | .comments {} 51 | .gravatar-30 { img{ width: 30px; height: 30px; border-radius: 50%;} } 52 | .comment-author { font-weight: bold; font-size: 1em; 53 | a { color: $default-link-color;} 54 | } 55 | .comment-body { 56 | background-color: #f2f3f5; 57 | border-radius: 18px; 58 | color: #1c1e21; 59 | line-height: 16px; 60 | height: 43px; 61 | width: 89%; 62 | padding: 12px; 63 | word-wrap: break-word; 64 | font-size: 13px; 65 | } 66 | .comment-actions { font-size: 12px; 67 | a { color: $default-link-color; } 68 | .unlike-link {font-weight: bold;} 69 | } 70 | 71 | .comment-editor { 72 | textarea { font-size: 12px; width: 100%; height: 100%; outline: none; resize: none; 73 | background-color: #f2f3f5; color: #1d2129; border-radius: 18px; border: solid 1px #ccd0d5;; 74 | } 75 | .btn-comment { font-size: 11px; background-color: $default-button-bg; color: #fff; 76 | &:hover { background-color: $default-button-hover-bg; color: #fff; } 77 | } 78 | } 79 | 80 | .shortcut-left{ 81 | position: fixed; 82 | 83 | .user-navlink { 84 | .gravatar-20 { img{ width: 20px; height: 20px; border-radius: 50%; } } 85 | a { font-size: 12px; text-decoration: none; font-weight: bold; } 86 | &:hover { background-color: #f2f3f5; cursor: pointer;} 87 | } 88 | .newsfeed-link { 89 | img{ width: 20px; height: 20px; } 90 | a { font-size: 14px; text-decoration: none; font-weight: bold; color: #1d2129; } 91 | &:hover { background-color: #f2f3f5; cursor: pointer;} 92 | } 93 | } 94 | 95 | .shortcut-right{ 96 | position: fixed; 97 | width: 20%; 98 | font-size: 12px; 99 | h7 { font-weight: bold; color: #1d2129; font-size: 13px; } 100 | footer{ 101 | font-size: 12px; 102 | .copyright {color: #1d2129; font-weight: bold; } 103 | ul{ 104 | list-style: none; 105 | li { 106 | display:inline-block; 107 | } 108 | } 109 | } 110 | .lang {font-size: 11px; } 111 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

Nzuko - A social networking platform cloned from facebook

2 |

3 | Version 4 | 5 | Documentation 6 | 7 | 8 | Maintenance 9 | 10 | 11 | License: MIT 12 | 13 | 14 | Twitter: vokeugo 15 | 16 |

17 | 18 |
19 | 20 |

21 | This project is a minimal implementation of a social networking app that clones the core features of facebook. The word Nzuko is a local name meaning gathering. Visit the Live Url . 22 | 23 | It explores functionalities like: 24 | 25 | - Create new account 26 | - Writing posts and comments (text only) 27 | - Liking posts and comments 28 | - Sending / accepting / canceling friend requests 29 | - Notifications for new friend request. 30 | - User authentication using `Devise` and OAuth (omniauth-facebook) 31 | - User authorization for posts and comments 32 |

33 | 34 | ![](https://github.com/johnsonsirv/facebook-clone/blob/master/docs/profile-page-1.PNG) 35 | 36 | ![](https://github.com/johnsonsirv/facebook-clone/blob/master/docs/fb-timeline.PNG) 37 | 38 |

39 | 40 | ERD 41 | 42 |

43 | 44 | ### Future implementations: 45 | 46 | - Profile management is minimal but will be extended 47 | - Real-time news feed 48 | - Real-time notifications - from new posts, friend request and ads 49 | - Instant Messaging 50 | - Sharing and Tagging of posts 51 | - Support for multimedia content - videos, images and more 52 | - Additional social login - google, instagram 53 | 54 | ### Built with: 55 | 56 | - Ruby 2.4.0 57 | - Rails 5.2.3 58 | - PostgreSQL 59 | - Cucumber & Capybara (Integration tests) 60 | - RSpec (Unit test) 61 | - Devise / Omniauth-facebook (authentication) 62 | - Bootstrap (UI) 63 | - Guard / Figaro 64 | - FactoryBot (FactoryGirl) / Faker 65 | 66 | ### Installation 67 | 68 | ##### Clone this repository from your terminal 69 | 70 | > `git clone https://github.com/johnsonsirv/facebook-clone.git` 71 | 72 | ###### Database setup 73 | 74 | in your terminal run 75 | 76 | > `rake db:setup` 77 | > 78 | > `rake db:migrate db:test:prepare` 79 | 80 | ###### Run test suite 81 | 82 | ###### run integration level tests (user stories located in `features/`) 83 | 84 | in your terminal run 85 | 86 | > `cucumber features` 87 | 88 | ###### run unit level tests (specs location `spec/`) 89 | 90 | in your terminal run 91 | 92 | > `rspec spec` 93 | 94 | ### Usage 95 | 96 | on your terminal run 97 | 98 | > `rails server` 99 | 100 | Visit `localhost://3000` 101 | 102 | ### Contributor(s) 103 | 104 | [Victor Okeugo](https://angel.co/u/victorokeugo/) 105 | 106 | - Github: [@johnsonsirv](https://github.com/johnsonsirv) 107 | - Twitter: [@vokeugo](https://twitter.com/@vokeugo/) 108 | - Email: [okeugo.victor.c@gmail.com]() 109 | 110 | ### Contributing 111 | 112 | 1. Fork it (https://github.com/johnsonsirv/facebook-clone/fork) 113 | 2. Create your feature branch (git checkout -b feature/[choose-a-name]) 114 | 3. Commit your changes (git commit -m 'What this commit will fix/add') 115 | 4. Push to the branch (git push origin feature/[chosen name]) 116 | 5. Create a new Pull Request 117 | > You can also create [issues](https://github.com/johnsonsirv/facebook-clone/issues) 118 | -------------------------------------------------------------------------------- /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 = "fbreplica_#{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 | -------------------------------------------------------------------------------- /.rubocop_todo.yml: -------------------------------------------------------------------------------- 1 | # This configuration was generated by 2 | # `rubocop --auto-gen-config` 3 | # on 2019-11-20 15:42:57 +0000 using RuboCop version 0.76.0. 4 | # The point is for the user to remove these configuration records 5 | # one by one as the offenses are removed from the code base. 6 | # Note that changes in the inspected code, or installation of new 7 | # versions of RuboCop, may require this file to be generated again. 8 | 9 | # Offense count: 4 10 | # Cop supports --auto-correct. 11 | # Configuration parameters: TreatCommentsAsGroupSeparators, Include. 12 | # Include: **/*.gemfile, **/Gemfile, **/gems.rb 13 | Bundler/OrderedGems: 14 | Exclude: 15 | - 'Gemfile' 16 | 17 | # Offense count: 8 18 | # Cop supports --auto-correct. 19 | # Configuration parameters: EnforcedStyle, IndentationWidth. 20 | # SupportedStyles: with_first_argument, with_fixed_indentation 21 | Layout/AlignArguments: 22 | Exclude: 23 | - 'app/helpers/comments_helper.rb' 24 | - 'app/helpers/posts_helper.rb' 25 | - 'app/helpers/users_helper.rb' 26 | 27 | # Offense count: 1 28 | # Cop supports --auto-correct. 29 | Layout/EmptyLineAfterGuardClause: 30 | Exclude: 31 | - 'app/controllers/likes_controller.rb' 32 | 33 | # Offense count: 5 34 | # Cop supports --auto-correct. 35 | # Configuration parameters: EnforcedStyle. 36 | # SupportedStyles: normal, indented_internal_methods 37 | Layout/IndentationConsistency: 38 | Exclude: 39 | - 'app/controllers/likes_controller.rb' 40 | - 'app/controllers/posts_controller.rb' 41 | 42 | # Offense count: 12 43 | # Cop supports --auto-correct. 44 | # Configuration parameters: Width, IgnoredPatterns. 45 | Layout/IndentationWidth: 46 | Exclude: 47 | - 'app/controllers/likes_controller.rb' 48 | 49 | # Offense count: 1 50 | # Cop supports --auto-correct. 51 | # Configuration parameters: AllowDoxygenCommentStyle. 52 | Layout/LeadingCommentSpace: 53 | Exclude: 54 | - 'config/environments/development.rb' 55 | 56 | # Offense count: 5 57 | # Cop supports --auto-correct. 58 | # Configuration parameters: EnforcedStyle, IndentationWidth. 59 | # SupportedStyles: aligned, indented, indented_relative_to_receiver 60 | Layout/MultilineMethodCallIndentation: 61 | Exclude: 62 | - 'app/models/post.rb' 63 | 64 | # Offense count: 28 65 | # Cop supports --auto-correct. 66 | # Configuration parameters: IndentationWidth. 67 | Layout/Tab: 68 | Exclude: 69 | - 'app/controllers/likes_controller.rb' 70 | 71 | # Offense count: 21 72 | # Cop supports --auto-correct. 73 | # Configuration parameters: AllowInHeredoc. 74 | Layout/TrailingWhitespace: 75 | Exclude: 76 | - 'app/controllers/likes_controller.rb' 77 | - 'app/helpers/posts_helper.rb' 78 | - 'app/helpers/users_helper.rb' 79 | - 'config/environments/development.rb' 80 | 81 | # Offense count: 1 82 | # Configuration parameters: AllowSafeAssignment. 83 | Lint/AssignmentInCondition: 84 | Exclude: 85 | - 'app/models/user.rb' 86 | 87 | # Offense count: 1 88 | Lint/UselessAssignment: 89 | Exclude: 90 | - 'features/step_definitions/user_signup_steps.rb' 91 | 92 | # Offense count: 1 93 | Metrics/AbcSize: 94 | Max: 17 95 | 96 | # Offense count: 4 97 | # Configuration parameters: CountComments, ExcludedMethods. 98 | # ExcludedMethods: refine 99 | Metrics/BlockLength: 100 | Max: 56 101 | 102 | # Offense count: 1 103 | # Configuration parameters: CountComments, ExcludedMethods. 104 | Metrics/MethodLength: 105 | Max: 15 106 | 107 | # Offense count: 1 108 | Naming/AccessorMethodName: 109 | Exclude: 110 | - 'app/controllers/users_controller.rb' 111 | 112 | # Offense count: 28 113 | Style/Documentation: 114 | Enabled: false 115 | 116 | # Offense count: 4 117 | # Cop supports --auto-correct. 118 | Style/IfUnlessModifier: 119 | Exclude: 120 | - 'lib/tasks/cucumber.rake' 121 | - 'spec/rails_helper.rb' 122 | 123 | # Offense count: 2 124 | Style/MixinUsage: 125 | Exclude: 126 | - 'bin/setup' 127 | - 'bin/update' 128 | 129 | # Offense count: 3 130 | # Cop supports --auto-correct. 131 | Style/MultilineIfModifier: 132 | Exclude: 133 | - 'app/helpers/comments_helper.rb' 134 | - 'app/helpers/posts_helper.rb' 135 | 136 | # Offense count: 101 137 | # Cop supports --auto-correct. 138 | # Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. 139 | # URISchemes: http, https 140 | Metrics/LineLength: 141 | Max: 158 142 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # This file was generated by the `rails generate rspec:install` command. Conventionally, all 4 | # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. 5 | # The generated `.rspec` file contains `--require spec_helper` which will cause 6 | # this file to always be loaded, without a need to explicitly require it in any 7 | # files. 8 | # 9 | # Given that it is always loaded, you are encouraged to keep this file as 10 | # light-weight as possible. Requiring heavyweight dependencies from this file 11 | # will add to the boot time of your test suite on EVERY test run, even for an 12 | # individual file that may not need all of that loaded. Instead, consider making 13 | # a separate helper file that requires the additional dependencies and performs 14 | # the additional setup, and require it from the spec files that actually need 15 | # it. 16 | # 17 | # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration 18 | RSpec.configure do |config| 19 | # rspec-expectations config goes here. You can use an alternate 20 | # assertion/expectation library such as wrong or the stdlib/minitest 21 | # assertions if you prefer. 22 | config.expect_with :rspec do |expectations| 23 | # This option will default to `true` in RSpec 4. It makes the `description` 24 | # and `failure_message` of custom matchers include text for helper methods 25 | # defined using `chain`, e.g.: 26 | # be_bigger_than(2).and_smaller_than(4).description 27 | # # => "be bigger than 2 and smaller than 4" 28 | # ...rather than: 29 | # # => "be bigger than 2" 30 | expectations.include_chain_clauses_in_custom_matcher_descriptions = true 31 | end 32 | 33 | # rspec-mocks config goes here. You can use an alternate test double 34 | # library (such as bogus or mocha) by changing the `mock_with` option here. 35 | config.mock_with :rspec do |mocks| 36 | # Prevents you from mocking or stubbing a method that does not exist on 37 | # a real object. This is generally recommended, and will default to 38 | # `true` in RSpec 4. 39 | mocks.verify_partial_doubles = true 40 | end 41 | 42 | # This option will default to `:apply_to_host_groups` in RSpec 4 (and will 43 | # have no way to turn it off -- the option exists only for backwards 44 | # compatibility in RSpec 3). It causes shared context metadata to be 45 | # inherited by the metadata hash of host groups and examples, rather than 46 | # triggering implicit auto-inclusion in groups with matching metadata. 47 | config.shared_context_metadata_behavior = :apply_to_host_groups 48 | 49 | # The settings below are suggested to provide a good initial experience 50 | # with RSpec, but feel free to customize to your heart's content. 51 | # # This allows you to limit a spec run to individual examples or groups 52 | # # you care about by tagging them with `:focus` metadata. When nothing 53 | # # is tagged with `:focus`, all examples get run. RSpec also provides 54 | # # aliases for `it`, `describe`, and `context` that include `:focus` 55 | # # metadata: `fit`, `fdescribe` and `fcontext`, respectively. 56 | # config.filter_run_when_matching :focus 57 | # 58 | # # Allows RSpec to persist some state between runs in order to support 59 | # # the `--only-failures` and `--next-failure` CLI options. We recommend 60 | # # you configure your source control system to ignore this file. 61 | # config.example_status_persistence_file_path = "spec/examples.txt" 62 | # 63 | # # Limits the available syntax to the non-monkey patched syntax that is 64 | # # recommended. For more details, see: 65 | # # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/ 66 | # # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ 67 | # # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode 68 | # config.disable_monkey_patching! 69 | # 70 | # # Many RSpec users commonly either run the entire suite or an individual 71 | # # file, and it's useful to allow more verbose output when running an 72 | # # individual spec file. 73 | # if config.files_to_run.one? 74 | # # Use the documentation formatter for detailed output, 75 | # # unless a formatter has already been configured 76 | # # (e.g. via a command-line flag). 77 | # config.default_formatter = "doc" 78 | # end 79 | # 80 | # # Print the 10 slowest examples and example groups at the 81 | # # end of the spec run, to help surface which specs are running 82 | # # particularly slow. 83 | # config.profile_examples = 10 84 | # 85 | # # Run specs in random order to surface order dependencies. If you find an 86 | # # order dependency and want to debug it, you can fix the order by providing 87 | # # the seed, which is printed after each run. 88 | # # --seed 1234 89 | # config.order = :random 90 | # 91 | # # Seed global randomization in this process using the `--seed` CLI option. 92 | # # Setting this allows you to use `--seed` to deterministically reproduce 93 | # # test failures related to randomization by passing the same `--seed` value 94 | # # as the one that triggered the failure. 95 | # Kernel.srand config.seed 96 | end 97 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | actioncable (5.2.3) 5 | actionpack (= 5.2.3) 6 | nio4r (~> 2.0) 7 | websocket-driver (>= 0.6.1) 8 | actionmailer (5.2.3) 9 | actionpack (= 5.2.3) 10 | actionview (= 5.2.3) 11 | activejob (= 5.2.3) 12 | mail (~> 2.5, >= 2.5.4) 13 | rails-dom-testing (~> 2.0) 14 | actionpack (5.2.3) 15 | actionview (= 5.2.3) 16 | activesupport (= 5.2.3) 17 | rack (~> 2.0) 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.3) 22 | activesupport (= 5.2.3) 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.3) 28 | activesupport (= 5.2.3) 29 | globalid (>= 0.3.6) 30 | activemodel (5.2.3) 31 | activesupport (= 5.2.3) 32 | activerecord (5.2.3) 33 | activemodel (= 5.2.3) 34 | activesupport (= 5.2.3) 35 | arel (>= 9.0) 36 | activestorage (5.2.3) 37 | actionpack (= 5.2.3) 38 | activerecord (= 5.2.3) 39 | marcel (~> 0.3.1) 40 | activesupport (5.2.3) 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.0) 49 | execjs 50 | backports (3.15.0) 51 | bcrypt (3.1.13) 52 | bindex (0.8.1) 53 | bootsnap (1.4.5) 54 | msgpack (~> 1.0) 55 | bootstrap (4.3.1) 56 | autoprefixer-rails (>= 9.1.0) 57 | popper_js (>= 1.14.3, < 2) 58 | sassc-rails (>= 2.0.0) 59 | builder (3.2.3) 60 | bullet (5.9.0) 61 | activesupport (>= 3.0.0) 62 | uniform_notifier (~> 1.11) 63 | byebug (11.0.1) 64 | capybara (3.29.0) 65 | addressable 66 | mini_mime (>= 0.1.3) 67 | nokogiri (~> 1.8) 68 | rack (>= 1.6.0) 69 | rack-test (>= 0.6.3) 70 | regexp_parser (~> 1.5) 71 | xpath (~> 3.2) 72 | childprocess (3.0.0) 73 | coderay (1.1.2) 74 | coffee-rails (4.2.2) 75 | coffee-script (>= 2.2.0) 76 | railties (>= 4.0.0) 77 | coffee-script (2.4.1) 78 | coffee-script-source 79 | execjs 80 | coffee-script-source (1.12.2) 81 | concurrent-ruby (1.1.5) 82 | crass (1.0.5) 83 | cucumber (3.1.2) 84 | builder (>= 2.1.2) 85 | cucumber-core (~> 3.2.0) 86 | cucumber-expressions (~> 6.0.1) 87 | cucumber-wire (~> 0.0.1) 88 | diff-lcs (~> 1.3) 89 | gherkin (~> 5.1.0) 90 | multi_json (>= 1.7.5, < 2.0) 91 | multi_test (>= 0.1.2) 92 | cucumber-core (3.2.1) 93 | backports (>= 3.8.0) 94 | cucumber-tag_expressions (~> 1.1.0) 95 | gherkin (~> 5.0) 96 | cucumber-expressions (6.0.1) 97 | cucumber-rails (1.8.0) 98 | capybara (>= 2.12, < 4) 99 | cucumber (>= 3.0.2, < 4) 100 | mime-types (>= 2.0, < 4) 101 | nokogiri (~> 1.8) 102 | railties (>= 4.2, < 7) 103 | cucumber-tag_expressions (1.1.1) 104 | cucumber-wire (0.0.1) 105 | database_cleaner (1.7.0) 106 | devise (4.7.1) 107 | bcrypt (~> 3.0) 108 | orm_adapter (~> 0.1) 109 | railties (>= 4.1.0) 110 | responders 111 | warden (~> 1.2.3) 112 | diff-lcs (1.3) 113 | erubi (1.9.0) 114 | execjs (2.7.0) 115 | factory_bot (5.1.1) 116 | activesupport (>= 4.2.0) 117 | factory_bot_rails (5.1.1) 118 | factory_bot (~> 5.1.0) 119 | railties (>= 4.2.0) 120 | faker (2.6.0) 121 | i18n (>= 1.6, < 1.8) 122 | faraday (0.17.0) 123 | multipart-post (>= 1.2, < 3) 124 | ffi (1.11.1) 125 | figaro (1.1.1) 126 | thor (~> 0.14) 127 | font-awesome-rails (4.7.0.5) 128 | railties (>= 3.2, < 6.1) 129 | formatador (0.2.5) 130 | gherkin (5.1.0) 131 | globalid (0.4.2) 132 | activesupport (>= 4.2.0) 133 | guard (2.15.1) 134 | formatador (>= 0.2.4) 135 | listen (>= 2.7, < 4.0) 136 | lumberjack (>= 1.0.12, < 2.0) 137 | nenv (~> 0.1) 138 | notiffany (~> 0.0) 139 | pry (>= 0.9.12) 140 | shellany (~> 0.0) 141 | thor (>= 0.18.1) 142 | guard-compat (1.2.1) 143 | guard-cucumber (1.5.4) 144 | cucumber (>= 1.3.0) 145 | guard-compat (~> 1.0) 146 | nenv (~> 0.1) 147 | guard-rspec (4.7.3) 148 | guard (~> 2.1) 149 | guard-compat (~> 1.1) 150 | rspec (>= 2.99.0, < 4.0) 151 | hashie (3.6.0) 152 | hirb (0.7.3) 153 | i18n (1.7.0) 154 | concurrent-ruby (~> 1.0) 155 | jbuilder (2.9.1) 156 | activesupport (>= 4.2.0) 157 | jquery-rails (4.3.5) 158 | rails-dom-testing (>= 1, < 3) 159 | railties (>= 4.2.0) 160 | thor (>= 0.14, < 2.0) 161 | jwt (2.2.1) 162 | libv8 (7.3.492.27.1) 163 | listen (3.1.5) 164 | rb-fsevent (~> 0.9, >= 0.9.4) 165 | rb-inotify (~> 0.9, >= 0.9.7) 166 | ruby_dep (~> 1.2) 167 | loofah (2.3.1) 168 | crass (~> 1.0.2) 169 | nokogiri (>= 1.5.9) 170 | lumberjack (1.0.13) 171 | mail (2.7.1) 172 | mini_mime (>= 0.1.1) 173 | marcel (0.3.3) 174 | mimemagic (~> 0.3.2) 175 | method_source (0.9.2) 176 | mime-types (3.3) 177 | mime-types-data (~> 3.2015) 178 | mime-types-data (3.2019.1009) 179 | mimemagic (0.3.3) 180 | mini_mime (1.0.2) 181 | mini_portile2 (2.4.0) 182 | mini_racer (0.2.6) 183 | libv8 (>= 6.9.411) 184 | minitest (5.12.2) 185 | msgpack (1.3.1) 186 | multi_json (1.14.1) 187 | multi_test (0.1.2) 188 | multi_xml (0.6.0) 189 | multipart-post (2.1.1) 190 | nenv (0.3.0) 191 | nio4r (2.5.2) 192 | nokogiri (1.10.8) 193 | mini_portile2 (~> 2.4.0) 194 | notiffany (0.1.3) 195 | nenv (~> 0.1) 196 | shellany (~> 0.0) 197 | oauth2 (1.4.2) 198 | faraday (>= 0.8, < 2.0) 199 | jwt (>= 1.0, < 3.0) 200 | multi_json (~> 1.3) 201 | multi_xml (~> 0.5) 202 | rack (>= 1.2, < 3) 203 | omniauth (1.9.0) 204 | hashie (>= 3.4.6, < 3.7.0) 205 | rack (>= 1.6.2, < 3) 206 | omniauth-facebook (5.0.0) 207 | omniauth-oauth2 (~> 1.2) 208 | omniauth-oauth2 (1.6.0) 209 | oauth2 (~> 1.1) 210 | omniauth (~> 1.9) 211 | orm_adapter (0.5.0) 212 | pg (1.1.4) 213 | popper_js (1.14.5) 214 | pry (0.12.2) 215 | coderay (~> 1.1.0) 216 | method_source (~> 0.9.0) 217 | public_suffix (4.0.1) 218 | puma (3.12.6) 219 | rack (2.0.8) 220 | rack-test (1.1.0) 221 | rack (>= 1.0, < 3) 222 | rails (5.2.3) 223 | actioncable (= 5.2.3) 224 | actionmailer (= 5.2.3) 225 | actionpack (= 5.2.3) 226 | actionview (= 5.2.3) 227 | activejob (= 5.2.3) 228 | activemodel (= 5.2.3) 229 | activerecord (= 5.2.3) 230 | activestorage (= 5.2.3) 231 | activesupport (= 5.2.3) 232 | bundler (>= 1.3.0) 233 | railties (= 5.2.3) 234 | sprockets-rails (>= 2.0.0) 235 | rails-dom-testing (2.0.3) 236 | activesupport (>= 4.2.0) 237 | nokogiri (>= 1.6) 238 | rails-html-sanitizer (1.3.0) 239 | loofah (~> 2.3) 240 | railties (5.2.3) 241 | actionpack (= 5.2.3) 242 | activesupport (= 5.2.3) 243 | method_source 244 | rake (>= 0.8.7) 245 | thor (>= 0.19.0, < 2.0) 246 | rake (13.0.0) 247 | rb-fsevent (0.10.3) 248 | rb-inotify (0.10.0) 249 | ffi (~> 1.0) 250 | regexp_parser (1.6.0) 251 | responders (3.0.0) 252 | actionpack (>= 5.0) 253 | railties (>= 5.0) 254 | rspec (3.9.0) 255 | rspec-core (~> 3.9.0) 256 | rspec-expectations (~> 3.9.0) 257 | rspec-mocks (~> 3.9.0) 258 | rspec-core (3.9.0) 259 | rspec-support (~> 3.9.0) 260 | rspec-expectations (3.9.0) 261 | diff-lcs (>= 1.2.0, < 2.0) 262 | rspec-support (~> 3.9.0) 263 | rspec-mocks (3.9.0) 264 | diff-lcs (>= 1.2.0, < 2.0) 265 | rspec-support (~> 3.9.0) 266 | rspec-rails (3.9.0) 267 | actionpack (>= 3.0) 268 | activesupport (>= 3.0) 269 | railties (>= 3.0) 270 | rspec-core (~> 3.9.0) 271 | rspec-expectations (~> 3.9.0) 272 | rspec-mocks (~> 3.9.0) 273 | rspec-support (~> 3.9.0) 274 | rspec-support (3.9.0) 275 | ruby_dep (1.5.0) 276 | rubyzip (2.0.0) 277 | sass (3.7.4) 278 | sass-listen (~> 4.0.0) 279 | sass-listen (4.0.0) 280 | rb-fsevent (~> 0.9, >= 0.9.4) 281 | rb-inotify (~> 0.9, >= 0.9.7) 282 | sass-rails (5.1.0) 283 | railties (>= 5.2.0) 284 | sass (~> 3.1) 285 | sprockets (>= 2.8, < 4.0) 286 | sprockets-rails (>= 2.0, < 4.0) 287 | tilt (>= 1.1, < 3) 288 | sassc (2.2.1) 289 | ffi (~> 1.9) 290 | sassc-rails (2.1.2) 291 | railties (>= 4.0.0) 292 | sassc (>= 2.0) 293 | sprockets (> 3.0) 294 | sprockets-rails 295 | tilt 296 | selenium-webdriver (3.142.6) 297 | childprocess (>= 0.5, < 4.0) 298 | rubyzip (>= 1.2.2) 299 | shellany (0.0.1) 300 | shoulda-callback-matchers (1.1.4) 301 | activesupport (>= 3) 302 | shoulda-matchers (4.1.2) 303 | activesupport (>= 4.2.0) 304 | spring (2.1.0) 305 | spring-watcher-listen (2.0.1) 306 | listen (>= 2.7, < 4.0) 307 | spring (>= 1.2, < 3.0) 308 | sprockets (3.7.2) 309 | concurrent-ruby (~> 1.0) 310 | rack (> 1, < 3) 311 | sprockets-rails (3.2.1) 312 | actionpack (>= 4.0) 313 | activesupport (>= 4.0) 314 | sprockets (>= 3.0.0) 315 | thor (0.20.3) 316 | thread_safe (0.3.6) 317 | tilt (2.0.10) 318 | turbolinks (5.2.1) 319 | turbolinks-source (~> 5.2) 320 | turbolinks-source (5.2.0) 321 | tzinfo (1.2.5) 322 | thread_safe (~> 0.1) 323 | uglifier (4.2.0) 324 | execjs (>= 0.3.0, < 3) 325 | uniform_notifier (1.13.0) 326 | warden (1.2.8) 327 | rack (>= 2.0.6) 328 | web-console (3.7.0) 329 | actionview (>= 5.0) 330 | activemodel (>= 5.0) 331 | bindex (>= 0.4.0) 332 | railties (>= 5.0) 333 | webdrivers (4.1.3) 334 | nokogiri (~> 1.6) 335 | rubyzip (>= 1.3.0) 336 | selenium-webdriver (>= 3.0, < 4.0) 337 | websocket-driver (0.7.1) 338 | websocket-extensions (>= 0.1.0) 339 | websocket-extensions (0.1.5) 340 | xpath (3.2.0) 341 | nokogiri (~> 1.8) 342 | 343 | PLATFORMS 344 | ruby 345 | 346 | DEPENDENCIES 347 | bootsnap (>= 1.1.0) 348 | bootstrap (~> 4.3.1) 349 | bullet (~> 5.7, >= 5.7.5) 350 | byebug 351 | capybara (>= 2.15) 352 | coffee-rails (~> 4.2) 353 | cucumber-rails 354 | database_cleaner 355 | devise 356 | factory_bot_rails 357 | faker 358 | figaro 359 | font-awesome-rails 360 | guard 361 | guard-cucumber 362 | guard-rspec 363 | hirb 364 | jbuilder (~> 2.5) 365 | jquery-rails 366 | listen (>= 3.0.5, < 3.2) 367 | mini_racer 368 | omniauth-facebook 369 | pg (>= 0.18, < 2.0) 370 | puma (~> 3.12) 371 | rails (~> 5.2.3) 372 | rspec-rails 373 | sass-rails (~> 5.0) 374 | selenium-webdriver 375 | shoulda-callback-matchers (~> 1.1.1) 376 | shoulda-matchers 377 | spring 378 | spring-watcher-listen (~> 2.0.0) 379 | turbolinks (~> 5) 380 | tzinfo-data 381 | uglifier (>= 1.3.0) 382 | web-console (>= 3.3.0) 383 | webdrivers (~> 4.0) 384 | 385 | RUBY VERSION 386 | ruby 2.4.0p0 387 | 388 | BUNDLED WITH 389 | 1.14.6 390 | -------------------------------------------------------------------------------- /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 = '0acbb63a91a70e1e4feac2fa83379c4279b67e5ee38d8559ad0f0040faf1a1c2c57c6eaa6bb5c85c28800047f6895e0d43c9f3d0c124a4481da1dbab0b9f60c4' 12 | 13 | # ==> Controller configuration 14 | # Configure the parent class to the devise controllers. 15 | # config.parent_controller = 'DeviseController' 16 | 17 | # ==> Mailer Configuration 18 | # Configure the e-mail address which will be shown in Devise::Mailer, 19 | # note that it will be overwritten if you use your own mailer class 20 | # with default "from" parameter. 21 | config.mailer_sender = 'please-change-me-at-config-initializers-devise@example.com' 22 | 23 | # Configure the class responsible to send e-mails. 24 | # config.mailer = 'Devise::Mailer' 25 | 26 | # Configure the parent class responsible to send e-mails. 27 | # config.parent_mailer = 'ActionMailer::Base' 28 | 29 | # ==> ORM configuration 30 | # Load and configure the ORM. Supports :active_record (default) and 31 | # :mongoid (bson_ext recommended) by default. Other ORMs may be 32 | # available as additional gems. 33 | require 'devise/orm/active_record' 34 | 35 | # ==> Configuration for any authentication mechanism 36 | # Configure which keys are used when authenticating a user. The default is 37 | # just :email. You can configure it to use [:username, :subdomain], so for 38 | # authenticating a user, both parameters are required. Remember that those 39 | # parameters are used only when authenticating and not when retrieving from 40 | # session. If you need permissions, you should implement that in a before filter. 41 | # You can also supply a hash where the value is a boolean determining whether 42 | # or not authentication should be aborted when the value is not present. 43 | # config.authentication_keys = [:email] 44 | 45 | # Configure parameters from the request object used for authentication. Each entry 46 | # given should be a request method and it will automatically be passed to the 47 | # find_for_authentication method and considered in your model lookup. For instance, 48 | # if you set :request_keys to [:subdomain], :subdomain will be used on authentication. 49 | # The same considerations mentioned for authentication_keys also apply to request_keys. 50 | # config.request_keys = [] 51 | 52 | # Configure which authentication keys should be case-insensitive. 53 | # These keys will be downcased upon creating or modifying a user and when used 54 | # to authenticate or find a user. Default is :email. 55 | config.case_insensitive_keys = [:email] 56 | 57 | # Configure which authentication keys should have whitespace stripped. 58 | # These keys will have whitespace before and after removed upon creating or 59 | # modifying a user and when used to authenticate or find a user. Default is :email. 60 | config.strip_whitespace_keys = [:email] 61 | 62 | # Tell if authentication through request.params is enabled. True by default. 63 | # It can be set to an array that will enable params authentication only for the 64 | # given strategies, for example, `config.params_authenticatable = [:database]` will 65 | # enable it only for database (email + password) authentication. 66 | # config.params_authenticatable = true 67 | 68 | # Tell if authentication through HTTP Auth is enabled. False by default. 69 | # It can be set to an array that will enable http authentication only for the 70 | # given strategies, for example, `config.http_authenticatable = [:database]` will 71 | # enable it only for database authentication. The supported strategies are: 72 | # :database = Support basic authentication with authentication key + password 73 | # config.http_authenticatable = false 74 | 75 | # If 401 status code should be returned for AJAX requests. True by default. 76 | # config.http_authenticatable_on_xhr = true 77 | 78 | # The realm used in Http Basic Authentication. 'Application' by default. 79 | # config.http_authentication_realm = 'Application' 80 | 81 | # It will change confirmation, password recovery and other workflows 82 | # to behave the same regardless if the e-mail provided was right or wrong. 83 | # Does not affect registerable. 84 | # config.paranoid = true 85 | 86 | # By default Devise will store the user in session. You can skip storage for 87 | # particular strategies by setting this option. 88 | # Notice that if you are skipping storage for all authentication paths, you 89 | # may want to disable generating routes to Devise's sessions controller by 90 | # passing skip: :sessions to `devise_for` in your config/routes.rb 91 | config.skip_session_storage = [:http_auth] 92 | 93 | # By default, Devise cleans up the CSRF token on authentication to 94 | # avoid CSRF token fixation attacks. This means that, when using AJAX 95 | # requests for sign in and sign up, you need to get a new CSRF token 96 | # from the server. You can disable this option at your own risk. 97 | # config.clean_up_csrf_token_on_authentication = true 98 | 99 | # When false, Devise will not attempt to reload routes on eager load. 100 | # This can reduce the time taken to boot the app but if your application 101 | # requires the Devise mappings to be loaded during boot time the application 102 | # won't boot properly. 103 | # config.reload_routes = true 104 | 105 | # ==> Configuration for :database_authenticatable 106 | # For bcrypt, this is the cost for hashing the password and defaults to 11. If 107 | # using other algorithms, it sets how many times you want the password to be hashed. 108 | # 109 | # Limiting the stretches to just one in testing will increase the performance of 110 | # your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use 111 | # a value less than 10 in other environments. Note that, for bcrypt (the default 112 | # algorithm), the cost increases exponentially with the number of stretches (e.g. 113 | # a value of 20 is already extremely slow: approx. 60 seconds for 1 calculation). 114 | config.stretches = Rails.env.test? ? 1 : 11 115 | 116 | # Set up a pepper to generate the hashed password. 117 | # config.pepper = 'e411b71134a512aaa64186569a88c42365633ecfe24ea09662ee0269ca7473c83089412d1e0aa19f554c0f2ce3fb933c66c808a08a1aad68ee16e3b865745ede' 118 | 119 | # Send a notification to the original email when the user's email is changed. 120 | # config.send_email_changed_notification = false 121 | 122 | # Send a notification email when the user's password is changed. 123 | # config.send_password_change_notification = false 124 | 125 | # ==> Configuration for :confirmable 126 | # A period that the user is allowed to access the website even without 127 | # confirming their account. For instance, if set to 2.days, the user will be 128 | # able to access the website for two days without confirming their account, 129 | # access will be blocked just in the third day. 130 | # You can also set it to nil, which will allow the user to access the website 131 | # without confirming their account. 132 | # Default is 0.days, meaning the user cannot access the website without 133 | # confirming their account. 134 | # config.allow_unconfirmed_access_for = 2.days 135 | 136 | # A period that the user is allowed to confirm their account before their 137 | # token becomes invalid. For example, if set to 3.days, the user can confirm 138 | # their account within 3 days after the mail was sent, but on the fourth day 139 | # their account can't be confirmed with the token any more. 140 | # Default is nil, meaning there is no restriction on how long a user can take 141 | # before confirming their account. 142 | # config.confirm_within = 3.days 143 | 144 | # If true, requires any email changes to be confirmed (exactly the same way as 145 | # initial account confirmation) to be applied. Requires additional unconfirmed_email 146 | # db field (see migrations). Until confirmed, new email is stored in 147 | # unconfirmed_email column, and copied to email column on successful confirmation. 148 | config.reconfirmable = true 149 | 150 | # Defines which key will be used when confirming an account 151 | # config.confirmation_keys = [:email] 152 | 153 | # ==> Configuration for :rememberable 154 | # The time the user will be remembered without asking for credentials again. 155 | # config.remember_for = 2.weeks 156 | 157 | # Invalidates all the remember me tokens when the user signs out. 158 | config.expire_all_remember_me_on_sign_out = true 159 | 160 | # If true, extends the user's remember period when remembered via cookie. 161 | # config.extend_remember_period = false 162 | 163 | # Options to be passed to the created cookie. For instance, you can set 164 | # secure: true in order to force SSL only cookies. 165 | # config.rememberable_options = {} 166 | 167 | # ==> Configuration for :validatable 168 | # Range for password length. 169 | config.password_length = 6..128 170 | 171 | # Email regex used to validate email formats. It simply asserts that 172 | # one (and only one) @ exists in the given string. This is mainly 173 | # to give user feedback and not to assert the e-mail validity. 174 | config.email_regexp = /\A[^@\s]+@[^@\s]+\z/ 175 | 176 | # ==> Configuration for :timeoutable 177 | # The time you want to timeout the user session without activity. After this 178 | # time the user will be asked for credentials again. Default is 30 minutes. 179 | # config.timeout_in = 30.minutes 180 | 181 | # ==> Configuration for :lockable 182 | # Defines which strategy will be used to lock an account. 183 | # :failed_attempts = Locks an account after a number of failed attempts to sign in. 184 | # :none = No lock strategy. You should handle locking by yourself. 185 | # config.lock_strategy = :failed_attempts 186 | 187 | # Defines which key will be used when locking and unlocking an account 188 | # config.unlock_keys = [:email] 189 | 190 | # Defines which strategy will be used to unlock an account. 191 | # :email = Sends an unlock link to the user email 192 | # :time = Re-enables login after a certain amount of time (see :unlock_in below) 193 | # :both = Enables both strategies 194 | # :none = No unlock strategy. You should handle unlocking by yourself. 195 | # config.unlock_strategy = :both 196 | 197 | # Number of authentication tries before locking an account if lock_strategy 198 | # is failed attempts. 199 | # config.maximum_attempts = 20 200 | 201 | # Time interval to unlock the account if :time is enabled as unlock_strategy. 202 | # config.unlock_in = 1.hour 203 | 204 | # Warn on the last attempt before the account is locked. 205 | # config.last_attempt_warning = true 206 | 207 | # ==> Configuration for :recoverable 208 | # 209 | # Defines which key will be used when recovering the password for an account 210 | # config.reset_password_keys = [:email] 211 | 212 | # Time interval you can reset your password with a reset password key. 213 | # Don't put a too small interval or your users won't have the time to 214 | # change their passwords. 215 | config.reset_password_within = 6.hours 216 | 217 | # When set to false, does not sign a user in automatically after their password is 218 | # reset. Defaults to true, so a user is signed in automatically after a reset. 219 | # config.sign_in_after_reset_password = true 220 | 221 | # ==> Configuration for :encryptable 222 | # Allow you to use another hashing or encryption algorithm besides bcrypt (default). 223 | # You can use :sha1, :sha512 or algorithms from others authentication tools as 224 | # :clearance_sha1, :authlogic_sha512 (then you should set stretches above to 20 225 | # for default behavior) and :restful_authentication_sha1 (then you should set 226 | # stretches to 10, and copy REST_AUTH_SITE_KEY to pepper). 227 | # 228 | # Require the `devise-encryptable` gem when using anything other than bcrypt 229 | # config.encryptor = :sha512 230 | 231 | # ==> Scopes configuration 232 | # Turn scoped views on. Before rendering "sessions/new", it will first check for 233 | # "users/sessions/new". It's turned off by default because it's slower if you 234 | # are using only default views. 235 | # config.scoped_views = false 236 | 237 | # Configure the default scope given to Warden. By default it's the first 238 | # devise role declared in your routes (usually :user). 239 | # config.default_scope = :user 240 | 241 | # Set this configuration to false if you want /users/sign_out to sign out 242 | # only the current scope. By default, Devise signs out all scopes. 243 | # config.sign_out_all_scopes = true 244 | 245 | # ==> Navigation configuration 246 | # Lists the formats that should be treated as navigational. Formats like 247 | # :html, should redirect to the sign in page when the user does not have 248 | # access, but formats like :xml or :json, should return 401. 249 | # 250 | # If you have any extra navigational formats, like :iphone or :mobile, you 251 | # should add them to the navigational formats lists. 252 | # 253 | # The "*/*" below is required to match Internet Explorer requests. 254 | # config.navigational_formats = ['*/*', :html] 255 | 256 | # The default HTTP method used to sign out a resource. Default is :delete. 257 | config.sign_out_via = :delete 258 | 259 | # ==> OmniAuth 260 | # Add a new OmniAuth provider. Check the wiki for more information on setting 261 | # up on your models and hooks. 262 | # config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo' 263 | config.omniauth :facebook, Figaro.env.facebook_app_id, Figaro.env.facebook_app_secret 264 | # ==> Warden configuration 265 | # If you want to use other strategies, that are not supported by Devise, or 266 | # change the failure app, you can configure them inside the config.warden block. 267 | # 268 | # config.warden do |manager| 269 | # manager.intercept_401 = false 270 | # manager.default_strategies(scope: :user).unshift :some_external_strategy 271 | # end 272 | 273 | # ==> Mountable engine configurations 274 | # When using Devise inside an engine, let's call it `MyEngine`, and this engine 275 | # is mountable, there are some extra configurations to be taken into account. 276 | # The following options are available, assuming the engine is mounted as: 277 | # 278 | # mount MyEngine, at: '/my_engine' 279 | # 280 | # The router that invoked `devise_for`, in the example above, would be: 281 | # config.router_name = :my_engine 282 | # 283 | # When using OmniAuth, Devise cannot automatically set OmniAuth path, 284 | # so you need to do it manually. For the users scope, it would be: 285 | # config.omniauth_path_prefix = '/my_engine/users/auth' 286 | 287 | # ==> Turbolinks configuration 288 | # If your app is using Turbolinks, Turbolinks::Controller needs to be included to make redirection work correctly: 289 | # 290 | # ActiveSupport.on_load(:devise_failure_app) do 291 | # include Turbolinks::Controller 292 | # end 293 | 294 | # ==> Configuration for :registerable 295 | 296 | # When set to false, does not sign a user in automatically after their password is 297 | # changed. Defaults to true, so a user is signed in automatically after changing a password. 298 | # config.sign_in_after_change_password = true 299 | end 300 | --------------------------------------------------------------------------------