active_hash 0.10.0 → 1.0.0

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.
data/CHANGELOG CHANGED
@@ -1,3 +1,6 @@
1
+ 2013-06-24 (v1.0.0)
2
+ - save is a no-op on existing records, instead of raising an error (issue #63)
3
+
1
4
  2013-06-24 (v0.10.0)
2
5
  - added ActiveYaml::Aliases module so you can DRY up your repetitive yaml (brett-richardson)
3
6
 
@@ -67,6 +67,12 @@ module ActiveHash
67
67
  end
68
68
  end
69
69
 
70
+ def exists?(record)
71
+ if record.id.present?
72
+ record_index[record.id.to_s].present?
73
+ end
74
+ end
75
+
70
76
  def insert(record)
71
77
  @records ||= []
72
78
  record.attributes[:id] ||= next_id
@@ -444,7 +450,9 @@ module ActiveHash
444
450
  end
445
451
 
446
452
  def save(*args)
447
- self.class.insert(self)
453
+ unless self.class.exists?(self)
454
+ self.class.insert(self)
455
+ end
448
456
  true
449
457
  end
450
458
 
@@ -1,5 +1,5 @@
1
1
  module ActiveHash
2
2
  module Gem
3
- VERSION = "0.10.0"
3
+ VERSION = "1.0.0"
4
4
  end
5
5
  end
@@ -898,6 +898,16 @@ describe ActiveHash, "Base" do
898
898
  Country.dirty.should be_true
899
899
  end
900
900
 
901
+ it "it is a no-op if the object has already been added to the collection" do
902
+ Country.all.should be_empty
903
+ country = Country.new :id => 1, :name => "foo"
904
+ country.save
905
+ country.name = "bar"
906
+ country.save
907
+ country.save!
908
+ Country.all.should == [country]
909
+ end
910
+
901
911
  end
902
912
 
903
913
  describe ".create" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_hash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -152,7 +152,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
152
152
  version: '0'
153
153
  segments:
154
154
  - 0
155
- hash: 514643025697724371
155
+ hash: -1921449152937241746
156
156
  required_rubygems_version: !ruby/object:Gem::Requirement
157
157
  none: false
158
158
  requirements: