spec/cases/simple_spec.rb in activecleaner-0.2.0 vs spec/cases/simple_spec.rb in activecleaner-0.3.0
- old
+ new
@@ -7,15 +7,16 @@
# This is to demonstrate when we want to clean some simple fields
#
class Post
include ActiveCleaner
- attr_accessor :title, :name, :body
+ attr_accessor :title, :name, :body, :user_generated_content
clean :title
clean :name, as: :string
clean :body, as: :text
+ clean :user_generated_content, as: :utf8mb3
end
#
# The specs
@@ -24,12 +25,12 @@
describe Post, "._cleaners" do
subject { Post._cleaners }
- it "has 3 cleaners" do
- expect(subject.length).to eq(3)
+ it "has 4 cleaners" do
+ expect(subject.length).to eq(4)
end
it "includes a StringCleaner for #title" do
expect(subject[:title].first).to eq(ActiveCleaner::StringCleaner.new(:title))
end
@@ -40,10 +41,14 @@
it "includes a TextCleaner for #body" do
expect(subject[:body].first).to eq(ActiveCleaner::TextCleaner.new(:body))
end
+ it "includes a Utf8mb3Cleaner for #user_generated_content" do
+ expect(subject[:user_generated_content].first).to eq(ActiveCleaner::Utf8mb3Cleaner.new(:user_generated_content))
+ end
+
end # describe
context "considering a post" do
let(:subject) { Post.new }
@@ -90,9 +95,25 @@
it "is cleaned as a text" do
subject.body = "Lorem \t ipsum \t \n dolor \t sit \t amet.\n\n\nLorem."
subject.valid?
expect(subject.body).to eq("Lorem ipsum\ndolor sit amet.\n\nLorem.")
+ end
+
+ end # describe
+
+ describe "#user_generated_content, marked as to clean as utf8mb3" do
+
+ it "is untouched when legit" do
+ subject.user_generated_content = "A good user generated content!"
+ subject.valid?
+ expect(subject.user_generated_content).to eq("A good user generated content!")
+ end
+
+ it "is cleaned as an utf8mb3" do
+ subject.user_generated_content = "A good 😀 user generated content!"
+ subject.valid?
+ expect(subject.user_generated_content).to eq("A good user generated content!")
end
end # describe
end # context