Use truncate helper on spam logs list

This commit is contained in:
Douglas Barbosa Alexandre 2016-01-26 16:59:23 -02:00
parent d20e75a8d8
commit 64c9768bd6
4 changed files with 21 additions and 15 deletions

View file

@ -2,12 +2,4 @@ class SpamLog < ActiveRecord::Base
belongs_to :user
validates :user, presence: true
def truncated_description
if description.present? && description.length > 100
return description[0..100] + "..."
end
description
end
end

View file

@ -16,7 +16,7 @@
%td
= spam_log.title
%td
= spam_log.truncated_description
= truncate(spam_log.description, length: 100)
%td
- if user
= link_to 'Remove user', admin_spam_log_path(spam_log, remove_user: true),

View file

@ -4,15 +4,25 @@ class Spinach::Features::AdminSpamLogs < Spinach::FeatureSteps
include SharedAdmin
step 'I should see list of spam logs' do
page.should have_content("Spam Logs")
spam_log = SpamLog.first
page.should have_content spam_log.title
page.should have_content spam_log.description
page.should have_link("Remove user")
page.should have_link("Block user")
expect(page).to have_content('Spam Logs')
expect(page).to have_content spam_log.source_ip
expect(page).to have_content spam_log.noteable_type
expect(page).to have_content 'N'
expect(page).to have_content spam_log.title
expect(page).to have_content truncate(spam_log.description)
expect(page).to have_link('Remove user')
expect(page).to have_link('Block user')
end
step 'spam logs exist' do
create(:spam_log)
end
def spam_log
@spam_log ||= SpamLog.first
end
def truncate(description)
"#{spam_log.description[0...97]}..."
end
end

View file

@ -3,5 +3,9 @@
FactoryGirl.define do
factory :spam_log do
user
source_ip { FFaker::Internet.ip_v4_address }
noteable_type 'Issue'
title { FFaker::Lorem.sentence }
description { FFaker::Lorem.paragraph(5) }
end
end