shamu 0.0.9 → 0.0.11
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.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/Gemfile +5 -3
- data/bin/rake +17 -0
- data/bin/rspec +17 -0
- data/lib/shamu/attributes.rb +3 -1
- data/lib/shamu/events/active_record/migration.rb +6 -6
- data/lib/shamu/json_api/builder_methods/identifier.rb +18 -4
- data/lib/shamu/json_api/context.rb +3 -1
- data/lib/shamu/json_api/error.rb +7 -1
- data/lib/shamu/json_api/presenter.rb +23 -1
- data/lib/shamu/json_api/rails/controller.rb +195 -62
- data/lib/shamu/locale/en.yml +3 -1
- data/lib/shamu/rails/controller.rb +5 -2
- data/lib/shamu/rails/entity.rb +29 -15
- data/lib/shamu/rails/railtie.rb +12 -7
- data/lib/shamu/services/active_record.rb +2 -2
- data/lib/shamu/services/active_record_crud.rb +36 -38
- data/lib/shamu/services/error.rb +11 -1
- data/lib/shamu/services/lazy_transform.rb +9 -4
- data/lib/shamu/services/request_support.rb +5 -2
- data/lib/shamu/services/result.rb +40 -7
- data/lib/shamu/services/service.rb +17 -8
- data/lib/shamu/services/service_call_failed_error.rb +4 -0
- data/lib/shamu/version.rb +2 -2
- data/shamu.gemspec +4 -4
- data/spec/lib/shamu/json_api/builder_methods/identifier_spec.rb +45 -0
- data/spec/lib/shamu/json_api/rails/controller_spec.rb +141 -7
- data/spec/lib/shamu/json_api/rails/responder_spec.rb +9 -9
- data/spec/lib/shamu/rails/controller_spec.rb +4 -4
- data/spec/lib/shamu/rails/entity_spec.rb +34 -16
- data/spec/lib/shamu/rails/features_spec.rb +6 -6
- data/spec/lib/shamu/services/active_record_crud_spec.rb +12 -7
- data/spec/lib/shamu/services/lazy_transform_spec.rb +23 -14
- data/spec/lib/shamu/services/request_support_spec.rb +15 -1
- data/spec/lib/shamu/services/result_spec.rb +37 -1
- data/spec/lib/shamu/services/service_spec.rb +25 -14
- data/spec/spec_helper.rb +1 -1
- metadata +23 -17
@@ -34,4 +34,40 @@ describe Shamu::Services::Result do
|
|
34
34
|
result = Shamu::Services::Result.new
|
35
35
|
expect( result.entity ).to be_nil
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
|
+
describe "#value!" do
|
39
|
+
it "raises an error if not valid" do
|
40
|
+
result = Shamu::Services::Result.new
|
41
|
+
result.errors.add :base, :whatever
|
42
|
+
|
43
|
+
expect do
|
44
|
+
result.value!
|
45
|
+
end.to raise_error Shamu::Services::ServiceRequestFailedError
|
46
|
+
end
|
47
|
+
|
48
|
+
it "returns #value if valid" do
|
49
|
+
result = Shamu::Services::Result.new :one
|
50
|
+
|
51
|
+
expect( result.value! ).to eq :one
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "#entity!" do
|
56
|
+
it "raises an error if not valid" do
|
57
|
+
entity = Shamu::Entities::Entity.new
|
58
|
+
result = Shamu::Services::Result.new entity
|
59
|
+
result.errors.add :base, :whatever
|
60
|
+
|
61
|
+
expect do
|
62
|
+
result.entity!
|
63
|
+
end.to raise_error Shamu::Services::ServiceRequestFailedError
|
64
|
+
end
|
65
|
+
|
66
|
+
it "returns #entity if valid" do
|
67
|
+
entity = Shamu::Entities::Entity.new
|
68
|
+
result = Shamu::Services::Result.new entity
|
69
|
+
|
70
|
+
expect( result.entity! ).to be entity
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -25,8 +25,10 @@ module ServiceSpec
|
|
25
25
|
public :lookup_association
|
26
26
|
public :lazy_association
|
27
27
|
|
28
|
-
def
|
29
|
-
|
28
|
+
def build_entities( records )
|
29
|
+
records.map do |record|
|
30
|
+
scorpion.fetch ServiceSpec::Entity, { record: record }, {}
|
31
|
+
end
|
30
32
|
end
|
31
33
|
end
|
32
34
|
|
@@ -51,10 +53,19 @@ describe Shamu::Services::Service do
|
|
51
53
|
|
52
54
|
let( :service ) { scorpion.new ServiceSpec::Service }
|
53
55
|
|
56
|
+
def transformer( &block )
|
57
|
+
->( records ) {
|
58
|
+
records.map do |r|
|
59
|
+
yield || r
|
60
|
+
end
|
61
|
+
}
|
62
|
+
end
|
63
|
+
|
64
|
+
|
54
65
|
describe "#entity_list" do
|
55
66
|
it "maps each record" do
|
56
67
|
expect do |b|
|
57
|
-
list = service.entity_list [ double ], &b
|
68
|
+
list = service.entity_list [ double ], &transformer( &b )
|
58
69
|
list.to_a
|
59
70
|
end.to yield_control
|
60
71
|
end
|
@@ -64,7 +75,7 @@ describe Shamu::Services::Service do
|
|
64
75
|
end
|
65
76
|
|
66
77
|
it "invokes build_entity if no transformer provided" do
|
67
|
-
expect( service ).to receive( :
|
78
|
+
expect( service ).to receive( :build_entities ).and_call_original
|
68
79
|
list = service.entity_list( [{}] )
|
69
80
|
list.first
|
70
81
|
end
|
@@ -100,7 +111,7 @@ describe Shamu::Services::Service do
|
|
100
111
|
|
101
112
|
it "yields for a matching id" do
|
102
113
|
expect do |b|
|
103
|
-
service.entity_lookup_list( records, [record.id], ServiceSpec::NullEntity, &b )
|
114
|
+
service.entity_lookup_list( records, [record.id], ServiceSpec::NullEntity, &transformer( &b ) )
|
104
115
|
end.to yield_control
|
105
116
|
end
|
106
117
|
|
@@ -109,24 +120,24 @@ describe Shamu::Services::Service do
|
|
109
120
|
end
|
110
121
|
|
111
122
|
it "matches on id by default" do
|
112
|
-
list = service.entity_lookup_list( records, [record.id], ServiceSpec::NullEntity ) do |
|
113
|
-
scorpion.fetch ServiceSpec::Entity, { record: r }, {}
|
123
|
+
list = service.entity_lookup_list( records, [record.id], ServiceSpec::NullEntity ) do |records|
|
124
|
+
records.map { |r| scorpion.fetch ServiceSpec::Entity, { record: r }, {} }
|
114
125
|
end
|
115
126
|
|
116
127
|
expect( list.first ).to be_present
|
117
128
|
end
|
118
129
|
|
119
130
|
it "matches on id with string numbers" do
|
120
|
-
list = service.entity_lookup_list( records, [record.id.to_s], ServiceSpec::NullEntity ) do |
|
121
|
-
scorpion.fetch ServiceSpec::Entity, { record: r }, {}
|
131
|
+
list = service.entity_lookup_list( records, [record.id.to_s], ServiceSpec::NullEntity ) do |records|
|
132
|
+
records.map { |r| scorpion.fetch ServiceSpec::Entity, { record: r }, {} }
|
122
133
|
end
|
123
134
|
|
124
135
|
expect( list.first ).to be_present
|
125
136
|
end
|
126
137
|
|
127
138
|
it "matches on a custom field" do
|
128
|
-
list = service.entity_lookup_list( records, [record.amount], ServiceSpec::NullEntity, match: :amount ) do |
|
129
|
-
scorpion.fetch ServiceSpec::Entity, { record: r }, {}
|
139
|
+
list = service.entity_lookup_list( records, [record.amount], ServiceSpec::NullEntity, match: :amount ) do |records|
|
140
|
+
records.map { |r| scorpion.fetch ServiceSpec::Entity, { record: r }, {} }
|
130
141
|
end
|
131
142
|
|
132
143
|
expect( list.first ).to be_present
|
@@ -134,8 +145,8 @@ describe Shamu::Services::Service do
|
|
134
145
|
|
135
146
|
it "matches with a custom proc" do
|
136
147
|
matcher = ->( record ) { record.amount }
|
137
|
-
list = service.entity_lookup_list( records, [record.amount], ServiceSpec::NullEntity, match: matcher ) do |
|
138
|
-
scorpion.fetch ServiceSpec::Entity, { record: r }, {}
|
148
|
+
list = service.entity_lookup_list( records, [record.amount], ServiceSpec::NullEntity, match: matcher ) do |records|
|
149
|
+
records.map { |r| scorpion.fetch ServiceSpec::Entity, { record: r }, {} }
|
139
150
|
end
|
140
151
|
|
141
152
|
expect( list.first ).to be_present
|
@@ -304,4 +315,4 @@ describe Shamu::Services::Service do
|
|
304
315
|
|
305
316
|
|
306
317
|
end
|
307
|
-
end
|
318
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -24,7 +24,7 @@ RSpec.configure do |config|
|
|
24
24
|
|
25
25
|
config.order = "random"
|
26
26
|
|
27
|
-
config.filter_gems_from_backtrace "activesupport", "actionpack", "actionview", "scorpion-ioc", "rspec-wait"
|
27
|
+
config.filter_gems_from_backtrace "activesupport", "actionpack", "actionview", "scorpion-ioc", "rspec-wait", "rspec-core", "rspec", "rspec-support", "rspec-expectations"
|
28
28
|
|
29
29
|
config.filter_run focus: true
|
30
30
|
config.filter_run_excluding :broken => true
|
metadata
CHANGED
@@ -1,57 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shamu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Alexander
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-05-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '5.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '5.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activesupport
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '5.0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '5.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: scorpion-ioc
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.
|
47
|
+
version: '0.6'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.
|
54
|
+
version: '0.6'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: multi_json
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -70,14 +70,14 @@ dependencies:
|
|
70
70
|
name: rack
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '1'
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '1'
|
83
83
|
- !ruby/object:Gem::Dependency
|
@@ -195,7 +195,9 @@ dependencies:
|
|
195
195
|
description:
|
196
196
|
email:
|
197
197
|
- me@phallguy.com
|
198
|
-
executables:
|
198
|
+
executables:
|
199
|
+
- rake
|
200
|
+
- rspec
|
199
201
|
extensions: []
|
200
202
|
extra_rdoc_files: []
|
201
203
|
files:
|
@@ -212,6 +214,8 @@ files:
|
|
212
214
|
- LICENSE
|
213
215
|
- README.md
|
214
216
|
- Rakefile
|
217
|
+
- bin/rake
|
218
|
+
- bin/rspec
|
215
219
|
- circle.yml
|
216
220
|
- config.ru
|
217
221
|
- lib/generators/shamu.rb
|
@@ -349,6 +353,7 @@ files:
|
|
349
353
|
- lib/shamu/services/request_support.rb
|
350
354
|
- lib/shamu/services/result.rb
|
351
355
|
- lib/shamu/services/service.rb
|
356
|
+
- lib/shamu/services/service_call_failed_error.rb
|
352
357
|
- lib/shamu/sessions.rb
|
353
358
|
- lib/shamu/sessions/README.md
|
354
359
|
- lib/shamu/sessions/cookie_store.rb
|
@@ -407,6 +412,7 @@ files:
|
|
407
412
|
- spec/lib/shamu/features/toggle_codec_spec.rb
|
408
413
|
- spec/lib/shamu/features/toggle_spec.rb
|
409
414
|
- spec/lib/shamu/json_api/base_builder_spec.rb
|
415
|
+
- spec/lib/shamu/json_api/builder_methods/identifier_spec.rb
|
410
416
|
- spec/lib/shamu/json_api/common_builder_spec.rb
|
411
417
|
- spec/lib/shamu/json_api/context_spec.rb
|
412
418
|
- spec/lib/shamu/json_api/error_builder_spec.rb
|
@@ -466,7 +472,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
466
472
|
version: '0'
|
467
473
|
requirements: []
|
468
474
|
rubyforge_project:
|
469
|
-
rubygems_version: 2.
|
475
|
+
rubygems_version: 2.6.10
|
470
476
|
signing_key:
|
471
477
|
specification_version: 4
|
472
478
|
summary: Have a whale of a good time adding Service Oriented Architecture to your
|
@@ -522,6 +528,7 @@ test_files:
|
|
522
528
|
- spec/lib/shamu/features/toggle_codec_spec.rb
|
523
529
|
- spec/lib/shamu/features/toggle_spec.rb
|
524
530
|
- spec/lib/shamu/json_api/base_builder_spec.rb
|
531
|
+
- spec/lib/shamu/json_api/builder_methods/identifier_spec.rb
|
525
532
|
- spec/lib/shamu/json_api/common_builder_spec.rb
|
526
533
|
- spec/lib/shamu/json_api/context_spec.rb
|
527
534
|
- spec/lib/shamu/json_api/error_builder_spec.rb
|
@@ -561,4 +568,3 @@ test_files:
|
|
561
568
|
- spec/support/active_record.rb
|
562
569
|
- spec/support/database.rb
|
563
570
|
- spec/support/logger.rb
|
564
|
-
has_rdoc:
|