her 0.8.1 → 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.
@@ -5,14 +5,14 @@ describe Her::Model::ORM do
5
5
  context "mapping data to Ruby objects" do
6
6
  before do
7
7
  api = Her::API.new
8
- api.setup :url => "https://api.example.com" do |builder|
8
+ api.setup url: "https://api.example.com" do |builder|
9
9
  builder.use Her::Middleware::FirstLevelParseJSON
10
10
  builder.use Faraday::Request::UrlEncoded
11
11
  builder.adapter :test do |stub|
12
- stub.get("/users/1") { |env| [200, {}, { :id => 1, :name => "Tobias Fünke" }.to_json] }
13
- stub.get("/users") { |env| [200, {}, [{ :id => 1, :name => "Tobias Fünke" }, { :id => 2, :name => "Lindsay Fünke" }].to_json] }
14
- stub.get("/admin_users") { |env| [200, {}, [{ :admin_id => 1, :name => "Tobias Fünke" }, { :admin_id => 2, :name => "Lindsay Fünke" }].to_json] }
15
- stub.get("/admin_users/1") { |env| [200, {}, { :admin_id => 1, :name => "Tobias Fünke" }.to_json] }
12
+ stub.get("/users/1") { [200, {}, { id: 1, name: "Tobias Fünke" }.to_json] }
13
+ stub.get("/users") { [200, {}, [{ id: 1, name: "Tobias Fünke" }, { id: 2, name: "Lindsay Fünke" }].to_json] }
14
+ stub.get("/admin_users") { [200, {}, [{ admin_id: 1, name: "Tobias Fünke" }, { admin_id: 2, name: "Lindsay Fünke" }].to_json] }
15
+ stub.get("/admin_users/1") { [200, {}, { admin_id: 1, name: "Tobias Fünke" }.to_json] }
16
16
  end
17
17
  end
18
18
 
@@ -28,53 +28,55 @@ describe Her::Model::ORM do
28
28
 
29
29
  it "maps a single resource to a Ruby object" do
30
30
  @user = Foo::User.find(1)
31
- @user.id.should == 1
32
- @user.name.should == "Tobias Fünke"
31
+ expect(@user.id).to eq(1)
32
+ expect(@user.name).to eq("Tobias Fünke")
33
33
 
34
34
  @admin = Foo::AdminUser.find(1)
35
- @admin.id.should == 1
36
- @admin.name.should == "Tobias Fünke"
35
+ expect(@admin.id).to eq(1)
36
+ expect(@admin.name).to eq("Tobias Fünke")
37
37
  end
38
38
 
39
39
  it "maps a collection of resources to an array of Ruby objects" do
40
40
  @users = Foo::User.all
41
- @users.length.should == 2
42
- @users.first.name.should == "Tobias Fünke"
41
+ expect(@users.length).to eq(2)
42
+ expect(@users.first.name).to eq("Tobias Fünke")
43
43
 
44
44
  @users = Foo::AdminUser.all
45
- @users.length.should == 2
46
- @users.first.name.should == "Tobias Fünke"
45
+ expect(@users.length).to eq(2)
46
+ expect(@users.first.name).to eq("Tobias Fünke")
47
47
  end
48
48
 
49
49
  it "handles new resource" do
50
- @new_user = Foo::User.new(:fullname => "Tobias Fünke")
51
- @new_user.new?.should be_truthy
52
- @new_user.new_record?.should be_truthy
53
- @new_user.fullname.should == "Tobias Fünke"
50
+ @new_user = Foo::User.new(fullname: "Tobias Fünke")
51
+ expect(@new_user.new?).to be_truthy
52
+ expect(@new_user.new_record?).to be_truthy
53
+ expect(@new_user.fullname).to eq("Tobias Fünke")
54
54
 
55
55
  @existing_user = Foo::User.find(1)
56
- @existing_user.new?.should be_falsey
57
- @existing_user.new_record?.should be_falsey
56
+ expect(@existing_user.new?).to be_falsey
57
+ expect(@existing_user.new_record?).to be_falsey
58
58
  end
59
59
 
60
- it 'handles new resource with custom primary key' do
61
- @new_user = Foo::AdminUser.new(:fullname => 'Lindsay Fünke', :id => -1)
62
- @new_user.should be_new
60
+ it "handles new resource with custom primary key" do
61
+ @new_user = Foo::AdminUser.new(fullname: "Lindsay Fünke", id: -1)
62
+ expect(@new_user).to be_new
63
63
 
64
64
  @existing_user = Foo::AdminUser.find(1)
65
- @existing_user.should_not be_new
65
+ expect(@existing_user).not_to be_new
66
66
  end
67
67
  end
68
68
 
69
69
  context "mapping data, metadata and error data to Ruby objects" do
70
70
  before do
71
71
  api = Her::API.new
72
- api.setup :url => "https://api.example.com" do |builder|
72
+ api.setup url: "https://api.example.com" do |builder|
73
73
  builder.use Her::Middleware::SecondLevelParseJSON
74
74
  builder.use Faraday::Request::UrlEncoded
75
75
  builder.adapter :test do |stub|
76
+ stub.get("/users") { [200, {}, { data: [{ id: 1, name: "Tobias Fünke" }, { id: 2, name: "Lindsay Fünke" }], metadata: { total_pages: 10, next_page: 2 }, errors: %w(Oh My God) }.to_json] }
76
77
  stub.get("/users") { |env| [200, {}, { :data => [{ :id => 1, :name => "Tobias Fünke" }, { :id => 2, :name => "Lindsay Fünke" }], :metadata => { :total_pages => 10, :next_page => 2 }, :errors => ["Oh", "My", "God"] }.to_json] }
77
78
  stub.post("/users") { |env| [200, {}, { :data => { :name => "George Michael Bluth" }, :metadata => { :foo => "bar" }, :errors => ["Yes", "Sir"] }.to_json] }
79
+ stub.delete("/users/1") { |env| [200, {}, { :data => { :id => 1 }, :metadata => { :foo => "bar" }, :errors => ["Yes", "Sir"] }.to_json] }
78
80
  end
79
81
  end
80
82
 
@@ -85,21 +87,31 @@ describe Her::Model::ORM do
85
87
 
86
88
  it "handles metadata on a collection" do
87
89
  @users = User.all
88
- @users.metadata[:total_pages].should == 10
90
+ expect(@users.metadata[:total_pages]).to eq(10)
89
91
  end
90
92
 
91
93
  it "handles error data on a collection" do
92
94
  @users = User.all
93
- @users.errors.length.should == 3
95
+ expect(@users.errors.length).to eq(3)
94
96
  end
95
97
 
96
98
  it "handles metadata on a resource" do
97
- @user = User.create(:name => "George Michael Bluth")
98
- @user.metadata[:foo].should == "bar"
99
+ @user = User.create(name: "George Michael Bluth")
100
+ expect(@user.metadata[:foo]).to eq("bar")
99
101
  end
100
102
 
101
103
  it "handles error data on a resource" do
102
- @user = User.create(:name => "George Michael Bluth")
104
+ @user = User.create(name: "George Michael Bluth")
105
+ expect(@user.response_errors).to eq(%w(Yes Sir))
106
+ end
107
+
108
+ it "handles metadata on a destroyed resource" do
109
+ @user = User.destroy_existing(1)
110
+ @user.metadata[:foo].should == "bar"
111
+ end
112
+
113
+ it "handles error data on a destroyed resource" do
114
+ @user = User.destroy_existing(1)
103
115
  @user.response_errors.should == ["Yes", "Sir"]
104
116
  end
105
117
  end
@@ -107,12 +119,12 @@ describe Her::Model::ORM do
107
119
  context "mapping data, metadata and error data in string keys to Ruby objects" do
108
120
  before do
109
121
  api = Her::API.new
110
- api.setup :url => "https://api.example.com" do |builder|
122
+ api.setup url: "https://api.example.com" do |builder|
111
123
  builder.use Her::Middleware::SecondLevelParseJSON
112
124
  builder.use Faraday::Request::UrlEncoded
113
125
  builder.adapter :test do |stub|
114
- stub.get("/users") { |env| [200, {}, { 'data' => [{ :id => 1, :name => "Tobias Fünke" }, { :id => 2, :name => "Lindsay Fünke" }], 'metadata' => { :total_pages => 10, :next_page => 2 }, 'errors' => ["Oh", "My", "God"] }.to_json] }
115
- stub.post("/users") { |env| [200, {}, { 'data' => { :name => "George Michael Bluth" }, 'metadata' => { :foo => "bar" }, 'errors' => ["Yes", "Sir"] }.to_json] }
126
+ stub.get("/users") { [200, {}, { data: [{ id: 1, name: "Tobias Fünke" }, { id: 2, name: "Lindsay Fünke" }], metadata: { total_pages: 10, next_page: 2 }, errors: %w(Oh My God) }.to_json] }
127
+ stub.post("/users") { [200, {}, { data: { name: "George Michael Bluth" }, metadata: { foo: "bar" }, errors: %w(Yes Sir) }.to_json] }
116
128
  end
117
129
  end
118
130
 
@@ -123,34 +135,34 @@ describe Her::Model::ORM do
123
135
 
124
136
  it "handles metadata on a collection" do
125
137
  @users = User.all
126
- @users.metadata[:total_pages].should == 10
138
+ expect(@users.metadata[:total_pages]).to eq(10)
127
139
  end
128
140
 
129
141
  it "handles error data on a collection" do
130
142
  @users = User.all
131
- @users.errors.length.should == 3
143
+ expect(@users.errors.length).to eq(3)
132
144
  end
133
145
 
134
146
  it "handles metadata on a resource" do
135
- @user = User.create(:name => "George Michael Bluth")
136
- @user.metadata[:foo].should == "bar"
147
+ @user = User.create(name: "George Michael Bluth")
148
+ expect(@user.metadata[:foo]).to eq("bar")
137
149
  end
138
150
 
139
151
  it "handles error data on a resource" do
140
- @user = User.create(:name => "George Michael Bluth")
141
- @user.response_errors.should == ["Yes", "Sir"]
152
+ @user = User.create(name: "George Michael Bluth")
153
+ expect(@user.response_errors).to eq(%w(Yes Sir))
142
154
  end
143
155
  end
144
156
 
145
157
  context "defining custom getters and setters" do
146
158
  before do
147
159
  api = Her::API.new
148
- api.setup :url => "https://api.example.com" do |builder|
160
+ api.setup url: "https://api.example.com" do |builder|
149
161
  builder.use Her::Middleware::FirstLevelParseJSON
150
162
  builder.use Faraday::Request::UrlEncoded
151
163
  builder.adapter :test do |stub|
152
- stub.get("/users/1") { |env| [200, {}, { :id => 1, :friends => ["Maeby", "GOB", "Anne"] }.to_json] }
153
- stub.get("/users/2") { |env| [200, {}, { :id => 1 }.to_json] }
164
+ stub.get("/users/1") { [200, {}, { id: 1, friends: %w(Maeby GOB Anne) }.to_json] }
165
+ stub.get("/users/2") { [200, {}, { id: 1 }.to_json] }
154
166
  end
155
167
  end
156
168
 
@@ -159,7 +171,7 @@ describe Her::Model::ORM do
159
171
  belongs_to :organization
160
172
 
161
173
  def friends=(val)
162
- val = val.gsub("\r", "").split("\n").map { |friend| friend.gsub(/^\s*\*\s*/, "") } if val and val.is_a?(String)
174
+ val = val.delete("\r").split("\n").map { |friend| friend.gsub(/^\s*\*\s*/, "") } if val && val.is_a?(String)
163
175
  @attributes[:friends] = val
164
176
  end
165
177
 
@@ -171,18 +183,18 @@ describe Her::Model::ORM do
171
183
 
172
184
  it "handles custom setters" do
173
185
  @user = User.find(1)
174
- @user.friends.should == "* Maeby\n* GOB\n* Anne"
186
+ expect(@user.friends).to eq("* Maeby\n* GOB\n* Anne")
175
187
  @user.instance_eval do
176
- @attributes[:friends] = ["Maeby", "GOB", "Anne"]
188
+ @attributes[:friends] = %w(Maeby GOB Anne)
177
189
  end
178
190
  end
179
191
 
180
192
  it "handles custom getters" do
181
193
  @user = User.new
182
194
  @user.friends = "* George\n* Oscar\n* Lucille"
183
- @user.friends.should == "* George\n* Oscar\n* Lucille"
195
+ expect(@user.friends).to eq("* George\n* Oscar\n* Lucille")
184
196
  @user.instance_eval do
185
- @attributes[:friends] = ["George", "Oscar", "Lucille"]
197
+ @attributes[:friends] = %w(George Oscar Lucille)
186
198
  end
187
199
  end
188
200
  end
@@ -190,16 +202,16 @@ describe Her::Model::ORM do
190
202
  context "finding resources" do
191
203
  before do
192
204
  api = Her::API.new
193
- api.setup :url => "https://api.example.com" do |builder|
205
+ api.setup url: "https://api.example.com" do |builder|
194
206
  builder.use Her::Middleware::FirstLevelParseJSON
195
207
  builder.use Faraday::Request::UrlEncoded
196
208
  builder.adapter :test do |stub|
197
- stub.get("/users/1") { |env| [200, {}, { :id => 1, :age => 42 }.to_json] }
198
- stub.get("/users/2") { |env| [200, {}, { :id => 2, :age => 34 }.to_json] }
199
- stub.get("/users?id[]=1&id[]=2") { |env| [200, {}, [{ :id => 1, :age => 42 }, { :id => 2, :age => 34 }].to_json] }
200
- stub.get("/users?age=42&foo=bar") { |env| [200, {}, [{ :id => 3, :age => 42 }].to_json] }
201
- stub.get("/users?age=42") { |env| [200, {}, [{ :id => 1, :age => 42 }].to_json] }
202
- stub.get("/users?age=40") { |env| [200, {}, [{ :id => 1, :age => 40 }].to_json] }
209
+ stub.get("/users/1") { [200, {}, { id: 1, age: 42 }.to_json] }
210
+ stub.get("/users/2") { [200, {}, { id: 2, age: 34 }.to_json] }
211
+ stub.get("/users?id[]=1&id[]=2") { [200, {}, [{ id: 1, age: 42 }, { id: 2, age: 34 }].to_json] }
212
+ stub.get("/users?age=42&foo=bar") { [200, {}, [{ id: 3, age: 42 }].to_json] }
213
+ stub.get("/users?age=42") { [200, {}, [{ id: 1, age: 42 }].to_json] }
214
+ stub.get("/users?age=40") { [200, {}, [{ id: 1, age: 40 }].to_json] }
203
215
  end
204
216
  end
205
217
 
@@ -210,58 +222,58 @@ describe Her::Model::ORM do
210
222
 
211
223
  it "handles finding by a single id" do
212
224
  @user = User.find(1)
213
- @user.id.should == 1
225
+ expect(@user.id).to eq(1)
214
226
  end
215
227
 
216
228
  it "handles finding by multiple ids" do
217
229
  @users = User.find(1, 2)
218
- @users.should be_kind_of(Array)
219
- @users.length.should == 2
220
- @users[0].id.should == 1
221
- @users[1].id.should == 2
230
+ expect(@users).to be_kind_of(Array)
231
+ expect(@users.length).to eq(2)
232
+ expect(@users[0].id).to eq(1)
233
+ expect(@users[1].id).to eq(2)
222
234
  end
223
235
 
224
236
  it "handles finding by an array of ids" do
225
237
  @users = User.find([1, 2])
226
- @users.should be_kind_of(Array)
227
- @users.length.should == 2
228
- @users[0].id.should == 1
229
- @users[1].id.should == 2
238
+ expect(@users).to be_kind_of(Array)
239
+ expect(@users.length).to eq(2)
240
+ expect(@users[0].id).to eq(1)
241
+ expect(@users[1].id).to eq(2)
230
242
  end
231
243
 
232
244
  it "handles finding by an array of ids of length 1" do
233
245
  @users = User.find([1])
234
- @users.should be_kind_of(Array)
235
- @users.length.should == 1
236
- @users[0].id.should == 1
246
+ expect(@users).to be_kind_of(Array)
247
+ expect(@users.length).to eq(1)
248
+ expect(@users[0].id).to eq(1)
237
249
  end
238
250
 
239
251
  it "handles finding by an array id param of length 2" do
240
252
  @users = User.find(id: [1, 2])
241
- @users.should be_kind_of(Array)
242
- @users.length.should == 2
243
- @users[0].id.should == 1
244
- @users[1].id.should == 2
253
+ expect(@users).to be_kind_of(Array)
254
+ expect(@users.length).to eq(2)
255
+ expect(@users[0].id).to eq(1)
256
+ expect(@users[1].id).to eq(2)
245
257
  end
246
258
 
247
- it 'handles finding with id parameter as an array' do
259
+ it "handles finding with id parameter as an array" do
248
260
  @users = User.where(id: [1, 2])
249
- @users.should be_kind_of(Array)
250
- @users.length.should == 2
251
- @users[0].id.should == 1
252
- @users[1].id.should == 2
261
+ expect(@users).to be_kind_of(Array)
262
+ expect(@users.length).to eq(2)
263
+ expect(@users[0].id).to eq(1)
264
+ expect(@users[1].id).to eq(2)
253
265
  end
254
266
 
255
267
  it "handles finding with other parameters" do
256
- @users = User.where(:age => 42, :foo => "bar").all
257
- @users.should be_kind_of(Array)
258
- @users.first.id.should == 3
268
+ @users = User.where(age: 42, foo: "bar").all
269
+ expect(@users).to be_kind_of(Array)
270
+ expect(@users.first.id).to eq(3)
259
271
  end
260
272
 
261
273
  it "handles finding with other parameters and scoped" do
262
274
  @users = User.scoped
263
- @users.where(:age => 42).should be_all { |u| u.age == 42 }
264
- @users.where(:age => 40).should be_all { |u| u.age == 40 }
275
+ expect(@users.where(age: 42)).to be_all { |u| u.age == 42 }
276
+ expect(@users.where(age: 40)).to be_all { |u| u.age == 40 }
265
277
  end
266
278
  end
267
279
 
@@ -272,20 +284,20 @@ describe Her::Model::ORM do
272
284
  end
273
285
 
274
286
  it "builds a new resource without requesting it" do
275
- Foo::User.should_not_receive(:request)
276
- @new_user = Foo::User.build(:fullname => "Tobias Fünke")
277
- @new_user.new?.should be_truthy
278
- @new_user.fullname.should == "Tobias Fünke"
287
+ expect(Foo::User).not_to receive(:request)
288
+ @new_user = Foo::User.build(fullname: "Tobias Fünke")
289
+ expect(@new_user.new?).to be_truthy
290
+ expect(@new_user.fullname).to eq("Tobias Fünke")
279
291
  end
280
292
  end
281
293
 
282
294
  context "when request_new_object_on_build is set" do
283
295
  before do
284
- Her::API.setup :url => "https://api.example.com" do |builder|
296
+ Her::API.setup url: "https://api.example.com" do |builder|
285
297
  builder.use Her::Middleware::FirstLevelParseJSON
286
298
  builder.use Faraday::Request::UrlEncoded
287
299
  builder.adapter :test do |stub|
288
- stub.get("/users/new") { |env| ok! :id => nil, :fullname => params(env)[:fullname], :email => "tobias@bluthcompany.com" }
300
+ stub.get("/users/new") { |env| ok! id: nil, fullname: params(env)[:fullname], email: "tobias@bluthcompany.com" }
289
301
  end
290
302
  end
291
303
 
@@ -293,23 +305,23 @@ describe Her::Model::ORM do
293
305
  end
294
306
 
295
307
  it "requests a new resource" do
296
- Foo::User.should_receive(:request).once.and_call_original
297
- @new_user = Foo::User.build(:fullname => "Tobias Fünke")
298
- @new_user.new?.should be_truthy
299
- @new_user.fullname.should == "Tobias Fünke"
300
- @new_user.email.should == "tobias@bluthcompany.com"
308
+ expect(Foo::User).to receive(:request).once.and_call_original
309
+ @new_user = Foo::User.build(fullname: "Tobias Fünke")
310
+ expect(@new_user.new?).to be_truthy
311
+ expect(@new_user.fullname).to eq("Tobias Fünke")
312
+ expect(@new_user.email).to eq("tobias@bluthcompany.com")
301
313
  end
302
314
  end
303
315
  end
304
316
 
305
317
  context "creating resources" do
306
318
  before do
307
- Her::API.setup :url => "https://api.example.com" do |builder|
319
+ Her::API.setup url: "https://api.example.com" do |builder|
308
320
  builder.use Her::Middleware::FirstLevelParseJSON
309
321
  builder.use Faraday::Request::UrlEncoded
310
322
  builder.adapter :test do |stub|
311
- stub.post("/users") { |env| [200, {}, { :id => 1, :fullname => Faraday::Utils.parse_query(env[:body])['fullname'], :email => Faraday::Utils.parse_query(env[:body])['email'] }.to_json] }
312
- stub.post("/companies") { |env| [200, {}, { :errors => ["name is required"] }.to_json] }
323
+ stub.post("/users") { |env| [200, {}, { id: 1, fullname: Faraday::Utils.parse_query(env[:body])["fullname"], email: Faraday::Utils.parse_query(env[:body])["email"] }.to_json] }
324
+ stub.post("/companies") { [200, {}, { errors: ["name is required"] }.to_json] }
313
325
  end
314
326
  end
315
327
 
@@ -318,27 +330,27 @@ describe Her::Model::ORM do
318
330
  end
319
331
 
320
332
  it "handle one-line resource creation" do
321
- @user = Foo::User.create(:fullname => "Tobias Fünke", :email => "tobias@bluth.com")
322
- @user.id.should == 1
323
- @user.fullname.should == "Tobias Fünke"
324
- @user.email.should == "tobias@bluth.com"
333
+ @user = Foo::User.create(fullname: "Tobias Fünke", email: "tobias@bluth.com")
334
+ expect(@user.id).to eq(1)
335
+ expect(@user.fullname).to eq("Tobias Fünke")
336
+ expect(@user.email).to eq("tobias@bluth.com")
325
337
  end
326
338
 
327
339
  it "handle resource creation through Model.new + #save" do
328
- @user = Foo::User.new(:fullname => "Tobias Fünke")
329
- @user.save.should be_truthy
330
- @user.fullname.should == "Tobias Fünke"
340
+ @user = Foo::User.new(fullname: "Tobias Fünke")
341
+ expect(@user.save).to be_truthy
342
+ expect(@user.fullname).to eq("Tobias Fünke")
331
343
  end
332
344
 
333
345
  it "handle resource creation through Model.new + #save!" do
334
- @user = Foo::User.new(:fullname => "Tobias Fünke")
335
- @user.save!.should be_truthy
336
- @user.fullname.should == "Tobias Fünke"
346
+ @user = Foo::User.new(fullname: "Tobias Fünke")
347
+ expect(@user.save!).to be_truthy
348
+ expect(@user.fullname).to eq("Tobias Fünke")
337
349
  end
338
350
 
339
351
  it "returns false when #save gets errors" do
340
352
  @company = Foo::Company.new
341
- @company.save.should be_falsey
353
+ expect(@company.save).to be_falsey
342
354
  end
343
355
 
344
356
  it "raises ResourceInvalid when #save! gets errors" do
@@ -347,20 +359,20 @@ describe Her::Model::ORM do
347
359
  end
348
360
 
349
361
  it "don't overwrite data if response is empty" do
350
- @company = Foo::Company.new(:name => 'Company Inc.')
351
- @company.save.should be_falsey
352
- @company.name.should == "Company Inc."
362
+ @company = Foo::Company.new(name: "Company Inc.")
363
+ expect(@company.save).to be_falsey
364
+ expect(@company.name).to eq("Company Inc.")
353
365
  end
354
366
  end
355
367
 
356
368
  context "updating resources" do
357
369
  before do
358
- Her::API.setup :url => "https://api.example.com" do |builder|
370
+ Her::API.setup url: "https://api.example.com" do |builder|
359
371
  builder.use Her::Middleware::FirstLevelParseJSON
360
372
  builder.use Faraday::Request::UrlEncoded
361
373
  builder.adapter :test do |stub|
362
- stub.get("/users/1") { |env| [200, {}, { :id => 1, :fullname => "Tobias Fünke" }.to_json] }
363
- stub.put("/users/1") { |env| [200, {}, { :id => 1, :fullname => "Lindsay Fünke" }.to_json] }
374
+ stub.get("/users/1") { [200, {}, { id: 1, fullname: "Tobias Fünke" }.to_json] }
375
+ stub.put("/users/1") { [200, {}, { id: 1, fullname: "Lindsay Fünke" }.to_json] }
364
376
  end
365
377
  end
366
378
 
@@ -369,32 +381,32 @@ describe Her::Model::ORM do
369
381
 
370
382
  it "handle resource data update without saving it" do
371
383
  @user = Foo::User.find(1)
372
- @user.fullname.should == "Tobias Fünke"
384
+ expect(@user.fullname).to eq("Tobias Fünke")
373
385
  @user.fullname = "Kittie Sanchez"
374
- @user.fullname.should == "Kittie Sanchez"
386
+ expect(@user.fullname).to eq("Kittie Sanchez")
375
387
  end
376
388
 
377
389
  it "handle resource update through the .update class method" do
378
- @user = Foo::User.save_existing(1, { :fullname => "Lindsay Fünke" })
379
- @user.fullname.should == "Lindsay Fünke"
390
+ @user = Foo::User.save_existing(1, fullname: "Lindsay Fünke")
391
+ expect(@user.fullname).to eq("Lindsay Fünke")
380
392
  end
381
393
 
382
394
  it "handle resource update through #save on an existing resource" do
383
395
  @user = Foo::User.find(1)
384
396
  @user.fullname = "Lindsay Fünke"
385
397
  @user.save
386
- @user.fullname.should == "Lindsay Fünke"
398
+ expect(@user.fullname).to eq("Lindsay Fünke")
387
399
  end
388
400
  end
389
401
 
390
402
  context "deleting resources" do
391
403
  before do
392
- Her::API.setup :url => "https://api.example.com" do |builder|
404
+ Her::API.setup url: "https://api.example.com" do |builder|
393
405
  builder.use Her::Middleware::FirstLevelParseJSON
394
406
  builder.use Faraday::Request::UrlEncoded
395
407
  builder.adapter :test do |stub|
396
- stub.get("/users/1") { |env| [200, {}, { :id => 1, :fullname => "Tobias Fünke", :active => true }.to_json] }
397
- stub.delete("/users/1") { |env| [200, {}, { :id => 1, :fullname => "Lindsay Fünke", :active => false }.to_json] }
408
+ stub.get("/users/1") { [200, {}, { id: 1, fullname: "Tobias Fünke", active: true }.to_json] }
409
+ stub.delete("/users/1") { [200, {}, { id: 1, fullname: "Lindsay Fünke", active: false }.to_json] }
398
410
  end
399
411
  end
400
412
 
@@ -403,78 +415,103 @@ describe Her::Model::ORM do
403
415
 
404
416
  it "handle resource deletion through the .destroy class method" do
405
417
  @user = Foo::User.destroy_existing(1)
406
- @user.active.should be_falsey
407
- @user.should be_destroyed
418
+ expect(@user.active).to be_falsey
419
+ expect(@user).to be_destroyed
408
420
  end
409
421
 
410
422
  it "handle resource deletion through #destroy on an existing resource" do
411
423
  @user = Foo::User.find(1)
412
424
  @user.destroy
413
- @user.active.should be_falsey
414
- @user.should be_destroyed
425
+ expect(@user.active).to be_falsey
426
+ expect(@user).to be_destroyed
427
+ end
428
+
429
+ context "with params" do
430
+ before do
431
+ Her::API.setup url: "https://api.example.com" do |builder|
432
+ builder.use Her::Middleware::FirstLevelParseJSON
433
+ builder.use Faraday::Request::UrlEncoded
434
+ builder.adapter :test do |stub|
435
+ stub.delete("/users/1?delete_type=soft") { [200, {}, { id: 1, fullname: "Lindsay Fünke", active: false }.to_json] }
436
+ end
437
+ end
438
+ end
439
+
440
+ it "handle resource deletion through the .destroy class method" do
441
+ @user = Foo::User.destroy_existing(1, delete_type: "soft")
442
+ expect(@user.active).to be_falsey
443
+ expect(@user).to be_destroyed
444
+ end
445
+
446
+ it "handle resource deletion through #destroy on an existing resource" do
447
+ @user = Foo::User.find(1)
448
+ @user.destroy(delete_type: "soft")
449
+ expect(@user.active).to be_falsey
450
+ expect(@user).to be_destroyed
451
+ end
415
452
  end
416
453
  end
417
454
 
418
- context 'customizing HTTP methods' do
455
+ context "customizing HTTP methods" do
419
456
  before do
420
- Her::API.setup :url => "https://api.example.com" do |builder|
457
+ Her::API.setup url: "https://api.example.com" do |builder|
421
458
  builder.use Her::Middleware::FirstLevelParseJSON
422
459
  builder.use Faraday::Request::UrlEncoded
423
460
  end
424
461
  end
425
462
 
426
- context 'create' do
463
+ context "create" do
427
464
  before do
428
465
  Her::API.default_api.connection.adapter :test do |stub|
429
- stub.put('/users') { |env| [200, {}, { :id => 1, :fullname => 'Tobias Fünke' }.to_json] }
466
+ stub.put("/users") { [200, {}, { id: 1, fullname: "Tobias Fünke" }.to_json] }
430
467
  end
431
- spawn_model 'Foo::User' do
468
+ spawn_model "Foo::User" do
432
469
  attributes :fullname, :email
433
- method_for :create, 'PUT'
470
+ method_for :create, "PUT"
434
471
  end
435
472
  end
436
473
 
437
- context 'for top-level class' do
438
- it 'uses the custom method (PUT) instead of default method (POST)' do
439
- user = Foo::User.new(:fullname => 'Tobias Fünke')
440
- user.should be_new
441
- user.save.should be_truthy
474
+ context "for top-level class" do
475
+ it "uses the custom method (PUT) instead of default method (POST)" do
476
+ user = Foo::User.new(fullname: "Tobias Fünke")
477
+ expect(user).to be_new
478
+ expect(user.save).to be_truthy
442
479
  end
443
480
  end
444
481
 
445
- context 'for children class' do
482
+ context "for children class" do
446
483
  before do
447
484
  class User < Foo::User; end
448
485
  @spawned_models << :User
449
486
  end
450
487
 
451
- it 'uses the custom method (PUT) instead of default method (POST)' do
452
- user = User.new(:fullname => 'Tobias Fünke')
453
- user.should be_new
454
- user.save.should be_truthy
488
+ it "uses the custom method (PUT) instead of default method (POST)" do
489
+ user = User.new(fullname: "Tobias Fünke")
490
+ expect(user).to be_new
491
+ expect(user.save).to be_truthy
455
492
  end
456
493
  end
457
494
  end
458
495
 
459
- context 'update' do
496
+ context "update" do
460
497
  before do
461
498
  Her::API.default_api.connection.adapter :test do |stub|
462
- stub.get('/users/1') { |env| [200, {}, { :id => 1, :fullname => 'Lindsay Fünke' }.to_json] }
463
- stub.post('/users/1') { |env| [200, {}, { :id => 1, :fullname => 'Tobias Fünke' }.to_json] }
499
+ stub.get("/users/1") { [200, {}, { id: 1, fullname: "Lindsay Fünke" }.to_json] }
500
+ stub.post("/users/1") { [200, {}, { id: 1, fullname: "Tobias Fünke" }.to_json] }
464
501
  end
465
502
 
466
- spawn_model 'Foo::User' do
503
+ spawn_model "Foo::User" do
467
504
  attributes :fullname, :email
468
505
  method_for :update, :post
469
506
  end
470
507
  end
471
508
 
472
- it 'uses the custom method (POST) instead of default method (PUT)' do
509
+ it "uses the custom method (POST) instead of default method (PUT)" do
473
510
  user = Foo::User.find(1)
474
- user.fullname.should eq 'Lindsay Fünke'
475
- user.fullname = 'Toby Fünke'
511
+ expect(user.fullname).to eq "Lindsay Fünke"
512
+ user.fullname = "Toby Fünke"
476
513
  user.save
477
- user.fullname.should eq 'Tobias Fünke'
514
+ expect(user.fullname).to eq "Tobias Fünke"
478
515
  end
479
516
  end
480
517
  end