her 0.10.4 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +29 -8
- data/gemfiles/Gemfile.activemodel-4.2 +0 -1
- data/gemfiles/{Gemfile.activemodel-3.2.x → Gemfile.activemodel-5.0} +1 -2
- data/gemfiles/{Gemfile.activemodel-4.0 → Gemfile.activemodel-5.1} +1 -2
- data/gemfiles/{Gemfile.activemodel-4.1 → Gemfile.activemodel-5.2} +1 -2
- data/her.gemspec +1 -2
- data/lib/her/model/associations/belongs_to_association.rb +1 -1
- data/lib/her/model/attributes.rb +1 -1
- data/lib/her/model/orm.rb +1 -4
- data/lib/her/model/parse.rb +1 -2
- data/lib/her/version.rb +1 -1
- data/spec/model/associations_spec.rb +3 -2
- data/spec/model/attributes_spec.rb +13 -61
- data/spec/model/parse_spec.rb +0 -22
- metadata +7 -33
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 72114f9b29011146dffc658a0e7d4e4982ded486
|
4
|
+
data.tar.gz: c2118def58a8024890fba2115b921adeee329783
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 110eb7da65e83503c0922e787999ea4125886d105ea0e70f23abed9539ea6342f288953c69445b1664b7680c2e96884777ef2aaf5af1bbfda9b629c67fa557ea
|
7
|
+
data.tar.gz: 39020447959095c9b29b270102f64648b272520e4d88f7e2e3f4ae7e3f8212b74c07e323b44b8702272d79237d20f3a5386e8436d5a367bfa9f87f7d830f0bb7
|
data/.travis.yml
CHANGED
@@ -3,18 +3,39 @@ language: ruby
|
|
3
3
|
sudo: false
|
4
4
|
|
5
5
|
rvm:
|
6
|
-
- 2.4.2
|
7
|
-
- 2.3.5
|
8
|
-
- 2.2.8
|
9
|
-
- 2.1.6
|
10
|
-
- 2.0.0
|
11
6
|
- 1.9.3
|
7
|
+
- 2.0.0
|
8
|
+
- 2.1.6
|
9
|
+
- 2.2.8
|
10
|
+
- 2.3.5
|
11
|
+
- 2.4.2
|
12
12
|
|
13
13
|
gemfile:
|
14
14
|
- gemfiles/Gemfile.activemodel-4.2
|
15
|
-
- gemfiles/Gemfile.activemodel-
|
16
|
-
- gemfiles/Gemfile.activemodel-
|
17
|
-
- gemfiles/Gemfile.activemodel-
|
15
|
+
- gemfiles/Gemfile.activemodel-5.0
|
16
|
+
- gemfiles/Gemfile.activemodel-5.1
|
17
|
+
- gemfiles/Gemfile.activemodel-5.2
|
18
|
+
|
19
|
+
matrix:
|
20
|
+
exclude:
|
21
|
+
- gemfile: gemfiles/Gemfile.activemodel-5.0
|
22
|
+
rvm: 1.9.3
|
23
|
+
- gemfile: gemfiles/Gemfile.activemodel-5.0
|
24
|
+
rvm: 2.0.0
|
25
|
+
- gemfile: gemfiles/Gemfile.activemodel-5.0
|
26
|
+
rvm: 2.1.6
|
27
|
+
- gemfile: gemfiles/Gemfile.activemodel-5.1
|
28
|
+
rvm: 1.9.3
|
29
|
+
- gemfile: gemfiles/Gemfile.activemodel-5.1
|
30
|
+
rvm: 2.0.0
|
31
|
+
- gemfile: gemfiles/Gemfile.activemodel-5.1
|
32
|
+
rvm: 2.1.6
|
33
|
+
- gemfile: gemfiles/Gemfile.activemodel-5.2
|
34
|
+
rvm: 1.9.3
|
35
|
+
- gemfile: gemfiles/Gemfile.activemodel-5.2
|
36
|
+
rvm: 2.0.0
|
37
|
+
- gemfile: gemfiles/Gemfile.activemodel-5.2
|
38
|
+
rvm: 2.1.6
|
18
39
|
|
19
40
|
before_install:
|
20
41
|
- gem install bundler
|
data/her.gemspec
CHANGED
@@ -21,8 +21,7 @@ Gem::Specification.new do |s|
|
|
21
21
|
s.add_development_dependency "rspec", "~> 3.5"
|
22
22
|
s.add_development_dependency "json", "~> 1.8"
|
23
23
|
|
24
|
-
s.add_runtime_dependency "activemodel", ">=
|
25
|
-
s.add_runtime_dependency "activesupport", ">= 3.0.0", "< 5.2.0"
|
24
|
+
s.add_runtime_dependency "activemodel", ">= 4.2.1"
|
26
25
|
s.add_runtime_dependency "faraday", ">= 0.8", "< 1.0"
|
27
26
|
s.add_runtime_dependency "multi_json", "~> 1.7"
|
28
27
|
end
|
@@ -80,7 +80,7 @@ module Her
|
|
80
80
|
return @parent.attributes[@name] unless @params.any? || @parent.attributes[@name].blank?
|
81
81
|
|
82
82
|
path_params = @parent.attributes.merge(@params.merge(@klass.primary_key => foreign_key_value))
|
83
|
-
path = build_association_path
|
83
|
+
path = build_association_path lambda { @klass.build_request_path(path_params) }
|
84
84
|
@klass.get_resource(path, @params).tap do |result|
|
85
85
|
@cached_result = result if @params.blank?
|
86
86
|
end
|
data/lib/her/model/attributes.rb
CHANGED
@@ -162,7 +162,7 @@ module Her
|
|
162
162
|
attributes = klass.parse(record).merge(_metadata: parsed_data[:metadata],
|
163
163
|
_errors: parsed_data[:errors])
|
164
164
|
klass.new(attributes).tap do |record|
|
165
|
-
record.
|
165
|
+
record.send :clear_changes_information
|
166
166
|
record.run_callbacks :find
|
167
167
|
end
|
168
168
|
end
|
data/lib/her/model/orm.rb
CHANGED
@@ -44,10 +44,7 @@ module Her
|
|
44
44
|
self.class.request(to_params.merge(:_method => method, :_path => request_path)) do |parsed_data, response|
|
45
45
|
load_from_parsed_data(parsed_data)
|
46
46
|
return false if !response.success? || @response_errors.any?
|
47
|
-
|
48
|
-
@previously_changed = self.changes.clone
|
49
|
-
self.changed_attributes.clear
|
50
|
-
end
|
47
|
+
changes_applied
|
51
48
|
end
|
52
49
|
end
|
53
50
|
end
|
data/lib/her/model/parse.rb
CHANGED
data/lib/her/version.rb
CHANGED
@@ -661,7 +661,8 @@ describe Her::Model::Associations do
|
|
661
661
|
builder.adapter :test do |stub|
|
662
662
|
stub.get("/users/1") { [200, {}, { id: 1, name: "Tobias Fünke", organization: { id: 1, name: "Bluth Company Inc." }, organization_id: 1 }.to_json] }
|
663
663
|
stub.get("/users/4") { [200, {}, { id: 1, name: "Tobias Fünke", organization: { id: 1, name: "Bluth Company Inc." } }.to_json] }
|
664
|
-
stub.get("/users/3") { [200, {}, { id: 2, name: "Lindsay Fünke",
|
664
|
+
stub.get("/users/3") { [200, {}, { id: 2, name: "Lindsay Fünke", company: nil }.to_json] }
|
665
|
+
stub.get("/companies/1") { [200, {}, { id: 1, name: "Bluth Company" }.to_json] }
|
665
666
|
end
|
666
667
|
end
|
667
668
|
end
|
@@ -698,7 +699,7 @@ describe Her::Model::Associations do
|
|
698
699
|
builder.use Faraday::Request::UrlEncoded
|
699
700
|
builder.adapter :test do |stub|
|
700
701
|
stub.get("/users/2") { [200, {}, { id: 2, name: "Lindsay Fünke", organization_id: 1 }.to_json] }
|
701
|
-
stub.get("/
|
702
|
+
stub.get("/companies/1") { [200, {}, { id: 1, name: "Bluth Company" }.to_json] }
|
702
703
|
end
|
703
704
|
end
|
704
705
|
end
|
@@ -310,10 +310,16 @@ describe Her::Model::Attributes do
|
|
310
310
|
context "when attribute methods are already defined" do
|
311
311
|
before do
|
312
312
|
class AbstractUser
|
313
|
-
|
313
|
+
def fullname
|
314
|
+
raise NotImplementedError
|
315
|
+
end
|
316
|
+
|
317
|
+
def fullname=(value)
|
318
|
+
raise NotImplementedError
|
319
|
+
end
|
314
320
|
|
315
321
|
def fullname?
|
316
|
-
|
322
|
+
raise NotImplementedError
|
317
323
|
end
|
318
324
|
end
|
319
325
|
@spawned_models << :AbstractUser
|
@@ -324,72 +330,18 @@ describe Her::Model::Attributes do
|
|
324
330
|
end
|
325
331
|
|
326
332
|
it "overrides getter method" do
|
327
|
-
expect(Foo::User.generated_attribute_methods.instance_methods).to include(:fullname)
|
328
|
-
end
|
329
|
-
|
330
|
-
it "overrides setter method" do
|
331
|
-
expect(Foo::User.generated_attribute_methods.instance_methods).to include(:fullname=)
|
332
|
-
end
|
333
|
-
|
334
|
-
it "overrides predicate method" do
|
335
|
-
expect(Foo::User.generated_attribute_methods.instance_methods).to include(:fullname?)
|
336
|
-
end
|
337
|
-
|
338
|
-
it "defines setter that affects attributes" do
|
339
333
|
user = Foo::User.new
|
340
|
-
user.fullname
|
341
|
-
expect(user.attributes[:fullname]).to eq("Tobias Fünke")
|
334
|
+
expect { user.fullname }.to_not raise_error(NotImplementedError)
|
342
335
|
end
|
343
336
|
|
344
|
-
it "
|
337
|
+
it "overrides setter method" do
|
345
338
|
user = Foo::User.new
|
346
|
-
user.
|
347
|
-
expect(user.fullname).to eq("Tobias Fünke")
|
339
|
+
expect { user.fullname = "foo" }.to_not raise_error(NotImplementedError)
|
348
340
|
end
|
349
341
|
|
350
|
-
it "
|
342
|
+
it "overrides predicate method" do
|
351
343
|
user = Foo::User.new
|
352
|
-
expect
|
353
|
-
user.attributes[:fullname] = "Tobias Fünke"
|
354
|
-
expect(user.fullname?).to be_truthy
|
355
|
-
end
|
356
|
-
end
|
357
|
-
|
358
|
-
if ActiveModel::VERSION::MAJOR < 4
|
359
|
-
it "creates a new mutex" do
|
360
|
-
expect(Mutex).to receive(:new).once.and_call_original
|
361
|
-
spawn_model "Foo::User" do
|
362
|
-
attributes :fullname
|
363
|
-
end
|
364
|
-
expect(Foo::User.attribute_methods_mutex).not_to eq(Foo::User.generated_attribute_methods)
|
365
|
-
end
|
366
|
-
|
367
|
-
it "works well with Module#synchronize monkey patched by ActiveSupport" do
|
368
|
-
Module.class_eval do
|
369
|
-
def synchronize(*_args)
|
370
|
-
raise "gotcha!"
|
371
|
-
end
|
372
|
-
end
|
373
|
-
expect(Mutex).to receive(:new).once.and_call_original
|
374
|
-
spawn_model "Foo::User" do
|
375
|
-
attributes :fullname
|
376
|
-
end
|
377
|
-
expect(Foo::User.attribute_methods_mutex).not_to eq(Foo::User.generated_attribute_methods)
|
378
|
-
Module.class_eval do
|
379
|
-
undef :synchronize
|
380
|
-
end
|
381
|
-
end
|
382
|
-
else
|
383
|
-
it "uses ActiveModel's mutex" do
|
384
|
-
expect(Foo::User.attribute_methods_mutex).to eq(Foo::User.generated_attribute_methods)
|
385
|
-
end
|
386
|
-
end
|
387
|
-
|
388
|
-
it "uses a mutex" do
|
389
|
-
spawn_model "Foo::User"
|
390
|
-
expect(Foo::User.attribute_methods_mutex).to receive(:synchronize).once.and_call_original
|
391
|
-
Foo::User.class_eval do
|
392
|
-
attributes :fullname, :documents
|
344
|
+
expect { user.fullname? }.to_not raise_error(NotImplementedError)
|
393
345
|
end
|
394
346
|
end
|
395
347
|
end
|
data/spec/model/parse_spec.rb
CHANGED
@@ -251,7 +251,6 @@ describe Her::Model::Parse do
|
|
251
251
|
|
252
252
|
it "parse the data with the symbol" do
|
253
253
|
@new_user = Foo::User.create(fullname: "Lindsay Fünke")
|
254
|
-
expect(@new_user.id).to eq(1)
|
255
254
|
expect(@new_user.fullname).to eq("Lindsay Fünke")
|
256
255
|
end
|
257
256
|
end
|
@@ -494,25 +493,4 @@ describe Her::Model::Parse do
|
|
494
493
|
expect(user.to_params).to eq(model: { name: 'foo' })
|
495
494
|
end
|
496
495
|
end
|
497
|
-
|
498
|
-
context "when attribute uses the same name as root element" do
|
499
|
-
before do
|
500
|
-
Her::API.setup url: "https://api.example.com" do |builder|
|
501
|
-
builder.use Her::Middleware::FirstLevelParseJSON
|
502
|
-
builder.use Faraday::Request::UrlEncoded
|
503
|
-
end
|
504
|
-
|
505
|
-
Her::API.default_api.connection.adapter :test do |stub|
|
506
|
-
stub.post("/users") { |env| [200, {}, { user: "foobar", id: 1, fullname: params(env)[:fullname] }.to_json] }
|
507
|
-
end
|
508
|
-
|
509
|
-
spawn_model "Foo::User"
|
510
|
-
end
|
511
|
-
|
512
|
-
it "parses as attribute instead of root element" do
|
513
|
-
user = Foo::User.create(fullname: "barfoo")
|
514
|
-
expect(user.fullname).to eq "barfoo"
|
515
|
-
expect(user.user).to eq "foobar"
|
516
|
-
end
|
517
|
-
end
|
518
496
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: her
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rémi Prévost
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-04-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -58,40 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
62
|
-
- - "<"
|
63
|
-
- !ruby/object:Gem::Version
|
64
|
-
version: 5.2.0
|
61
|
+
version: 4.2.1
|
65
62
|
type: :runtime
|
66
63
|
prerelease: false
|
67
64
|
version_requirements: !ruby/object:Gem::Requirement
|
68
65
|
requirements:
|
69
66
|
- - ">="
|
70
67
|
- !ruby/object:Gem::Version
|
71
|
-
version:
|
72
|
-
- - "<"
|
73
|
-
- !ruby/object:Gem::Version
|
74
|
-
version: 5.2.0
|
75
|
-
- !ruby/object:Gem::Dependency
|
76
|
-
name: activesupport
|
77
|
-
requirement: !ruby/object:Gem::Requirement
|
78
|
-
requirements:
|
79
|
-
- - ">="
|
80
|
-
- !ruby/object:Gem::Version
|
81
|
-
version: 3.0.0
|
82
|
-
- - "<"
|
83
|
-
- !ruby/object:Gem::Version
|
84
|
-
version: 5.2.0
|
85
|
-
type: :runtime
|
86
|
-
prerelease: false
|
87
|
-
version_requirements: !ruby/object:Gem::Requirement
|
88
|
-
requirements:
|
89
|
-
- - ">="
|
90
|
-
- !ruby/object:Gem::Version
|
91
|
-
version: 3.0.0
|
92
|
-
- - "<"
|
93
|
-
- !ruby/object:Gem::Version
|
94
|
-
version: 5.2.0
|
68
|
+
version: 4.2.1
|
95
69
|
- !ruby/object:Gem::Dependency
|
96
70
|
name: faraday
|
97
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -144,10 +118,10 @@ files:
|
|
144
118
|
- README.md
|
145
119
|
- Rakefile
|
146
120
|
- UPGRADE.md
|
147
|
-
- gemfiles/Gemfile.activemodel-3.2.x
|
148
|
-
- gemfiles/Gemfile.activemodel-4.0
|
149
|
-
- gemfiles/Gemfile.activemodel-4.1
|
150
121
|
- gemfiles/Gemfile.activemodel-4.2
|
122
|
+
- gemfiles/Gemfile.activemodel-5.0
|
123
|
+
- gemfiles/Gemfile.activemodel-5.1
|
124
|
+
- gemfiles/Gemfile.activemodel-5.2
|
151
125
|
- her.gemspec
|
152
126
|
- lib/her.rb
|
153
127
|
- lib/her/api.rb
|