simple_record 1.1.65 → 1.1.67

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -26,14 +26,16 @@ module SimpleRecord
26
26
  end
27
27
 
28
28
 
29
- if att_meta.options
30
- if att_meta.options[:encrypted]
29
+ unless value.blank?
30
+ if att_meta.options
31
+ if att_meta.options[:encrypted]
31
32
  # puts "ENCRYPTING #{name} value #{value}"
32
- ret = Translations.encrypt(ret, att_meta.options[:encrypted])
33
+ ret = Translations.encrypt(ret, att_meta.options[:encrypted])
33
34
  # puts 'encrypted value=' + ret.to_s
34
- end
35
- if att_meta.options[:hashed]
36
- ret = Translations.pass_hash(ret)
35
+ end
36
+ if att_meta.options[:hashed]
37
+ ret = Translations.pass_hash(ret)
38
+ end
37
39
  end
38
40
  end
39
41
 
@@ -48,7 +50,7 @@ module SimpleRecord
48
50
  return nil if value.nil?
49
51
  att_meta = defined_attributes_local[name.to_sym]
50
52
 
51
- if att_meta.options
53
+ if att_meta.options
52
54
  if att_meta.options[:encrypted]
53
55
  value = Translations.decrypt(value, att_meta.options[:encrypted])
54
56
  end
data/lib/simple_record.rb CHANGED
@@ -321,6 +321,7 @@ module SimpleRecord
321
321
  #
322
322
  def save(options={})
323
323
  # puts 'SAVING: ' + self.inspect
324
+ # todo: Clean out undefined values in @attributes (in case someone set the attributes hash with values that they hadn't defined)
324
325
  clear_errors
325
326
  # todo: decide whether this should go before pre_save or after pre_save? pre_save dirties "updated" and perhaps other items due to callbacks
326
327
  if options[:dirty]
@@ -745,6 +746,11 @@ module SimpleRecord
745
746
  @dirty = {}
746
747
  end
747
748
 
749
+ def hash
750
+ # same as ActiveRecord
751
+ id.hash
752
+ end
753
+
748
754
  end
749
755
 
750
756
 
data/test/my_model.rb CHANGED
@@ -3,7 +3,7 @@ require 'my_base_model'
3
3
 
4
4
  class MyModel < MyBaseModel
5
5
 
6
- has_strings :name, :nickname
6
+ has_strings :name, :nickname, :s1, :s2
7
7
  has_ints :age, :save_count
8
8
  has_booleans :cool
9
9
  has_dates :birthday, :date1, :date2, :date3
@@ -6,6 +6,7 @@ require "yaml"
6
6
  require 'aws'
7
7
  require 'my_model'
8
8
  require 'my_child_model'
9
+ require 'model_with_enc'
9
10
  require 'active_support'
10
11
 
11
12
  # Tests for SimpleRecord
@@ -52,6 +53,17 @@ class TestSimpleRecord < TestBase
52
53
  assert mm2.age.nil?, "doh, age is " + mm2.age.inspect
53
54
  end
54
55
 
56
+ def test_funky_values
57
+ mm = MyModel.new(:name=>"Funky")
58
+ mm.s1 = "other/2009-11-10/04/84.eml" # reported here: http://groups.google.com/group/simple-record/browse_thread/thread/3659e82491d03a2c?hl=en
59
+ assert mm.save
60
+ assert mm.errors.size == 0
61
+
62
+ mm2 = MyModel.find(mm.id)
63
+ puts 'mm2=' + mm2.inspect
64
+
65
+ end
66
+
55
67
 
56
68
  def test_create
57
69
  mm = MyModel.create(:name=>"Travis", :age=>32, :cool=>true)
@@ -559,4 +571,12 @@ class TestSimpleRecord < TestBase
559
571
 
560
572
  end
561
573
 
574
+ def test_empty_initialize
575
+ mm = MyModel.new
576
+
577
+ mme = ModelWithEnc.new
578
+ mme = ModelWithEnc.new(:ssn=>"", :password=>"") # this caused encryptor errors
579
+ mme = ModelWithEnc.new(:ssn=>nil, :password=>nil)
580
+ end
581
+
562
582
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_record
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.65
4
+ version: 1.1.67
5
5
  platform: ruby
6
6
  authors:
7
7
  - Travis Reeder
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2010-01-06 00:00:00 -08:00
14
+ date: 2010-01-23 00:00:00 -08:00
15
15
  default_executable:
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency