simply_stored 0.3.7 → 0.3.8

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,6 +1,10 @@
1
1
  Changelog
2
2
  =============
3
3
 
4
+ 0.3.8
5
+
6
+ - Fix loading of has_many/has_one associations for inherited relations.
7
+
4
8
  - Pre-populate the parent object on has_many and has_one associations so that user.posts.first.user
5
9
  doesn't reload the user.
6
10
 
@@ -163,7 +163,7 @@ module SimplyStored
163
163
  :dependent => :nullify,
164
164
  :through => nil,
165
165
  :class_name => name.to_s.singularize.camelize,
166
- :foreign_key => owner_clazz.name.singularize.underscore.foreign_key
166
+ :foreign_key => nil
167
167
  }.update(options)
168
168
  @name, @options = name, options
169
169
 
@@ -64,7 +64,7 @@ module SimplyStored
64
64
  options = {
65
65
  :dependent => :nullify,
66
66
  :class_name => name.to_s.singularize.camelize,
67
- :foreign_key => owner_clazz.name.singularize.underscore.foreign_key
67
+ :foreign_key => nil
68
68
  }.update(options)
69
69
  @name, @options = name, options
70
70
 
@@ -175,7 +175,7 @@ module SimplyStored
175
175
  end
176
176
 
177
177
  def find_associated(from, to, options = {})
178
- foreign_key = options.delete(:foreign_key).gsub(/_id$/, '')
178
+ foreign_key = (options.delete(:foreign_key) || self.class.name.singularize.underscore.foreign_key ).gsub(/_id$/, '')
179
179
  view_options = {}
180
180
  view_options[:reduce] = false
181
181
  view_options[:descending] = options[:descending] if options[:descending]
data/lib/simply_stored.rb CHANGED
@@ -4,7 +4,7 @@ require File.expand_path(File.dirname(__FILE__) + '/simply_stored/storage')
4
4
  require File.expand_path(File.dirname(__FILE__) + '/simply_stored/class_methods_base')
5
5
 
6
6
  module SimplyStored
7
- VERSION = '0.3.7'
7
+ VERSION = '0.3.8'
8
8
  class Error < RuntimeError; end
9
9
  class RecordNotFound < RuntimeError; end
10
10
  end
@@ -155,6 +155,15 @@ class CouchHasManyTest < Test::Unit::TestCase
155
155
  assert_equal [post], user.posts(:force_reload => true)
156
156
  end
157
157
 
158
+ should "use the correct view when handling inheritance" do
159
+ problem = Problem.create
160
+ big_problem = BigProblem.create
161
+ issue = Issue.create(:name => 'Thing', :problem => problem)
162
+ assert_equal 1, problem.issues.size
163
+ issue.update_attributes(:problem_id => nil, :big_problem_id => big_problem.id)
164
+ assert_equal 1, big_problem.issues.size
165
+ end
166
+
158
167
  context "when adding items" do
159
168
  should "add the item to the internal cache" do
160
169
  daddy = User.new(:title => "Mr.")
@@ -26,6 +26,15 @@ class CouchHasOneTest < Test::Unit::TestCase
26
26
  assert_equal instance, instance.identity.instance
27
27
  end
28
28
 
29
+ should "use the correct view when handling inheritance" do
30
+ problem = Problem.create
31
+ big_problem = BigProblem.create
32
+ issue = Issue.create(:name => 'Thing', :problem => problem)
33
+ assert_equal issue, problem.issue
34
+ issue.update_attributes(:problem_id => nil, :big_problem_id => big_problem.id)
35
+ assert_equal issue, big_problem.issue
36
+ end
37
+
29
38
  should "verify the given options for the accessor method" do
30
39
  instance = Instance.create
31
40
  assert_raise(ArgumentError) do
@@ -208,3 +208,24 @@ class Servant
208
208
 
209
209
  belongs_to :master
210
210
  end
211
+
212
+ class Issue
213
+ include SimplyStored::Couch
214
+
215
+ belongs_to :problem
216
+ belongs_to :big_problem
217
+
218
+ property :name
219
+ end
220
+
221
+ class Problem
222
+ include SimplyStored::Couch
223
+
224
+ has_many :issues
225
+ has_one :issue
226
+ end
227
+
228
+ class BigProblem < Problem
229
+
230
+ end
231
+
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simply_stored
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 3
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 7
10
- version: 0.3.7
9
+ - 8
10
+ version: 0.3.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - Mathias Meyer, Jonathan Weiss