10 | <% resource.errors.full_messages.each do |message| %>
11 |
<%= message %>
12 | <% end %>
13 |
14 |
15 | <% end %>
16 |
--------------------------------------------------------------------------------
/spec/helpers/likes_helper_spec.rb:
--------------------------------------------------------------------------------
1 | # require 'rails_helper'
2 |
3 | # # Specs in this file have access to a helper object that includes
4 | # # the LikesHelper. For example:
5 | # #
6 | # # describe LikesHelper do
7 | # # describe "string concat" do
8 | # # it "concats two strings with spaces" do
9 | # # expect(helper.concat_strings("this","that")).to eq("this that")
10 | # # end
11 | # # end
12 | # # end
13 | # RSpec.describe LikesHelper, type: :helper do
14 | # pending "add some examples to (or delete) #{__FILE__}"
15 | # end
16 |
--------------------------------------------------------------------------------
/spec/helpers/posts_helper_spec.rb:
--------------------------------------------------------------------------------
1 | # require 'rails_helper'
2 |
3 | # # Specs in this file have access to a helper object that includes
4 | # # the PostsHelper. For example:
5 | # #
6 | # # describe PostsHelper do
7 | # # describe "string concat" do
8 | # # it "concats two strings with spaces" do
9 | # # expect(helper.concat_strings("this","that")).to eq("this that")
10 | # # end
11 | # # end
12 | # # end
13 | # RSpec.describe PostsHelper, type: :helper do
14 | # pending "add some examples to (or delete) #{__FILE__}"
15 | # end
16 |
--------------------------------------------------------------------------------
/spec/helpers/users_helper_spec.rb:
--------------------------------------------------------------------------------
1 | # require 'rails_helper'
2 |
3 | # # Specs in this file have access to a helper object that includes
4 | # # the UsersHelper. For example:
5 | # #
6 | # # describe UsersHelper do
7 | # # describe "string concat" do
8 | # # it "concats two strings with spaces" do
9 | # # expect(helper.concat_strings("this","that")).to eq("this that")
10 | # # end
11 | # # end
12 | # # end
13 | # RSpec.describe UsersHelper, type: :helper do
14 | # pending "add some examples to (or delete) #{__FILE__}"
15 | # end
16 |
--------------------------------------------------------------------------------
/spec/helpers/comments_helper_spec.rb:
--------------------------------------------------------------------------------
1 | # require 'rails_helper'
2 |
3 | # # Specs in this file have access to a helper object that includes
4 | # # the CommentsHelper. For example:
5 | # #
6 | # # describe CommentsHelper do
7 | # # describe "string concat" do
8 | # # it "concats two strings with spaces" do
9 | # # expect(helper.concat_strings("this","that")).to eq("this that")
10 | # # end
11 | # # end
12 | # # end
13 | # RSpec.describe CommentsHelper, type: :helper do
14 | # pending "add some examples to (or delete) #{__FILE__}"
15 | # end
16 |
--------------------------------------------------------------------------------
/config/initializers/assets.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Version of your assets, change this if you want to expire all your assets.
4 | Rails.application.config.assets.version = '1.0'
5 |
6 | # Add additional assets to the asset load path.
7 | # Rails.application.config.assets.paths << Emoji.images_path
8 |
9 | # Precompile additional assets.
10 | # application.js, application.css, and all non-JS/CSS in the app/assets
11 | # folder are already added.
12 | # Rails.application.config.assets.precompile += %w( admin.js admin.css )
13 |
--------------------------------------------------------------------------------
/app/views/devise/unlocks/new.html.erb:
--------------------------------------------------------------------------------
1 |
14 | <% end %>
15 |
16 | <%= render "devise/shared/links" %>
17 |
--------------------------------------------------------------------------------
/config/initializers/inflections.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Add new inflection rules using the following format. Inflections
4 | # are locale specific, and you may define rules for as many different
5 | # locales as you wish. All of these examples are active by default:
6 | # ActiveSupport::Inflector.inflections(:en) do |inflect|
7 | # inflect.plural /^(ox)$/i, "\\1en"
8 | # inflect.singular /^(ox)en/i, "\\1"
9 | # inflect.irregular "person", "people"
10 | # inflect.uncountable %w( fish sheep )
11 | # end
12 |
13 | # These inflection rules are supported but not enabled by default:
14 | # ActiveSupport::Inflector.inflections(:en) do |inflect|
15 | # inflect.acronym "RESTful"
16 | # end
17 |
--------------------------------------------------------------------------------
/app/views/posts/new.html.erb:
--------------------------------------------------------------------------------
1 |
2 |
New post
3 | <% if @new_post.errors.any? %>
4 |
5 | <% @new_post.errors.full_messages.each do |message| %>
6 |
<%= message %>
7 | <% end %>
8 |
9 | <% end %>
10 | <%= form_with model: @new_post, url: user_posts_path(@current_user) do |form| %>
11 |
32 | <% end %>
33 |
34 | <%= render "devise/shared/links" %>
35 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2023 Osama Ashraf
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/views/users/show.html.erb:
--------------------------------------------------------------------------------
1 |
Posted by <%= @user.name %> on <%= @post.created_at.strftime("%B %d, %Y") %>
--------------------------------------------------------------------------------
/spec/features/user_index_spec.rb:
--------------------------------------------------------------------------------
1 | require 'rails_helper'
2 |
3 | RSpec.describe 'User Index', type: :feature do
4 | before :each do
5 | @user1 = User.create(
6 | name: 'Osama',
7 | photo: 'https://www.shutterstock.com/image-vector/hi-hello-banner-speech-bubble-poster-1505210795',
8 | bio: 'Full stack',
9 | postsCounter: 3
10 | )
11 | @user2 = User.create(
12 | name: 'Salem',
13 | photo: 'https://www.shutterstock.com/image-vector/hi-hello-banner-speech-bubble-poster-1505210795',
14 | bio: 'programmer',
15 | postsCounter: 0
16 | )
17 | visit root_path
18 | end
19 |
20 | it 'username of all user' do
21 | expect(page).to have_content(@user1.name)
22 | expect(page).to have_content(@user2.name)
23 | end
24 |
25 | it 'photo of user' do
26 | assert page.has_xpath?("//img[@src = 'https://www.shutterstock.com/image-vector/hi-hello-banner-speech-bubble-poster-1505210795']")
27 | assert page.has_xpath?("//img[@src = 'https://www.shutterstock.com/image-vector/hi-hello-banner-speech-bubble-poster-1505210795']")
28 | end
29 |
30 | it 'number of posts' do
31 | expect(page).to have_content(' 3')
32 | expect(page).to have_content('0')
33 | end
34 |
35 | it 'show on click' do
36 | click_link(@user1.name)
37 | expect(page).to have_current_path user_path(@user1.id)
38 | end
39 | end
40 |
--------------------------------------------------------------------------------
/app/controllers/posts_controller.rb:
--------------------------------------------------------------------------------
1 | class PostsController < ApplicationController
2 | load_and_authorize_resource
3 | def index
4 | @user = User.find(params[:user_id])
5 | @posts = @user.posts.includes(:comments)
6 | end
7 |
8 | def show
9 | @user = User.find(params[:user_id])
10 | @post = @user.posts.find(params[:id])
11 | @comments = @post.comments
12 | @likes = @post.likes
13 | end
14 |
15 | def new
16 | @current_user = current_user
17 | @new_post = Post.new
18 | end
19 |
20 | def create
21 | @new_post = Post.new(post_params)
22 | @new_post.author = current_user
23 |
24 | if @new_post.save
25 | @new_post.update_post_counter
26 | flash[:notice] = 'successfully post.'
27 | redirect_to user_path(@new_post.author_id), notice: 'Post successfully'
28 | else
29 | render :new, alert: 'error'
30 | end
31 | end
32 |
33 | def destroy
34 | deleted_post = Post.find(params[:id])
35 | user = User.find(deleted_post.author_id)
36 | user.postsCounter -= 1
37 | deleted_post.destroy
38 | if user.save
39 | redirect_to user_path(params[:user_id]), notice: 'delete successfully'
40 | else
41 | render :new, alert: 'error at deleting post'
42 | end
43 | end
44 |
45 | private
46 |
47 | def post_params
48 | params.require(:post).permit(:title, :text)
49 | end
50 | end
51 |
--------------------------------------------------------------------------------
/spec/models/user_spec.rb:
--------------------------------------------------------------------------------
1 | require 'rails_helper'
2 |
3 | RSpec.describe User, type: :model do
4 | describe 'here I will add the test for the user of methods and validations' do
5 | subject { User.new(name: 'osama', photo: 'osamaportrait', bio: 'I am engineer of computer enginerring') }
6 | before { subject.save }
7 | it 'the name ought to be present' do
8 | subject.name = nil
9 | expect(subject).to_not be_valid
10 | end
11 | it ' add a test for the name of the author, where it is valid.' do
12 | subject.name = 'abc'
13 | expect(subject).to be_valid
14 | end
15 | it 'the posts counter ought to be integer num' do
16 | subject.postsCounter = 'osama'
17 | expect(subject).to_not be_valid
18 | end
19 | it 'the posts counter ought to be greater than zero' do
20 | subject.postsCounter = -6
21 | expect(subject).to_not be_valid
22 | end
23 | it 'the posts counter ought to be integer num' do
24 | subject.postsCounter = 6.2
25 | expect(subject).to_not be_valid
26 | end
27 | it 'add a test for the post counter where it is valid' do
28 | subject.postsCounter = 6
29 | expect(subject).to be_valid
30 | end
31 | it 'The length of the array of recent_posts method' do
32 | method_length = subject.recent_posts.length
33 | expect(method_length).to be(0)
34 | end
35 | end
36 | end
37 |
--------------------------------------------------------------------------------
/spec/requests/posts_spec.rb:
--------------------------------------------------------------------------------
1 | require 'rails_helper'
2 |
3 | RSpec.describe PostsController, type: :request do
4 | let(:user) { User.create(name: 'Test User') }
5 | let(:post) { user.posts.create(title: 'Test Post', text: 'This is a test post.') }
6 |
7 | describe 'GET /users/:user_id/posts' do
8 | it 'renders the index template' do
9 | get user_posts_path(user)
10 | expect(response).to render_template(:index)
11 | end
12 |
13 | it 'returns a 200 OK status code' do
14 | get user_posts_path(user)
15 | expect(response).to have_http_status(:ok)
16 | end
17 |
18 | it 'includes the post title in the response body' do
19 | get user_posts_path(user)
20 | expect(response.body).to include('Test User')
21 | end
22 | end
23 |
24 | describe 'GET /users/:user_id/posts/:id' do
25 | it 'renders the show template' do
26 | get user_post_path(user, post)
27 | expect(response).to render_template(:show)
28 | end
29 |
30 | it 'returns a 200 OK status code' do
31 | get user_post_path(user, post)
32 | expect(response).to have_http_status(:ok)
33 | end
34 |
35 | it 'includes the post title and body in the response body' do
36 | get user_post_path(user, post)
37 | expect(response.body).to include('This is a test post.')
38 | # expect(response.body).to include(post.text)
39 | end
40 | end
41 | end
42 |
--------------------------------------------------------------------------------
/spec/requests/users_spec.rb:
--------------------------------------------------------------------------------
1 | require 'rails_helper'
2 |
3 | RSpec.describe 'Users', type: :request do
4 | describe 'GET #index' do
5 | user = User.create(name: 'osamamar', photo: 'https://unsplash.com/photos/F_-0BxGuVvo',
6 | bio: 'carpenter from america.')
7 | before(:each) do
8 | get '/users'
9 | end
10 |
11 | it 'When the GET request response status is right' do
12 | expect(response).to have_http_status(:ok)
13 | end
14 |
15 | it 'When renders the correct template' do
16 | expect(response).to render_template(:index)
17 | end
18 |
19 | it 'when response involves right placeholder text' do
20 | expect(response.body).to include('All Users')
21 | end
22 |
23 | describe 'GET #show' do
24 | before(:each) do
25 | user = User.create(name: 'osamamar', photo: 'https://unsplash.com/photos/F_-0BxGuVvo',
26 | bio: 'carpenter from america.')
27 | get "/users/#{user.id}"
28 | end
29 |
30 | it 'When the GET request response status is right' do
31 | expect(response).to have_http_status(:ok)
32 | end
33 |
34 | it 'When renders the right template' do
35 | expect(response).to render_template(:show)
36 | end
37 | it 'When renders content rightly' do
38 | expect(response.body).to include('osamamar')
39 | end
40 | end
41 | end
42 | end
43 |
--------------------------------------------------------------------------------
/spec/features/post_show_spec.rb:
--------------------------------------------------------------------------------
1 | require 'rails_helper'
2 |
3 | RSpec.describe 'pooost index', type: :feature do
4 | before :each do
5 | @user = User.create(
6 | name: 'Osama',
7 | photo: 'https://www.shutterstock.com/image-vector/hi-hello-banner-speech-bubble-poster-1505210795',
8 | bio: 'Egyptian developer',
9 | postsCounter: 0
10 | )
11 | @usersalem = User.create(
12 | name: 'Salem',
13 | photo: 'https://www.shutterstock.com/image-vector/hi-hello-banner-speech-bubble-poster-1505210795',
14 | bio: 'Egyptian programmer',
15 | postsCounter: 0
16 | )
17 | @post = Post.create(author_id: @user.id, title: 'title', text: 'My first ost for osama', commentsCounter: 0,
18 | likesCounter: 0)
19 | Comment.create(post_id: @post.id, author_id: @user.id, text: 'curious comment')
20 | Comment.create(post_id: @post.id, author_id: @usersalem.id, text: 'osama comment')
21 | visit user_posts_path(@user.id)
22 | end
23 |
24 | it 'username of the user' do
25 | expect(page).to have_content(@post.title)
26 | end
27 |
28 | it 'writer of the post' do
29 | expect(page).to have_content('Osama')
30 | end
31 |
32 | it 'comments for post' do
33 | expect(page).to have_content('comments: 0')
34 | end
35 |
36 | it 'likes for post' do
37 | expect(page).to have_content('likes: 0')
38 | end
39 |
40 | it ' body of post' do
41 | expect(page).to have_content('My first ost for osama')
42 | end
43 |
44 | it 'username of commenter' do
45 | expect(page).to have_content('Salem')
46 | end
47 |
48 | it 'comment of commenter' do
49 | expect(page).to have_content('My first ost for osama')
50 | end
51 | end
52 |
--------------------------------------------------------------------------------
/app/views/devise/registrations/edit.html.erb:
--------------------------------------------------------------------------------
1 |
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?", turbo_confirm: "Are you sure?" }, method: :delete %>
42 |
43 | <%= link_to "Back", :back %>
44 |
--------------------------------------------------------------------------------
/spec/features/post_index_spec.rb:
--------------------------------------------------------------------------------
1 | require 'rails_helper'
2 |
3 | RSpec.describe 'the index of post', type: :feature do
4 | before :each do
5 | @user = User.create(
6 | name: 'Osama',
7 | photo: 'https://www.shutterstock.com/image-vector/hi-hello-banner-speech-bubble-poster-1505210795',
8 | bio: 'Egyptian developer',
9 | postsCounter: 0
10 | )
11 | @post = Post.create(author_id: @user.id, title: 'title', text: 'My post of osama', commentsCounter: 0,
12 | likesCounter: 0)
13 | Comment.create(post_id: @post.id, author_id: @user.id, text: 'curious comment')
14 | Comment.create(post_id: @post.id, author_id: @user.id, text: 'This osama comment')
15 | visit user_posts_path(@user.id)
16 | end
17 |
18 | it 'the picture of the user' do
19 | assert page.has_xpath?("//img[@src='https://www.shutterstock.com/image-vector/hi-hello-banner-speech-bubble-poster-1505210795']")
20 | end
21 |
22 | it 'username of the user' do
23 | expect(page).to have_content(@user.name)
24 | end
25 |
26 | it 'number of post of user' do
27 | expect(page).to have_content('0')
28 | end
29 |
30 | it 'title of post' do
31 | expect(page).to have_content(@post.title)
32 | end
33 |
34 | it 'body of a post' do
35 | expect(page).to have_content('My post of osama')
36 | end
37 |
38 | it 'comments of a post' do
39 | expect(page).to have_content('curious comment')
40 | end
41 |
42 | it 'comments post' do
43 | expect(page).to have_content('comments: 0')
44 | end
45 |
46 | it 'likes for a post' do
47 | expect(page).to have_content('likes: 0')
48 | end
49 |
50 | it 'redirect to posts show' do
51 | click_on 'title'
52 | expect(page).to have_current_path user_post_path(@user.id, @post.id)
53 | end
54 | end
55 |
--------------------------------------------------------------------------------
/.github/workflows/linters.yml:
--------------------------------------------------------------------------------
1 | name: Linters
2 |
3 | on: pull_request
4 |
5 | env:
6 | FORCE_COLOR: 1
7 |
8 | jobs:
9 | rubocop:
10 | name: Rubocop
11 | runs-on: ubuntu-22.04
12 | steps:
13 | - uses: actions/checkout@v2
14 | - uses: actions/setup-ruby@v1
15 | with:
16 | ruby-version: 3.1.x
17 | - name: Setup Rubocop
18 | run: |
19 | gem install --no-document rubocop -v '>= 1.0, < 2.0' # https://docs.rubocop.org/en/stable/installation/
20 | [ -f .rubocop.yml ] || wget https://raw.githubusercontent.com/microverseinc/linters-config/master/ror/.rubocop.yml
21 | - name: Rubocop Report
22 | run: rubocop --color
23 | stylelint:
24 | name: Stylelint
25 | runs-on: ubuntu-22.04
26 | steps:
27 | - uses: actions/checkout@v2
28 | - uses: actions/setup-node@v1
29 | with:
30 | node-version: "18.x"
31 | - name: Setup Stylelint
32 | run: |
33 | npm install --save-dev stylelint@13.x stylelint-scss@3.x stylelint-config-standard@21.x stylelint-csstree-validator@1.x
34 | [ -f .stylelintrc.json ] || wget https://raw.githubusercontent.com/microverseinc/linters-config/master/ror/.stylelintrc.json
35 | - name: Stylelint Report
36 | run: npx stylelint "**/*.{css,scss}"
37 | nodechecker:
38 | name: node_modules checker
39 | runs-on: ubuntu-22.04
40 | steps:
41 | - uses: actions/checkout@v2
42 | - name: Check node_modules existence
43 | run: |
44 | if [ -d "node_modules/" ]; then echo -e "\e[1;31mThe node_modules/ folder was pushed to the repo. Please remove it from the GitHub repository and try again."; echo -e "\e[1;32mYou can set up a .gitignore file with this folder included on it to prevent this from happening in the future." && exit 1; fi
45 |
--------------------------------------------------------------------------------
/app/assets/stylesheets/style.css:
--------------------------------------------------------------------------------
1 | /* start index styles */
2 |
3 | /*
4 | 1.index styles
5 | 2.universal styles
6 | 3.common styles
7 | 4.content styles
8 | 5.mediaquery styles
9 | */
10 |
11 | /* end index styles */
12 |
13 | /* start universal styles */
14 | *,
15 | *::after,
16 | *::before {
17 | padding: 0;
18 | margin: 0;
19 | box-sizing: border-box;
20 | }
21 |
22 | body {
23 | font-size: 16px;
24 | line-height: 1.42857143;
25 | color: #777;
26 | display: grid;
27 | place-items: center;
28 | }
29 |
30 | /* end universal styles */
31 |
32 | /* start common styles */
33 | ul {
34 | list-style-type: none;
35 | }
36 |
37 | a {
38 | text-decoration: none;
39 | }
40 |
41 | .container {
42 | width: 80%;
43 | margin: 0 auto;
44 | }
45 |
46 | .pd-y {
47 | padding: 120px 0;
48 | }
49 |
50 | .responsive {
51 | width: 100%;
52 | height: 100%;
53 | object-fit: cover;
54 | }
55 |
56 | /* end common styles */
57 |
58 | /* start content styles */
59 | .aside__left__responsive {
60 | width: 7%;
61 | }
62 |
63 | .aside {
64 | display: flex;
65 | align-items: center;
66 | border: 1px solid;
67 | margin-bottom: 15px;
68 | }
69 |
70 | .bio {
71 | height: 100px;
72 | border: 1px solid;
73 | }
74 |
75 | .useridposts li,
76 | .showpost {
77 | border: 1px solid;
78 | margin-bottom: 15px;
79 | display: flex;
80 | flex-direction: column;
81 | padding: 50px;
82 | }
83 |
84 | .seeallposts {
85 | margin: 0 auto;
86 | display: block;
87 | margin-bottom: 30px;
88 | }
89 |
90 | .postshow,
91 | .postcomment,
92 | .showpostcomment {
93 | border: 1px solid;
94 | }
95 |
96 | .flex {
97 | display: flex;
98 | align-items: center;
99 | }
100 |
101 | /* end content styles */
102 |
103 | /* start mediaquery styles */
104 |
105 | /* end mediaquery styles */
106 |
--------------------------------------------------------------------------------
/db/migrate/20230309152328_add_devise_to_users.rb:
--------------------------------------------------------------------------------
1 | class AddDeviseToUsers < ActiveRecord::Migration[7.0]
2 | def self.up
3 | change_table :users do |t|
4 | ## Database authenticatable
5 | t.string :email, null: false, default: ''
6 | t.string :encrypted_password, null: false, default: ''
7 |
8 | ## Recoverable
9 | t.string :reset_password_token
10 | t.datetime :reset_password_sent_at
11 |
12 | ## Rememberable
13 | t.datetime :remember_created_at
14 |
15 | ## Trackable
16 | # t.integer :sign_in_count, default: 0, null: false
17 | # t.datetime :current_sign_in_at
18 | # t.datetime :last_sign_in_at
19 | # t.string :current_sign_in_ip
20 | # t.string :last_sign_in_ip
21 |
22 | ## Confirmable
23 | t.string :confirmation_token
24 | t.datetime :confirmed_at
25 | t.datetime :confirmation_sent_at
26 | t.string :unconfirmed_email # Only if using reconfirmable
27 |
28 | ## Lockable
29 | # t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
30 | # t.string :unlock_token # Only if unlock strategy is :email or :both
31 | # t.datetime :locked_at
32 |
33 | # Uncomment below if timestamps were not included in your original model.
34 | # t.timestamps null: false
35 | end
36 |
37 | add_index :users, :email, unique: true
38 | add_index :users, :reset_password_token, unique: true
39 | # add_index :users, :confirmation_token, unique: true
40 | # add_index :users, :unlock_token, unique: true
41 | end
42 |
43 | def self.down
44 | # By default, we don't want to make any assumption about how to roll back a migration when your
45 | # model already existed. Please edit below which fields you would like to remove in this migration.
46 | raise ActiveRecord::IrreversibleMigration
47 | end
48 | end
49 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/config/puma.rb:
--------------------------------------------------------------------------------
1 | # Puma can serve each request in a thread from an internal thread pool.
2 | # The `threads` method setting takes two numbers: a minimum and maximum.
3 | # Any libraries that use thread pools should be configured to match
4 | # the maximum value specified for Puma. Default is set to 5 threads for minimum
5 | # and maximum; this matches the default thread size of Active Record.
6 | #
7 | max_threads_count = ENV.fetch('RAILS_MAX_THREADS', 5)
8 | min_threads_count = ENV.fetch('RAILS_MIN_THREADS') { max_threads_count }
9 | threads min_threads_count, max_threads_count
10 |
11 | # Specifies the `worker_timeout` threshold that Puma will use to wait before
12 | # terminating a worker in development environments.
13 | #
14 | worker_timeout 3600 if ENV.fetch('RAILS_ENV', 'development') == 'development'
15 |
16 | # Specifies the `port` that Puma will listen on to receive requests; default is 3000.
17 | #
18 | port ENV.fetch('PORT', 3000)
19 |
20 | # Specifies the `environment` that Puma will run in.
21 | #
22 | environment ENV.fetch('RAILS_ENV') { 'development' }
23 |
24 | # Specifies the `pidfile` that Puma will use.
25 | pidfile ENV.fetch('PIDFILE') { 'tmp/pids/server.pid' }
26 |
27 | # Specifies the number of `workers` to boot in clustered mode.
28 | # Workers are forked web server processes. If using threads and workers together
29 | # the concurrency of the application would be max `threads` * `workers`.
30 | # Workers do not work on JRuby or Windows (both of which do not support
31 | # processes).
32 | #
33 | # workers ENV.fetch("WEB_CONCURRENCY") { 2 }
34 |
35 | # Use the `preload_app!` method when specifying a `workers` number.
36 | # This directive tells Puma to first boot the application and load code
37 | # before forking the application. This takes advantage of Copy On Write
38 | # process behavior so workers use less memory.
39 | #
40 | # preload_app!
41 |
42 | # Allow puma to be restarted by `bin/rails restart` command.
43 | plugin :tmp_restart
44 |
--------------------------------------------------------------------------------
/db/seeds.rb:
--------------------------------------------------------------------------------
1 | # This file should contain all the record creation needed to seed the database with its default values.
2 | # The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup).
3 | #
4 | # Examples:
5 | #
6 | # movies = Movie.create([{ name: "Star Wars" }, { name: "Lord of the Rings" }])
7 | # Character.create(name: "Luke", movie: movies.first)
8 | first_user = User.create(name: 'Tom', photo: 'https://unsplash.com/photos/F_-0BxGuVvo', bio: 'Teacher from Mexico.')
9 | second_user = User.create(name: 'Lilly', photo: 'https://unsplash.com/photos/F_-0BxGuVvo', bio: 'Teacher from Poland.')
10 | first_post = Post.create(author: first_user, title: 'Hello', text: 'This is my first post')
11 | Post.create(author: first_user, title: 'Hedsallo1', text: 'This is my fidsadsarst post')
12 | Post.create(author: first_user, title: 'Hello2', text: 'This is dsasamy first post')
13 | Post.create(author: first_user, title: 'Hello3', text: 'This is my first dsadsapost')
14 | Post.create(author: first_user, title: 'Hello4', text: 'This ddsasais my first post')
15 | Post.create(author: first_user, title: 'Hello5', text: 'This is mdsdsaay first post')
16 | Post.create(author: first_user, title: 'Hello6', text: 'This is my last post')
17 | Post.create(author: first_user, title: 'Hello7', text: 'This is my test post')
18 | Comment.create(post: first_post, author: second_user, text: 'Hi 3!')
19 | Comment.create(post: first_post, author: second_user, text: 'Hi T2!')
20 | Comment.create(post: first_post, author: second_user, text: 'Hi 1!')
21 | Comment.create(post: first_post, author: second_user, text: 'Hi ')
22 | Comment.create(post: first_post, author: second_user, text: 'Hi 4!')
23 | Comment.create(post: first_post, author: second_user, text: 'Hi 5!')
24 | Comment.create(post: first_post, author: second_user, text: 'Hi 6!')
25 | Comment.create(post: first_post, author: second_user, text: 'Hi Tom!')
26 | puts('created successfully')
27 |
--------------------------------------------------------------------------------
/spec/features/user_show_spec.rb:
--------------------------------------------------------------------------------
1 | require 'rails_helper'
2 |
3 | RSpec.describe 'idex user', type: :feature do
4 | before :each do
5 | @user = User.create(
6 | name: 'Osama',
7 | photo: 'https://www.shutterstock.com/image-vector/hi-hello-banner-speech-bubble-poster-1505210795',
8 | bio: 'Programmer',
9 | postsCounter: 0
10 | )
11 | @post1 = Post.create(author_id: @user.id, title: 'title osama', text: 'osama post one', commentsCounter: 0,
12 | likesCounter: 0)
13 | @post2 = Post.create(author_id: @user.id, title: 'my title of osama', text: 'osama post two', commentsCounter: 0,
14 | likesCounter: 0)
15 | @post3 = Post.create(author_id: @user.id, title: 'osama title', text: 'osama post three', commentsCounter: 0,
16 | likesCounter: 0)
17 | visit user_path(@user.id)
18 | end
19 |
20 | it 'picture of user' do
21 | assert page.has_xpath?("//img[@src = 'https://www.shutterstock.com/image-vector/hi-hello-banner-speech-bubble-poster-1505210795']")
22 | end
23 |
24 | it 'username' do
25 | expect(page).to have_content(@user.name)
26 | end
27 |
28 | it 'posts user' do
29 | expect(page).to have_content('0')
30 | end
31 |
32 | it 'user bio' do
33 | expect(page).to have_content('Programmer')
34 | end
35 |
36 | it 'first three posts of user' do
37 | expect(page).to have_content(@post1.title)
38 | expect(page).to have_content(@post2.title)
39 | expect(page).to have_content(@post3.title)
40 | end
41 |
42 | it 'button for all post' do
43 | expect(page).to have_link('See all posts')
44 | end
45 |
46 | it 'redirect to post show' do
47 | click_on 'title osama'
48 | expect(page).to have_current_path user_post_path(@user.id, @post1.id)
49 | end
50 |
51 | it 'redirect to all index ' do
52 | click_link('See all posts')
53 | expect(page).to have_current_path user_posts_path(@user.id)
54 | end
55 | end
56 |
--------------------------------------------------------------------------------
/spec/models/post_spec.rb:
--------------------------------------------------------------------------------
1 | require 'rails_helper'
2 |
3 | RSpec.describe Post, type: :model do
4 | describe 'the post test ' do
5 | before(:each) do
6 | @author = User.new(name: 'osama', photo: 'osamaportrait', bio: 'engineer of computer engineering')
7 | @post = Post.new(author: @author, title: 'Hi guys I am testing the post model', text: 'powered By osama')
8 | end
9 |
10 | it 'title ought to be present' do
11 | @post.title = nil
12 | expect(@post).to_not be_valid
13 | end
14 |
15 | it 'add a test for Post where the title is valid.' do
16 | @post.title = 'osama'
17 | expect(@post).to be_valid
18 | end
19 |
20 | it 'is valid with a title that is 250 characters or less' do
21 | @post = Post.new(title: 'f' * 250, text: 'Lorem ipsum', author: @author)
22 | expect(@post).to be_valid
23 | end
24 |
25 | it 'the comments counter ought to be integer num' do
26 | @post.commentsCounter = 6.2
27 | expect(@post).not_to be_valid
28 | end
29 |
30 | it 'the comments counter ought to be integer num' do
31 | @post.commentsCounter = 'osama'
32 | expect(@post).to_not be_valid
33 | end
34 |
35 | it ' add a test for the comments counter where it is valid' do
36 | @post.commentsCounter = 5
37 | expect(@post).to be_valid
38 | end
39 |
40 | it 'the likes counter ought to be greater than zero' do
41 | @post.likesCounter = -6
42 | expect(@post).to_not be_valid
43 | end
44 | it ' add a test for the likes counter where it is valid' do
45 | @post.likesCounter = -6
46 | expect(@post).to_not be_valid
47 | end
48 |
49 | it 'here is the test of method recent_five_comments method' do
50 | expect(@post.recent_five_comments.length).to be(0)
51 | end
52 |
53 | it 'here is the test of method update_post_counter' do
54 | @post.update_post_counter
55 | expect(@author.postsCounter).to be(1)
56 | end
57 | end
58 | end
59 |
--------------------------------------------------------------------------------
/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 | require 'active_support/core_ext/integer/time'
2 |
3 | # The test environment is used exclusively to run your application's
4 | # test suite. You never need to work with it otherwise. Remember that
5 | # your test database is "scratch space" for the test suite and is wiped
6 | # and recreated between test runs. Don't rely on the data there!
7 |
8 | Rails.application.configure do
9 | # Settings specified here will take precedence over those in config/application.rb.
10 |
11 | # Turn false under Spring and add config.action_view.cache_template_loading = true.
12 | config.cache_classes = true
13 |
14 | # Eager loading loads your whole application. When running a single test locally,
15 | # this probably isn't necessary. It's a good idea to do in a continuous integration
16 | # system, or in some way before deploying your code.
17 | config.eager_load = ENV['CI'].present?
18 |
19 | # Configure public file server for tests with Cache-Control for performance.
20 | config.public_file_server.enabled = true
21 | config.public_file_server.headers = {
22 | 'Cache-Control' => "public, max-age=#{1.hour.to_i}"
23 | }
24 |
25 | # Show full error reports and disable caching.
26 | config.consider_all_requests_local = true
27 | config.action_controller.perform_caching = false
28 | config.cache_store = :null_store
29 |
30 | # Raise exceptions instead of rendering exception templates.
31 | config.action_dispatch.show_exceptions = false
32 |
33 | # Disable request forgery protection in test environment.
34 | config.action_controller.allow_forgery_protection = false
35 |
36 | # Store uploaded files on the local file system in a temporary directory.
37 | config.active_storage.service = :test
38 |
39 | config.action_mailer.perform_caching = false
40 |
41 | # Tell Action Mailer not to deliver emails to the real world.
42 | # The :test delivery method accumulates sent emails in the
43 | # ActionMailer::Base.deliveries array.
44 | config.action_mailer.delivery_method = :test
45 |
46 | # Print deprecation notices to the stderr.
47 | config.active_support.deprecation = :stderr
48 |
49 | # Raise exceptions for disallowed deprecations.
50 | config.active_support.disallowed_deprecation = :raise
51 |
52 | # Tell Active Support which deprecation messages to disallow.
53 | config.active_support.disallowed_deprecation_warnings = []
54 |
55 | # Raises error for missing translations.
56 | # config.i18n.raise_on_missing_translations = true
57 |
58 | # Annotate rendered view with file names.
59 | # config.action_view.annotate_rendered_view_with_filenames = true
60 | end
61 |
--------------------------------------------------------------------------------
/Gemfile:
--------------------------------------------------------------------------------
1 | source 'https://rubygems.org'
2 |
3 | gem 'rubocop', '>= 1.0', '< 2.0'
4 |
5 | git_source(:github) { |repo| "https://github.com/#{repo}.git" }
6 |
7 | ruby '3.2.0'
8 |
9 | # Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
10 | gem 'rails', '~> 7.0.4', '>= 7.0.4.2'
11 |
12 | # The original asset pipeline for Rails [https://github.com/rails/sprockets-rails]
13 | gem 'sprockets-rails'
14 |
15 | # Use postgresql as the database for Active Record
16 | gem 'pg', '~> 1.1'
17 |
18 | # Use the Puma web server [https://github.com/puma/puma]
19 | gem 'puma', '~> 5.0'
20 |
21 | # Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails]
22 | gem 'importmap-rails'
23 |
24 | # Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev]
25 | gem 'turbo-rails'
26 |
27 | # Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev]
28 | gem 'stimulus-rails'
29 |
30 | # Build JSON APIs with ease [https://github.com/rails/jbuilder]
31 | gem 'jbuilder'
32 |
33 | # Use Redis adapter to run Action Cable in production
34 | # gem "redis", "~> 4.0"
35 |
36 | # Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis]
37 | # gem "kredis"
38 |
39 | # Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword]
40 | # gem "bcrypt", "~> 3.1.7"
41 |
42 | # Windows does not include zoneinfo files, so bundle the tzinfo-data gem
43 | gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby]
44 |
45 | # Reduces boot times through caching; required in config/boot.rb
46 | gem 'bootsnap', require: false
47 |
48 | # Use Sass to process CSS
49 | # gem "sassc-rails"
50 |
51 | # Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]
52 | # gem "image_processing", "~> 1.2"
53 |
54 | group :development, :test do
55 | # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
56 | gem 'debug', platforms: %i[mri mingw x64_mingw]
57 | gem 'rails-controller-testing'
58 | gem 'rspec-rails'
59 | end
60 |
61 | group :development do
62 | # Use console on exceptions pages [https://github.com/rails/web-console]
63 | gem 'letter_opener'
64 | gem 'web-console'
65 |
66 | # Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler]
67 | # gem "rack-mini-profiler"
68 |
69 | # Speed up commands on slow machines / big apps [https://github.com/rails/spring]
70 | # gem "spring"
71 | end
72 |
73 | group :test do
74 | # Use system testing [https://guides.rubyonrails.org/testing.html#system-testing]
75 | gem 'capybara'
76 | gem 'selenium-webdriver'
77 | gem 'webdrivers'
78 | end
79 | gem 'cancancan'
80 | gem 'devise'
81 |
82 | gem 'jwt'
83 |
--------------------------------------------------------------------------------
/spec/rails_helper.rb:
--------------------------------------------------------------------------------
1 | # This file is copied to spec/ when you run 'rails generate rspec:install'
2 | require 'spec_helper'
3 | ENV['RAILS_ENV'] ||= 'test'
4 | require_relative '../config/environment'
5 | # Prevent database truncation if the environment is production
6 | abort('The Rails environment is running in production mode!') if Rails.env.production?
7 | require 'rspec/rails'
8 | # Add additional requires below this line. Rails is not loaded until this point!
9 |
10 | # Requires supporting ruby files with custom matchers and macros, etc, in
11 | # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
12 | # run as spec files by default. This means that files in spec/support that end
13 | # in _spec.rb will both be required and run as specs, causing the specs to be
14 | # run twice. It is recommended that you do not name files matching this glob to
15 | # end with _spec.rb. You can configure this pattern with the --pattern
16 | # option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
17 | #
18 | # The following line is provided for convenience purposes. It has the downside
19 | # of increasing the boot-up time by auto-requiring all files in the support
20 | # directory. Alternatively, in the individual `*_spec.rb` files, manually
21 | # require only the support files necessary.
22 | #
23 | # Dir[Rails.root.join('spec', 'support', '**', '*.rb')].sort.each { |f| require f }
24 |
25 | # Checks for pending migrations and applies them before tests are run.
26 | # If you are not using ActiveRecord, you can remove these lines.
27 | begin
28 | ActiveRecord::Migration.maintain_test_schema!
29 | rescue ActiveRecord::PendingMigrationError => e
30 | abort e.to_s.strip
31 | end
32 | RSpec.configure do |config|
33 | # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
34 | config.fixture_path = "#{Rails.root}/spec/fixtures"
35 |
36 | # If you're not using ActiveRecord, or you'd prefer not to run each of your
37 | # examples within a transaction, remove the following line or assign false
38 | # instead of true.
39 | config.use_transactional_fixtures = true
40 |
41 | # You can uncomment this line to turn off ActiveRecord support entirely.
42 | # config.use_active_record = false
43 |
44 | # RSpec Rails can automatically mix in different behaviours to your tests
45 | # based on their file location, for example enabling you to call `get` and
46 | # `post` in specs under `spec/controllers`.
47 | #
48 | # You can disable this behaviour by removing the line below, and instead
49 | # explicitly tag your specs with their type, e.g.:
50 | #
51 | # RSpec.describe UsersController, type: :controller do
52 | # # ...
53 | # end
54 | #
55 | # The different available types are documented in the features, such as in
56 | # https://relishapp.com/rspec/rspec-rails/docs
57 | config.infer_spec_type_from_file_location!
58 |
59 | # Filter lines from Rails gems in backtraces.
60 | config.filter_rails_from_backtrace!
61 | # arbitrary gems may also be filtered via:
62 | # config.filter_gems_from_backtrace("gem name")
63 | end
64 |
--------------------------------------------------------------------------------
/config/environments/development.rb:
--------------------------------------------------------------------------------
1 | require 'active_support/core_ext/integer/time'
2 |
3 | Rails.application.configure do
4 | # Settings specified here will take precedence over those in config/application.rb.
5 |
6 | # In the development environment your application's code is reloaded any time
7 | # it changes. This slows down response time but is perfect for development
8 | # since you don't have to restart the web server when you make code changes.
9 | config.cache_classes = false
10 |
11 | # Do not eager load code on boot.
12 | config.eager_load = false
13 |
14 | # Show full error reports.
15 | config.consider_all_requests_local = true
16 |
17 | # Enable server timing
18 | config.server_timing = true
19 |
20 | # Enable/disable caching. By default caching is disabled.
21 | # Run rails dev:cache to toggle caching.
22 | if Rails.root.join('tmp/caching-dev.txt').exist?
23 | config.action_controller.perform_caching = true
24 | config.action_controller.enable_fragment_cache_logging = true
25 |
26 | config.cache_store = :memory_store
27 | config.public_file_server.headers = {
28 | 'Cache-Control' => "public, max-age=#{2.days.to_i}"
29 | }
30 | else
31 | config.action_controller.perform_caching = false
32 |
33 | config.cache_store = :null_store
34 | end
35 |
36 | # Store uploaded files on the local file system (see config/storage.yml for options).
37 | config.active_storage.service = :local
38 |
39 | # Don't care if the mailer can't send.
40 | config.action_mailer.raise_delivery_errors = false
41 |
42 | config.action_mailer.perform_caching = false
43 |
44 | # =================================================================
45 | config.action_mailer.delivery_method = :letter_opener
46 | config.action_mailer.perform_deliveries = true
47 | config.action_mailer.default_url_options = { host: 'localhost:3000' }
48 |
49 | # config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
50 |
51 | # config.action_mailer.delivery_method = :letter_opener
52 |
53 | # # =======================
54 |
55 | # Print deprecation notices to the Rails logger.
56 | config.active_support.deprecation = :log
57 |
58 | # Raise exceptions for disallowed deprecations.
59 | config.active_support.disallowed_deprecation = :raise
60 |
61 | # Tell Active Support which deprecation messages to disallow.
62 | config.active_support.disallowed_deprecation_warnings = []
63 |
64 | # Raise an error on page load if there are pending migrations.
65 | config.active_record.migration_error = :page_load
66 |
67 | # Highlight code that triggered database queries in logs.
68 | config.active_record.verbose_query_logs = true
69 |
70 | # Suppress logger output for asset requests.
71 | config.assets.quiet = true
72 |
73 | # Raises error for missing translations.
74 | # config.i18n.raise_on_missing_translations = true
75 |
76 | # Annotate rendered view with file names.
77 | # config.action_view.annotate_rendered_view_with_filenames = true
78 |
79 | # Uncomment if you wish to allow Action Cable access from any origin.
80 | # config.action_cable.disable_request_forgery_protection = true
81 | end
82 |
--------------------------------------------------------------------------------
/db/schema.rb:
--------------------------------------------------------------------------------
1 | # This file is auto-generated from the current state of the database. Instead
2 | # of editing this file, please use the migrations feature of Active Record to
3 | # incrementally modify your database, and then regenerate this schema definition.
4 | #
5 | # This file is the source Rails uses to define your schema when running `bin/rails
6 | # db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
7 | # be faster and is potentially less error prone than running all of your
8 | # migrations from scratch. Old migrations may fail to apply correctly if those
9 | # migrations use external dependencies or application code.
10 | #
11 | # It's strongly recommended that you check this file into your version control system.
12 |
13 | # rubocop:disable Metrics/BlockLength
14 | ActiveRecord::Schema[7.0].define(version: 20_230_310_115_215) do
15 | # These are extensions that must be enabled in order to support this database
16 | enable_extension 'plpgsql'
17 |
18 | create_table 'comments', force: :cascade do |t|
19 | t.bigint 'author_id'
20 | t.bigint 'post_id'
21 | t.text 'text'
22 | t.datetime 'created_at', null: false
23 | t.datetime 'updated_at', null: false
24 | t.index ['author_id'], name: 'index_comments_on_author_id'
25 | t.index ['post_id'], name: 'index_comments_on_post_id'
26 | end
27 |
28 | create_table 'likes', force: :cascade do |t|
29 | t.bigint 'author_id'
30 | t.bigint 'post_id'
31 | t.datetime 'created_at', null: false
32 | t.datetime 'updated_at', null: false
33 | t.index ['author_id'], name: 'index_likes_on_author_id'
34 | t.index ['post_id'], name: 'index_likes_on_post_id'
35 | end
36 |
37 | create_table 'posts', force: :cascade do |t|
38 | t.bigint 'author_id'
39 | t.string 'title'
40 | t.text 'text'
41 | t.integer 'commentsCounter'
42 | t.integer 'likesCounter'
43 | t.datetime 'created_at', null: false
44 | t.datetime 'updated_at', null: false
45 | t.index ['author_id'], name: 'index_posts_on_author_id'
46 | end
47 |
48 | create_table 'users', force: :cascade do |t|
49 | t.string 'name'
50 | t.string 'photo'
51 | t.text 'bio'
52 | t.integer 'postsCounter'
53 | t.datetime 'created_at', null: false
54 | t.datetime 'updated_at', null: false
55 | t.string 'email', default: '', null: false
56 | t.string 'encrypted_password', default: '', null: false
57 | t.string 'reset_password_token'
58 | t.datetime 'reset_password_sent_at'
59 | t.datetime 'remember_created_at'
60 | t.string 'confirmation_token'
61 | t.datetime 'confirmed_at'
62 | t.datetime 'confirmation_sent_at'
63 | t.string 'unconfirmed_email'
64 | t.string 'role'
65 | t.index ['email'], name: 'index_users_on_email', unique: true
66 | t.index ['reset_password_token'], name: 'index_users_on_reset_password_token', unique: true
67 | end
68 |
69 | add_foreign_key 'comments', 'posts'
70 | add_foreign_key 'comments', 'users', column: 'author_id'
71 | add_foreign_key 'likes', 'posts'
72 | add_foreign_key 'likes', 'users', column: 'author_id'
73 | add_foreign_key 'posts', 'users', column: 'author_id'
74 | end
75 | # rubocop:enable Metrics/BlockLength
76 |
--------------------------------------------------------------------------------
/config/database.yml:
--------------------------------------------------------------------------------
1 | # PostgreSQL. Versions 9.3 and up are supported.
2 | #
3 | # Install the pg driver:
4 | # gem install pg
5 | # On macOS with Homebrew:
6 | # gem install pg -- --with-pg-config=/usr/local/bin/pg_config
7 | # On macOS with MacPorts:
8 | # gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
9 | # On Windows:
10 | # gem install pg
11 | # Choose the win32 build.
12 | # Install PostgreSQL and put its /bin directory on your path.
13 | #
14 | # Configure Using Gemfile
15 | # gem "pg"
16 | #
17 | default: &default
18 | adapter: postgresql
19 | encoding: unicode
20 | # For details on connection pooling, see Rails configuration guide
21 | # https://guides.rubyonrails.org/configuring.html#database-pooling
22 | pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
23 |
24 | development:
25 | <<: *default
26 | database: blogs_development
27 |
28 | host: localhost
29 | username: blogs
30 | password: blogs
31 |
32 |
33 | # The specified database role being used to connect to postgres.
34 | # To create additional roles in postgres see `$ createuser --help`.
35 | # When left blank, postgres will use the default role. This is
36 | # the same name as the operating system user running Rails.
37 | #username: blogs
38 |
39 | # The password associated with the postgres role (username).
40 | #password:
41 |
42 | # Connect on a TCP socket. Omitted by default since the client uses a
43 | # domain socket that doesn't need configuration. Windows does not have
44 | # domain sockets, so uncomment these lines.
45 | #host: localhost
46 |
47 | # The TCP port the server listens on. Defaults to 5432.
48 | # If your server runs on a different port number, change accordingly.
49 | #port: 5432
50 |
51 | # Schema search path. The server defaults to $user,public
52 | #schema_search_path: myapp,sharedapp,public
53 |
54 | # Minimum log levels, in increasing order:
55 | # debug5, debug4, debug3, debug2, debug1,
56 | # log, notice, warning, error, fatal, and panic
57 | # Defaults to warning.
58 | #min_messages: notice
59 |
60 | # Warning: The database defined as "test" will be erased and
61 | # re-generated from your development database when you run "rake".
62 | # Do not set this db to the same as development or production.
63 | test:
64 | <<: *default
65 | database: blogs_test
66 |
67 | # As with config/credentials.yml, you never want to store sensitive information,
68 | # like your database password, in your source code. If your source code is
69 | # ever seen by anyone, they now have access to your database.
70 | #
71 | # Instead, provide the password or a full connection URL as an environment
72 | # variable when you boot the app. For example:
73 | #
74 | # DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase"
75 | #
76 | # If the connection URL is provided in the special DATABASE_URL environment
77 | # variable, Rails will automatically merge its configuration values on top of
78 | # the values provided in this file. Alternatively, you can specify a connection
79 | # URL environment variable explicitly:
80 | #
81 | # production:
82 | # url: <%= ENV["MY_APP_DATABASE_URL"] %>
83 | #
84 | # Read https://guides.rubyonrails.org/configuring.html#configuring-a-database
85 | # for a full overview on how database connection configuration can be specified.
86 | #
87 | production:
88 | <<: *default
89 | database: blogs_production
90 | username: blogs
91 | password: <%= ENV["BLOGS_DATABASE_PASSWORD"] %>
92 |
--------------------------------------------------------------------------------
/bin/bundle:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 |
3 | # rubocop:disable all
4 |
5 |
6 | # frozen_string_literal: true
7 |
8 |
9 | #
10 | # This file was generated by Bundler.
11 | #
12 | # The application 'bundle' is installed as part of a gem, and
13 | # this file is here to facilitate running it.
14 | #
15 |
16 | require 'rubygems'
17 |
18 | m = Module.new do
19 | module_function
20 |
21 | def invoked_as_script?
22 | File.expand_path($PROGRAM_NAME) == File.expand_path(__FILE__)
23 | end
24 |
25 | def env_var_version
26 | ENV.fetch('BUNDLER_VERSION', nil)
27 | end
28 |
29 | def cli_arg_version
30 | return unless invoked_as_script? # don't want to hijack other binstubs
31 | return unless 'update'.start_with?(ARGV.first || ' ') # must be running `bundle update`
32 |
33 | bundler_version = nil
34 | update_index = nil
35 | ARGV.each_with_index do |a, i|
36 | bundler_version = a if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN
37 | next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/
38 |
39 | bundler_version = Regexp.last_match(1)
40 | update_index = i
41 | end
42 | bundler_version
43 | end
44 |
45 | def gemfile
46 | gemfile = ENV.fetch('BUNDLE_GEMFILE', nil)
47 | return gemfile if gemfile && !gemfile.empty?
48 |
49 | File.expand_path('../Gemfile', __dir__)
50 | end
51 |
52 | def lockfile
53 | lockfile =
54 | case File.basename(gemfile)
55 | when 'gems.rb' then gemfile.sub(/\.rb$/, gemfile)
56 | else "#{gemfile}.lock"
57 | end
58 | File.expand_path(lockfile)
59 | end
60 |
61 | def lockfile_version
62 | return unless File.file?(lockfile)
63 |
64 | lockfile_contents = File.read(lockfile)
65 | return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/
66 |
67 | Regexp.last_match(1)
68 | end
69 |
70 | def bundler_requirement
71 | @bundler_requirement ||=
72 | env_var_version ||
73 | cli_arg_version ||
74 | bundler_requirement_for(lockfile_version)
75 | end
76 |
77 | def bundler_requirement_for(version)
78 | return "#{Gem::Requirement.default}.a" unless version
79 |
80 | bundler_gem_version = Gem::Version.new(version)
81 |
82 | bundler_gem_version.approximate_recommendation
83 | end
84 |
85 | def load_bundler!
86 | ENV['BUNDLE_GEMFILE'] ||= gemfile
87 |
88 | activate_bundler
89 | end
90 |
91 | def activate_bundler
92 | gem_error = activation_error_handling do
93 | gem 'bundler', bundler_requirement
94 | end
95 | return if gem_error.nil?
96 |
97 | require_error = activation_error_handling do
98 | require 'bundler/version'
99 | end
100 | if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION))
101 | return
102 | end
103 |
104 | warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`" # rubocop:disable Layout/LineLength
105 | exit 42
106 | end
107 |
108 | def activation_error_handling
109 | yield
110 | nil
111 | rescue StandardError, LoadError => e
112 | e
113 | end
114 | end
115 |
116 | m.load_bundler!
117 |
118 | load Gem.bin_path('bundler', 'bundle') if m.invoked_as_script?
119 | # rubocop:enable Metrics/PerceivedComplexity
120 |
121 |
--------------------------------------------------------------------------------
/config/environments/production.rb:
--------------------------------------------------------------------------------
1 | require 'active_support/core_ext/integer/time'
2 |
3 | Rails.application.configure do
4 | # Settings specified here will take precedence over those in config/application.rb.
5 |
6 | # Code is not reloaded between requests.
7 | config.cache_classes = true
8 |
9 | # Eager load code on boot. This eager loads most of Rails and
10 | # your application in memory, allowing both threaded web servers
11 | # and those relying on copy on write to perform better.
12 | # Rake tasks automatically ignore this option for performance.
13 | config.eager_load = true
14 |
15 | # Full error reports are disabled and caching is turned on.
16 | config.consider_all_requests_local = false
17 | config.action_controller.perform_caching = true
18 |
19 | # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"]
20 | # or in config/master.key. This key is used to decrypt credentials (and other encrypted files).
21 | # config.require_master_key = true
22 |
23 | # Disable serving static files from the `/public` folder by default since
24 | # Apache or NGINX already handles this.
25 | config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
26 |
27 | # Compress CSS using a preprocessor.
28 | # config.assets.css_compressor = :sass
29 |
30 | # Do not fallback to assets pipeline if a precompiled asset is missed.
31 | config.assets.compile = false
32 |
33 | # Enable serving of images, stylesheets, and JavaScripts from an asset server.
34 | # config.asset_host = "http://assets.example.com"
35 |
36 | # Specifies the header that your server uses for sending files.
37 | # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for Apache
38 | # config.action_dispatch.x_sendfile_header = "X-Accel-Redirect" # for NGINX
39 |
40 | # Store uploaded files on the local file system (see config/storage.yml for options).
41 | config.active_storage.service = :local
42 |
43 | # Mount Action Cable outside main process or domain.
44 | # config.action_cable.mount_path = nil
45 | # config.action_cable.url = "wss://example.com/cable"
46 | # config.action_cable.allowed_request_origins = [ "http://example.com", /http:\/\/example.*/ ]
47 |
48 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
49 | # config.force_ssl = true
50 |
51 | # Include generic and useful information about system operation, but avoid logging too much
52 | # information to avoid inadvertent exposure of personally identifiable information (PII).
53 | config.log_level = :info
54 |
55 | # Prepend all log lines with the following tags.
56 | config.log_tags = [:request_id]
57 |
58 | # Use a different cache store in production.
59 | # config.cache_store = :mem_cache_store
60 |
61 | # Use a real queuing backend for Active Job (and separate queues per environment).
62 | # config.active_job.queue_adapter = :resque
63 | # config.active_job.queue_name_prefix = "blogs_production"
64 |
65 | config.action_mailer.perform_caching = false
66 |
67 | # Ignore bad email addresses and do not raise email delivery errors.
68 | # Set this to true and configure the email server for immediate delivery to raise delivery errors.
69 | # config.action_mailer.raise_delivery_errors = false
70 |
71 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
72 | # the I18n.default_locale when a translation cannot be found).
73 | config.i18n.fallbacks = true
74 |
75 | # Don't log any deprecations.
76 | config.active_support.report_deprecations = false
77 |
78 | # Use default logging formatter so that PID and timestamp are not suppressed.
79 | config.log_formatter = Logger::Formatter.new
80 |
81 | # Use a different logger for distributed setups.
82 | # require "syslog/logger"
83 | # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new "app-name")
84 |
85 | if ENV['RAILS_LOG_TO_STDOUT'].present?
86 | logger = ActiveSupport::Logger.new($stdout)
87 | logger.formatter = config.log_formatter
88 | config.logger = ActiveSupport::TaggedLogging.new(logger)
89 | end
90 |
91 | # Do not dump schema after migrations.
92 | config.active_record.dump_schema_after_migration = false
93 | end
94 |
--------------------------------------------------------------------------------
/config/locales/devise.en.yml:
--------------------------------------------------------------------------------
1 | # Additional translations at https://github.com/heartcombo/devise/wiki/I18n
2 |
3 | en:
4 | devise:
5 | confirmations:
6 | confirmed: "Your email address has been successfully confirmed."
7 | send_instructions: "You will receive an email with instructions for how to confirm your email address in a few minutes."
8 | send_paranoid_instructions: "If your email address exists in our database, you will receive an email with instructions for how to confirm your email address in a few minutes."
9 | failure:
10 | already_authenticated: "You are already signed in."
11 | inactive: "Your account is not activated yet."
12 | invalid: "Invalid %{authentication_keys} or password."
13 | locked: "Your account is locked."
14 | last_attempt: "You have one more attempt before your account is locked."
15 | not_found_in_database: "Invalid %{authentication_keys} or password."
16 | timeout: "Your session expired. Please sign in again to continue."
17 | unauthenticated: "You need to sign in or sign up before continuing."
18 | unconfirmed: "You have to confirm your email address before continuing."
19 | mailer:
20 | confirmation_instructions:
21 | subject: "Confirmation instructions"
22 | reset_password_instructions:
23 | subject: "Reset password instructions"
24 | unlock_instructions:
25 | subject: "Unlock instructions"
26 | email_changed:
27 | subject: "Email Changed"
28 | password_change:
29 | subject: "Password Changed"
30 | omniauth_callbacks:
31 | failure: "Could not authenticate you from %{kind} because \"%{reason}\"."
32 | success: "Successfully authenticated from %{kind} account."
33 | passwords:
34 | no_token: "You can't access this page without coming from a password reset email. If you do come from a password reset email, please make sure you used the full URL provided."
35 | send_instructions: "You will receive an email with instructions on how to reset your password in a few minutes."
36 | send_paranoid_instructions: "If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes."
37 | updated: "Your password has been changed successfully. You are now signed in."
38 | updated_not_active: "Your password has been changed successfully."
39 | registrations:
40 | destroyed: "Bye! Your account has been successfully cancelled. We hope to see you again soon."
41 | signed_up: "Welcome! You have signed up successfully."
42 | signed_up_but_inactive: "You have signed up successfully. However, we could not sign you in because your account is not yet activated."
43 | signed_up_but_locked: "You have signed up successfully. However, we could not sign you in because your account is locked."
44 | signed_up_but_unconfirmed: "A message with a confirmation link has been sent to your email address. Please follow the link to activate your account."
45 | update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and follow the confirmation link to confirm your new email address."
46 | updated: "Your account has been updated successfully."
47 | updated_but_not_signed_in: "Your account has been updated successfully, but since your password was changed, you need to sign in again."
48 | sessions:
49 | signed_in: "Signed in successfully."
50 | signed_out: "Signed out successfully."
51 | already_signed_out: "Signed out successfully."
52 | unlocks:
53 | send_instructions: "You will receive an email with instructions for how to unlock your account in a few minutes."
54 | send_paranoid_instructions: "If your account exists, you will receive an email with instructions for how to unlock it in a few minutes."
55 | unlocked: "Your account has been unlocked successfully. Please sign in to continue."
56 | errors:
57 | messages:
58 | already_confirmed: "was already confirmed, please try signing in"
59 | confirmation_period_expired: "needs to be confirmed within %{period}, please request a new one"
60 | expired: "has expired, please request a new one"
61 | not_found: "not found"
62 | not_locked: "was not locked"
63 | not_saved:
64 | one: "1 error prohibited this %{resource} from being saved:"
65 | other: "%{count} errors prohibited this %{resource} from being saved:"
66 |
--------------------------------------------------------------------------------
/spec/spec_helper.rb:
--------------------------------------------------------------------------------
1 | # This file was generated by the `rails generate rspec:install` command. Conventionally, all
2 | # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3 | # The generated `.rspec` file contains `--require spec_helper` which will cause
4 | # this file to always be loaded, without a need to explicitly require it in any
5 | # files.
6 | #
7 | # Given that it is always loaded, you are encouraged to keep this file as
8 | # light-weight as possible. Requiring heavyweight dependencies from this file
9 | # will add to the boot time of your test suite on EVERY test run, even for an
10 | # individual file that may not need all of that loaded. Instead, consider making
11 | # a separate helper file that requires the additional dependencies and performs
12 | # the additional setup, and require it from the spec files that actually need
13 | # it.
14 | #
15 | # See https://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
16 | RSpec.configure do |config|
17 | # rspec-expectations config goes here. You can use an alternate
18 | # assertion/expectation library such as wrong or the stdlib/minitest
19 | # assertions if you prefer.
20 | config.expect_with :rspec do |expectations|
21 | # This option will default to `true` in RSpec 4. It makes the `description`
22 | # and `failure_message` of custom matchers include text for helper methods
23 | # defined using `chain`, e.g.:
24 | # be_bigger_than(2).and_smaller_than(4).description
25 | # # => "be bigger than 2 and smaller than 4"
26 | # ...rather than:
27 | # # => "be bigger than 2"
28 | expectations.include_chain_clauses_in_custom_matcher_descriptions = true
29 | end
30 |
31 | # rspec-mocks config goes here. You can use an alternate test double
32 | # library (such as bogus or mocha) by changing the `mock_with` option here.
33 | config.mock_with :rspec do |mocks|
34 | # Prevents you from mocking or stubbing a method that does not exist on
35 | # a real object. This is generally recommended, and will default to
36 | # `true` in RSpec 4.
37 | mocks.verify_partial_doubles = true
38 | end
39 |
40 | # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
41 | # have no way to turn it off -- the option exists only for backwards
42 | # compatibility in RSpec 3). It causes shared context metadata to be
43 | # inherited by the metadata hash of host groups and examples, rather than
44 | # triggering implicit auto-inclusion in groups with matching metadata.
45 | config.shared_context_metadata_behavior = :apply_to_host_groups
46 |
47 | # The settings below are suggested to provide a good initial experience
48 | # with RSpec, but feel free to customize to your heart's content.
49 | # # This allows you to limit a spec run to individual examples or groups
50 | # # you care about by tagging them with `:focus` metadata. When nothing
51 | # # is tagged with `:focus`, all examples get run. RSpec also provides
52 | # # aliases for `it`, `describe`, and `context` that include `:focus`
53 | # # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
54 | # config.filter_run_when_matching :focus
55 | #
56 | # # Allows RSpec to persist some state between runs in order to support
57 | # # the `--only-failures` and `--next-failure` CLI options. We recommend
58 | # # you configure your source control system to ignore this file.
59 | # config.example_status_persistence_file_path = "spec/examples.txt"
60 | #
61 | # # Limits the available syntax to the non-monkey patched syntax that is
62 | # # recommended. For more details, see:
63 | # # https://relishapp.com/rspec/rspec-core/docs/configuration/zero-monkey-patching-mode
64 | # config.disable_monkey_patching!
65 | #
66 | # # Many RSpec users commonly either run the entire suite or an individual
67 | # # file, and it's useful to allow more verbose output when running an
68 | # # individual spec file.
69 | # if config.files_to_run.one?
70 | # # Use the documentation formatter for detailed output,
71 | # # unless a formatter has already been configured
72 | # # (e.g. via a command-line flag).
73 | # config.default_formatter = "doc"
74 | # end
75 | #
76 | # # Print the 10 slowest examples and example groups at the
77 | # # end of the spec run, to help surface which specs are running
78 | # # particularly slow.
79 | # config.profile_examples = 10
80 | #
81 | # # Run specs in random order to surface order dependencies. If you find an
82 | # # order dependency and want to debug it, you can fix the order by providing
83 | # # the seed, which is printed after each run.
84 | # # --seed 1234
85 | # config.order = :random
86 | #
87 | # # Seed global randomization in this process using the `--seed` CLI option.
88 | # # Setting this allows you to use `--seed` to deterministically reproduce
89 | # # test failures related to randomization by passing the same `--seed` value
90 | # # as the one that triggered the failure.
91 | # Kernel.srand config.seed
92 | end
93 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | # 📗 Table of Contents
5 |
6 | - [📗 Table of Contents](#-table-of-contents)
7 | - [📖 \[Blog App\] ](#-blog-app-)
8 | - [🛠 Built With ](#-built-with-)
9 | - [Tech Stack ](#tech-stack-)
10 | - [Key Features ](#key-features-)
11 | - [💻 Getting Started ](#-getting-started-)
12 | - [Prerequisites](#prerequisites)
13 | - [Setup](#setup)
14 | - [Install](#install)
15 | - [Usage](#usage)
16 | - [👥 Authors ](#-authors-)
17 | - [🔭 Future Features ](#-future-features-)
18 | - [🤝 Contributing ](#-contributing-)
19 | - [⭐️ Show your support ](#️-show-your-support-)
20 | - [🙏 Acknowledgments ](#-acknowledgments-)
21 | - [📝 License ](#-license-)
22 |
23 |
24 |
25 | # 📖 [Blog App]
26 |
27 | > In this project, The Blog app will be a classic example of a blog website. I will create a fully functional website that will show the list of posts and empower readers to interact with them by adding comments and liking posts.
28 |
29 | ## 🛠 Built With
30 |
31 | - [x] Database👌
32 | - [x] ROR (Ruby on Rails)
33 | - [x] Postgresql
34 |
35 | ### Tech Stack
36 |
37 |
38 | Client
39 |
56 |
57 |
58 |
59 |
60 | ### Key Features
61 |
62 | - [ ] Create a new app. Give it a meaningful name.
63 | - [ ] Initialize my project with Git.💯
64 | - [ ] Build my project schema.💯
65 | - Create and run the necessary migration files.
66 | - Table and column names match the ERD diagram.
67 | - note: photo for users table be a link to an image
68 | - Foreign keys be included.
69 | - All columns that are foreign keys have a corresponding index.👌
70 |
71 |
151 |
152 |
153 |
154 | ## 🔭 Future Features
155 |
156 | > Add the authentication for the app💯
157 | > Add the authorization for the app
158 | > Add the test for it😊
159 | > Add the UI for the project💯
160 |
161 |
203 |
204 |
--------------------------------------------------------------------------------
/Gemfile.lock:
--------------------------------------------------------------------------------
1 | GEM
2 | remote: https://rubygems.org/
3 | specs:
4 | actioncable (7.0.4.2)
5 | actionpack (= 7.0.4.2)
6 | activesupport (= 7.0.4.2)
7 | nio4r (~> 2.0)
8 | websocket-driver (>= 0.6.1)
9 | actionmailbox (7.0.4.2)
10 | actionpack (= 7.0.4.2)
11 | activejob (= 7.0.4.2)
12 | activerecord (= 7.0.4.2)
13 | activestorage (= 7.0.4.2)
14 | activesupport (= 7.0.4.2)
15 | mail (>= 2.7.1)
16 | net-imap
17 | net-pop
18 | net-smtp
19 | actionmailer (7.0.4.2)
20 | actionpack (= 7.0.4.2)
21 | actionview (= 7.0.4.2)
22 | activejob (= 7.0.4.2)
23 | activesupport (= 7.0.4.2)
24 | mail (~> 2.5, >= 2.5.4)
25 | net-imap
26 | net-pop
27 | net-smtp
28 | rails-dom-testing (~> 2.0)
29 | actionpack (7.0.4.2)
30 | actionview (= 7.0.4.2)
31 | activesupport (= 7.0.4.2)
32 | rack (~> 2.0, >= 2.2.0)
33 | rack-test (>= 0.6.3)
34 | rails-dom-testing (~> 2.0)
35 | rails-html-sanitizer (~> 1.0, >= 1.2.0)
36 | actiontext (7.0.4.2)
37 | actionpack (= 7.0.4.2)
38 | activerecord (= 7.0.4.2)
39 | activestorage (= 7.0.4.2)
40 | activesupport (= 7.0.4.2)
41 | globalid (>= 0.6.0)
42 | nokogiri (>= 1.8.5)
43 | actionview (7.0.4.2)
44 | activesupport (= 7.0.4.2)
45 | builder (~> 3.1)
46 | erubi (~> 1.4)
47 | rails-dom-testing (~> 2.0)
48 | rails-html-sanitizer (~> 1.1, >= 1.2.0)
49 | activejob (7.0.4.2)
50 | activesupport (= 7.0.4.2)
51 | globalid (>= 0.3.6)
52 | activemodel (7.0.4.2)
53 | activesupport (= 7.0.4.2)
54 | activerecord (7.0.4.2)
55 | activemodel (= 7.0.4.2)
56 | activesupport (= 7.0.4.2)
57 | activestorage (7.0.4.2)
58 | actionpack (= 7.0.4.2)
59 | activejob (= 7.0.4.2)
60 | activerecord (= 7.0.4.2)
61 | activesupport (= 7.0.4.2)
62 | marcel (~> 1.0)
63 | mini_mime (>= 1.1.0)
64 | activesupport (7.0.4.2)
65 | concurrent-ruby (~> 1.0, >= 1.0.2)
66 | i18n (>= 1.6, < 2)
67 | minitest (>= 5.1)
68 | tzinfo (~> 2.0)
69 | addressable (2.8.1)
70 | public_suffix (>= 2.0.2, < 6.0)
71 | ast (2.4.2)
72 | bcrypt (3.1.18)
73 | bindex (0.8.1)
74 | bootsnap (1.16.0)
75 | msgpack (~> 1.2)
76 | builder (3.2.4)
77 | cancancan (3.5.0)
78 | capybara (3.38.0)
79 | addressable
80 | matrix
81 | mini_mime (>= 0.1.3)
82 | nokogiri (~> 1.8)
83 | rack (>= 1.6.0)
84 | rack-test (>= 0.6.3)
85 | regexp_parser (>= 1.5, < 3.0)
86 | xpath (~> 3.2)
87 | concurrent-ruby (1.2.0)
88 | crass (1.0.6)
89 | date (3.3.3)
90 | debug (1.7.1)
91 | irb (>= 1.5.0)
92 | reline (>= 0.3.1)
93 | devise (4.9.0)
94 | bcrypt (~> 3.0)
95 | orm_adapter (~> 0.1)
96 | railties (>= 4.1.0)
97 | responders
98 | warden (~> 1.2.3)
99 | diff-lcs (1.5.0)
100 | erubi (1.12.0)
101 | globalid (1.1.0)
102 | activesupport (>= 5.0)
103 | i18n (1.12.0)
104 | concurrent-ruby (~> 1.0)
105 | importmap-rails (1.1.5)
106 | actionpack (>= 6.0.0)
107 | railties (>= 6.0.0)
108 | io-console (0.6.0)
109 | irb (1.6.2)
110 | reline (>= 0.3.0)
111 | jbuilder (2.11.5)
112 | actionview (>= 5.0.0)
113 | activesupport (>= 5.0.0)
114 | json (2.6.3)
115 | jwt (2.7.0)
116 | launchy (2.5.2)
117 | addressable (~> 2.8)
118 | letter_opener (1.8.1)
119 | launchy (>= 2.2, < 3)
120 | loofah (2.19.1)
121 | crass (~> 1.0.2)
122 | nokogiri (>= 1.5.9)
123 | mail (2.8.1)
124 | mini_mime (>= 0.1.1)
125 | net-imap
126 | net-pop
127 | net-smtp
128 | marcel (1.0.2)
129 | matrix (0.4.2)
130 | method_source (1.0.0)
131 | mini_mime (1.1.2)
132 | minitest (5.17.0)
133 | msgpack (1.6.0)
134 | net-imap (0.3.4)
135 | date
136 | net-protocol
137 | net-pop (0.1.2)
138 | net-protocol
139 | net-protocol (0.2.1)
140 | timeout
141 | net-smtp (0.3.3)
142 | net-protocol
143 | nio4r (2.5.8)
144 | nokogiri (1.14.2-x86_64-linux)
145 | racc (~> 1.4)
146 | orm_adapter (0.5.0)
147 | parallel (1.22.1)
148 | parser (3.2.1.0)
149 | ast (~> 2.4.1)
150 | pg (1.4.5)
151 | public_suffix (5.0.1)
152 | puma (5.6.5)
153 | nio4r (~> 2.0)
154 | racc (1.6.2)
155 | rack (2.2.6.2)
156 | rack-test (2.0.2)
157 | rack (>= 1.3)
158 | rails (7.0.4.2)
159 | actioncable (= 7.0.4.2)
160 | actionmailbox (= 7.0.4.2)
161 | actionmailer (= 7.0.4.2)
162 | actionpack (= 7.0.4.2)
163 | actiontext (= 7.0.4.2)
164 | actionview (= 7.0.4.2)
165 | activejob (= 7.0.4.2)
166 | activemodel (= 7.0.4.2)
167 | activerecord (= 7.0.4.2)
168 | activestorage (= 7.0.4.2)
169 | activesupport (= 7.0.4.2)
170 | bundler (>= 1.15.0)
171 | railties (= 7.0.4.2)
172 | rails-controller-testing (1.0.5)
173 | actionpack (>= 5.0.1.rc1)
174 | actionview (>= 5.0.1.rc1)
175 | activesupport (>= 5.0.1.rc1)
176 | rails-dom-testing (2.0.3)
177 | activesupport (>= 4.2.0)
178 | nokogiri (>= 1.6)
179 | rails-html-sanitizer (1.5.0)
180 | loofah (~> 2.19, >= 2.19.1)
181 | railties (7.0.4.2)
182 | actionpack (= 7.0.4.2)
183 | activesupport (= 7.0.4.2)
184 | method_source
185 | rake (>= 12.2)
186 | thor (~> 1.0)
187 | zeitwerk (~> 2.5)
188 | rainbow (3.1.1)
189 | rake (13.0.6)
190 | regexp_parser (2.7.0)
191 | reline (0.3.2)
192 | io-console (~> 0.5)
193 | responders (3.1.0)
194 | actionpack (>= 5.2)
195 | railties (>= 5.2)
196 | rexml (3.2.5)
197 | rspec-core (3.12.1)
198 | rspec-support (~> 3.12.0)
199 | rspec-expectations (3.12.2)
200 | diff-lcs (>= 1.2.0, < 2.0)
201 | rspec-support (~> 3.12.0)
202 | rspec-mocks (3.12.3)
203 | diff-lcs (>= 1.2.0, < 2.0)
204 | rspec-support (~> 3.12.0)
205 | rspec-rails (6.0.1)
206 | actionpack (>= 6.1)
207 | activesupport (>= 6.1)
208 | railties (>= 6.1)
209 | rspec-core (~> 3.11)
210 | rspec-expectations (~> 3.11)
211 | rspec-mocks (~> 3.11)
212 | rspec-support (~> 3.11)
213 | rspec-support (3.12.0)
214 | rubocop (1.45.1)
215 | json (~> 2.3)
216 | parallel (~> 1.10)
217 | parser (>= 3.2.0.0)
218 | rainbow (>= 2.2.2, < 4.0)
219 | regexp_parser (>= 1.8, < 3.0)
220 | rexml (>= 3.2.5, < 4.0)
221 | rubocop-ast (>= 1.24.1, < 2.0)
222 | ruby-progressbar (~> 1.7)
223 | unicode-display_width (>= 2.4.0, < 3.0)
224 | rubocop-ast (1.26.0)
225 | parser (>= 3.2.1.0)
226 | ruby-progressbar (1.11.0)
227 | rubyzip (2.3.2)
228 | selenium-webdriver (4.8.1)
229 | rexml (~> 3.2, >= 3.2.5)
230 | rubyzip (>= 1.2.2, < 3.0)
231 | websocket (~> 1.0)
232 | sprockets (4.2.0)
233 | concurrent-ruby (~> 1.0)
234 | rack (>= 2.2.4, < 4)
235 | sprockets-rails (3.4.2)
236 | actionpack (>= 5.2)
237 | activesupport (>= 5.2)
238 | sprockets (>= 3.0.0)
239 | stimulus-rails (1.2.1)
240 | railties (>= 6.0.0)
241 | thor (1.2.1)
242 | timeout (0.3.2)
243 | turbo-rails (1.3.3)
244 | actionpack (>= 6.0.0)
245 | activejob (>= 6.0.0)
246 | railties (>= 6.0.0)
247 | tzinfo (2.0.6)
248 | concurrent-ruby (~> 1.0)
249 | unicode-display_width (2.4.2)
250 | warden (1.2.9)
251 | rack (>= 2.0.9)
252 | web-console (4.2.0)
253 | actionview (>= 6.0.0)
254 | activemodel (>= 6.0.0)
255 | bindex (>= 0.4.0)
256 | railties (>= 6.0.0)
257 | webdrivers (5.2.0)
258 | nokogiri (~> 1.6)
259 | rubyzip (>= 1.3.0)
260 | selenium-webdriver (~> 4.0)
261 | websocket (1.2.9)
262 | websocket-driver (0.7.5)
263 | websocket-extensions (>= 0.1.0)
264 | websocket-extensions (0.1.5)
265 | xpath (3.2.0)
266 | nokogiri (~> 1.8)
267 | zeitwerk (2.6.7)
268 |
269 | PLATFORMS
270 | x86_64-linux
271 |
272 | DEPENDENCIES
273 | bootsnap
274 | cancancan
275 | capybara
276 | debug
277 | devise
278 | importmap-rails
279 | jbuilder
280 | jwt
281 | letter_opener
282 | pg (~> 1.1)
283 | puma (~> 5.0)
284 | rails (~> 7.0.4, >= 7.0.4.2)
285 | rails-controller-testing
286 | rspec-rails
287 | rubocop (>= 1.0, < 2.0)
288 | selenium-webdriver
289 | sprockets-rails
290 | stimulus-rails
291 | turbo-rails
292 | tzinfo-data
293 | web-console
294 | webdrivers
295 |
296 | RUBY VERSION
297 | ruby 3.2.0p0
298 |
299 | BUNDLED WITH
300 | 2.4.5
301 |
--------------------------------------------------------------------------------
/config/initializers/devise.rb:
--------------------------------------------------------------------------------
1 | # rubocop:disable Layout/LineLength
2 |
3 | # Assuming you have not yet modified this file, each configuration option below
4 | # is set to its default value. Note that some are commented out while others
5 | # are not: uncommented lines are intended to protect your configuration from
6 | # breaking changes in upgrades (i.e., in the event that future versions of
7 | # Devise change the default values for those options).
8 | #
9 | # Use this hook to configure devise mailer, warden hooks and so forth.
10 | # Many of these configuration options can be set straight in your model.
11 | Devise.setup do |config|
12 | # The secret key used by Devise. Devise uses this key to generate
13 | # random tokens. Changing this key will render invalid all existing
14 | # confirmation, reset password and unlock tokens in the database.
15 | # Devise will use the `secret_key_base` as its `secret_key`
16 | # by default. You can change it below and use your own secret key.
17 | # config.secret_key = '6d720d8403914da9dd05121b8075074d8f86be9df32c3d3013c3bf68dd173f7f1490cc5cf43fe4dc80345d30ffed191bde635ea4ae7c9f0a56c4c088b33c7c8e'
18 |
19 | # ==> Controller configuration
20 | # Configure the parent class to the devise controllers.
21 | # config.parent_controller = 'DeviseController'
22 |
23 | # ==> Mailer Configuration
24 | # Configure the e-mail address which will be shown in Devise::Mailer,
25 | # note that it will be overwritten if you use your own mailer class
26 | # with default "from" parameter.
27 | config.mailer_sender = 'please-change-me-at-config-initializers-devise@example.com'
28 |
29 | # Configure the class responsible to send e-mails.
30 | # config.mailer = 'Devise::Mailer'
31 |
32 | # Configure the parent class responsible to send e-mails.
33 | # config.parent_mailer = 'ActionMailer::Base'
34 |
35 | # ==> ORM configuration
36 | # Load and configure the ORM. Supports :active_record (default) and
37 | # :mongoid (bson_ext recommended) by default. Other ORMs may be
38 | # available as additional gems.
39 | require 'devise/orm/active_record'
40 |
41 | # ==> Configuration for any authentication mechanism
42 | # Configure which keys are used when authenticating a user. The default is
43 | # just :email. You can configure it to use [:username, :subdomain], so for
44 | # authenticating a user, both parameters are required. Remember that those
45 | # parameters are used only when authenticating and not when retrieving from
46 | # session. If you need permissions, you should implement that in a before filter.
47 | # You can also supply a hash where the value is a boolean determining whether
48 | # or not authentication should be aborted when the value is not present.
49 | # config.authentication_keys = [:email]
50 |
51 | # Configure parameters from the request object used for authentication. Each entry
52 | # given should be a request method and it will automatically be passed to the
53 | # find_for_authentication method and considered in your model lookup. For instance,
54 | # if you set :request_keys to [:subdomain], :subdomain will be used on authentication.
55 | # The same considerations mentioned for authentication_keys also apply to request_keys.
56 | # config.request_keys = []
57 |
58 | # Configure which authentication keys should be case-insensitive.
59 | # These keys will be downcased upon creating or modifying a user and when used
60 | # to authenticate or find a user. Default is :email.
61 | config.case_insensitive_keys = [:email]
62 |
63 | # Configure which authentication keys should have whitespace stripped.
64 | # These keys will have whitespace before and after removed upon creating or
65 | # modifying a user and when used to authenticate or find a user. Default is :email.
66 | config.strip_whitespace_keys = [:email]
67 |
68 | # Tell if authentication through request.params is enabled. True by default.
69 | # It can be set to an array that will enable params authentication only for the
70 | # given strategies, for example, `config.params_authenticatable = [:database]` will
71 | # enable it only for database (email + password) authentication.
72 | # config.params_authenticatable = true
73 |
74 | # Tell if authentication through HTTP Auth is enabled. False by default.
75 | # It can be set to an array that will enable http authentication only for the
76 | # given strategies, for example, `config.http_authenticatable = [:database]` will
77 | # enable it only for database authentication.
78 | # For API-only applications to support authentication "out-of-the-box", you will likely want to
79 | # enable this with :database unless you are using a custom strategy.
80 | # The supported strategies are:
81 | # :database = Support basic authentication with authentication key + password
82 | # config.http_authenticatable = false
83 |
84 | # If 401 status code should be returned for AJAX requests. True by default.
85 | # config.http_authenticatable_on_xhr = true
86 |
87 | # The realm used in Http Basic Authentication. 'Application' by default.
88 | # config.http_authentication_realm = 'Application'
89 |
90 | # It will change confirmation, password recovery and other workflows
91 | # to behave the same regardless if the e-mail provided was right or wrong.
92 | # Does not affect registerable.
93 | # config.paranoid = true
94 |
95 | # By default Devise will store the user in session. You can skip storage for
96 | # particular strategies by setting this option.
97 | # Notice that if you are skipping storage for all authentication paths, you
98 | # may want to disable generating routes to Devise's sessions controller by
99 | # passing skip: :sessions to `devise_for` in your config/routes.rb
100 | config.skip_session_storage = [:http_auth]
101 |
102 | # By default, Devise cleans up the CSRF token on authentication to
103 | # avoid CSRF token fixation attacks. This means that, when using AJAX
104 | # requests for sign in and sign up, you need to get a new CSRF token
105 | # from the server. You can disable this option at your own risk.
106 | # config.clean_up_csrf_token_on_authentication = true
107 |
108 | # When false, Devise will not attempt to reload routes on eager load.
109 | # This can reduce the time taken to boot the app but if your application
110 | # requires the Devise mappings to be loaded during boot time the application
111 | # won't boot properly.
112 | # config.reload_routes = true
113 |
114 | # ==> Configuration for :database_authenticatable
115 | # For bcrypt, this is the cost for hashing the password and defaults to 12. If
116 | # using other algorithms, it sets how many times you want the password to be hashed.
117 | # The number of stretches used for generating the hashed password are stored
118 | # with the hashed password. This allows you to change the stretches without
119 | # invalidating existing passwords.
120 | #
121 | # Limiting the stretches to just one in testing will increase the performance of
122 | # your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use
123 | # a value less than 10 in other environments. Note that, for bcrypt (the default
124 | # algorithm), the cost increases exponentially with the number of stretches (e.g.
125 | # a value of 20 is already extremely slow: approx. 60 seconds for 1 calculation).
126 | config.stretches = Rails.env.test? ? 1 : 12
127 |
128 | # Set up a pepper to generate the hashed password.
129 | # config.pepper = 'dfc0c87acb82a380348a6b4b9d25bad677ac6f2a5ca7c7fdcd1b978956bbba6d715860ef9568b6db69bce29d379d9eb24f5106a571a39713698c09842547ec4c'
130 |
131 | # Send a notification to the original email when the user's email is changed.
132 | # config.send_email_changed_notification = false
133 |
134 | # Send a notification email when the user's password is changed.
135 | # config.send_password_change_notification = false
136 |
137 | # ==> Configuration for :confirmable
138 | # A period that the user is allowed to access the website even without
139 | # confirming their account. For instance, if set to 2.days, the user will be
140 | # able to access the website for two days without confirming their account,
141 | # access will be blocked just in the third day.
142 | # You can also set it to nil, which will allow the user to access the website
143 | # without confirming their account.
144 | # Default is 0.days, meaning the user cannot access the website without
145 | # confirming their account.
146 | # config.allow_unconfirmed_access_for = 2.days
147 |
148 | # A period that the user is allowed to confirm their account before their
149 | # token becomes invalid. For example, if set to 3.days, the user can confirm
150 | # their account within 3 days after the mail was sent, but on the fourth day
151 | # their account can't be confirmed with the token any more.
152 | # Default is nil, meaning there is no restriction on how long a user can take
153 | # before confirming their account.
154 | # config.confirm_within = 3.days
155 |
156 | # If true, requires any email changes to be confirmed (exactly the same way as
157 | # initial account confirmation) to be applied. Requires additional unconfirmed_email
158 | # db field (see migrations). Until confirmed, new email is stored in
159 | # unconfirmed_email column, and copied to email column on successful confirmation.
160 | config.reconfirmable = true
161 |
162 | # Defines which key will be used when confirming an account
163 | # config.confirmation_keys = [:email]
164 |
165 | # ==> Configuration for :rememberable
166 | # The time the user will be remembered without asking for credentials again.
167 | # config.remember_for = 2.weeks
168 |
169 | # Invalidates all the remember me tokens when the user signs out.
170 | config.expire_all_remember_me_on_sign_out = true
171 |
172 | # If true, extends the user's remember period when remembered via cookie.
173 | # config.extend_remember_period = false
174 |
175 | # Options to be passed to the created cookie. For instance, you can set
176 | # secure: true in order to force SSL only cookies.
177 | # config.rememberable_options = {}
178 |
179 | # ==> Configuration for :validatable
180 | # Range for password length.
181 | config.password_length = 6..128
182 |
183 | # Email regex used to validate email formats. It simply asserts that
184 | # one (and only one) @ exists in the given string. This is mainly
185 | # to give user feedback and not to assert the e-mail validity.
186 | config.email_regexp = /\A[^@\s]+@[^@\s]+\z/
187 |
188 | # ==> Configuration for :timeoutable
189 | # The time you want to timeout the user session without activity. After this
190 | # time the user will be asked for credentials again. Default is 30 minutes.
191 | # config.timeout_in = 30.minutes
192 |
193 | # ==> Configuration for :lockable
194 | # Defines which strategy will be used to lock an account.
195 | # :failed_attempts = Locks an account after a number of failed attempts to sign in.
196 | # :none = No lock strategy. You should handle locking by yourself.
197 | # config.lock_strategy = :failed_attempts
198 |
199 | # Defines which key will be used when locking and unlocking an account
200 | # config.unlock_keys = [:email]
201 |
202 | # Defines which strategy will be used to unlock an account.
203 | # :email = Sends an unlock link to the user email
204 | # :time = Re-enables login after a certain amount of time (see :unlock_in below)
205 | # :both = Enables both strategies
206 | # :none = No unlock strategy. You should handle unlocking by yourself.
207 | # config.unlock_strategy = :both
208 |
209 | # Number of authentication tries before locking an account if lock_strategy
210 | # is failed attempts.
211 | # config.maximum_attempts = 20
212 |
213 | # Time interval to unlock the account if :time is enabled as unlock_strategy.
214 | # config.unlock_in = 1.hour
215 |
216 | # Warn on the last attempt before the account is locked.
217 | # config.last_attempt_warning = true
218 |
219 | # ==> Configuration for :recoverable
220 | #
221 | # Defines which key will be used when recovering the password for an account
222 | # config.reset_password_keys = [:email]
223 |
224 | # Time interval you can reset your password with a reset password key.
225 | # Don't put a too small interval or your users won't have the time to
226 | # change their passwords.
227 | config.reset_password_within = 6.hours
228 |
229 | # When set to false, does not sign a user in automatically after their password is
230 | # reset. Defaults to true, so a user is signed in automatically after a reset.
231 | # config.sign_in_after_reset_password = true
232 |
233 | # ==> Configuration for :encryptable
234 | # Allow you to use another hashing or encryption algorithm besides bcrypt (default).
235 | # You can use :sha1, :sha512 or algorithms from others authentication tools as
236 | # :clearance_sha1, :authlogic_sha512 (then you should set stretches above to 20
237 | # for default behavior) and :restful_authentication_sha1 (then you should set
238 | # stretches to 10, and copy REST_AUTH_SITE_KEY to pepper).
239 | #
240 | # Require the `devise-encryptable` gem when using anything other than bcrypt
241 | # config.encryptor = :sha512
242 |
243 | # ==> Scopes configuration
244 | # Turn scoped views on. Before rendering "sessions/new", it will first check for
245 | # "users/sessions/new". It's turned off by default because it's slower if you
246 | # are using only default views.
247 | # config.scoped_views = false
248 |
249 | # Configure the default scope given to Warden. By default it's the first
250 | # devise role declared in your routes (usually :user).
251 | # config.default_scope = :user
252 |
253 | # Set this configuration to false if you want /users/sign_out to sign out
254 | # only the current scope. By default, Devise signs out all scopes.
255 | # config.sign_out_all_scopes = true
256 |
257 | # ==> Navigation configuration
258 | # Lists the formats that should be treated as navigational. Formats like
259 | # :html should redirect to the sign in page when the user does not have
260 | # access, but formats like :xml or :json, should return 401.
261 | #
262 | # If you have any extra navigational formats, like :iphone or :mobile, you
263 | # should add them to the navigational formats lists.
264 | #
265 | # The "*/*" below is required to match Internet Explorer requests.
266 | # config.navigational_formats = ['*/*', :html, :turbo_stream]
267 |
268 | # The default HTTP method used to sign out a resource. Default is :delete.
269 | config.sign_out_via = :delete
270 |
271 | # ==> OmniAuth
272 | # Add a new OmniAuth provider. Check the wiki for more information on setting
273 | # up on your models and hooks.
274 | # config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo'
275 |
276 | # ==> Warden configuration
277 | # If you want to use other strategies, that are not supported by Devise, or
278 | # change the failure app, you can configure them inside the config.warden block.
279 | #
280 | # config.warden do |manager|
281 | # manager.intercept_401 = false
282 | # manager.default_strategies(scope: :user).unshift :some_external_strategy
283 | # end
284 |
285 | # ==> Mountable engine configurations
286 | # When using Devise inside an engine, let's call it `MyEngine`, and this engine
287 | # is mountable, there are some extra configurations to be taken into account.
288 | # The following options are available, assuming the engine is mounted as:
289 | #
290 | # mount MyEngine, at: '/my_engine'
291 | #
292 | # The router that invoked `devise_for`, in the example above, would be:
293 | # config.router_name = :my_engine
294 | #
295 | # When using OmniAuth, Devise cannot automatically set OmniAuth path,
296 | # so you need to do it manually. For the users scope, it would be:
297 | # config.omniauth_path_prefix = '/my_engine/users/auth'
298 |
299 | # ==> Hotwire/Turbo configuration
300 | # When using Devise with Hotwire/Turbo, the http status for error responses
301 | # and some redirects must match the following. The default in Devise for existing
302 | # apps is `200 OK` and `302 Found respectively`, but new apps are generated with
303 | # these new defaults that match Hotwire/Turbo behavior.
304 | # Note: These might become the new default in future versions of Devise.
305 | config.responder.error_status = :unprocessable_entity
306 | config.responder.redirect_status = :see_other
307 |
308 | # ==> Configuration for :registerable
309 |
310 | # When set to false, does not sign a user in automatically after their password is
311 | # changed. Defaults to true, so a user is signed in automatically after changing a password.
312 | # config.sign_in_after_change_password = true
313 | end
314 |
315 | # rubocop:enable Layout/LineLength
316 |
--------------------------------------------------------------------------------
<%= comment.author.name %> : <%= comment.text %>
30 | <% end %> 31 |