active_remote 1.3.0 → 1.3.1
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/.gitignore
CHANGED
@@ -39,7 +39,9 @@ module ActiveRemote
|
|
39
39
|
#
|
40
40
|
def belongs_to(belongs_to_klass, options={})
|
41
41
|
perform_association( belongs_to_klass, options ) do |klass, obj|
|
42
|
-
|
42
|
+
foreign_key = options.fetch(:foreign_key) { :"#{belongs_to_klass}_guid" }
|
43
|
+
association_guid = obj.read_attribute(foreign_key)
|
44
|
+
klass.search(:guid => association_guid).first
|
43
45
|
end
|
44
46
|
end
|
45
47
|
|
@@ -75,7 +77,8 @@ module ActiveRemote
|
|
75
77
|
#
|
76
78
|
def has_many(has_many_class, options={})
|
77
79
|
perform_association( has_many_class, options ) do |klass, obj|
|
78
|
-
|
80
|
+
foreign_key = options.fetch(:foreign_key) { :"#{obj.class.name.demodulize.underscore}_guid" }
|
81
|
+
klass.search(foreign_key => obj.guid)
|
79
82
|
end
|
80
83
|
end
|
81
84
|
|
@@ -110,7 +113,8 @@ module ActiveRemote
|
|
110
113
|
#
|
111
114
|
def has_one(has_one_klass, options={})
|
112
115
|
perform_association( has_one_klass, options ) do |klass, obj|
|
113
|
-
|
116
|
+
foreign_key = options.fetch(:foreign_key) { :"#{obj.class.name.demodulize.underscore}_guid" }
|
117
|
+
klass.search(foreign_key => obj.guid).first
|
114
118
|
end
|
115
119
|
end
|
116
120
|
|
@@ -17,7 +17,7 @@ describe ActiveRemote::Association do
|
|
17
17
|
subject.author.should eq record
|
18
18
|
end
|
19
19
|
|
20
|
-
it '
|
20
|
+
it 'memoizes the result record' do
|
21
21
|
Author.should_receive(:search).once.with(:guid => subject.author_guid).and_return(records)
|
22
22
|
3.times { subject.author.should eq record }
|
23
23
|
end
|
@@ -42,6 +42,18 @@ describe ActiveRemote::Association do
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
+
context 'specific association with class name and foreign_key' do
|
46
|
+
let(:author_guid) { 'AUT-456' }
|
47
|
+
|
48
|
+
subject { Post.new(:author_guid => author_guid) }
|
49
|
+
it { should respond_to(:bestseller) }
|
50
|
+
|
51
|
+
it 'searches the associated model for a single record' do
|
52
|
+
Author.should_receive(:search).with(:guid => subject.bestseller_guid).and_return(records)
|
53
|
+
subject.author.should eq record
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
45
57
|
end
|
46
58
|
|
47
59
|
describe '.has_many' do
|
@@ -76,6 +88,15 @@ describe ActiveRemote::Association do
|
|
76
88
|
subject.flagged_posts.should be_empty
|
77
89
|
end
|
78
90
|
end
|
91
|
+
|
92
|
+
context 'specific association with class name and foreign_key' do
|
93
|
+
it { should respond_to(:bestseller_posts) }
|
94
|
+
|
95
|
+
it 'searches the associated model for multiple record' do
|
96
|
+
Post.should_receive(:search).with(:bestseller_guid => subject.guid).and_return(records)
|
97
|
+
subject.bestseller_posts.should eq(records)
|
98
|
+
end
|
99
|
+
end
|
79
100
|
end
|
80
101
|
|
81
102
|
describe '.has_one' do
|
@@ -109,6 +130,15 @@ describe ActiveRemote::Association do
|
|
109
130
|
subject.main_category.should eq record
|
110
131
|
end
|
111
132
|
end
|
133
|
+
|
134
|
+
context 'specific association with class name and foreign_key' do
|
135
|
+
it { should respond_to(:default_category) }
|
136
|
+
|
137
|
+
it 'searches the associated model for a single record' do
|
138
|
+
Category.should_receive(:search).with(:template_post_guid => subject.guid).and_return(records)
|
139
|
+
subject.default_category.should eq record
|
140
|
+
end
|
141
|
+
end
|
112
142
|
end
|
113
143
|
|
114
144
|
end
|
data/spec/support/models/post.rb
CHANGED
@@ -11,8 +11,11 @@ class Post < ::ActiveRemote::Base
|
|
11
11
|
attribute :author_guid
|
12
12
|
|
13
13
|
belongs_to :author
|
14
|
-
belongs_to :coauthor, :class_name => ::Author
|
14
|
+
belongs_to :coauthor, :class_name => '::Author'
|
15
|
+
belongs_to :bestseller, :class_name => '::Author', :foreign_key => :bestseller_guid
|
15
16
|
has_one :category
|
16
|
-
has_one :main_category, :class_name => ::Category
|
17
|
+
has_one :main_category, :class_name => '::Category'
|
18
|
+
has_one :default_category, :class_name => '::Category', :foreign_key => :template_post_guid
|
17
19
|
|
20
|
+
alias_method :bestseller_guid, :author_guid
|
18
21
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_remote
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-01-
|
12
|
+
date: 2013-01-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: active_attr
|
@@ -218,7 +218,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
218
218
|
version: '0'
|
219
219
|
segments:
|
220
220
|
- 0
|
221
|
-
hash:
|
221
|
+
hash: 760636464474141912
|
222
222
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
223
223
|
none: false
|
224
224
|
requirements:
|
@@ -227,7 +227,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
227
227
|
version: '0'
|
228
228
|
segments:
|
229
229
|
- 0
|
230
|
-
hash:
|
230
|
+
hash: 760636464474141912
|
231
231
|
requirements: []
|
232
232
|
rubyforge_project:
|
233
233
|
rubygems_version: 1.8.24
|