infinum_json_api_setup 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +6 -0
- data/.overcommit.yml +26 -0
- data/.rspec +2 -0
- data/.rubocop.yml +29 -0
- data/.ruby-version +1 -0
- data/.simplecov +3 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +268 -0
- data/README.md +156 -0
- data/Rakefile +1 -0
- data/bin/setup +18 -0
- data/infinum_json_api_setup.gemspec +30 -0
- data/lib/generators/infinum_json_api_setup/install_generator.rb +12 -0
- data/lib/generators/infinum_json_api_setup/templates/config/locales/json_api.en.yml +21 -0
- data/lib/infinum_json_api_setup/error.rb +61 -0
- data/lib/infinum_json_api_setup/json_api/content_negotiation.rb +29 -0
- data/lib/infinum_json_api_setup/json_api/error_handling.rb +49 -0
- data/lib/infinum_json_api_setup/json_api/error_serializer.rb +72 -0
- data/lib/infinum_json_api_setup/json_api/request_parsing.rb +17 -0
- data/lib/infinum_json_api_setup/json_api/responder.rb +31 -0
- data/lib/infinum_json_api_setup/json_api/serializer_options.rb +76 -0
- data/lib/infinum_json_api_setup/rails.rb +28 -0
- data/lib/infinum_json_api_setup/rspec/helpers/request_helper.rb +80 -0
- data/lib/infinum_json_api_setup/rspec/helpers/response_helper.rb +56 -0
- data/lib/infinum_json_api_setup/rspec/matchers/have_empty_data.rb +32 -0
- data/lib/infinum_json_api_setup/rspec/matchers/have_error_pointer.rb +37 -0
- data/lib/infinum_json_api_setup/rspec/matchers/have_resource_count_of.rb +37 -0
- data/lib/infinum_json_api_setup/rspec/matchers/include_all_resource_ids.rb +51 -0
- data/lib/infinum_json_api_setup/rspec/matchers/include_all_resource_ids_sorted.rb +21 -0
- data/lib/infinum_json_api_setup/rspec/matchers/include_all_resource_string_ids.rb +17 -0
- data/lib/infinum_json_api_setup/rspec/matchers/include_error_detail.rb +37 -0
- data/lib/infinum_json_api_setup/rspec/matchers/include_related_resource.rb +42 -0
- data/lib/infinum_json_api_setup/rspec/matchers/json_body_matcher.rb +42 -0
- data/lib/infinum_json_api_setup/rspec/matchers/schema_matchers.rb +29 -0
- data/lib/infinum_json_api_setup/rspec.rb +21 -0
- data/lib/infinum_json_api_setup/version.rb +3 -0
- data/lib/infinum_json_api_setup.rb +16 -0
- data/spec/controllers/api/v1/base_controller_spec.rb +9 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/config/manifest.js +1 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
- data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
- data/spec/dummy/app/controllers/api/v1/base_controller.rb +11 -0
- data/spec/dummy/app/controllers/api/v1/locations_controller.rb +64 -0
- data/spec/dummy/app/controllers/application_controller.rb +2 -0
- data/spec/dummy/app/controllers/concerns/.keep +0 -0
- data/spec/dummy/app/javascript/packs/application.js +15 -0
- data/spec/dummy/app/jobs/application_job.rb +7 -0
- data/spec/dummy/app/mailers/application_mailer.rb +4 -0
- data/spec/dummy/app/models/application_record.rb +3 -0
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/dummy/app/models/location.rb +38 -0
- data/spec/dummy/app/models/location_label.rb +3 -0
- data/spec/dummy/app/policies/application_policy.rb +51 -0
- data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
- data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
- data/spec/dummy/app/web/api/v1/locations/label_serializer.rb +13 -0
- data/spec/dummy/app/web/api/v1/locations/policy.rb +28 -0
- data/spec/dummy/app/web/api/v1/locations/query.rb +12 -0
- data/spec/dummy/app/web/api/v1/locations/serializer.rb +15 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/bin/setup +33 -0
- data/spec/dummy/config/application.rb +39 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/cable.yml +10 -0
- data/spec/dummy/config/database.yml +15 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +65 -0
- data/spec/dummy/config/environments/production.rb +114 -0
- data/spec/dummy/config/environments/test.rb +60 -0
- data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +10 -0
- data/spec/dummy/config/initializers/cors.rb +16 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +6 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +33 -0
- data/spec/dummy/config/locales/json_api.en.yml +21 -0
- data/spec/dummy/config/puma.rb +43 -0
- data/spec/dummy/config/routes.rb +7 -0
- data/spec/dummy/config/storage.yml +34 -0
- data/spec/dummy/config.ru +6 -0
- data/spec/dummy/db/migrate/20210709100750_create_locations.rb +10 -0
- data/spec/dummy/db/migrate/20210714104736_create_location_labels.rb +10 -0
- data/spec/dummy/db/schema.rb +34 -0
- data/spec/dummy/log/.keep +0 -0
- data/spec/dummy/storage/.keep +0 -0
- data/spec/factories/location.rb +11 -0
- data/spec/factories/location_label.rb +6 -0
- data/spec/infinum_json_api_setup/rspec/matchers/have_empty_data_spec.rb +43 -0
- data/spec/infinum_json_api_setup/rspec/matchers/have_error_pointer_spec.rb +43 -0
- data/spec/infinum_json_api_setup/rspec/matchers/have_resource_count_of_spec.rb +43 -0
- data/spec/infinum_json_api_setup/rspec/matchers/include_all_resource_ids_sorted_spec.rb +53 -0
- data/spec/infinum_json_api_setup/rspec/matchers/include_all_resource_ids_spec.rb +49 -0
- data/spec/infinum_json_api_setup/rspec/matchers/include_all_resource_string_ids_spec.rb +49 -0
- data/spec/infinum_json_api_setup/rspec/matchers/include_error_detail_spec.rb +43 -0
- data/spec/infinum_json_api_setup/rspec/matchers/include_related_resource_spec.rb +43 -0
- data/spec/infinum_json_api_setup/rspec/matchers/util/body_parser.rb +30 -0
- data/spec/rails_helper.rb +77 -0
- data/spec/requests/api/v1/content_negotiation_spec.rb +29 -0
- data/spec/requests/api/v1/error_handling_spec.rb +114 -0
- data/spec/requests/api/v1/responder_spec.rb +91 -0
- data/spec/requests/api/v1/serializer_options_spec.rb +46 -0
- data/spec/spec_helper.rb +94 -0
- data/spec/support/factory_bot.rb +7 -0
- data/spec/support/infinum_json_api_setup.rb +1 -0
- data/spec/support/rspec_expectations.rb +5 -0
- data/spec/support/test_helpers/matchers/response.rb +17 -0
- data/spec/support/test_helpers/request.rb +11 -0
- data/spec/support/test_helpers/response.rb +8 -0
- 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,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'
|
data/spec/dummy/Rakefile
ADDED
@@ -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,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
|
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
|
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,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 @@
|
|
1
|
+
<%= yield %>
|
@@ -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,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
|
data/spec/dummy/bin/rake
ADDED
@@ -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,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
|