her 0.8.2 → 0.8.3

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.
@@ -6,89 +6,88 @@ describe Her::Model::Attributes do
6
6
  before { spawn_model "Foo::User" }
7
7
 
8
8
  it "handles new resource" do
9
- @new_user = Foo::User.new(:fullname => "Tobias Fünke")
10
- @new_user.new?.should be_truthy
11
- @new_user.fullname.should == "Tobias Fünke"
9
+ @new_user = Foo::User.new(fullname: "Tobias Fünke")
10
+ expect(@new_user.new?).to be_truthy
11
+ expect(@new_user.fullname).to eq("Tobias Fünke")
12
12
  end
13
13
 
14
14
  it "accepts new resource with strings as hash keys" do
15
- @new_user = Foo::User.new('fullname' => "Tobias Fünke")
16
- @new_user.fullname.should == "Tobias Fünke"
15
+ @new_user = Foo::User.new("fullname" => "Tobias Fünke")
16
+ expect(@new_user.fullname).to eq("Tobias Fünke")
17
17
  end
18
18
 
19
19
  it "handles method missing for getter" do
20
- @new_user = Foo::User.new(:fullname => 'Mayonegg')
20
+ @new_user = Foo::User.new(fullname: "Mayonegg")
21
21
  expect { @new_user.unknown_method_for_a_user }.to raise_error(NoMethodError)
22
- expect { @new_user.fullname }.not_to raise_error()
22
+ expect { @new_user.fullname }.not_to raise_error
23
23
  end
24
24
 
25
25
  it "handles method missing for setter" do
26
26
  @new_user = Foo::User.new
27
- expect { @new_user.fullname = "Tobias Fünke" }.not_to raise_error()
27
+ expect { @new_user.fullname = "Tobias Fünke" }.not_to raise_error
28
28
  end
29
29
 
30
30
  it "handles method missing for query" do
31
31
  @new_user = Foo::User.new
32
- expect { @new_user.fullname? }.not_to raise_error()
32
+ expect { @new_user.fullname? }.not_to raise_error
33
33
  end
34
34
 
35
35
  it "handles respond_to for getter" do
36
- @new_user = Foo::User.new(:fullname => 'Mayonegg')
37
- @new_user.should_not respond_to(:unknown_method_for_a_user)
38
- @new_user.should respond_to(:fullname)
36
+ @new_user = Foo::User.new(fullname: "Mayonegg")
37
+ expect(@new_user).not_to respond_to(:unknown_method_for_a_user)
38
+ expect(@new_user).to respond_to(:fullname)
39
39
  end
40
40
 
41
41
  it "handles respond_to for setter" do
42
42
  @new_user = Foo::User.new
43
- @new_user.should respond_to(:fullname=)
43
+ expect(@new_user).to respond_to(:fullname=)
44
44
  end
45
45
 
46
46
  it "handles respond_to for query" do
47
47
  @new_user = Foo::User.new
48
- @new_user.should respond_to(:fullname?)
48
+ expect(@new_user).to respond_to(:fullname?)
49
49
  end
50
50
 
51
51
  it "handles has_attribute? for getter" do
52
- @new_user = Foo::User.new(:fullname => 'Mayonegg')
53
- @new_user.should_not have_attribute(:unknown_method_for_a_user)
54
- @new_user.should have_attribute(:fullname)
52
+ @new_user = Foo::User.new(fullname: "Mayonegg")
53
+ expect(@new_user).not_to have_attribute(:unknown_method_for_a_user)
54
+ expect(@new_user).to have_attribute(:fullname)
55
55
  end
56
56
 
57
57
  it "handles get_attribute for getter" do
58
- @new_user = Foo::User.new(:fullname => 'Mayonegg')
59
- @new_user.get_attribute(:unknown_method_for_a_user).should be_nil
60
- @new_user.get_attribute(:fullname).should == 'Mayonegg'
58
+ @new_user = Foo::User.new(fullname: "Mayonegg")
59
+ expect(@new_user.get_attribute(:unknown_method_for_a_user)).to be_nil
60
+ expect(@new_user.get_attribute(:fullname)).to eq("Mayonegg")
61
61
  end
62
62
 
63
63
  it "handles get_attribute for getter with dash" do
64
- @new_user = Foo::User.new(:'life-span' => '3 years')
65
- @new_user.get_attribute(:unknown_method_for_a_user).should be_nil
66
- @new_user.get_attribute(:'life-span').should == '3 years'
64
+ @new_user = Foo::User.new(:'life-span' => "3 years")
65
+ expect(@new_user.get_attribute(:unknown_method_for_a_user)).to be_nil
66
+ expect(@new_user.get_attribute(:'life-span')).to eq("3 years")
67
67
  end
68
68
  end
69
69
 
70
-
71
70
  context "assigning new resource data" do
72
71
  before do
73
72
  spawn_model "Foo::User"
74
- @user = Foo::User.new(:active => false)
73
+ @user = Foo::User.new(active: false)
75
74
  end
76
75
 
77
76
  it "handles data update through #assign_attributes" do
78
- @user.assign_attributes :active => true
79
- @user.should be_active
77
+ @user.assign_attributes active: true
78
+ expect(@user).to be_active
80
79
  end
81
80
  end
82
81
 
83
82
  context "checking resource equality" do
84
83
  before do
85
- Her::API.setup :url => "https://api.example.com" do |builder|
84
+ Her::API.setup url: "https://api.example.com" do |builder|
86
85
  builder.use Her::Middleware::FirstLevelParseJSON
87
86
  builder.use Faraday::Request::UrlEncoded
88
87
  builder.adapter :test do |stub|
89
- stub.get("/users/1") { |env| [200, {}, { :id => 1, :fullname => "Lindsay Fünke" }.to_json] }
90
- stub.get("/users/2") { |env| [200, {}, { :id => 1, :fullname => "Tobias Fünke" }.to_json] }
91
- stub.get("/admins/1") { |env| [200, {}, { :id => 1, :fullname => "Lindsay Fünke" }.to_json] }
88
+ stub.get("/users/1") { [200, {}, { id: 1, fullname: "Lindsay Fünke" }.to_json] }
89
+ stub.get("/users/2") { [200, {}, { id: 1, fullname: "Tobias Fünke" }.to_json] }
90
+ stub.get("/admins/1") { [200, {}, { id: 1, fullname: "Lindsay Fünke" }.to_json] }
92
91
  end
93
92
  end
94
93
 
@@ -99,69 +98,69 @@ describe Her::Model::Attributes do
99
98
  let(:user) { Foo::User.find(1) }
100
99
 
101
100
  it "returns true for the exact same object" do
102
- user.should == user
101
+ expect(user).to eq(user)
103
102
  end
104
103
 
105
104
  it "returns true for the same resource via find" do
106
- user.should == Foo::User.find(1)
105
+ expect(user).to eq(Foo::User.find(1))
107
106
  end
108
107
 
109
108
  it "returns true for the same class with identical data" do
110
- user.should == Foo::User.new(:id => 1, :fullname => "Lindsay Fünke")
109
+ expect(user).to eq(Foo::User.new(id: 1, fullname: "Lindsay Fünke"))
111
110
  end
112
111
 
113
112
  it "returns true for a different resource with the same data" do
114
- user.should == Foo::Admin.find(1)
113
+ expect(user).to eq(Foo::Admin.find(1))
115
114
  end
116
115
 
117
116
  it "returns false for the same class with different data" do
118
- user.should_not == Foo::User.new(:id => 2, :fullname => "Tobias Fünke")
117
+ expect(user).not_to eq(Foo::User.new(id: 2, fullname: "Tobias Fünke"))
119
118
  end
120
119
 
121
120
  it "returns false for a non-resource with the same data" do
122
- fake_user = double(:data => { :id => 1, :fullname => "Lindsay Fünke" })
123
- user.should_not == fake_user
121
+ fake_user = double(data: { id: 1, fullname: "Lindsay Fünke" })
122
+ expect(user).not_to eq(fake_user)
124
123
  end
125
124
 
126
125
  it "delegates eql? to ==" do
127
126
  other = Object.new
128
- user.should_receive(:==).with(other).and_return(true)
129
- user.eql?(other).should be_truthy
127
+ expect(user).to receive(:==).with(other).and_return(true)
128
+ expect(user.eql?(other)).to be_truthy
130
129
  end
131
130
 
132
131
  it "treats equal resources as equal for Array#uniq" do
133
132
  user2 = Foo::User.find(1)
134
- [user, user2].uniq.should == [user]
133
+ expect([user, user2].uniq).to eq([user])
135
134
  end
136
135
 
137
136
  it "treats equal resources as equal for hash keys" do
138
137
  Foo::User.find(1)
139
138
  hash = { user => true }
140
139
  hash[Foo::User.find(1)] = false
141
- hash.size.should == 1
142
- hash.should == { user => false }
140
+ expect(hash.size).to eq(1)
141
+ expect(hash).to eq(user => false)
143
142
  end
144
143
  end
145
144
 
146
145
  context "handling metadata and errors" do
147
146
  before do
148
- Her::API.setup :url => "https://api.example.com" do |builder|
147
+ Her::API.setup url: "https://api.example.com" do |builder|
149
148
  builder.use Her::Middleware::FirstLevelParseJSON
150
149
  builder.adapter :test do |stub|
151
- stub.post("/users") { |env| [200, {}, { :id => 1, :fullname => "Tobias Fünke" }.to_json] }
150
+ stub.post("/users") { [200, {}, { id: 1, fullname: "Tobias Fünke" }.to_json] }
152
151
  end
153
152
  end
154
153
 
155
- spawn_model 'Foo::User' do
154
+ spawn_model "Foo::User" do
156
155
  store_response_errors :errors
157
156
  store_metadata :my_data
158
157
  end
159
158
 
160
- @user = Foo::User.new(:_errors => ["Foo", "Bar"], :_metadata => { :secret => true })
159
+ @user = Foo::User.new(_errors: %w(Foo Bar), _metadata: { secret: true })
161
160
  end
162
161
 
163
162
  it "should return response_errors stored in the method provided by `store_response_errors`" do
164
- @user.errors.should == ["Foo", "Bar"]
163
+ expect(@user.errors).to eq(%w(Foo Bar))
165
164
  end
166
165
 
167
166
  it "should remove the default method for errors" do
@@ -169,7 +168,7 @@ describe Her::Model::Attributes do
169
168
  end
170
169
 
171
170
  it "should return metadata stored in the method provided by `store_metadata`" do
172
- @user.my_data.should == { :secret => true }
171
+ expect(@user.my_data).to eq(secret: true)
173
172
  end
174
173
 
175
174
  it "should remove the default method for metadata" do
@@ -177,25 +176,25 @@ describe Her::Model::Attributes do
177
176
  end
178
177
 
179
178
  it "should work with #save" do
180
- @user.assign_attributes(:fullname => "Tobias Fünke")
179
+ @user.assign_attributes(fullname: "Tobias Fünke")
181
180
  @user.save
182
181
  expect { @user.metadata }.to raise_error(NoMethodError)
183
- @user.my_data.should be_empty
184
- @user.errors.should be_empty
182
+ expect(@user.my_data).to be_empty
183
+ expect(@user.errors).to be_empty
185
184
  end
186
185
  end
187
186
 
188
187
  context "overwriting default attribute methods" do
189
188
  context "for getter method" do
190
189
  before do
191
- Her::API.setup :url => "https://api.example.com" do |builder|
190
+ Her::API.setup url: "https://api.example.com" do |builder|
192
191
  builder.use Her::Middleware::FirstLevelParseJSON
193
192
  builder.adapter :test do |stub|
194
- stub.get("/users/1") { |env| [200, {}, { :id => 1, :fullname => "Tobias Fünke", :document => { :url => "http://example.com" } }.to_json] }
193
+ stub.get("/users/1") { [200, {}, { id: 1, fullname: "Tobias Fünke", document: { url: "http://example.com" } }.to_json] }
195
194
  end
196
195
  end
197
196
 
198
- spawn_model 'Foo::User' do
197
+ spawn_model "Foo::User" do
199
198
  def document
200
199
  @attributes[:document][:url]
201
200
  end
@@ -204,23 +203,23 @@ describe Her::Model::Attributes do
204
203
 
205
204
  it "bypasses Her's method" do
206
205
  @user = Foo::User.find(1)
207
- @user.document.should == "http://example.com"
206
+ expect(@user.document).to eq("http://example.com")
208
207
 
209
208
  @user = Foo::User.find(1)
210
- @user.document.should == "http://example.com"
209
+ expect(@user.document).to eq("http://example.com")
211
210
  end
212
211
  end
213
212
 
214
213
  context "for setter method" do
215
214
  before do
216
- Her::API.setup :url => "https://api.example.com" do |builder|
215
+ Her::API.setup url: "https://api.example.com" do |builder|
217
216
  builder.use Her::Middleware::FirstLevelParseJSON
218
217
  builder.adapter :test do |stub|
219
- stub.get("/users/1") { |env| [200, {}, { :id => 1, :fullname => "Tobias Fünke", :document => { :url => "http://example.com" } }.to_json] }
218
+ stub.get("/users/1") { [200, {}, { id: 1, fullname: "Tobias Fünke", document: { url: "http://example.com" } }.to_json] }
220
219
  end
221
220
  end
222
221
 
223
- spawn_model 'Foo::User' do
222
+ spawn_model "Foo::User" do
224
223
  def document=(document)
225
224
  @attributes[:document] = document[:url]
226
225
  end
@@ -229,24 +228,24 @@ describe Her::Model::Attributes do
229
228
 
230
229
  it "bypasses Her's method" do
231
230
  @user = Foo::User.find(1)
232
- @user.document.should == "http://example.com"
231
+ expect(@user.document).to eq("http://example.com")
233
232
 
234
233
  @user = Foo::User.find(1)
235
- @user.document.should == "http://example.com"
234
+ expect(@user.document).to eq("http://example.com")
236
235
  end
237
236
  end
238
237
 
239
238
  context "for predicate method" do
240
239
  before do
241
- Her::API.setup :url => "https://api.example.com" do |builder|
240
+ Her::API.setup url: "https://api.example.com" do |builder|
242
241
  builder.use Her::Middleware::FirstLevelParseJSON
243
242
  builder.adapter :test do |stub|
244
- stub.get("/users/1") { |env| [200, {}, { :id => 1, :fullname => "Lindsay Fünke", :document => { :url => nil } }.to_json] }
245
- stub.get("/users/2") { |env| [200, {}, { :id => 1, :fullname => "Tobias Fünke", :document => { :url => "http://example.com" } }.to_json] }
243
+ stub.get("/users/1") { [200, {}, { id: 1, fullname: "Lindsay Fünke", document: { url: nil } }.to_json] }
244
+ stub.get("/users/2") { [200, {}, { id: 1, fullname: "Tobias Fünke", document: { url: "http://example.com" } }.to_json] }
246
245
  end
247
246
  end
248
247
 
249
- spawn_model 'Foo::User' do
248
+ spawn_model "Foo::User" do
250
249
  def document?
251
250
  document[:url].present?
252
251
  end
@@ -255,20 +254,20 @@ describe Her::Model::Attributes do
255
254
 
256
255
  it "byoasses Her's method" do
257
256
  @user = Foo::User.find(1)
258
- @user.document?.should be_falsey
257
+ expect(@user.document?).to be_falsey
259
258
 
260
259
  @user = Foo::User.find(1)
261
- @user.document?.should be_falsey
260
+ expect(@user.document?).to be_falsey
262
261
 
263
262
  @user = Foo::User.find(2)
264
- @user.document?.should be_truthy
263
+ expect(@user.document?).to be_truthy
265
264
  end
266
265
  end
267
266
  end
268
267
 
269
268
  context "attributes class method" do
270
269
  before do
271
- spawn_model 'Foo::User' do
270
+ spawn_model "Foo::User" do
272
271
  attributes :fullname, :document
273
272
  end
274
273
  end
@@ -276,28 +275,28 @@ describe Her::Model::Attributes do
276
275
  context "instance" do
277
276
  subject { Foo::User.new }
278
277
 
279
- it { should respond_to(:fullname) }
280
- it { should respond_to(:fullname=) }
281
- it { should respond_to(:fullname?) }
278
+ it { is_expected.to respond_to(:fullname) }
279
+ it { is_expected.to respond_to(:fullname=) }
280
+ it { is_expected.to respond_to(:fullname?) }
282
281
  end
283
282
 
284
283
  it "defines setter that affects @attributes" do
285
284
  user = Foo::User.new
286
- user.fullname = 'Tobias Fünke'
287
- user.attributes[:fullname].should eq('Tobias Fünke')
285
+ user.fullname = "Tobias Fünke"
286
+ expect(user.attributes[:fullname]).to eq("Tobias Fünke")
288
287
  end
289
288
 
290
289
  it "defines getter that reads @attributes" do
291
290
  user = Foo::User.new
292
- user.assign_attributes(fullname: 'Tobias Fünke')
293
- user.fullname.should eq('Tobias Fünke')
291
+ user.assign_attributes(fullname: "Tobias Fünke")
292
+ expect(user.fullname).to eq("Tobias Fünke")
294
293
  end
295
294
 
296
295
  it "defines predicate that reads @attributes" do
297
296
  user = Foo::User.new
298
- user.fullname?.should be_falsey
299
- user.assign_attributes(fullname: 'Tobias Fünke')
300
- user.fullname?.should be_truthy
297
+ expect(user.fullname?).to be_falsey
298
+ user.assign_attributes(fullname: "Tobias Fünke")
299
+ expect(user.fullname?).to be_truthy
301
300
  end
302
301
 
303
302
  context "when attribute methods are already defined" do
@@ -311,75 +310,75 @@ describe Her::Model::Attributes do
311
310
  end
312
311
  @spawned_models << :AbstractUser
313
312
 
314
- spawn_model 'Foo::User', super_class: AbstractUser do
313
+ spawn_model "Foo::User", super_class: AbstractUser do
315
314
  attributes :fullname
316
315
  end
317
316
  end
318
317
 
319
318
  it "overrides getter method" do
320
- Foo::User.generated_attribute_methods.instance_methods.should include(:fullname)
319
+ expect(Foo::User.generated_attribute_methods.instance_methods).to include(:fullname)
321
320
  end
322
321
 
323
322
  it "overrides setter method" do
324
- Foo::User.generated_attribute_methods.instance_methods.should include(:fullname=)
323
+ expect(Foo::User.generated_attribute_methods.instance_methods).to include(:fullname=)
325
324
  end
326
325
 
327
326
  it "overrides predicate method" do
328
- Foo::User.generated_attribute_methods.instance_methods.should include(:fullname?)
327
+ expect(Foo::User.generated_attribute_methods.instance_methods).to include(:fullname?)
329
328
  end
330
329
 
331
330
  it "defines setter that affects @attributes" do
332
331
  user = Foo::User.new
333
- user.fullname = 'Tobias Fünke'
334
- user.attributes[:fullname].should eq('Tobias Fünke')
332
+ user.fullname = "Tobias Fünke"
333
+ expect(user.attributes[:fullname]).to eq("Tobias Fünke")
335
334
  end
336
335
 
337
336
  it "defines getter that reads @attributes" do
338
337
  user = Foo::User.new
339
- user.attributes[:fullname] = 'Tobias Fünke'
340
- user.fullname.should eq('Tobias Fünke')
338
+ user.attributes[:fullname] = "Tobias Fünke"
339
+ expect(user.fullname).to eq("Tobias Fünke")
341
340
  end
342
341
 
343
342
  it "defines predicate that reads @attributes" do
344
343
  user = Foo::User.new
345
- user.fullname?.should be_falsey
346
- user.attributes[:fullname] = 'Tobias Fünke'
347
- user.fullname?.should be_truthy
344
+ expect(user.fullname?).to be_falsey
345
+ user.attributes[:fullname] = "Tobias Fünke"
346
+ expect(user.fullname?).to be_truthy
348
347
  end
349
348
  end
350
349
 
351
350
  if ActiveModel::VERSION::MAJOR < 4
352
351
  it "creates a new mutex" do
353
352
  expect(Mutex).to receive(:new).once.and_call_original
354
- spawn_model 'Foo::User' do
353
+ spawn_model "Foo::User" do
355
354
  attributes :fullname
356
355
  end
357
- Foo::User.attribute_methods_mutex.should_not eq(Foo::User.generated_attribute_methods)
356
+ expect(Foo::User.attribute_methods_mutex).not_to eq(Foo::User.generated_attribute_methods)
358
357
  end
359
358
 
360
359
  it "works well with Module#synchronize monkey patched by ActiveSupport" do
361
360
  Module.class_eval do
362
- def synchronize(*args)
363
- raise 'gotcha!'
361
+ def synchronize(*_args)
362
+ raise "gotcha!"
364
363
  end
365
364
  end
366
365
  expect(Mutex).to receive(:new).once.and_call_original
367
- spawn_model 'Foo::User' do
366
+ spawn_model "Foo::User" do
368
367
  attributes :fullname
369
368
  end
370
- Foo::User.attribute_methods_mutex.should_not eq(Foo::User.generated_attribute_methods)
369
+ expect(Foo::User.attribute_methods_mutex).not_to eq(Foo::User.generated_attribute_methods)
371
370
  Module.class_eval do
372
371
  undef :synchronize
373
372
  end
374
373
  end
375
374
  else
376
375
  it "uses ActiveModel's mutex" do
377
- Foo::User.attribute_methods_mutex.should eq(Foo::User.generated_attribute_methods)
376
+ expect(Foo::User.attribute_methods_mutex).to eq(Foo::User.generated_attribute_methods)
378
377
  end
379
378
  end
380
379
 
381
380
  it "uses a mutex" do
382
- spawn_model 'Foo::User'
381
+ spawn_model "Foo::User"
383
382
  expect(Foo::User.attribute_methods_mutex).to receive(:synchronize).once.and_call_original
384
383
  Foo::User.class_eval do
385
384
  attributes :fullname, :documents