rhino_project_core 0.20.0.alpha.0 → 0.20.0.beta.18

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.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +4 -5
  3. data/app/controllers/concerns/rhino/error_handling.rb +0 -2
  4. data/app/controllers/rhino/simple_controller.rb +1 -3
  5. data/app/overrides/devise_token_auth/omniauth_callbacks_controller_override.rb +2 -2
  6. data/app/overrides/devise_token_auth/registrations_controller_override.rb +1 -1
  7. data/lib/commands/rhino_command.rb +59 -0
  8. data/lib/generators/rhino/dev/setup/setup_generator.rb +31 -55
  9. data/lib/generators/rhino/module/module_generator.rb +59 -58
  10. data/lib/generators/rhino/module/templates/engine.rb.tt +19 -0
  11. data/lib/generators/rhino/module/templates/{lib/generators/%namespaced_name%/install/install_generator.rb.tt → install_generator.rb.tt} +1 -1
  12. data/lib/generators/rhino/module/templates/module_tasks.rake.tt +17 -0
  13. data/lib/rhino/engine.rb +14 -40
  14. data/lib/rhino/resource/active_model_extension/properties.rb +0 -2
  15. data/lib/rhino/resource/active_record_extension/properties.rb +1 -1
  16. data/lib/rhino/resource/active_record_extension/properties_describe.rb +0 -2
  17. data/lib/rhino/resource/active_record_extension.rb +0 -2
  18. data/lib/rhino/resource/properties.rb +2 -2
  19. data/lib/rhino/resource/reference.rb +2 -0
  20. data/lib/rhino/resource.rb +1 -2
  21. data/lib/rhino/sieve.rb +0 -1
  22. data/lib/rhino/test_case/controller.rb +9 -20
  23. data/lib/rhino/test_case.rb +0 -1
  24. data/lib/rhino/version.rb +1 -1
  25. data/lib/{rhino_project_core.rb → rhino.rb} +0 -2
  26. data/lib/tasks/rhino.rake +14 -0
  27. metadata +19 -372
  28. data/LICENSE +0 -21
  29. data/lib/commands/rhino/module/coverage_command.rb +0 -44
  30. data/lib/commands/rhino/module/dummy_command.rb +0 -43
  31. data/lib/commands/rhino/module/new_command.rb +0 -34
  32. data/lib/commands/rhino/module/rails_command.rb +0 -43
  33. data/lib/commands/rhino/module/test_command.rb +0 -43
  34. data/lib/generators/rhino/dev/setup/templates/env.root.tt +0 -1
  35. data/lib/generators/rhino/model/model_generator.rb +0 -96
  36. data/lib/generators/rhino/module/USAGE +0 -6
  37. data/lib/generators/rhino/module/templates/%name%.gemspec.tt +0 -24
  38. data/lib/generators/rhino/module/templates/lib/%namespaced_name%/engine.rb.tt +0 -18
  39. data/lib/generators/rhino/module/templates/lib/tasks/%namespaced_name%_tasks.rake.tt +0 -13
  40. data/lib/generators/rhino/module/templates/test/dummy/app/models/user.rb +0 -4
  41. data/lib/generators/rhino/module/templates/test/dummy/config/database.yml +0 -25
  42. data/lib/generators/rhino/module/templates/test/dummy/config/initializers/devise.rb +0 -311
  43. data/lib/generators/rhino/module/templates/test/dummy/config/initializers/devise_token_auth.rb +0 -71
  44. data/lib/generators/rhino/module/templates/test/test_helper.rb +0 -54
  45. data/lib/rhino/resource/active_record_extension/super_admin.rb +0 -25
  46. data/lib/rhino/sieve/geospatial.rb +0 -45
  47. data/lib/rhino/test_case/model.rb +0 -86
@@ -1,311 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Assuming you have not yet modified this file, each configuration option below
4
- # is set to its default value. Note that some are commented out while others
5
- # are not: uncommented lines are intended to protect your configuration from
6
- # breaking changes in upgrades (i.e., in the event that future versions of
7
- # Devise change the default values for those options).
8
- #
9
- # Use this hook to configure devise mailer, warden hooks and so forth.
10
- # Many of these configuration options can be set straight in your model.
11
- Devise.setup do |config|
12
- # The secret key used by Devise. Devise uses this key to generate
13
- # random tokens. Changing this key will render invalid all existing
14
- # confirmation, reset password and unlock tokens in the database.
15
- # Devise will use the `secret_key_base` as its `secret_key`
16
- # by default. You can change it below and use your own secret key.
17
- # config.secret_key = '1b7b3cb6c9406b83c9dee1e2408d312241fcf7228320bd533d8f619531abdc5203f74296f2fc560753c2117f37f8533d841ced6be9ed6c9fe2f913d576db6dd2'
18
-
19
- # ==> Controller configuration
20
- # Configure the parent class to the devise controllers.
21
- # config.parent_controller = 'DeviseController'
22
-
23
- # ==> Mailer Configuration
24
- # Configure the e-mail address which will be shown in Devise::Mailer,
25
- # note that it will be overwritten if you use your own mailer class
26
- # with default "from" parameter.
27
- config.mailer_sender = ENV.fetch("DEFAULT_EMAIL_SENDER", "from@example.com")
28
-
29
- # Configure the class responsible to send e-mails.
30
- # config.mailer = 'Devise::Mailer'
31
-
32
- # Configure the parent class responsible to send e-mails.
33
- # config.parent_mailer = 'ActionMailer::Base'
34
-
35
- # ==> ORM configuration
36
- # Load and configure the ORM. Supports :active_record (default) and
37
- # :mongoid (bson_ext recommended) by default. Other ORMs may be
38
- # available as additional gems.
39
- require 'devise/orm/active_record'
40
-
41
- # ==> Configuration for any authentication mechanism
42
- # Configure which keys are used when authenticating a user. The default is
43
- # just :email. You can configure it to use [:username, :subdomain], so for
44
- # authenticating a user, both parameters are required. Remember that those
45
- # parameters are used only when authenticating and not when retrieving from
46
- # session. If you need permissions, you should implement that in a before filter.
47
- # You can also supply a hash where the value is a boolean determining whether
48
- # or not authentication should be aborted when the value is not present.
49
- # config.authentication_keys = [:email]
50
-
51
- # Configure parameters from the request object used for authentication. Each entry
52
- # given should be a request method and it will automatically be passed to the
53
- # find_for_authentication method and considered in your model lookup. For instance,
54
- # if you set :request_keys to [:subdomain], :subdomain will be used on authentication.
55
- # The same considerations mentioned for authentication_keys also apply to request_keys.
56
- # config.request_keys = []
57
-
58
- # Configure which authentication keys should be case-insensitive.
59
- # These keys will be downcased upon creating or modifying a user and when used
60
- # to authenticate or find a user. Default is :email.
61
- config.case_insensitive_keys = [:email]
62
-
63
- # Configure which authentication keys should have whitespace stripped.
64
- # These keys will have whitespace before and after removed upon creating or
65
- # modifying a user and when used to authenticate or find a user. Default is :email.
66
- config.strip_whitespace_keys = [:email]
67
-
68
- # Tell if authentication through request.params is enabled. True by default.
69
- # It can be set to an array that will enable params authentication only for the
70
- # given strategies, for example, `config.params_authenticatable = [:database]` will
71
- # enable it only for database (email + password) authentication.
72
- # config.params_authenticatable = true
73
-
74
- # Tell if authentication through HTTP Auth is enabled. False by default.
75
- # It can be set to an array that will enable http authentication only for the
76
- # given strategies, for example, `config.http_authenticatable = [:database]` will
77
- # enable it only for database authentication.
78
- # For API-only applications to support authentication "out-of-the-box", you will likely want to
79
- # enable this with :database unless you are using a custom strategy.
80
- # The supported strategies are:
81
- # :database = Support basic authentication with authentication key + password
82
- # config.http_authenticatable = false
83
-
84
- # If 401 status code should be returned for AJAX requests. True by default.
85
- # config.http_authenticatable_on_xhr = true
86
-
87
- # The realm used in Http Basic Authentication. 'Application' by default.
88
- # config.http_authentication_realm = 'Application'
89
-
90
- # It will change confirmation, password recovery and other workflows
91
- # to behave the same regardless if the e-mail provided was right or wrong.
92
- # Does not affect registerable.
93
- # config.paranoid = true
94
-
95
- # By default Devise will store the user in session. You can skip storage for
96
- # particular strategies by setting this option.
97
- # Notice that if you are skipping storage for all authentication paths, you
98
- # may want to disable generating routes to Devise's sessions controller by
99
- # passing skip: :sessions to `devise_for` in your config/routes.rb
100
- config.skip_session_storage = [:http_auth]
101
-
102
- # By default, Devise cleans up the CSRF token on authentication to
103
- # avoid CSRF token fixation attacks. This means that, when using AJAX
104
- # requests for sign in and sign up, you need to get a new CSRF token
105
- # from the server. You can disable this option at your own risk.
106
- # config.clean_up_csrf_token_on_authentication = true
107
-
108
- # When false, Devise will not attempt to reload routes on eager load.
109
- # This can reduce the time taken to boot the app but if your application
110
- # requires the Devise mappings to be loaded during boot time the application
111
- # won't boot properly.
112
- # config.reload_routes = true
113
-
114
- # ==> Configuration for :database_authenticatable
115
- # For bcrypt, this is the cost for hashing the password and defaults to 12. If
116
- # using other algorithms, it sets how many times you want the password to be hashed.
117
- # The number of stretches used for generating the hashed password are stored
118
- # with the hashed password. This allows you to change the stretches without
119
- # invalidating existing passwords.
120
- #
121
- # Limiting the stretches to just one in testing will increase the performance of
122
- # your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use
123
- # a value less than 10 in other environments. Note that, for bcrypt (the default
124
- # algorithm), the cost increases exponentially with the number of stretches (e.g.
125
- # a value of 20 is already extremely slow: approx. 60 seconds for 1 calculation).
126
- config.stretches = Rails.env.test? ? 1 : 12
127
-
128
- # Set up a pepper to generate the hashed password.
129
- # config.pepper = '82ac2dcad675b91cf651a60b4bbc6c44403cd3ef47af621fca84f8e91d7bf0d45a058e6444eb4dbf787c3d9f7b9ed42a86a469d20dc67046816815c6f40cbb6d'
130
-
131
- # Send a notification to the original email when the user's email is changed.
132
- # config.send_email_changed_notification = false
133
-
134
- # Send a notification email when the user's password is changed.
135
- # config.send_password_change_notification = false
136
-
137
- # ==> Configuration for :confirmable
138
- # A period that the user is allowed to access the website even without
139
- # confirming their account. For instance, if set to 2.days, the user will be
140
- # able to access the website for two days without confirming their account,
141
- # access will be blocked just in the third day.
142
- # You can also set it to nil, which will allow the user to access the website
143
- # without confirming their account.
144
- # Default is 0.days, meaning the user cannot access the website without
145
- # confirming their account.
146
- # config.allow_unconfirmed_access_for = 2.days
147
-
148
- # A period that the user is allowed to confirm their account before their
149
- # token becomes invalid. For example, if set to 3.days, the user can confirm
150
- # their account within 3 days after the mail was sent, but on the fourth day
151
- # their account can't be confirmed with the token any more.
152
- # Default is nil, meaning there is no restriction on how long a user can take
153
- # before confirming their account.
154
- # config.confirm_within = 3.days
155
-
156
- # If true, requires any email changes to be confirmed (exactly the same way as
157
- # initial account confirmation) to be applied. Requires additional unconfirmed_email
158
- # db field (see migrations). Until confirmed, new email is stored in
159
- # unconfirmed_email column, and copied to email column on successful confirmation.
160
- config.reconfirmable = true
161
-
162
- # Defines which key will be used when confirming an account
163
- # config.confirmation_keys = [:email]
164
-
165
- # ==> Configuration for :rememberable
166
- # The time the user will be remembered without asking for credentials again.
167
- # config.remember_for = 2.weeks
168
-
169
- # Invalidates all the remember me tokens when the user signs out.
170
- config.expire_all_remember_me_on_sign_out = true
171
-
172
- # If true, extends the user's remember period when remembered via cookie.
173
- # config.extend_remember_period = false
174
-
175
- # Options to be passed to the created cookie. For instance, you can set
176
- # secure: true in order to force SSL only cookies.
177
- # config.rememberable_options = {}
178
-
179
- # ==> Configuration for :validatable
180
- # Range for password length.
181
- config.password_length = 6..128
182
-
183
- # Email regex used to validate email formats. It simply asserts that
184
- # one (and only one) @ exists in the given string. This is mainly
185
- # to give user feedback and not to assert the e-mail validity.
186
- config.email_regexp = /\A[^@\s]+@[^@\s]+\z/
187
-
188
- # ==> Configuration for :timeoutable
189
- # The time you want to timeout the user session without activity. After this
190
- # time the user will be asked for credentials again. Default is 30 minutes.
191
- # config.timeout_in = 30.minutes
192
-
193
- # ==> Configuration for :lockable
194
- # Defines which strategy will be used to lock an account.
195
- # :failed_attempts = Locks an account after a number of failed attempts to sign in.
196
- # :none = No lock strategy. You should handle locking by yourself.
197
- # config.lock_strategy = :failed_attempts
198
-
199
- # Defines which key will be used when locking and unlocking an account
200
- # config.unlock_keys = [:email]
201
-
202
- # Defines which strategy will be used to unlock an account.
203
- # :email = Sends an unlock link to the user email
204
- # :time = Re-enables login after a certain amount of time (see :unlock_in below)
205
- # :both = Enables both strategies
206
- # :none = No unlock strategy. You should handle unlocking by yourself.
207
- # config.unlock_strategy = :both
208
-
209
- # Number of authentication tries before locking an account if lock_strategy
210
- # is failed attempts.
211
- # config.maximum_attempts = 20
212
-
213
- # Time interval to unlock the account if :time is enabled as unlock_strategy.
214
- # config.unlock_in = 1.hour
215
-
216
- # Warn on the last attempt before the account is locked.
217
- # config.last_attempt_warning = true
218
-
219
- # ==> Configuration for :recoverable
220
- #
221
- # Defines which key will be used when recovering the password for an account
222
- # config.reset_password_keys = [:email]
223
-
224
- # Time interval you can reset your password with a reset password key.
225
- # Don't put a too small interval or your users won't have the time to
226
- # change their passwords.
227
- config.reset_password_within = 6.hours
228
-
229
- # When set to false, does not sign a user in automatically after their password is
230
- # reset. Defaults to true, so a user is signed in automatically after a reset.
231
- # config.sign_in_after_reset_password = true
232
-
233
- # ==> Configuration for :encryptable
234
- # Allow you to use another hashing or encryption algorithm besides bcrypt (default).
235
- # You can use :sha1, :sha512 or algorithms from others authentication tools as
236
- # :clearance_sha1, :authlogic_sha512 (then you should set stretches above to 20
237
- # for default behavior) and :restful_authentication_sha1 (then you should set
238
- # stretches to 10, and copy REST_AUTH_SITE_KEY to pepper).
239
- #
240
- # Require the `devise-encryptable` gem when using anything other than bcrypt
241
- # config.encryptor = :sha512
242
-
243
- # ==> Scopes configuration
244
- # Turn scoped views on. Before rendering "sessions/new", it will first check for
245
- # "users/sessions/new". It's turned off by default because it's slower if you
246
- # are using only default views.
247
- # config.scoped_views = false
248
-
249
- # Configure the default scope given to Warden. By default it's the first
250
- # devise role declared in your routes (usually :user).
251
- # config.default_scope = :user
252
-
253
- # Set this configuration to false if you want /users/sign_out to sign out
254
- # only the current scope. By default, Devise signs out all scopes.
255
- # config.sign_out_all_scopes = true
256
-
257
- # ==> Navigation configuration
258
- # Lists the formats that should be treated as navigational. Formats like
259
- # :html, should redirect to the sign in page when the user does not have
260
- # access, but formats like :xml or :json, should return 401.
261
- #
262
- # If you have any extra navigational formats, like :iphone or :mobile, you
263
- # should add them to the navigational formats lists.
264
- #
265
- # The "*/*" below is required to match Internet Explorer requests.
266
- # config.navigational_formats = ['*/*', :html]
267
-
268
- # The default HTTP method used to sign out a resource. Default is :delete.
269
- config.sign_out_via = :delete
270
-
271
- # ==> OmniAuth
272
- # Add a new OmniAuth provider. Check the wiki for more information on setting
273
- # up on your models and hooks.
274
- # config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo'
275
-
276
- # ==> Warden configuration
277
- # If you want to use other strategies, that are not supported by Devise, or
278
- # change the failure app, you can configure them inside the config.warden block.
279
- #
280
- # config.warden do |manager|
281
- # manager.intercept_401 = false
282
- # manager.default_strategies(scope: :user).unshift :some_external_strategy
283
- # end
284
-
285
- # ==> Mountable engine configurations
286
- # When using Devise inside an engine, let's call it `MyEngine`, and this engine
287
- # is mountable, there are some extra configurations to be taken into account.
288
- # The following options are available, assuming the engine is mounted as:
289
- #
290
- # mount MyEngine, at: '/my_engine'
291
- #
292
- # The router that invoked `devise_for`, in the example above, would be:
293
- # config.router_name = :my_engine
294
- #
295
- # When using OmniAuth, Devise cannot automatically set OmniAuth path,
296
- # so you need to do it manually. For the users scope, it would be:
297
- # config.omniauth_path_prefix = '/my_engine/users/auth'
298
-
299
- # ==> Turbolinks configuration
300
- # If your app is using Turbolinks, Turbolinks::Controller needs to be included to make redirection work correctly:
301
- #
302
- # ActiveSupport.on_load(:devise_failure_app) do
303
- # include Turbolinks::Controller
304
- # end
305
-
306
- # ==> Configuration for :registerable
307
-
308
- # When set to false, does not sign a user in automatically after their password is
309
- # changed. Defaults to true, so a user is signed in automatically after changing a password.
310
- # config.sign_in_after_change_password = true
311
- end
@@ -1,71 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- DeviseTokenAuth.setup do |config|
4
- config.cookie_enabled = true
5
- config.cookie_attributes = {
6
- secure: true,
7
- httponly: true,
8
- expires: 1.day,
9
- same_site: "None"
10
- # WARNING: the :domain attribute specifies to whom the cookie will be sent to. It's recommended to leave it empty, so it acts in the most restrictive way as per https://cheatsheetseries.owasp.org/cheatsheets/Session_Management_Cheat_Sheet.html#domain-and-path-attributes
11
- }
12
- # By default the authorization headers will change after each request. The
13
- # client is responsible for keeping track of the changing tokens. Change
14
- # this to false to prevent the Authorization header from changing after
15
- # each request.
16
- config.change_headers_on_each_request = false
17
-
18
- # By default, users will need to re-authenticate after 2 weeks. This setting
19
- # determines how long tokens will remain valid after they are issued.
20
- # config.token_lifespan = 2.weeks
21
-
22
- # Limiting the token_cost to just 4 in testing will increase the performance of
23
- # your test suite dramatically. The possible cost value is within range from 4
24
- # to 31. It is recommended to not use a value more than 10 in other environments.
25
- config.token_cost = Rails.env.test? ? 4 : 10
26
-
27
- # Sets the max number of concurrent devices per user, which is 10 by default.
28
- # After this limit is reached, the oldest tokens will be removed.
29
- # config.max_number_of_devices = 10
30
-
31
- # Sometimes it's necessary to make several requests to the API at the same
32
- # time. In this case, each request in the batch will need to share the same
33
- # auth token. This setting determines how far apart the requests can be while
34
- # still using the same auth token.
35
- # config.batch_request_buffer_throttle = 5.seconds
36
-
37
- # This route will be the prefix for all oauth2 redirect callbacks. For
38
- # example, using the default '/omniauth', the github oauth2 provider will
39
- # redirect successful authentications to '/omniauth/github/callback'
40
- config.omniauth_prefix = "/api/auth/omniauth"
41
-
42
- # By default sending current password is not needed for the password update.
43
- # Uncomment to enforce current_password param to be checked before all
44
- # attribute updates. Set it to :password if you want it to be checked only if
45
- # password is updated.
46
- # config.check_current_password_before_update = :attributes
47
-
48
- # By default we will use callbacks for single omniauth.
49
- # It depends on fields like email, provider and uid.
50
- # config.default_callbacks = true
51
-
52
- # Makes it possible to change the headers names
53
- # config.headers_names = {:'access-token' => 'access-token',
54
- # :'client' => 'client',
55
- # :'expiry' => 'expiry',
56
- # :'uid' => 'uid',
57
- # :'token-type' => 'token-type' }
58
-
59
- # By default, only Bearer Token authentication is implemented out of the box.
60
- # If, however, you wish to integrate with legacy Devise authentication, you can
61
- # do so by enabling this flag. NOTE: This feature is highly experimental!
62
- # config.enable_standard_devise_support = false
63
-
64
- # By default DeviseTokenAuth will not send confirmation email, even when including
65
- # devise confirmable module. If you want to use devise confirmable module and
66
- # send email, set it to true. (This is a setting for compatibility)
67
- # config.send_confirmation_email = true
68
-
69
- config.default_confirm_success_url = "#{ENV['FRONT_END_URL']}/auth/signin"
70
- config.default_password_reset_url = "#{ENV['FRONT_END_URL']}/auth/reset-password"
71
- end
@@ -1,54 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "simplecov" if ENV["COVERAGE"]
4
-
5
- # Configure Rails Environment
6
- ENV["RAILS_ENV"] = "test"
7
-
8
- require_relative "../test/dummy/config/environment"
9
- ActiveRecord::Migrator.migrations_paths = [File.expand_path("../test/dummy/db/migrate", __dir__)]
10
- require "rails/test_help"
11
-
12
- require "rhino/test_case"
13
-
14
- # Filter out the backtrace from minitest while preserving the one from other libraries.
15
- Minitest.backtrace_filter = Minitest::BacktraceFilter.new
16
-
17
- # Load fixtures from the engine
18
- if ActiveSupport::TestCase.respond_to?(:fixture_path=)
19
- ActiveSupport::TestCase.fixture_path = File.expand_path("fixtures", __dir__)
20
- ActionDispatch::IntegrationTest.fixture_path = ActiveSupport::TestCase.fixture_path
21
- ActiveSupport::TestCase.file_fixture_path = File.expand_path("fixtures/files", __dir__)
22
- ActiveSupport::TestCase.fixtures :all
23
- end
24
-
25
- # Load all test helpers
26
- # https://guides.rubyonrails.org/testing.html#eagerly-requiring-helpers
27
- # But we are in an engine so use that root - Rails.root would point to dummy
28
- Dir[Rhino::Engine.root.join("test", "test_helpers", "**", "*.rb")].each { |file| require file }
29
-
30
- class ActiveSupport::TestCase
31
- # Run tests in parallel with specified workers
32
- parallelize(workers: :number_of_processors)
33
-
34
- # make each process running tests a separate command for simple cov.
35
- # in the end, they will all get merged and not overwrite each other's results
36
- # https://github.com/simplecov-ruby/simplecov/issues/718#issuecomment-538201587
37
-
38
- parallelize_setup do |worker|
39
- SimpleCov.command_name "#{SimpleCov.command_name}-#{worker}" if ENV["COVERAGE"]
40
-
41
- # https://guides.rubyonrails.org/active_storage_overview.html#discarding-files-created-during-tests
42
- ActiveStorage::Blob.service.root = "#{ActiveStorage::Blob.service.root}-#{worker}"
43
- end
44
-
45
- parallelize_teardown do |_worker|
46
- SimpleCov.result if ENV["COVERAGE"]
47
-
48
- # https://guides.rubyonrails.org/active_storage_overview.html#cleaning-up-fixtures
49
- FileUtils.rm_rf(ActiveStorage::Blob.services.fetch(:test).root)
50
- end
51
-
52
- # Add more helper methods to be used by all tests here...
53
- include FactoryBot::Syntax::Methods
54
- end
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Rhino
4
- module Resource
5
- module ActiveRecordExtension
6
- module SuperAdmin
7
- extend ActiveSupport::Concern
8
-
9
- class_methods do
10
- def ransackable_attributes(_auth_object = nil)
11
- authorizable_ransackable_attributes & read_properties
12
- end
13
-
14
- def ransackable_associations(_auth_object = nil)
15
- authorizable_ransackable_associations & references.map(&:to_s)
16
- end
17
-
18
- def ransackable_filters(auth_object = nil)
19
- ransackable_attributes(auth_object) + ransackable_associations
20
- end
21
- end
22
- end
23
- end
24
- end
25
- end
@@ -1,45 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Rhino
4
- module Sieve
5
- class Geospatial
6
- def initialize(app)
7
- @app = app
8
- end
9
-
10
- # geospatial={near: {location: { latitude: 41.2565, longitude: -95.9345 }, max_distance: 10, units: 'km'}}
11
- # geospatial={near: {location: 'Omaha, NE, US', max_distance: 10, units: 'km'}}
12
- def resolve(scope, params)
13
- return @app.resolve(scope, params) unless valid?(params)
14
-
15
- @app.resolve(
16
- scope.near(
17
- @location_params,
18
- @near_params[:max_distance],
19
- units: @near_params[:units]
20
- ), params
21
- )
22
- end
23
-
24
- private
25
- def valid?(params) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
26
- @geospatial_params = params[:geospatial]
27
- return false unless @geospatial_params.is_a?(ActionController::Parameters)
28
-
29
- @near_params = @geospatial_params[:near]
30
- return false unless @near_params.is_a?(ActionController::Parameters)
31
-
32
- @location_params = @near_params[:location]
33
- if @location_params.is_a?(String)
34
- @location_params = @near_params[:location]
35
- elsif @location_params.is_a?(ActionController::Parameters) && @location_params[:latitude].present? && @location_params[:longitude].present?
36
- @location_params = [@location_params[:latitude], @location_params[:longitude]]
37
- else
38
- return false
39
- end
40
-
41
- @near_params[:max_distance].present?
42
- end
43
- end
44
- end
45
- end
@@ -1,86 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Rhino
4
- module TestCase
5
- class ModelTest < ActiveSupport::TestCase
6
- protected
7
- def assert_required(attribute)
8
- instance = @model.new
9
- instance[attribute] = nil
10
- assert instance.invalid?
11
- assert_includes instance.errors.messages[attribute], "can't be blank", ":#{attribute} should be required"
12
- end
13
-
14
- def assert_not_required(attribute)
15
- instance = build factory
16
- instance[attribute] = nil
17
- assert instance.valid?, ":#{attribute} should not be required, got errors: #{instance.errors.full_messages}"
18
- end
19
-
20
- def assert_association_required(association)
21
- instance = @model.new
22
- instance.send("#{association}_id=", nil)
23
- assert instance.invalid?
24
- assert_includes instance.errors.messages[association], "must exist", ":#{association} should be required"
25
- end
26
-
27
- def assert_uniqueness(attribute, scope: nil)
28
- instance = create factory
29
- duplicate = build factory, attribute => instance[attribute]
30
- duplicate.send("#{scope}=", instance.send(scope)) if scope.present?
31
- assert duplicate.invalid?, "Should be invalid with duplicate #{attribute}"
32
- assert_includes duplicate.errors.messages[attribute], "has already been taken", ":#{attribute} should be unique"
33
- end
34
-
35
- # association_model is a symbol
36
- def assert_accepts_nested_attributes_for(association_model, association_factory: association_model) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity
37
- association = @model.reflect_on_association(association_model)
38
-
39
- assert association.present?, "association :#{association_model} not found"
40
-
41
- key = if association.macro == :belongs_to || association.macro == :has_one
42
- "#{association_model}_attributes"
43
- else
44
- "#{association_model.to_s.pluralize}_attributes"
45
- end
46
-
47
- success_checker = if association.macro == :belongs_to || association.macro == :has_one
48
- ->(instance) { instance.reload.send(association_model).present? }
49
- else
50
- ->(instance) { instance.reload.send(association_model).any? }
51
- end
52
-
53
- assert @model.new.respond_to?("#{key}="),
54
- "#{@model} doesn't have a #{key} setter method. Probably there's no `accepts_nested_attributes_for :#{association_model}` in #{@model}" # rubocop:disable Layout/LineLength
55
- object = if association_factory.is_a?(Proc)
56
- model_instance = build factory
57
- association_instance = association_factory.call model_instance
58
- model_instance.send("#{key}=", association_instance.attributes)
59
- model_instance
60
- else
61
- build factory, { key => build(association_factory).attributes }
62
- end
63
- assert object.valid?, "Should be valid after assigning nested model attributes, but got errors: #{object.errors.full_messages}"
64
- assert object.save, "Should be able to save after assigning nested model attributes, but got errors: #{object.errors.full_messages}"
65
- assert success_checker.call(object), "Should have a #{association_model} after assigning nested model attributes"
66
- end
67
-
68
- def assert_destroy_association_cascade(association_model, association_factory: association_model) # rubocop:disable Metrics/AbcSize
69
- instance = create factory
70
- association_instance = if association_factory.is_a?(Proc)
71
- association_factory.call(instance)
72
- else
73
- create association, { @model.to_s.underscore => instance }
74
- end
75
- assert instance.reload.send(association_model).any?, "Should have a #{association_model} after creating #{@model}"
76
- assert instance.destroy, "Should be able to destroy #{@model}"
77
- assert_not association_instance.class.exists?(association_instance.id), "Should destroy #{association_model} when destroying #{@model}"
78
- end
79
-
80
- private
81
- def factory
82
- @factory ||= @model.to_s.underscore.to_sym
83
- end
84
- end
85
- end
86
- end