Skip to content
Browse files

Adding support for symbols in fields.

  • Loading branch information...
1 parent fae1f14 commit aea997aff6465e9579200a2e53a109d71fc1fdf0 @JEG2 committed
Showing with 18 additions and 3 deletions.
  1. +2 −0 .gitignore
  2. +2 −1 lib/rrdb.rb
  3. +14 −2 test/tc_update.rb
View
2 .gitignore
@@ -1 +1,3 @@
doc
+.DS_Store
+**/.DS_Store
View
3 lib/rrdb.rb
@@ -136,7 +136,8 @@ def self.config(hash_or_key = nil)
# the values your application prefers.
#
def self.field_name(name)
- name.to_s.delete("^a-zA-Z0-9_")[0..18]
+ name.to_s.tr( "-~!@\#$%^&*+=|<>./?",
+ "mtbahdpcnmveplgddq" ).delete("^a-zA-Z0-9_")[0..18]
end
#
View
16 test/tc_update.rb
@@ -48,10 +48,22 @@ def test_running_out_of_fields_to_claim_raises_fields_exhausted_error
end
def test_unsupported_characters_are_removed_from_names
- @db.update(Time.now, "a'b=" => 4)
+ @db.update(Time.now, "a'b)" => 4)
assert(@db.fields.include?("ab"), "Trimmed field name not found.")
end
+ def test_common_symbols_are_translated
+ @db.update(Time.now, '~ z ! @#$%^&*-+=|<>./?' => 4)
+ assert( @db.fields.include?("tzbahdpcnmmveplgddq"),
+ "Common symbols were not translated." )
+ end
+
+ def test_fields_that_differ_only_by_symbol
+ @db.update(Time.now, "Swap Used" => 1, "% Swap Used" => 2)
+ assert(@db.fields.include?("SwapUsed"), "Non-symbol field was not found.")
+ assert(@db.fields.include?("pSwapUsed"), "Symbol field was not found.")
+ end
+
def test_long_field_names_are_shortened_on_entry
@db.update(Time.now, ("a".."z").to_a.join => 5)
assert( @db.fields.include?(("a".."z").to_a.join[0..18]),
@@ -63,7 +75,7 @@ def test_field_names_must_be_at_least_one_supported_character_long
@db.update(Time.now, String.new => 6)
end
assert_raise(RRDB::FieldNameConflictError) do
- @db.update(Time.now, "!@\#$%^&*" => 7)
+ @db.update(Time.now, "`(){}[]'" => 7)
end
end

0 comments on commit aea997a

Please sign in to comment.
Something went wrong with that request. Please try again.