ridley 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ridley/resource.rb +11 -2
- data/lib/ridley/version.rb +1 -1
- data/spec/unit/ridley/resource_spec.rb +82 -0
- metadata +3 -3
data/lib/ridley/resource.rb
CHANGED
@@ -5,6 +5,7 @@ module Ridley
|
|
5
5
|
include ActiveModel::AttributeMethods
|
6
6
|
include ActiveModel::Validations
|
7
7
|
include ActiveModel::Serializers::JSON
|
8
|
+
include Comparable
|
8
9
|
|
9
10
|
included do
|
10
11
|
attribute_method_suffix('=')
|
@@ -287,15 +288,23 @@ module Ridley
|
|
287
288
|
# @param [Object] other
|
288
289
|
#
|
289
290
|
# @return [Boolean]
|
291
|
+
def <=>(other)
|
292
|
+
self.chef_id <=> other.chef_id
|
293
|
+
end
|
294
|
+
|
290
295
|
def ==(other)
|
291
|
-
self.
|
296
|
+
self.chef_id == other.chef_id
|
292
297
|
end
|
293
298
|
|
294
299
|
# @param [Object] other
|
295
300
|
#
|
296
301
|
# @return [Boolean]
|
297
302
|
def eql?(other)
|
298
|
-
|
303
|
+
self.class == other.class && self == other
|
304
|
+
end
|
305
|
+
|
306
|
+
def hash
|
307
|
+
self.chef_id.hash
|
299
308
|
end
|
300
309
|
|
301
310
|
private
|
data/lib/ridley/version.rb
CHANGED
@@ -211,4 +211,86 @@ describe Ridley::Resource do
|
|
211
211
|
subject.attributes[:name].should eql("reset")
|
212
212
|
end
|
213
213
|
end
|
214
|
+
|
215
|
+
describe "comparable" do
|
216
|
+
subject do
|
217
|
+
Class.new do
|
218
|
+
include Ridley::Resource
|
219
|
+
|
220
|
+
set_chef_id "name"
|
221
|
+
|
222
|
+
attribute "name"
|
223
|
+
attribute "other_extra"
|
224
|
+
attribute "extra"
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
let(:one) { subject.new(connection) }
|
229
|
+
let(:two) { subject.new(connection) }
|
230
|
+
|
231
|
+
context "given two objects with the same value for their 'chef_id'" do
|
232
|
+
before(:each) do
|
233
|
+
one.attributes = { name: "reset", other_extra: "stuff" }
|
234
|
+
two.attributes = { name: "reset", extra: "stuff" }
|
235
|
+
end
|
236
|
+
|
237
|
+
it "is equal" do
|
238
|
+
one.should be_eql(two)
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
context "given two objects with different values for their 'chef_id'" do
|
243
|
+
before(:each) do
|
244
|
+
one.attributes = { name: "jamie", other_extra: "stuff" }
|
245
|
+
two.attributes = { name: "winsor", extra: "stuff" }
|
246
|
+
end
|
247
|
+
|
248
|
+
it "is not equal" do
|
249
|
+
one.should_not be_eql(two)
|
250
|
+
end
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
describe "uniqueness" do
|
255
|
+
subject do
|
256
|
+
Class.new do
|
257
|
+
include Ridley::Resource
|
258
|
+
|
259
|
+
set_chef_id "name"
|
260
|
+
|
261
|
+
attribute "name"
|
262
|
+
attribute "other_extra"
|
263
|
+
attribute "extra"
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
267
|
+
let(:one) { subject.new(connection) }
|
268
|
+
let(:two) { subject.new(connection) }
|
269
|
+
|
270
|
+
context "given an array of objects with the same value for their 'chef_id'" do
|
271
|
+
let(:nodes) do
|
272
|
+
one.attributes = { name: "reset", other_extra: "stuff" }
|
273
|
+
two.attributes = { name: "reset", extra: "stuff" }
|
274
|
+
|
275
|
+
[ one, two ]
|
276
|
+
end
|
277
|
+
|
278
|
+
it "returns only one unique element" do
|
279
|
+
nodes.uniq.should have(1).item
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
context "given an array of objects with different values for their 'chef_id'" do
|
284
|
+
let(:nodes) do
|
285
|
+
one.attributes = { name: "jamie", other_extra: "stuff" }
|
286
|
+
two.attributes = { name: "winsor", extra: "stuff" }
|
287
|
+
|
288
|
+
[ one, two ]
|
289
|
+
end
|
290
|
+
|
291
|
+
it "returns all of the elements" do
|
292
|
+
nodes.uniq.should have(2).item
|
293
|
+
end
|
294
|
+
end
|
295
|
+
end
|
214
296
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ridley
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.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: 2012-10-
|
12
|
+
date: 2012-10-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: chozo
|
@@ -434,7 +434,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
434
434
|
version: '0'
|
435
435
|
segments:
|
436
436
|
- 0
|
437
|
-
hash:
|
437
|
+
hash: -1603548164029238966
|
438
438
|
requirements: []
|
439
439
|
rubyforge_project:
|
440
440
|
rubygems_version: 1.8.23
|