cfoundry 2.0.2 → 2.1.0
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/lib/cfoundry/v2/model.rb +12 -1
- data/lib/cfoundry/version.rb +1 -1
- data/spec/cfoundry/v2/model_spec.rb +63 -5
- metadata +18 -2
data/lib/cfoundry/v2/model.rb
CHANGED
@@ -21,6 +21,7 @@ module CFoundry::V2
|
|
21
21
|
end
|
22
22
|
|
23
23
|
attr_accessor :guid, :cache, :changes
|
24
|
+
attr_reader :created_at, :updated_at
|
24
25
|
attr_reader :diff
|
25
26
|
|
26
27
|
def initialize(guid, client, manifest = nil, partial = false)
|
@@ -33,6 +34,16 @@ module CFoundry::V2
|
|
33
34
|
@changes = {}
|
34
35
|
end
|
35
36
|
|
37
|
+
def created_at
|
38
|
+
timestamp = @manifest.try(:[], :metadata).try(:[], :created_at)
|
39
|
+
DateTime.parse(timestamp) if timestamp.present?
|
40
|
+
end
|
41
|
+
|
42
|
+
def updated_at
|
43
|
+
timestamp = @manifest.try(:[], :metadata).try(:[], :updated_at)
|
44
|
+
DateTime.parse(timestamp) if timestamp.present?
|
45
|
+
end
|
46
|
+
|
36
47
|
def manifest
|
37
48
|
@manifest ||= @client.base.send(object_name, @guid)
|
38
49
|
end
|
@@ -124,7 +135,7 @@ module CFoundry::V2
|
|
124
135
|
end
|
125
136
|
|
126
137
|
def update!
|
127
|
-
@client.base.put("v2", plural_object_name, guid,
|
138
|
+
@manifest = @client.base.put("v2", plural_object_name, guid,
|
128
139
|
:content => :json,
|
129
140
|
:accept => :json,
|
130
141
|
:payload => @diff
|
data/lib/cfoundry/version.rb
CHANGED
@@ -59,7 +59,11 @@ module CFoundry
|
|
59
59
|
describe "#create!" do
|
60
60
|
before do
|
61
61
|
stub(client.base).post {
|
62
|
-
{:metadata => {
|
62
|
+
{:metadata => {
|
63
|
+
:guid => "123",
|
64
|
+
:created_at => "2013-06-10 10:41:15 -0700",
|
65
|
+
:updated_at => "2015-06-10 10:41:15 -0700"
|
66
|
+
}}
|
63
67
|
}
|
64
68
|
model.foo = "bar"
|
65
69
|
end
|
@@ -81,23 +85,46 @@ module CFoundry
|
|
81
85
|
|
82
86
|
it "sets manifest from the response" do
|
83
87
|
model.create!
|
84
|
-
model.manifest.should == {
|
88
|
+
model.manifest.should == {
|
89
|
+
:metadata => {
|
90
|
+
:guid => "123",
|
91
|
+
:created_at => "2013-06-10 10:41:15 -0700",
|
92
|
+
:updated_at => "2015-06-10 10:41:15 -0700"
|
93
|
+
}
|
94
|
+
}
|
85
95
|
end
|
86
96
|
|
87
97
|
it "sets guid from the response metadata" do
|
88
98
|
model.create!
|
89
99
|
model.guid.should == "123"
|
90
100
|
end
|
101
|
+
|
102
|
+
it "sets timestamps from the response metadata" do
|
103
|
+
model.create!
|
104
|
+
|
105
|
+
model.created_at.should == DateTime.parse("2013-06-10 10:41:15 -0700")
|
106
|
+
model.updated_at.should == DateTime.parse("2015-06-10 10:41:15 -0700")
|
107
|
+
end
|
91
108
|
end
|
92
109
|
|
93
110
|
describe "#update!" do
|
94
111
|
before do
|
95
|
-
stub(client.base).put
|
112
|
+
stub(client.base).put {
|
113
|
+
{
|
114
|
+
:metadata => {
|
115
|
+
:guid => guid,
|
116
|
+
:created_at => "2013-06-10 10:41:15 -0700",
|
117
|
+
:updated_at => "2015-06-12 10:41:15 -0700"
|
118
|
+
},
|
119
|
+
:entity => {
|
120
|
+
:foo => "updated"
|
121
|
+
}
|
122
|
+
}
|
123
|
+
}
|
96
124
|
end
|
97
125
|
|
98
126
|
it "updates using the client with the v2 api, its plural model name, object guid, and diff object" do
|
99
127
|
model.foo = "bar"
|
100
|
-
|
101
128
|
mock(client.base).put("v2", :test_models, guid,
|
102
129
|
:content => :json,
|
103
130
|
:accept => :json,
|
@@ -106,6 +133,16 @@ module CFoundry
|
|
106
133
|
model.update!
|
107
134
|
end
|
108
135
|
|
136
|
+
it "updates the updated_at timestamp" do
|
137
|
+
model.update!
|
138
|
+
model.updated_at.should == DateTime.parse("2015-06-12 10:41:15 -0700")
|
139
|
+
end
|
140
|
+
|
141
|
+
it "reloads it's data from the manifest" do
|
142
|
+
model.update!
|
143
|
+
model.foo.should == "updated"
|
144
|
+
end
|
145
|
+
|
109
146
|
it "clears diff" do
|
110
147
|
model.foo = "bar"
|
111
148
|
|
@@ -264,11 +301,32 @@ module CFoundry
|
|
264
301
|
end
|
265
302
|
end
|
266
303
|
|
304
|
+
describe "metadata" do
|
305
|
+
let(:new_object) { client.test_model }
|
306
|
+
|
307
|
+
context "when metadata are set" do
|
308
|
+
it "has timestamps" do
|
309
|
+
new_object.created_at.should be_nil
|
310
|
+
new_object.updated_at.should be_nil
|
311
|
+
end
|
312
|
+
end
|
313
|
+
|
314
|
+
context "when metadata are not defined" do
|
315
|
+
before do
|
316
|
+
stub(new_object).manifest(nil)
|
317
|
+
end
|
318
|
+
|
319
|
+
it "returns nil for timestamps" do
|
320
|
+
new_object.updated_at.should be_nil
|
321
|
+
new_object.updated_at.should be_nil
|
322
|
+
end
|
323
|
+
end
|
324
|
+
end
|
325
|
+
|
267
326
|
describe "creating a new object" do
|
268
327
|
let(:new_object) { client.test_model }
|
269
328
|
|
270
329
|
describe "getting attributes" do
|
271
|
-
|
272
330
|
it "does not go to cloud controller" do
|
273
331
|
expect {
|
274
332
|
new_object.foo
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cfoundry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -92,6 +92,22 @@ dependencies:
|
|
92
92
|
- - ~>
|
93
93
|
- !ruby/object:Gem::Version
|
94
94
|
version: '0.9'
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: anchorman
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ! '>='
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
type: :development
|
104
|
+
prerelease: false
|
105
|
+
version_requirements: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
95
111
|
- !ruby/object:Gem::Dependency
|
96
112
|
name: factory_girl
|
97
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -413,7 +429,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
413
429
|
version: '0'
|
414
430
|
segments:
|
415
431
|
- 0
|
416
|
-
hash: -
|
432
|
+
hash: -3172782678702157575
|
417
433
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
418
434
|
none: false
|
419
435
|
requirements:
|