n_base_rails 0.1.1

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 (139) hide show
  1. checksums.yaml +7 -0
  2. data/.ruby-version +1 -0
  3. data/CHANGELOG.md +5 -0
  4. data/CODE_OF_CONDUCT.md +84 -0
  5. data/Gemfile +8 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +49 -0
  8. data/Rakefile +4 -0
  9. data/bin/console +15 -0
  10. data/bin/setup +8 -0
  11. data/lib/.env +4 -0
  12. data/lib/.rspec +1 -0
  13. data/lib/.rubocop.yml +288 -0
  14. data/lib/.rubocop_disabled.yml +31 -0
  15. data/lib/.rubocop_enabled.yml +0 -0
  16. data/lib/Capfile +46 -0
  17. data/lib/Gemfile +51 -0
  18. data/lib/config/database.yml +24 -0
  19. data/lib/config/deploy/development.rb +85 -0
  20. data/lib/config/deploy/production.rb +63 -0
  21. data/lib/config/deploy/staging.rb +56 -0
  22. data/lib/config/deploy.rb +7 -0
  23. data/lib/config/initializers/devise.rb +315 -0
  24. data/lib/config/locales/devise.en.yml +65 -0
  25. data/lib/config/locales/en.yml +33 -0
  26. data/lib/config/locales/errors.en.yml +57 -0
  27. data/lib/config/routes.rb +26 -0
  28. data/lib/config/settings.yml +22 -0
  29. data/lib/controllers/api/admin/base_controller.rb +5 -0
  30. data/lib/controllers/api/admin/sessions_controller.rb +39 -0
  31. data/lib/controllers/api/admin/users_controller.rb +9 -0
  32. data/lib/controllers/api/v1/base_controller.rb +5 -0
  33. data/lib/controllers/api/v1/sessions_controller.rb +39 -0
  34. data/lib/controllers/api/v1/users_controller.rb +7 -0
  35. data/lib/controllers/application_controller.rb +30 -0
  36. data/lib/controllers/concerns/.DS_Store +0 -0
  37. data/lib/controllers/concerns/.keep +0 -0
  38. data/lib/controllers/concerns/base_concern.rb +9 -0
  39. data/lib/controllers/concerns/json_renderer.rb +76 -0
  40. data/lib/controllers/concerns/pagination.rb +32 -0
  41. data/lib/controllers/concerns/rescue_exception.rb +73 -0
  42. data/lib/db/migrate/20220721091426_devise_create_users.rb +46 -0
  43. data/lib/db/migrate/20230113072522_create_devices.rb +13 -0
  44. data/lib/db/migrate/20230227135020_create_posts.rb +15 -0
  45. data/lib/db/migrate/20230303165318_devise_create_admins.rb +46 -0
  46. data/lib/db/schema.rb +62 -0
  47. data/lib/db/seeds.rb +7 -0
  48. data/lib/generators/n_base_rails/install_generator.rb +42 -0
  49. data/lib/lib/.DS_Store +0 -0
  50. data/lib/lib/active_record_validation/error.rb +33 -0
  51. data/lib/lib/api/error.rb +63 -0
  52. data/lib/lib/json_web_token.rb +13 -0
  53. data/lib/log/.keep +0 -0
  54. data/lib/log/capistrano.log +28367 -0
  55. data/lib/log/development.log +30201 -0
  56. data/lib/log/test.log +11768 -0
  57. data/lib/models/admin.rb +10 -0
  58. data/lib/models/application_record.rb +5 -0
  59. data/lib/models/concerns/.keep +0 -0
  60. data/lib/models/device.rb +11 -0
  61. data/lib/models/post.rb +5 -0
  62. data/lib/models/user.rb +9 -0
  63. data/lib/n_base_rails/version.rb +5 -0
  64. data/lib/n_base_rails.rb +9 -0
  65. data/lib/public/404.html +67 -0
  66. data/lib/public/422.html +67 -0
  67. data/lib/public/500.html +66 -0
  68. data/lib/public/apple-touch-icon-precomposed.png +0 -0
  69. data/lib/public/apple-touch-icon.png +0 -0
  70. data/lib/public/docs/api/admin/definitions/users.yaml +15 -0
  71. data/lib/public/docs/api/admin/paths/index.yaml +29 -0
  72. data/lib/public/docs/api/admin/paths/sessions.yaml +121 -0
  73. data/lib/public/docs/api/admin/paths/users.yaml +39 -0
  74. data/lib/public/docs/api/shared/meta_infos.yaml +41 -0
  75. data/lib/public/docs/api/shared/unauthorized_response.yaml +31 -0
  76. data/lib/public/docs/api/v1/definitions/users.yaml +13 -0
  77. data/lib/public/docs/api/v1/paths/example.yaml +431 -0
  78. data/lib/public/docs/api/v1/paths/index.yaml +28 -0
  79. data/lib/public/docs/api/v1/paths/sessions.yaml +121 -0
  80. data/lib/public/docs/api/v1/paths/users.yaml +24 -0
  81. data/lib/public/favicon.ico +0 -0
  82. data/lib/public/robots.txt +1 -0
  83. data/lib/public/swagger/admin/admin-swagger-initializer.js +24 -0
  84. data/lib/public/swagger/admin/admin.html +19 -0
  85. data/lib/public/swagger/favicon-16x16.png +0 -0
  86. data/lib/public/swagger/favicon-32x32.png +0 -0
  87. data/lib/public/swagger/index.css +16 -0
  88. data/lib/public/swagger/oauth2-redirect.html +79 -0
  89. data/lib/public/swagger/swagger-ui-bundle.js +3 -0
  90. data/lib/public/swagger/swagger-ui-bundle.js.map +1 -0
  91. data/lib/public/swagger/swagger-ui-es-bundle-core.js +2 -0
  92. data/lib/public/swagger/swagger-ui-es-bundle-core.js.map +1 -0
  93. data/lib/public/swagger/swagger-ui-es-bundle.js +3 -0
  94. data/lib/public/swagger/swagger-ui-es-bundle.js.map +1 -0
  95. data/lib/public/swagger/swagger-ui-standalone-preset.js +3 -0
  96. data/lib/public/swagger/swagger-ui-standalone-preset.js.map +1 -0
  97. data/lib/public/swagger/swagger-ui.css +4 -0
  98. data/lib/public/swagger/swagger-ui.css.map +1 -0
  99. data/lib/public/swagger/swagger-ui.js +2 -0
  100. data/lib/public/swagger/swagger-ui.js.map +1 -0
  101. data/lib/public/swagger/v1/app.html +19 -0
  102. data/lib/public/swagger/v1/swagger-initializer.js +25 -0
  103. data/lib/serializers/.DS_Store +0 -0
  104. data/lib/serializers/action_not_allowed_serializer.rb +18 -0
  105. data/lib/serializers/api/.DS_Store +0 -0
  106. data/lib/serializers/api/admin/base_serializer.rb +14 -0
  107. data/lib/serializers/api/admin/hash_serializer.rb +22 -0
  108. data/lib/serializers/api/admin/user_serializer.rb +9 -0
  109. data/lib/serializers/api/v1/base_serializer.rb +14 -0
  110. data/lib/serializers/api/v1/hash_serializer.rb +22 -0
  111. data/lib/serializers/api/v1/user_serializer.rb +9 -0
  112. data/lib/serializers/record_not_found_serializer.rb +28 -0
  113. data/lib/serializers/validation_error_serializer.rb +45 -0
  114. data/lib/services/api/admin/generate_access_token_service.rb +34 -0
  115. data/lib/services/api/admin/generate_refresh_token_service.rb +24 -0
  116. data/lib/services/api/authorize_request_service.rb +35 -0
  117. data/lib/services/api/v1/generate_access_token_service.rb +34 -0
  118. data/lib/services/api/v1/generate_refresh_token_service.rb +24 -0
  119. data/lib/spec/controllers/api/admin/sessions_controller_spec.rb +125 -0
  120. data/lib/spec/controllers/api/admin/users_controller_spec.rb +35 -0
  121. data/lib/spec/controllers/api/v1/sessions_controller_spec.rb +125 -0
  122. data/lib/spec/controllers/api/v1/users_controller_spec.rb +23 -0
  123. data/lib/spec/factories/admins.rb +8 -0
  124. data/lib/spec/factories/devices.rb +7 -0
  125. data/lib/spec/factories/posts.rb +6 -0
  126. data/lib/spec/factories/users.rb +8 -0
  127. data/lib/spec/helpers/request_helpers.rb +7 -0
  128. data/lib/spec/models/admin_spec.rb +9 -0
  129. data/lib/spec/models/device_spec.rb +13 -0
  130. data/lib/spec/models/post_spec.rb +6 -0
  131. data/lib/spec/models/user_spec.rb +9 -0
  132. data/lib/spec/rails_helper.rb +66 -0
  133. data/lib/spec/serializers/api/admin/user_serializer.rb +20 -0
  134. data/lib/spec/serializers/api/v1/user_serializer.rb +20 -0
  135. data/lib/spec/spec_helper.rb +94 -0
  136. data/lib/spec/supports/shared_context.rb +19 -0
  137. data/lib/spec/supports/shared_example/admin_authentication.rb +47 -0
  138. data/lib/spec/supports/shared_example/user_authentication.rb +47 -0
  139. metadata +181 -0
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails_helper"
4
+
5
+ RSpec.describe Api::V1::SessionsController, type: :request do
6
+ describe "GET #show" do
7
+ include_context "user_logged_in"
8
+
9
+ before do
10
+ get api_v1_user_path(user.id), headers: headers
11
+ end
12
+
13
+ context "when get user details success" do
14
+ it "should return status 200" do
15
+ expect(response.status).to eq 200
16
+ expect(json_response["success"]).to eq true
17
+ expect(json_response["data"]["user"].present?).to eq true
18
+ end
19
+ end
20
+
21
+ include_examples :user_authentication
22
+ end
23
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ FactoryBot.define do
4
+ factory :admin do
5
+ email {Faker::Internet.email}
6
+ password {"Aa@123456"}
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ FactoryBot.define do
4
+ factory :device do
5
+ refresh_token {Digest::SHA1.hexdigest([Time.zone.now, rand].join)}
6
+ end
7
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ FactoryBot.define do
4
+ factory :post do
5
+ end
6
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ FactoryBot.define do
4
+ factory :user do
5
+ email {Faker::Internet.email}
6
+ password {"Aa@123456"}
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RequestHelpers
4
+ def json_response
5
+ JSON.parse(response.body)
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails_helper"
4
+
5
+ RSpec.describe Admin, type: :model do
6
+ context "associations" do
7
+ it {is_expected.to have_many(:devices).dependent(:destroy)}
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails_helper"
4
+
5
+ RSpec.describe Device, type: :model do
6
+ context "associations" do
7
+ it {is_expected.to belong_to :resourceable}
8
+ end
9
+
10
+ context "enum" do
11
+ it {should define_enum_for(:platform).with_values({web: 0, ios: 1, android: 2})}
12
+ end
13
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails_helper"
4
+
5
+ RSpec.describe Post, type: :model do
6
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails_helper"
4
+
5
+ RSpec.describe User, type: :model do
6
+ context "associations" do
7
+ it {is_expected.to have_many(:devices).dependent(:destroy)}
8
+ end
9
+ end
@@ -0,0 +1,66 @@
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
+
6
+ ENV["RAILS_ENV"] ||= "test"
7
+ require_relative "../config/environment"
8
+ require Rails.root.join("config/routes.rb")
9
+
10
+ # Prevent database truncation if the environment is production
11
+ abort("The Rails environment is running in production mode!") if Rails.env.production?
12
+ require "rspec/rails"
13
+
14
+ # Add additional requires below this line. Rails is not loaded until this point!
15
+ Dir[Rails.root.join("spec/supports/**/*.rb")].sort.each {|f| require f}
16
+ Dir[Rails.root.join("spec/helpers/**/*.rb")].each {|f| require f}
17
+ # Checks for pending migrations and applies them before tests are run.
18
+ # If you are not using ActiveRecord, you can remove these lines.
19
+ begin
20
+ ActiveRecord::Migration.maintain_test_schema!
21
+ rescue ActiveRecord::PendingMigrationError => e
22
+ puts e.to_s.strip
23
+ exit 1
24
+ end
25
+
26
+ RSpec.configure do |config|
27
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
28
+ config.fixture_path = Rails.root.join("spec/fixtures")
29
+ config.include RequestHelpers
30
+ config.include FactoryBot::Syntax::Methods
31
+ config.include Rails.application.routes.url_helpers
32
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
33
+ # examples within a transaction, remove the following line or assign false
34
+ # instead of true.
35
+ config.use_transactional_fixtures = true
36
+
37
+ # You can uncomment this line to turn off ActiveRecord support entirely.
38
+ # config.use_active_record = false
39
+
40
+ # RSpec Rails can automatically mix in different behaviours to your tests
41
+ # based on their file location, for example enabling you to call `get` and
42
+ # `post` in specs under `spec/controllers`.
43
+ #
44
+ # You can disable this behaviour by removing the line below, and instead
45
+ # explicitly tag your specs with their type, e.g.:
46
+ #
47
+ # RSpec.describe UsersController, type: :controller do
48
+ # # ...
49
+ # end
50
+ #
51
+ # The different available types are documented in the features, such as in
52
+ # https://relishapp.com/rspec/rspec-rails/docs
53
+ config.infer_spec_type_from_file_location!
54
+
55
+ # Filter lines from Rails gems in backtraces.
56
+ config.filter_rails_from_backtrace!
57
+ # arbitrary gems may also be filtered via:
58
+ # config.filter_gems_from_backtrace("gem name")
59
+ end
60
+
61
+ Shoulda::Matchers.configure do |config|
62
+ config.integrate do |with|
63
+ with.test_framework :rspec
64
+ with.library :rails
65
+ end
66
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails_helper"
4
+
5
+ RSpec.describe Api::Admin::UserSerializer, type: :serializer do
6
+ let(:user) {create :user}
7
+
8
+ describe "#users_list" do
9
+ let(:params) {{type: :user_list}}
10
+ let(:serialized_user) {described_class.new(user, params).serializable_hash}
11
+
12
+ context "when get correct attributes" do
13
+ it "should includes all attributes" do
14
+ expect(serialized_user[:id]).to eq user.id
15
+ expect(serialized_user[:email]).to eq user.email
16
+ expect(serialized_user).to include(:email, :id)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails_helper"
4
+
5
+ RSpec.describe Api::V1::UserSerializer, type: :serializer do
6
+ let(:user) {create :user}
7
+
8
+ describe "#user_details" do
9
+ let(:params) {{type: :user_details}}
10
+ let(:serialized_user) {described_class.new(user, params).serializable_hash}
11
+
12
+ context "when get correct attributes" do
13
+ it "should includes all attributes" do
14
+ expect(serialized_user[:id]).to eq user.id
15
+ expect(serialized_user[:email]).to eq user.email
16
+ expect(serialized_user).to include(:email, :id)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,94 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This file was generated by the `rails generate rspec:install` command. Conventionally, all
4
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
5
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
6
+ # this file to always be loaded, without a need to explicitly require it in any
7
+ # files.
8
+ #
9
+ # Given that it is always loaded, you are encouraged to keep this file as
10
+ # light-weight as possible. Requiring heavyweight dependencies from this file
11
+ # will add to the boot time of your test suite on EVERY test run, even for an
12
+ # individual file that may not need all of that loaded. Instead, consider making
13
+ # a separate helper file that requires the additional dependencies and performs
14
+ # the additional setup, and require it from the spec files that actually need
15
+ # it.
16
+ #
17
+ # See https://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
18
+ RSpec.configure do |config|
19
+ # rspec-expectations config goes here. You can use an alternate
20
+ # assertion/expectation library such as wrong or the stdlib/minitest
21
+ # assertions if you prefer.
22
+ config.expect_with :rspec do |expectations|
23
+ # This option will default to `true` in RSpec 4. It makes the `description`
24
+ # and `failure_message` of custom matchers include text for helper methods
25
+ # defined using `chain`, e.g.:
26
+ # be_bigger_than(2).and_smaller_than(4).description
27
+ # # => "be bigger than 2 and smaller than 4"
28
+ # ...rather than:
29
+ # # => "be bigger than 2"
30
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
31
+ end
32
+
33
+ # rspec-mocks config goes here. You can use an alternate test double
34
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
35
+ config.mock_with :rspec do |mocks|
36
+ # Prevents you from mocking or stubbing a method that does not exist on
37
+ # a real object. This is generally recommended, and will default to
38
+ # `true` in RSpec 4.
39
+ mocks.verify_partial_doubles = true
40
+ end
41
+
42
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
43
+ # have no way to turn it off -- the option exists only for backwards
44
+ # compatibility in RSpec 3). It causes shared context metadata to be
45
+ # inherited by the metadata hash of host groups and examples, rather than
46
+ # triggering implicit auto-inclusion in groups with matching metadata.
47
+ config.shared_context_metadata_behavior = :apply_to_host_groups
48
+
49
+ # The settings below are suggested to provide a good initial experience
50
+ # with RSpec, but feel free to customize to your heart's content.
51
+ # # This allows you to limit a spec run to individual examples or groups
52
+ # # you care about by tagging them with `:focus` metadata. When nothing
53
+ # # is tagged with `:focus`, all examples get run. RSpec also provides
54
+ # # aliases for `it`, `describe`, and `context` that include `:focus`
55
+ # # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
56
+ # config.filter_run_when_matching :focus
57
+ #
58
+ # # Allows RSpec to persist some state between runs in order to support
59
+ # # the `--only-failures` and `--next-failure` CLI options. We recommend
60
+ # # you configure your source control system to ignore this file.
61
+ # config.example_status_persistence_file_path = "spec/examples.txt"
62
+ #
63
+ # # Limits the available syntax to the non-monkey patched syntax that is
64
+ # # recommended. For more details, see:
65
+ # # https://relishapp.com/rspec/rspec-core/docs/configuration/zero-monkey-patching-mode
66
+ # config.disable_monkey_patching!
67
+ #
68
+ # # Many RSpec users commonly either run the entire suite or an individual
69
+ # # file, and it's useful to allow more verbose output when running an
70
+ # # individual spec file.
71
+ # if config.files_to_run.one?
72
+ # # Use the documentation formatter for detailed output,
73
+ # # unless a formatter has already been configured
74
+ # # (e.g. via a command-line flag).
75
+ # config.default_formatter = "doc"
76
+ # end
77
+ #
78
+ # # Print the 10 slowest examples and example groups at the
79
+ # # end of the spec run, to help surface which specs are running
80
+ # # particularly slow.
81
+ # config.profile_examples = 10
82
+ #
83
+ # # Run specs in random order to surface order dependencies. If you find an
84
+ # # order dependency and want to debug it, you can fix the order by providing
85
+ # # the seed, which is printed after each run.
86
+ # # --seed 1234
87
+ # config.order = :random
88
+ #
89
+ # # Seed global randomization in this process using the `--seed` CLI option.
90
+ # # Setting this allows you to use `--seed` to deterministically reproduce
91
+ # # test failures related to randomization by passing the same `--seed` value
92
+ # # as the one that triggered the failure.
93
+ # Kernel.srand config.seed
94
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.shared_context "user_logged_in" do
4
+ let!(:user) {create :user, email: "test@example.com", password: "password"}
5
+ let(:headers) {{Authorization: json_response["data"]["access_token"]}}
6
+
7
+ before do
8
+ post api_v1_sign_in_path, params: {user: {email: user.email, password: "password"}}
9
+ end
10
+ end
11
+
12
+ RSpec.shared_context "admin_logged_in" do
13
+ let!(:admin) {create :admin, email: "test@example.com", password: "password"}
14
+ let(:headers) {{Authorization: json_response["data"]["access_token"]}}
15
+
16
+ before do
17
+ post api_admin_sign_in_path, params: {admin: {email: admin.email, password: "password"}}
18
+ end
19
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.shared_examples :admin_authentication do |_action|
4
+ context "when the token is invalid" do
5
+ let(:headers) {{Authorization: "invalid_token"}}
6
+
7
+ it "returns a 401 status" do
8
+ expect(response.status).to eq 401
9
+ expect(json_response["success"]).to eq false
10
+ expect(json_response["errors"][0]["code"]).to eq 1204
11
+ expect(json_response["errors"][0]["message"]).to eq "Invalid Token"
12
+ end
13
+ end
14
+
15
+ context "when the token is invalid type" do
16
+ let(:headers) {{Authorization: JsonWebToken.encode({id: admin.id, resource_type: "invalid_type"})}}
17
+
18
+ it "returns a 401 status" do
19
+ expect(response.status).to eq 401
20
+ expect(json_response["success"]).to eq false
21
+ expect(json_response["errors"][0]["code"]).to eq 1204
22
+ expect(json_response["errors"][0]["message"]).to eq "Invalid Token"
23
+ end
24
+ end
25
+
26
+ context "when the token is invalid author resource" do
27
+ let(:headers) {{Authorization: JsonWebToken.encode({id: 0, resource_type: "admin"})}}
28
+
29
+ it "returns a 401 status" do
30
+ expect(response.status).to eq 401
31
+ expect(json_response["success"]).to eq false
32
+ expect(json_response["errors"][0]["code"]).to eq 1204
33
+ expect(json_response["errors"][0]["message"]).to eq "Invalid Token"
34
+ end
35
+ end
36
+
37
+ context "when the token is invalid device" do
38
+ let(:headers) {{Authorization: JsonWebToken.encode({id: admin.id, resource_type: "admin", device_id: 0})}}
39
+
40
+ it "returns a 401 status" do
41
+ expect(response.status).to eq 401
42
+ expect(json_response["success"]).to eq false
43
+ expect(json_response["errors"][0]["code"]).to eq 1204
44
+ expect(json_response["errors"][0]["message"]).to eq "Invalid Token"
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.shared_examples :user_authentication do |_action|
4
+ context "when the token is invalid" do
5
+ let(:headers) {{Authorization: "invalid_token"}}
6
+
7
+ it "returns a 401 status" do
8
+ expect(response.status).to eq 401
9
+ expect(json_response["success"]).to eq false
10
+ expect(json_response["errors"][0]["code"]).to eq 1204
11
+ expect(json_response["errors"][0]["message"]).to eq "Invalid Token"
12
+ end
13
+ end
14
+
15
+ context "when the token is invalid type" do
16
+ let(:headers) {{Authorization: JsonWebToken.encode({id: user.id, resource_type: "invalid_type"})}}
17
+
18
+ it "returns a 401 status" do
19
+ expect(response.status).to eq 401
20
+ expect(json_response["success"]).to eq false
21
+ expect(json_response["errors"][0]["code"]).to eq 1204
22
+ expect(json_response["errors"][0]["message"]).to eq "Invalid Token"
23
+ end
24
+ end
25
+
26
+ context "when the token is invalid author resource" do
27
+ let(:headers) {{Authorization: JsonWebToken.encode({id: 0, resource_type: "User"})}}
28
+
29
+ it "returns a 401 status" do
30
+ expect(response.status).to eq 401
31
+ expect(json_response["success"]).to eq false
32
+ expect(json_response["errors"][0]["code"]).to eq 1204
33
+ expect(json_response["errors"][0]["message"]).to eq "Invalid Token"
34
+ end
35
+ end
36
+
37
+ context "when the token is invalid device" do
38
+ let(:headers) {{Authorization: JsonWebToken.encode({id: user.id, resource_type: "User", device_id: 0})}}
39
+
40
+ it "returns a 401 status" do
41
+ expect(response.status).to eq 401
42
+ expect(json_response["success"]).to eq false
43
+ expect(json_response["errors"][0]["code"]).to eq 1204
44
+ expect(json_response["errors"][0]["message"]).to eq "Invalid Token"
45
+ end
46
+ end
47
+ end
metadata ADDED
@@ -0,0 +1,181 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: n_base_rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Do Huy Thanh
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-04-08 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: It good for create base shortly
14
+ email:
15
+ - thanhdh@nal.vn
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".ruby-version"
21
+ - CHANGELOG.md
22
+ - CODE_OF_CONDUCT.md
23
+ - Gemfile
24
+ - LICENSE.txt
25
+ - README.md
26
+ - Rakefile
27
+ - bin/console
28
+ - bin/setup
29
+ - lib/.env
30
+ - lib/.rspec
31
+ - lib/.rubocop.yml
32
+ - lib/.rubocop_disabled.yml
33
+ - lib/.rubocop_enabled.yml
34
+ - lib/Capfile
35
+ - lib/Gemfile
36
+ - lib/config/database.yml
37
+ - lib/config/deploy.rb
38
+ - lib/config/deploy/development.rb
39
+ - lib/config/deploy/production.rb
40
+ - lib/config/deploy/staging.rb
41
+ - lib/config/initializers/devise.rb
42
+ - lib/config/locales/devise.en.yml
43
+ - lib/config/locales/en.yml
44
+ - lib/config/locales/errors.en.yml
45
+ - lib/config/routes.rb
46
+ - lib/config/settings.yml
47
+ - lib/controllers/api/admin/base_controller.rb
48
+ - lib/controllers/api/admin/sessions_controller.rb
49
+ - lib/controllers/api/admin/users_controller.rb
50
+ - lib/controllers/api/v1/base_controller.rb
51
+ - lib/controllers/api/v1/sessions_controller.rb
52
+ - lib/controllers/api/v1/users_controller.rb
53
+ - lib/controllers/application_controller.rb
54
+ - lib/controllers/concerns/.DS_Store
55
+ - lib/controllers/concerns/.keep
56
+ - lib/controllers/concerns/base_concern.rb
57
+ - lib/controllers/concerns/json_renderer.rb
58
+ - lib/controllers/concerns/pagination.rb
59
+ - lib/controllers/concerns/rescue_exception.rb
60
+ - lib/db/migrate/20220721091426_devise_create_users.rb
61
+ - lib/db/migrate/20230113072522_create_devices.rb
62
+ - lib/db/migrate/20230227135020_create_posts.rb
63
+ - lib/db/migrate/20230303165318_devise_create_admins.rb
64
+ - lib/db/schema.rb
65
+ - lib/db/seeds.rb
66
+ - lib/generators/n_base_rails/install_generator.rb
67
+ - lib/lib/.DS_Store
68
+ - lib/lib/active_record_validation/error.rb
69
+ - lib/lib/api/error.rb
70
+ - lib/lib/json_web_token.rb
71
+ - lib/log/.keep
72
+ - lib/log/capistrano.log
73
+ - lib/log/development.log
74
+ - lib/log/test.log
75
+ - lib/models/admin.rb
76
+ - lib/models/application_record.rb
77
+ - lib/models/concerns/.keep
78
+ - lib/models/device.rb
79
+ - lib/models/post.rb
80
+ - lib/models/user.rb
81
+ - lib/n_base_rails.rb
82
+ - lib/n_base_rails/version.rb
83
+ - lib/public/404.html
84
+ - lib/public/422.html
85
+ - lib/public/500.html
86
+ - lib/public/apple-touch-icon-precomposed.png
87
+ - lib/public/apple-touch-icon.png
88
+ - lib/public/docs/api/admin/definitions/users.yaml
89
+ - lib/public/docs/api/admin/paths/index.yaml
90
+ - lib/public/docs/api/admin/paths/sessions.yaml
91
+ - lib/public/docs/api/admin/paths/users.yaml
92
+ - lib/public/docs/api/shared/meta_infos.yaml
93
+ - lib/public/docs/api/shared/unauthorized_response.yaml
94
+ - lib/public/docs/api/v1/definitions/users.yaml
95
+ - lib/public/docs/api/v1/paths/example.yaml
96
+ - lib/public/docs/api/v1/paths/index.yaml
97
+ - lib/public/docs/api/v1/paths/sessions.yaml
98
+ - lib/public/docs/api/v1/paths/users.yaml
99
+ - lib/public/favicon.ico
100
+ - lib/public/robots.txt
101
+ - lib/public/swagger/admin/admin-swagger-initializer.js
102
+ - lib/public/swagger/admin/admin.html
103
+ - lib/public/swagger/favicon-16x16.png
104
+ - lib/public/swagger/favicon-32x32.png
105
+ - lib/public/swagger/index.css
106
+ - lib/public/swagger/oauth2-redirect.html
107
+ - lib/public/swagger/swagger-ui-bundle.js
108
+ - lib/public/swagger/swagger-ui-bundle.js.map
109
+ - lib/public/swagger/swagger-ui-es-bundle-core.js
110
+ - lib/public/swagger/swagger-ui-es-bundle-core.js.map
111
+ - lib/public/swagger/swagger-ui-es-bundle.js
112
+ - lib/public/swagger/swagger-ui-es-bundle.js.map
113
+ - lib/public/swagger/swagger-ui-standalone-preset.js
114
+ - lib/public/swagger/swagger-ui-standalone-preset.js.map
115
+ - lib/public/swagger/swagger-ui.css
116
+ - lib/public/swagger/swagger-ui.css.map
117
+ - lib/public/swagger/swagger-ui.js
118
+ - lib/public/swagger/swagger-ui.js.map
119
+ - lib/public/swagger/v1/app.html
120
+ - lib/public/swagger/v1/swagger-initializer.js
121
+ - lib/serializers/.DS_Store
122
+ - lib/serializers/action_not_allowed_serializer.rb
123
+ - lib/serializers/api/.DS_Store
124
+ - lib/serializers/api/admin/base_serializer.rb
125
+ - lib/serializers/api/admin/hash_serializer.rb
126
+ - lib/serializers/api/admin/user_serializer.rb
127
+ - lib/serializers/api/v1/base_serializer.rb
128
+ - lib/serializers/api/v1/hash_serializer.rb
129
+ - lib/serializers/api/v1/user_serializer.rb
130
+ - lib/serializers/record_not_found_serializer.rb
131
+ - lib/serializers/validation_error_serializer.rb
132
+ - lib/services/api/admin/generate_access_token_service.rb
133
+ - lib/services/api/admin/generate_refresh_token_service.rb
134
+ - lib/services/api/authorize_request_service.rb
135
+ - lib/services/api/v1/generate_access_token_service.rb
136
+ - lib/services/api/v1/generate_refresh_token_service.rb
137
+ - lib/spec/controllers/api/admin/sessions_controller_spec.rb
138
+ - lib/spec/controllers/api/admin/users_controller_spec.rb
139
+ - lib/spec/controllers/api/v1/sessions_controller_spec.rb
140
+ - lib/spec/controllers/api/v1/users_controller_spec.rb
141
+ - lib/spec/factories/admins.rb
142
+ - lib/spec/factories/devices.rb
143
+ - lib/spec/factories/posts.rb
144
+ - lib/spec/factories/users.rb
145
+ - lib/spec/helpers/request_helpers.rb
146
+ - lib/spec/models/admin_spec.rb
147
+ - lib/spec/models/device_spec.rb
148
+ - lib/spec/models/post_spec.rb
149
+ - lib/spec/models/user_spec.rb
150
+ - lib/spec/rails_helper.rb
151
+ - lib/spec/serializers/api/admin/user_serializer.rb
152
+ - lib/spec/serializers/api/v1/user_serializer.rb
153
+ - lib/spec/spec_helper.rb
154
+ - lib/spec/supports/shared_context.rb
155
+ - lib/spec/supports/shared_example/admin_authentication.rb
156
+ - lib/spec/supports/shared_example/user_authentication.rb
157
+ homepage: http://rubygems.org/gems/n_base_rails
158
+ licenses:
159
+ - MIT
160
+ metadata:
161
+ source_code_uri: https://github.com/huythanh176/n_base_rails
162
+ post_install_message:
163
+ rdoc_options: []
164
+ require_paths:
165
+ - lib
166
+ required_ruby_version: !ruby/object:Gem::Requirement
167
+ requirements:
168
+ - - ">="
169
+ - !ruby/object:Gem::Version
170
+ version: 2.6.0
171
+ required_rubygems_version: !ruby/object:Gem::Requirement
172
+ requirements:
173
+ - - ">="
174
+ - !ruby/object:Gem::Version
175
+ version: '0'
176
+ requirements: []
177
+ rubygems_version: 3.2.3
178
+ signing_key:
179
+ specification_version: 4
180
+ summary: NBaseRails is the gem to create base for rails api
181
+ test_files: []