active_hash 0.10.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +3 -0
- data/lib/active_hash/base.rb +9 -1
- data/lib/active_hash/version.rb +1 -1
- data/spec/active_hash/base_spec.rb +10 -0
- metadata +2 -2
data/CHANGELOG
CHANGED
data/lib/active_hash/base.rb
CHANGED
@@ -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.
|
453
|
+
unless self.class.exists?(self)
|
454
|
+
self.class.insert(self)
|
455
|
+
end
|
448
456
|
true
|
449
457
|
end
|
450
458
|
|
data/lib/active_hash/version.rb
CHANGED
@@ -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.
|
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:
|
155
|
+
hash: -1921449152937241746
|
156
156
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
157
157
|
none: false
|
158
158
|
requirements:
|