Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blog app - integration specs for views and fix n+1 problems #4

Merged
merged 22 commits into from
Oct 5, 2023

Conversation

SAZZAD1Q2
Copy link
Owner

@SAZZAD1Q2 SAZZAD1Q2 commented Oct 4, 2023

see the username of all other users.
see the profile picture for each user.
see the number of posts each user has written.

user show page:

I can see the user's profile picture.
I can see the user's username.
I can see the number of posts the user has written.
I can see the user's bio.
I can see the user's first 3 posts.
I can see a button that lets me view all of a user's posts.
When I click a user's post, it redirects me to that post's show page.
When I click to see all posts, it redirects me to the user's post's index page.

Copy link

@thecodechaser thecodechaser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

STATUS: CHANGES REQUIRED ♻️

Hi @SAZZAD1Q2, and @Theodoraldo👋,

Good job so far!
There are some issues that you still need to work on to go to the next project but you are almost there!

To Highlight 🎉

  • Good job fixing n+1 problems. ✔️
  • No linter errors. ✔️
  • Gitflow is followed. ✔️
  • Professional README file. ✔️
  • PR has a good title and summary. ✔️

Required Changes ♻️

Check the comments under the review.

Optional suggestions

Every comment with the [OPTIONAL] prefix is not crucial enough to stop the approval of this PR. However, I strongly recommend you to take them into account as they can make your code better.

You can also consider:
N/A

Cheers and Happy coding!👏👏👏

Feel free to leave any questions or comments in the PR thread if something is not 100% clear.
Please, remember to tag me in your question so I can receive the notification.

Please, do not open a new Pull Request for re-reviews. You should use the same Pull Request submitted for the first review, either valid or invalid unless it is requested otherwise.


As described in the Code reviews limits policy you have a limited number of reviews per project (check the exact number in your Dashboard). If you think that the code review was not fair, you can request a second opinion using this form.

Comment on lines 2 to 20

RSpec.describe 'User index page', type: :feature do
describe 'Should display some text and links' do
let!(:users) do
[
User.create(name: 'Microverse A', photo: 'http://via.placeholder.com/250x250',
bio: 'A programmer engineer from Ghana.'),
User.create(name: 'Microverse B', photo: 'http://via.placeholder.com/250x250',
bio: 'A backend developer from Peru.')
]
end

before do
visit users_path
end

it 'Display header text' do
expect(page).to have_content('List of all users')
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Currently, you have added tests for all pages in a single file. Please make sure to separate them into different files. It will make the code more readable and clean.
  • Suggested file structure example for users#index page. feature/users/index_spec.rb.

Comment on lines 60 to 74
RSpec.describe 'User show page', type: :feature do
describe 'Should display user and their posts' do
user = User.create(name: 'Theodoraldo Gishun', photo: 'http://via.placeholder.com/250x250',
bio: 'A programmer engineer from Ghana.')
let!(:posts) do
[
Post.create(title: 'Arrival', text: 'Post content 1', author: user),
Post.create(title: 'Departure', text: 'Post content 2', author: user)
]
end

before do
visit user_path(user)
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • You missed adding the below tests for the users#show page. Please make sure to add them and they should pass without any errors.
    • Tests that assert you can see the user's first 3 posts.
    • Tests that redirect to the post's show page when you click on a user's post.

Comment on lines 131 to 165

RSpec.describe 'post index page', type: :feature do
describe 'Should display user and their posts' do
user = User.create(name: 'Emmanuella Ansah', photo: 'http://via.placeholder.com/250x250',
bio: 'A programmer engineer from Ghana.')
let!(:posts) do
[
Post.create(title: 'Birth rate', text: 'Post content 1', author: user),
Post.create(title: 'Death rate', text: 'Post content 2', author: user)
]
end

let(:comments) do
[
Comment.create(text: 'First comment for birth rate post', author: user, post: posts[0]),
Comment.create(text: 'Second comment for death rate post', author: user, post: posts[1])
]
end

before do
visit user_posts_path(user)
end

it 'Display header text' do
expect(page).to have_content('List of all posts')
end

it 'displays the user name and their posts' do
expect(page).to have_content("Name: #{user.name}")
end

it 'displays the profile picture for each user' do
expect(page).to have_css("img[src='#{user.photo}'][alt='user photo']")
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • You missed adding the below tests for the posts#index page. Please make sure to add them and they should pass without any errors.
    • Tests that assert you can see the first comments on a post.

Comment on lines 211 to 224

RSpec.describe 'Post show page', type: :feature do
describe 'Should display post details of a user' do
user = User.create(name: 'Douglas Opoku', photo: 'http://via.placeholder.com/250x250',
bio: 'A programmer engineer from USA.')
let!(:posts) do
Post.create(title: 'Birth rate', text: 'Post content 1', author: user)
end

let(:comments) do
Comment.create(text: 'Second comment for death rate post', author: user, post: posts)
end

before do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • You missed adding the below tests for the posts#index page. Please make sure to add them and they should pass without any errors.
    • Tests that assert you can see the username of each comment.
    • Tests that assert you can see the comment each comment left.

Copy link

@Gambit142 Gambit142 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @SAZZAD1Q2 @Theodoraldo 👋,

Great work on making the changes requested by a previous reviewer 👏

Highlights

  • Setup linters properly ✔️
  • Used Rspec as testing library ✔️
  • Wrote feature tests for Users and Posts pages ✔️

You've done well implementing some of the requested changes, but there are still some which aren't addressed yet.

Required Changes ♻️

Kindly check the comments under the review.

Optional suggestions

Every comment with the [OPTIONAL] prefix won't stop the approval of this PR. However, I strongly recommend you consider them as they can improve your code. Some of them were simply missed by the previous reviewer and addressing them will improve your application.

N/A

Cheers, and Happy coding!👏👏👏

Feel free to leave any questions or comments in the PR thread if something is not 100% clear.

Please tag me in your question so I can receive the notification. You can tag me by typing @Gambit142

Please, do not open a new Pull Request for re-reviews. You should use the same Pull Request submitted for the first review, either valid or invalid unless it is requested otherwise.


As described in the Code reviews limits policy you have a limited number of reviews per project (check the exact number in your Dashboard). If you think the code review was unfair, request a second opinion using this form.

Comment on lines 1 to 80
require 'rails_helper'

RSpec.describe 'posts#index', type: :feature do
before(:each) do
User.destroy_all # Destroy all existing users to start with a clean slate
Post.destroy_all # Destroy all existing posts to start with a clean slate

@user_one = User.create(
name: 'Sazzad',
photo: 'http://via.placeholder.com/250x250',
bio: 'A programmer from Bangladesh.',
post_counter: 0
)

@posts = [
Post.create(
author: @user_one,
title: 'Blog1',
text: 'Post content 1'
),
Post.create(
author: @user_one,
title: 'Blog2',
text: 'Post content 2'
)
]

visit user_posts_url(user_id: @user_one.id)
end

describe '#Indexpage' do
it 'can see the user profile picture.' do
expect(page).to have_css("img[src='#{@user_one.photo}']")
end
it 'I can see the user username.' do
expect(page).to have_content(@user_one.name.to_s)
end
it 'I can see the number of posts the user has written.' do
expect(page).to have_content(@user_one.post_counter.to_s)
end

it 'should see title of the post' do
@posts.each do |post|
expect(page).to have_content(post.title.to_s)
end
end

it 'should see body of the post' do
@posts.each do |post|
expect(page).to have_content(post.text.to_s)
end
end

it 'I can see the first comments on a post.' do
@posts.each do |post|
post.recent_comments.each do |comment|
expect(page).to have_content(comment.user.text)
end
end
end
it 'I can see how many comments a post has' do
@posts.each do |post|
expect(page).to have_content("Comments:#{post.comment_counter}")
end
end
it 'I can see how many likes a post has' do
@posts.each do |post|
expect(page).to have_content("Likes:#{post.like_counter}")
end
end
end
describe 'GET show/page' do
it 'When I click on a post, I am redirected to that postshow page.' do
visit user_posts_url(user_id: @user_one.id)
post = @posts.first
click_link(post.id)
expect(page).to have_current_path(user_post_path(@user_one.id, post.id))
end
end
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Great work making all the changes requested by the previous reviewer. However, I noticed that all the tests didn't pass. Kindly fix the issues and ensure that all the tests pass. 👍

image

Copy link

@uwadonat uwadonat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @SAZZAD1Q2,

Your project is complete! There is nothing else to say other than... it's time to merge it :shipit:

Congratulations! 🎉

Highlights

  • Your tests pass successfully ✔️
  • No linter errors ✔️
  • Correct workflow was used ✔️

Status: Approved ✔️✔️✔️

approv

Cheers and Happy coding!👏👏👏

Feel free to leave any questions or comments in the PR thread if something is not 100%.
Please, remember to tag me @uwadonat in your question so I can receive the notification.


As described in the Code reviews limits policy you have a limited number of reviews per project (check the exact number in your Dashboard). If you think that the code review was not fair, you can request a second opinion using this form.

@SAZZAD1Q2 SAZZAD1Q2 merged commit f27f0ef into dev Oct 5, 2023
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants