Skip to content

Commit 509bcf2

Browse files
authored
Merge branch 'master' into personal_details
2 parents 1deb20a + 9f2b5f9 commit 509bcf2

31 files changed

+221
-51
lines changed

.DS_Store

2 KB
Binary file not shown.

Gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ git_source(:github) do |repo_name|
55
"https://github.com/#{repo_name}.git"
66
end
77

8-
8+
gem 'orderly'
99
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
1010
gem 'rails', '~> 6.0.0'
1111
# Use postgresql as the database for Active Record

Gemfile.lock

+8
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ GEM
114114
nokogiri (1.11.7)
115115
mini_portile2 (~> 2.5.0)
116116
racc (~> 1.4)
117+
orderly (0.1.1)
118+
capybara (>= 1.1)
119+
rspec (>= 2.14)
117120
orm_adapter (0.5.0)
118121
pg (1.2.3)
119122
public_suffix (4.0.6)
@@ -155,6 +158,10 @@ GEM
155158
responders (3.0.1)
156159
actionpack (>= 5.0)
157160
railties (>= 5.0)
161+
rspec (3.10.0)
162+
rspec-core (~> 3.10.0)
163+
rspec-expectations (~> 3.10.0)
164+
rspec-mocks (~> 3.10.0)
158165
rspec-core (3.10.1)
159166
rspec-support (~> 3.10.0)
160167
rspec-expectations (3.10.1)
@@ -226,6 +233,7 @@ DEPENDENCIES
226233
jbuilder (~> 2.5)
227234
listen (>= 3.0.5, < 3.2)
228235
mimemagic!
236+
orderly
229237
pg
230238
puma (~> 3.12.6)
231239
rails (~> 6.0.0)

app/.DS_Store

0 Bytes
Binary file not shown.

app/assets/.DS_Store

6 KB
Binary file not shown.

app/assets/images/favicon.ico

14.7 KB
Binary file not shown.

app/assets/stylesheets/application.css

+1
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@
1313
*= require_tree .
1414
*= require_self
1515
*/
16+

app/assets/stylesheets/comments.scss

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Place all the styles related to the comments controller here.
2+
// They will automatically be included in application.css.
3+
// You can use Sass (SCSS) here: https://sass-lang.com/
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class CommentsController < ApplicationController
2+
3+
def new
4+
@comment = Comment.new
5+
end
6+
7+
def create
8+
@comment = Comment.create(comment: comments_params["comment"], post_id: id_params)
9+
redirect_to posts_url
10+
end
11+
12+
def index
13+
@comment = Comment.new
14+
end
15+
16+
private
17+
18+
def comments_params
19+
params.require(:comment).permit(:comment)
20+
end
21+
22+
def id_params
23+
params.require(:post_id)
24+
end
25+
end

app/controllers/posts_controller.rb

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
class PostsController < ApplicationController
2+
3+
24
def new
35
@post = Post.new
46
end
@@ -9,12 +11,16 @@ def create
911
end
1012

1113
def index
12-
@posts = Post.all
14+
@post = Post.new
15+
@comment = Comment.new
16+
@posts = Post.all.order(created_at: :desc)
17+
@posts_comments = Comment.all.order(created_at: :desc)
1318
end
1419

1520
def update
16-
p post = Post.find_by(id: id_params)
17-
post.update(likes: (post.likes.to_i + 1 ))
21+
post = Post.find_by(id: id_params)
22+
post.increment(:likes)
23+
post.save
1824
redirect_to posts_url
1925
end
2026

@@ -26,7 +32,7 @@ def post_params
2632
end
2733

2834
def id_params
29-
p params.require(:id)
35+
params.require(:id)
3036
end
31-
3237
end
38+

app/helpers/comments_helper.rb

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
module CommentsHelper
2+
end

app/models/comment.rb

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class Comment < ApplicationRecord
2+
end

app/models/post.rb

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
class Post < ApplicationRecord
2-
32
end
43

app/models/user_sign_in.rb

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
class UserSignIn < ApplicationRecord
2-
# Include default devise modules. Others available are:
3-
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
4-
devise :database_authenticatable, :registerable,
5-
:recoverable, :rememberable, :validatable
6-
end
1+
# class UserSignIn < ApplicationRecord
2+
# # Include default devise modules. Others available are:
3+
# # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
4+
# devise :database_authenticatable, :registerable,
5+
# :recoverable, :rememberable, :validatable
6+
# end
7+
8+
#file not in use

app/views/comments/index.html.erb

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

app/views/layouts/application.html.erb

+3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4+
45
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
56
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
67
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
78
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
9+
<%= favicon_link_tag asset_path('favicon.ico') %>
10+
811
<title>Acebook</title>
912
<%= csrf_meta_tags %>
1013

app/views/posts/hello.html.erb

Whitespace-only changes.

app/views/posts/index.html.erb

+71-26
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,20 @@
88
<!-- Bootstrap CSS -->
99
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
1010

11-
</head>
12-
<body>
11+
</head>
12+
<body>
1313

14-
<nav class="navbar navbar-dark bg-primary">
15-
<div class="container-fluid">
16-
<a class="navbar-brand">Acebook</a>
17-
<form class="d-flex">
18-
<input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
19-
<button class="btn btn-outline-success" type="submit">Search</button>
20-
</form>
21-
</div>
22-
</nav>
14+
<nav class="navbar navbar-dark bg-primary">
15+
<div class="container-fluid">
16+
<a class="navbar-brand">Acebook</a>
17+
<form class="d-flex">
18+
<input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
19+
<button class="btn btn-outline-success" type="submit">Search</button>
20+
</form>
21+
</div>
22+
</nav>
2323

24+
2425
<ul class="nav justify-content-end">
2526
<li class="nav-item">
2627
<a class="nav-link active" aria-current="page" href="#home">Home</a>
@@ -40,14 +41,29 @@
4041
Write a post
4142
<% end %> </p1>
4243

43-
<div id="home" class="center"
44-
<div class="mb-3 offset-4" style="text-align: center;">
45-
<label for="post" class="form-label"> <h4>Whats on your mind?</h4></label>
46-
<textarea class="form-control offset-4" id="exampleFormControlTextarea1" rows="4" style="width: 40rem;"></textarea>
47-
<div class="row">
48-
<br>
44+
45+
46+
<div class="container">
47+
<div class = "row">
48+
<div class="center" style="width: 50rem;">
49+
<div class="form-control offset-4" style="text-align: center;">
50+
<label for="post" class="form-label"> <h4>Whats on your mind?</h4></label>
51+
<%= form_for @post, html: {class: 'form-control offsetWidth-8'} do |form| %>
52+
<%= form.label 'message' %>
53+
<%= form.text_field :message %>
54+
<%= form.submit "Submit" %>
55+
<% end %>
56+
<div class="row">
57+
<br>
58+
</div>
59+
</div>
60+
</div>
61+
4962
</div>
5063
</div>
64+
65+
<div class="row">
66+
<br>
5167
</div>
5268

5369
<% @posts.each do |post| %>
@@ -56,28 +72,57 @@
5672
<div class="card shadow p-3 mb-5 bg-white rounded" style="width: 100rem;">
5773
<div class="card-body">
5874
<h5 class="card-title">Users name</h5>
59-
<h6 class="card-subtitle mb-2 text-muted">26/11/2021</h6>
75+
<h6 class="card-subtitle mb-2 text-muted"><%= post.created_at %></h6>
6076
<p class="card-text"><%= post.message %></p>
61-
62-
63-
64-
6577
<%= button_to (post.likes.to_s + ' Likes'), post_path(post.id), :method => :patch %>
78+
</div>
6679

67-
80+
<%= form_for @comment, html: {class: 'form-control offsetWidth-8'} do |form| %>
81+
<%= form.label 'comment' %>
82+
<%= form.text_field :comment %>
83+
<%= hidden_field_tag :post_id, post.id %>
84+
<%= form.submit "Submit comment" %>
85+
<% end %>
6886

69-
<a href="#" class="card-link">Comment</a>
87+
<div class="row">
88+
<br>
7089
</div>
71-
</div>
90+
91+
<% @posts_comments.each do |comments| %>
92+
<% if comments.post_id == post.id %>
93+
<div class="container">
94+
<div class ="row">
95+
<div class="card" style="width: 30rem;">
96+
<p> User Name </p>
97+
<%= comments.created_at %> <br>
98+
<%= comments.comment %>
99+
<div class="row">
100+
<br>
101+
</div>
102+
</div>
103+
</div>
104+
</div>
105+
<% end %>
106+
<div class="row">
107+
<br>
108+
</div>
109+
<% end %>
110+
72111
<div class="row">
73112
<br>
74113
</div>
114+
</div>
115+
116+
<div class="row">
117+
<br>
118+
</div>
119+
75120
</div>
76121
</div>
77122
<% end %>
78123

79-
80124
</body>
81125
</html>
82126
</div>
83127

128+

app/views/posts/new.html.erb

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
<body>
1313

1414

15+
16+
17+
18+
1519
<%= form_for @post do |form| %>
1620
<%= form.label :message %>
1721
<%= form.text_field :message %>

app/views/posts/show.html.erb

Whitespace-only changes.

config/routes.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
resources :sessions
99
resources :users
1010
resources :posts
11-
11+
resources :comments
1212
end

db/migrate/20170526114520_create_posts.rb

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ def change
33
create_table :posts do |t|
44
t.string :message
55
t.timestamps
6-
76
end
87
end
98
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class NewCommentTable < ActiveRecord::Migration[6.0]
2+
def change
3+
create_table :comments do |t|
4+
t.integer :user_id
5+
t.integer :post_id
6+
t.string :comment
7+
t.timestamps
8+
end
9+
end
10+
end

db/schema.rb

+12
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212

1313
ActiveRecord::Schema.define(version: 2021_11_30_115933) do
1414

15+
16+
17+
1518
# These are extensions that must be enabled in order to support this database
1619
enable_extension "plpgsql"
1720

@@ -30,6 +33,14 @@
3033
t.integer "likes"
3134
end
3235

36+
create_table "user_log_ins", force: :cascade do |t|
37+
t.string "email", null: false
38+
t.string "password_digest"
39+
t.datetime "created_at", precision: 6, null: false
40+
t.datetime "updated_at", precision: 6, null: false
41+
t.string "name"
42+
end
43+
3344
create_table "user_sign_ins", force: :cascade do |t|
3445
t.string "email", default: "", null: false
3546
t.string "encrypted_password", default: "", null: false
@@ -57,4 +68,5 @@
5768
t.datetime "updated_at", precision: 6, null: false
5869
end
5970

71+
add_foreign_key "comments", "posts"
6072
end

spec/features/user_can_submit_posts_spec.rb

+12-4
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,26 @@
33
RSpec.feature "Timeline", type: :feature do
44
scenario "Can submit posts and view them" do
55
visit "/posts"
6-
click_link "New post"
76
fill_in "Message", with: "Hello, world!"
87
click_button "Submit"
98
expect(page).to have_content("Hello, world!")
109
end
1110

1211
scenario "User can like a post" do
1312
visit "/posts"
14-
click_link "New post"
13+
1514
fill_in "Message", with: "Hello, world!"
1615
click_button "Submit"
17-
click_button ("Hello, world!")
18-
expect(page).to have_content("1 Like")
16+
click_button ("Likes")
17+
expect(page).to have_button("1 Likes")
1918
end
19+
20+
scenario 'Posts are displayed in descending order' do
21+
visit '/posts'
22+
fill_in "Message", with: "First post"
23+
click_button "Submit"
24+
fill_in "Message", with: "Second post"
25+
click_button "Submit"
26+
expect('Second post').to appear_before('First post')
27+
end
2028
end

0 commit comments

Comments
 (0)