api_resource 0.6.6 → 0.6.7
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/Gemfile.lock +1 -1
- data/lib/api_resource/associations/association_proxy.rb +1 -1
- data/lib/api_resource/associations/single_object_proxy.rb +7 -6
- data/lib/api_resource/finders/single_finder.rb +1 -0
- data/lib/api_resource/version.rb +1 -1
- data/spec/lib/associations/has_one_remote_object_proxy_spec.rb +0 -1
- data/spec/lib/base_spec.rb +66 -17
- metadata +2 -2
data/Gemfile.lock
CHANGED
@@ -14,12 +14,13 @@ module ApiResource
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def internal_object
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
17
|
+
# we are already loaded - return the internal object
|
18
|
+
if self.loaded?
|
19
|
+
return @internal_object
|
20
|
+
elsif self.remote_path.present?
|
21
|
+
@internal_object = self.load
|
22
|
+
else
|
23
|
+
nil
|
23
24
|
end
|
24
25
|
end
|
25
26
|
|
data/lib/api_resource/version.rb
CHANGED
data/spec/lib/base_spec.rb
CHANGED
@@ -11,31 +11,51 @@ describe "Base" do
|
|
11
11
|
HasManyObject.reload_resource_definition
|
12
12
|
end
|
13
13
|
|
14
|
-
context ".new_element_path" do
|
15
14
|
|
16
|
-
|
15
|
+
context ".instantiate_record" do
|
17
16
|
|
18
|
-
|
19
|
-
|
20
|
-
end
|
17
|
+
context "should handle blank associations and not load them
|
18
|
+
afterwards" do
|
21
19
|
|
22
|
-
|
23
|
-
|
20
|
+
it "belongs_to_remote" do
|
21
|
+
tr = TestResource.instantiate_record(
|
22
|
+
:name => "X",
|
23
|
+
:belongs_to_object => nil
|
24
|
+
)
|
25
|
+
# load our resource definition so we can say we never expect a
|
26
|
+
# get
|
27
|
+
BelongsToObject.reload_resource_definition
|
28
|
+
BelongsToObject.connection.expects(:get).never
|
29
|
+
|
30
|
+
tr.belongs_to_object?.should be false
|
24
31
|
end
|
25
32
|
|
26
|
-
|
33
|
+
it "has_one_remote" do
|
34
|
+
tr = TestResource.instantiate_record(
|
35
|
+
:name => "X",
|
36
|
+
:has_one_object => nil
|
37
|
+
)
|
38
|
+
# load our resource definition so we can say we never expect a
|
39
|
+
# get
|
40
|
+
HasOneObject.reload_resource_definition
|
41
|
+
HasOneObject.connection.expects(:get).never
|
27
42
|
|
43
|
+
tr.has_one_object?.should be false
|
44
|
+
end
|
28
45
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
46
|
+
it "has_many_remote" do
|
47
|
+
tr = TestResource.instantiate_record(
|
48
|
+
:name => "X",
|
49
|
+
:has_many_objects => []
|
50
|
+
)
|
51
|
+
# load our resource definition so we can say we never expect a
|
52
|
+
# get
|
53
|
+
HasManyObject.reload_resource_definition
|
54
|
+
HasManyObject.connection.expects(:get).never
|
55
|
+
|
56
|
+
tr.has_many_objects?.should be false
|
57
|
+
end
|
34
58
|
|
35
|
-
it "should return a non-nested path if there are nested ids" do
|
36
|
-
DynamicPrefixResource.new_element_path.should eql(
|
37
|
-
"/dynamic_prefix_resources/new.json"
|
38
|
-
)
|
39
59
|
end
|
40
60
|
|
41
61
|
end
|
@@ -61,6 +81,35 @@ describe "Base" do
|
|
61
81
|
|
62
82
|
end
|
63
83
|
|
84
|
+
context ".new_element_path" do
|
85
|
+
|
86
|
+
before(:all) do
|
87
|
+
|
88
|
+
PrefixResource = Class.new(ApiResource::Base) do
|
89
|
+
self.prefix = "/path/to/project"
|
90
|
+
end
|
91
|
+
|
92
|
+
DynamicPrefixResource = Class.new(ApiResource::Base) do
|
93
|
+
self.prefix = "/path/to/nested/:id/"
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
|
99
|
+
it "should return a full path if there are no nested ids" do
|
100
|
+
PrefixResource.new_element_path.should eql(
|
101
|
+
"/path/to/project/prefix_resources/new.json"
|
102
|
+
)
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should return a non-nested path if there are nested ids" do
|
106
|
+
DynamicPrefixResource.new_element_path.should eql(
|
107
|
+
"/dynamic_prefix_resources/new.json"
|
108
|
+
)
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
|
64
113
|
context "#method_missing" do
|
65
114
|
|
66
115
|
after(:all) do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api_resource
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2013-04-
|
14
|
+
date: 2013-04-18 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: rake
|