yeti 0.3.17 → 0.3.18

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3bbd8487f2f17ceeec1a08a107737d2f13cdce68
4
- data.tar.gz: 21d17721e0460e747ba55b552fd18208cb7cc6ff
3
+ metadata.gz: cbc3c3c5ad3cf40d7070a5e0473e57bdc346e20e
4
+ data.tar.gz: 442fabcf40e47bfa938a03fe3986f401a9ee6ec4
5
5
  SHA512:
6
- metadata.gz: 599f03ea7b706f6ba33972bbd2a3272f4b1d7086e9a60ae9dc17f21c5e7304a85c744800922e4049e179ad409dcbbd3ab904fb74a3bc41cd53ed0f97595f18d7
7
- data.tar.gz: daeb6e68efadacf59c330fc1f1dd8cc33185d6c628fa88036cc59f7ccd7f9d65383ccb08e2c6b949700495d81ac65073706821941d069e065dc700477611d0c1
6
+ metadata.gz: c2ed3b0d2ba92511d0b978cf930f4e6a5b0000b9f28fcc3e3b1a1ddc0107c2bda885cc13fef6e227bb1439dc7730b20605e5226ae436e91fb2ec9342c67f53e8
7
+ data.tar.gz: b73b9b438afe64808eadf24a023daa733c1c11f50683c0991c277edc936df39ff10102049cf3d05cde83e11f09e35e4887ddb9199c2bcc876a1a02065aefdbd9
@@ -1 +1 @@
1
- 2.1.1
1
+ 2.1.2
data/Gemfile CHANGED
@@ -2,3 +2,6 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in yeti.gemspec
4
4
  gemspec
5
+
6
+ # Fix I18n.enforce_available_locales deprecation warning
7
+ gem "i18n", github: "svenfuchs/i18n"
@@ -15,7 +15,7 @@ module Yeti
15
15
  def normalize_message(attribute, message, options)
16
16
  message ||= :invalid
17
17
  if untranslated? && !message.is_a?(Proc)
18
- message
18
+ options.fetch :message, message
19
19
  else
20
20
  super
21
21
  end
@@ -1,3 +1,3 @@
1
1
  module Yeti
2
- VERSION = "0.3.17"
2
+ VERSION = "0.3.18"
3
3
  end
@@ -1,6 +1,6 @@
1
1
  RSpec::Matchers.define :delegates do |delegated_method|
2
2
  match do |subject|
3
- stubbed = send(@delegate).stub(@delegate_method)
3
+ stubbed = allow(send @delegate).to receive @delegate_method
4
4
  stubbed.with @delegate_params if @delegate_params
5
5
  stubbed.and_return expected=double
6
6
  subject.send(delegated_method) === expected
@@ -25,11 +25,11 @@ RSpec::Matchers.define :delegates do |delegated_method|
25
25
  "delegates #{delegated_method} to #{@delegate}#{delegate_method}#{delegate_params}"
26
26
  end
27
27
 
28
- failure_message_for_should do |text|
28
+ failure_message do |text|
29
29
  "expected delegation of #{delegated_method} to #{@delegate}"
30
30
  end
31
31
 
32
- failure_message_for_should do |text|
32
+ failure_message do |text|
33
33
  "do not expected delegation of #{delegated_method} to #{@delegate}"
34
34
  end
35
35
  end
@@ -3,20 +3,20 @@ require "spec_helper"
3
3
  describe Yeti::Context do
4
4
  context "without hash" do
5
5
  it "#account is an instance of Yeti::Context::NoAccount" do
6
- Yeti::Context.new.account.should be_kind_of Yeti::Context::NoAccount
6
+ expect(Yeti::Context.new.account).to be_kind_of Yeti::Context::NoAccount
7
7
  end
8
8
  end
9
9
  context "when account_id is not in hash" do
10
10
  it "#account is an instance of Yeti::Context::NoAccount" do
11
- Yeti::Context.new({}).account.should be_kind_of Yeti::Context::NoAccount
11
+ expect(Yeti::Context.new({}).account).to be_kind_of Yeti::Context::NoAccount
12
12
  end
13
13
  end
14
14
  context "when account_id is nil" do
15
15
  subject{ Yeti::Context.new account_id: nil }
16
16
  it "#account is an instance of Yeti::Context::NoAccount" do
17
- subject.account.should be_kind_of Yeti::Context::NoAccount
17
+ expect(subject.account).to be_kind_of Yeti::Context::NoAccount
18
18
  end
19
- it("#account_id is nil"){ subject.account_id.should be_nil }
19
+ it("#account_id is nil"){ expect(subject.account_id).to be_nil }
20
20
  it "no account can be overriden by subclasses" do
21
21
  subclass = Class.new Yeti::Context do
22
22
  def no_account
@@ -24,14 +24,14 @@ describe Yeti::Context do
24
24
  end
25
25
  end
26
26
  subject = subclass.new account_id: nil
27
- subject.account.should == :custom_no_account
27
+ expect(subject.account).to eq(:custom_no_account)
28
28
  end
29
29
  end
30
30
  context "when account_id" do
31
31
  subject{ Yeti::Context.new account_id: 1 }
32
32
  it "uses find_account_by_id to find account" do
33
- subject.stub(:find_account_by_id).with(1).and_return(expected = double)
34
- subject.account.should be expected
33
+ allow(subject).to receive(:find_account_by_id).with(1).and_return(expected = double)
34
+ expect(subject.account).to be expected
35
35
  end
36
36
  it "#find_account_by_id is virtual" do
37
37
  expect do
@@ -39,8 +39,8 @@ describe Yeti::Context do
39
39
  end.to raise_error NotImplementedError
40
40
  end
41
41
  it "#account_id returns account.id" do
42
- subject.stub(:find_account_by_id).with(1).and_return double(id: 2)
43
- subject.account_id.should be 2
42
+ allow(subject).to receive(:find_account_by_id).with(1).and_return double(id: 2)
43
+ expect(subject.account_id).to be 2
44
44
  end
45
45
  end
46
46
  end
@@ -17,9 +17,9 @@ describe ::Yeti::Editor do
17
17
  let(:new_object){ double :new_object }
18
18
  let(:existing_object){ double :existing_object }
19
19
  context "with context only" do
20
- before{ described_class.stub(:new_object).with(context).and_return new_object }
20
+ before{ allow(described_class).to receive(:new_object).with(context).and_return new_object }
21
21
  it "keeps given context" do
22
- subject.context.should be context
22
+ expect(subject.context).to be context
23
23
  end
24
24
  it "#persist! is virtual" do
25
25
  expect do
@@ -27,29 +27,29 @@ describe ::Yeti::Editor do
27
27
  end.to raise_error NotImplementedError, "Yeti::Editor#persist!"
28
28
  end
29
29
  it "uses .new_object to initialize edited object" do
30
- subject.edited.should == new_object
30
+ expect(subject.edited).to eq(new_object)
31
31
  end
32
32
  it "delegates id to edited object" do
33
- should delegates(:id).to :new_object
33
+ is_expected.to delegates(:id).to :new_object
34
34
  end
35
35
  it "delegates to_param to edited object" do
36
- should delegates(:to_param).to :new_object
36
+ is_expected.to delegates(:to_param).to :new_object
37
37
  end
38
38
  it "delegates persisted? edited object" do
39
- should delegates(:persisted?).to :new_object
39
+ is_expected.to delegates(:persisted?).to :new_object
40
40
  end
41
41
  it ".new_object can be nil" do
42
- described_class.stub :new_object
43
- subject.edited.should be_nil
44
- subject.id.should be_nil
45
- subject.to_param.should be_nil
46
- subject.should_not be_persisted
42
+ allow(described_class).to receive :new_object
43
+ expect(subject.edited).to be_nil
44
+ expect(subject.id).to be_nil
45
+ expect(subject.to_param).to be_nil
46
+ expect(subject).not_to be_persisted
47
47
  end
48
48
  end
49
49
  context "initialize with context and object to edit" do
50
50
  subject{ described_class.new context, existing_object }
51
51
  it "keeps given context" do
52
- subject.context.should be context
52
+ expect(subject.context).to be context
53
53
  end
54
54
  it "#persist! is virtual" do
55
55
  expect do
@@ -57,13 +57,13 @@ describe ::Yeti::Editor do
57
57
  end.to raise_error NotImplementedError, "Yeti::Editor#persist!"
58
58
  end
59
59
  it "delegates id to edited object" do
60
- should delegates(:id).to :existing_object
60
+ is_expected.to delegates(:id).to :existing_object
61
61
  end
62
62
  it "delegates to_param to edited object" do
63
- should delegates(:to_param).to :existing_object
63
+ is_expected.to delegates(:to_param).to :existing_object
64
64
  end
65
65
  it "delegates persisted? edited object" do
66
- should delegates(:persisted?).to :existing_object
66
+ is_expected.to delegates(:persisted?).to :existing_object
67
67
  end
68
68
  end
69
69
  end
@@ -74,37 +74,37 @@ describe ::Yeti::Editor do
74
74
  context "when given_id is nil" do
75
75
  let(:given_id){ nil }
76
76
  it "uses .new_object to generate object to edit" do
77
- described_class.should_receive(:new_object).with(context).and_return new_object
78
- subject.edited.should be new_object
77
+ expect(described_class).to receive(:new_object).with(context).and_return new_object
78
+ expect(subject.edited).to be new_object
79
79
  end
80
80
  end
81
81
  context "when given_id is not nil" do
82
82
  let(:given_id){ "1" }
83
83
  it "uses .find_by_id to find object to edit" do
84
- described_class.should_receive(:find_by_id).with(context, "1").and_return do
84
+ expect(described_class).to receive(:find_by_id).with(context, "1") do
85
85
  existing_object
86
86
  end
87
- subject.edited.should be existing_object
88
- subject.id.should be 1
87
+ expect(subject.edited).to be existing_object
88
+ expect(subject.id).to be 1
89
89
  end
90
90
  end
91
91
  end
92
92
  context "when not valid" do
93
93
  it "#save returns false" do
94
- subject.should_receive(:valid?).and_return false
95
- subject.should_not_receive :persist!
96
- subject.save.should be false
94
+ expect(subject).to receive(:valid?).and_return false
95
+ expect(subject).not_to receive :persist!
96
+ expect(subject.save).to be false
97
97
  end
98
98
  it "#save(validate: false) calls persist! then returns true" do
99
- subject.should_not_receive :valid?
100
- subject.should_receive :persist!
101
- subject.save(validate: false).should be true
99
+ expect(subject).not_to receive :valid?
100
+ expect(subject).to receive :persist!
101
+ expect(subject.save(validate: false)).to be true
102
102
  end
103
103
  end
104
104
  context "when valid" do
105
105
  it "#save calls persist! then returns true" do
106
- subject.should_receive :persist!
107
- subject.save.should be true
106
+ expect(subject).to receive :persist!
107
+ expect(subject.save).to be true
108
108
  end
109
109
  end
110
110
  context "editor of one record" do
@@ -116,118 +116,137 @@ describe ::Yeti::Editor do
116
116
  "ObjectEditor"
117
117
  end
118
118
  def self.new_object(context)
119
- Struct.new(:id, :name).new nil, nil
119
+ Struct.new(:id, :name, :password).new nil, nil, nil
120
120
  end
121
121
  end
122
122
  end
123
123
  context "new record" do
124
- its(:id){ should be_nil }
125
- its(:name){ should be_nil }
124
+ describe '#id' do
125
+ subject { super().id }
126
+ it { is_expected.to be_nil }
127
+ end
128
+
129
+ describe '#name' do
130
+ subject { super().name }
131
+ it { is_expected.to be_nil }
132
+ end
126
133
  it "#name= don't touch value if it's not a string" do
127
134
  subject.name = ["test"]
128
- subject.name.should == ["test"]
135
+ expect(subject.name).to eq(["test"])
129
136
  end
130
137
  it "#name= cleans the value of harmful content if it's a string" do
131
138
  subject.name = "\tInfected\210\004"
132
- subject.name.should == "Infected"
139
+ expect(subject.name).to eq("Infected")
133
140
  end
134
141
  it "#name= accepts nil" do
135
142
  subject.name = "Valid"
136
143
  subject.name = nil
137
- subject.name.should be_nil
144
+ expect(subject.name).to be_nil
138
145
  end
139
146
  it "#attributes returns a hash" do
140
- subject.attributes.should == {name: nil}
147
+ expect(subject.attributes).to eq({name: nil})
141
148
  end
142
149
  it "#attributes= assigns each attribute" do
143
- subject.should_receive(:name=).with "Anthony"
150
+ expect(subject).to receive(:name=).with "Anthony"
144
151
  subject.attributes = {name: "Anthony"}
145
152
  end
146
153
  it "#attributes= skips unknown attributes" do
147
154
  subject.attributes = {unknown: "Anthony"}
155
+ expect(subject.attributes).to eq({name: nil})
148
156
  end
149
157
  context "before validation" do
150
- its(:errors){ should be_empty }
151
- it{ should be_without_error }
158
+ describe '#errors' do
159
+ subject { super().errors }
160
+ it { is_expected.to be_empty }
161
+ end
162
+ it{ is_expected.to be_without_error }
152
163
  end
153
164
  context "after validation" do
154
165
  it "has an error on name" do
155
166
  subject.valid?
156
- subject.errors[:name].should have(1).item
157
- subject.errors[:name].should == ["can't be blank"]
167
+ expect(subject.errors[:name].size).to eq(1)
168
+ expect(subject.errors[:name]).to eq(["can't be blank"])
158
169
  end
159
170
  it "is not without_error? anymore" do
160
171
  subject.valid?
161
- subject.should_not be_without_error
172
+ expect(subject).not_to be_without_error
162
173
  end
163
174
  it "can return untranslated error messages" do
164
175
  described_class.class_eval do
165
176
  dont_translate_error_messages
166
177
  end
167
178
  subject.valid?
168
- subject.errors[:name].should == [:blank]
179
+ expect(subject.errors[:name]).to eq([:blank])
180
+ end
181
+ it "message can be overridden" do
182
+ described_class.class_eval do
183
+ attribute :password
184
+ validates_presence_of :password, message: "overridden message"
185
+ end
186
+ subject.valid?
187
+ expect(subject.errors[:password]).to eq(["overridden message"])
169
188
  end
170
189
  end
171
190
  context "when name is empty" do
172
- it{ should_not be_valid }
191
+ it{ is_expected.not_to be_valid }
173
192
  end
174
193
  context "when name is changed" do
175
194
  before{ subject.name = "Anthony" }
176
- it{ should be_valid }
195
+ it{ is_expected.to be_valid }
177
196
  it "#attributes is updated" do
178
- subject.attributes.should == {name: "Anthony"}
197
+ expect(subject.attributes).to eq({name: "Anthony"})
179
198
  end
180
- it("name is updated"){ subject.name.should == "Anthony" }
181
- it("name is dirty"){ subject.name_changed?.should be true }
199
+ it("name is updated"){ expect(subject.name).to eq("Anthony") }
200
+ it("name is dirty"){ expect(subject.name_changed?).to be true }
182
201
  it "name isn't dirty anymore if original value is set back" do
183
202
  subject.name = nil
184
- subject.name_changed?.should be false
203
+ expect(subject.name_changed?).to be false
185
204
  end
186
205
  end
187
206
  context "after save" do
188
207
  before do
189
208
  subject.name = "Anthony"
190
- subject.stub :persist!
209
+ allow(subject).to receive :persist!
191
210
  subject.save
192
211
  end
193
212
  it "resets dirty attributes" do
194
- subject.name_changed?.should be false
213
+ expect(subject.name_changed?).to be false
195
214
  end
196
215
  it "still knows previous changes" do
197
- subject.previous_changes.should == {"name"=>[nil, "Anthony"]}
216
+ expect(subject.previous_changes).to eq({"name"=>[nil, "Anthony"]})
198
217
  end
199
218
  end
200
219
  end
201
220
  context "existing record" do
202
221
  let(:existing_object){ double :existing_object, id: 1, name: "Anthony" }
203
222
  subject{ described_class.new context, existing_object }
204
- it("gets id from record"){ subject.id.should be 1 }
223
+ it("gets id from record"){ expect(subject.id).to be 1 }
205
224
  it "gets name from record" do
206
- subject.name.should == "Anthony"
225
+ expect(subject.name).to eq("Anthony")
207
226
  end
208
- it{ should be_valid }
227
+ it{ is_expected.to be_valid }
209
228
  it "output formatting can be customized" do
210
- subject.stub(:format_output).with("Anthony", {
229
+ allow(subject).to receive(:format_output).with("Anthony", {
211
230
  attribute_name: :name,
212
231
  from: :edited,
213
232
  }).and_return(expected = double)
214
- subject.name.should be expected
233
+ expect(subject.name).to be expected
215
234
  end
216
235
  it "input formatting can be customized" do
217
- subject.stub(:format_input).with("Tony", {
236
+ allow(subject).to receive(:format_input).with("Tony", {
218
237
  attribute_name: :name,
219
238
  from: :edited,
220
239
  }).and_return(expected = double)
221
240
  subject.name = "Tony"
222
- subject.name.should be expected
241
+ expect(subject.name).to be expected
223
242
  end
224
243
  context "when name is changed" do
225
244
  before{ subject.name = nil }
226
- it("name is updated"){ subject.name.should be_nil }
227
- it("name is dirty"){ subject.name_changed?.should be true }
245
+ it("name is updated"){ expect(subject.name).to be_nil }
246
+ it("name is dirty"){ expect(subject.name_changed?).to be true }
228
247
  it "name isn't dirty anymore if original value is set back" do
229
248
  subject.name = "Anthony"
230
- subject.name_changed?.should be false
249
+ expect(subject.name_changed?).to be false
231
250
  end
232
251
  end
233
252
  end
@@ -257,27 +276,30 @@ describe ::Yeti::Editor do
257
276
  end.new context, existing_object
258
277
  end
259
278
  it "attribute default value comes from edited" do
260
- subject.id.should == 1
261
- subject.name.should == "Anthony"
279
+ expect(subject.id).to eq(1)
280
+ expect(subject.name).to eq("Anthony")
262
281
  end
263
282
  it "attribute value can come from another object" do
264
- subject.description.should == "Business man"
283
+ expect(subject.description).to eq("Business man")
265
284
  end
266
285
  it "attribute value can come from nowhere" do
267
- subject.password.should be_nil
286
+ expect(subject.password).to be_nil
268
287
  end
269
288
  it "attribute value can come from specified method on self" do
270
- subject.timestamp.should == "2001-01-01"
289
+ expect(subject.timestamp).to eq("2001-01-01")
271
290
  end
272
291
  it "attribute value can come from specified method on another object" do
273
- subject.related_id.should == 2
292
+ expect(subject.related_id).to eq(2)
274
293
  end
275
294
  it "attribute raises if value cannot be found in source" do
276
295
  expect{ subject.invalid }.to raise_error NoMethodError
277
296
  end
297
+ it "calling an undefined method doesn't trigger a stack overflow" do
298
+ expect{ subject.undefined }.to raise_error NoMethodError
299
+ end
278
300
  it "do not assign default value on access" do
279
- subject.with_default_from_another_attribute.should eq(2)
280
- subject.instance_variable_get(:@with_default_from_another_attribute).should be_nil
301
+ expect(subject.with_default_from_another_attribute).to eq(2)
302
+ expect(subject.instance_variable_get(:@with_default_from_another_attribute)).to be_nil
281
303
  end
282
304
  end
283
305
  describe "#mandatory?" do
@@ -289,13 +311,13 @@ describe ::Yeti::Editor do
289
311
  end.new context
290
312
  end
291
313
  it "is true for an attribute with validates_presence_of" do
292
- subject.mandatory?(:name).should be true
314
+ expect(subject.mandatory?(:name)).to be true
293
315
  end
294
316
  it "is false for an attribute without validates_presence_of" do
295
- subject.mandatory?(:password).should be false
317
+ expect(subject.mandatory?(:password)).to be false
296
318
  end
297
319
  it "is false for an invalid attribute" do
298
- subject.mandatory?(:invalid).should be false
320
+ expect(subject.mandatory?(:invalid)).to be false
299
321
  end
300
322
  end
301
323
  describe "equality" do
@@ -303,41 +325,41 @@ describe ::Yeti::Editor do
303
325
  let(:another){ double :object, id: 2, persisted?: true }
304
326
  subject{ described_class.from_id context, 1 }
305
327
  before do
306
- described_class.stub(:find_by_id).with(context, 1).and_return existing
307
- described_class.stub(:find_by_id).with(context, 2).and_return another
308
- described_class.stub(:new_object).with(context).and_return do
328
+ allow(described_class).to receive(:find_by_id).with(context, 1).and_return existing
329
+ allow(described_class).to receive(:find_by_id).with(context, 2).and_return another
330
+ allow(described_class).to receive(:new_object).with(context) do
309
331
  double persisted?: false, id: nil
310
332
  end
311
333
  end
312
334
  it "two new editors are not equal" do
313
335
  subject = described_class.new context
314
336
  other = described_class.new context
315
- subject.should_not == other
316
- subject.should_not eql other
317
- subject.hash.should == other.hash
337
+ expect(subject).not_to eq(other)
338
+ expect(subject).not_to eql other
339
+ expect(subject.hash).to eq(other.hash)
318
340
  end
319
341
  it "two editors of the same class with the same id are equal" do
320
342
  other = described_class.from_id context, 1
321
- subject.should == other
322
- subject.should eql other
323
- subject.hash.should == other.hash
343
+ expect(subject).to eq(other)
344
+ expect(subject).to eql other
345
+ expect(subject.hash).to eq(other.hash)
324
346
  end
325
347
  it "two editors of the same class with different ids are not equal" do
326
348
  other = described_class.from_id context, 2
327
- subject.should_not == other
328
- subject.should_not eql other
329
- subject.hash.should_not == other.hash
349
+ expect(subject).not_to eq(other)
350
+ expect(subject).not_to eql other
351
+ expect(subject.hash).not_to eq(other.hash)
330
352
  end
331
353
  it "two editors of different classes with the same id are not equal" do
332
354
  other = Class.new(described_class).from_id context, 1
333
- subject.should_not == other
334
- subject.should_not eql other
335
- subject.hash.should == other.hash
355
+ expect(subject).not_to eq(other)
356
+ expect(subject).not_to eql other
357
+ expect(subject.hash).to eq(other.hash)
336
358
  end
337
359
  end
338
360
  describe "#attributes_for_persist" do
339
361
  subject{ described_class.new context }
340
- before{ described_class.stub(:new_object).with(context).and_return record }
362
+ before{ allow(described_class).to receive(:new_object).with(context).and_return record }
341
363
  context "parses date format" do
342
364
  let :described_class do
343
365
  Class.new ::Yeti::Editor do
@@ -347,31 +369,31 @@ describe ::Yeti::Editor do
347
369
  let(:record){ double :new_record, valid_from: Date.parse("2002-09-01") }
348
370
  it "when a new value is assigned" do
349
371
  subject.valid_from = "2002-12-31"
350
- subject.attributes.should == {valid_from: "2002-12-31"}
351
- subject.attributes_for_persist.should == {
372
+ expect(subject.attributes).to eq({valid_from: "2002-12-31"})
373
+ expect(subject.attributes_for_persist).to eq({
352
374
  valid_from: Date.parse("2002-12-31")
353
- }
375
+ })
354
376
  end
355
377
  it "without new value" do
356
- subject.attributes.should == {valid_from: Date.parse("2002-09-01")}
357
- subject.attributes_for_persist.should == {
378
+ expect(subject.attributes).to eq({valid_from: Date.parse("2002-09-01")})
379
+ expect(subject.attributes_for_persist).to eq({
358
380
  valid_from: Date.parse("2002-09-01")
359
- }
381
+ })
360
382
  end
361
383
  it "when nil is assigned" do
362
384
  subject.valid_from = nil
363
- subject.attributes.should == {valid_from: nil}
364
- subject.attributes_for_persist.should == {valid_from: nil}
385
+ expect(subject.attributes).to eq({valid_from: nil})
386
+ expect(subject.attributes_for_persist).to eq({valid_from: nil})
365
387
  end
366
388
  it "when date is assigned" do
367
389
  today = Date.today
368
390
  subject.valid_from = today
369
- subject.attributes.should == {valid_from: today}
370
- subject.attributes_for_persist.should == {valid_from: today}
391
+ expect(subject.attributes).to eq({valid_from: today})
392
+ expect(subject.attributes_for_persist).to eq({valid_from: today})
371
393
  end
372
394
  it "when incorrect value is assigned" do
373
395
  subject.valid_from = "2002-13-31"
374
- subject.attributes.should == {valid_from: "2002-13-31"}
396
+ expect(subject.attributes).to eq({valid_from: "2002-13-31"})
375
397
  expect do
376
398
  subject.attributes_for_persist
377
399
  end.to raise_error ::Yeti::Editor::InvalidDate, "2002-13-31"
@@ -386,18 +408,18 @@ describe ::Yeti::Editor do
386
408
  let(:record){ double :new_record, name: nil }
387
409
  it "uses format_input_for_persist on each value" do
388
410
  subject.name = "Tony"
389
- subject.should_receive(:format_input_for_persist).with(
411
+ expect(subject).to receive(:format_input_for_persist).with(
390
412
  "Tony",
391
413
  attribute_name: :name,
392
414
  from: :edited
393
415
  ).and_return "Anthony"
394
- subject.attributes_for_persist.should == {name: "Anthony"}
416
+ expect(subject.attributes_for_persist).to eq({name: "Anthony"})
395
417
  end
396
418
  end
397
419
  end
398
420
  describe "allows defining additional attributes in subclass" do
399
421
  subject{ described_class.new context }
400
- before{ described_class.stub(:new_object).with(context).and_return record }
422
+ before{ allow(described_class).to receive(:new_object).with(context).and_return record }
401
423
  let(:record){ double :new_record, name: "Anthony", password: "tony" }
402
424
  let :parent_class do
403
425
  Class.new ::Yeti::Editor do
@@ -410,21 +432,21 @@ describe ::Yeti::Editor do
410
432
  end
411
433
  end
412
434
  it "merges attributes from parent" do
413
- subject.attributes.should == {
435
+ expect(subject.attributes).to eq({
414
436
  name: "Anthony",
415
437
  password: "tony",
416
- }
438
+ })
417
439
  end
418
440
  end
419
441
  context "#update_attributes" do
420
442
  it "can be called without argument" do
421
- subject.should_receive(:attributes=).with({})
422
- subject.should_receive(:save).and_return(expected = double)
443
+ expect(subject).to receive(:attributes=).with({})
444
+ expect(subject).to receive(:save).and_return(expected = double)
423
445
  expect( subject.update_attributes ).to be expected
424
446
  end
425
447
  it "can be called with attributes" do
426
- subject.should_receive(:attributes=).with name: "Anthony"
427
- subject.should_receive(:save).and_return(expected = double)
448
+ expect(subject).to receive(:attributes=).with name: "Anthony"
449
+ expect(subject).to receive(:save).and_return(expected = double)
428
450
  expect( subject.update_attributes name: "Anthony" ).to be expected
429
451
  end
430
452
  end
@@ -13,16 +13,16 @@ describe Yeti::Search do
13
13
  context "given context and an empty hash" do
14
14
  subject{ Yeti::Search.new context, {} }
15
15
  it "keeps given context" do
16
- subject.context.should be context
16
+ expect(subject.context).to be context
17
17
  end
18
18
  it "#search defaults to {}" do
19
- subject.search.should == {}
19
+ expect(subject.search).to eq({})
20
20
  end
21
21
  it "#page defaults to 1" do
22
- subject.page.should == 1
22
+ expect(subject.page).to eq(1)
23
23
  end
24
24
  it "#per_page defaults to 20" do
25
- subject.per_page.should == 20
25
+ expect(subject.per_page).to eq(20)
26
26
  end
27
27
  end
28
28
  context "given context and params" do
@@ -37,65 +37,65 @@ describe Yeti::Search do
37
37
  end
38
38
  let(:results){ double :results }
39
39
  subject{ Yeti::Search.new context, search: search }
40
- before{ subject.stub(:results).and_return results }
40
+ before{ allow(subject).to receive(:results).and_return results }
41
41
  it "#search comes from hash" do
42
- subject.search.should == search
42
+ expect(subject.search).to eq(search)
43
43
  end
44
44
  it "gets common filters from search" do
45
- subject.should respond_to(:name_contains)
46
- subject.should respond_to(:popular_equals)
47
- subject.should respond_to(:created_at_gte)
48
- subject.should respond_to(:created_at_lte)
49
- subject.name_contains.should == "tony"
50
- subject.popular_equals.should == "1"
51
- subject.created_at_gte.should == "2001-01-01"
52
- subject.created_at_lte.should == "2002-01-01"
45
+ expect(subject).to respond_to(:name_contains)
46
+ expect(subject).to respond_to(:popular_equals)
47
+ expect(subject).to respond_to(:created_at_gte)
48
+ expect(subject).to respond_to(:created_at_lte)
49
+ expect(subject.name_contains).to eq("tony")
50
+ expect(subject.popular_equals).to eq("1")
51
+ expect(subject.created_at_gte).to eq("2001-01-01")
52
+ expect(subject.created_at_lte).to eq("2002-01-01")
53
53
  end
54
54
  it "doesn't get everything from search" do
55
- subject.should_not respond_to(:uncommon_filter)
55
+ expect(subject).not_to respond_to(:uncommon_filter)
56
56
  expect{ subject.invalid_method }.to raise_error NoMethodError
57
57
  expect{ subject.uncommon_filter }.to raise_error NoMethodError
58
58
  end
59
59
  it "#page comes from hash" do
60
- Yeti::Search.new(context, page: "2").page.should be 2
60
+ expect(Yeti::Search.new(context, page: "2").page).to be 2
61
61
  end
62
62
  it "doesn't accept page to be lower than 1" do
63
- Yeti::Search.new(context, page: "0").page.should be 1
63
+ expect(Yeti::Search.new(context, page: "0").page).to be 1
64
64
  end
65
65
  it "#per_page comes from hash" do
66
- Yeti::Search.new(context, per_page: "10").per_page.should be 10
66
+ expect(Yeti::Search.new(context, per_page: "10").per_page).to be 10
67
67
  end
68
68
  it "doesn't accept per_page to be lower than 1" do
69
- Yeti::Search.new(context, per_page: "0").per_page.should be 1
69
+ expect(Yeti::Search.new(context, per_page: "0").per_page).to be 1
70
70
  end
71
71
  it "by default per_page has no limit" do
72
- Yeti::Search.max_per_page.should be_nil
73
- Yeti::Search.new(context, per_page: "9999").per_page.should be 9999
72
+ expect(Yeti::Search.max_per_page).to be_nil
73
+ expect(Yeti::Search.new(context, per_page: "9999").per_page).to be 9999
74
74
  end
75
75
  it "per_page can be limited" do
76
76
  search_class = Class.new Yeti::Search do
77
77
  max_per_page 50
78
78
  end
79
- search_class.max_per_page.should be 50
80
- search_class.new(context, per_page: "9999").per_page.should be 50
79
+ expect(search_class.max_per_page).to be 50
80
+ expect(search_class.new(context, per_page: "9999").per_page).to be 50
81
81
  end
82
82
  it "#paginated_results is virtual" do
83
83
  expect do
84
84
  subject.paginated_results
85
85
  end.to raise_error NotImplementedError
86
86
  end
87
- it{ should delegates(:to_ary).to :results }
88
- it{ should delegates(:empty?).to :results }
89
- it{ should delegates(:each).to :results }
90
- it{ should delegates(:group_by).to :results }
91
- it{ should delegates(:size).to :results }
87
+ it{ is_expected.to delegates(:to_ary).to :results }
88
+ it{ is_expected.to delegates(:empty?).to :results }
89
+ it{ is_expected.to delegates(:each).to :results }
90
+ it{ is_expected.to delegates(:group_by).to :results }
91
+ it{ is_expected.to delegates(:size).to :results }
92
92
  end
93
93
  context "when paginated_results is defined" do
94
94
  let(:paginated_results){ double :paginated_results }
95
95
  subject{ Yeti::Search.new context, {} }
96
- before{ subject.stub(:paginated_results).and_return paginated_results }
97
- it{ should delegates(:page_count).to :paginated_results }
98
- it{ should delegates(:count).to "paginated_results#pagination_record_count" }
99
- it{ should delegates(:results).to "paginated_results#all" }
96
+ before{ allow(subject).to receive(:paginated_results).and_return paginated_results }
97
+ it{ is_expected.to delegates(:page_count).to :paginated_results }
98
+ it{ is_expected.to delegates(:count).to "paginated_results#pagination_record_count" }
99
+ it{ is_expected.to delegates(:results).to "paginated_results#all" }
100
100
  end
101
101
  end
@@ -11,29 +11,29 @@ describe ::Yeti::Viewer do
11
11
  let(:existing_object){ double :existing_object }
12
12
  subject{ described_class.new context, existing_object }
13
13
  it "keeps given context" do
14
- subject.context.should be context
14
+ expect(subject.context).to be context
15
15
  end
16
16
  it "keeps given object to decorate" do
17
- subject.decorated.should be existing_object
17
+ expect(subject.decorated).to be existing_object
18
18
  end
19
19
  it "delegates id to decorated object" do
20
- should delegates(:id).to :existing_object
20
+ is_expected.to delegates(:id).to :existing_object
21
21
  end
22
22
  it "delegates to_param to decorated object" do
23
- should delegates(:to_param).to :existing_object
23
+ is_expected.to delegates(:to_param).to :existing_object
24
24
  end
25
25
  it "delegates persisted? decorated object" do
26
- should delegates(:persisted?).to :existing_object
26
+ is_expected.to delegates(:persisted?).to :existing_object
27
27
  end
28
28
  end
29
29
  describe ".from_id(context, given_id)" do
30
30
  let(:existing_object){ double :existing_object }
31
31
  subject{ described_class.from_id context, "1" }
32
32
  it "uses .find_by_id to find object to edit" do
33
- described_class.should_receive(:find_by_id).with(context, "1").and_return do
33
+ expect(described_class).to receive(:find_by_id).with(context, "1") do
34
34
  existing_object
35
35
  end
36
- subject.decorated.should be existing_object
36
+ expect(subject.decorated).to be existing_object
37
37
  end
38
38
  end
39
39
  describe "equality" do
@@ -41,26 +41,26 @@ describe ::Yeti::Viewer do
41
41
  let(:another){ double :object, id: 2 }
42
42
  subject{ described_class.from_id context, 1 }
43
43
  before do
44
- described_class.stub(:find_by_id).with(context, 1).and_return existing
45
- described_class.stub(:find_by_id).with(context, 2).and_return another
44
+ allow(described_class).to receive(:find_by_id).with(context, 1).and_return existing
45
+ allow(described_class).to receive(:find_by_id).with(context, 2).and_return another
46
46
  end
47
47
  it "two viewers of the same class with the same id are equal" do
48
48
  other = described_class.from_id context, 1
49
- subject.should == other
50
- subject.should eql other
51
- subject.hash.should == other.hash
49
+ expect(subject).to eq(other)
50
+ expect(subject).to eql other
51
+ expect(subject.hash).to eq(other.hash)
52
52
  end
53
53
  it "two viewers of the same class with different ids are not equal" do
54
54
  other = described_class.from_id context, 2
55
- subject.should_not == other
56
- subject.should_not eql other
57
- subject.hash.should_not == other.hash
55
+ expect(subject).not_to eq(other)
56
+ expect(subject).not_to eql other
57
+ expect(subject.hash).not_to eq(other.hash)
58
58
  end
59
59
  it "two viewers of different classes with the same id are not equal" do
60
60
  other = Class.new(described_class).from_id context, 1
61
- subject.should_not == other
62
- subject.should_not eql other
63
- subject.hash.should == other.hash
61
+ expect(subject).not_to eq(other)
62
+ expect(subject).not_to eql other
63
+ expect(subject.hash).to eq(other.hash)
64
64
  end
65
65
  end
66
66
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yeti
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.17
4
+ version: 0.3.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joseph HALTER
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-07 00:00:00.000000000 Z
11
+ date: 2014-07-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel