praxis 2.0.pre.3 → 2.0.pre.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rspec +0 -1
- data/.ruby-version +1 -0
- data/CHANGELOG.md +26 -0
- data/Gemfile +1 -1
- data/Guardfile +2 -1
- data/Rakefile +1 -7
- data/TODO.md +28 -0
- data/lib/api_browser/package-lock.json +7110 -0
- data/lib/praxis.rb +7 -4
- data/lib/praxis/action_definition.rb +9 -16
- data/lib/praxis/api_general_info.rb +21 -0
- data/lib/praxis/application.rb +1 -2
- data/lib/praxis/bootloader_stages/routing.rb +2 -4
- data/lib/praxis/docs/generator.rb +11 -6
- data/lib/praxis/docs/open_api_generator.rb +255 -0
- data/lib/praxis/docs/openapi/info_object.rb +31 -0
- data/lib/praxis/docs/openapi/media_type_object.rb +59 -0
- data/lib/praxis/docs/openapi/operation_object.rb +40 -0
- data/lib/praxis/docs/openapi/parameter_object.rb +69 -0
- data/lib/praxis/docs/openapi/paths_object.rb +55 -0
- data/lib/praxis/docs/openapi/request_body_object.rb +51 -0
- data/lib/praxis/docs/openapi/response_object.rb +63 -0
- data/lib/praxis/docs/openapi/responses_object.rb +44 -0
- data/lib/praxis/docs/openapi/schema_object.rb +87 -0
- data/lib/praxis/docs/openapi/server_object.rb +24 -0
- data/lib/praxis/docs/openapi/tag_object.rb +21 -0
- data/lib/praxis/extensions/attribute_filtering.rb +2 -0
- data/lib/praxis/extensions/attribute_filtering/active_record_filter_query_builder.rb +148 -157
- data/lib/praxis/extensions/attribute_filtering/active_record_patches.rb +15 -0
- data/lib/praxis/extensions/attribute_filtering/active_record_patches/5x.rb +90 -0
- data/lib/praxis/extensions/attribute_filtering/active_record_patches/6_0.rb +68 -0
- data/lib/praxis/extensions/attribute_filtering/active_record_patches/6_1_plus.rb +58 -0
- data/lib/praxis/extensions/attribute_filtering/filter_tree_node.rb +35 -0
- data/lib/praxis/extensions/attribute_filtering/filtering_params.rb +13 -12
- data/lib/praxis/extensions/attribute_filtering/sequel_filter_query_builder.rb +3 -2
- data/lib/praxis/extensions/field_selection/active_record_query_selector.rb +7 -9
- data/lib/praxis/extensions/field_selection/field_selector.rb +4 -0
- data/lib/praxis/extensions/field_selection/sequel_query_selector.rb +6 -9
- data/lib/praxis/extensions/pagination.rb +130 -0
- data/lib/praxis/extensions/pagination/active_record_pagination_handler.rb +42 -0
- data/lib/praxis/extensions/pagination/header_generator.rb +70 -0
- data/lib/praxis/extensions/pagination/ordering_params.rb +238 -0
- data/lib/praxis/extensions/pagination/pagination_handler.rb +68 -0
- data/lib/praxis/extensions/pagination/pagination_params.rb +378 -0
- data/lib/praxis/extensions/pagination/sequel_pagination_handler.rb +45 -0
- data/lib/praxis/handlers/json.rb +2 -0
- data/lib/praxis/handlers/www_form.rb +5 -0
- data/lib/praxis/handlers/{xml.rb → xml-sample.rb} +6 -0
- data/lib/praxis/links.rb +4 -0
- data/lib/praxis/mapper/active_model_compat.rb +23 -5
- data/lib/praxis/mapper/resource.rb +16 -9
- data/lib/praxis/mapper/selector_generator.rb +11 -10
- data/lib/praxis/mapper/sequel_compat.rb +1 -0
- data/lib/praxis/media_type.rb +1 -56
- data/lib/praxis/multipart/part.rb +5 -2
- data/lib/praxis/plugins/mapper_plugin.rb +1 -1
- data/lib/praxis/plugins/pagination_plugin.rb +71 -0
- data/lib/praxis/resource_definition.rb +4 -12
- data/lib/praxis/response_definition.rb +1 -1
- data/lib/praxis/route.rb +2 -4
- data/lib/praxis/routing_config.rb +4 -8
- data/lib/praxis/tasks/api_docs.rb +23 -0
- data/lib/praxis/tasks/routes.rb +10 -15
- data/lib/praxis/types/media_type_common.rb +10 -0
- data/lib/praxis/types/multipart_array.rb +62 -0
- data/lib/praxis/validation_handler.rb +1 -2
- data/lib/praxis/version.rb +1 -1
- data/praxis.gemspec +4 -5
- data/spec/functional_spec.rb +9 -6
- data/spec/praxis/action_definition_spec.rb +4 -16
- data/spec/praxis/api_general_info_spec.rb +6 -6
- data/spec/praxis/extensions/attribute_filtering/active_record_filter_query_builder_spec.rb +304 -0
- data/spec/praxis/extensions/attribute_filtering/filter_tree_node_spec.rb +39 -0
- data/spec/praxis/extensions/attribute_filtering/filtering_params_spec.rb +34 -0
- data/spec/praxis/extensions/field_expansion_spec.rb +6 -24
- data/spec/praxis/extensions/field_selection/active_record_query_selector_spec.rb +15 -11
- data/spec/praxis/extensions/field_selection/sequel_query_selector_spec.rb +4 -3
- data/spec/praxis/extensions/pagination/active_record_pagination_handler_spec.rb +130 -0
- data/spec/praxis/extensions/{field_selection/support → support}/spec_resources_active_model.rb +45 -2
- data/spec/praxis/extensions/{field_selection/support → support}/spec_resources_sequel.rb +0 -0
- data/spec/praxis/mapper/selector_generator_spec.rb +32 -0
- data/spec/praxis/media_type_spec.rb +5 -129
- data/spec/praxis/request_spec.rb +3 -22
- data/spec/praxis/resource_definition_spec.rb +1 -1
- data/spec/praxis/response_definition_spec.rb +8 -9
- data/spec/praxis/route_spec.rb +2 -9
- data/spec/praxis/routing_config_spec.rb +4 -13
- data/spec/praxis/types/multipart_array_spec.rb +4 -21
- data/spec/spec_app/config/environment.rb +0 -2
- data/spec/spec_app/design/api.rb +7 -1
- data/spec/spec_app/design/media_types/instance.rb +0 -8
- data/spec/spec_app/design/media_types/volume.rb +0 -12
- data/spec/spec_app/design/resources/instances.rb +1 -2
- data/spec/spec_helper.rb +6 -0
- data/spec/support/spec_media_types.rb +0 -73
- metadata +51 -49
- data/spec/praxis/handlers/xml_spec.rb +0 -177
- data/spec/praxis/links_spec.rb +0 -68
@@ -37,7 +37,7 @@ describe Praxis::Extensions::FieldSelection::SequelQuerySelector do
|
|
37
37
|
# Pay the price for creating and connecting only in this spec instead in spec helper
|
38
38
|
# this way all other specs do not need to be slower and it's a better TDD experience
|
39
39
|
|
40
|
-
require_relative 'support/spec_resources_sequel.rb'
|
40
|
+
require_relative '../support/spec_resources_sequel.rb'
|
41
41
|
|
42
42
|
let(:selector_fields) do
|
43
43
|
{
|
@@ -65,9 +65,10 @@ describe Praxis::Extensions::FieldSelection::SequelQuerySelector do
|
|
65
65
|
end
|
66
66
|
|
67
67
|
let(:selector_node) { Praxis::Mapper::SelectorGenerator.new.add(SequelSimpleResource,selector_fields) }
|
68
|
-
subject {described_class.new(query: query, selectors: selector_node) }
|
68
|
+
subject {described_class.new(query: query, selectors: selector_node, debug: debug) }
|
69
69
|
|
70
70
|
context 'generate' do
|
71
|
+
let(:debug) { false }
|
71
72
|
context 'using the real models and DB' do
|
72
73
|
let(:query) { SequelSimpleModel }
|
73
74
|
|
@@ -109,7 +110,7 @@ describe Praxis::Extensions::FieldSelection::SequelQuerySelector do
|
|
109
110
|
it 'calls the explain debug method if enabled' do
|
110
111
|
suppress_output do
|
111
112
|
# Actually make it run all the way...but suppressing the output
|
112
|
-
subject.generate
|
113
|
+
subject.generate
|
113
114
|
end
|
114
115
|
end
|
115
116
|
end
|
@@ -0,0 +1,130 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require_relative '../support/spec_resources_active_model.rb'
|
4
|
+
require 'praxis/extensions/pagination'
|
5
|
+
|
6
|
+
class Book < Praxis::MediaType
|
7
|
+
attributes do
|
8
|
+
attribute :id, Integer
|
9
|
+
attribute :simple_name, String
|
10
|
+
attribute :category_uuid, String
|
11
|
+
end
|
12
|
+
end
|
13
|
+
Book.finalize!
|
14
|
+
BookPaginationParamsAttribute = Attributor::Attribute.new(Praxis::Types::PaginationParams.for(Book)) do
|
15
|
+
max_items 3
|
16
|
+
page_size 2
|
17
|
+
# disallow :paging
|
18
|
+
default by: :id
|
19
|
+
end
|
20
|
+
|
21
|
+
BookOrderingParamsAttribute = Attributor::Attribute.new(Praxis::Types::OrderingParams.for(Book)) do
|
22
|
+
enforce_for :all
|
23
|
+
end
|
24
|
+
|
25
|
+
describe Praxis::Extensions::Pagination::ActiveRecordPaginationHandler do
|
26
|
+
shared_examples 'sorts_the_same' do |op, expected|
|
27
|
+
let(:order_params) { BookOrderingParamsAttribute.load(op) }
|
28
|
+
it do
|
29
|
+
loaded_ids = subject.all.map(&:id)
|
30
|
+
expected_ids = expected.all.map(&:id)
|
31
|
+
expect(loaded_ids).to eq(expected_ids)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
shared_examples 'paginates_the_same' do |par, expected|
|
36
|
+
let(:paginator_params) { BookPaginationParamsAttribute.load(par) }
|
37
|
+
it do
|
38
|
+
loaded_ids = subject.all.map(&:id)
|
39
|
+
expected_ids = expected.all.map(&:id)
|
40
|
+
expect(loaded_ids).to eq(expected_ids)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
let(:query) { ActiveBook }
|
45
|
+
let(:table) { ActiveBook.table_name }
|
46
|
+
let(:paginator_params) { nil }
|
47
|
+
let(:order_params) { nil }
|
48
|
+
let(:pagination) do
|
49
|
+
Praxis::Extensions::Pagination::PaginationStruct.new(paginator_params, order_params)
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
context '.paginate' do
|
54
|
+
subject {described_class.paginate(query, pagination) }
|
55
|
+
|
56
|
+
context 'empty struct' do
|
57
|
+
let(:paginator_params) { nil }
|
58
|
+
|
59
|
+
it 'does not change the query with an empty struct' do
|
60
|
+
expect(subject).to be(query)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context 'page-based' do
|
65
|
+
it_behaves_like 'paginates_the_same', 'page=1,items=3',
|
66
|
+
::ActiveBook.limit(3)
|
67
|
+
it_behaves_like 'paginates_the_same', 'page=2,items=3',
|
68
|
+
::ActiveBook.offset(3).limit(3)
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'page-based with defaults' do
|
72
|
+
it_behaves_like 'paginates_the_same', '',
|
73
|
+
::ActiveBook.offset(0).limit(2)
|
74
|
+
it_behaves_like 'paginates_the_same', 'page=2',
|
75
|
+
::ActiveBook.offset(2).limit(2)
|
76
|
+
end
|
77
|
+
|
78
|
+
context 'cursor-based' do
|
79
|
+
it_behaves_like 'paginates_the_same', 'by=id,items=3',
|
80
|
+
::ActiveBook.limit(3).order(id: :asc)
|
81
|
+
it_behaves_like 'paginates_the_same', 'by=id,from=1000,items=3',
|
82
|
+
::ActiveBook.where("id > 1000").limit(3).order(id: :asc)
|
83
|
+
it_behaves_like 'paginates_the_same', 'by=simple_name,from=Book1000,items=3',
|
84
|
+
::ActiveBook.where("simple_name > 'Book1000'").limit(3).order(simple_name: :asc)
|
85
|
+
end
|
86
|
+
|
87
|
+
context 'cursor-based with defaults' do
|
88
|
+
it_behaves_like 'paginates_the_same', '',
|
89
|
+
::ActiveBook.limit(2).order(id: :asc)
|
90
|
+
it_behaves_like 'paginates_the_same', 'by=id,from=1000',
|
91
|
+
::ActiveBook.where("id > 1000").limit(2).order(id: :asc)
|
92
|
+
end
|
93
|
+
|
94
|
+
context 'including order' do
|
95
|
+
let(:order_params) { BookOrderingParamsAttribute.load(op_string) }
|
96
|
+
|
97
|
+
context 'when compatible with cursor' do
|
98
|
+
let(:op_string){ 'id'}
|
99
|
+
# Compatible cursor field
|
100
|
+
it_behaves_like 'paginates_the_same', 'by=id,items=3',
|
101
|
+
::ActiveBook.limit(3).order(id: :asc)
|
102
|
+
end
|
103
|
+
|
104
|
+
context 'when incompatible with cursor' do
|
105
|
+
let(:op_string){ 'id'}
|
106
|
+
let(:paginator_params) { BookPaginationParamsAttribute.load('by=simple_name,items=3') }
|
107
|
+
it do
|
108
|
+
expect{subject.all}.to raise_error(described_class::PaginationException, /is incompatible with pagination/)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
context '.order' do
|
115
|
+
subject {described_class.order(query, pagination.order) }
|
116
|
+
|
117
|
+
it 'does not change the query with an empty struct' do
|
118
|
+
expect(subject).to be(query)
|
119
|
+
end
|
120
|
+
|
121
|
+
it_behaves_like 'sorts_the_same', 'simple_name',
|
122
|
+
::ActiveBook.order(simple_name: :asc)
|
123
|
+
it_behaves_like 'sorts_the_same', '-simple_name',
|
124
|
+
::ActiveBook.order(simple_name: :desc)
|
125
|
+
it_behaves_like 'sorts_the_same', '-simple_name,id',
|
126
|
+
::ActiveBook.order(simple_name: :desc, id: :asc)
|
127
|
+
it_behaves_like 'sorts_the_same', '-simple_name,-id',
|
128
|
+
::ActiveBook.order(simple_name: :desc, id: :desc)
|
129
|
+
end
|
130
|
+
end
|
data/spec/praxis/extensions/{field_selection/support → support}/spec_resources_active_model.rb
RENAMED
@@ -36,6 +36,7 @@ def create_tables
|
|
36
36
|
create_table :active_taggings do |table|
|
37
37
|
table.column :book_id, :integer
|
38
38
|
table.column :tag_id, :integer
|
39
|
+
table.column :label, :string, null: true
|
39
40
|
end
|
40
41
|
end
|
41
42
|
end
|
@@ -48,8 +49,12 @@ class ActiveBook < ActiveRecord::Base
|
|
48
49
|
|
49
50
|
belongs_to :category, class_name: 'ActiveCategory', foreign_key: :category_uuid, primary_key: :uuid
|
50
51
|
belongs_to :author, class_name: 'ActiveAuthor'
|
52
|
+
|
51
53
|
has_many :taggings, class_name: 'ActiveTagging', foreign_key: :book_id
|
54
|
+
has_many :primary_taggings, lambda { where(label: 'primary')}, class_name: 'ActiveTagging', foreign_key: :book_id
|
55
|
+
|
52
56
|
has_many :tags, class_name: 'ActiveTag', through: :taggings
|
57
|
+
has_many :primary_tags, class_name: 'ActiveTag', through: :primary_taggings, source: :tag
|
53
58
|
end
|
54
59
|
|
55
60
|
class ActiveAuthor < ActiveRecord::Base
|
@@ -64,6 +69,8 @@ end
|
|
64
69
|
|
65
70
|
class ActiveTag < ActiveRecord::Base
|
66
71
|
include Praxis::Mapper::ActiveModelCompat
|
72
|
+
has_many :taggings, class_name: 'ActiveTagging', foreign_key: :tag_id
|
73
|
+
has_many :books, class_name: 'ActiveBook', through: :taggings, source: :book
|
67
74
|
end
|
68
75
|
|
69
76
|
class ActiveTagging < ActiveRecord::Base
|
@@ -94,6 +101,26 @@ end
|
|
94
101
|
class ActiveBookResource < ActiveBaseResource
|
95
102
|
model ActiveBook
|
96
103
|
|
104
|
+
filters_mapping(
|
105
|
+
id: :id,
|
106
|
+
category_uuid: :category_uuid,
|
107
|
+
'fake_nested.name': 'simple_name',
|
108
|
+
'name': 'simple_name',
|
109
|
+
'name_is_not': lambda do |spec| # Silly way to use a proc, but good enough for testing
|
110
|
+
{ name: :simple_name, value: spec[:value] , op: '!=' } # Can be an array for multiple conditions as well
|
111
|
+
end,
|
112
|
+
'author.id': 'author.id',
|
113
|
+
'author.name': 'author.name',
|
114
|
+
'taggings.label': 'taggings.label',
|
115
|
+
'taggings.tag_id': 'taggings.tag_id',
|
116
|
+
'taggings.tag.taggings.tag_id': 'taggings.tag.taggings.tag_id',
|
117
|
+
'tags.name': 'tags.name',
|
118
|
+
'primary_tags.name': 'primary_tags.name',
|
119
|
+
'category.name': 'category.name',
|
120
|
+
'category.books.name': 'category.books.simple_name',
|
121
|
+
'category.books.taggings.tag_id': 'category.books.taggings.tag_id',
|
122
|
+
'category.books.taggings.label': 'category.books.taggings.label',
|
123
|
+
)
|
97
124
|
# Forces to add an extra column (added_column)...and yet another (author_id) that will serve
|
98
125
|
# to check that if that's already automatically added due to an association, it won't interfere or duplicate
|
99
126
|
property :author, dependencies: [:author, :added_column, :author_id]
|
@@ -108,23 +135,39 @@ def seed_data
|
|
108
135
|
|
109
136
|
author1 = ActiveAuthor.create( id: 11, name: 'author1' )
|
110
137
|
author2 = ActiveAuthor.create( id: 22, name: 'author2' )
|
138
|
+
author3 = ActiveAuthor.create( id: 33, name: nil )
|
111
139
|
|
112
140
|
tag_blue = ActiveTag.create(id: 1 , name: 'blue' )
|
113
141
|
tag_red = ActiveTag.create(id: 2 , name: 'red' )
|
142
|
+
tag_green = ActiveTag.create(id: 3 , name: 'green' )
|
114
143
|
|
115
144
|
book1 = ActiveBook.create( id: 1 , simple_name: 'Book1', category_uuid: 'deadbeef1')
|
116
145
|
book1.author = author1
|
117
146
|
book1.category = cat1
|
118
147
|
book1.save
|
119
|
-
ActiveTagging.create(book: book1, tag: tag_blue)
|
148
|
+
ActiveTagging.create(book: book1, tag: tag_blue, label: 'primary')
|
120
149
|
ActiveTagging.create(book: book1, tag: tag_red)
|
150
|
+
ActiveTagging.create(book: book1, tag: tag_green, label: 'primary')
|
121
151
|
|
122
152
|
|
123
153
|
book2 = ActiveBook.create( id: 2 , simple_name: 'Book2', category_uuid: 'deadbeef1')
|
124
154
|
book2.author = author2
|
125
155
|
book2.category = cat2
|
126
156
|
book2.save
|
127
|
-
ActiveTagging.create(book: book2, tag: tag_red)
|
157
|
+
ActiveTagging.create(book: book2, tag: tag_red, label: 'primary')
|
158
|
+
|
159
|
+
book3 = ActiveBook.create( id: 3 , simple_name: 'Book3', category_uuid: 'deadbeef1')
|
160
|
+
book3.author = author3
|
161
|
+
book3.save
|
162
|
+
ActiveTagging.create(book: book3, tag: tag_red, label: 'primary')
|
163
|
+
|
164
|
+
# More stuff
|
165
|
+
|
166
|
+
10.times do |i|
|
167
|
+
bid = 1000+i
|
168
|
+
ActiveBook.create( id: bid , simple_name: "Book#{bid}")
|
169
|
+
end
|
170
|
+
|
128
171
|
end
|
129
172
|
|
130
173
|
seed_data
|
File without changes
|
@@ -181,6 +181,38 @@ describe Praxis::Mapper::SelectorGenerator do
|
|
181
181
|
end
|
182
182
|
it_behaves_like 'a proper selector'
|
183
183
|
end
|
184
|
+
|
185
|
+
context 'merging multiple tracks with the same name within a node' do
|
186
|
+
let(:fields) do
|
187
|
+
{ # Both everything_from_parent and parent will track the underlying 'parent' assoc
|
188
|
+
# ...and the final respective fields and tracks will need to be merged together.
|
189
|
+
# columns will be merged by just *, and tracks will merge true with simple children
|
190
|
+
everything_from_parent: true,
|
191
|
+
parent: {
|
192
|
+
simple_children: true
|
193
|
+
}
|
194
|
+
}
|
195
|
+
end
|
196
|
+
let(:selectors) do
|
197
|
+
{
|
198
|
+
model: SimpleModel,
|
199
|
+
columns: [:parent_id, :added_column],
|
200
|
+
tracks: {
|
201
|
+
parent: {
|
202
|
+
model: ParentModel,
|
203
|
+
columns: [:*],
|
204
|
+
tracks: {
|
205
|
+
simple_children: {
|
206
|
+
model: SimpleModel,
|
207
|
+
columns: [:parent_id]
|
208
|
+
}
|
209
|
+
}
|
210
|
+
}
|
211
|
+
}
|
212
|
+
}
|
213
|
+
end
|
214
|
+
it_behaves_like 'a proper selector'
|
215
|
+
end
|
184
216
|
end
|
185
217
|
|
186
218
|
context 'string associations' do
|
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Praxis::MediaType do
|
4
|
-
let(:owner_resource) { instance_double(Person, id: 100, name: /[:name:]/.gen, href: '/'
|
5
|
-
let(:manager_resource) { instance_double(Person, id: 101, name: /[:name:]/.gen, href: '/'
|
6
|
-
let(:custodian_resource) { instance_double(Person, id: 102, name: /[:name:]/.gen, href: '/'
|
4
|
+
let(:owner_resource) { instance_double(Person, id: 100, name: /[:name:]/.gen, href: '/') }
|
5
|
+
let(:manager_resource) { instance_double(Person, id: 101, name: /[:name:]/.gen, href: '/') }
|
6
|
+
let(:custodian_resource) { instance_double(Person, id: 102, name: /[:name:]/.gen, href: '/') }
|
7
7
|
let(:residents_summary_resource) do
|
8
8
|
instance_double(Person::CollectionSummary, href: "/people", size: 2)
|
9
9
|
end
|
@@ -27,15 +27,6 @@ describe Praxis::MediaType do
|
|
27
27
|
its(:id) { should eq(1) }
|
28
28
|
its(:name) { should eq('Home') }
|
29
29
|
its(:owner) { should be_instance_of(Person) }
|
30
|
-
|
31
|
-
context 'links' do
|
32
|
-
it 'respects using' do
|
33
|
-
expect(address.links.super).to be_kind_of(Person)
|
34
|
-
expect(address.links.super.object).to be(resource.manager)
|
35
|
-
expect(address.links.caretaker.object).to be(resource.custodian)
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
39
30
|
end
|
40
31
|
|
41
32
|
|
@@ -62,36 +53,6 @@ describe Praxis::MediaType do
|
|
62
53
|
|
63
54
|
its(:description) { should be_kind_of(String) }
|
64
55
|
|
65
|
-
context 'links' do
|
66
|
-
context 'with a custom links attribute' do
|
67
|
-
subject(:person) { Person.new(owner_resource) }
|
68
|
-
|
69
|
-
its(:links) { should be_kind_of(Array) }
|
70
|
-
its(:links) { should eq(owner_resource.links) }
|
71
|
-
end
|
72
|
-
|
73
|
-
context 'using the links DSL' do
|
74
|
-
subject(:address) { Address.new(resource) }
|
75
|
-
its(:links) { should be_kind_of(Address::Links) }
|
76
|
-
|
77
|
-
it 'inherits types appropriately' do
|
78
|
-
links_attribute = Address::Links.attributes
|
79
|
-
expect(links_attribute[:owner].type).to be(Person)
|
80
|
-
expect(links_attribute[:super].type).to be(Person)
|
81
|
-
expect(links_attribute[:caretaker].type).to be(Person)
|
82
|
-
end
|
83
|
-
|
84
|
-
context 'loading returned values' do
|
85
|
-
subject(:residents) { address.links.residents }
|
86
|
-
let(:residents_summary_resource) do
|
87
|
-
{href: "/people", size: 2}
|
88
|
-
end
|
89
|
-
|
90
|
-
its(:href) { should eq('/people') }
|
91
|
-
its(:size) { should eq(2) }
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
56
|
end
|
96
57
|
|
97
58
|
context "rendering" do
|
@@ -102,43 +63,8 @@ describe Praxis::MediaType do
|
|
102
63
|
its([:owner]) { should eq(Person.dump(owner_resource, view: :default)) }
|
103
64
|
its([:fields]) { should eq(address.fields.dump ) }
|
104
65
|
|
105
|
-
context 'links' do
|
106
|
-
subject(:links) { output[:links] }
|
107
|
-
|
108
|
-
its([:owner]) { should eq(Person.dump(owner_resource, view: :link)) }
|
109
|
-
its([:super]) { should eq(Person.dump(manager_resource, view: :link)) }
|
110
|
-
|
111
|
-
context 'for a collection summary' do
|
112
|
-
let(:volume) { Volume.example }
|
113
|
-
let(:snapshots_summary) { volume.snapshots_summary }
|
114
|
-
let(:output) { volume.render(view: :default) }
|
115
|
-
subject { links[:snapshots] }
|
116
|
-
|
117
|
-
its([:name]) { should eq(snapshots_summary.name) }
|
118
|
-
its([:size]) { should eq(snapshots_summary.size) }
|
119
|
-
its([:href]) { should eq(snapshots_summary.href) }
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
|
124
|
-
end
|
125
|
-
|
126
|
-
context '.example' do
|
127
|
-
subject(:example) { Address.example }
|
128
|
-
|
129
|
-
its('links.owner') { should be(example.owner) }
|
130
|
-
its('links.super') { should be(example.object.manager) }
|
131
|
-
|
132
|
-
it 'does not respond to non-top-level attributes from links' do
|
133
|
-
expect { example.super }.to raise_error(NoMethodError)
|
134
|
-
end
|
135
|
-
|
136
|
-
it 'responds to non-top-level attributes from links on its inner Struct' do
|
137
|
-
expect(example.links.super).to be(example.object.manager)
|
138
|
-
end
|
139
66
|
end
|
140
67
|
|
141
|
-
|
142
68
|
context 'describing' do
|
143
69
|
|
144
70
|
subject(:described){ Address.describe }
|
@@ -161,10 +87,10 @@ describe Praxis::MediaType do
|
|
161
87
|
its([:name]) { should eq(Address.name) }
|
162
88
|
its([:identifier]) { should eq(Address.identifier.to_s) }
|
163
89
|
it 'should include the defined views' do
|
164
|
-
expect( subject[:views].keys ).to match_array([:default, :master
|
90
|
+
expect( subject[:views].keys ).to match_array([:default, :master])
|
165
91
|
end
|
166
92
|
it 'should include the defined attributes' do
|
167
|
-
expect( subject[:attributes].keys ).to match_array([:id, :name, :owner, :custodian, :residents, :residents_summary, :
|
93
|
+
expect( subject[:attributes].keys ).to match_array([:id, :name, :owner, :custodian, :residents, :residents_summary, :fields])
|
168
94
|
end
|
169
95
|
end
|
170
96
|
|
@@ -182,56 +108,6 @@ describe Praxis::MediaType do
|
|
182
108
|
|
183
109
|
subject(:output) { field_resolver.resolve(User,fields) }
|
184
110
|
|
185
|
-
|
186
|
-
it 'merges link stuff in properly' do
|
187
|
-
expect(output).to_not have_key(:links)
|
188
|
-
expect(output).to have_key(:primary_blog)
|
189
|
-
|
190
|
-
expect(output[:primary_blog]).to eq({href: true})
|
191
|
-
end
|
192
|
-
|
193
|
-
it 'resolves link aliases (from link ... using:)' do
|
194
|
-
expect(output).to have_key(:posts_summary)
|
195
|
-
expect(output[:posts_summary]).to eq({href: true})
|
196
|
-
end
|
197
|
-
|
198
|
-
context 'merging top-level attributes with those from links' do
|
199
|
-
let(:user_view) { User.views[:extended] }
|
200
|
-
|
201
|
-
subject(:primary_blog_output) { output[:primary_blog] }
|
202
|
-
it 'merges them' do
|
203
|
-
expected = {
|
204
|
-
href: true,
|
205
|
-
id: true,
|
206
|
-
name: true,
|
207
|
-
description: true
|
208
|
-
}
|
209
|
-
expect(primary_blog_output).to eq(expected)
|
210
|
-
end
|
211
|
-
end
|
212
|
-
|
213
|
-
context 'deep-merging fields' do
|
214
|
-
let(:fields) do
|
215
|
-
{
|
216
|
-
primary_blog: {
|
217
|
-
owner: { first: true, last: true }
|
218
|
-
},
|
219
|
-
links: {
|
220
|
-
primary_blog: {
|
221
|
-
owner: { href: true }
|
222
|
-
}
|
223
|
-
}
|
224
|
-
}
|
225
|
-
end
|
226
|
-
|
227
|
-
it 'does a deep-merge for sub-attributes' do
|
228
|
-
expected = {
|
229
|
-
owner: {first: true, last: true, href: true}
|
230
|
-
}
|
231
|
-
expect(output[:primary_blog]).to eq(expected)
|
232
|
-
end
|
233
|
-
end
|
234
|
-
|
235
111
|
context 'resolving collections' do
|
236
112
|
let(:fields) { {:id=>true, :posts=>[{:href=>true}]}}
|
237
113
|
it 'strips arrays from the incoming fields' do
|