yeti 0.3.6 → 0.3.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/yeti/editor.rb +9 -0
- data/lib/yeti/version.rb +1 -1
- data/lib/yeti/viewer.rb +4 -0
- data/spec/yeti/editor_spec.rb +25 -0
- data/spec/yeti/viewer_spec.rb +18 -0
- metadata +3 -3
data/lib/yeti/editor.rb
CHANGED
@@ -73,6 +73,15 @@ module Yeti
|
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
76
|
+
def ==(other)
|
77
|
+
other.equal?(self) || (
|
78
|
+
persisted? &&
|
79
|
+
other.instance_of?(self.class) &&
|
80
|
+
other.persisted? &&
|
81
|
+
other.id==id
|
82
|
+
)
|
83
|
+
end
|
84
|
+
|
76
85
|
protected
|
77
86
|
|
78
87
|
# ~~~ methods to be implemented in subclasses ~~~
|
data/lib/yeti/version.rb
CHANGED
data/lib/yeti/viewer.rb
CHANGED
data/spec/yeti/editor_spec.rb
CHANGED
@@ -288,4 +288,29 @@ describe ::Yeti::Editor do
|
|
288
288
|
subject.mandatory?(:invalid).should be false
|
289
289
|
end
|
290
290
|
end
|
291
|
+
describe "#==" do
|
292
|
+
let(:existing){ mock :object, id: 1, persisted?: true }
|
293
|
+
let(:another){ mock :object, id: 2, persisted?: true }
|
294
|
+
subject{ described_class.from_id context, 1 }
|
295
|
+
before do
|
296
|
+
described_class.stub(:find_by_id).with(context, 1).and_return existing
|
297
|
+
described_class.stub(:find_by_id).with(context, 2).and_return another
|
298
|
+
described_class.stub(:new_object).with(context).and_return do
|
299
|
+
mock persisted?: false
|
300
|
+
end
|
301
|
+
end
|
302
|
+
it "two new editors are not equal" do
|
303
|
+
subject = described_class.new context
|
304
|
+
subject.should_not == described_class.new(context)
|
305
|
+
end
|
306
|
+
it "two editors of the same class with the same id are equal" do
|
307
|
+
subject.should == described_class.from_id(context, 1)
|
308
|
+
end
|
309
|
+
it "two editors of the same class with different ids are not equal" do
|
310
|
+
subject.should_not == described_class.from_id(context, 2)
|
311
|
+
end
|
312
|
+
it "two editors of different classes with the same id are not equal" do
|
313
|
+
subject.should_not == Class.new(described_class).from_id(context, 1)
|
314
|
+
end
|
315
|
+
end
|
291
316
|
end
|
data/spec/yeti/viewer_spec.rb
CHANGED
@@ -37,4 +37,22 @@ describe ::Yeti::Viewer do
|
|
37
37
|
subject.decorated.should be existing_object
|
38
38
|
end
|
39
39
|
end
|
40
|
+
describe "#==" do
|
41
|
+
let(:existing){ mock :object, id: 1 }
|
42
|
+
let(:another){ mock :object, id: 2 }
|
43
|
+
subject{ described_class.from_id context, 1 }
|
44
|
+
before do
|
45
|
+
described_class.stub(:find_by_id).with(context, 1).and_return existing
|
46
|
+
described_class.stub(:find_by_id).with(context, 2).and_return another
|
47
|
+
end
|
48
|
+
it "two viewers of the same class with the same id are equal" do
|
49
|
+
subject.should == described_class.from_id(context, 1)
|
50
|
+
end
|
51
|
+
it "two viewers of the same class with different ids are not equal" do
|
52
|
+
subject.should_not == described_class.from_id(context, 2)
|
53
|
+
end
|
54
|
+
it "two viewers of different classes with the same id are not equal" do
|
55
|
+
subject.should_not == Class.new(described_class).from_id(context, 1)
|
56
|
+
end
|
57
|
+
end
|
40
58
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yeti
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -116,7 +116,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
116
116
|
version: '0'
|
117
117
|
segments:
|
118
118
|
- 0
|
119
|
-
hash: -
|
119
|
+
hash: -4028484294120140186
|
120
120
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
121
|
none: false
|
122
122
|
requirements:
|
@@ -125,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
125
|
version: '0'
|
126
126
|
segments:
|
127
127
|
- 0
|
128
|
-
hash: -
|
128
|
+
hash: -4028484294120140186
|
129
129
|
requirements: []
|
130
130
|
rubyforge_project:
|
131
131
|
rubygems_version: 1.8.23
|