active_hash 0.9.6 → 0.9.7

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,6 @@
1
+ 2011-09-18 (v0.9.7)
2
+ - Fixing the setting of a belongs_to_active_hash association by association (not id).
3
+
1
4
  2011-08-31
2
5
  - added a module which adds a .belongs_to_active_hash method to ActiveRecord, since it was broken for Rails 3.1 (thanks to felixclack for pointing this issue out)
3
6
 
data/README.md CHANGED
@@ -4,7 +4,7 @@ ActiveHash is a simple base class that allows you to use a ruby hash as a readon
4
4
 
5
5
  ActiveHash assumes that every hash has an :id key, which is what you would probably store in a database. This allows you to seemlessly upgrade from ActiveHash objects to full ActiveRecord objects without having to change any code in your app, or any foreign keys in your database.
6
6
 
7
- It also allows you to use #has_many and #belongs_to in your AR objects.
7
+ It also allows you to use #has_many and #belongs_to (via belongs_to_active_hash) in your AR objects.
8
8
 
9
9
  ActiveHash can also be useful to create simple test classes that run without a database - ideal for testing plugins or gems that rely on simple AR behavior, but don't want to deal with databases or migrations for the spec suite.
10
10
 
data/active_hash.gemspec CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |s|
26
26
  "Vladimir Andrijevik",
27
27
  "Adam Anderson"
28
28
  ]
29
- s.date = %q{2011-08-31}
29
+ s.date = %q{2011-09-18}
30
30
  s.email = %q{jeff@zilkey.com}
31
31
  s.extra_rdoc_files = [
32
32
  "LICENSE",
@@ -1,5 +1,5 @@
1
1
  module ActiveHash
2
2
  module Gem
3
- VERSION = "0.9.6"
3
+ VERSION = "0.9.7"
4
4
  end
5
5
  end
@@ -14,7 +14,7 @@ module ActiveHash
14
14
  end
15
15
 
16
16
  define_method("#{association_id}=") do |new_value|
17
- attributes[options[:foreign_key].to_sym] = new_value ? new_value.id : nil
17
+ send "#{options[:foreign_key]}=", new_value ? new_value.id : nil
18
18
  end
19
19
  end
20
20
 
@@ -97,20 +97,36 @@ describe ActiveHash::Base, "associations" do
97
97
  describe ActiveHash::Associations::ActiveRecordExtensions do
98
98
 
99
99
  describe "#belongs_to_active_hash" do
100
- it "finds the correct records" do
101
- School.belongs_to_active_hash :city
102
- city = City.create
103
- school = School.create :city_id => city.id
104
- school.city.should == city
105
- end
106
-
107
- it "returns nil when the record does not exist" do
108
- School.belongs_to_active_hash :city
109
- school = School.create! :city_id => nil
110
- school.city.should be_nil
100
+ context "setting by id" do
101
+ it "finds the correct records" do
102
+ School.belongs_to_active_hash :city
103
+ city = City.create
104
+ school = School.create :city_id => city.id
105
+ school.city.should == city
106
+ end
107
+
108
+ it "returns nil when the record does not exist" do
109
+ School.belongs_to_active_hash :city
110
+ school = School.create! :city_id => nil
111
+ school.city.should be_nil
112
+ end
113
+ end
114
+
115
+ context "setting by association" do
116
+ it "finds the correct records" do
117
+ School.belongs_to_active_hash :city
118
+ city = City.create
119
+ school = School.create :city => city
120
+ school.city.should == city
121
+ end
122
+
123
+ it "returns nil when the record does not exist" do
124
+ School.belongs_to_active_hash :city
125
+ school = School.create! :city => nil
126
+ school.city.should be_nil
127
+ end
111
128
  end
112
129
  end
113
-
114
130
  end
115
131
 
116
132
  describe "#belongs_to" do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_hash
3
3
  version: !ruby/object:Gem::Version
4
- hash: 55
4
+ hash: 53
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
- - 6
10
- version: 0.9.6
9
+ - 7
10
+ version: 0.9.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jeff Dean
@@ -30,7 +30,7 @@ autorequire:
30
30
  bindir: bin
31
31
  cert_chain: []
32
32
 
33
- date: 2011-08-31 00:00:00 -06:00
33
+ date: 2011-09-18 00:00:00 -04:00
34
34
  default_executable:
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
@@ -63,13 +63,13 @@ files:
63
63
  - LICENSE
64
64
  - README.md
65
65
  - active_hash.gemspec
66
- - lib/active_file/base.rb
67
- - lib/active_hash/base.rb
68
- - lib/active_hash/version.rb
66
+ - lib/enum/enum.rb
69
67
  - lib/active_hash.rb
70
68
  - lib/active_yaml/base.rb
69
+ - lib/active_file/base.rb
70
+ - lib/active_hash/version.rb
71
+ - lib/active_hash/base.rb
71
72
  - lib/associations/associations.rb
72
- - lib/enum/enum.rb
73
73
  - Gemfile
74
74
  - spec/active_file/base_spec.rb
75
75
  - spec/active_hash/base_spec.rb
@@ -108,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
108
  requirements: []
109
109
 
110
110
  rubyforge_project:
111
- rubygems_version: 1.6.2
111
+ rubygems_version: 1.6.0
112
112
  signing_key:
113
113
  specification_version: 3
114
114
  summary: An ActiveRecord-like model that uses a hash or file as a datasource