api_resource 0.6.6 → 0.6.7

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- api_resource (0.6.4)
4
+ api_resource (0.6.7)
5
5
  colorize
6
6
  differ
7
7
  json
@@ -34,7 +34,7 @@ module ApiResource
34
34
  instance = #{self}.new(
35
35
  #{associated_class}, self, #{opts}
36
36
  )
37
- if @attributes[:#{assoc_name}].present?
37
+ if @attributes.key?(:#{assoc_name})
38
38
  instance.internal_object = @attributes[:#{assoc_name}]
39
39
  end
40
40
  instance
@@ -14,12 +14,13 @@ module ApiResource
14
14
  end
15
15
 
16
16
  def internal_object
17
- @internal_object ||= begin
18
- if self.remote_path.present? && !self.loaded?
19
- self.load
20
- else
21
- nil
22
- end
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
 
@@ -6,6 +6,7 @@ module ApiResource
6
6
 
7
7
  def load
8
8
  data = self.klass.connection.get(self.build_load_path)
9
+
9
10
  @loaded = true
10
11
  return nil if data.blank?
11
12
  @internal_object = self.klass.instantiate_record(data)
@@ -1,3 +1,3 @@
1
1
  module ApiResource
2
- VERSION = "0.6.6"
2
+ VERSION = "0.6.7"
3
3
  end
@@ -17,7 +17,6 @@ module ApiResource
17
17
  tr = TestResource.new(
18
18
  :has_one_object => {:service_uri => "/has_one_objects/1.json"}
19
19
  )
20
-
21
20
  tr.has_one_object.internal_object.should be_instance_of(
22
21
  HasOneObject
23
22
  )
@@ -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
- before(:all) do
15
+ context ".instantiate_record" do
17
16
 
18
- PrefixResource = Class.new(ApiResource::Base) do
19
- self.prefix = "/path/to/project"
20
- end
17
+ context "should handle blank associations and not load them
18
+ afterwards" do
21
19
 
22
- DynamicPrefixResource = Class.new(ApiResource::Base) do
23
- self.prefix = "/path/to/nested/:id/"
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
- end
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
- it "should return a full path if there are no nested ids" do
30
- PrefixResource.new_element_path.should eql(
31
- "/path/to/project/prefix_resources/new.json"
32
- )
33
- end
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.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-17 00:00:00.000000000 Z
14
+ date: 2013-04-18 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rake