dhs 1.0.0
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 +7 -0
- data/.github/workflows/rubocop.yml +27 -0
- data/.github/workflows/test.yml +27 -0
- data/.gitignore +39 -0
- data/.rubocop.yml +186 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/LICENSE +674 -0
- data/README.md +2807 -0
- data/Rakefile +26 -0
- data/dhs.gemspec +44 -0
- data/docs/accessing-data.png +0 -0
- data/lib/dhs.rb +67 -0
- data/lib/dhs/collection.rb +84 -0
- data/lib/dhs/complex.rb +158 -0
- data/lib/dhs/concerns/autoload_records.rb +57 -0
- data/lib/dhs/concerns/collection/handle_nested.rb +43 -0
- data/lib/dhs/concerns/collection/internal_collection.rb +74 -0
- data/lib/dhs/concerns/configuration.rb +20 -0
- data/lib/dhs/concerns/data/becomes.rb +18 -0
- data/lib/dhs/concerns/data/equality.rb +14 -0
- data/lib/dhs/concerns/data/extend.rb +87 -0
- data/lib/dhs/concerns/data/json.rb +14 -0
- data/lib/dhs/concerns/data/to_hash.rb +14 -0
- data/lib/dhs/concerns/inspect.rb +70 -0
- data/lib/dhs/concerns/is_href.rb +15 -0
- data/lib/dhs/concerns/item/destroy.rb +38 -0
- data/lib/dhs/concerns/item/endpoint_lookup.rb +27 -0
- data/lib/dhs/concerns/item/save.rb +55 -0
- data/lib/dhs/concerns/item/update.rb +50 -0
- data/lib/dhs/concerns/item/validation.rb +61 -0
- data/lib/dhs/concerns/o_auth.rb +25 -0
- data/lib/dhs/concerns/option_blocks.rb +26 -0
- data/lib/dhs/concerns/proxy/accessors.rb +132 -0
- data/lib/dhs/concerns/proxy/create.rb +45 -0
- data/lib/dhs/concerns/proxy/link.rb +25 -0
- data/lib/dhs/concerns/proxy/problems.rb +27 -0
- data/lib/dhs/concerns/record/attribute_assignment.rb +25 -0
- data/lib/dhs/concerns/record/batch.rb +40 -0
- data/lib/dhs/concerns/record/chainable.rb +465 -0
- data/lib/dhs/concerns/record/configuration.rb +103 -0
- data/lib/dhs/concerns/record/create.rb +24 -0
- data/lib/dhs/concerns/record/custom_setters.rb +22 -0
- data/lib/dhs/concerns/record/destroy.rb +18 -0
- data/lib/dhs/concerns/record/endpoints.rb +108 -0
- data/lib/dhs/concerns/record/equality.rb +14 -0
- data/lib/dhs/concerns/record/find.rb +86 -0
- data/lib/dhs/concerns/record/find_by.rb +38 -0
- data/lib/dhs/concerns/record/first.rb +20 -0
- data/lib/dhs/concerns/record/href_for.rb +19 -0
- data/lib/dhs/concerns/record/last.rb +27 -0
- data/lib/dhs/concerns/record/mapping.rb +25 -0
- data/lib/dhs/concerns/record/merge.rb +26 -0
- data/lib/dhs/concerns/record/model.rb +23 -0
- data/lib/dhs/concerns/record/pagination.rb +49 -0
- data/lib/dhs/concerns/record/provider.rb +23 -0
- data/lib/dhs/concerns/record/relations.rb +26 -0
- data/lib/dhs/concerns/record/request.rb +581 -0
- data/lib/dhs/concerns/record/scope.rb +25 -0
- data/lib/dhs/concerns/record/tracing.rb +24 -0
- data/lib/dhs/concerns/record/update.rb +17 -0
- data/lib/dhs/config.rb +24 -0
- data/lib/dhs/data.rb +180 -0
- data/lib/dhs/endpoint.rb +12 -0
- data/lib/dhs/interceptors/auto_oauth/interceptor.rb +33 -0
- data/lib/dhs/interceptors/auto_oauth/thread_registry.rb +18 -0
- data/lib/dhs/interceptors/extended_rollbar/handler.rb +40 -0
- data/lib/dhs/interceptors/extended_rollbar/interceptor.rb +20 -0
- data/lib/dhs/interceptors/extended_rollbar/thread_registry.rb +19 -0
- data/lib/dhs/interceptors/request_cycle_cache/interceptor.rb +41 -0
- data/lib/dhs/interceptors/request_cycle_cache/thread_registry.rb +18 -0
- data/lib/dhs/item.rb +59 -0
- data/lib/dhs/pagination/base.rb +90 -0
- data/lib/dhs/pagination/link.rb +21 -0
- data/lib/dhs/pagination/offset.rb +22 -0
- data/lib/dhs/pagination/page.rb +18 -0
- data/lib/dhs/pagination/start.rb +22 -0
- data/lib/dhs/pagination/total_pages.rb +9 -0
- data/lib/dhs/problems/base.rb +113 -0
- data/lib/dhs/problems/errors.rb +69 -0
- data/lib/dhs/problems/nested/base.rb +54 -0
- data/lib/dhs/problems/nested/errors.rb +16 -0
- data/lib/dhs/problems/nested/warnings.rb +15 -0
- data/lib/dhs/problems/warnings.rb +24 -0
- data/lib/dhs/proxy.rb +69 -0
- data/lib/dhs/railtie.rb +34 -0
- data/lib/dhs/record.rb +112 -0
- data/lib/dhs/rspec.rb +10 -0
- data/lib/dhs/test/stubbable_records.rb +34 -0
- data/lib/dhs/unprocessable.rb +6 -0
- data/lib/dhs/version.rb +5 -0
- data/script/ci/build.sh +18 -0
- data/spec/auto_oauth_spec.rb +163 -0
- data/spec/autoloading_spec.rb +45 -0
- data/spec/collection/accessors_spec.rb +31 -0
- data/spec/collection/collection_items_spec.rb +44 -0
- data/spec/collection/configurable_spec.rb +43 -0
- data/spec/collection/delegate_spec.rb +21 -0
- data/spec/collection/enumerable_spec.rb +27 -0
- data/spec/collection/href_spec.rb +17 -0
- data/spec/collection/meta_data_spec.rb +58 -0
- data/spec/collection/respond_to_spec.rb +20 -0
- data/spec/collection/to_a_spec.rb +34 -0
- data/spec/collection/to_ary_spec.rb +40 -0
- data/spec/collection/without_object_items_spec.rb +27 -0
- data/spec/complex/reduce_spec.rb +202 -0
- data/spec/concerns/record/request_spec.rb +78 -0
- data/spec/data/collection_spec.rb +56 -0
- data/spec/data/equality_spec.rb +23 -0
- data/spec/data/inspect_spec.rb +88 -0
- data/spec/data/is_item_or_collection_spec.rb +40 -0
- data/spec/data/item_spec.rb +106 -0
- data/spec/data/merge_spec.rb +27 -0
- data/spec/data/parent_spec.rb +39 -0
- data/spec/data/raw_spec.rb +48 -0
- data/spec/data/respond_to_spec.rb +26 -0
- data/spec/data/root_spec.rb +25 -0
- data/spec/data/select_spec.rb +27 -0
- data/spec/data/to_ary_spec.rb +28 -0
- data/spec/data/to_json_spec.rb +68 -0
- data/spec/dummy/Rakefile +8 -0
- data/spec/dummy/app/assets/images/.keep +0 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/controllers/application_controller.rb +26 -0
- data/spec/dummy/app/controllers/automatic_authentication_controller.rb +29 -0
- data/spec/dummy/app/controllers/concerns/.keep +0 -0
- data/spec/dummy/app/controllers/error_handling_with_chains_controller.rb +36 -0
- data/spec/dummy/app/controllers/extended_rollbar_controller.rb +10 -0
- data/spec/dummy/app/controllers/option_blocks_controller.rb +15 -0
- data/spec/dummy/app/controllers/request_cycle_cache_controller.rb +27 -0
- data/spec/dummy/app/helpers/application_helper.rb +4 -0
- data/spec/dummy/app/mailers/.keep +0 -0
- data/spec/dummy/app/models/.keep +0 -0
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/dummy/app/models/concerns/dummy_customer/some_concern.rb +9 -0
- data/spec/dummy/app/models/dummy_customer.rb +7 -0
- data/spec/dummy/app/models/dummy_record.rb +6 -0
- data/spec/dummy/app/models/dummy_record_with_auto_oauth_provider.rb +6 -0
- data/spec/dummy/app/models/dummy_record_with_multiple_oauth_providers1.rb +7 -0
- data/spec/dummy/app/models/dummy_record_with_multiple_oauth_providers2.rb +7 -0
- data/spec/dummy/app/models/dummy_record_with_multiple_providers_per_endpoint.rb +6 -0
- data/spec/dummy/app/models/dummy_record_with_oauth.rb +7 -0
- data/spec/dummy/app/models/dummy_user.rb +6 -0
- data/spec/dummy/app/models/providers/customer_system.rb +7 -0
- data/spec/dummy/app/models/providers/internal_services.rb +7 -0
- data/spec/dummy/app/views/error_handling_with_chains/error.html.erb +1 -0
- data/spec/dummy/app/views/error_handling_with_chains/show.html.erb +3 -0
- data/spec/dummy/app/views/form_for.html.erb +5 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/bin/bundle +5 -0
- data/spec/dummy/bin/rails +6 -0
- data/spec/dummy/bin/rake +6 -0
- data/spec/dummy/config.ru +6 -0
- data/spec/dummy/config/application.rb +16 -0
- data/spec/dummy/config/boot.rb +7 -0
- data/spec/dummy/config/environment.rb +7 -0
- data/spec/dummy/config/environments/development.rb +36 -0
- data/spec/dummy/config/environments/production.rb +77 -0
- data/spec/dummy/config/environments/test.rb +40 -0
- data/spec/dummy/config/initializers/assets.rb +10 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +9 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +5 -0
- data/spec/dummy/config/initializers/dhs.rb +5 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +6 -0
- data/spec/dummy/config/initializers/inflections.rb +18 -0
- data/spec/dummy/config/initializers/mime_types.rb +6 -0
- data/spec/dummy/config/initializers/rollbar.rb +9 -0
- data/spec/dummy/config/initializers/session_store.rb +5 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +11 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +27 -0
- data/spec/dummy/config/secrets.yml +22 -0
- data/spec/dummy/lib/assets/.keep +0 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/endpoint/for_url_spec.rb +27 -0
- data/spec/extended_rollbar_spec.rb +67 -0
- data/spec/item/access_errors_spec.rb +31 -0
- data/spec/item/accessors_spec.rb +21 -0
- data/spec/item/add_error_spec.rb +21 -0
- data/spec/item/becomes_spec.rb +38 -0
- data/spec/item/blacklisted_keywords_spec.rb +28 -0
- data/spec/item/delegate_spec.rb +32 -0
- data/spec/item/destroy_spec.rb +113 -0
- data/spec/item/dig_spec.rb +29 -0
- data/spec/item/error_codes_spec.rb +55 -0
- data/spec/item/errors_spec.rb +324 -0
- data/spec/item/fetch_spec.rb +39 -0
- data/spec/item/getter_spec.rb +24 -0
- data/spec/item/internal_data_structure_spec.rb +37 -0
- data/spec/item/map_spec.rb +46 -0
- data/spec/item/nested_errors_spec.rb +27 -0
- data/spec/item/partial_update_spec.rb +168 -0
- data/spec/item/respond_to_spec.rb +31 -0
- data/spec/item/save_spec.rb +115 -0
- data/spec/item/setter_spec.rb +44 -0
- data/spec/item/translate_errors_spec.rb +257 -0
- data/spec/item/update_spec.rb +161 -0
- data/spec/item/validation_spec.rb +131 -0
- data/spec/item/warning_codes_spec.rb +55 -0
- data/spec/item/warnings_spec.rb +51 -0
- data/spec/option_blocks/ensure_reset_between_requests_spec.rb +23 -0
- data/spec/option_blocks/main_spec.rb +54 -0
- data/spec/pagination/link/current_page_spec.rb +19 -0
- data/spec/pagination/link/pages_left_spec.rb +36 -0
- data/spec/pagination/link/parallel_spec.rb +19 -0
- data/spec/pagination/link/total_spec.rb +45 -0
- data/spec/pagination/offset/pages_left_spec.rb +26 -0
- data/spec/pagination/parameters_spec.rb +59 -0
- data/spec/pagination/total_pages_spec.rb +51 -0
- data/spec/proxy/create_sub_resource_spec.rb +182 -0
- data/spec/proxy/load_spec.rb +75 -0
- data/spec/proxy/record_identification_spec.rb +35 -0
- data/spec/rails_helper.rb +13 -0
- data/spec/record/all_spec.rb +133 -0
- data/spec/record/attribute_assignment_spec.rb +28 -0
- data/spec/record/build_spec.rb +26 -0
- data/spec/record/cast_nested_data_spec.rb +80 -0
- data/spec/record/compact_spec.rb +93 -0
- data/spec/record/create_spec.rb +160 -0
- data/spec/record/creation_failed_spec.rb +55 -0
- data/spec/record/custom_setters_spec.rb +42 -0
- data/spec/record/definitions_spec.rb +29 -0
- data/spec/record/destroy_spec.rb +38 -0
- data/spec/record/dig_configuration_spec.rb +75 -0
- data/spec/record/dup_spec.rb +20 -0
- data/spec/record/endpoint_inheritance_spec.rb +65 -0
- data/spec/record/endpoint_options_spec.rb +51 -0
- data/spec/record/endpoint_priorities_spec.rb +24 -0
- data/spec/record/endpoints_spec.rb +96 -0
- data/spec/record/equality_spec.rb +27 -0
- data/spec/record/error_handling_integration_spec.rb +25 -0
- data/spec/record/error_handling_spec.rb +40 -0
- data/spec/record/expanded_spec.rb +69 -0
- data/spec/record/fetch_spec.rb +40 -0
- data/spec/record/find_by_chains_spec.rb +21 -0
- data/spec/record/find_by_spec.rb +76 -0
- data/spec/record/find_each_spec.rb +57 -0
- data/spec/record/find_in_batches_spec.rb +122 -0
- data/spec/record/find_in_parallel_spec.rb +67 -0
- data/spec/record/find_spec.rb +103 -0
- data/spec/record/first_spec.rb +39 -0
- data/spec/record/force_merge_spec.rb +55 -0
- data/spec/record/handle_includes_errors_spec.rb +33 -0
- data/spec/record/has_many_spec.rb +118 -0
- data/spec/record/has_one_spec.rb +114 -0
- data/spec/record/href_for_spec.rb +24 -0
- data/spec/record/ignore_errors_spec.rb +137 -0
- data/spec/record/immutable_chains_spec.rb +22 -0
- data/spec/record/includes_after_expansion_spec.rb +70 -0
- data/spec/record/includes_expanded_spec.rb +37 -0
- data/spec/record/includes_first_page_spec.rb +738 -0
- data/spec/record/includes_missing_spec.rb +57 -0
- data/spec/record/includes_spec.rb +690 -0
- data/spec/record/includes_warning_spec.rb +46 -0
- data/spec/record/item_key_spec.rb +81 -0
- data/spec/record/items_created_key_configuration_spec.rb +37 -0
- data/spec/record/last_spec.rb +64 -0
- data/spec/record/loading_twice_spec.rb +19 -0
- data/spec/record/mapping_spec.rb +103 -0
- data/spec/record/model_name_spec.rb +17 -0
- data/spec/record/new_spec.rb +106 -0
- data/spec/record/options_getter_spec.rb +25 -0
- data/spec/record/options_spec.rb +164 -0
- data/spec/record/paginatable_collection_spec.rb +360 -0
- data/spec/record/pagination_chain_spec.rb +101 -0
- data/spec/record/pagination_links_spec.rb +72 -0
- data/spec/record/pagination_spec.rb +71 -0
- data/spec/record/persisted_spec.rb +52 -0
- data/spec/record/provider_spec.rb +40 -0
- data/spec/record/references_spec.rb +95 -0
- data/spec/record/relation_caching_spec.rb +120 -0
- data/spec/record/reload_by_id_spec.rb +43 -0
- data/spec/record/reload_spec.rb +64 -0
- data/spec/record/request_spec.rb +90 -0
- data/spec/record/save_spec.rb +40 -0
- data/spec/record/scope_chains_spec.rb +39 -0
- data/spec/record/select_spec.rb +17 -0
- data/spec/record/to_ary_spec.rb +65 -0
- data/spec/record/to_hash_spec.rb +22 -0
- data/spec/record/to_json_spec.rb +22 -0
- data/spec/record/tracing_spec.rb +149 -0
- data/spec/record/update_spec.rb +61 -0
- data/spec/record/where_chains_spec.rb +57 -0
- data/spec/record/where_spec.rb +62 -0
- data/spec/record/where_values_hash_spec.rb +32 -0
- data/spec/request_cycle_cache_spec.rb +106 -0
- data/spec/require_dhs_spec.rb +9 -0
- data/spec/spec_helper.rb +6 -0
- data/spec/stubs/all_spec.rb +69 -0
- data/spec/support/fixtures/json/feedback.json +11 -0
- data/spec/support/fixtures/json/feedbacks.json +174 -0
- data/spec/support/fixtures/json/localina_content_ad.json +23 -0
- data/spec/support/load_json.rb +5 -0
- data/spec/support/request_cycle_cache.rb +10 -0
- data/spec/support/reset.rb +67 -0
- data/spec/views/form_for_spec.rb +20 -0
- metadata +783 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'rails_helper'
|
|
4
|
+
|
|
5
|
+
describe DHS::Data do
|
|
6
|
+
before do
|
|
7
|
+
class Record < DHS::Record
|
|
8
|
+
endpoint '{+datastore}/v2/entries/{entry_id}/content-ads/{campaign_id}/feedbacks'
|
|
9
|
+
endpoint '{+datastore}/v2/{campaign_id}/feedbacks'
|
|
10
|
+
endpoint '{+datastore}/v2/feedbacks'
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
let(:data_from_raw) do
|
|
15
|
+
DHS::Data.new({ href: 'http://www.depay.fi/v2/stuff', id: '123123123' }, nil, Record)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
let(:data_from_item) do
|
|
19
|
+
raw = { href: 'http://www.depay.fi/v2/stuff' }
|
|
20
|
+
item = DHS::Item.new(DHS::Data.new(raw, nil, Record))
|
|
21
|
+
DHS::Data.new(item)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
let(:data_from_array) do
|
|
25
|
+
DHS::Data.new([
|
|
26
|
+
{ href: 'http://www.depay.fi/v2/stuff/3', id: '123123123' },
|
|
27
|
+
{ href: 'http://www.depay.fi/v2/stuff/4', id: '123123124' }
|
|
28
|
+
].to_json)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
context 'raw' do
|
|
32
|
+
it 'you can access raw data that is underlying' do
|
|
33
|
+
expect(data_from_raw._raw).to be_kind_of Hash
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it 'forwards raw when you feed data with some DHS object' do
|
|
37
|
+
expect(data_from_item._raw).to be_kind_of Hash
|
|
38
|
+
expect(data_from_item._raw).to eq(
|
|
39
|
+
href: 'http://www.depay.fi/v2/stuff'
|
|
40
|
+
)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it 'returns a Hash with symbols when the input is an array' do
|
|
44
|
+
expect(data_from_array._raw).to be_kind_of Array
|
|
45
|
+
expect(data_from_array._raw.first.keys.first).to be_kind_of Symbol
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'rails_helper'
|
|
4
|
+
|
|
5
|
+
describe DHS::Data do
|
|
6
|
+
before do
|
|
7
|
+
class Record < DHS::Record
|
|
8
|
+
map :test_mapping?, ->(_item) { true }
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
context '#respond_to?' do
|
|
13
|
+
it 'is true for mappings that are defined' do
|
|
14
|
+
data = DHS::Data.new({ 'campaign' => { 'id' => 123 } }, nil, Record)
|
|
15
|
+
|
|
16
|
+
expect(data.respond_to?(:test_mapping?)).to be(true)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# proxy for this example is DHC::Collection which implements total
|
|
20
|
+
it 'is true for calls forwarded to proxy' do
|
|
21
|
+
data = DHS::Data.new({ 'items' => [{ 'campaign' => { 'id' => 123 } }] }, nil, Record)
|
|
22
|
+
|
|
23
|
+
expect(data.respond_to?(:total)).to be(true)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'rails_helper'
|
|
4
|
+
|
|
5
|
+
describe DHS::Data do
|
|
6
|
+
before do
|
|
7
|
+
class Record < DHS::Record
|
|
8
|
+
endpoint '{+datastore}/v2/entries/{entry_id}/content-ads/{campaign_id}/feedbacks'
|
|
9
|
+
endpoint '{+datastore}/v2/{campaign_id}/feedbacks'
|
|
10
|
+
endpoint '{+datastore}/v2/feedbacks'
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
context 'root' do
|
|
15
|
+
it 'is navigateable from nested data' do
|
|
16
|
+
root = DHS::Data.new({ 'items' => [{ 'campaign' => { 'id' => 123 } }] }, nil, Record)
|
|
17
|
+
child = root.first
|
|
18
|
+
leafe = child.campaign
|
|
19
|
+
expect(leafe._root).to eq root
|
|
20
|
+
expect(leafe._parent).to be_kind_of DHS::Data
|
|
21
|
+
expect(leafe._parent._parent).to be_kind_of DHS::Data
|
|
22
|
+
expect(leafe._parent._parent).to eq root
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'rails_helper'
|
|
4
|
+
|
|
5
|
+
describe DHS::Data do
|
|
6
|
+
let(:raw) do
|
|
7
|
+
{ labels: { de: %w[cat dog] } }
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
let(:data) do
|
|
11
|
+
DHS::Data.new(raw, nil, Record)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
before do
|
|
15
|
+
class Record < DHS::Record
|
|
16
|
+
endpoint '{+datastore}/v2/data'
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
context 'select' do
|
|
21
|
+
it 'works with select' do
|
|
22
|
+
expect(
|
|
23
|
+
data.labels.de.select { |x| x }.join
|
|
24
|
+
).to eq 'catdog'
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'rails_helper'
|
|
4
|
+
|
|
5
|
+
describe DHS::Data do
|
|
6
|
+
before do
|
|
7
|
+
class Record < DHS::Record
|
|
8
|
+
endpoint '{+datastore}/v2/{campaign_id}/feedbacks'
|
|
9
|
+
endpoint '{+datastore}/v2/feedbacks'
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
let(:json) do
|
|
14
|
+
load_json(:feedbacks)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
let(:data) do
|
|
18
|
+
DHS::Data.new(json, nil, Record)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
let(:item) do
|
|
22
|
+
data[0]
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it 'does not respond to to_ary' do
|
|
26
|
+
expect(item.respond_to?(:to_ary)).to eq false
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'rails_helper'
|
|
4
|
+
|
|
5
|
+
describe DHS::Data do
|
|
6
|
+
before do
|
|
7
|
+
class Record < DHS::Record
|
|
8
|
+
endpoint '{+datastore}/v2/{campaign_id}/feedbacks'
|
|
9
|
+
endpoint '{+datastore}/v2/feedbacks'
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
let(:json) do
|
|
14
|
+
load_json(:feedbacks)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
let(:collection) do
|
|
18
|
+
DHS::Data.new(json, nil, Record)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
let(:item) do
|
|
22
|
+
collection[0]
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it 'converts item to json' do
|
|
26
|
+
expect(item.to_json)
|
|
27
|
+
.to eq JSON.parse(load_json(:feedbacks))['items'].first.to_json
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it 'converts collection to json' do
|
|
31
|
+
expect(collection.to_json)
|
|
32
|
+
.to eq JSON.parse(load_json(:feedbacks)).to_json
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it 'converts collection with options to json' do
|
|
36
|
+
expect(collection.as_json(only: %i[items href])).to eq(
|
|
37
|
+
'items' => [
|
|
38
|
+
{ 'href' => 'http://depay.fi/v2/feedbacks/0sdaetZ-OWVg4oBiBJ-7IQ' },
|
|
39
|
+
{ 'href' => 'http://depay.fi/v2/feedbacks/QsUOQWNJoB-GFUNsX7z0jg' },
|
|
40
|
+
{ 'href' => 'http://depay.fi/v2/feedbacks/QynNtmpXlsEGvUJ0ekDKVw' },
|
|
41
|
+
{ 'href' => 'http://depay.fi/v2/feedbacks/INmminYWNZwW_qNFx5peJQ' },
|
|
42
|
+
{ 'href' => 'http://depay.fi/v2/feedbacks/ltgfr0VRYDN2nxyC119wTg' },
|
|
43
|
+
{ 'href' => 'http://depay.fi/v2/feedbacks/5dUdQP-kZ6sulN8NtpGXTw' },
|
|
44
|
+
{ 'href' => 'http://depay.fi/v2/feedbacks/Z3KfWzIEQ3ZVCUj2IdrSNQ' },
|
|
45
|
+
{ 'href' => 'http://depay.fi/v2/feedbacks/ZUUUeiw-Stw5Zb1baHDUzQ' },
|
|
46
|
+
{ 'href' => 'http://depay.fi/v2/feedbacks/GyeWvhEtU4cYN_5T2FX2UA' },
|
|
47
|
+
{ 'href' => 'http://depay.fi/v2/feedbacks/o-qTRqQGFS3Z_RPJm1f8SA' }
|
|
48
|
+
],
|
|
49
|
+
'href' => 'http://depay.fi/v2/feedbacks/?exclude_hidden=false&offset=0&limit=10'
|
|
50
|
+
)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it 'converts link to json' do
|
|
54
|
+
expect(item.campaign.to_json)
|
|
55
|
+
.to eq item.campaign._raw.to_json
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
context 'collections from arrays' do
|
|
59
|
+
let(:collection) do
|
|
60
|
+
DHS::Data.new([{ foo: 'foo', bar: 'bar' }])
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it 'converts with options to json' do
|
|
64
|
+
expect(collection.as_json(only: :foo)).to eq [{ 'foo' => 'foo' }]
|
|
65
|
+
expect(collection.to_json(only: :foo)).to eq '[{"foo":"foo"}]'
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
data/spec/dummy/Rakefile
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
|
4
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
|
5
|
+
|
|
6
|
+
require File.expand_path('config/application', __dir__)
|
|
7
|
+
|
|
8
|
+
Rails.application.load_tasks
|
|
File without changes
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
|
2
|
+
// listed below.
|
|
3
|
+
//
|
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
|
6
|
+
//
|
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
|
8
|
+
// compiled file.
|
|
9
|
+
//
|
|
10
|
+
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
|
|
11
|
+
// about supported directives.
|
|
12
|
+
//
|
|
13
|
+
//= require_tree .
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
|
3
|
+
* listed below.
|
|
4
|
+
*
|
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
|
7
|
+
*
|
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any styles
|
|
10
|
+
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
|
11
|
+
* file per style scope.
|
|
12
|
+
*
|
|
13
|
+
*= require_tree .
|
|
14
|
+
*= require_self
|
|
15
|
+
*/
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class ApplicationController < ActionController::Base
|
|
4
|
+
include DHS::OAuth
|
|
5
|
+
ACCESS_TOKEN = 'token-12345'
|
|
6
|
+
|
|
7
|
+
# Prevent CSRF attacks by raising an exception.
|
|
8
|
+
# For APIs, you may want to use :null_session instead.
|
|
9
|
+
protect_from_forgery with: :exception
|
|
10
|
+
|
|
11
|
+
def root
|
|
12
|
+
render nothing: true
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def access_token
|
|
16
|
+
ACCESS_TOKEN
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def access_token_provider_1
|
|
20
|
+
"#{ACCESS_TOKEN}_provider_1"
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def access_token_provider_2
|
|
24
|
+
"#{ACCESS_TOKEN}_provider_2"
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class AutomaticAuthenticationController < ApplicationController
|
|
4
|
+
|
|
5
|
+
def o_auth
|
|
6
|
+
render json: {
|
|
7
|
+
record: DummyRecordWithOauth.find(1).as_json,
|
|
8
|
+
records: DummyRecordWithOauth.where(color: 'blue').as_json
|
|
9
|
+
}
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def o_auth_with_multiple_providers
|
|
13
|
+
render json: {
|
|
14
|
+
record: DummyRecordWithMultipleOauthProviders1.find(1).as_json,
|
|
15
|
+
records: DummyRecordWithMultipleOauthProviders2.where(color: 'blue').as_json,
|
|
16
|
+
per_endpoint: {
|
|
17
|
+
record: DummyRecordWithMultipleOauthProvidersPerEndpoint.find(1).as_json,
|
|
18
|
+
records: DummyRecordWithMultipleOauthProvidersPerEndpoint.where(color: 'blue').as_json
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def o_auth_with_provider
|
|
24
|
+
render json: {
|
|
25
|
+
record: DummyRecordWithAutoOauthProvider.find(1).as_json,
|
|
26
|
+
records: DummyRecordWithAutoOauthProvider.where(color: 'blue').as_json
|
|
27
|
+
}
|
|
28
|
+
end
|
|
29
|
+
end
|
|
File without changes
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class ErrorHandlingWithChainsController < ApplicationController
|
|
4
|
+
|
|
5
|
+
# Example where the query chain is resolved
|
|
6
|
+
# in the view (during render 'show')
|
|
7
|
+
def fetch_in_view
|
|
8
|
+
@records = DummyRecord
|
|
9
|
+
.rescue(DHC::Error, ->(error) { handle_error(error) })
|
|
10
|
+
.where(color: 'blue')
|
|
11
|
+
render 'show'
|
|
12
|
+
render_error if @error
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# Example where the query chain is resolved
|
|
16
|
+
# before the view is rendered
|
|
17
|
+
def fetch_in_controller
|
|
18
|
+
@records = DummyRecord
|
|
19
|
+
.rescue(DHC::Error, ->(error) { handle_error(error) })
|
|
20
|
+
.where(color: 'blue').fetch
|
|
21
|
+
render 'show'
|
|
22
|
+
render_error if @error
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
def handle_error(error)
|
|
28
|
+
@error = error
|
|
29
|
+
nil
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def render_error
|
|
33
|
+
self.response_body = nil
|
|
34
|
+
render 'error'
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class ExtendedRollbarController < ApplicationController
|
|
4
|
+
|
|
5
|
+
def extended_rollbar
|
|
6
|
+
DummyRecord.where(color: 'blue').fetch
|
|
7
|
+
DummyRecord.where(color: 'red').fetch
|
|
8
|
+
raise "Let's see if rollbar logs information about what kind of requests where made around here!"
|
|
9
|
+
end
|
|
10
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class OptionBlocksController < ApplicationController
|
|
4
|
+
|
|
5
|
+
def first
|
|
6
|
+
DHS::OptionBlocks::CurrentOptionBlock.options = { params: { request: 'first' } }
|
|
7
|
+
DummyRecord.where(request: 'second').fetch
|
|
8
|
+
render text: 'ok'
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def second
|
|
12
|
+
DummyRecord.where(request: 'second').fetch
|
|
13
|
+
render text: 'ok'
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class RequestCycleCacheController < ApplicationController
|
|
4
|
+
def simple
|
|
5
|
+
User.find(1) # first request
|
|
6
|
+
user = User.find(1) # second request that should be serverd from request cycle cache
|
|
7
|
+
render json: user.to_json
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def no_caching_interceptor
|
|
11
|
+
User.options(interceptors: []).find(1) # first request
|
|
12
|
+
user = User.options(interceptors: []).find(1) # second request
|
|
13
|
+
render json: user.to_json
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def parallel
|
|
17
|
+
User.find(1, 2) # first request
|
|
18
|
+
users = User.find(1, 2) # second request that should be serverd from request cycle cache
|
|
19
|
+
render json: users.to_json
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def headers_are_different
|
|
23
|
+
User.find(1) # first request
|
|
24
|
+
user = User.options(headers: { 'Authentication' => 'Bearer 123' }).find(1) # second request that should NOT be serverd from request cycle cache as the headers are different
|
|
25
|
+
render json: user.to_json
|
|
26
|
+
end
|
|
27
|
+
end
|
|
File without changes
|
|
File without changes
|
|
File without changes
|