Skip to content

Commit

Permalink
Journal: Strip whitespace from slug, headline, and name (#1637)
Browse files Browse the repository at this point in the history
- https://github.com/zinc-collective/convene/issues/1566
- #1630 (comment)

> Not really part of your PR, but now that we have the
> `strip_attributes` gem, it might be worth throwing that on for
> `headline` and `body`, just so that we don't store trailing/preceding
> whitespace.
  • Loading branch information
zspencer authored Jul 6, 2023
1 parent 14d6ce1 commit 8688478
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/furniture/journal/entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class Entry < ApplicationRecord
attribute :slug, :string
validates :slug, uniqueness: {scope: :journal_id}

strip_attributes only: [:body, :headline, :slug]

# FriendlyId does the legwork to make the slug uri-friendly
extend FriendlyId
friendly_id :headline, use: :scoped, scope: :journal
Expand Down
1 change: 1 addition & 0 deletions spec/furniture/journal/entry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

it { is_expected.to validate_presence_of(:headline) }
it { is_expected.to validate_presence_of(:body) }
it { is_expected.to strip_attributes(:slug, :body, :headline) }

describe "#to_html" do
subject(:to_html) { entry.to_html }
Expand Down
5 changes: 5 additions & 0 deletions spec/support/strip_attributes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require "strip_attributes/matchers"

RSpec.configure do |config|
config.include StripAttributes::Matchers
end

0 comments on commit 8688478

Please sign in to comment.