html_terminator 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module HtmlTerminator
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -7,7 +7,11 @@ module HtmlTerminator
7
7
  }
8
8
 
9
9
  def self.sanitize(val)
10
- Sanitize.clean(val, SANITIZE_OPTIONS).strip unless val.nil?
10
+ if val and val.is_a?(String)
11
+ Sanitize.clean(val, SANITIZE_OPTIONS).strip
12
+ else
13
+ val
14
+ end
11
15
  end
12
16
 
13
17
  module ClassMethods
@@ -1,8 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe HtmlTerminator do
4
- it "should terminate name only fields specified" do
5
- @user = User.new
4
+ it "sanitizes only fields specified" do
5
+ @user = OnlyFirstName.new
6
6
 
7
7
  @user.first_name = "Hello <img>"
8
8
  @user.first_name.should == "Hello"
@@ -14,19 +14,25 @@ describe HtmlTerminator do
14
14
  @user.age.should == 3
15
15
  end
16
16
 
17
- it "should terminate all except what is specified" do
18
- @student = Student.new
17
+ it "sanitizes all except what is specified" do
18
+ @user = ExceptFirstName.new
19
19
 
20
- @student.first_name = "Hello <img>"
21
- @student.first_name.should == "Hello <img>"
20
+ @user.first_name = "Hello <img>"
21
+ @user.first_name.should == "Hello <img>"
22
+
23
+ @user.last_name = "Hello <img>"
24
+ @user.last_name.should == "Hello"
25
+ end
22
26
 
23
- @student.last_name = "Hello <img>"
24
- @student.last_name.should == "Hello"
27
+ it "doesn't blow up if value is nil" do
28
+ @user = ExceptFirstName.new
29
+ @user.first_name = nil
30
+ @user.first_name.should == nil
25
31
  end
26
32
 
27
- it "should not blow up if value is nil" do
28
- @student = Student.new
29
- @student.first_name = nil
30
- @student.first_name.should == nil
33
+ it "doesn't blow up if value is not a string" do
34
+ @user = OnlyFirstName.new
35
+ @user.first_name = 1
36
+ @user.first_name.should == 1
31
37
  end
32
38
  end
@@ -7,26 +7,26 @@ ActiveRecord::Base.establish_connection({
7
7
  })
8
8
 
9
9
  ActiveRecord::Schema.define do
10
- create_table "users", :force => true do |t|
10
+ create_table "only_first_names", :force => true do |t|
11
11
  t.column "first_name", :text
12
12
  t.column "last_name", :text
13
13
  t.column "age", :integer
14
14
  end
15
15
 
16
- create_table "students", :force => true do |t|
16
+ create_table "except_first_names", :force => true do |t|
17
17
  t.column "first_name", :text
18
18
  t.column "last_name", :text
19
19
  t.column "age", :integer
20
20
  end
21
21
  end
22
22
 
23
- class User < ActiveRecord::Base
23
+ class OnlyFirstName < ActiveRecord::Base
24
24
  include HtmlTerminator
25
25
 
26
26
  terminate_html :first_name
27
27
  end
28
28
 
29
- class Student < ActiveRecord::Base
29
+ class ExceptFirstName < ActiveRecord::Base
30
30
  include HtmlTerminator
31
31
 
32
32
  terminate_html :except => [:first_name]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: html_terminator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-11-05 00:00:00.000000000 Z
13
+ date: 2013-11-12 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler