test/cleaners_test.rb in data_cleansing-0.9.0 vs test/cleaners_test.rb in data_cleansing-1.0.0

- old
+ new

@@ -6,11 +6,12 @@ include DataCleansing::Cleanse attr_accessor :first_name, :last_name, :address1, :address2, :make_this_upper, :clean_non_word, :clean_non_printable, :clean_html, :clean_from_uri, :clean_to_uri, :clean_whitespace, - :clean_digits_only, :clean_to_integer, :clean_to_float, :clean_end_of_day + :clean_digits_only, :clean_to_integer, :clean_to_float, :clean_end_of_day, + :clean_order cleanse :first_name, :last_name, :address1, :address2, cleaner: :strip cleanse :make_this_upper, cleaner: :upcase cleanse :clean_non_word, cleaner: :remove_non_word cleanse :clean_non_printable, cleaner: :remove_non_printable @@ -20,10 +21,14 @@ cleanse :clean_whitespace, cleaner: :compress_whitespace cleanse :clean_digits_only, cleaner: :digits_only cleanse :clean_to_integer, cleaner: :string_to_integer cleanse :clean_to_float, cleaner: :string_to_float cleanse :clean_end_of_day, cleaner: :end_of_day + + # Call cleaners in the order they are defined + cleanse :clean_order, cleaner: [:upcase, :strip] + cleanse :clean_order, cleaner: -> val { val == 'BLAH' ? ' yes ' : ' no ' } end describe 'Cleaners' do it '#strip' do user = User.new @@ -138,21 +143,21 @@ assert_equal ' ', user.clean_from_uri end end describe '#escape_uri' do - it 'converts %20' do + it 'converts spaces' do user = User.new user.clean_to_uri = 'Jim Bob ' user.cleanse_attributes! - assert_equal 'Jim%20%20Bob%20', user.clean_to_uri + assert_equal 'Jim++Bob+', user.clean_to_uri end - it 'converts %20 only' do + it 'converts space only' do user = User.new user.clean_to_uri = ' ' user.cleanse_attributes! - assert_equal '%20', user.clean_to_uri + assert_equal '+', user.clean_to_uri end end describe '#compress_whitespace' do it 'compresses multiple spaces' do @@ -201,9 +206,16 @@ it '#date_to_time_at_end_of_day' do user = User.new user.clean_end_of_day = Time.parse('2016-03-03 14:33:44 +0000') user.cleanse_attributes! assert_equal Time.parse('2016-03-03 23:59:59 +0000').to_i, user.clean_end_of_day.to_i + end + + it 'cleans in the order defined' do + user = User.new + user.clean_order = ' blah ' + user.cleanse_attributes! + assert_equal ' yes ', user.clean_order end end end