infinum_json_api_setup 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +6 -0
  3. data/.overcommit.yml +26 -0
  4. data/.rspec +2 -0
  5. data/.rubocop.yml +29 -0
  6. data/.ruby-version +1 -0
  7. data/.simplecov +3 -0
  8. data/Gemfile +10 -0
  9. data/Gemfile.lock +268 -0
  10. data/README.md +156 -0
  11. data/Rakefile +1 -0
  12. data/bin/setup +18 -0
  13. data/infinum_json_api_setup.gemspec +30 -0
  14. data/lib/generators/infinum_json_api_setup/install_generator.rb +12 -0
  15. data/lib/generators/infinum_json_api_setup/templates/config/locales/json_api.en.yml +21 -0
  16. data/lib/infinum_json_api_setup/error.rb +61 -0
  17. data/lib/infinum_json_api_setup/json_api/content_negotiation.rb +29 -0
  18. data/lib/infinum_json_api_setup/json_api/error_handling.rb +49 -0
  19. data/lib/infinum_json_api_setup/json_api/error_serializer.rb +72 -0
  20. data/lib/infinum_json_api_setup/json_api/request_parsing.rb +17 -0
  21. data/lib/infinum_json_api_setup/json_api/responder.rb +31 -0
  22. data/lib/infinum_json_api_setup/json_api/serializer_options.rb +76 -0
  23. data/lib/infinum_json_api_setup/rails.rb +28 -0
  24. data/lib/infinum_json_api_setup/rspec/helpers/request_helper.rb +80 -0
  25. data/lib/infinum_json_api_setup/rspec/helpers/response_helper.rb +56 -0
  26. data/lib/infinum_json_api_setup/rspec/matchers/have_empty_data.rb +32 -0
  27. data/lib/infinum_json_api_setup/rspec/matchers/have_error_pointer.rb +37 -0
  28. data/lib/infinum_json_api_setup/rspec/matchers/have_resource_count_of.rb +37 -0
  29. data/lib/infinum_json_api_setup/rspec/matchers/include_all_resource_ids.rb +51 -0
  30. data/lib/infinum_json_api_setup/rspec/matchers/include_all_resource_ids_sorted.rb +21 -0
  31. data/lib/infinum_json_api_setup/rspec/matchers/include_all_resource_string_ids.rb +17 -0
  32. data/lib/infinum_json_api_setup/rspec/matchers/include_error_detail.rb +37 -0
  33. data/lib/infinum_json_api_setup/rspec/matchers/include_related_resource.rb +42 -0
  34. data/lib/infinum_json_api_setup/rspec/matchers/json_body_matcher.rb +42 -0
  35. data/lib/infinum_json_api_setup/rspec/matchers/schema_matchers.rb +29 -0
  36. data/lib/infinum_json_api_setup/rspec.rb +21 -0
  37. data/lib/infinum_json_api_setup/version.rb +3 -0
  38. data/lib/infinum_json_api_setup.rb +16 -0
  39. data/spec/controllers/api/v1/base_controller_spec.rb +9 -0
  40. data/spec/dummy/Rakefile +6 -0
  41. data/spec/dummy/app/assets/config/manifest.js +1 -0
  42. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  43. data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
  44. data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
  45. data/spec/dummy/app/controllers/api/v1/base_controller.rb +11 -0
  46. data/spec/dummy/app/controllers/api/v1/locations_controller.rb +64 -0
  47. data/spec/dummy/app/controllers/application_controller.rb +2 -0
  48. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  49. data/spec/dummy/app/javascript/packs/application.js +15 -0
  50. data/spec/dummy/app/jobs/application_job.rb +7 -0
  51. data/spec/dummy/app/mailers/application_mailer.rb +4 -0
  52. data/spec/dummy/app/models/application_record.rb +3 -0
  53. data/spec/dummy/app/models/concerns/.keep +0 -0
  54. data/spec/dummy/app/models/location.rb +38 -0
  55. data/spec/dummy/app/models/location_label.rb +3 -0
  56. data/spec/dummy/app/policies/application_policy.rb +51 -0
  57. data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
  58. data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
  59. data/spec/dummy/app/web/api/v1/locations/label_serializer.rb +13 -0
  60. data/spec/dummy/app/web/api/v1/locations/policy.rb +28 -0
  61. data/spec/dummy/app/web/api/v1/locations/query.rb +12 -0
  62. data/spec/dummy/app/web/api/v1/locations/serializer.rb +15 -0
  63. data/spec/dummy/bin/rails +4 -0
  64. data/spec/dummy/bin/rake +4 -0
  65. data/spec/dummy/bin/setup +33 -0
  66. data/spec/dummy/config/application.rb +39 -0
  67. data/spec/dummy/config/boot.rb +5 -0
  68. data/spec/dummy/config/cable.yml +10 -0
  69. data/spec/dummy/config/database.yml +15 -0
  70. data/spec/dummy/config/environment.rb +5 -0
  71. data/spec/dummy/config/environments/development.rb +65 -0
  72. data/spec/dummy/config/environments/production.rb +114 -0
  73. data/spec/dummy/config/environments/test.rb +60 -0
  74. data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -0
  75. data/spec/dummy/config/initializers/backtrace_silencers.rb +10 -0
  76. data/spec/dummy/config/initializers/cors.rb +16 -0
  77. data/spec/dummy/config/initializers/filter_parameter_logging.rb +6 -0
  78. data/spec/dummy/config/initializers/inflections.rb +16 -0
  79. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  80. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  81. data/spec/dummy/config/locales/en.yml +33 -0
  82. data/spec/dummy/config/locales/json_api.en.yml +21 -0
  83. data/spec/dummy/config/puma.rb +43 -0
  84. data/spec/dummy/config/routes.rb +7 -0
  85. data/spec/dummy/config/storage.yml +34 -0
  86. data/spec/dummy/config.ru +6 -0
  87. data/spec/dummy/db/migrate/20210709100750_create_locations.rb +10 -0
  88. data/spec/dummy/db/migrate/20210714104736_create_location_labels.rb +10 -0
  89. data/spec/dummy/db/schema.rb +34 -0
  90. data/spec/dummy/log/.keep +0 -0
  91. data/spec/dummy/storage/.keep +0 -0
  92. data/spec/factories/location.rb +11 -0
  93. data/spec/factories/location_label.rb +6 -0
  94. data/spec/infinum_json_api_setup/rspec/matchers/have_empty_data_spec.rb +43 -0
  95. data/spec/infinum_json_api_setup/rspec/matchers/have_error_pointer_spec.rb +43 -0
  96. data/spec/infinum_json_api_setup/rspec/matchers/have_resource_count_of_spec.rb +43 -0
  97. data/spec/infinum_json_api_setup/rspec/matchers/include_all_resource_ids_sorted_spec.rb +53 -0
  98. data/spec/infinum_json_api_setup/rspec/matchers/include_all_resource_ids_spec.rb +49 -0
  99. data/spec/infinum_json_api_setup/rspec/matchers/include_all_resource_string_ids_spec.rb +49 -0
  100. data/spec/infinum_json_api_setup/rspec/matchers/include_error_detail_spec.rb +43 -0
  101. data/spec/infinum_json_api_setup/rspec/matchers/include_related_resource_spec.rb +43 -0
  102. data/spec/infinum_json_api_setup/rspec/matchers/util/body_parser.rb +30 -0
  103. data/spec/rails_helper.rb +77 -0
  104. data/spec/requests/api/v1/content_negotiation_spec.rb +29 -0
  105. data/spec/requests/api/v1/error_handling_spec.rb +114 -0
  106. data/spec/requests/api/v1/responder_spec.rb +91 -0
  107. data/spec/requests/api/v1/serializer_options_spec.rb +46 -0
  108. data/spec/spec_helper.rb +94 -0
  109. data/spec/support/factory_bot.rb +7 -0
  110. data/spec/support/infinum_json_api_setup.rb +1 -0
  111. data/spec/support/rspec_expectations.rb +5 -0
  112. data/spec/support/test_helpers/matchers/response.rb +17 -0
  113. data/spec/support/test_helpers/request.rb +11 -0
  114. data/spec/support/test_helpers/response.rb +8 -0
  115. metadata +351 -0
@@ -0,0 +1,42 @@
1
+ module InfinumJsonApiSetup
2
+ module RSpec
3
+ module Matchers
4
+ # @param [String] type
5
+ # @param [Integer] id
6
+ # @return [InfinumJsonApiSetup::Rspec::Matchers::IncludeRelatedResource]
7
+ def include_related_resource(type, id)
8
+ IncludeRelatedResource.new(type, id)
9
+ end
10
+
11
+ class IncludeRelatedResource < JsonBodyMatcher
12
+ # @param [String] type
13
+ # @param [Integer] id
14
+ def initialize(type, id)
15
+ super(Matchers::Util::BodyParser.new('included'))
16
+
17
+ @type = type
18
+ @id = id
19
+ end
20
+
21
+ private
22
+
23
+ attr_reader :id
24
+ attr_reader :included
25
+ attr_reader :pointer
26
+ attr_reader :type
27
+
28
+ def body_matches?
29
+ included.one? { |item| item['type'] == type && item['id'].to_i == id }
30
+ end
31
+
32
+ def match_failure_message
33
+ "Expected included items to include (type = #{type}, id = #{id}), but didn't"
34
+ end
35
+
36
+ def process_parsing_result(result)
37
+ @included = result
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,42 @@
1
+ module InfinumJsonApiSetup
2
+ module RSpec
3
+ module Matchers
4
+ class JsonBodyMatcher
5
+ def initialize(parser)
6
+ @parser = parser
7
+ end
8
+
9
+ # @param [ActionDispatch::TestResponse] response
10
+ # @return [Boolean]
11
+ def matches?(response)
12
+ @response = response
13
+ success, result = parser.process(response)
14
+
15
+ if success
16
+ process_parsing_result(result)
17
+ body_matches?
18
+ else
19
+ @error_message = result
20
+ false
21
+ end
22
+ end
23
+
24
+ # @return [String]
25
+ def failure_message
26
+ @error_message || match_failure_message
27
+ end
28
+
29
+ private
30
+
31
+ attr_reader :parser
32
+ attr_reader :response
33
+
34
+ def body_matches?; end
35
+
36
+ def match_failure_message; end
37
+
38
+ def process_parsing_result(_result); end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,29 @@
1
+ RSpec::Matchers.define :match_response_schema do |schema|
2
+ match do |response|
3
+ schema_path = RSpec.configuration.schema_response_root.join("#{schema}.json")
4
+ schemer = JSONSchemer.schema(schema_path)
5
+
6
+ @errors = schemer.validate(JSON.parse(response.body))
7
+
8
+ @errors.none?
9
+ end
10
+
11
+ failure_message do |_|
12
+ @errors.map { |error| JSONSchemer::Errors.pretty error }
13
+ end
14
+ end
15
+
16
+ RSpec::Matchers.define :match_request_schema do |schema|
17
+ match do |request|
18
+ schema_path = RSpec.configuration.schema_request_root.join("#{schema}.json")
19
+ schemer = JSONSchemer.schema(schema_path)
20
+
21
+ @errors = schemer.validate(JSON.parse(request.body.readpartial))
22
+
23
+ @errors.none?
24
+ end
25
+
26
+ failure_message do |_|
27
+ @errors.map { |error| JSONSchemer::Errors.pretty error }
28
+ end
29
+ end
@@ -0,0 +1,21 @@
1
+ require 'infinum_json_api_setup/rspec/matchers/schema_matchers'
2
+ require 'infinum_json_api_setup/rspec/matchers/util/body_parser'
3
+ require 'infinum_json_api_setup/rspec/matchers/json_body_matcher'
4
+ require 'infinum_json_api_setup/rspec/matchers/include_all_resource_ids'
5
+ require 'infinum_json_api_setup/rspec/matchers/include_all_resource_string_ids'
6
+ require 'infinum_json_api_setup/rspec/matchers/include_all_resource_ids_sorted'
7
+ require 'infinum_json_api_setup/rspec/matchers/have_empty_data'
8
+ require 'infinum_json_api_setup/rspec/matchers/have_resource_count_of'
9
+ require 'infinum_json_api_setup/rspec/matchers/include_error_detail'
10
+ require 'infinum_json_api_setup/rspec/matchers/have_error_pointer'
11
+ require 'infinum_json_api_setup/rspec/matchers/include_related_resource'
12
+
13
+ require 'infinum_json_api_setup/rspec/helpers/request_helper'
14
+ require 'infinum_json_api_setup/rspec/helpers/response_helper'
15
+
16
+ RSpec.configure do |config|
17
+ config.include InfinumJsonApiSetup::RSpec::Matchers
18
+
19
+ config.add_setting :schema_response_root
20
+ config.add_setting :schema_request_root
21
+ end
@@ -0,0 +1,3 @@
1
+ module InfinumJsonApiSetup
2
+ VERSION = '0.0.3'.freeze
3
+ end
@@ -0,0 +1,16 @@
1
+ require 'jsonapi_parameters'
2
+ require 'rails'
3
+ require 'responders'
4
+ require 'pagy'
5
+ require 'json_schemer'
6
+
7
+ require 'infinum_json_api_setup/error'
8
+ require 'infinum_json_api_setup/json_api/error_handling'
9
+ require 'infinum_json_api_setup/json_api/error_serializer'
10
+
11
+ require 'infinum_json_api_setup/json_api/content_negotiation'
12
+ require 'infinum_json_api_setup/json_api/request_parsing'
13
+ require 'infinum_json_api_setup/json_api/serializer_options'
14
+ require 'infinum_json_api_setup/json_api/responder'
15
+
16
+ require 'infinum_json_api_setup/rails'
@@ -0,0 +1,9 @@
1
+ describe Api::V1::BaseController do
2
+ it 'sets responder' do
3
+ expect(described_class.responder).to eq(InfinumJsonApiSetup::JsonApi::Responder)
4
+ end
5
+
6
+ it 'sets respond_to' do
7
+ expect(described_class.respond_to).to have_key(:json_api)
8
+ end
9
+ end
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require_relative 'config/application'
5
+
6
+ Rails.application.load_tasks
@@ -0,0 +1 @@
1
+ //= link_directory ../stylesheets .css
@@ -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 any plugin's vendor/assets/stylesheets directory 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 other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,4 @@
1
+ module ApplicationCable
2
+ class Channel < ActionCable::Channel::Base
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module ApplicationCable
2
+ class Connection < ActionCable::Connection::Base
3
+ end
4
+ end
@@ -0,0 +1,11 @@
1
+ module Api
2
+ module V1
3
+ class BaseController < ApplicationController
4
+ include InfinumJsonApiSetup::JsonApi::ErrorHandling
5
+ include InfinumJsonApiSetup::JsonApi::ContentNegotiation
6
+
7
+ self.responder = InfinumJsonApiSetup::JsonApi::Responder
8
+ respond_to :json_api
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,64 @@
1
+ module Api
2
+ module V1
3
+ class LocationsController < BaseController
4
+ include Pundit
5
+
6
+ around_action :with_locale
7
+
8
+ # GET /api/v1/locations
9
+ def index
10
+ q = Api::V1::Locations::Query.new(Location.all, params.to_unsafe_hash)
11
+
12
+ respond_with q.results, pagination_details: q.pagination_details
13
+ end
14
+
15
+ # GET /api/v1/locations
16
+ def create
17
+ location = Location.create(permitted_params)
18
+
19
+ respond_with location
20
+ end
21
+
22
+ # GET /api/v1/locations/:id
23
+ def show
24
+ location = authorize(Location.find(params[:id]))
25
+
26
+ respond_with location
27
+ end
28
+
29
+ # PUT/PATCH /api/v1/locations/:id
30
+ def update
31
+ location = authorize(Location.find(params[:id]))
32
+ location.update(permitted_params)
33
+
34
+ respond_with location
35
+ end
36
+
37
+ # DELETE /api/v1/locations/:id
38
+ def destroy
39
+ location = authorize(Location.find(params[:id]))
40
+ location.destroy
41
+
42
+ respond_with location
43
+ end
44
+
45
+ private
46
+
47
+ def with_locale(&block)
48
+ I18n.with_locale(params.fetch(:locale, :en), &block)
49
+ end
50
+
51
+ def permitted_params
52
+ params.require(:location).permit(:latitude, :longitude)
53
+ end
54
+
55
+ def authorize(record)
56
+ super(record, policy_class: Api::V1::Locations::Policy)
57
+ end
58
+
59
+ def pundit_user
60
+ nil
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,2 @@
1
+ class ApplicationController < ActionController::API
2
+ end
File without changes
@@ -0,0 +1,15 @@
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 any plugin's vendor/assets/javascripts directory 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. JavaScript code in this file should be added after the last require_* statement.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require rails-ujs
14
+ //= require activestorage
15
+ //= require_tree .
@@ -0,0 +1,7 @@
1
+ class ApplicationJob < ActiveJob::Base
2
+ # Automatically retry jobs that encountered a deadlock
3
+ # retry_on ActiveRecord::Deadlocked
4
+
5
+ # Most jobs are safe to ignore if the underlying records are no longer available
6
+ # discard_on ActiveJob::DeserializationError
7
+ end
@@ -0,0 +1,4 @@
1
+ class ApplicationMailer < ActionMailer::Base
2
+ default from: 'from@example.com'
3
+ layout 'mailer'
4
+ end
@@ -0,0 +1,3 @@
1
+ class ApplicationRecord < ActiveRecord::Base
2
+ self.abstract_class = true
3
+ end
File without changes
@@ -0,0 +1,38 @@
1
+ class Location < ApplicationRecord
2
+ MIN_LATITUDE = -90
3
+ MAX_LATITUDE = 90
4
+ MIN_LONGITUDE = -180
5
+ MAX_LONGITUDE = 180
6
+ FIRST_QUADRANT = :first
7
+ SECOND_QUADRANT = :second
8
+ THIRD_QUADRANT = :third
9
+ FOURTH_QUADRANT = :fourth
10
+ ORIGIN = :origin
11
+ X_AXIS = :x_axis
12
+ Y_AXIS = :y_axis
13
+
14
+ has_many :labels, class_name: 'LocationLabel'
15
+ validates :latitude, numericality: { greater_than_or_equal_to: MIN_LATITUDE,
16
+ less_than_or_equal_to: MAX_LATITUDE }
17
+ validates :longitude, numericality: { greater_than_or_equal_to: MIN_LONGITUDE,
18
+ less_than_or_equal_to: MAX_LONGITUDE }
19
+
20
+ # @return [Integer]
21
+ def quadrant # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
22
+ if latitude.positive? && longitude.positive?
23
+ FIRST_QUADRANT
24
+ elsif latitude.positive? && longitude.negative?
25
+ SECOND_QUADRANT
26
+ elsif latitude.negative? && longitude.negative?
27
+ THIRD_QUADRANT
28
+ elsif latitude.negative? && longitude.positive?
29
+ FOURTH_QUADRANT
30
+ elsif latitude.zero? && longitude.zero?
31
+ ORIGIN
32
+ elsif latitude.zero?
33
+ X_AXIS
34
+ else
35
+ Y_AXIS
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,3 @@
1
+ class LocationLabel < ApplicationRecord
2
+ belongs_to :location
3
+ end
@@ -0,0 +1,51 @@
1
+ class ApplicationPolicy
2
+ attr_reader :user
3
+ attr_reader :record
4
+
5
+ def initialize(user, record)
6
+ @user = user
7
+ @record = record
8
+ end
9
+
10
+ def index?
11
+ false
12
+ end
13
+
14
+ def show?
15
+ false
16
+ end
17
+
18
+ def create?
19
+ false
20
+ end
21
+
22
+ def new?
23
+ create?
24
+ end
25
+
26
+ def update?
27
+ false
28
+ end
29
+
30
+ def edit?
31
+ update?
32
+ end
33
+
34
+ def destroy?
35
+ false
36
+ end
37
+
38
+ class Scope
39
+ attr_reader :user
40
+ attr_reader :scope
41
+
42
+ def initialize(user, scope)
43
+ @user = user
44
+ @scope = scope
45
+ end
46
+
47
+ def resolve
48
+ scope.all
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,13 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5
+ <style>
6
+ /* Email styles need to be inline */
7
+ </style>
8
+ </head>
9
+
10
+ <body>
11
+ <%= yield %>
12
+ </body>
13
+ </html>
@@ -0,0 +1 @@
1
+ <%= yield %>
@@ -0,0 +1,13 @@
1
+ module Api
2
+ module V1
3
+ module Locations
4
+ class LabelSerializer
5
+ include JSONAPI::Serializer
6
+
7
+ attribute :title
8
+ attribute :created_at
9
+ attribute :updated_at
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,28 @@
1
+ module Api
2
+ module V1
3
+ module Locations
4
+ class Policy < ApplicationPolicy
5
+ # @return [Boolean]
6
+ def show?
7
+ first_quadrant?
8
+ end
9
+
10
+ # @return [Boolean]
11
+ def update?
12
+ first_quadrant?
13
+ end
14
+
15
+ # @return [Boolean]
16
+ def destroy?
17
+ first_quadrant?
18
+ end
19
+
20
+ private
21
+
22
+ def first_quadrant?
23
+ record.quadrant == Location::FIRST_QUADRANT
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,12 @@
1
+ module Api
2
+ module V1
3
+ module Locations
4
+ class Query < Jsonapi::QueryBuilder::BaseQuery
5
+ default_sort created_at: :asc
6
+
7
+ sorts_by :latitude
8
+ sorts_by :longitude
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,15 @@
1
+ module Api
2
+ module V1
3
+ module Locations
4
+ class Serializer
5
+ include JSONAPI::Serializer
6
+
7
+ has_many :labels, serializer: LabelSerializer
8
+ attribute :latitude
9
+ attribute :longitude
10
+ attribute :created_at
11
+ attribute :updated_at
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = File.expand_path('../config/application', __dir__)
3
+ require_relative '../config/boot'
4
+ require 'rails/commands'
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../config/boot'
3
+ require 'rake'
4
+ Rake.application.run
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env ruby
2
+ require 'fileutils'
3
+
4
+ # path to your application root.
5
+ APP_ROOT = File.expand_path('..', __dir__)
6
+
7
+ def system!(*args)
8
+ system(*args) || abort("\n== Command #{args} failed ==")
9
+ end
10
+
11
+ FileUtils.chdir APP_ROOT do
12
+ # This script is a way to set up or update your development environment automatically.
13
+ # This script is idempotent, so that you can run it at any time and get an expectable outcome.
14
+ # Add necessary setup steps to this file.
15
+
16
+ puts '== Installing dependencies =='
17
+ system! 'gem install bundler --conservative'
18
+ system('bundle check') || system!('bundle install')
19
+
20
+ # puts "\n== Copying sample files =="
21
+ # unless File.exist?('config/database.yml')
22
+ # FileUtils.cp 'config/database.yml.sample', 'config/database.yml'
23
+ # end
24
+
25
+ puts "\n== Preparing database =="
26
+ system! 'bin/rails db:prepare'
27
+
28
+ puts "\n== Removing old logs and tempfiles =="
29
+ system! 'bin/rails log:clear tmp:clear'
30
+
31
+ puts "\n== Restarting application server =="
32
+ system! 'bin/rails restart'
33
+ end
@@ -0,0 +1,39 @@
1
+ require_relative 'boot'
2
+
3
+ require 'rails'
4
+ # Pick the frameworks you want:
5
+ require 'active_model/railtie'
6
+ require 'active_job/railtie'
7
+ require 'active_record/railtie'
8
+ require 'active_storage/engine'
9
+ require 'action_controller/railtie'
10
+ require 'action_mailer/railtie'
11
+ require 'action_mailbox/engine'
12
+ require 'action_text/engine'
13
+ require 'action_view/railtie'
14
+ require 'action_cable/engine'
15
+ # require "sprockets/railtie"
16
+ require 'rails/test_unit/railtie'
17
+
18
+ # Require the gems listed in Gemfile, including any gems
19
+ # you've limited to :test, :development, or :production.
20
+ Bundler.require(*Rails.groups)
21
+
22
+ module Dummy
23
+ class Application < Rails::Application
24
+ config.load_defaults Rails::VERSION::STRING.to_f
25
+
26
+ # Configuration for the application, engines, and railties goes here.
27
+ #
28
+ # These settings can be overridden in specific environments using the files
29
+ # in config/environments, which are processed later.
30
+ #
31
+ # config.time_zone = "Central Time (US & Canada)"
32
+ # config.eager_load_paths << Rails.root.join("extras")
33
+
34
+ # Only loads a smaller set of middleware suitable for API only apps.
35
+ # Middleware like session, flash, cookies can be added back manually.
36
+ # Skip views, helpers and assets when generating a new resource.
37
+ config.api_only = true
38
+ end
39
+ end
@@ -0,0 +1,5 @@
1
+ # Set up gems listed in the Gemfile.
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../Gemfile', __dir__)
3
+
4
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
5
+ $LOAD_PATH.unshift File.expand_path('../../../lib', __dir__)
@@ -0,0 +1,10 @@
1
+ development:
2
+ adapter: async
3
+
4
+ test:
5
+ adapter: test
6
+
7
+ production:
8
+ adapter: redis
9
+ url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>
10
+ channel_prefix: dummy_production
@@ -0,0 +1,15 @@
1
+ default: &default
2
+ adapter: postgresql
3
+ encoding: unicode
4
+ pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
5
+
6
+ development:
7
+ <<: *default
8
+ database: infinum-json-api-setup-dev
9
+
10
+ # Warning: The database defined as "test" will be erased and
11
+ # re-generated from your development database when you run "rake".
12
+ # Do not set this db to the same as development or production.
13
+ test:
14
+ <<: *default
15
+ database: infinum-json-api-setup-test
@@ -0,0 +1,5 @@
1
+ # Load the Rails application.
2
+ require_relative 'application'
3
+
4
+ # Initialize the Rails application.
5
+ Rails.application.initialize!