jsonapi-resources 0.7.1.beta1 → 0.7.1.beta2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +248 -74
- data/lib/jsonapi-resources.rb +5 -3
- data/lib/jsonapi/acts_as_resource_controller.rb +77 -14
- data/lib/jsonapi/configuration.rb +77 -16
- data/lib/jsonapi/error.rb +12 -0
- data/lib/jsonapi/error_codes.rb +2 -0
- data/lib/jsonapi/exceptions.rb +29 -9
- data/lib/jsonapi/formatter.rb +29 -4
- data/lib/jsonapi/link_builder.rb +18 -18
- data/lib/jsonapi/mime_types.rb +25 -6
- data/lib/jsonapi/naive_cache.rb +30 -0
- data/lib/jsonapi/operation.rb +10 -342
- data/lib/jsonapi/operation_dispatcher.rb +87 -0
- data/lib/jsonapi/operation_result.rb +2 -1
- data/lib/jsonapi/paginator.rb +6 -2
- data/lib/jsonapi/processor.rb +283 -0
- data/lib/jsonapi/relationship.rb +6 -4
- data/lib/jsonapi/{request.rb → request_parser.rb} +46 -35
- data/lib/jsonapi/resource.rb +88 -13
- data/lib/jsonapi/resource_controller.rb +2 -14
- data/lib/jsonapi/resource_controller_metal.rb +17 -0
- data/lib/jsonapi/resource_serializer.rb +62 -47
- data/lib/jsonapi/resources/version.rb +1 -1
- data/lib/jsonapi/response_document.rb +13 -2
- data/lib/jsonapi/routing_ext.rb +49 -11
- metadata +37 -129
- data/.gitignore +0 -22
- data/.travis.yml +0 -9
- data/Gemfile +0 -23
- data/Rakefile +0 -20
- data/jsonapi-resources.gemspec +0 -29
- data/lib/jsonapi/active_record_operations_processor.rb +0 -35
- data/lib/jsonapi/operations_processor.rb +0 -120
- data/locales/en.yml +0 -80
- data/test/config/database.yml +0 -5
- data/test/controllers/controller_test.rb +0 -3312
- data/test/fixtures/active_record.rb +0 -1486
- data/test/fixtures/author_details.yml +0 -9
- data/test/fixtures/book_authors.yml +0 -3
- data/test/fixtures/book_comments.yml +0 -12
- data/test/fixtures/books.yml +0 -7
- data/test/fixtures/categories.yml +0 -35
- data/test/fixtures/comments.yml +0 -21
- data/test/fixtures/comments_tags.yml +0 -20
- data/test/fixtures/companies.yml +0 -4
- data/test/fixtures/craters.yml +0 -9
- data/test/fixtures/customers.yml +0 -11
- data/test/fixtures/documents.yml +0 -3
- data/test/fixtures/expense_entries.yml +0 -13
- data/test/fixtures/facts.yml +0 -11
- data/test/fixtures/hair_cuts.yml +0 -3
- data/test/fixtures/iso_currencies.yml +0 -17
- data/test/fixtures/line_items.yml +0 -37
- data/test/fixtures/makes.yml +0 -2
- data/test/fixtures/moons.yml +0 -6
- data/test/fixtures/numeros_telefone.yml +0 -3
- data/test/fixtures/order_flags.yml +0 -7
- data/test/fixtures/people.yml +0 -31
- data/test/fixtures/pictures.yml +0 -15
- data/test/fixtures/planet_types.yml +0 -19
- data/test/fixtures/planets.yml +0 -47
- data/test/fixtures/posts.yml +0 -102
- data/test/fixtures/posts_tags.yml +0 -59
- data/test/fixtures/preferences.yml +0 -14
- data/test/fixtures/products.yml +0 -3
- data/test/fixtures/purchase_orders.yml +0 -23
- data/test/fixtures/sections.yml +0 -8
- data/test/fixtures/tags.yml +0 -39
- data/test/fixtures/vehicles.yml +0 -17
- data/test/fixtures/web_pages.yml +0 -3
- data/test/helpers/assertions.rb +0 -13
- data/test/helpers/functional_helpers.rb +0 -59
- data/test/helpers/value_matchers.rb +0 -60
- data/test/helpers/value_matchers_test.rb +0 -40
- data/test/integration/requests/namespaced_model_test.rb +0 -13
- data/test/integration/requests/request_test.rb +0 -932
- data/test/integration/routes/routes_test.rb +0 -218
- data/test/integration/sti_fields_test.rb +0 -18
- data/test/lib/generators/jsonapi/controller_generator_test.rb +0 -25
- data/test/lib/generators/jsonapi/resource_generator_test.rb +0 -30
- data/test/test_helper.rb +0 -342
- data/test/unit/formatters/dasherized_key_formatter_test.rb +0 -8
- data/test/unit/jsonapi_request/jsonapi_request_test.rb +0 -199
- data/test/unit/operation/operations_processor_test.rb +0 -528
- data/test/unit/pagination/offset_paginator_test.rb +0 -245
- data/test/unit/pagination/paged_paginator_test.rb +0 -242
- data/test/unit/resource/resource_test.rb +0 -560
- data/test/unit/serializer/include_directives_test.rb +0 -113
- data/test/unit/serializer/link_builder_test.rb +0 -244
- data/test/unit/serializer/polymorphic_serializer_test.rb +0 -383
- data/test/unit/serializer/response_document_test.rb +0 -61
- data/test/unit/serializer/serializer_test.rb +0 -1939
@@ -1,218 +0,0 @@
|
|
1
|
-
require File.expand_path('../../../test_helper', __FILE__)
|
2
|
-
|
3
|
-
class RoutesTest < ActionDispatch::IntegrationTest
|
4
|
-
|
5
|
-
def test_routing_post
|
6
|
-
assert_routing({path: 'posts', method: :post},
|
7
|
-
{controller: 'posts', action: 'create'})
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_routing_patch
|
11
|
-
assert_routing({path: '/posts/1', method: :patch},
|
12
|
-
{controller: 'posts', action: 'update', id: '1'})
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_routing_posts_show
|
16
|
-
assert_routing({path: '/posts/1', method: :get},
|
17
|
-
{action: 'show', controller: 'posts', id: '1'})
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_routing_posts_links_author_show
|
21
|
-
assert_routing({path: '/posts/1/relationships/author', method: :get},
|
22
|
-
{controller: 'posts', action: 'show_relationship', post_id: '1', relationship: 'author'})
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_routing_posts_links_author_destroy
|
26
|
-
assert_routing({path: '/posts/1/relationships/author', method: :delete},
|
27
|
-
{controller: 'posts', action: 'destroy_relationship', post_id: '1', relationship: 'author'})
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_routing_posts_links_author_update
|
31
|
-
assert_routing({path: '/posts/1/relationships/author', method: :patch},
|
32
|
-
{controller: 'posts', action: 'update_relationship', post_id: '1', relationship: 'author'})
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_routing_posts_links_tags_show
|
36
|
-
assert_routing({path: '/posts/1/relationships/tags', method: :get},
|
37
|
-
{controller: 'posts', action: 'show_relationship', post_id: '1', relationship: 'tags'})
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_routing_posts_links_tags_destroy
|
41
|
-
assert_routing({path: '/posts/1/relationships/tags', method: :delete},
|
42
|
-
{controller: 'posts', action: 'destroy_relationship', post_id: '1', relationship: 'tags'})
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_routing_posts_links_tags_create
|
46
|
-
assert_routing({path: '/posts/1/relationships/tags', method: :post},
|
47
|
-
{controller: 'posts', action: 'create_relationship', post_id: '1', relationship: 'tags'})
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_routing_posts_links_tags_update_acts_as_set
|
51
|
-
assert_routing({path: '/posts/1/relationships/tags', method: :patch},
|
52
|
-
{controller: 'posts', action: 'update_relationship', post_id: '1', relationship: 'tags'})
|
53
|
-
end
|
54
|
-
|
55
|
-
def test_routing_uuid
|
56
|
-
assert_routing({path: '/pets/v1/cats/f1a4d5f2-e77a-4d0a-acbb-ee0b98b3f6b5', method: :get},
|
57
|
-
{action: 'show', controller: 'pets/v1/cats', id: 'f1a4d5f2-e77a-4d0a-acbb-ee0b98b3f6b5'})
|
58
|
-
end
|
59
|
-
|
60
|
-
# ToDo: refute this routing
|
61
|
-
# def test_routing_uuid_bad_format
|
62
|
-
# assert_routing({path: '/pets/v1/cats/f1a4d5f2-e77a-4d0a-acbb-ee0b9', method: :get},
|
63
|
-
# {action: 'show', controller: 'pets/v1/cats', id: 'f1a4d5f2-e77a-4d0a-acbb-ee0b98'})
|
64
|
-
# end
|
65
|
-
|
66
|
-
# Polymorphic
|
67
|
-
def test_routing_polymorphic_get_related_resource
|
68
|
-
assert_routing(
|
69
|
-
{
|
70
|
-
path: '/pictures/1/imageable',
|
71
|
-
method: :get
|
72
|
-
},
|
73
|
-
{
|
74
|
-
relationship: 'imageable',
|
75
|
-
source: 'pictures',
|
76
|
-
controller: 'imageables',
|
77
|
-
action: 'get_related_resource',
|
78
|
-
picture_id: '1'
|
79
|
-
}
|
80
|
-
)
|
81
|
-
end
|
82
|
-
|
83
|
-
def test_routing_polymorphic_patch_related_resource
|
84
|
-
assert_routing(
|
85
|
-
{
|
86
|
-
path: '/pictures/1/relationships/imageable',
|
87
|
-
method: :patch
|
88
|
-
},
|
89
|
-
{
|
90
|
-
relationship: 'imageable',
|
91
|
-
controller: 'pictures',
|
92
|
-
action: 'update_relationship',
|
93
|
-
picture_id: '1'
|
94
|
-
}
|
95
|
-
)
|
96
|
-
end
|
97
|
-
|
98
|
-
def test_routing_polymorphic_delete_related_resource
|
99
|
-
assert_routing(
|
100
|
-
{
|
101
|
-
path: '/pictures/1/relationships/imageable',
|
102
|
-
method: :delete
|
103
|
-
},
|
104
|
-
{
|
105
|
-
relationship: 'imageable',
|
106
|
-
controller: 'pictures',
|
107
|
-
action: 'destroy_relationship',
|
108
|
-
picture_id: '1'
|
109
|
-
}
|
110
|
-
)
|
111
|
-
end
|
112
|
-
|
113
|
-
# V1
|
114
|
-
def test_routing_v1_posts_show
|
115
|
-
assert_routing({path: '/api/v1/posts/1', method: :get},
|
116
|
-
{action: 'show', controller: 'api/v1/posts', id: '1'})
|
117
|
-
end
|
118
|
-
|
119
|
-
def test_routing_v1_posts_delete
|
120
|
-
assert_routing({path: '/api/v1/posts/1', method: :delete},
|
121
|
-
{action: 'destroy', controller: 'api/v1/posts', id: '1'})
|
122
|
-
end
|
123
|
-
|
124
|
-
def test_routing_v1_posts_links_writer_show
|
125
|
-
assert_routing({path: '/api/v1/posts/1/relationships/writer', method: :get},
|
126
|
-
{controller: 'api/v1/posts', action: 'show_relationship', post_id: '1', relationship: 'writer'})
|
127
|
-
end
|
128
|
-
|
129
|
-
# V2
|
130
|
-
def test_routing_v2_posts_links_author_show
|
131
|
-
assert_routing({path: '/api/v2/posts/1/relationships/author', method: :get},
|
132
|
-
{controller: 'api/v2/posts', action: 'show_relationship', post_id: '1', relationship: 'author'})
|
133
|
-
end
|
134
|
-
|
135
|
-
def test_routing_v2_preferences_show
|
136
|
-
assert_routing({path: '/api/v2/preferences', method: :get},
|
137
|
-
{action: 'show', controller: 'api/v2/preferences'})
|
138
|
-
end
|
139
|
-
|
140
|
-
# V3
|
141
|
-
def test_routing_v3_posts_show
|
142
|
-
assert_routing({path: '/api/v3/posts/1', method: :get},
|
143
|
-
{action: 'show', controller: 'api/v3/posts', id: '1'})
|
144
|
-
end
|
145
|
-
|
146
|
-
# V4 camelCase
|
147
|
-
def test_routing_v4_posts_show
|
148
|
-
assert_routing({path: '/api/v4/posts/1', method: :get},
|
149
|
-
{action: 'show', controller: 'api/v4/posts', id: '1'})
|
150
|
-
end
|
151
|
-
|
152
|
-
def test_routing_v4_isoCurrencies_resources
|
153
|
-
assert_routing({path: '/api/v4/isoCurrencies/USD', method: :get},
|
154
|
-
{action: 'show', controller: 'api/v4/iso_currencies', id: 'USD'})
|
155
|
-
end
|
156
|
-
|
157
|
-
def test_routing_v4_expenseEntries_resources
|
158
|
-
assert_routing({path: '/api/v4/expenseEntries/1', method: :get},
|
159
|
-
{action: 'show', controller: 'api/v4/expense_entries', id: '1'})
|
160
|
-
|
161
|
-
assert_routing({path: '/api/v4/expenseEntries/1/relationships/isoCurrency', method: :get},
|
162
|
-
{controller: 'api/v4/expense_entries', action: 'show_relationship', expense_entry_id: '1', relationship: 'iso_currency'})
|
163
|
-
end
|
164
|
-
|
165
|
-
# V5 dasherized
|
166
|
-
def test_routing_v5_posts_show
|
167
|
-
assert_routing({path: '/api/v5/posts/1', method: :get},
|
168
|
-
{action: 'show', controller: 'api/v5/posts', id: '1'})
|
169
|
-
end
|
170
|
-
|
171
|
-
def test_routing_v5_isoCurrencies_resources
|
172
|
-
assert_routing({path: '/api/v5/iso-currencies/USD', method: :get},
|
173
|
-
{action: 'show', controller: 'api/v5/iso_currencies', id: 'USD'})
|
174
|
-
end
|
175
|
-
|
176
|
-
def test_routing_v5_expenseEntries_resources
|
177
|
-
assert_routing({path: '/api/v5/expense-entries/1', method: :get},
|
178
|
-
{action: 'show', controller: 'api/v5/expense_entries', id: '1'})
|
179
|
-
|
180
|
-
assert_routing({path: '/api/v5/expense-entries/1/relationships/iso-currency', method: :get},
|
181
|
-
{controller: 'api/v5/expense_entries', action: 'show_relationship', expense_entry_id: '1', relationship: 'iso_currency'})
|
182
|
-
end
|
183
|
-
|
184
|
-
def test_routing_authors_show
|
185
|
-
assert_routing({path: '/api/v5/authors/1', method: :get},
|
186
|
-
{action: 'show', controller: 'api/v5/authors', id: '1'})
|
187
|
-
end
|
188
|
-
|
189
|
-
def test_routing_author_links_posts_create_not_acts_as_set
|
190
|
-
assert_routing({path: '/api/v5/authors/1/relationships/posts', method: :post},
|
191
|
-
{controller: 'api/v5/authors', action: 'create_relationship', author_id: '1', relationship: 'posts'})
|
192
|
-
end
|
193
|
-
|
194
|
-
#primary_key
|
195
|
-
def test_routing_primary_key_jsonapi_resources
|
196
|
-
assert_routing({path: '/iso_currencies/USD', method: :get},
|
197
|
-
{action: 'show', controller: 'iso_currencies', id: 'USD'})
|
198
|
-
end
|
199
|
-
|
200
|
-
# ToDo: Refute routing
|
201
|
-
# def test_routing_v3_posts_delete
|
202
|
-
# assert_routing({ path: '/api/v3/posts/1', method: :delete },
|
203
|
-
# {action: 'destroy', controller: 'api/v3/posts', id: '1'})
|
204
|
-
# end
|
205
|
-
|
206
|
-
# def test_routing_posts_links_author_except_destroy
|
207
|
-
# assert_routing({ path: '/api/v3/posts/1/relationships/author', method: :delete },
|
208
|
-
# { controller: 'api/v3/posts', action: 'destroy_relationship', post_id: '1', relationship: 'author' })
|
209
|
-
# end
|
210
|
-
#
|
211
|
-
# def test_routing_posts_links_tags_only_create_show
|
212
|
-
# assert_routing({ path: '/api/v3/posts/1/relationships/tags/1,2', method: :delete },
|
213
|
-
# { controller: 'api/v3/posts', action: 'destroy_relationship', post_id: '1', keys: '1,2', relationship: 'tags' })
|
214
|
-
# end
|
215
|
-
|
216
|
-
# Test that non acts as set to_many relationship update route is not created
|
217
|
-
|
218
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
require File.expand_path("../../test_helper", __FILE__)
|
2
|
-
|
3
|
-
class StiFieldsTest < ActionDispatch::IntegrationTest
|
4
|
-
def test_index_fields_when_resource_does_not_match_relationship
|
5
|
-
get "/posts", { filter: { id: "1,2" },
|
6
|
-
include: "author",
|
7
|
-
fields: { posts: "author", people: "email" } }
|
8
|
-
assert_response :success
|
9
|
-
assert_equal 2, json_response["data"].size
|
10
|
-
assert json_response["data"][0]["relationships"].key?("author")
|
11
|
-
assert json_response["included"][0]["attributes"].keys == ["email"]
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_fields_for_parent_class
|
15
|
-
get "/firms", { fields: { companies: "name" } }
|
16
|
-
assert_equal json_response["data"][0]["attributes"].keys, ["name"]
|
17
|
-
end
|
18
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
require File.expand_path('../../../../test_helper', __FILE__)
|
2
|
-
require 'generators/jsonapi/controller_generator'
|
3
|
-
|
4
|
-
module Jsonapi
|
5
|
-
class ControllerGeneratorTest < Rails::Generators::TestCase
|
6
|
-
tests ControllerGenerator
|
7
|
-
destination Rails.root.join('../controllers')
|
8
|
-
setup :prepare_destination
|
9
|
-
teardown :cleanup_destination_root
|
10
|
-
|
11
|
-
def cleanup_destination_root
|
12
|
-
FileUtils.rm_rf destination_root
|
13
|
-
end
|
14
|
-
|
15
|
-
test "controller is created" do
|
16
|
-
run_generator ["post"]
|
17
|
-
assert_file 'app/controllers/posts_controller.rb', /class PostsController < JSONAPI::ResourceController/
|
18
|
-
end
|
19
|
-
|
20
|
-
test "controller is created with namespace" do
|
21
|
-
run_generator ["api/v1/post"]
|
22
|
-
assert_file 'app/controllers/api/v1/posts_controller.rb', /class Api::V1::PostsController < JSONAPI::ResourceController/
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require File.expand_path('../../../../test_helper', __FILE__)
|
2
|
-
require 'generators/jsonapi/resource_generator'
|
3
|
-
|
4
|
-
module Jsonapi
|
5
|
-
class ResourceGeneratorTest < Rails::Generators::TestCase
|
6
|
-
tests ResourceGenerator
|
7
|
-
destination Rails.root.join('../resources')
|
8
|
-
setup :prepare_destination
|
9
|
-
teardown :cleanup_destination_root
|
10
|
-
|
11
|
-
def cleanup_destination_root
|
12
|
-
FileUtils.rm_rf destination_root
|
13
|
-
end
|
14
|
-
|
15
|
-
test "resource is created" do
|
16
|
-
run_generator ["post"]
|
17
|
-
assert_file 'app/resources/post_resource.rb', /class PostResource < JSONAPI::Resource/
|
18
|
-
end
|
19
|
-
|
20
|
-
test "resource is singular" do
|
21
|
-
run_generator ["posts"]
|
22
|
-
assert_file 'app/resources/post_resource.rb', /class PostResource < JSONAPI::Resource/
|
23
|
-
end
|
24
|
-
|
25
|
-
test "resource is created with namespace" do
|
26
|
-
run_generator ["api/v1/post"]
|
27
|
-
assert_file 'app/resources/api/v1/post_resource.rb', /class Api::V1::PostResource < JSONAPI::Resource/
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
data/test/test_helper.rb
DELETED
@@ -1,342 +0,0 @@
|
|
1
|
-
require 'simplecov'
|
2
|
-
|
3
|
-
# To run tests with coverage:
|
4
|
-
# COVERAGE=true rake test
|
5
|
-
# To Switch rails versions and run a particular test order:
|
6
|
-
# export RAILS_VERSION=4.2.0; bundle update rails; bundle exec rake TESTOPTS="--seed=39333" test
|
7
|
-
# We are no longer having Travis test Rails 4.0.x. To test on Rails 4.0.x use this:
|
8
|
-
# export RAILS_VERSION=4.0.0; bundle update rails; bundle exec rake test
|
9
|
-
|
10
|
-
if ENV['COVERAGE']
|
11
|
-
SimpleCov.start do
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
require 'rails/all'
|
16
|
-
require 'rails/test_help'
|
17
|
-
require 'minitest/mock'
|
18
|
-
require 'jsonapi-resources'
|
19
|
-
require 'pry'
|
20
|
-
|
21
|
-
require File.expand_path('../helpers/value_matchers', __FILE__)
|
22
|
-
require File.expand_path('../helpers/assertions', __FILE__)
|
23
|
-
require File.expand_path('../helpers/functional_helpers', __FILE__)
|
24
|
-
|
25
|
-
Rails.env = 'test'
|
26
|
-
|
27
|
-
I18n.load_path += Dir[File.expand_path("../../locales/*.yml", __FILE__)]
|
28
|
-
I18n.enforce_available_locales = false
|
29
|
-
|
30
|
-
JSONAPI.configure do |config|
|
31
|
-
config.json_key_format = :camelized_key
|
32
|
-
end
|
33
|
-
|
34
|
-
puts "Testing With RAILS VERSION #{Rails.version}"
|
35
|
-
|
36
|
-
class TestApp < Rails::Application
|
37
|
-
config.eager_load = false
|
38
|
-
config.root = File.dirname(__FILE__)
|
39
|
-
config.session_store :cookie_store, key: 'session'
|
40
|
-
config.secret_key_base = 'secret'
|
41
|
-
|
42
|
-
#Raise errors on unsupported parameters
|
43
|
-
config.action_controller.action_on_unpermitted_parameters = :raise
|
44
|
-
|
45
|
-
ActiveRecord::Schema.verbose = false
|
46
|
-
config.active_record.schema_format = :none
|
47
|
-
config.active_support.test_order = :random
|
48
|
-
|
49
|
-
# Turn off millisecond precision to maintain Rails 4.0 and 4.1 compatibility in test results
|
50
|
-
ActiveSupport::JSON::Encoding.time_precision = 0 if Rails::VERSION::MAJOR >= 4 && Rails::VERSION::MINOR >= 1
|
51
|
-
end
|
52
|
-
|
53
|
-
module MyEngine
|
54
|
-
class Engine < ::Rails::Engine
|
55
|
-
isolate_namespace MyEngine
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
# Patch RAILS 4.0 to not use millisecond precision
|
60
|
-
if Rails::VERSION::MAJOR >= 4 && Rails::VERSION::MINOR < 1
|
61
|
-
module ActiveSupport
|
62
|
-
class TimeWithZone
|
63
|
-
def as_json(options = nil)
|
64
|
-
if ActiveSupport::JSON::Encoding.use_standard_json_time_format
|
65
|
-
xmlschema
|
66
|
-
else
|
67
|
-
%(#{time.strftime("%Y/%m/%d %H:%M:%S")} #{formatted_offset(false)})
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
def count_queries(&block)
|
75
|
-
@query_count = 0
|
76
|
-
@queries = []
|
77
|
-
ActiveSupport::Notifications.subscribe('sql.active_record') do |name, started, finished, unique_id, payload|
|
78
|
-
@query_count = @query_count + 1
|
79
|
-
@queries.push payload[:sql]
|
80
|
-
end
|
81
|
-
yield block
|
82
|
-
ActiveSupport::Notifications.unsubscribe('sql.active_record')
|
83
|
-
@query_count
|
84
|
-
end
|
85
|
-
|
86
|
-
def assert_query_count(expected, msg = nil)
|
87
|
-
msg = message(msg) {
|
88
|
-
"Expected #{expected} queries, ran #{@query_count} queries"
|
89
|
-
}
|
90
|
-
show_queries unless expected == @query_count
|
91
|
-
assert expected == @query_count, msg
|
92
|
-
end
|
93
|
-
|
94
|
-
def show_queries
|
95
|
-
@queries.each_with_index do |query, index|
|
96
|
-
puts "sql[#{index}]: #{query}"
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
TestApp.initialize!
|
101
|
-
|
102
|
-
require File.expand_path('../fixtures/active_record', __FILE__)
|
103
|
-
|
104
|
-
module Pets
|
105
|
-
module V1
|
106
|
-
class CatsController < JSONAPI::ResourceController
|
107
|
-
|
108
|
-
end
|
109
|
-
|
110
|
-
class CatResource < JSONAPI::Resource
|
111
|
-
attribute :name
|
112
|
-
attribute :breed
|
113
|
-
|
114
|
-
key_type :uuid
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
JSONAPI.configuration.route_format = :underscored_route
|
120
|
-
TestApp.routes.draw do
|
121
|
-
jsonapi_resources :people
|
122
|
-
jsonapi_resources :special_people
|
123
|
-
jsonapi_resources :comments
|
124
|
-
jsonapi_resources :firms
|
125
|
-
jsonapi_resources :tags
|
126
|
-
jsonapi_resources :posts do
|
127
|
-
jsonapi_relationships
|
128
|
-
jsonapi_links :special_tags
|
129
|
-
end
|
130
|
-
jsonapi_resources :sections
|
131
|
-
jsonapi_resources :iso_currencies
|
132
|
-
jsonapi_resources :expense_entries
|
133
|
-
jsonapi_resources :breeds
|
134
|
-
jsonapi_resources :planets
|
135
|
-
jsonapi_resources :planet_types
|
136
|
-
jsonapi_resources :moons
|
137
|
-
jsonapi_resources :craters
|
138
|
-
jsonapi_resources :preferences
|
139
|
-
jsonapi_resources :facts
|
140
|
-
jsonapi_resources :categories
|
141
|
-
jsonapi_resources :pictures
|
142
|
-
jsonapi_resources :documents
|
143
|
-
jsonapi_resources :products
|
144
|
-
jsonapi_resources :vehicles
|
145
|
-
jsonapi_resources :cars
|
146
|
-
jsonapi_resources :boats
|
147
|
-
jsonapi_resources :flat_posts
|
148
|
-
|
149
|
-
jsonapi_resources :books
|
150
|
-
jsonapi_resources :authors
|
151
|
-
|
152
|
-
namespace :api do
|
153
|
-
namespace :v1 do
|
154
|
-
jsonapi_resources :people
|
155
|
-
jsonapi_resources :comments
|
156
|
-
jsonapi_resources :tags
|
157
|
-
jsonapi_resources :posts
|
158
|
-
jsonapi_resources :sections
|
159
|
-
jsonapi_resources :iso_currencies
|
160
|
-
jsonapi_resources :expense_entries
|
161
|
-
jsonapi_resources :breeds
|
162
|
-
jsonapi_resources :planets
|
163
|
-
jsonapi_resources :planet_types
|
164
|
-
jsonapi_resources :moons
|
165
|
-
jsonapi_resources :craters
|
166
|
-
jsonapi_resources :preferences
|
167
|
-
jsonapi_resources :likes
|
168
|
-
end
|
169
|
-
|
170
|
-
JSONAPI.configuration.route_format = :underscored_route
|
171
|
-
namespace :v2 do
|
172
|
-
jsonapi_resources :posts do
|
173
|
-
jsonapi_link :author, except: :destroy
|
174
|
-
end
|
175
|
-
|
176
|
-
jsonapi_resource :preferences, except: [:create, :destroy]
|
177
|
-
|
178
|
-
jsonapi_resources :books
|
179
|
-
jsonapi_resources :book_comments
|
180
|
-
end
|
181
|
-
|
182
|
-
namespace :v3 do
|
183
|
-
jsonapi_resource :preferences do
|
184
|
-
# Intentionally empty block to skip relationship urls
|
185
|
-
end
|
186
|
-
|
187
|
-
jsonapi_resources :posts, except: [:destroy] do
|
188
|
-
jsonapi_link :author, except: [:destroy]
|
189
|
-
jsonapi_links :tags, only: [:show, :create]
|
190
|
-
end
|
191
|
-
end
|
192
|
-
|
193
|
-
JSONAPI.configuration.route_format = :camelized_route
|
194
|
-
namespace :v4 do
|
195
|
-
jsonapi_resources :posts do
|
196
|
-
end
|
197
|
-
|
198
|
-
jsonapi_resources :expense_entries do
|
199
|
-
jsonapi_link :iso_currency
|
200
|
-
jsonapi_related_resource :iso_currency
|
201
|
-
end
|
202
|
-
|
203
|
-
jsonapi_resources :iso_currencies do
|
204
|
-
end
|
205
|
-
|
206
|
-
jsonapi_resources :books
|
207
|
-
end
|
208
|
-
|
209
|
-
JSONAPI.configuration.route_format = :dasherized_route
|
210
|
-
namespace :v5 do
|
211
|
-
jsonapi_resources :posts do
|
212
|
-
end
|
213
|
-
|
214
|
-
jsonapi_resources :authors
|
215
|
-
jsonapi_resources :expense_entries
|
216
|
-
jsonapi_resources :iso_currencies
|
217
|
-
|
218
|
-
jsonapi_resources :employees
|
219
|
-
|
220
|
-
end
|
221
|
-
JSONAPI.configuration.route_format = :underscored_route
|
222
|
-
|
223
|
-
JSONAPI.configuration.route_format = :dasherized_route
|
224
|
-
namespace :v6 do
|
225
|
-
jsonapi_resources :customers
|
226
|
-
jsonapi_resources :purchase_orders
|
227
|
-
jsonapi_resources :line_items
|
228
|
-
end
|
229
|
-
JSONAPI.configuration.route_format = :underscored_route
|
230
|
-
|
231
|
-
namespace :v7 do
|
232
|
-
jsonapi_resources :customers
|
233
|
-
jsonapi_resources :purchase_orders
|
234
|
-
jsonapi_resources :line_items
|
235
|
-
jsonapi_resources :categories
|
236
|
-
|
237
|
-
jsonapi_resources :clients
|
238
|
-
end
|
239
|
-
|
240
|
-
namespace :v8 do
|
241
|
-
jsonapi_resources :numeros_telefone
|
242
|
-
end
|
243
|
-
end
|
244
|
-
|
245
|
-
namespace :admin_api do
|
246
|
-
namespace :v1 do
|
247
|
-
jsonapi_resources :people
|
248
|
-
end
|
249
|
-
end
|
250
|
-
|
251
|
-
namespace :pets do
|
252
|
-
namespace :v1 do
|
253
|
-
jsonapi_resources :cats
|
254
|
-
end
|
255
|
-
end
|
256
|
-
|
257
|
-
mount MyEngine::Engine => "/boomshaka", as: :my_engine
|
258
|
-
end
|
259
|
-
|
260
|
-
MyEngine::Engine.routes.draw do
|
261
|
-
namespace :api do
|
262
|
-
namespace :v1 do
|
263
|
-
jsonapi_resources :people
|
264
|
-
end
|
265
|
-
end
|
266
|
-
|
267
|
-
namespace :admin_api do
|
268
|
-
namespace :v1 do
|
269
|
-
jsonapi_resources :people
|
270
|
-
end
|
271
|
-
end
|
272
|
-
end
|
273
|
-
|
274
|
-
# Ensure backward compatibility with Minitest 4
|
275
|
-
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)
|
276
|
-
|
277
|
-
class Minitest::Test
|
278
|
-
include Helpers::Assertions
|
279
|
-
include Helpers::ValueMatchers
|
280
|
-
include Helpers::FunctionalHelpers
|
281
|
-
include ActiveRecord::TestFixtures
|
282
|
-
|
283
|
-
def run_in_transaction?
|
284
|
-
true
|
285
|
-
end
|
286
|
-
|
287
|
-
self.fixture_path = "#{Rails.root}/fixtures"
|
288
|
-
fixtures :all
|
289
|
-
end
|
290
|
-
|
291
|
-
class ActiveSupport::TestCase
|
292
|
-
self.fixture_path = "#{Rails.root}/fixtures"
|
293
|
-
fixtures :all
|
294
|
-
setup do
|
295
|
-
@routes = TestApp.routes
|
296
|
-
end
|
297
|
-
end
|
298
|
-
|
299
|
-
class ActionDispatch::IntegrationTest
|
300
|
-
self.fixture_path = "#{Rails.root}/fixtures"
|
301
|
-
fixtures :all
|
302
|
-
end
|
303
|
-
|
304
|
-
class UpperCamelizedKeyFormatter < JSONAPI::KeyFormatter
|
305
|
-
class << self
|
306
|
-
def format(key)
|
307
|
-
super.camelize(:upper)
|
308
|
-
end
|
309
|
-
|
310
|
-
def unformat(formatted_key)
|
311
|
-
formatted_key.to_s.underscore
|
312
|
-
end
|
313
|
-
end
|
314
|
-
end
|
315
|
-
|
316
|
-
class DateWithTimezoneValueFormatter < JSONAPI::ValueFormatter
|
317
|
-
class << self
|
318
|
-
def format(raw_value)
|
319
|
-
raw_value.in_time_zone('Eastern Time (US & Canada)').to_s
|
320
|
-
end
|
321
|
-
end
|
322
|
-
end
|
323
|
-
|
324
|
-
class DateValueFormatter < JSONAPI::ValueFormatter
|
325
|
-
class << self
|
326
|
-
def format(raw_value)
|
327
|
-
raw_value.strftime('%m/%d/%Y')
|
328
|
-
end
|
329
|
-
end
|
330
|
-
end
|
331
|
-
|
332
|
-
class TitleValueFormatter < JSONAPI::ValueFormatter
|
333
|
-
class << self
|
334
|
-
def format(raw_value)
|
335
|
-
super(raw_value).titlecase
|
336
|
-
end
|
337
|
-
|
338
|
-
def unformat(value)
|
339
|
-
value.to_s.downcase
|
340
|
-
end
|
341
|
-
end
|
342
|
-
end
|