From 5f61820e08cb5aecbd5d102ff94d0e54565ae24c Mon Sep 17 00:00:00 2001 From: Edward Odhiambo Date: Thu, 4 Aug 2022 13:10:07 +0300 Subject: [PATCH 1/9] Edit Spec --- spec/integration/posts_show_spec.rb | 62 ----------------------------- 1 file changed, 62 deletions(-) diff --git a/spec/integration/posts_show_spec.rb b/spec/integration/posts_show_spec.rb index 320d67f..e69de29 100644 --- a/spec/integration/posts_show_spec.rb +++ b/spec/integration/posts_show_spec.rb @@ -1,62 +0,0 @@ -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 From d84068642db2776139897e35b54336f68b119943 Mon Sep 17 00:00:00 2001 From: Edward Odhiambo Date: Thu, 4 Aug 2022 13:10:53 +0300 Subject: [PATCH 2/9] Add Post Show Integration --- spec/integration/posts_show_spec.rb | 62 +++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/spec/integration/posts_show_spec.rb b/spec/integration/posts_show_spec.rb index e69de29..320d67f 100644 --- a/spec/integration/posts_show_spec.rb +++ 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 From e01b91aa702f0ba31e1958dd433d2db8db639c5c Mon Sep 17 00:00:00 2001 From: Edward Odhiambo Date: Thu, 4 Aug 2022 13:11:13 +0300 Subject: [PATCH 3/9] Edit Spec --- spec/integration/posts_index_spec.rb | 77 ---------------------------- 1 file changed, 77 deletions(-) diff --git a/spec/integration/posts_index_spec.rb b/spec/integration/posts_index_spec.rb index 4f0fc78..e69de29 100644 --- a/spec/integration/posts_index_spec.rb +++ b/spec/integration/posts_index_spec.rb @@ -1,77 +0,0 @@ -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 From 703f6dd19c1a4f3881471beb4bf3a6a98614029e Mon Sep 17 00:00:00 2001 From: Edward Odhiambo Date: Thu, 4 Aug 2022 13:11:36 +0300 Subject: [PATCH 4/9] Add Post Index Integration --- spec/integration/posts_index_spec.rb | 77 ++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/spec/integration/posts_index_spec.rb b/spec/integration/posts_index_spec.rb index e69de29..4f0fc78 100644 --- a/spec/integration/posts_index_spec.rb +++ 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 From 32198d0db66578eb673cbdf84cdc641ea1b51a05 Mon Sep 17 00:00:00 2001 From: Edward Odhiambo Date: Thu, 4 Aug 2022 13:13:03 +0300 Subject: [PATCH 5/9] Edit Readme --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index ab6209e..0f0bcb1 100644 --- a/README.md +++ b/README.md @@ -173,6 +173,12 @@ This project is build with: - Twitter: [@Evans_22J](https://twitter.com/Evans_22J) - LinkedIn: [@Evans Sitibekiso](https://www.linkedin.com/in/evans-sitibekiso/) +👤 **Edward Odhiambo** + +- GitHub: [@whit3d](https://github.com/white3d) +- Twitter: [@odhiambo_ed](https://twitter.com/odhiambo_ed) +- LinkedIn: [Edward Odhiambo](https://www.linkedin.com/in/edward-odhiambo-6a462a21b/) + ## 🤝 Contributor From 275824e473eae52f9a709881648fe222127c51e2 Mon Sep 17 00:00:00 2001 From: Edward Odhiambo Date: Thu, 4 Aug 2022 19:38:21 +0300 Subject: [PATCH 6/9] Edit Readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0f0bcb1..e1b8e69 100644 --- a/README.md +++ b/README.md @@ -198,4 +198,4 @@ Give a ⭐️ if you like this project! ## 📝 License -This project is [MIT](https://github.com/microverseinc/readme-template/blob/master/MIT.md) licensed. +This project is [MIT](https://github.com/microverseinc/readme-template/blob/master/MIT.md) licensed From 2b68a2e05f76f75c8388d9d8c9e60cb927615a0d Mon Sep 17 00:00:00 2001 From: Edward Odhiambo Date: Thu, 4 Aug 2022 22:42:04 +0300 Subject: [PATCH 7/9] Add Redirect To User Index Spec --- Gemfile.lock | 3 +++ spec/integration/user_index_spec.rb | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/Gemfile.lock b/Gemfile.lock index a749d98..2b6a810 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -134,6 +134,8 @@ GEM racc (~> 1.4) nokogiri (1.13.7-x64-mingw-ucrt) racc (~> 1.4) + nokogiri (1.13.7-x86_64-darwin) + racc (~> 1.4) nokogiri (1.13.7-x86_64-linux) racc (~> 1.4) parallel (1.22.1) @@ -260,6 +262,7 @@ GEM PLATFORMS arm64-darwin-21 x64-mingw-ucrt + x86_64-darwin-21 x86_64-linux DEPENDENCIES diff --git a/spec/integration/user_index_spec.rb b/spec/integration/user_index_spec.rb index 7adf167..9035851 100644 --- a/spec/integration/user_index_spec.rb +++ b/spec/integration/user_index_spec.rb @@ -31,5 +31,11 @@ expect(page).to have_content('3') expect(page).to have_content('5') end + + it 'redirects to users show page' do + visit root_path + click_on @first_user.name + expect(page).to have_content(`#{@username1}\'s Most Recent Posts`) + end end end From bc892690f6a0b401ac74748b3bd92dcac31cc9a6 Mon Sep 17 00:00:00 2001 From: Edward Odhiambo Date: Thu, 4 Aug 2022 23:12:06 +0300 Subject: [PATCH 8/9] Add Redirects To User Index --- spec/integration/user_index_spec.rb | 7 ++++--- spec/integration/user_show_spec.rb | 13 +++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/spec/integration/user_index_spec.rb b/spec/integration/user_index_spec.rb index 9035851..8210e41 100644 --- a/spec/integration/user_index_spec.rb +++ b/spec/integration/user_index_spec.rb @@ -31,11 +31,12 @@ expect(page).to have_content('3') expect(page).to have_content('5') end - + it 'redirects to users show page' do visit root_path - click_on @first_user.name - expect(page).to have_content(`#{@username1}\'s Most Recent Posts`) + click_link @first_user.name + expect(page).to have_content(@first_user.name) + expect(page).to have_content(@first_user.bio) end end end diff --git a/spec/integration/user_show_spec.rb b/spec/integration/user_show_spec.rb index c84fb02..6077cba 100644 --- a/spec/integration/user_show_spec.rb +++ b/spec/integration/user_show_spec.rb @@ -42,5 +42,18 @@ it 'should have button to show all posts' do expect(page).to have_link('See all posts') end + + it "redirects me to that post's show page." do + first('.post > a').click + expect(page).to have_content('Add a new comment') + find_button('like post') + expect(page).to have_content('Comments: 0 Likes: 0') + end + + it 'redirects me to the user's post's index page' do + click_button('See all posts') + expect(page).to have_content(@user.bio) + expect(page).to have_content("Number of posts: #{@user.posts_counter}") + end end end From 5caf8bf95f069981e6fadd74edae56d9958d53d3 Mon Sep 17 00:00:00 2001 From: Edward Odhiambo Date: Thu, 4 Aug 2022 23:32:55 +0300 Subject: [PATCH 9/9] Edit Integration --- spec/integration/user_show_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/integration/user_show_spec.rb b/spec/integration/user_show_spec.rb index 6077cba..9f32e48 100644 --- a/spec/integration/user_show_spec.rb +++ b/spec/integration/user_show_spec.rb @@ -50,7 +50,7 @@ expect(page).to have_content('Comments: 0 Likes: 0') end - it 'redirects me to the user's post's index page' do + it 'redirects me to the user post index page' do click_button('See all posts') expect(page).to have_content(@user.bio) expect(page).to have_content("Number of posts: #{@user.posts_counter}")