activecleaner 0.2.0 โ†’ 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 54ad3d4c2a454cfb2e8237abb6399bab45d5448c
4
- data.tar.gz: 3bf151d63ce0286fa4819a2ce1a25e61a62a3047
3
+ metadata.gz: f568e263b920da28be6897d33c390ba37d100d02
4
+ data.tar.gz: 6649a5b52ece6e7181a8c3d8bc635c3e671dd5d7
5
5
  SHA512:
6
- metadata.gz: 46a2b65f759e7d9501de3795637707e9a5de27375185526e7fc55c6bb9cd270f880b498e0e6817f3ac414d68449407734f5976b9107bbb8727b28585f01c13d8
7
- data.tar.gz: 7a7d84b9e7ff1e68733b13e1b4c995f85f07f001a2a77de562c2ef501ae76aae9cdc222c0fc6eeafb2337645c9a76602f353feab9b2955ea4ab319b2ff81cb6e
6
+ metadata.gz: 09c356b188281b08dd78d2c9d99622234c0be6d2be3f795a9dce25c7e27c527f3e5880cf60f4f125bad8f648e319658aeab9d810c47cf7e7b97f1467122e3cc0
7
+ data.tar.gz: 26fcaef9a2105e5df417ec0a8c1440d56b1792acfac489bbd2606fdc1464333dcbb83296cf6f4084abcc61398920cd0cb10244f7a308d4ddfcd1b5187810bc5a
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # ActiveCleaner
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/activecleaner.svg)](http://badge.fury.io/rb/activecleaner) [![Build Status](https://travis-ci.org/maximeg/activecleaner.svg?branch=master)](https://travis-ci.org/maximeg/activecleaner)
3
+ [![Gem Version](https://badge.fury.io/rb/activecleaner.svg)](https://rubygems.org/gems/activecleaner)
4
+ [![Build Status](https://travis-ci.org/maximeg/activecleaner.svg?branch=master)](https://travis-ci.org/maximeg/activecleaner)
5
+ [![Dependency Status](https://gemnasium.com/maximeg/activecleaner.svg)](https://gemnasium.com/maximeg/activecleaner)
4
6
 
5
7
  `ActiveCleaner` is a set of helpers that helps you in cleaning user-typed content in your ActiveModel depending models (ActiveRecord, Mongoid...)
6
8
 
@@ -26,6 +28,7 @@ end
26
28
  * `:string` (StringCleaner, the default one) : cleans all the space characters. It turns `" A \n \t title \t "` into `"A title"`.
27
29
  * `:text` (TextCleaner) : like `:string`, but preserves new lines (with a max of 2 successive new lines). useful when the field is rendered with the `simple_format` Rails helper.
28
30
  * `:markdown` (MarkdownCleaner) : like `:text`, but preserves spaces in the beginning of lines (the indentation). useful for... markdown!
31
+ * `:utf8mb3` (Utf8mb3Cleaner) : removes all 4-bytes encoded chars in UTF8 strings that mess with the `utf8` encoding in MySQL (iOS6 emojis for example).
29
32
 
30
33
 
31
34
 
@@ -10,6 +10,7 @@ require 'active_cleaner/base_cleaner'
10
10
  require 'active_cleaner/string_cleaner'
11
11
  require 'active_cleaner/text_cleaner'
12
12
  require 'active_cleaner/markdown_cleaner'
13
+ require 'active_cleaner/utf8mb3_cleaner'
13
14
 
14
15
  require 'active_cleaner/version'
15
16
 
@@ -0,0 +1,13 @@
1
+ # encoding: utf-8
2
+
3
+ module ActiveCleaner
4
+ class Utf8mb3Cleaner < BaseCleaner
5
+
6
+ def clean_value(old_value, record=nil)
7
+ unless old_value.nil?
8
+ old_value.each_char.select { |char| char.bytesize < 4 }.join('')
9
+ end
10
+ end
11
+
12
+ end
13
+ end
@@ -2,7 +2,7 @@
2
2
  module ActiveCleaner
3
3
  module Version
4
4
 
5
- STRING = '0.2.0'
5
+ STRING = '0.3.0'
6
6
 
7
7
  end
8
8
  end
@@ -17,9 +17,10 @@ class Ad
17
17
  end
18
18
 
19
19
  class CarAd < Ad
20
- attr_accessor :body
20
+ attr_accessor :body, :user_generated_content
21
21
 
22
22
  clean :body, as: :text
23
+ clean :user_generated_content, as: :utf8mb3
23
24
  end
24
25
 
25
26
  #
@@ -49,8 +50,8 @@ describe "Case: an ad and his inherited car ad" do
49
50
 
50
51
  subject { CarAd._cleaners }
51
52
 
52
- it "has 3 cleaners" do
53
- expect(subject.length).to eq(3)
53
+ it "has 4 cleaners" do
54
+ expect(subject.length).to eq(4)
54
55
  end
55
56
 
56
57
  it "includes a StringCleaner for #title" do
@@ -65,6 +66,10 @@ describe "Case: an ad and his inherited car ad" do
65
66
  expect(subject[:body].first).to eq(ActiveCleaner::TextCleaner.new(:body))
66
67
  end
67
68
 
69
+ it "includes a Utf8mb3Cleaner for #user_generated_content" do
70
+ expect(subject[:user_generated_content].first).to eq(ActiveCleaner::Utf8mb3Cleaner.new(:user_generated_content))
71
+ end
72
+
68
73
  end # describe
69
74
 
70
75
  context "considering a car ad" do
@@ -119,6 +124,22 @@ describe "Case: an ad and his inherited car ad" do
119
124
 
120
125
  end # describe
121
126
 
127
+ describe "#user_generated_content, marked as to clean as utf8mb3" do
128
+
129
+ it "is untouched when legit" do
130
+ subject.user_generated_content = "A good user generated content!"
131
+ subject.valid?
132
+ expect(subject.user_generated_content).to eq("A good user generated content!")
133
+ end
134
+
135
+ it "is cleaned as an utf8mb3" do
136
+ subject.user_generated_content = "A good ๐Ÿ˜€ user generated content!"
137
+ subject.valid?
138
+ expect(subject.user_generated_content).to eq("A good user generated content!")
139
+ end
140
+
141
+ end # describe
142
+
122
143
  end # context
123
144
 
124
145
  end # describe
@@ -9,11 +9,12 @@ require "spec_helper"
9
9
  class OptimizedPost
10
10
  include ActiveCleaner
11
11
 
12
- attr_accessor :title, :name, :body
12
+ attr_accessor :title, :name, :body, :user_generated_content
13
13
 
14
14
  clean :title, nilify: true
15
15
  clean :name, as: :string, nilify: true
16
16
  clean :body, as: :text, nilify: true
17
+ clean :user_generated_content, as: :utf8mb3, nilify: true
17
18
  end
18
19
 
19
20
 
@@ -26,8 +27,8 @@ describe "Case: a simple post with nulify" do
26
27
 
27
28
  subject { OptimizedPost._cleaners }
28
29
 
29
- it "has 3 cleaners" do
30
- expect(subject.length).to eq(3)
30
+ it "has 4 cleaners" do
31
+ expect(subject.length).to eq(4)
31
32
  end
32
33
 
33
34
  it "includes a StringCleaner for #title" do
@@ -42,6 +43,10 @@ describe "Case: a simple post with nulify" do
42
43
  expect(subject[:body].first).to eq(ActiveCleaner::TextCleaner.new(:body, nilify: true))
43
44
  end
44
45
 
46
+ it "includes a Utf8mb3Cleaner for #user_generated_content" do
47
+ expect(subject[:user_generated_content].first).to eq(ActiveCleaner::Utf8mb3Cleaner.new(:user_generated_content, nilify: true))
48
+ end
49
+
45
50
  end # describe
46
51
 
47
52
  context "considering a post" do
@@ -96,6 +101,22 @@ describe "Case: a simple post with nulify" do
96
101
 
97
102
  end # describe
98
103
 
104
+ describe "#user_generated_content, marked as to clean as utf8mb3" do
105
+
106
+ it "is untouched when legit" do
107
+ subject.user_generated_content = "A good user generated content!"
108
+ subject.valid?
109
+ expect(subject.user_generated_content).to eq("A good user generated content!")
110
+ end
111
+
112
+ it "is nulified" do
113
+ subject.user_generated_content = "๐Ÿ˜€"
114
+ subject.valid?
115
+ expect(subject.user_generated_content).to be_nil
116
+ end
117
+
118
+ end # describe
119
+
99
120
  end # context
100
121
 
101
122
  end # describe
@@ -9,11 +9,12 @@ require "spec_helper"
9
9
  class Post
10
10
  include ActiveCleaner
11
11
 
12
- attr_accessor :title, :name, :body
12
+ attr_accessor :title, :name, :body, :user_generated_content
13
13
 
14
14
  clean :title
15
15
  clean :name, as: :string
16
16
  clean :body, as: :text
17
+ clean :user_generated_content, as: :utf8mb3
17
18
  end
18
19
 
19
20
 
@@ -26,8 +27,8 @@ describe "Case: a simple post" do
26
27
 
27
28
  subject { Post._cleaners }
28
29
 
29
- it "has 3 cleaners" do
30
- expect(subject.length).to eq(3)
30
+ it "has 4 cleaners" do
31
+ expect(subject.length).to eq(4)
31
32
  end
32
33
 
33
34
  it "includes a StringCleaner for #title" do
@@ -42,6 +43,10 @@ describe "Case: a simple post" do
42
43
  expect(subject[:body].first).to eq(ActiveCleaner::TextCleaner.new(:body))
43
44
  end
44
45
 
46
+ it "includes a Utf8mb3Cleaner for #user_generated_content" do
47
+ expect(subject[:user_generated_content].first).to eq(ActiveCleaner::Utf8mb3Cleaner.new(:user_generated_content))
48
+ end
49
+
45
50
  end # describe
46
51
 
47
52
  context "considering a post" do
@@ -96,6 +101,22 @@ describe "Case: a simple post" do
96
101
 
97
102
  end # describe
98
103
 
104
+ describe "#user_generated_content, marked as to clean as utf8mb3" do
105
+
106
+ it "is untouched when legit" do
107
+ subject.user_generated_content = "A good user generated content!"
108
+ subject.valid?
109
+ expect(subject.user_generated_content).to eq("A good user generated content!")
110
+ end
111
+
112
+ it "is cleaned as an utf8mb3" do
113
+ subject.user_generated_content = "A good ๐Ÿ˜€ user generated content!"
114
+ subject.valid?
115
+ expect(subject.user_generated_content).to eq("A good user generated content!")
116
+ end
117
+
118
+ end # describe
119
+
99
120
  end # context
100
121
 
101
122
  end # describe
@@ -0,0 +1,29 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe ActiveCleaner::Utf8mb3Cleaner do
5
+
6
+ let(:cleaner) { ActiveCleaner::Utf8mb3Cleaner.new(:title) }
7
+
8
+ describe "#clean_value" do
9
+
10
+ it "doesn't touch legit value" do
11
+ expect(cleaner.clean_value("A good title!")).to eq("A good title!")
12
+ end
13
+
14
+ it "cleans emoticons" do
15
+ emoticons = "๐Ÿ˜€๐Ÿ˜๐Ÿ˜‚๐Ÿ˜ƒ๐Ÿ˜„๐Ÿ˜…๐Ÿ˜†๐Ÿ˜‡๐Ÿ˜ˆ๐Ÿ˜‰๐Ÿ˜Š๐Ÿ˜‹๐Ÿ˜Œ๐Ÿ˜๐Ÿ˜Ž๐Ÿ˜๐Ÿ˜๐Ÿ˜‘๐Ÿ˜’๐Ÿ˜“๐Ÿ˜”๐Ÿ˜•๐Ÿ˜–๐Ÿ˜—๐Ÿ˜˜๐Ÿ˜™๐Ÿ˜š๐Ÿ˜›๐Ÿ˜œ๐Ÿ˜๐Ÿ˜ž๐Ÿ˜Ÿ๐Ÿ˜ ๐Ÿ˜ก๐Ÿ˜ข๐Ÿ˜ฃ๐Ÿ˜ค๐Ÿ˜ฅ๐Ÿ˜ฆ๐Ÿ˜ง๐Ÿ˜จ๐Ÿ˜ฉ๐Ÿ˜ช๐Ÿ˜ซ๐Ÿ˜ฌ๐Ÿ˜ญ๐Ÿ˜ฎ๐Ÿ˜ฏ๐Ÿ˜ฐ๐Ÿ˜ฑ๐Ÿ˜ฒ๐Ÿ˜ณ๐Ÿ˜ด๐Ÿ˜ต๐Ÿ˜ถ๐Ÿ˜ท๐Ÿ˜ธ๐Ÿ˜น๐Ÿ˜บ๐Ÿ˜ป๐Ÿ˜ผ๐Ÿ˜ฝ๐Ÿ˜พ๐Ÿ˜ฟ๐Ÿ™€๐Ÿ™๐Ÿ™‚๐Ÿ™…๐Ÿ™†๐Ÿ™‡๐Ÿ™ˆ๐Ÿ™‰๐Ÿ™Š๐Ÿ™‹๐Ÿ™Œ๐Ÿ™๐Ÿ™Ž๐Ÿ™"
16
+ expect(cleaner.clean_value("A good #{emoticons} title!")).to eq("A good title!")
17
+ end
18
+
19
+ it "kepts accentued chars" do
20
+ expect(cleaner.clean_value("L'Inouรฏ Goรปter ร€ Manger.")).to eq("L'Inouรฏ Goรปter ร€ Manger.")
21
+ end
22
+
23
+ it "kepts japanese chars" do
24
+ expect(cleaner.clean_value("ginkล is written as ้Š€่กŒ")).to eq("ginkล is written as ้Š€่กŒ")
25
+ end
26
+
27
+ end
28
+
29
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activecleaner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maxime Garcia
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-19 00:00:00.000000000 Z
11
+ date: 2014-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -86,6 +86,7 @@ files:
86
86
  - lib/active_cleaner/markdown_cleaner.rb
87
87
  - lib/active_cleaner/string_cleaner.rb
88
88
  - lib/active_cleaner/text_cleaner.rb
89
+ - lib/active_cleaner/utf8mb3_cleaner.rb
89
90
  - lib/active_cleaner/version.rb
90
91
  - lib/activecleaner.rb
91
92
  - spec/cases/inherit_spec.rb
@@ -94,6 +95,7 @@ files:
94
95
  - spec/lib/active_cleaner/markdown_cleaner_spec.rb
95
96
  - spec/lib/active_cleaner/string_cleaner_spec.rb
96
97
  - spec/lib/active_cleaner/text_cleaner_spec.rb
98
+ - spec/lib/active_cleaner/utf8mb4_cleaner_spec.rb
97
99
  - spec/lib/active_cleaner_spec.rb
98
100
  - spec/spec_helper.rb
99
101
  homepage: http://github.com/maximeg/activecleaner
@@ -116,16 +118,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
118
  version: 1.3.6
117
119
  requirements: []
118
120
  rubyforge_project:
119
- rubygems_version: 2.4.1
121
+ rubygems_version: 2.4.2
120
122
  signing_key:
121
123
  specification_version: 4
122
124
  summary: Clean the fields in your models
123
125
  test_files:
124
- - spec/lib/active_cleaner/string_cleaner_spec.rb
126
+ - spec/cases/simple_spec.rb
127
+ - spec/cases/inherit_spec.rb
128
+ - spec/cases/nilify_spec.rb
125
129
  - spec/lib/active_cleaner/text_cleaner_spec.rb
130
+ - spec/lib/active_cleaner/utf8mb4_cleaner_spec.rb
131
+ - spec/lib/active_cleaner/string_cleaner_spec.rb
126
132
  - spec/lib/active_cleaner/markdown_cleaner_spec.rb
127
133
  - spec/lib/active_cleaner_spec.rb
128
134
  - spec/spec_helper.rb
129
- - spec/cases/inherit_spec.rb
130
- - spec/cases/simple_spec.rb
131
- - spec/cases/nilify_spec.rb