her 0.8.2 → 0.10.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +1 -1
  3. data/.rubocop.yml +1291 -0
  4. data/.travis.yml +6 -1
  5. data/README.md +29 -11
  6. data/her.gemspec +3 -5
  7. data/lib/her/api.rb +16 -9
  8. data/lib/her/middleware/json_api_parser.rb +1 -1
  9. data/lib/her/model/associations/association.rb +32 -5
  10. data/lib/her/model/associations/association_proxy.rb +1 -1
  11. data/lib/her/model/associations/belongs_to_association.rb +1 -1
  12. data/lib/her/model/associations/has_many_association.rb +3 -3
  13. data/lib/her/model/attributes.rb +105 -75
  14. data/lib/her/model/http.rb +3 -3
  15. data/lib/her/model/introspection.rb +1 -1
  16. data/lib/her/model/orm.rb +96 -19
  17. data/lib/her/model/parse.rb +27 -17
  18. data/lib/her/model/relation.rb +46 -2
  19. data/lib/her/version.rb +1 -1
  20. data/spec/api_spec.rb +34 -31
  21. data/spec/collection_spec.rb +25 -10
  22. data/spec/json_api/model_spec.rb +75 -72
  23. data/spec/middleware/accept_json_spec.rb +1 -1
  24. data/spec/middleware/first_level_parse_json_spec.rb +20 -20
  25. data/spec/middleware/json_api_parser_spec.rb +26 -7
  26. data/spec/middleware/second_level_parse_json_spec.rb +8 -9
  27. data/spec/model/associations/association_proxy_spec.rb +2 -5
  28. data/spec/model/associations_spec.rb +617 -295
  29. data/spec/model/attributes_spec.rb +114 -107
  30. data/spec/model/callbacks_spec.rb +59 -27
  31. data/spec/model/dirty_spec.rb +70 -29
  32. data/spec/model/http_spec.rb +67 -35
  33. data/spec/model/introspection_spec.rb +26 -22
  34. data/spec/model/nested_attributes_spec.rb +31 -31
  35. data/spec/model/orm_spec.rb +332 -157
  36. data/spec/model/parse_spec.rb +250 -77
  37. data/spec/model/paths_spec.rb +109 -109
  38. data/spec/model/relation_spec.rb +89 -69
  39. data/spec/model/validations_spec.rb +6 -6
  40. data/spec/model_spec.rb +17 -17
  41. data/spec/spec_helper.rb +2 -3
  42. data/spec/support/macros/model_macros.rb +2 -2
  43. metadata +36 -63
@@ -10,64 +10,64 @@ describe Her::Model::Paths do
10
10
 
11
11
  describe "#request_path" do
12
12
  it "builds paths with defaults" do
13
- Foo::User.new(:id => "foo").request_path.should == "users/foo"
14
- Foo::User.new(:id => nil).request_path.should == "users"
15
- Foo::User.new().request_path.should == "users"
13
+ expect(Foo::User.new(id: "foo").request_path).to eq("users/foo")
14
+ expect(Foo::User.new(id: nil).request_path).to eq("users")
15
+ expect(Foo::User.new.request_path).to eq("users")
16
16
  end
17
17
 
18
18
  it "builds paths with custom collection path" do
19
19
  Foo::User.collection_path "/utilisateurs"
20
- Foo::User.new(:id => "foo").request_path.should == "/utilisateurs/foo"
21
- Foo::User.new().request_path.should == "/utilisateurs"
20
+ expect(Foo::User.new(id: "foo").request_path).to eq("/utilisateurs/foo")
21
+ expect(Foo::User.new.request_path).to eq("/utilisateurs")
22
22
  end
23
23
 
24
24
  it "builds paths with custom relative collection path" do
25
25
  Foo::User.collection_path "utilisateurs"
26
- Foo::User.new(:id => "foo").request_path.should == "utilisateurs/foo"
27
- Foo::User.new().request_path.should == "utilisateurs"
26
+ expect(Foo::User.new(id: "foo").request_path).to eq("utilisateurs/foo")
27
+ expect(Foo::User.new.request_path).to eq("utilisateurs")
28
28
  end
29
29
 
30
30
  it "builds paths with custom collection path with multiple variables" do
31
31
  Foo::User.collection_path "/organizations/:organization_id/utilisateurs"
32
32
 
33
- Foo::User.new(:id => "foo").request_path(:_organization_id => "acme").should == "/organizations/acme/utilisateurs/foo"
34
- Foo::User.new().request_path(:_organization_id => "acme").should == "/organizations/acme/utilisateurs"
33
+ expect(Foo::User.new(id: "foo").request_path(_organization_id: "acme")).to eq("/organizations/acme/utilisateurs/foo")
34
+ expect(Foo::User.new.request_path(_organization_id: "acme")).to eq("/organizations/acme/utilisateurs")
35
35
 
36
- Foo::User.new(:id => "foo", :organization_id => "acme").request_path.should == "/organizations/acme/utilisateurs/foo"
37
- Foo::User.new(:organization_id => "acme").request_path.should == "/organizations/acme/utilisateurs"
36
+ expect(Foo::User.new(id: "foo", organization_id: "acme").request_path).to eq("/organizations/acme/utilisateurs/foo")
37
+ expect(Foo::User.new(organization_id: "acme").request_path).to eq("/organizations/acme/utilisateurs")
38
38
  end
39
39
 
40
40
  it "builds paths with custom relative collection path with multiple variables" do
41
41
  Foo::User.collection_path "organizations/:organization_id/utilisateurs"
42
42
 
43
- Foo::User.new(:id => "foo").request_path(:_organization_id => "acme").should == "organizations/acme/utilisateurs/foo"
44
- Foo::User.new().request_path(:_organization_id => "acme").should == "organizations/acme/utilisateurs"
43
+ expect(Foo::User.new(id: "foo").request_path(_organization_id: "acme")).to eq("organizations/acme/utilisateurs/foo")
44
+ expect(Foo::User.new.request_path(_organization_id: "acme")).to eq("organizations/acme/utilisateurs")
45
45
 
46
- Foo::User.new(:id => "foo", :organization_id => "acme").request_path.should == "organizations/acme/utilisateurs/foo"
47
- Foo::User.new(:organization_id => "acme").request_path.should == "organizations/acme/utilisateurs"
46
+ expect(Foo::User.new(id: "foo", organization_id: "acme").request_path).to eq("organizations/acme/utilisateurs/foo")
47
+ expect(Foo::User.new(organization_id: "acme").request_path).to eq("organizations/acme/utilisateurs")
48
48
  end
49
49
 
50
50
  it "builds paths with custom item path" do
51
51
  Foo::User.resource_path "/utilisateurs/:id"
52
- Foo::User.new(:id => "foo").request_path.should == "/utilisateurs/foo"
53
- Foo::User.new().request_path.should == "users"
52
+ expect(Foo::User.new(id: "foo").request_path).to eq("/utilisateurs/foo")
53
+ expect(Foo::User.new.request_path).to eq("users")
54
54
  end
55
55
 
56
56
  it "builds paths with custom relative item path" do
57
57
  Foo::User.resource_path "utilisateurs/:id"
58
- Foo::User.new(:id => "foo").request_path.should == "utilisateurs/foo"
59
- Foo::User.new().request_path.should == "users"
58
+ expect(Foo::User.new(id: "foo").request_path).to eq("utilisateurs/foo")
59
+ expect(Foo::User.new.request_path).to eq("users")
60
60
  end
61
61
 
62
62
  it "raises exceptions when building a path without required custom variables" do
63
63
  Foo::User.collection_path "/organizations/:organization_id/utilisateurs"
64
- expect { Foo::User.new(:id => "foo").request_path }.to raise_error(Her::Errors::PathError, "Missing :_organization_id parameter to build the request path. Path is `/organizations/:organization_id/utilisateurs/:id`. Parameters are `{:id=>\"foo\"}`.")
64
+ expect { Foo::User.new(id: "foo").request_path }.to raise_error(Her::Errors::PathError, "Missing :_organization_id parameter to build the request path. Path is `/organizations/:organization_id/utilisateurs/:id`. Parameters are `{:id=>\"foo\"}`.")
65
65
  end
66
66
 
67
67
  it "escapes the variable values" do
68
68
  Foo::User.collection_path "organizations/:organization_id/utilisateurs"
69
- Foo::User.new(:id => "Привет").request_path(:_organization_id => 'лол').should == "organizations/%D0%BB%D0%BE%D0%BB/utilisateurs/%D0%9F%D1%80%D0%B8%D0%B2%D0%B5%D1%82"
70
- Foo::User.new(:organization_id => 'лол', :id => "Привет").request_path.should == "organizations/%D0%BB%D0%BE%D0%BB/utilisateurs/%D0%9F%D1%80%D0%B8%D0%B2%D0%B5%D1%82"
69
+ expect(Foo::User.new(id: "Привет").request_path(_organization_id: "лол")).to eq("organizations/%D0%BB%D0%BE%D0%BB/utilisateurs/%D0%9F%D1%80%D0%B8%D0%B2%D0%B5%D1%82")
70
+ expect(Foo::User.new(organization_id: "лол", id: "Привет").request_path).to eq("organizations/%D0%BB%D0%BE%D0%BB/utilisateurs/%D0%9F%D1%80%D0%B8%D0%B2%D0%B5%D1%82")
71
71
  end
72
72
  end
73
73
  end
@@ -79,65 +79,65 @@ describe Her::Model::Paths do
79
79
 
80
80
  describe "#request_path" do
81
81
  it "builds paths with defaults" do
82
- Foo::AdminUser.new(:id => "foo").request_path.should == "admin_users/foo"
83
- Foo::AdminUser.new().request_path.should == "admin_users"
82
+ expect(Foo::AdminUser.new(id: "foo").request_path).to eq("admin_users/foo")
83
+ expect(Foo::AdminUser.new.request_path).to eq("admin_users")
84
84
  end
85
85
 
86
86
  it "builds paths with custom collection path" do
87
87
  Foo::AdminUser.collection_path "/users"
88
- Foo::AdminUser.new(:id => "foo").request_path.should == "/users/foo"
89
- Foo::AdminUser.new().request_path.should == "/users"
88
+ expect(Foo::AdminUser.new(id: "foo").request_path).to eq("/users/foo")
89
+ expect(Foo::AdminUser.new.request_path).to eq("/users")
90
90
  end
91
91
 
92
92
  it "builds paths with custom relative collection path" do
93
93
  Foo::AdminUser.collection_path "users"
94
- Foo::AdminUser.new(:id => "foo").request_path.should == "users/foo"
95
- Foo::AdminUser.new().request_path.should == "users"
94
+ expect(Foo::AdminUser.new(id: "foo").request_path).to eq("users/foo")
95
+ expect(Foo::AdminUser.new.request_path).to eq("users")
96
96
  end
97
97
 
98
98
  it "builds paths with custom collection path with multiple variables" do
99
99
  Foo::AdminUser.collection_path "/organizations/:organization_id/users"
100
- Foo::AdminUser.new(:id => "foo").request_path(:_organization_id => "acme").should == "/organizations/acme/users/foo"
101
- Foo::AdminUser.new().request_path(:_organization_id => "acme").should == "/organizations/acme/users"
100
+ expect(Foo::AdminUser.new(id: "foo").request_path(_organization_id: "acme")).to eq("/organizations/acme/users/foo")
101
+ expect(Foo::AdminUser.new.request_path(_organization_id: "acme")).to eq("/organizations/acme/users")
102
102
  end
103
103
 
104
104
  it "builds paths with custom relative collection path with multiple variables" do
105
105
  Foo::AdminUser.collection_path "organizations/:organization_id/users"
106
- Foo::AdminUser.new(:id => "foo").request_path(:_organization_id => "acme").should == "organizations/acme/users/foo"
107
- Foo::AdminUser.new().request_path(:_organization_id => "acme").should == "organizations/acme/users"
106
+ expect(Foo::AdminUser.new(id: "foo").request_path(_organization_id: "acme")).to eq("organizations/acme/users/foo")
107
+ expect(Foo::AdminUser.new.request_path(_organization_id: "acme")).to eq("organizations/acme/users")
108
108
  end
109
109
 
110
110
  it "builds paths with custom item path" do
111
111
  Foo::AdminUser.resource_path "/users/:id"
112
- Foo::AdminUser.new(:id => "foo").request_path.should == "/users/foo"
113
- Foo::AdminUser.new().request_path.should == "admin_users"
112
+ expect(Foo::AdminUser.new(id: "foo").request_path).to eq("/users/foo")
113
+ expect(Foo::AdminUser.new.request_path).to eq("admin_users")
114
114
  end
115
115
 
116
116
  it "builds paths with custom relative item path" do
117
117
  Foo::AdminUser.resource_path "users/:id"
118
- Foo::AdminUser.new(:id => "foo").request_path.should == "users/foo"
119
- Foo::AdminUser.new().request_path.should == "admin_users"
118
+ expect(Foo::AdminUser.new(id: "foo").request_path).to eq("users/foo")
119
+ expect(Foo::AdminUser.new.request_path).to eq("admin_users")
120
120
  end
121
121
 
122
122
  it "raises exceptions when building a path without required custom variables" do
123
123
  Foo::AdminUser.collection_path "/organizations/:organization_id/users"
124
- expect { Foo::AdminUser.new(:id => "foo").request_path }.to raise_error(Her::Errors::PathError, "Missing :_organization_id parameter to build the request path. Path is `/organizations/:organization_id/users/:id`. Parameters are `{:id=>\"foo\"}`.")
124
+ expect { Foo::AdminUser.new(id: "foo").request_path }.to raise_error(Her::Errors::PathError, "Missing :_organization_id parameter to build the request path. Path is `/organizations/:organization_id/users/:id`. Parameters are `{:id=>\"foo\"}`.")
125
125
  end
126
126
 
127
127
  it "raises exceptions when building a relative path without required custom variables" do
128
128
  Foo::AdminUser.collection_path "organizations/:organization_id/users"
129
- expect { Foo::AdminUser.new(:id => "foo").request_path }.to raise_error(Her::Errors::PathError, "Missing :_organization_id parameter to build the request path. Path is `organizations/:organization_id/users/:id`. Parameters are `{:id=>\"foo\"}`.")
129
+ expect { Foo::AdminUser.new(id: "foo").request_path }.to raise_error(Her::Errors::PathError, "Missing :_organization_id parameter to build the request path. Path is `organizations/:organization_id/users/:id`. Parameters are `{:id=>\"foo\"}`.")
130
130
  end
131
131
  end
132
132
  end
133
133
 
134
134
  context "children model" do
135
135
  before do
136
- Her::API.setup :url => "https://api.example.com" do |builder|
136
+ Her::API.setup url: "https://api.example.com" do |builder|
137
137
  builder.use Her::Middleware::FirstLevelParseJSON
138
138
  builder.use Faraday::Request::UrlEncoded
139
139
  builder.adapter :test do |stub|
140
- stub.get("/users/foo") { |env| [200, {}, { :id => 'foo' }.to_json] }
140
+ stub.get("/users/foo") { [200, {}, { id: "foo" }.to_json] }
141
141
  end
142
142
  end
143
143
 
@@ -148,8 +148,8 @@ describe Her::Model::Paths do
148
148
  end
149
149
 
150
150
  it "builds path using the children model name" do
151
- User.find('foo').id.should == 'foo'
152
- User.find('foo').id.should == 'foo'
151
+ expect(User.find("foo").id).to eq("foo")
152
+ expect(User.find("foo").id).to eq("foo")
153
153
  end
154
154
  end
155
155
 
@@ -160,34 +160,34 @@ describe Her::Model::Paths do
160
160
 
161
161
  describe "#request_path" do
162
162
  it "builds paths with defaults" do
163
- Foo::User.new(:id => "foo").request_path.should == "users/foo"
164
- Foo::User.new.request_path.should == "users"
163
+ expect(Foo::User.new(id: "foo").request_path).to eq("users/foo")
164
+ expect(Foo::User.new.request_path).to eq("users")
165
165
  end
166
166
  end
167
167
  end
168
168
 
169
- context 'custom primary key' do
169
+ context "custom primary key" do
170
170
  before do
171
- spawn_model 'User' do
172
- primary_key 'UserId'
173
- resource_path 'users/:UserId'
171
+ spawn_model "User" do
172
+ primary_key "UserId"
173
+ resource_path "users/:UserId"
174
174
  end
175
175
 
176
- spawn_model 'Customer' do
176
+ spawn_model "Customer" do
177
177
  primary_key :customer_id
178
- resource_path 'customers/:id'
178
+ resource_path "customers/:id"
179
179
  end
180
180
  end
181
181
 
182
- describe '#request_path' do
183
- it 'uses the correct primary key attribute' do
184
- User.new(:UserId => 'foo').request_path.should == 'users/foo'
185
- User.new(:id => 'foo').request_path.should == 'users'
182
+ describe "#request_path" do
183
+ it "uses the correct primary key attribute" do
184
+ expect(User.new(UserId: "foo").request_path).to eq("users/foo")
185
+ expect(User.new(id: "foo").request_path).to eq("users")
186
186
  end
187
187
 
188
- it 'replaces :id with the appropriate primary key' do
189
- Customer.new(:customer_id => 'joe').request_path.should == 'customers/joe'
190
- Customer.new(:id => 'joe').request_path.should == 'customers'
188
+ it "replaces :id with the appropriate primary key" do
189
+ expect(Customer.new(customer_id: "joe").request_path).to eq("customers/joe")
190
+ expect(Customer.new(id: "joe").request_path).to eq("customers")
191
191
  end
192
192
  end
193
193
  end
@@ -195,15 +195,15 @@ describe Her::Model::Paths do
195
195
 
196
196
  context "making subdomain HTTP requests" do
197
197
  before do
198
- Her::API.setup :url => "https://api.example.com/" do |builder|
198
+ Her::API.setup url: "https://api.example.com/" do |builder|
199
199
  builder.use Her::Middleware::FirstLevelParseJSON
200
200
  builder.use Faraday::Request::UrlEncoded
201
201
  builder.adapter :test do |stub|
202
- stub.get("organizations/2/users") { |env| [200, {}, [{ :id => 1, :fullname => "Tobias Fünke", :organization_id => 2 }, { :id => 2, :fullname => "Lindsay Fünke", :organization_id => 2 }].to_json] }
203
- stub.post("organizations/2/users") { |env| [200, {}, { :id => 1, :fullname => "Tobias Fünke", :organization_id => 2 }.to_json] }
204
- stub.put("organizations/2/users/1") { |env| [200, {}, { :id => 1, :fullname => "Lindsay Fünke", :organization_id => 2 }.to_json] }
205
- stub.get("organizations/2/users/1") { |env| [200, {}, { :id => 1, :fullname => "Tobias Fünke", :organization_id => 2, :active => true }.to_json] }
206
- stub.delete("organizations/2/users/1") { |env| [200, {}, { :id => 1, :fullname => "Lindsay Fünke", :organization_id => 2, :active => false }.to_json] }
202
+ stub.get("organizations/2/users") { [200, {}, [{ id: 1, fullname: "Tobias Fünke", organization_id: 2 }, { id: 2, fullname: "Lindsay Fünke", organization_id: 2 }].to_json] }
203
+ stub.post("organizations/2/users") { [200, {}, { id: 1, fullname: "Tobias Fünke", organization_id: 2 }.to_json] }
204
+ stub.put("organizations/2/users/1") { [200, {}, { id: 1, fullname: "Lindsay Fünke", organization_id: 2 }.to_json] }
205
+ stub.get("organizations/2/users/1") { [200, {}, { id: 1, fullname: "Tobias Fünke", organization_id: 2, active: true }.to_json] }
206
+ stub.delete("organizations/2/users/1") { [200, {}, { id: 1, fullname: "Lindsay Fünke", organization_id: 2, active: false }.to_json] }
207
207
  end
208
208
  end
209
209
 
@@ -214,94 +214,94 @@ describe Her::Model::Paths do
214
214
 
215
215
  describe "fetching a resource" do
216
216
  it "maps a single resource to a Ruby object" do
217
- @user = Foo::User.find(1, :_organization_id => 2)
218
- @user.id.should == 1
219
- @user.fullname.should == "Tobias Fünke"
217
+ @user = Foo::User.find(1, _organization_id: 2)
218
+ expect(@user.id).to eq(1)
219
+ expect(@user.fullname).to eq("Tobias Fünke")
220
220
  end
221
221
 
222
222
  it "maps a single resource using a scope to a Ruby object" do
223
- Foo::User.scope :for_organization, lambda { |o| where(:organization_id => o) }
223
+ Foo::User.scope :for_organization, ->(o) { where(organization_id: o) }
224
224
  @user = Foo::User.for_organization(2).find(1)
225
- @user.id.should == 1
226
- @user.fullname.should == "Tobias Fünke"
225
+ expect(@user.id).to eq(1)
226
+ expect(@user.fullname).to eq("Tobias Fünke")
227
227
  end
228
228
  end
229
229
 
230
230
  describe "fetching a collection" do
231
231
  it "maps a collection of resources to an array of Ruby objects" do
232
- @users = Foo::User.where(:_organization_id => 2).all
233
- @users.length.should == 2
234
- @users.first.fullname.should == "Tobias Fünke"
232
+ @users = Foo::User.where(_organization_id: 2).all
233
+ expect(@users.length).to eq(2)
234
+ expect(@users.first.fullname).to eq("Tobias Fünke")
235
235
  end
236
236
  end
237
237
 
238
238
  describe "handling new resource" do
239
239
  it "handles new resource" do
240
- @new_user = Foo::User.new(:fullname => "Tobias Fünke", :organization_id => 2)
241
- @new_user.new?.should be_truthy
240
+ @new_user = Foo::User.new(fullname: "Tobias Fünke", organization_id: 2)
241
+ expect(@new_user.new?).to be_truthy
242
242
 
243
- @existing_user = Foo::User.find(1, :_organization_id => 2)
244
- @existing_user.new?.should be_falsey
243
+ @existing_user = Foo::User.find(1, _organization_id: 2)
244
+ expect(@existing_user.new?).to be_falsey
245
245
  end
246
246
  end
247
247
 
248
248
  describe "creating resources" do
249
249
  it "handle one-line resource creation" do
250
- @user = Foo::User.create(:fullname => "Tobias Fünke", :organization_id => 2)
251
- @user.id.should == 1
252
- @user.fullname.should == "Tobias Fünke"
250
+ @user = Foo::User.create(fullname: "Tobias Fünke", organization_id: 2)
251
+ expect(@user.id).to eq(1)
252
+ expect(@user.fullname).to eq("Tobias Fünke")
253
253
  end
254
254
 
255
255
  it "handle resource creation through Model.new + #save" do
256
- @user = Foo::User.new(:fullname => "Tobias Fünke", :organization_id => 2)
256
+ @user = Foo::User.new(fullname: "Tobias Fünke", organization_id: 2)
257
257
  @user.save
258
- @user.fullname.should == "Tobias Fünke"
258
+ expect(@user.fullname).to eq("Tobias Fünke")
259
259
  end
260
260
  end
261
261
 
262
262
  context "updating resources" do
263
263
  it "handle resource data update without saving it" do
264
- @user = Foo::User.find(1, :_organization_id => 2)
265
- @user.fullname.should == "Tobias Fünke"
264
+ @user = Foo::User.find(1, _organization_id: 2)
265
+ expect(@user.fullname).to eq("Tobias Fünke")
266
266
  @user.fullname = "Kittie Sanchez"
267
- @user.fullname.should == "Kittie Sanchez"
267
+ expect(@user.fullname).to eq("Kittie Sanchez")
268
268
  end
269
269
 
270
270
  it "handle resource update through the .update class method" do
271
- @user = Foo::User.save_existing(1, { :fullname => "Lindsay Fünke", :organization_id => 2 })
272
- @user.fullname.should == "Lindsay Fünke"
271
+ @user = Foo::User.save_existing(1, fullname: "Lindsay Fünke", organization_id: 2)
272
+ expect(@user.fullname).to eq("Lindsay Fünke")
273
273
  end
274
274
 
275
275
  it "handle resource update through #save on an existing resource" do
276
- @user = Foo::User.find(1, :_organization_id => 2)
276
+ @user = Foo::User.find(1, _organization_id: 2)
277
277
  @user.fullname = "Lindsay Fünke"
278
278
  @user.save
279
- @user.fullname.should == "Lindsay Fünke"
279
+ expect(@user.fullname).to eq("Lindsay Fünke")
280
280
  end
281
281
  end
282
282
 
283
283
  context "deleting resources" do
284
284
  it "handle resource deletion through the .destroy class method" do
285
- @user = Foo::User.destroy_existing(1, :_organization_id => 2)
286
- @user.active.should be_falsey
285
+ @user = Foo::User.destroy_existing(1, _organization_id: 2)
286
+ expect(@user.active).to be_falsey
287
287
  end
288
288
 
289
289
  it "handle resource deletion through #destroy on an existing resource" do
290
- @user = Foo::User.find(1, :_organization_id => 2)
290
+ @user = Foo::User.find(1, _organization_id: 2)
291
291
  @user.destroy
292
- @user.active.should be_falsey
292
+ expect(@user.active).to be_falsey
293
293
  end
294
294
  end
295
295
  end
296
296
 
297
297
  context "making path HTTP requests" do
298
298
  before do
299
- Her::API.setup :url => "https://example.com/api/" do |builder|
299
+ Her::API.setup url: "https://example.com/api/" do |builder|
300
300
  builder.use Her::Middleware::FirstLevelParseJSON
301
301
  builder.use Faraday::Request::UrlEncoded
302
302
  builder.adapter :test do |stub|
303
- stub.get("/api/organizations/2/users") { |env| [200, {}, [{ :id => 1, :fullname => "Tobias Fünke", :organization_id => 2 }, { :id => 2, :fullname => "Lindsay Fünke", :organization_id => 2 }].to_json] }
304
- stub.get("/api/organizations/2/users/1") { |env| [200, {}, { :id => 1, :fullname => "Tobias Fünke", :organization_id => 2, :active => true }.to_json] }
303
+ stub.get("/api/organizations/2/users") { [200, {}, [{ id: 1, fullname: "Tobias Fünke", organization_id: 2 }, { id: 2, fullname: "Lindsay Fünke", organization_id: 2 }].to_json] }
304
+ stub.get("/api/organizations/2/users/1") { [200, {}, { id: 1, fullname: "Tobias Fünke", organization_id: 2, active: true }.to_json] }
305
305
  end
306
306
  end
307
307
 
@@ -312,35 +312,35 @@ describe Her::Model::Paths do
312
312
 
313
313
  describe "fetching a resource" do
314
314
  it "maps a single resource to a Ruby object" do
315
- @user = Foo::User.find(1, :_organization_id => 2)
316
- @user.id.should == 1
317
- @user.fullname.should == "Tobias Fünke"
315
+ @user = Foo::User.find(1, _organization_id: 2)
316
+ expect(@user.id).to eq(1)
317
+ expect(@user.fullname).to eq("Tobias Fünke")
318
318
  end
319
319
  end
320
320
 
321
321
  describe "fetching a collection" do
322
322
  it "maps a collection of resources to an array of Ruby objects" do
323
- @users = Foo::User.where(:_organization_id => 2).all
324
- @users.length.should == 2
325
- @users.first.fullname.should == "Tobias Fünke"
323
+ @users = Foo::User.where(_organization_id: 2).all
324
+ expect(@users.length).to eq(2)
325
+ expect(@users.first.fullname).to eq("Tobias Fünke")
326
326
  end
327
327
  end
328
328
 
329
329
  describe "fetching a resource with absolute path" do
330
330
  it "maps a single resource to a Ruby object" do
331
- Foo::User.resource_path '/api/' + Foo::User.resource_path
332
- @user = Foo::User.find(1, :_organization_id => 2)
333
- @user.id.should == 1
334
- @user.fullname.should == "Tobias Fünke"
331
+ Foo::User.resource_path "/api/" + Foo::User.resource_path
332
+ @user = Foo::User.find(1, _organization_id: 2)
333
+ expect(@user.id).to eq(1)
334
+ expect(@user.fullname).to eq("Tobias Fünke")
335
335
  end
336
336
  end
337
337
 
338
338
  describe "fetching a collection with absolute path" do
339
339
  it "maps a collection of resources to an array of Ruby objects" do
340
- Foo::User.collection_path '/api/' + Foo::User.collection_path
341
- @users = Foo::User.where(:_organization_id => 2).all
342
- @users.length.should == 2
343
- @users.first.fullname.should == "Tobias Fünke"
340
+ Foo::User.collection_path "/api/" + Foo::User.collection_path
341
+ @users = Foo::User.where(_organization_id: 2).all
342
+ expect(@users.length).to eq(2)
343
+ expect(@users.first.fullname).to eq("Tobias Fünke")
344
344
  end
345
345
  end
346
346
  end