cleanerupper 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{cleanerupper}
8
- s.version = "0.2.0"
8
+ s.version = "0.2.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Mike Trpcic"]
12
- s.date = %q{2010-04-16}
12
+ s.date = %q{2010-04-20}
13
13
  s.email = %q{mike@fluidmedia.com}
14
14
  s.extra_rdoc_files = [
15
15
  "README.markdown"
@@ -24,6 +24,7 @@ Gem::Specification.new do |s|
24
24
  "./pkg/cleanerupper-0.0.0.gem",
25
25
  "./pkg/cleanerupper-0.1.0.gem",
26
26
  "./pkg/cleanerupper-0.1.1.gem",
27
+ "./pkg/cleanerupper-0.2.0.gem",
27
28
  "./rails/init.rb",
28
29
  "./tasks/cleanerupper_tasks.rake",
29
30
  "./test/cleanerupper_test.rb",
@@ -42,7 +42,7 @@ module Cleaner
42
42
 
43
43
  #Append the following methods to the ActiveRecord::Base class
44
44
  def bind(column, method, dictionary, callback = nil)
45
- #debugger
45
+ dictionary = [dictionary].flatten.map{|d| Cleaner::Data.dictionaries[d]}.flatten.uniq
46
46
  old_value = read_attribute(column)
47
47
  to_save = true
48
48
 
@@ -81,7 +81,7 @@ module Cleaner
81
81
 
82
82
  #This method scrambles data by rearranging the letters.
83
83
  def scramble(value, dict)
84
- Cleaner::Data.dictionaries[dict].each do |word|
84
+ dict.each do |word|
85
85
  value.to_s.gsub!(/#{word}/, word.split(//).shuffle.join(''))
86
86
  end
87
87
  value
@@ -90,7 +90,7 @@ module Cleaner
90
90
  #This method removes selected words from the string and replaces them
91
91
  #with nothing
92
92
  def remove(value, dict)
93
- Cleaner::Data.dictionaries[dict].each do |word|
93
+ dict.each do |word|
94
94
  value.to_s.gsub!(/#{word}/, "")
95
95
  end
96
96
  value
@@ -99,7 +99,7 @@ module Cleaner
99
99
  #This method removes selected words from the string and replaces them
100
100
  #with 'swear' characters,such as '#$@!%&'
101
101
  def replace(value, dict)
102
- Cleaner::Data.dictionaries[dict].each do |word|
102
+ dict.each do |word|
103
103
  value.to_s.gsub!(/#{word}/, word.split(//).map{|c| c = Cleaner::Data.replacement_chars.shuffle[0]}.join(''))
104
104
  end
105
105
  value
@@ -2,7 +2,8 @@ require File.join(File.dirname(__FILE__), 'test_helper')
2
2
 
3
3
  Cleaner::Data.dictionaries = {
4
4
  :words => ["scramble_test", "remove_test", "replace_test", "custom_test", "default_test"],
5
- :animals => ["cat_test", "dog_test", "fish_test"]
5
+ :animals => ["cat_test", "dog_test", "fish_test"],
6
+ :furniture => ["bed_test", "chair_test"]
6
7
  }
7
8
 
8
9
  class Widget < ActiveRecord::Base
@@ -59,6 +60,11 @@ class CustomDictWidget < ActiveRecord::Base
59
60
  clean :body, :with => :scramble, :dictionary => :animals
60
61
  end
61
62
 
63
+ class MultiDictWidget < ActiveRecord::Base
64
+ set_table_name :widgets
65
+ clean :body, :with => :scramble, :dictionary => [:animals, :furniture]
66
+ end
67
+
62
68
  class CleanerupperTest < Test::Unit::TestCase
63
69
 
64
70
  def test_automatically_replace
@@ -135,8 +141,18 @@ class CleanerupperTest < Test::Unit::TestCase
135
141
  w = CustomDictWidget.new(:body => body.dup)
136
142
  w.save
137
143
  w = CustomDictWidget.find(w.id)
138
- puts w.body
139
144
  assert w.body != body
140
145
  assert w.body.include?("bird_test")
141
146
  end
147
+
148
+ def test_multiple_dictionaries
149
+ body = "dog_test regular_test bed_test"
150
+ w = MultiDictWidget.new(:body => body.dup)
151
+ w.save
152
+ w = MultiDictWidget.find(w.id)
153
+ assert w.body != body
154
+ assert w.body.include?("regular_test")
155
+ assert !w.body.include?("dog_test")
156
+ assert !w.body.include?("bed_test")
157
+ end
142
158
  end
@@ -2719,3 +2719,84 @@
2719
2719
  CustomWidget Load (0.5ms) SELECT * FROM "widgets" WHERE ("widgets"."id" = 6) 
2720
2720
  ScrambleWidget Create (0.2ms) INSERT INTO "widgets" ("title", "body", "author_name") VALUES('cleanerupper tteusletfd_a body', NULL, NULL)
2721
2721
  ScrambleWidget Load (0.2ms) SELECT * FROM "widgets" WHERE ("widgets"."id" = 7) 
2722
+ SQL (0.4ms) select sqlite_version(*)
2723
+ SQL (0.8ms)  SELECT name
2724
+ FROM sqlite_master
2725
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
2726
+ 
2727
+ SQL (73.8ms) DROP TABLE "widgets"
2728
+ SQL (2.9ms) CREATE TABLE "widgets" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar(100), "body" varchar(255), "author_name" varchar(100)) 
2729
+ SQL (0.3ms)  SELECT name
2730
+ FROM sqlite_master
2731
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
2732
+ 
2733
+ SQL (0.1ms) SELECT version FROM "schema_migrations"
2734
+ RemoveWidget Create (0.4ms) INSERT INTO "widgets" ("title", "body", "author_name") VALUES('cleanerupper test', 'cleanerupper test', NULL)
2735
+ RemoveWidget Load (0.3ms) SELECT * FROM "widgets" WHERE ("widgets"."id" = 1) 
2736
+ ReplaceWidget Create (0.2ms) INSERT INTO "widgets" ("title", "body", "author_name") VALUES(NULL, 'cleanerupper *%&*@*$@!%%! test', NULL)
2737
+ ReplaceWidget Load (0.2ms) SELECT * FROM "widgets" WHERE ("widgets"."id" = 2) 
2738
+ ScrambleWidget Create (0.2ms) INSERT INTO "widgets" ("title", "body", "author_name") VALUES('cleanerupper lcs_artetbesm test', NULL, NULL)
2739
+ ScrambleWidget Load (0.2ms) SELECT * FROM "widgets" WHERE ("widgets"."id" = 3) 
2740
+ CallbackWidget Create (0.2ms) INSERT INTO "widgets" ("title", "body", "author_name") VALUES('CALLBACK', 'cleanerupper msuotet_cts body', NULL)
2741
+ CallbackWidget Load (0.3ms) SELECT * FROM "widgets" WHERE ("widgets"."id" = 4) 
2742
+ CustomDictWidget Create (0.2ms) INSERT INTO "widgets" ("title", "body", "author_name") VALUES(NULL, 'gtdte_os bird_test fehittss_', NULL)
2743
+ CustomDictWidget Load (0.3ms) SELECT * FROM "widgets" WHERE ("widgets"."id" = 5) 
2744
+ CustomWidget Create (0.2ms) INSERT INTO "widgets" ("title", "body", "author_name") VALUES('Custom Value: cleanerupper remove_test title', 'Custom Value: cleanerupper scramble_test body', NULL)
2745
+ CustomWidget Load (0.3ms) SELECT * FROM "widgets" WHERE ("widgets"."id" = 6) 
2746
+ ScrambleWidget Create (0.1ms) INSERT INTO "widgets" ("title", "body", "author_name") VALUES('cleanerupper lte_tafetdsu body', NULL, NULL)
2747
+ ScrambleWidget Load (0.2ms) SELECT * FROM "widgets" WHERE ("widgets"."id" = 7) 
2748
+ SQL (0.4ms) select sqlite_version(*)
2749
+ SQL (0.7ms)  SELECT name
2750
+ FROM sqlite_master
2751
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
2752
+ 
2753
+ SQL (41.0ms) DROP TABLE "widgets"
2754
+ SQL (4.1ms) CREATE TABLE "widgets" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar(100), "body" varchar(255), "author_name" varchar(100)) 
2755
+ SQL (0.3ms)  SELECT name
2756
+ FROM sqlite_master
2757
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
2758
+ 
2759
+ SQL (0.1ms) SELECT version FROM "schema_migrations"
2760
+ RemoveWidget Create (0.3ms) INSERT INTO "widgets" ("title", "body", "author_name") VALUES('cleanerupper test', 'cleanerupper test', NULL)
2761
+ RemoveWidget Load (0.3ms) SELECT * FROM "widgets" WHERE ("widgets"."id" = 1) 
2762
+ ReplaceWidget Create (0.2ms) INSERT INTO "widgets" ("title", "body", "author_name") VALUES(NULL, 'cleanerupper $@!&*%%@!*!% test', NULL)
2763
+ ReplaceWidget Load (0.2ms) SELECT * FROM "widgets" WHERE ("widgets"."id" = 2) 
2764
+ ScrambleWidget Create (0.3ms) INSERT INTO "widgets" ("title", "body", "author_name") VALUES('cleanerupper reteml_scbast test', NULL, NULL)
2765
+ ScrambleWidget Load (0.4ms) SELECT * FROM "widgets" WHERE ("widgets"."id" = 3) 
2766
+ CallbackWidget Create (0.2ms) INSERT INTO "widgets" ("title", "body", "author_name") VALUES('CALLBACK', 'cleanerupper tsocste_tum body', NULL)
2767
+ CallbackWidget Load (0.3ms) SELECT * FROM "widgets" WHERE ("widgets"."id" = 4) 
2768
+ CustomDictWidget Create (0.2ms) INSERT INTO "widgets" ("title", "body", "author_name") VALUES(NULL, 'tst_oged bird_test si_hfetst', NULL)
2769
+ CustomDictWidget Load (0.3ms) SELECT * FROM "widgets" WHERE ("widgets"."id" = 5) 
2770
+ CustomWidget Create (0.2ms) INSERT INTO "widgets" ("title", "body", "author_name") VALUES('Custom Value: cleanerupper remove_test title', 'Custom Value: cleanerupper scramble_test body', NULL)
2771
+ CustomWidget Load (0.3ms) SELECT * FROM "widgets" WHERE ("widgets"."id" = 6) 
2772
+ ScrambleWidget Create (0.2ms) INSERT INTO "widgets" ("title", "body", "author_name") VALUES('cleanerupper etatl_sedfut body', NULL, NULL)
2773
+ ScrambleWidget Load (0.3ms) SELECT * FROM "widgets" WHERE ("widgets"."id" = 7) 
2774
+ MultiDictWidget Create (0.2ms) INSERT INTO "widgets" ("title", "body", "author_name") VALUES(NULL, 'tetdos_g regular_test ebted_st', NULL)
2775
+ SQL (0.7ms) select sqlite_version(*)
2776
+ SQL (0.8ms)  SELECT name
2777
+ FROM sqlite_master
2778
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
2779
+ 
2780
+ SQL (71.9ms) DROP TABLE "widgets"
2781
+ SQL (3.2ms) CREATE TABLE "widgets" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar(100), "body" varchar(255), "author_name" varchar(100)) 
2782
+ SQL (0.3ms)  SELECT name
2783
+ FROM sqlite_master
2784
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
2785
+ 
2786
+ SQL (0.1ms) SELECT version FROM "schema_migrations"
2787
+ RemoveWidget Create (0.3ms) INSERT INTO "widgets" ("title", "body", "author_name") VALUES('cleanerupper test', 'cleanerupper test', NULL)
2788
+ RemoveWidget Load (0.3ms) SELECT * FROM "widgets" WHERE ("widgets"."id" = 1) 
2789
+ ReplaceWidget Create (0.2ms) INSERT INTO "widgets" ("title", "body", "author_name") VALUES(NULL, 'cleanerupper !&%@$%!!*@*@ test', NULL)
2790
+ ReplaceWidget Load (0.3ms) SELECT * FROM "widgets" WHERE ("widgets"."id" = 2) 
2791
+ ScrambleWidget Create (0.2ms) INSERT INTO "widgets" ("title", "body", "author_name") VALUES('cleanerupper lascbe_tetmrs test', NULL, NULL)
2792
+ ScrambleWidget Load (0.3ms) SELECT * FROM "widgets" WHERE ("widgets"."id" = 3) 
2793
+ CallbackWidget Create (0.2ms) INSERT INTO "widgets" ("title", "body", "author_name") VALUES('CALLBACK', 'cleanerupper tm_setcstuo body', NULL)
2794
+ CallbackWidget Load (0.2ms) SELECT * FROM "widgets" WHERE ("widgets"."id" = 4) 
2795
+ CustomDictWidget Create (0.2ms) INSERT INTO "widgets" ("title", "body", "author_name") VALUES(NULL, '_tedsogt bird_test eifths_st', NULL)
2796
+ CustomDictWidget Load (0.3ms) SELECT * FROM "widgets" WHERE ("widgets"."id" = 5) 
2797
+ CustomWidget Create (0.2ms) INSERT INTO "widgets" ("title", "body", "author_name") VALUES('Custom Value: cleanerupper remove_test title', 'Custom Value: cleanerupper scramble_test body', NULL)
2798
+ CustomWidget Load (0.3ms) SELECT * FROM "widgets" WHERE ("widgets"."id" = 6) 
2799
+ ScrambleWidget Create (0.2ms) INSERT INTO "widgets" ("title", "body", "author_name") VALUES('cleanerupper tdtaflt_suee body', NULL, NULL)
2800
+ ScrambleWidget Load (0.2ms) SELECT * FROM "widgets" WHERE ("widgets"."id" = 7) 
2801
+ MultiDictWidget Create (0.2ms) INSERT INTO "widgets" ("title", "body", "author_name") VALUES(NULL, 'stdotge_ regular_test tb_edtse', NULL)
2802
+ MultiDictWidget Load (0.3ms) SELECT * FROM "widgets" WHERE ("widgets"."id" = 8) 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 0
9
- version: 0.2.0
8
+ - 1
9
+ version: 0.2.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Mike Trpcic
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-16 00:00:00 -04:00
17
+ date: 2010-04-20 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
@@ -36,6 +36,7 @@ files:
36
36
  - ./pkg/cleanerupper-0.0.0.gem
37
37
  - ./pkg/cleanerupper-0.1.0.gem
38
38
  - ./pkg/cleanerupper-0.1.1.gem
39
+ - ./pkg/cleanerupper-0.2.0.gem
39
40
  - ./rails/init.rb
40
41
  - ./tasks/cleanerupper_tasks.rake
41
42
  - ./test/cleanerupper_test.rb