diff --git a/app/helpers/posts_helper.rb b/app/helpers/posts_helper.rb new file mode 100644 index 000000000..c7d7c6c2b --- /dev/null +++ b/app/helpers/posts_helper.rb @@ -0,0 +1,6 @@ +module PostsHelper + def display_post_truncated(post) + length = 300 + return truncate(post.body, length: length, separator: ' ', omission: '... ') { link_to "Read more", post_path(post) } + end +end diff --git a/app/models/post.rb b/app/models/post.rb index 46efa2e45..050af47f5 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -48,6 +48,10 @@ class Post < ApplicationRecord end end + def to_s + subject + end + private def update_crops_posts_association diff --git a/app/views/home/index.html.haml b/app/views/home/index.html.haml index 0b1e6965b..59ae38890 100644 --- a/app/views/home/index.html.haml +++ b/app/views/home/index.html.haml @@ -20,7 +20,6 @@ %h3= t('.recently_added') != Crop.recent.limit(30).map { |c| link_to(c, c) }.join(", ") - %section.seeds %h2.text-center= t('.seeds_available_to_trade') .homepage-cards @@ -28,13 +27,14 @@ .align-bottom %p.text-right= link_to "#{t('home.seeds.view_all')} ยป", seeds_path, class: 'btn' + %section.members= render 'members' + .col-xl-5 .row .col-md-6.col-sm-12=render 'plantings' .col-md-6.col-sm-12= render 'harvests' + .row + .col-12 + %section.members= render 'discuss' - %section.members= render 'discuss' - - -%section.members= render 'members' diff --git a/app/views/posts/_single.html.haml b/app/views/posts/_single.html.haml index 65999aa1d..6132343f1 100644 --- a/app/views/posts/_single.html.haml +++ b/app/views/posts/_single.html.haml @@ -1,4 +1,5 @@ -.well + +.card .post{ id: "post-#{post.id}" } .row .col-md-1 diff --git a/app/views/posts/index.html.haml b/app/views/posts/index.html.haml index c5996019c..dc50b5458 100644 --- a/app/views/posts/index.html.haml +++ b/app/views/posts/index.html.haml @@ -1,10 +1,12 @@ - content_for :title, @author ? t('.title.author_posts', author: @author) : t('.title.default') + +%h1= @author ? t('.title.author_posts', author: @author) : t('.title.default') .pagination= render 'layouts/pagination', collection: @posts .row .card-deck - @posts.each do |post| - .col-6.col-xs-12 + .col-6 .card .card-body .row diff --git a/spec/factories/post.rb b/spec/factories/post.rb index 8284ed393..f3471042f 100644 --- a/spec/factories/post.rb +++ b/spec/factories/post.rb @@ -1,8 +1,8 @@ FactoryBot.define do factory :post do - subject { "A Post" } + subject { Faker::Book.title } - body { "This is some text." } + body { Faker::Lorem.paragraphs.join("\n") } author created_at { Time.zone.now } diff --git a/spec/features/percy/percy_spec.rb b/spec/features/percy/percy_spec.rb index 22faf8ffb..4948f1dbf 100644 --- a/spec/features/percy/percy_spec.rb +++ b/spec/features/percy/percy_spec.rb @@ -88,7 +88,7 @@ describe 'Test with visual testing', type: :feature, js: true do tomato_planting = FactoryBot.create :planting, garden: garden, owner: member, crop: tomato tomato_photo.plantings << tomato_planting visit garden_path(garden) - Percy.snapshot(page, name: "#{prefix}/gardens#show-2") + Percy.snapshot(page, name: "#{prefix}/gardens#show") end end @@ -110,6 +110,16 @@ describe 'Test with visual testing', type: :feature, js: true do visit post_path(post) Percy.snapshot(page, name: "#{prefix}/posts#show") end + it 'loads posts#index' do + Member.all.each do |member| + FactoryBot.create_list :post, 12, author: member + end + Post.all.order(:id).limit(4) do |post| + FactoryBot.create_list :comment, rand(1..5), post: post + end + visit posts_path + Percy.snapshot(page, name: "#{prefix}/posts#index") + end end describe 'photos' do