carbonyte 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +0 -3
  3. data/Rakefile +6 -0
  4. data/app/controllers/carbonyte/application_controller.rb +17 -0
  5. data/app/controllers/carbonyte/concerns/correlatable.rb +48 -0
  6. data/app/controllers/carbonyte/concerns/loggable.rb +16 -0
  7. data/app/controllers/carbonyte/concerns/policiable.rb +27 -0
  8. data/app/controllers/carbonyte/concerns/rescuable.rb +93 -47
  9. data/app/controllers/carbonyte/concerns/serializable.rb +48 -0
  10. data/app/interactors/carbonyte/application_interactor.rb +14 -0
  11. data/app/interactors/carbonyte/finders/application_finder.rb +4 -6
  12. data/app/policies/carbonyte/application_policy.rb +55 -0
  13. data/config/routes.rb +1 -0
  14. data/lib/carbonyte.rb +1 -0
  15. data/lib/carbonyte/engine.rb +14 -0
  16. data/lib/carbonyte/initializers.rb +9 -0
  17. data/lib/carbonyte/initializers/lograge.rb +74 -0
  18. data/lib/carbonyte/version.rb +1 -1
  19. data/spec/api/health_spec.rb +12 -0
  20. data/spec/controllers/concerns/rescuable_spec.rb +89 -0
  21. data/spec/controllers/concerns/serializable_spec.rb +69 -0
  22. data/spec/dummy/Rakefile +8 -0
  23. data/spec/dummy/app/controllers/application_controller.rb +7 -0
  24. data/spec/dummy/app/models/application_record.rb +5 -0
  25. data/spec/dummy/app/models/user.rb +5 -0
  26. data/spec/dummy/bin/rails +6 -0
  27. data/spec/dummy/bin/rake +6 -0
  28. data/spec/dummy/bin/setup +35 -0
  29. data/spec/dummy/config.ru +7 -0
  30. data/spec/dummy/config/application.rb +33 -0
  31. data/spec/dummy/config/boot.rb +7 -0
  32. data/spec/dummy/config/database.yml +25 -0
  33. data/spec/dummy/config/environment.rb +7 -0
  34. data/spec/dummy/config/environments/development.rb +64 -0
  35. data/spec/dummy/config/environments/production.rb +114 -0
  36. data/spec/dummy/config/environments/test.rb +51 -0
  37. data/spec/dummy/config/initializers/content_security_policy.rb +29 -0
  38. data/spec/dummy/config/initializers/filter_parameter_logging.rb +6 -0
  39. data/spec/dummy/config/initializers/inflections.rb +17 -0
  40. data/spec/dummy/config/initializers/wrap_parameters.rb +16 -0
  41. data/spec/dummy/config/locales/en.yml +33 -0
  42. data/spec/dummy/config/puma.rb +40 -0
  43. data/spec/dummy/config/routes.rb +5 -0
  44. data/spec/dummy/config/spring.rb +8 -0
  45. data/spec/dummy/config/storage.yml +34 -0
  46. data/spec/dummy/db/migrate/20201007132857_create_users.rb +11 -0
  47. data/spec/dummy/db/schema.rb +21 -0
  48. data/spec/interactors/application_interactor_spec.rb +23 -0
  49. data/spec/interactors/finders/application_finder_spec.rb +60 -0
  50. data/spec/policies/application_policy_spec.rb +20 -0
  51. data/spec/rails_helper.rb +65 -0
  52. data/spec/spec_helper.rb +101 -0
  53. data/spec/support/carbonyte/api_helpers.rb +13 -0
  54. data/spec/support/carbonyte/spec_helper.rb +7 -0
  55. metadata +81 -23
@@ -0,0 +1,21 @@
1
+ # This file is auto-generated from the current state of the database. Instead
2
+ # of editing this file, please use the migrations feature of Active Record to
3
+ # incrementally modify your database, and then regenerate this schema definition.
4
+ #
5
+ # This file is the source Rails uses to define your schema when running `rails
6
+ # db:schema:load`. When creating a new database, `rails db:schema:load` tends to
7
+ # be faster and is potentially less error prone than running all of your
8
+ # migrations from scratch. Old migrations may fail to apply correctly if those
9
+ # migrations use external dependencies or application code.
10
+ #
11
+ # It's strongly recommended that you check this file into your version control system.
12
+
13
+ ActiveRecord::Schema.define(version: 2020_10_07_132857) do
14
+
15
+ create_table "users", force: :cascade do |t|
16
+ t.string "email", null: false
17
+ t.datetime "created_at", precision: 6, null: false
18
+ t.datetime "updated_at", precision: 6, null: false
19
+ end
20
+
21
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Carbonyte::ApplicationInteractor do
4
+ class TestInteractor < Carbonyte::ApplicationInteractor
5
+ def call
6
+ context.this_should_be_me = context.current_interactor
7
+ end
8
+ end
9
+
10
+ let(:interactor) { TestInteractor.new }
11
+
12
+ it 'sets the current_interactor in context before #call' do
13
+ interactor.run
14
+ res = interactor.context
15
+ expect(res.this_should_be_me).to eq(interactor)
16
+ end
17
+
18
+ it 'resets the current_interactor in context to nil after #call' do
19
+ interactor.run
20
+ res = interactor.context
21
+ expect(res.current_interactor).to be_nil
22
+ end
23
+ end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Carbonyte::Finders::ApplicationFinder do
4
+ class TestFinder < Carbonyte::Finders::ApplicationFinder
5
+ ALLOWED_INCLUDES = %i[field1 field2].freeze
6
+
7
+ def can_include?(rel)
8
+ ALLOWED_INCLUDES.include?(rel)
9
+ end
10
+ end
11
+
12
+ let(:params) { {} }
13
+ let(:scope) { double }
14
+ let(:finder) { TestFinder.new(scope: scope, params: params) }
15
+
16
+ before do
17
+ allow(scope).to receive(:limit).and_return(scope)
18
+ allow(scope).to receive(:page).and_return(scope)
19
+ end
20
+
21
+ it 'does not include any relation by default' do
22
+ expect(described_class.new.can_include?(:any)).to be_falsey
23
+ end
24
+
25
+ it 'automatically paginates the result with default values' do
26
+ expect(scope).to receive(:limit).with(25).and_return(scope)
27
+ expect(scope).to receive(:page).with(1).and_return(scope)
28
+ finder.run
29
+ end
30
+
31
+ context 'with include param' do
32
+ let(:params) { { include: 'field1,field2' } }
33
+
34
+ it 'automatically includes relations' do
35
+ expect(scope).to receive(:includes).with(:field1).and_return(scope)
36
+ expect(scope).to receive(:includes).with(:field2).and_return(scope)
37
+ finder.run
38
+ end
39
+ end
40
+
41
+ context 'with sort param' do
42
+ let(:params) { { sort: 'field1,-field2' } }
43
+
44
+ it 'automatically sorts the result' do
45
+ expect(scope).to receive(:order).with(:field1).and_return(scope)
46
+ expect(scope).to receive(:order).with({ field2: :desc }).and_return(scope)
47
+ finder.run
48
+ end
49
+ end
50
+
51
+ context 'with page and limit params' do
52
+ let(:params) { { limit: 10, page: 10 } }
53
+
54
+ it 'paginates the result based on settings' do
55
+ expect(scope).to receive(:limit).with(10).and_return(scope)
56
+ expect(scope).to receive(:page).with(10).and_return(scope)
57
+ finder.run
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Carbonyte::ApplicationPolicy do
4
+ class TestPolicy < Carbonyte::ApplicationPolicy; end
5
+
6
+ let(:policy) { TestPolicy.new(nil, nil) }
7
+ let(:policy_scope) { TestPolicy::Scope.new(nil, double(all: [])) }
8
+
9
+ it 'allows all default actions by default' do
10
+ expect(policy.index?).to be_truthy
11
+ expect(policy.show?).to be_truthy
12
+ expect(policy.create?).to be_truthy
13
+ expect(policy.update?).to be_truthy
14
+ expect(policy.destroy?).to be_truthy
15
+ end
16
+
17
+ it 'provides a default scope by default' do
18
+ expect(policy_scope.resolve).to eq([])
19
+ end
20
+ end
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
4
+ require 'spec_helper'
5
+ require 'support/carbonyte/spec_helper'
6
+
7
+ require 'rspec/rails'
8
+ # Add additional requires below this line. Rails is not loaded until this point!
9
+
10
+ # Requires supporting ruby files with custom matchers and macros, etc, in
11
+ # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
12
+ # run as spec files by default. This means that files in spec/support that end
13
+ # in _spec.rb will both be required and run as specs, causing the specs to be
14
+ # run twice. It is recommended that you do not name files matching this glob to
15
+ # end with _spec.rb. You can configure this pattern with the --pattern
16
+ # option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
17
+ #
18
+ # The following line is provided for convenience purposes. It has the downside
19
+ # of increasing the boot-up time by auto-requiring all files in the support
20
+ # directory. Alternatively, in the individual `*_spec.rb` files, manually
21
+ # require only the support files necessary.
22
+ #
23
+ Dir[File.dirname(__FILE__) + '/support/**/*.rb'].sort.each { |f| require f }
24
+
25
+ # Checks for pending migrations and applies them before tests are run.
26
+ # If you are not using ActiveRecord, you can remove these lines.
27
+ begin
28
+ ActiveRecord::Migration.maintain_test_schema!
29
+ rescue ActiveRecord::PendingMigrationError => e
30
+ puts e.to_s.strip
31
+ exit 1
32
+ end
33
+
34
+ RSpec.configure do |config|
35
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
36
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
37
+
38
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
39
+ # examples within a transaction, remove the following line or assign false
40
+ # instead of true.
41
+ config.use_transactional_fixtures = true
42
+
43
+ # You can uncomment this line to turn off ActiveRecord support entirely.
44
+ # config.use_active_record = false
45
+
46
+ # RSpec Rails can automatically mix in different behaviours to your tests
47
+ # based on their file location, for example enabling you to call `get` and
48
+ # `post` in specs under `spec/controllers`.
49
+ #
50
+ # You can disable this behaviour by removing the line below, and instead
51
+ # explicitly tag your specs with their type, e.g.:
52
+ #
53
+ # RSpec.describe UsersController, type: :controller do
54
+ # # ...
55
+ # end
56
+ #
57
+ # The different available types are documented in the features, such as in
58
+ # https://relishapp.com/rspec/rspec-rails/docs
59
+ config.infer_spec_type_from_file_location!
60
+
61
+ # Filter lines from Rails gems in backtraces.
62
+ config.filter_rails_from_backtrace!
63
+ # arbitrary gems may also be filtered via:
64
+ # config.filter_gems_from_backtrace("gem name")
65
+ end
@@ -0,0 +1,101 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'simplecov'
4
+
5
+ SimpleCov.start do
6
+ minimum_coverage 90
7
+ minimum_coverage_by_file 85
8
+ end
9
+
10
+ # This file was generated by the `rails generate rspec:install` command. Conventionally, all
11
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
12
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
13
+ # this file to always be loaded, without a need to explicitly require it in any
14
+ # files.
15
+ #
16
+ # Given that it is always loaded, you are encouraged to keep this file as
17
+ # light-weight as possible. Requiring heavyweight dependencies from this file
18
+ # will add to the boot time of your test suite on EVERY test run, even for an
19
+ # individual file that may not need all of that loaded. Instead, consider making
20
+ # a separate helper file that requires the additional dependencies and performs
21
+ # the additional setup, and require it from the spec files that actually need
22
+ # it.
23
+ #
24
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
25
+ RSpec.configure do |config|
26
+ # rspec-expectations config goes here. You can use an alternate
27
+ # assertion/expectation library such as wrong or the stdlib/minitest
28
+ # assertions if you prefer.
29
+ config.expect_with :rspec do |expectations|
30
+ # This option will default to `true` in RSpec 4. It makes the `description`
31
+ # and `failure_message` of custom matchers include text for helper methods
32
+ # defined using `chain`, e.g.:
33
+ # be_bigger_than(2).and_smaller_than(4).description
34
+ # # => "be bigger than 2 and smaller than 4"
35
+ # ...rather than:
36
+ # # => "be bigger than 2"
37
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
38
+ end
39
+
40
+ # rspec-mocks config goes here. You can use an alternate test double
41
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
42
+ config.mock_with :rspec do |mocks|
43
+ # Prevents you from mocking or stubbing a method that does not exist on
44
+ # a real object. This is generally recommended, and will default to
45
+ # `true` in RSpec 4.
46
+ mocks.verify_partial_doubles = true
47
+ end
48
+
49
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
50
+ # have no way to turn it off -- the option exists only for backwards
51
+ # compatibility in RSpec 3). It causes shared context metadata to be
52
+ # inherited by the metadata hash of host groups and examples, rather than
53
+ # triggering implicit auto-inclusion in groups with matching metadata.
54
+ config.shared_context_metadata_behavior = :apply_to_host_groups
55
+
56
+ # This allows you to limit a spec run to individual examples or groups
57
+ # you care about by tagging them with `:focus` metadata. When nothing
58
+ # is tagged with `:focus`, all examples get run. RSpec also provides
59
+ # aliases for `it`, `describe`, and `context` that include `:focus`
60
+ # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
61
+ # config.filter_run_when_matching :focus
62
+
63
+ # Allows RSpec to persist some state between runs in order to support
64
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
65
+ # you configure your source control system to ignore this file.
66
+ # config.example_status_persistence_file_path = "spec/examples.txt"
67
+
68
+ # Limits the available syntax to the non-monkey patched syntax that is
69
+ # recommended. For more details, see:
70
+ # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
71
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
72
+ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
73
+ # config.disable_monkey_patching!
74
+
75
+ # Many RSpec users commonly either run the entire suite or an individual
76
+ # file, and it's useful to allow more verbose output when running an
77
+ # individual spec file.
78
+ # if config.files_to_run.one?
79
+ # # Use the documentation formatter for detailed output,
80
+ # # unless a formatter has already been configured
81
+ # # (e.g. via a command-line flag).
82
+ # config.default_formatter = 'doc'
83
+ # end
84
+
85
+ # Print the 10 slowest examples and example groups at the
86
+ # end of the spec run, to help surface which specs are running
87
+ # particularly slow.
88
+ # config.profile_examples = 10
89
+
90
+ # Run specs in random order to surface order dependencies. If you find an
91
+ # order dependency and want to debug it, you can fix the order by providing
92
+ # the seed, which is printed after each run.
93
+ # --seed 1234
94
+ # config.order = :random
95
+
96
+ # Seed global randomization in this process using the `--seed` CLI option.
97
+ # Setting this allows you to use `--seed` to deterministically reproduce
98
+ # test failures related to randomization by passing the same `--seed` value
99
+ # as the one that triggered the failure.
100
+ # Kernel.srand config.seed
101
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ApiHelpers
4
+ def parsed_response
5
+ JSON.parse(response.body)
6
+ end
7
+ end
8
+
9
+ RSpec.configure do |config|
10
+ %i[request controller].each do |type|
11
+ config.include ApiHelpers, type: type
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ ENV['RAILS_ENV'] ||= 'test'
4
+
5
+ require File.expand_path('../../dummy/config/environment', __dir__)
6
+ # Prevent database truncation if the environment is production
7
+ abort('The Rails environment is running in production mode!') if Rails.env.production?
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carbonyte
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - iMacTia
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-11 00:00:00.000000000 Z
11
+ date: 2020-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: interactor-rails
@@ -38,6 +38,34 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: lograge
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.11'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.11'
55
+ - !ruby/object:Gem::Dependency
56
+ name: logstash-event
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.2'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.2'
41
69
  - !ruby/object:Gem::Dependency
42
70
  name: pundit
43
71
  requirement: !ruby/object:Gem::Requirement
@@ -73,33 +101,19 @@ dependencies:
73
101
  - !ruby/object:Gem::Version
74
102
  version: 6.0.3.2
75
103
  - !ruby/object:Gem::Dependency
76
- name: inch
104
+ name: request_store
77
105
  requirement: !ruby/object:Gem::Requirement
78
106
  requirements:
79
107
  - - "~>"
80
108
  - !ruby/object:Gem::Version
81
- version: 0.8.0
82
- type: :development
83
- prerelease: false
84
- version_requirements: !ruby/object:Gem::Requirement
85
- requirements:
86
- - - "~>"
87
- - !ruby/object:Gem::Version
88
- version: 0.8.0
89
- - !ruby/object:Gem::Dependency
90
- name: rspec-rails
91
- requirement: !ruby/object:Gem::Requirement
92
- requirements:
93
- - - "~>"
94
- - !ruby/object:Gem::Version
95
- version: '4.0'
96
- type: :development
109
+ version: '1.5'
110
+ type: :runtime
97
111
  prerelease: false
98
112
  version_requirements: !ruby/object:Gem::Requirement
99
113
  requirements:
100
114
  - - "~>"
101
115
  - !ruby/object:Gem::Version
102
- version: '4.0'
116
+ version: '1.5'
103
117
  description: Carbonyte is the core of great Microservices-oriented Architectures.
104
118
  email:
105
119
  - giuffrida.mattia@gmail.com
@@ -110,36 +124,80 @@ files:
110
124
  - README.md
111
125
  - Rakefile
112
126
  - app/controllers/carbonyte/application_controller.rb
127
+ - app/controllers/carbonyte/concerns/correlatable.rb
128
+ - app/controllers/carbonyte/concerns/loggable.rb
129
+ - app/controllers/carbonyte/concerns/policiable.rb
113
130
  - app/controllers/carbonyte/concerns/rescuable.rb
131
+ - app/controllers/carbonyte/concerns/serializable.rb
114
132
  - app/interactors/carbonyte/application_interactor.rb
115
133
  - app/interactors/carbonyte/finders/application_finder.rb
116
134
  - app/models/carbonyte/application_record.rb
135
+ - app/policies/carbonyte/application_policy.rb
117
136
  - app/serializers/carbonyte/application_serializer.rb
118
137
  - config/routes.rb
119
138
  - lib/carbonyte.rb
120
139
  - lib/carbonyte/engine.rb
140
+ - lib/carbonyte/initializers.rb
141
+ - lib/carbonyte/initializers/lograge.rb
121
142
  - lib/carbonyte/version.rb
122
143
  - lib/tasks/carbonyte_tasks.rake
144
+ - spec/api/health_spec.rb
145
+ - spec/controllers/concerns/rescuable_spec.rb
146
+ - spec/controllers/concerns/serializable_spec.rb
147
+ - spec/dummy/Rakefile
148
+ - spec/dummy/app/controllers/application_controller.rb
149
+ - spec/dummy/app/models/application_record.rb
150
+ - spec/dummy/app/models/user.rb
151
+ - spec/dummy/bin/rails
152
+ - spec/dummy/bin/rake
153
+ - spec/dummy/bin/setup
154
+ - spec/dummy/config.ru
155
+ - spec/dummy/config/application.rb
156
+ - spec/dummy/config/boot.rb
157
+ - spec/dummy/config/database.yml
158
+ - spec/dummy/config/environment.rb
159
+ - spec/dummy/config/environments/development.rb
160
+ - spec/dummy/config/environments/production.rb
161
+ - spec/dummy/config/environments/test.rb
162
+ - spec/dummy/config/initializers/content_security_policy.rb
163
+ - spec/dummy/config/initializers/filter_parameter_logging.rb
164
+ - spec/dummy/config/initializers/inflections.rb
165
+ - spec/dummy/config/initializers/wrap_parameters.rb
166
+ - spec/dummy/config/locales/en.yml
167
+ - spec/dummy/config/puma.rb
168
+ - spec/dummy/config/routes.rb
169
+ - spec/dummy/config/spring.rb
170
+ - spec/dummy/config/storage.yml
171
+ - spec/dummy/db/migrate/20201007132857_create_users.rb
172
+ - spec/dummy/db/schema.rb
173
+ - spec/interactors/application_interactor_spec.rb
174
+ - spec/interactors/finders/application_finder_spec.rb
175
+ - spec/policies/application_policy_spec.rb
176
+ - spec/rails_helper.rb
177
+ - spec/spec_helper.rb
178
+ - spec/support/carbonyte/api_helpers.rb
179
+ - spec/support/carbonyte/spec_helper.rb
123
180
  homepage: https://github.com/iMacTia/carbonyte
124
181
  licenses:
125
- - Copyright
182
+ - MIT
126
183
  metadata: {}
127
184
  post_install_message:
128
185
  rdoc_options: []
129
186
  require_paths:
130
187
  - lib
188
+ - spec/support
131
189
  required_ruby_version: !ruby/object:Gem::Requirement
132
190
  requirements:
133
191
  - - ">="
134
192
  - !ruby/object:Gem::Version
135
- version: '0'
193
+ version: 2.7.0
136
194
  required_rubygems_version: !ruby/object:Gem::Requirement
137
195
  requirements:
138
196
  - - ">="
139
197
  - !ruby/object:Gem::Version
140
198
  version: '0'
141
199
  requirements: []
142
- rubygems_version: 3.1.2
200
+ rubygems_version: 3.1.4
143
201
  signing_key:
144
202
  specification_version: 4
145
203
  summary: Build Microservices-oriented Architectures with ease