From 67204843cd027f60656c01d5879dbd94433144f5 Mon Sep 17 00:00:00 2001 From: Evans Sitibekiso Date: Sat, 30 Jul 2022 15:07:05 +0200 Subject: [PATCH 01/32] create new html file for comments --- app/controllers/comments_controller.rb | 29 ++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 app/controllers/comments_controller.rb diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb new file mode 100644 index 0000000..1ae46ca --- /dev/null +++ b/app/controllers/comments_controller.rb @@ -0,0 +1,29 @@ +class CommentsController < ApplicationController + def new + @comment = Comment.new + @user = current_user + end + + def create + @post = Post.find(params[:post_id] || params[:id]) + @comment = Comment.new(comment_params) + @comment.author_id = current_user.id + @comment.post = @post + + respond_to do |format| + if @comment.save! + format.html do + redirect_to user_post_url(current_user, @post), notice: 'Comment was successfully created.' + end + else + format.html { render :new, status: :unprocessable_entity } + end + end + end + + private + + def comment_params + params.require(:comment).permit(:text) + end + end \ No newline at end of file From c30a087bacb1ccbbc071831356db44409bdd4ae6 Mon Sep 17 00:00:00 2001 From: Evans Sitibekiso Date: Sat, 30 Jul 2022 15:11:12 +0200 Subject: [PATCH 02/32] Create likes_controller.rb --- app/controllers/likes_controller.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 app/controllers/likes_controller.rb diff --git a/app/controllers/likes_controller.rb b/app/controllers/likes_controller.rb new file mode 100644 index 0000000..61e1764 --- /dev/null +++ b/app/controllers/likes_controller.rb @@ -0,0 +1,20 @@ +class LikesController < ApplicationController + def new + @like = Like.new + @user = current_user + end + + def create + @post = Post.find(params[:post_id] || params[:id]) + @like = Like.new(post_id: @post.id, author_id: current_user.id) + @like.author_id = current_user.id + + respond_to do |format| + if @like.save + format.html { redirect_to user_post_url(current_user, @post), notice: 'Like was successfully created.' } + else + format.html { render :new, status: :unprocessable_entity } + end + end + end + end \ No newline at end of file From 18c6f44a963c664ca7dd45d9812b5924b2aac7d5 Mon Sep 17 00:00:00 2001 From: Evans Sitibekiso Date: Sat, 30 Jul 2022 15:19:12 +0200 Subject: [PATCH 03/32] Create post_params private method in posts_controller.rb --- app/controllers/posts_controller.rb | 36 +++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 722bbd0..da511fa 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -1,10 +1,42 @@ + + class PostsController < ApplicationController + before_action :set_post, only: %i[show edit update destroy] + def index - @user = User.find(params[:user_id]) + @user = current_user @posts = @user.posts end def show @post = Post.find(params[:id]) end -end + + def new + @post = Post.new + @user = current_user + end + + def create + @post = Post.new(post_params) + @post.author_id = current_user.id + + respond_to do |format| + if @post.save + format.html { redirect_to user_post_url(current_user, @post), notice: 'Post was successfully created.' } + else + format.html { render :new, status: :unprocessable_entity } + end + end + end + + private + + def set_post + @post = Post.find(params[:id]) + end + + def post_params + params.require(:post).permit(:title, :text, :comments_counter, :likes_counter) + end +end \ No newline at end of file From 63f0ce6ff2f08e6421c6dd2cf3ff30f836343bb5 Mon Sep 17 00:00:00 2001 From: Evans Sitibekiso Date: Sat, 30 Jul 2022 15:36:51 +0200 Subject: [PATCH 04/32] create new html file for comment --- app/models/post.rb | 6 +++--- app/models/user.rb | 4 ++-- app/views/comments/new.html.erb | 14 ++++++++++++++ 3 files changed, 19 insertions(+), 5 deletions(-) create mode 100644 app/views/comments/new.html.erb diff --git a/app/models/post.rb b/app/models/post.rb index 21254b2..92c0cd1 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -4,8 +4,8 @@ class Post < ApplicationRecord validates :likes_counter, numericality: { only_integer: true, greater_than_or_equal_to: 0 } belongs_to :author, class_name: 'User' - has_many :comments, class_name: 'Comment', foreign_key: 'post_id' - has_many :likes, class_name: 'Like', foreign_key: 'post_id' + has_many :comments, foreign_key: 'post_id' + has_many :likes, foreign_key: 'post_id' after_save :update_posts_counter @@ -18,4 +18,4 @@ def recent_comments def update_posts_counter author.increment!(:posts_counter) end -end +end \ No newline at end of file diff --git a/app/models/user.rb b/app/models/user.rb index 4d30401..39bf5c3 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -4,9 +4,9 @@ class User < ApplicationRecord has_many :posts, foreign_key: 'author_id' has_many :comments, foreign_key: 'author_id' - has_many :likes, class_name: 'like', foreign_key: 'author_id' + has_many :likes, foreign_key: 'author_id' def recent_posts posts.order(created_at: :desc).limit(3) end -end +end \ No newline at end of file diff --git a/app/views/comments/new.html.erb b/app/views/comments/new.html.erb new file mode 100644 index 0000000..c8635e0 --- /dev/null +++ b/app/views/comments/new.html.erb @@ -0,0 +1,14 @@ +
+

Add New Comment :

+ <%= form_with model: @comment, url: user_post_comments_path, method: :post, local: true, class: "form-control" do |form| %> + +
+ <%= form.label :text %> + <%= form.text_area :text, placeholder: "Type your comment here!", rows: 20, required: true, class: "form-post-text" %> +
+ +
+ <%= form.submit "Save", class: "button" %> +
+ <% end %> +
\ No newline at end of file From fc1a8540b199a05836d50cdb818c0803db6794fa Mon Sep 17 00:00:00 2001 From: Evans Sitibekiso Date: Sat, 30 Jul 2022 15:39:51 +0200 Subject: [PATCH 05/32] Create new html file for like and update show html file in posts --- app/views/likes/new.html.erb | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 app/views/likes/new.html.erb diff --git a/app/views/likes/new.html.erb b/app/views/likes/new.html.erb new file mode 100644 index 0000000..7649c46 --- /dev/null +++ b/app/views/likes/new.html.erb @@ -0,0 +1,5 @@ +
+ <%= form_with(model: @like, url: user_post_likes_path) do |form| %> + <%= form.submit 'Add Like', class: "button" %> + <% end %> +
\ No newline at end of file From f08265aa393e6b0ec78968c648ad06b08b0e4bc9 Mon Sep 17 00:00:00 2001 From: Evans Sitibekiso Date: Sat, 30 Jul 2022 15:49:50 +0200 Subject: [PATCH 06/32] Create new html file and update show html file in posts --- app/views/posts/index.html.erb | 1 + app/views/posts/new.html.erb | 23 +++++++++++++++++++++++ app/views/posts/show.html.erb | 6 +++++- 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 app/views/posts/new.html.erb diff --git a/app/views/posts/index.html.erb b/app/views/posts/index.html.erb index 60fdccc..1107702 100644 --- a/app/views/posts/index.html.erb +++ b/app/views/posts/index.html.erb @@ -33,6 +33,7 @@ <% end %>
+ <%= button_to 'Add New Post', new_user_post_url(id: @user.id), method: :get, class: "button"%> diff --git a/app/views/posts/new.html.erb b/app/views/posts/new.html.erb new file mode 100644 index 0000000..0bb4a1b --- /dev/null +++ b/app/views/posts/new.html.erb @@ -0,0 +1,23 @@ + + +
+

Add New Post :

+ <%= form_with model: @post, url: user_posts_path, method: :post, local: true, class: "form-control" do |form| %> + <%= form.hidden_field :comments_counter, value: 0 %> + <%= form.hidden_field :likes_counter, value: 0 %> + +
+ <%= form.label :title %> + <%= form.text_field :title, placeholder: "Title", required: true, class: "form-post-title" %> +
+ +
+ <%= form.label :text %> + <%= form.text_area :text, placeholder: "Type your post here!", rows: 20, required: true, class: "form-post-text" %> +
+ +
+ <%= form.submit "Save", class: "button" %> +
+ <% end %> +
\ No newline at end of file diff --git a/app/views/posts/show.html.erb b/app/views/posts/show.html.erb index 077f30a..619d365 100644 --- a/app/views/posts/show.html.erb +++ b/app/views/posts/show.html.erb @@ -19,5 +19,9 @@

<% end %> - + +
+ <%= button_to "Add Comment", new_user_post_comment_path(@post.author, @post), method: :get, class: "button" %> + <%= button_to "Add Like", new_user_post_like_path(@post.author, @post), method: :get, class: "button" %> +
\ No newline at end of file From afa087e2bfd58545fff503544b5ff48c88699c42 Mon Sep 17 00:00:00 2001 From: Evans Sitibekiso Date: Sat, 30 Jul 2022 15:56:03 +0200 Subject: [PATCH 07/32] Update routes to include new and create actions --- app/assets/stylesheets/user_style.css | 13 +++++++++---- config/routes.rb | 6 ++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/app/assets/stylesheets/user_style.css b/app/assets/stylesheets/user_style.css index 79e0f7a..0bfb06e 100644 --- a/app/assets/stylesheets/user_style.css +++ b/app/assets/stylesheets/user_style.css @@ -150,7 +150,11 @@ a { } .button-user { - text-align: center; + display: flex; + justify-content: center; + align-items: center; + + /* text-align: center; */ } .text-button { @@ -162,14 +166,15 @@ a { background-color: #2f4858; border: none; color: white; - padding: 10px 20px; + padding: 15px 20px; text-align: center; text-decoration: none; display: inline-block; font-size: 16px; - margin: 4px 2px; + margin: 10px; cursor: pointer; border-radius: 4px; + width: 150px; } .post-info, @@ -188,4 +193,4 @@ a { justify-content: space-between; align-items: flex-start; width: 100%; -} +} \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 30537c4..4d98a1a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,7 +1,9 @@ Rails.application.routes.draw do root 'users#index' resources :users, only: [:index, :show] do - resources :posts, only: [:index, :show] + resources :posts, only: [:index, :show, :new, :create] do + resources :comments, only: [:new, :create] + resources :likes, only: [:new, :create] + end end end - From 0e5d44bfb19c0a508dcb2b6c64b73e3e60b872b9 Mon Sep 17 00:00:00 2001 From: Evans Sitibekiso Date: Sat, 30 Jul 2022 16:02:58 +0200 Subject: [PATCH 08/32] resolve linter errors --- app/assets/stylesheets/user_style.css | 2 +- app/controllers/comments_controller.rb | 50 +++++++++++++------------- app/controllers/likes_controller.rb | 34 +++++++++--------- app/controllers/posts_controller.rb | 4 +-- app/models/post.rb | 2 +- app/models/user.rb | 2 +- 6 files changed, 46 insertions(+), 48 deletions(-) diff --git a/app/assets/stylesheets/user_style.css b/app/assets/stylesheets/user_style.css index 0bfb06e..52bd724 100644 --- a/app/assets/stylesheets/user_style.css +++ b/app/assets/stylesheets/user_style.css @@ -193,4 +193,4 @@ a { justify-content: space-between; align-items: flex-start; width: 100%; -} \ No newline at end of file +} diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 1ae46ca..4dbb215 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -1,29 +1,29 @@ class CommentsController < ApplicationController - def new - @comment = Comment.new - @user = current_user - end - - def create - @post = Post.find(params[:post_id] || params[:id]) - @comment = Comment.new(comment_params) - @comment.author_id = current_user.id - @comment.post = @post - - respond_to do |format| - if @comment.save! - format.html do - redirect_to user_post_url(current_user, @post), notice: 'Comment was successfully created.' - end - else - format.html { render :new, status: :unprocessable_entity } + def new + @comment = Comment.new + @user = current_user + end + + def create + @post = Post.find(params[:post_id] || params[:id]) + @comment = Comment.new(comment_params) + @comment.author_id = current_user.id + @comment.post = @post + + respond_to do |format| + if @comment.save! + format.html do + redirect_to user_post_url(current_user, @post), notice: 'Comment was successfully created.' end + else + format.html { render :new, status: :unprocessable_entity } end end - - private - - def comment_params - params.require(:comment).permit(:text) - end - end \ No newline at end of file + end + + private + + def comment_params + params.require(:comment).permit(:text) + end +end diff --git a/app/controllers/likes_controller.rb b/app/controllers/likes_controller.rb index 61e1764..39a16b2 100644 --- a/app/controllers/likes_controller.rb +++ b/app/controllers/likes_controller.rb @@ -1,20 +1,20 @@ class LikesController < ApplicationController - def new - @like = Like.new - @user = current_user - end - - def create - @post = Post.find(params[:post_id] || params[:id]) - @like = Like.new(post_id: @post.id, author_id: current_user.id) - @like.author_id = current_user.id - - respond_to do |format| - if @like.save - format.html { redirect_to user_post_url(current_user, @post), notice: 'Like was successfully created.' } - else - format.html { render :new, status: :unprocessable_entity } - end + def new + @like = Like.new + @user = current_user + end + + def create + @post = Post.find(params[:post_id] || params[:id]) + @like = Like.new(post_id: @post.id, author_id: current_user.id) + @like.author_id = current_user.id + + respond_to do |format| + if @like.save + format.html { redirect_to user_post_url(current_user, @post), notice: 'Like was successfully created.' } + else + format.html { render :new, status: :unprocessable_entity } end end - end \ No newline at end of file + end +end diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index da511fa..d69b9d9 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -1,5 +1,3 @@ - - class PostsController < ApplicationController before_action :set_post, only: %i[show edit update destroy] @@ -39,4 +37,4 @@ def set_post def post_params params.require(:post).permit(:title, :text, :comments_counter, :likes_counter) end -end \ No newline at end of file +end diff --git a/app/models/post.rb b/app/models/post.rb index 92c0cd1..d03e3bd 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -18,4 +18,4 @@ def recent_comments def update_posts_counter author.increment!(:posts_counter) end -end \ No newline at end of file +end diff --git a/app/models/user.rb b/app/models/user.rb index 39bf5c3..cc6a244 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -9,4 +9,4 @@ class User < ApplicationRecord def recent_posts posts.order(created_at: :desc).limit(3) end -end \ No newline at end of file +end From 3fbadb92e7b606622f50d40d62228878c37d07c3 Mon Sep 17 00:00:00 2001 From: Evans Sitibekiso Date: Sat, 30 Jul 2022 16:59:22 +0200 Subject: [PATCH 09/32] Update changes in readmile file --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 79766e4..ab6209e 100644 --- a/README.md +++ b/README.md @@ -192,4 +192,4 @@ Give a ⭐️ if you like this project! ## 📝 License -This project is [MIT](./MIT.md) licensed. +This project is [MIT](https://github.com/microverseinc/readme-template/blob/master/MIT.md) licensed. From 03bcc944a17399ac4b5f78424162df1a418a8eb2 Mon Sep 17 00:00:00 2001 From: Evans Sitibekiso Date: Mon, 1 Aug 2022 14:40:06 +0200 Subject: [PATCH 10/32] Add test for posts_index_spec.rb --- app/assets/images/margaret.jpeg | Bin 0 -> 6845 bytes app/controllers/posts_controller.rb | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 app/assets/images/margaret.jpeg diff --git a/app/assets/images/margaret.jpeg b/app/assets/images/margaret.jpeg new file mode 100644 index 0000000000000000000000000000000000000000..afae880597f0f11a6b8842f26fcce7ff7174487c GIT binary patch literal 6845 zcmbVwXIN8Px9&i{4S2)IeU zfjN*JlF?41megd9uln4Zyg2+`8ov z;)wAI^mTR&lf*cZ-!~0h0qCh|XlbbEX=!QCG0-!@FS5Xync)a-9=3~8N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$IQN4ZEl*(-slgUBs6U06H5?8a3e27&g+Xixt=DlTW#W3%e+)F#dj7O z?|;$DxO}P&gwJ;5y_|Z_cTl0y!GU4R%aR`$r}>-^JZ^>d3|2T!+Dnl{9jJ8}D?H<> z>*vIU;DLSZI_Wev(l+xb+icyc2#e4_&h0j;RxZn;1kb8=mIl6k6xZ^0_4J2TSMw}V zaYkqEJ0I!sH}p;)d01~Mvve2GbE;rUiLgzpFw+Yfnr7>DFvDS&M*l}I?yKp}7#o+C z)hWEXu_4{PW{a3s`n`KV@?{KL_jq_qdUH#y1cJ+UvgA4BR`)$59Tu5@jPH4Puh`@g z@(BzUsq^^9={Oa!L}pFWcZZdM({Zs;lisd^`{5CvIL}&Gvel5~1%~HmdGj``lyM0B zxqsQ(U~<(58cU-oIAIa2HZU7+i@c+wp-g0a(Q}4(f^$CBLkv<*C<~VQz`EQAJ zsLH;GblUWrlSz+tafVckj5p(l_vp1Q`gneg~QqtVLQtYZl}&h$JUWozS>wwy!$zL3yb3E%J&M++IcQ8T{j6% z+Etu0`^^$vpz|r9d*}64?{^9Q;X)_tjUO&ZCFci^1EgHOcxMR!`y1JGB4+BvIC2Hbtz+TONTz>ec+L`B^}q8_5|Kpq|eKpq!+2IycNIkEw=hz8Rz%6_GdTU9 zb1;(~1U>u0GhL2aSPiOe&|cM3Kt9Mnf+~&e|McFrHu7|N@Y)be`$hkf^>o+Ardr-Y zY(cWVn&(kv#L+adR|+qMeDHVSIt#;pnIVc=TY^m5-&~zVt3i4YttvhrkOt=yDe|5f zk%#oZgP5Ge Date: Mon, 1 Aug 2022 17:18:43 +0200 Subject: [PATCH 11/32] Add test --- app/views/posts/show.html.erb | 7 ++++++- config/database.yml | 14 ++++++++++---- config/environments/development.rb | 10 +++++++++- config/environments/test.rb | 5 +++-- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/app/views/posts/show.html.erb b/app/views/posts/show.html.erb index 619d365..f8dd84e 100644 --- a/app/views/posts/show.html.erb +++ b/app/views/posts/show.html.erb @@ -21,7 +21,12 @@ <% end %>
+ <%= button_to "Back", user_path(@post.author, @post), method: :get, class: "button" %> <%= button_to "Add Comment", new_user_post_comment_path(@post.author, @post), method: :get, class: "button" %> - <%= button_to "Add Like", new_user_post_like_path(@post.author, @post), method: :get, class: "button" %> +
+ <%= form_with model: @like, url: "/users/#{params['user_id']}/posts/#{params['id']}/likes", method: :post , local: true do |form|%> + <%= form.submit "Like", class: 'button' %> + <% end %> +
\ No newline at end of file diff --git a/config/database.yml b/config/database.yml index 2c208ea..7580899 100644 --- a/config/database.yml +++ b/config/database.yml @@ -1,3 +1,5 @@ + + # PostgreSQL. Versions 9.3 and up are supported. # # Install the pg driver: @@ -17,8 +19,8 @@ default: &default adapter: postgresql encoding: unicode - # username: postgres - # password: 2022 + username: postgres + password: 1993 # For details on connection pooling, see Rails configuration guide # https://guides.rubyonrails.org/configuring.html#database-pooling pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> @@ -26,6 +28,8 @@ default: &default development: <<: *default database: blog_app_development + username: postgres + password: 1993 # The specified database role being used to connect to postgres. # To create additional roles in postgres see `$ createuser --help`. @@ -60,6 +64,8 @@ development: test: <<: *default database: blog_app_test + username: postgres + password: 1993 # As with config/credentials.yml, you never want to store sensitive information, # like your database password, in your source code. If your source code is @@ -84,5 +90,5 @@ test: production: <<: *default database: blog_app_production - username: blog_app - password: <%= ENV["BLOG_APP_DATABASE_PASSWORD"] %> + username: postgres + password: 1993 diff --git a/config/environments/development.rb b/config/environments/development.rb index 8500f45..b7ce798 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -1,6 +1,14 @@ require "active_support/core_ext/integer/time" Rails.application.configure do + config.after_initialize do + Bullet.enable = true + Bullet.bullet_logger = true + Bullet.console = true + Bullet.rails_logger = true + Bullet.add_footer = true + end + # Settings specified here will take precedence over those in config/application.rb. # In the development environment your application's code is reloaded any time @@ -67,4 +75,4 @@ # Uncomment if you wish to allow Action Cable access from any origin. # config.action_cable.disable_request_forgery_protection = true -end +end \ No newline at end of file diff --git a/config/environments/test.rb b/config/environments/test.rb index 6ea4d1e..a4ecda5 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -6,6 +6,7 @@ # and recreated between test runs. Don't rely on the data there! Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. # Turn false under Spring and add config.action_view.cache_template_loading = true. @@ -23,7 +24,7 @@ } # Show full error reports and disable caching. - config.consider_all_requests_local = true + config.consider_all_requests_local = true config.action_controller.perform_caching = false config.cache_store = :null_store @@ -57,4 +58,4 @@ # Annotate rendered view with file names. # config.action_view.annotate_rendered_view_with_filenames = true -end +end \ No newline at end of file From f7abefc6a305b89840627ffe7ee009f4bcbde06a Mon Sep 17 00:00:00 2001 From: Evans Sitibekiso Date: Mon, 1 Aug 2022 17:39:42 +0200 Subject: [PATCH 12/32] fix n+1 and posts tests --- db/seeds.rb | 54 ++++++++++++++++++- spec/integration/posts_index_spec.rb | 77 ++++++++++++++++++++++++++++ spec/integration/posts_show_spec.rb | 62 ++++++++++++++++++++++ spec/integration/user_index_spec.rb | 35 +++++++++++++ spec/integration/user_show_spec.rb | 46 +++++++++++++++++ 5 files changed, 273 insertions(+), 1 deletion(-) create mode 100644 spec/integration/posts_index_spec.rb create mode 100644 spec/integration/posts_show_spec.rb create mode 100644 spec/integration/user_index_spec.rb create mode 100644 spec/integration/user_show_spec.rb diff --git a/db/seeds.rb b/db/seeds.rb index 1b303fe..e93cd7d 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1,3 +1,5 @@ + + # This file should contain all the record creation needed to seed the database with its default values. # The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup). # @@ -5,4 +7,54 @@ # # movies = Movie.create([{ name: "Star Wars" }, { name: "Lord of the Rings" }]) # Character.create(name: "Luke", movie: movies.first) -User.create(name: "test", photo: "image.jpg", bio: "good person", posts_counter: 0) +# This file should contain all the record creation needed to seed the database with its default values. +# The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup). +# +# Examples: +# +# movies = Movie.create([{ name: "Star Wars" }, { name: "Lord of the Rings" }]) +# Character.create(name: "Luke", movie: movies.first) + +mohammed = User.create!( + name: 'mohammed', + photo: 'https://dummyimage.com/600x400/000/fff', + bio: 'Lorem ipsum dolor sit amet, + consectetur adipiscing elit. Pellentesque nulla nunc, + lacinia sed volutpat ut, tristique et tortor. + Proin a nulla lorem. Duis ac nunc lectus. Ut non felis id elit tempor gravida. + Aenean varius sem vel tellus elementum, + in eleifend mauris eleifend. Donec at tempor libero, + et maximus magna. Nulla vehicula convallis nulla. + Duis arcu turpis, egestas ultrices est at, scelerisque lobortis est.', + posts_counter: 0) + + tom = User.create!( + name: 'tom', + photo: 'https://dummyimage.com/600x400/000/fff', + bio: 'Lorem ipsum dolor sit amet, + consectetur adipiscing elit. Pellentesque nulla nunc, + lacinia sed volutpat ut, tristique et tortor. + Proin a nulla lorem. Duis ac nunc lectus. Ut non felis id elit tempor gravida. + Aenean varius sem vel tellus elementum, + in eleifend mauris eleifend. Donec at tempor libero, + et maximus magna. Nulla vehicula convallis nulla. + Duis arcu turpis, egestas ultrices est at, scelerisque lobortis est.', + posts_counter: 0) + + post1 = mohammed.posts.create!(title: 'Ruby and Rails 1', text: 'this is first post about Ruby and Rails! 1', comments_counter: 0, likes_counter: 0) + post2 = mohammed.posts.create!(title: 'Ruby and Rails 2', text: 'this is first post about Ruby and Rails! 2', comments_counter: 0, likes_counter: 0) + post3 = mohammed.posts.create!(title: 'Ruby and Rails 3', text: 'this is first post about Ruby and Rails! 3', comments_counter: 0, likes_counter: 0) + post4 = mohammed.posts.create!(title: 'Ruby and Rails 4', text: 'this is first post about Ruby and Rails! 4', comments_counter: 0, likes_counter: 0) + post5 = mohammed.posts.create!(title: 'Ruby and Rails 5', text: 'this is first post about Ruby and Rails! 5', comments_counter: 0, likes_counter: 0) + post6 = tom.posts.create!(title: 'Never ending fun', text: 'this is second post but I don\'t think I should create another post again', comments_counter: 0, likes_counter: 0) + post7 = tom.posts.create!(title: 'The end of the world', text: 'it all around the corner', comments_counter: 0, likes_counter: 0) + + mohammed.comments.create!(text: 'really nice post Michael', post: post1) + mohammed.comments.create!(text: 'Absolutely amazing 1', post: post1) + mohammed.comments.create!(text: 'Absolutely amazing 2', post: post1) + mohammed.comments.create!(text: 'Absolutely amazing 3', post: post1) + mohammed.comments.create!(text: 'Absolutely amazing 4', post: post1) + mohammed.comments.create!(text: 'Absolutely amazing 5', post: post1) + tom.comments.create!(text: 'Well Done 👏👏👏', post: post1) + tom.comments.create!(text: 'Love 💓 it!!!', post: post1) + tom.comments.create!(text: 'I am with you to the bone man!', post: post1) \ No newline at end of file diff --git a/spec/integration/posts_index_spec.rb b/spec/integration/posts_index_spec.rb new file mode 100644 index 0000000..755ff13 --- /dev/null +++ b/spec/integration/posts_index_spec.rb @@ -0,0 +1,77 @@ +require 'rails_helper' + +RSpec.describe 'posts#index', type: :feature do + describe 'Post' do + before(:each) do + @user1 = User.create(name: 'Margaret', photo: 'margaret.jpeg', bio: 'bio', posts_counter: 0) + @user1.save! + visit root_path + + @post1 = Post.create(title: 'First Post', text: 'This is my first post', comments_counter: 0, likes_counter: 0, + author: @user1) + @post2 = Post.create(title: 'Second Post', text: 'This is my second post', comments_counter: 0, likes_counter: 0, + author: @user1) + @post3 = Post.create(title: 'Third Post', text: 'This is my third post', comments_counter: 0, likes_counter: 0, + author: @user1) + @comment1 = Comment.create(text: 'Comment 1!', author: User.first, + post: Post.first) + @comment2 = Comment.create(text: 'Comment 2!', author: User.first, post: Post.first) + @comment3 = Comment.create(text: 'Comment 2!', author: User.first, post: Post.first) + end + + it "shows user's profile picture" do + visit(user_posts_path(@user1.id)) + expect(page).to have_css('img[src*="margaret.jpeg"]') + end + + it 'shows the users username' do + visit(user_posts_path(@user1.id)) + expect(page).to have_content('Margaret') + end + + it 'shows number of posts of user has written' do + visit(user_posts_path(@user1.id)) + post = Post.all + expect(post.size).to eql(3) + end + + it 'shows number of posts by user' do + visit(user_posts_path(@user1.id)) + user = User.first + expect(page).to have_content(user.posts_counter) + end + + it 'shows posts title' do + visit(user_posts_path(@user1.id)) + expect(page).to have_content('First Post') + end + + it 'can see some of the post detail' do + visit(user_posts_path(@user1.id)) + expect(page).to have_content 'This is my first post' + end + + it 'can see the first comment on a post' do + visit(user_posts_path(@user1.id)) + expect(page).to have_content 'Comment 1' + end + + it 'can see how many comments a post has.' do + visit(user_posts_path(@user1.id)) + post = Post.first + expect(page).to have_content(post.comments_counter) + end + + it 'can see how many likes a post has.' do + visit(user_posts_path(@user1.id)) + post = Post.first + expect(page).to have_content(post.likes_counter) + end + + it "redirects the user to the post's show page after clickin on it" do + visit(user_posts_path(@user1.id)) + click_link 'First Post' + expect(page).to have_current_path user_post_path(@post1.author_id, @post1) + end + end +end \ No newline at end of file diff --git a/spec/integration/posts_show_spec.rb b/spec/integration/posts_show_spec.rb new file mode 100644 index 0000000..0a74a6d --- /dev/null +++ b/spec/integration/posts_show_spec.rb @@ -0,0 +1,62 @@ +require 'rails_helper' + +RSpec.describe 'Post show', type: :feature do + describe 'Post' do + before(:each) do + @first_user = User.create(name: 'Tom', photo: 'margaret.jpeg', bio: 'Teacher from Mexico.', posts_counter: 0) + @first_user.save! + @second_user = User.create(name: 'Lilly', photo: 'margaret.jpeg', bio: 'Teacher from Poland.', posts_counter: 0) + @second_user.save! + visit root_path + + @first_post = Post.create(author: @first_user, title: 'Hello', text: 'This is my first post', + comments_counter: 0, likes_counter: 0) + @second_post = Post.create(author: @first_user, title: 'Hello, again', text: 'This is my second post', + comments_counter: 0, likes_counter: 0) + @third_post = Post.create(author: @second_user, title: 'Hello', text: 'This is my first post', + comments_counter: 0, likes_counter: 0) + @fourth_post = Post.create(author: @second_user, title: 'Hello, again', text: 'This is my second post', + comments_counter: 0, likes_counter: 0) + + @comment1 = Comment.create(post: Post.first, author: User.first, text: 'Hi Tom!') + @comment2 = Comment.create(post: Post.first, author: User.first, text: 'Hi Tom Again!') + @comment3 = Comment.create(post: Post.first, author: User.first, text: 'Hi Tom Again twice!') + + visit user_post_path(@first_user, @first_post) + end + + it 'shows posts title' do + expect(page).to have_content('Hello') + end + + it 'shows the person who wrote the post' do + expect(page).to have_content('Tom') + end + + it 'shows number of comments' do + post = Post.first + expect(page).to have_content(post.comments_counter) + end + + it 'shows number of likes' do + post = Post.first + expect(page).to have_content(post.likes_counter) + end + + it 'can see the post\'s body.' do + expect(page).to have_content('Hi Tom!') + end + + it 'can see the username of each commentor.' do + post = Post.first + comment = post.comments.first + expect(page).to have_content(comment.author.name) + end + + it 'can see the comments of each commentor.' do + expect(page).to have_content 'Hi Tom!' + expect(page).to have_content 'Hi Tom Again!' + expect(page).to have_content 'Hi Tom Again twice!' + end + end +end \ No newline at end of file diff --git a/spec/integration/user_index_spec.rb b/spec/integration/user_index_spec.rb new file mode 100644 index 0000000..bfcbf68 --- /dev/null +++ b/spec/integration/user_index_spec.rb @@ -0,0 +1,35 @@ +require 'rails_helper' + +RSpec.describe 'Test Index Page', type: :feature do + describe 'GET index' do + before(:each) do + @first_user = User.create(name: 'Mohammed', photo: 'image1.png', bio: 'bio1', posts_counter: 1) + @first_user.save! + @second_user = User.create(name: 'Ahmed', photo: 'image2.png', bio: 'bio2', posts_counter: 3) + @second_user.save! + @third_user = User.create(name: 'Marwan', photo: 'image3.png', bio: 'bio3', posts_counter: 5) + @third_user.save! + end + + it 'shows the users username' do + visit root_path + expect(page).to have_content('Mohammed') + expect(page).to have_content('Ahmed') + expect(page).to have_content('Marwan') + end + + it 'shows the users profile picture' do + visit root_path + expect(page).to have_css('img[src*="image1.png"]') + expect(page).to have_css('img[src*="image2.png"]') + expect(page).to have_css('img[src*="image3.png"]') + end + + it 'shows the number of posts of each user' do + visit root_path + expect(page).to have_content('1') + expect(page).to have_content('3') + expect(page).to have_content('5') + end + end +end \ No newline at end of file diff --git a/spec/integration/user_show_spec.rb b/spec/integration/user_show_spec.rb new file mode 100644 index 0000000..34e71a0 --- /dev/null +++ b/spec/integration/user_show_spec.rb @@ -0,0 +1,46 @@ +require 'rails_helper' + +RSpec.describe 'Test Show user Page', type: :feature do + describe 'GET Show' do + before(:each) do + @user = User.create(name: 'Mohammed', photo: 'image1.png', bio: 'bio1', posts_counter: 0) + @user.save! + @first_post = Post.create(author: @user, title: 'My first post', text: 'post1 text', + comments_counter: 0, likes_counter: 0, id: 1) + @second_post = Post.create(author: @user, title: 'My second post', text: 'post2 text', + comments_counter: 0, likes_counter: 0, id: 2) + @third_post = Post.create(author: @user, title: 'My third post', text: 'post3 text', + comments_counter: 0, likes_counter: 0, id: 3) + @fourth_post = Post.create(author: @user, title: 'My last post', + text: 'last post text', comments_counter: 0, likes_counter: 0, id: 4) + + visit(user_path(id: @user.id)) + end + + it 'shows the user username' do + expect(page).to have_content('Mohammed') + end + + it 'shows the user profile picture' do + expect(page).to have_css('img[src*="image1.png"]') + end + + it 'shows the user bio' do + expect(page).to have_content('bio1') + end + + it 'shows the number of posts the user has written' do + expect(page).to have_content('4') + end + + it 'shows all the posts the user has written' do + expect(page).to have_content('My last post') + expect(page).to have_content('My third post') + expect(page).to have_content('My second post') + end + + it 'should have button to show all posts' do + expect(page).to have_link('See all posts') + end + end +end \ No newline at end of file From a6256108e4941b4287497f9a34bc932cb52a32ed Mon Sep 17 00:00:00 2001 From: Evans Sitibekiso Date: Mon, 1 Aug 2022 17:59:43 +0200 Subject: [PATCH 13/32] n+1 and add tests --- .idea/.gitignore | 8 + .idea/blog-app.iml | 561 +++++++++++++++++++ .idea/dataSources.xml | 32 ++ .idea/inspectionProfiles/Project_Default.xml | 6 + .idea/misc.xml | 4 + .idea/modules.xml | 8 + .idea/vcs.xml | 6 + Gemfile | 7 +- Gemfile.lock | 43 +- 9 files changed, 658 insertions(+), 17 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/blog-app.iml create mode 100644 .idea/dataSources.xml create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/blog-app.iml b/.idea/blog-app.iml new file mode 100644 index 0000000..7f42246 --- /dev/null +++ b/.idea/blog-app.iml @@ -0,0 +1,561 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml new file mode 100644 index 0000000..f35f58b --- /dev/null +++ b/.idea/dataSources.xml @@ -0,0 +1,32 @@ + + + + + postgresql + true + true + $PROJECT_DIR$/config/database.yml + org.postgresql.Driver + jdbc:postgresql://127.0.0.1:5432/blog_app_development + $ProjectFileDir$ + + + postgresql + true + true + $PROJECT_DIR$/config/database.yml + org.postgresql.Driver + jdbc:postgresql://127.0.0.1:5432/blog_app_test + $ProjectFileDir$ + + + postgresql + true + true + $PROJECT_DIR$/config/database.yml + org.postgresql.Driver + jdbc:postgresql://127.0.0.1:5432/blog_app_production + $ProjectFileDir$ + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..cff1354 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..fe02277 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..4abf1dc --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Gemfile b/Gemfile index 53f4c52..7796225 100644 --- a/Gemfile +++ b/Gemfile @@ -12,7 +12,7 @@ gem 'rails', '~> 7.0.3' gem 'sprockets-rails' # Use postgresql as the database for Active Record -gem 'pg' +gem 'pg', '~> 1.1' # Use the Puma web server [https://github.com/puma/puma] gem 'puma', '~> 5.0' @@ -50,7 +50,7 @@ gem 'bootsnap', require: false # Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images] # gem "image_processing", "~> 1.2" -gem 'ffi' +gem 'ffi', github: 'ffi/ffi', submodules: true group :development, :test do # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem @@ -60,6 +60,7 @@ end group :development do # Use console on exceptions pages [https://github.com/rails/web-console] + gem 'bullet' gem 'web-console' # Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler] @@ -74,4 +75,4 @@ group :test do gem 'capybara' gem 'selenium-webdriver' gem 'webdrivers' -end +end \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock index 0f7d4aa..abe4c17 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,3 +1,10 @@ +GIT + remote: https://github.com/ffi/ffi.git + revision: 07a1c0c028942f786b80f48206795a8fa6b0e8f5 + submodules: true + specs: + ffi (1.15.5) + GEM remote: https://rubygems.org/ specs: @@ -70,9 +77,12 @@ GEM public_suffix (>= 2.0.2, < 5.0) ast (2.4.2) bindex (0.8.1) - bootsnap (1.13.0) + bootsnap (1.12.0) msgpack (~> 1.2) builder (3.2.4) + bullet (7.0.2) + activesupport (>= 3.0.0) + uniform_notifier (~> 1.11) capybara (3.37.1) addressable matrix @@ -88,12 +98,11 @@ GEM diff-lcs (1.5.0) digest (3.1.0) erubi (1.10.0) - ffi (1.15.5) globalid (1.0.0) activesupport (>= 5.0) i18n (1.12.0) concurrent-ruby (~> 1.0) - importmap-rails (1.1.5) + importmap-rails (1.1.3) actionpack (>= 6.0.0) railties (>= 6.0.0) jbuilder (2.11.5) @@ -110,7 +119,7 @@ GEM method_source (1.0.0) mini_mime (1.1.2) minitest (5.16.2) - msgpack (1.5.4) + msgpack (1.5.3) net-imap (0.2.3) digest net-protocol @@ -126,12 +135,15 @@ GEM net-protocol timeout nio4r (2.5.8) - nokogiri (1.13.8-x86_64-linux) + nokogiri (1.13.7-arm64-darwin) + racc (~> 1.4) + nokogiri (1.13.7-x64-mingw-ucrt) racc (~> 1.4) parallel (1.22.1) parser (3.1.2.0) ast (~> 2.4.1) - pg (1.4.2) + pg (1.4.1) + pg (1.4.1-x64-mingw-ucrt) public_suffix (4.0.7) puma (5.6.4) nio4r (~> 2.0) @@ -190,14 +202,14 @@ GEM rspec-mocks (~> 3.10) rspec-support (~> 3.10) rspec-support (3.11.0) - rubocop (1.32.0) + rubocop (1.31.2) json (~> 2.3) parallel (~> 1.10) parser (>= 3.1.0.0) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.19.1, < 2.0) + rubocop-ast (>= 1.18.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 1.4.0, < 3.0) rubocop-ast (1.19.1) @@ -216,20 +228,21 @@ GEM actionpack (>= 5.2) activesupport (>= 5.2) sprockets (>= 3.0.0) - stimulus-rails (1.1.0) + stimulus-rails (1.0.4) railties (>= 6.0.0) - strscan (3.0.4) + strscan (3.0.3) thor (1.2.1) timeout (0.3.0) turbo-rails (1.1.1) actionpack (>= 6.0.0) activejob (>= 6.0.0) railties (>= 6.0.0) - tzinfo (2.0.5) + tzinfo (2.0.4) concurrent-ruby (~> 1.0) tzinfo-data (1.2022.1) tzinfo (>= 1.0.0) unicode-display_width (2.2.0) + uniform_notifier (1.16.0) web-console (4.2.0) actionview (>= 6.0.0) activemodel (>= 6.0.0) @@ -248,15 +261,17 @@ GEM zeitwerk (2.6.0) PLATFORMS - x86_64-linux + arm64-darwin-21 + x64-mingw-ucrt DEPENDENCIES bootsnap + bullet capybara - ffi + ffi! importmap-rails jbuilder - pg + pg (~> 1.1) puma (~> 5.0) rails (~> 7.0.3) rails-controller-testing From 3226d35a037cad10cda27c4a2bdff1bbfbf3e217 Mon Sep 17 00:00:00 2001 From: Evans Sitibekiso Date: Tue, 2 Aug 2022 10:37:58 +0200 Subject: [PATCH 14/32] fix linters --- Gemfile | 5 ++--- Gemfile.lock | 14 ++++++-------- config/database.yml | 11 +++-------- spec/integration/posts_index_spec.rb | 2 +- spec/integration/posts_show_spec.rb | 2 +- spec/integration/user_index_spec.rb | 2 +- spec/integration/user_show_spec.rb | 2 +- 7 files changed, 15 insertions(+), 23 deletions(-) diff --git a/Gemfile b/Gemfile index 7796225..e418f6a 100644 --- a/Gemfile +++ b/Gemfile @@ -50,8 +50,7 @@ gem 'bootsnap', require: false # Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images] # gem "image_processing", "~> 1.2" -gem 'ffi', github: 'ffi/ffi', submodules: true - +gem 'ffi' group :development, :test do # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem gem 'rails-controller-testing' @@ -75,4 +74,4 @@ group :test do gem 'capybara' gem 'selenium-webdriver' gem 'webdrivers' -end \ No newline at end of file +end diff --git a/Gemfile.lock b/Gemfile.lock index abe4c17..a749d98 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,10 +1,3 @@ -GIT - remote: https://github.com/ffi/ffi.git - revision: 07a1c0c028942f786b80f48206795a8fa6b0e8f5 - submodules: true - specs: - ffi (1.15.5) - GEM remote: https://rubygems.org/ specs: @@ -98,6 +91,8 @@ GEM diff-lcs (1.5.0) digest (3.1.0) erubi (1.10.0) + ffi (1.15.5) + ffi (1.15.5-x64-mingw-ucrt) globalid (1.0.0) activesupport (>= 5.0) i18n (1.12.0) @@ -139,6 +134,8 @@ GEM racc (~> 1.4) nokogiri (1.13.7-x64-mingw-ucrt) racc (~> 1.4) + nokogiri (1.13.7-x86_64-linux) + racc (~> 1.4) parallel (1.22.1) parser (3.1.2.0) ast (~> 2.4.1) @@ -263,12 +260,13 @@ GEM PLATFORMS arm64-darwin-21 x64-mingw-ucrt + x86_64-linux DEPENDENCIES bootsnap bullet capybara - ffi! + ffi importmap-rails jbuilder pg (~> 1.1) diff --git a/config/database.yml b/config/database.yml index 7580899..fa127a3 100644 --- a/config/database.yml +++ b/config/database.yml @@ -19,8 +19,7 @@ default: &default adapter: postgresql encoding: unicode - username: postgres - password: 1993 + # For details on connection pooling, see Rails configuration guide # https://guides.rubyonrails.org/configuring.html#database-pooling pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> @@ -28,8 +27,6 @@ default: &default development: <<: *default database: blog_app_development - username: postgres - password: 1993 # The specified database role being used to connect to postgres. # To create additional roles in postgres see `$ createuser --help`. @@ -64,8 +61,7 @@ development: test: <<: *default database: blog_app_test - username: postgres - password: 1993 + # As with config/credentials.yml, you never want to store sensitive information, # like your database password, in your source code. If your source code is @@ -90,5 +86,4 @@ test: production: <<: *default database: blog_app_production - username: postgres - password: 1993 + diff --git a/spec/integration/posts_index_spec.rb b/spec/integration/posts_index_spec.rb index 755ff13..4f0fc78 100644 --- a/spec/integration/posts_index_spec.rb +++ b/spec/integration/posts_index_spec.rb @@ -74,4 +74,4 @@ expect(page).to have_current_path user_post_path(@post1.author_id, @post1) end end -end \ No newline at end of file +end diff --git a/spec/integration/posts_show_spec.rb b/spec/integration/posts_show_spec.rb index 0a74a6d..320d67f 100644 --- a/spec/integration/posts_show_spec.rb +++ b/spec/integration/posts_show_spec.rb @@ -59,4 +59,4 @@ expect(page).to have_content 'Hi Tom Again twice!' end end -end \ No newline at end of file +end diff --git a/spec/integration/user_index_spec.rb b/spec/integration/user_index_spec.rb index bfcbf68..7adf167 100644 --- a/spec/integration/user_index_spec.rb +++ b/spec/integration/user_index_spec.rb @@ -32,4 +32,4 @@ expect(page).to have_content('5') end end -end \ No newline at end of file +end diff --git a/spec/integration/user_show_spec.rb b/spec/integration/user_show_spec.rb index 34e71a0..c84fb02 100644 --- a/spec/integration/user_show_spec.rb +++ b/spec/integration/user_show_spec.rb @@ -43,4 +43,4 @@ expect(page).to have_link('See all posts') end end -end \ No newline at end of file +end From a14160ae568e0c594f8646b4d829df2a64b3c910 Mon Sep 17 00:00:00 2001 From: Evans Sitibekiso Date: Tue, 2 Aug 2022 16:04:34 +0200 Subject: [PATCH 15/32] add devise gem configuration --- .idea/codestyles/codeStyleConfig.xml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .idea/codestyles/codeStyleConfig.xml diff --git a/.idea/codestyles/codeStyleConfig.xml b/.idea/codestyles/codeStyleConfig.xml new file mode 100644 index 0000000..79ee123 --- /dev/null +++ b/.idea/codestyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file From c4c3ab2d715890c25ddd9e2a6d2e608440872bbc Mon Sep 17 00:00:00 2001 From: Evans Sitibekiso Date: Tue, 2 Aug 2022 16:13:36 +0200 Subject: [PATCH 16/32] update styles --- .idea/blog-app.iml | 21 +++++++++++++++++++++ app/assets/stylesheets/user_style.css | 4 +--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/.idea/blog-app.iml b/.idea/blog-app.iml index 7f42246..5fc63fb 100644 --- a/.idea/blog-app.iml +++ b/.idea/blog-app.iml @@ -41,6 +41,7 @@ + @@ -50,6 +51,7 @@ + @@ -73,6 +75,7 @@ + @@ -89,6 +92,7 @@ + @@ -111,6 +115,7 @@ + @@ -127,12 +132,17 @@