aboutsummaryrefslogtreecommitdiffstats
path: root/lib/strip_attributes/test/strip_attributes_test.rb
diff options
context:
space:
mode:
authorMark Longair <mhl@pobox.com>2013-11-28 14:36:36 +0000
committerMark Longair <mhl@pobox.com>2013-11-29 12:22:59 +0000
commit600c3b356d804546bfa31fef89979cc1c44f3756 (patch)
treea2e45e35346601236fb92bff70a56989d9161f62 /lib/strip_attributes/test/strip_attributes_test.rb
parent20089cf7b5045d504b7240bc92e2b6068fcc2246 (diff)
Move strip_attributes out of vendor/plugins
Diffstat (limited to 'lib/strip_attributes/test/strip_attributes_test.rb')
-rw-r--r--lib/strip_attributes/test/strip_attributes_test.rb90
1 files changed, 90 insertions, 0 deletions
diff --git a/lib/strip_attributes/test/strip_attributes_test.rb b/lib/strip_attributes/test/strip_attributes_test.rb
new file mode 100644
index 000000000..8158dc664
--- /dev/null
+++ b/lib/strip_attributes/test/strip_attributes_test.rb
@@ -0,0 +1,90 @@
+require "#{File.dirname(__FILE__)}/test_helper"
+
+module MockAttributes
+ def self.included(base)
+ base.column :foo, :string
+ base.column :bar, :string
+ base.column :biz, :string
+ base.column :baz, :string
+ end
+end
+
+class StripAllMockRecord < ActiveRecord::Base
+ include MockAttributes
+ strip_attributes!
+end
+
+class StripOnlyOneMockRecord < ActiveRecord::Base
+ include MockAttributes
+ strip_attributes! :only => :foo
+end
+
+class StripOnlyThreeMockRecord < ActiveRecord::Base
+ include MockAttributes
+ strip_attributes! :only => [:foo, :bar, :biz]
+end
+
+class StripExceptOneMockRecord < ActiveRecord::Base
+ include MockAttributes
+ strip_attributes! :except => :foo
+end
+
+class StripExceptThreeMockRecord < ActiveRecord::Base
+ include MockAttributes
+ strip_attributes! :except => [:foo, :bar, :biz]
+end
+
+class StripAttributesTest < Test::Unit::TestCase
+ def setup
+ @init_params = { :foo => "\tfoo", :bar => "bar \t ", :biz => "\tbiz ", :baz => "" }
+ end
+
+ def test_should_exist
+ assert Object.const_defined?(:StripAttributes)
+ end
+
+ def test_should_strip_all_fields
+ record = StripAllMockRecord.new(@init_params)
+ record.valid?
+ assert_equal "foo", record.foo
+ assert_equal "bar", record.bar
+ assert_equal "biz", record.biz
+ assert_equal "", record.baz
+ end
+
+ def test_should_strip_only_one_field
+ record = StripOnlyOneMockRecord.new(@init_params)
+ record.valid?
+ assert_equal "foo", record.foo
+ assert_equal "bar \t ", record.bar
+ assert_equal "\tbiz ", record.biz
+ assert_equal "", record.baz
+ end
+
+ def test_should_strip_only_three_fields
+ record = StripOnlyThreeMockRecord.new(@init_params)
+ record.valid?
+ assert_equal "foo", record.foo
+ assert_equal "bar", record.bar
+ assert_equal "biz", record.biz
+ assert_equal "", record.baz
+ end
+
+ def test_should_strip_all_except_one_field
+ record = StripExceptOneMockRecord.new(@init_params)
+ record.valid?
+ assert_equal "\tfoo", record.foo
+ assert_equal "bar", record.bar
+ assert_equal "biz", record.biz
+ assert_equal "", record.baz
+ end
+
+ def test_should_strip_all_except_three_fields
+ record = StripExceptThreeMockRecord.new(@init_params)
+ record.valid?
+ assert_equal "\tfoo", record.foo
+ assert_equal "bar \t ", record.bar
+ assert_equal "\tbiz ", record.biz
+ assert_equal "", record.baz
+ end
+end