Tidy up posts

This commit is contained in:
Brenda Wallace
2019-05-18 21:41:41 +12:00
parent 2046d73330
commit f019969240
7 changed files with 33 additions and 10 deletions

View File

@@ -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

View File

@@ -48,6 +48,10 @@ class Post < ApplicationRecord
end
end
def to_s
subject
end
private
def update_crops_posts_association

View File

@@ -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'

View File

@@ -1,4 +1,5 @@
.well
.card
.post{ id: "post-#{post.id}" }
.row
.col-md-1

View File

@@ -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

View File

@@ -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 }

View File

@@ -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