yeti 0.3.6 → 0.3.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/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
@@ -1,3 +1,3 @@
1
1
  module Yeti
2
- VERSION = "0.3.6"
2
+ VERSION = "0.3.7"
3
3
  end
data/lib/yeti/viewer.rb CHANGED
@@ -13,6 +13,10 @@ module Yeti
13
13
  new context, (find_by_id context, id if id)
14
14
  end
15
15
 
16
+ def ==(other)
17
+ other.equal?(self) || (other.instance_of?(self.class) && other.id==id)
18
+ end
19
+
16
20
  protected
17
21
 
18
22
  # ~~~ methods to be implemented in subclasses ~~~
@@ -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
@@ -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.6
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: -227008563247670147
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: -227008563247670147
128
+ hash: -4028484294120140186
129
129
  requirements: []
130
130
  rubyforge_project:
131
131
  rubygems_version: 1.8.23