commons_yellowme 0.11.0 → 0.11.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (124) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +10 -0
  3. data/.rspec +3 -0
  4. data/Gemfile +12 -0
  5. data/Gemfile.lock +234 -0
  6. data/bin/test +5 -0
  7. data/commons.gemspec +43 -0
  8. data/lib/commons/version.rb +1 -1
  9. data/spec/commons/authentication/authenticate_by_jwt_spec.rb +37 -0
  10. data/spec/commons/authentication/json_web_token_spec.rb +41 -0
  11. data/spec/commons/concerns/attributes/sex_spec.rb +24 -0
  12. data/spec/commons/concerns/extensions/deleted_spec.rb +42 -0
  13. data/spec/commons/concerns/guard/capitalizable_spec.rb +13 -0
  14. data/spec/commons/concerns/validations/undestroyable_spec.rb +9 -0
  15. data/spec/commons/errors/bad_request_spec.rb +62 -0
  16. data/spec/commons/errors/conflict_spec.rb +62 -0
  17. data/spec/commons/errors/forbidden_spec.rb +62 -0
  18. data/spec/commons/errors/internal_server_error_spec.rb +62 -0
  19. data/spec/commons/errors/invalid_resource_spec.rb +62 -0
  20. data/spec/commons/errors/maintenance_mode_spec.rb +49 -0
  21. data/spec/commons/errors/missing_parameter_spec.rb +49 -0
  22. data/spec/commons/errors/not_unique_spec.rb +62 -0
  23. data/spec/commons/errors/payment_required_spec.rb +62 -0
  24. data/spec/commons/errors/precondition_failed_spec.rb +62 -0
  25. data/spec/commons/errors/resource_not_found_spec.rb +49 -0
  26. data/spec/commons/errors/route_not_found_spec.rb +49 -0
  27. data/spec/commons/errors/unauthorized_spec.rb +62 -0
  28. data/spec/commons/errors/unprocessable_entity_spec.rb +62 -0
  29. data/spec/commons/formatter/e164_phone_spec.rb +155 -0
  30. data/spec/commons/formatter/regex_constants_spec.rb +102 -0
  31. data/spec/commons/formatter/string_utils_spec.rb +19 -0
  32. data/spec/commons/repositories/base_repository_spec.rb +504 -0
  33. data/spec/commons/repositories/catalogs/base_catalog_spec.rb +55 -0
  34. data/spec/commons/serializers/bad_request_spec.rb +46 -0
  35. data/spec/commons/serializers/conflict_spec.rb +46 -0
  36. data/spec/commons/serializers/forbidden_spec.rb +46 -0
  37. data/spec/commons/serializers/internal_server_error_spec.rb +46 -0
  38. data/spec/commons/serializers/invalid_resource_spec.rb +46 -0
  39. data/spec/commons/serializers/maintenance_mode_spec.rb +46 -0
  40. data/spec/commons/serializers/missing_parameter_spec.rb +44 -0
  41. data/spec/commons/serializers/not_unique_spec.rb +46 -0
  42. data/spec/commons/serializers/payment_required_spec.rb +46 -0
  43. data/spec/commons/serializers/precondition_failed_spec.rb +46 -0
  44. data/spec/commons/serializers/route_not_found_spec.rb +46 -0
  45. data/spec/commons/serializers/unauthorized_spec.rb +46 -0
  46. data/spec/commons/serializers/unprocessable_entity_spec.rb +46 -0
  47. data/spec/commons/shared-examples/user_spec.rb +18 -0
  48. data/spec/dummy/.ruby-version +1 -0
  49. data/spec/dummy/Rakefile +6 -0
  50. data/spec/dummy/app/assets/config/manifest.js +2 -0
  51. data/spec/dummy/app/assets/images/.keep +0 -0
  52. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  53. data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
  54. data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
  55. data/spec/dummy/app/controllers/application_controller.rb +2 -0
  56. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  57. data/spec/dummy/app/controllers/miscellaneous_controller.rb +13 -0
  58. data/spec/dummy/app/errors/default_handling.rb +35 -0
  59. data/spec/dummy/app/errors/error_notifier.rb +12 -0
  60. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  61. data/spec/dummy/app/javascript/packs/application.js +15 -0
  62. data/spec/dummy/app/jobs/application_job.rb +7 -0
  63. data/spec/dummy/app/mailers/application_mailer.rb +4 -0
  64. data/spec/dummy/app/models/application_record.rb +3 -0
  65. data/spec/dummy/app/models/catalogs/application_parameter.rb +6 -0
  66. data/spec/dummy/app/models/concerns/.keep +0 -0
  67. data/spec/dummy/app/models/employee.rb +3 -0
  68. data/spec/dummy/app/models/user.rb +16 -0
  69. data/spec/dummy/app/repositories/catalogs/application_parameter_repository.rb +4 -0
  70. data/spec/dummy/app/repositories/employee_repository.rb +2 -0
  71. data/spec/dummy/app/repositories/user_repository.rb +2 -0
  72. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  73. data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
  74. data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
  75. data/spec/dummy/bin/rails +4 -0
  76. data/spec/dummy/bin/rake +4 -0
  77. data/spec/dummy/bin/setup +33 -0
  78. data/spec/dummy/config.ru +5 -0
  79. data/spec/dummy/config/application.rb +29 -0
  80. data/spec/dummy/config/boot.rb +5 -0
  81. data/spec/dummy/config/cable.yml +10 -0
  82. data/spec/dummy/config/database.yml +25 -0
  83. data/spec/dummy/config/environment.rb +5 -0
  84. data/spec/dummy/config/environments/development.rb +62 -0
  85. data/spec/dummy/config/environments/production.rb +112 -0
  86. data/spec/dummy/config/environments/test.rb +48 -0
  87. data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -0
  88. data/spec/dummy/config/initializers/assets.rb +12 -0
  89. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  90. data/spec/dummy/config/initializers/content_security_policy.rb +28 -0
  91. data/spec/dummy/config/initializers/cookies_serializer.rb +5 -0
  92. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  93. data/spec/dummy/config/initializers/inflections.rb +16 -0
  94. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  95. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  96. data/spec/dummy/config/locales/en.yml +33 -0
  97. data/spec/dummy/config/puma.rb +38 -0
  98. data/spec/dummy/config/routes.rb +9 -0
  99. data/spec/dummy/config/spring.rb +6 -0
  100. data/spec/dummy/config/storage.yml +34 -0
  101. data/spec/dummy/db/migrate/20191212233443_create_user.rb +13 -0
  102. data/spec/dummy/db/migrate/20191213072543_create_application_parameters.rb +8 -0
  103. data/spec/dummy/db/migrate/20200101204534_create_employee.rb +8 -0
  104. data/spec/dummy/db/schema.rb +35 -0
  105. data/spec/dummy/lib/assets/.keep +0 -0
  106. data/spec/dummy/log/.keep +0 -0
  107. data/spec/dummy/public/404.html +67 -0
  108. data/spec/dummy/public/422.html +67 -0
  109. data/spec/dummy/public/500.html +66 -0
  110. data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
  111. data/spec/dummy/public/apple-touch-icon.png +0 -0
  112. data/spec/dummy/public/favicon.ico +0 -0
  113. data/spec/factories/catalogs/application_parameters.rb +6 -0
  114. data/spec/factories/employees.rb +6 -0
  115. data/spec/factories/users.rb +7 -0
  116. data/spec/rails_helper.rb +68 -0
  117. data/spec/spec_helper.rb +104 -0
  118. data/spec/support/.DS_Store +0 -0
  119. data/spec/support/shared-examples/capitalizable.rb +16 -0
  120. data/spec/support/shared-examples/deletable.rb +39 -0
  121. data/spec/support/shared-examples/dimorphic.rb +28 -0
  122. data/spec/support/shared-examples/stripable.rb +17 -0
  123. data/spec/support/shared-examples/undestroyable.rb +8 -0
  124. metadata +240 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 72561778339f9301bc276ec516c4bf13d3e98323c93ba4a7bfce41d67dcca9d2
4
- data.tar.gz: 9036b246544ec395c0cfb7829bdbea2b85deb1cbf14b465c8aacf3eaaf56c709
3
+ metadata.gz: 8647af0312b7a12912e0aa7d1dcf10c2a810b17badfadb626cb4e7f548ae3832
4
+ data.tar.gz: a9794e7a96deb33df33d15e2e2b641fa900efcf93ed14661909ae7bd3caf63a9
5
5
  SHA512:
6
- metadata.gz: 563e23f1dfecd7805b3e274327365fe77a789db503cb421e00773d4ada57fb990456cfc5dea53fb0a411d1622074e4ef5985e851f54bce516ae6237d5863c785
7
- data.tar.gz: 87e562f16d6f70f1c870c6db5ade5f5ae3c48601704e7040f7c327f8ad7c3c42b56a345268a68fa2bc1c04965b5ab672512f9d46bd3dc83144eb31afc18c762d
6
+ metadata.gz: c1c7895faba91c9758b80ab388f3f3966068c8c7758cf8ec84dcf79181f80773d9b83cefd923c70e0b578a4047812e3d52703a310c1c72a3de9c77b0e52b39a0
7
+ data.tar.gz: af4f866a77d8fa9295b1add9157c2dc3fdce233f9abb6cec8a30cab999292a83756077c8ae312fda1be8748eccd5c3b051f27d24bf0edca983a72521f3869938
@@ -0,0 +1,10 @@
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ spec/dummy/db/*.sqlite3
5
+ spec/dummy/db/*.sqlite3-journal
6
+ spec/dummy/db/*.sqlite3-*
7
+ spec/dummy/log/*.log
8
+ spec/dummy/storage/
9
+ spec/dummy/tmp/
10
+ coverage
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --require spec_helper
2
+ --require rails_helper
3
+ --color
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
3
+
4
+ # Declare your gem's dependencies in commons.gemspec.
5
+ # Bundler will treat runtime dependencies like base dependencies, and
6
+ # development dependencies will be added by default to the :development group.
7
+ gemspec
8
+
9
+ # Declare any dependencies that are still in development here instead of in
10
+ # your gemspec. These might include edge Rails or gems from your path or
11
+ # Git. Remember to move these dependencies to your gemspec before releasing
12
+ # your gem to rubygems.org.
@@ -0,0 +1,234 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ commons (0.10.3)
5
+ active_model_serializers (~> 0.10.10)
6
+ dry-validation
7
+ json (~> 1.8)
8
+ jwt
9
+ phonelib (~> 0.6.29)
10
+ rails (~> 6.0.1)
11
+ strip_attributes
12
+
13
+ GEM
14
+ remote: https://rubygems.org/
15
+ specs:
16
+ actioncable (6.0.2)
17
+ actionpack (= 6.0.2)
18
+ nio4r (~> 2.0)
19
+ websocket-driver (>= 0.6.1)
20
+ actionmailbox (6.0.2)
21
+ actionpack (= 6.0.2)
22
+ activejob (= 6.0.2)
23
+ activerecord (= 6.0.2)
24
+ activestorage (= 6.0.2)
25
+ activesupport (= 6.0.2)
26
+ mail (>= 2.7.1)
27
+ actionmailer (6.0.2)
28
+ actionpack (= 6.0.2)
29
+ actionview (= 6.0.2)
30
+ activejob (= 6.0.2)
31
+ mail (~> 2.5, >= 2.5.4)
32
+ rails-dom-testing (~> 2.0)
33
+ actionpack (6.0.2)
34
+ actionview (= 6.0.2)
35
+ activesupport (= 6.0.2)
36
+ rack (~> 2.0)
37
+ rack-test (>= 0.6.3)
38
+ rails-dom-testing (~> 2.0)
39
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
40
+ actiontext (6.0.2)
41
+ actionpack (= 6.0.2)
42
+ activerecord (= 6.0.2)
43
+ activestorage (= 6.0.2)
44
+ activesupport (= 6.0.2)
45
+ nokogiri (>= 1.8.5)
46
+ actionview (6.0.2)
47
+ activesupport (= 6.0.2)
48
+ builder (~> 3.1)
49
+ erubi (~> 1.4)
50
+ rails-dom-testing (~> 2.0)
51
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
52
+ active_model_serializers (0.10.10)
53
+ actionpack (>= 4.1, < 6.1)
54
+ activemodel (>= 4.1, < 6.1)
55
+ case_transform (>= 0.2)
56
+ jsonapi-renderer (>= 0.1.1.beta1, < 0.3)
57
+ activejob (6.0.2)
58
+ activesupport (= 6.0.2)
59
+ globalid (>= 0.3.6)
60
+ activemodel (6.0.2)
61
+ activesupport (= 6.0.2)
62
+ activerecord (6.0.2)
63
+ activemodel (= 6.0.2)
64
+ activesupport (= 6.0.2)
65
+ activestorage (6.0.2)
66
+ actionpack (= 6.0.2)
67
+ activejob (= 6.0.2)
68
+ activerecord (= 6.0.2)
69
+ marcel (~> 0.3.1)
70
+ activesupport (6.0.2)
71
+ concurrent-ruby (~> 1.0, >= 1.0.2)
72
+ i18n (>= 0.7, < 2)
73
+ minitest (~> 5.1)
74
+ tzinfo (~> 1.1)
75
+ zeitwerk (~> 2.2)
76
+ builder (3.2.4)
77
+ case_transform (0.2)
78
+ activesupport
79
+ concurrent-ruby (1.1.5)
80
+ crass (1.0.5)
81
+ diff-lcs (1.3)
82
+ docile (1.3.2)
83
+ dry-configurable (0.9.0)
84
+ concurrent-ruby (~> 1.0)
85
+ dry-core (~> 0.4, >= 0.4.7)
86
+ dry-container (0.7.2)
87
+ concurrent-ruby (~> 1.0)
88
+ dry-configurable (~> 0.1, >= 0.1.3)
89
+ dry-core (0.4.9)
90
+ concurrent-ruby (~> 1.0)
91
+ dry-equalizer (0.3.0)
92
+ dry-inflector (0.2.0)
93
+ dry-initializer (3.0.3)
94
+ dry-logic (1.0.5)
95
+ concurrent-ruby (~> 1.0)
96
+ dry-core (~> 0.2)
97
+ dry-equalizer (~> 0.2)
98
+ dry-schema (1.4.3)
99
+ concurrent-ruby (~> 1.0)
100
+ dry-configurable (~> 0.8, >= 0.8.3)
101
+ dry-core (~> 0.4)
102
+ dry-equalizer (~> 0.2)
103
+ dry-initializer (~> 3.0)
104
+ dry-logic (~> 1.0)
105
+ dry-types (~> 1.2)
106
+ dry-types (1.2.2)
107
+ concurrent-ruby (~> 1.0)
108
+ dry-container (~> 0.3)
109
+ dry-core (~> 0.4, >= 0.4.4)
110
+ dry-equalizer (~> 0.3)
111
+ dry-inflector (~> 0.1, >= 0.1.2)
112
+ dry-logic (~> 1.0, >= 1.0.2)
113
+ dry-validation (1.4.2)
114
+ concurrent-ruby (~> 1.0)
115
+ dry-container (~> 0.7, >= 0.7.1)
116
+ dry-core (~> 0.4)
117
+ dry-equalizer (~> 0.2)
118
+ dry-initializer (~> 3.0)
119
+ dry-schema (~> 1.4, >= 1.4.3)
120
+ erubi (1.9.0)
121
+ factory_bot (5.1.1)
122
+ activesupport (>= 4.2.0)
123
+ factory_bot_rails (5.1.1)
124
+ factory_bot (~> 5.1.0)
125
+ railties (>= 4.2.0)
126
+ faker (2.8.1)
127
+ i18n (>= 1.6, < 1.8)
128
+ globalid (0.4.2)
129
+ activesupport (>= 4.2.0)
130
+ i18n (1.7.0)
131
+ concurrent-ruby (~> 1.0)
132
+ json (1.8.6)
133
+ jsonapi-renderer (0.2.2)
134
+ jwt (2.2.1)
135
+ loofah (2.4.0)
136
+ crass (~> 1.0.2)
137
+ nokogiri (>= 1.5.9)
138
+ mail (2.7.1)
139
+ mini_mime (>= 0.1.1)
140
+ marcel (0.3.3)
141
+ mimemagic (~> 0.3.2)
142
+ method_source (0.9.2)
143
+ mimemagic (0.3.4)
144
+ mini_mime (1.0.2)
145
+ mini_portile2 (2.4.0)
146
+ minitest (5.13.0)
147
+ nio4r (2.5.2)
148
+ nokogiri (1.10.7)
149
+ mini_portile2 (~> 2.4.0)
150
+ phonelib (0.6.41)
151
+ rack (2.0.7)
152
+ rack-test (1.1.0)
153
+ rack (>= 1.0, < 3)
154
+ rails (6.0.2)
155
+ actioncable (= 6.0.2)
156
+ actionmailbox (= 6.0.2)
157
+ actionmailer (= 6.0.2)
158
+ actionpack (= 6.0.2)
159
+ actiontext (= 6.0.2)
160
+ actionview (= 6.0.2)
161
+ activejob (= 6.0.2)
162
+ activemodel (= 6.0.2)
163
+ activerecord (= 6.0.2)
164
+ activestorage (= 6.0.2)
165
+ activesupport (= 6.0.2)
166
+ bundler (>= 1.3.0)
167
+ railties (= 6.0.2)
168
+ sprockets-rails (>= 2.0.0)
169
+ rails-dom-testing (2.0.3)
170
+ activesupport (>= 4.2.0)
171
+ nokogiri (>= 1.6)
172
+ rails-html-sanitizer (1.3.0)
173
+ loofah (~> 2.3)
174
+ railties (6.0.2)
175
+ actionpack (= 6.0.2)
176
+ activesupport (= 6.0.2)
177
+ method_source
178
+ rake (>= 0.8.7)
179
+ thor (>= 0.20.3, < 2.0)
180
+ rake (13.0.1)
181
+ rspec-core (3.9.0)
182
+ rspec-support (~> 3.9.0)
183
+ rspec-expectations (3.9.0)
184
+ diff-lcs (>= 1.2.0, < 2.0)
185
+ rspec-support (~> 3.9.0)
186
+ rspec-mocks (3.9.0)
187
+ diff-lcs (>= 1.2.0, < 2.0)
188
+ rspec-support (~> 3.9.0)
189
+ rspec-rails (3.9.0)
190
+ actionpack (>= 3.0)
191
+ activesupport (>= 3.0)
192
+ railties (>= 3.0)
193
+ rspec-core (~> 3.9.0)
194
+ rspec-expectations (~> 3.9.0)
195
+ rspec-mocks (~> 3.9.0)
196
+ rspec-support (~> 3.9.0)
197
+ rspec-support (3.9.0)
198
+ simplecov (0.17.1)
199
+ docile (~> 1.1)
200
+ json (>= 1.8, < 3)
201
+ simplecov-html (~> 0.10.0)
202
+ simplecov-html (0.10.2)
203
+ sprockets (4.0.0)
204
+ concurrent-ruby (~> 1.0)
205
+ rack (> 1, < 3)
206
+ sprockets-rails (3.2.1)
207
+ actionpack (>= 4.0)
208
+ activesupport (>= 4.0)
209
+ sprockets (>= 3.0.0)
210
+ sqlite3 (1.4.1)
211
+ strip_attributes (1.9.0)
212
+ activemodel (>= 3.0, < 7.0)
213
+ thor (1.0.0)
214
+ thread_safe (0.3.6)
215
+ tzinfo (1.2.5)
216
+ thread_safe (~> 0.1)
217
+ websocket-driver (0.7.1)
218
+ websocket-extensions (>= 0.1.0)
219
+ websocket-extensions (0.1.4)
220
+ zeitwerk (2.2.2)
221
+
222
+ PLATFORMS
223
+ ruby
224
+
225
+ DEPENDENCIES
226
+ commons!
227
+ factory_bot_rails (~> 5.1.1)
228
+ faker
229
+ rspec-rails
230
+ simplecov
231
+ sqlite3
232
+
233
+ BUNDLED WITH
234
+ 2.0.2
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ $: << File.expand_path("../test", __dir__)
3
+
4
+ require "bundler/setup"
5
+ require "rails/plugin/test"
@@ -0,0 +1,43 @@
1
+ $:.push File.expand_path("lib", __dir__)
2
+
3
+ # Maintain your gem's version:
4
+ require "commons/version"
5
+
6
+ # Describe your gem and declare its dependencies:
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "commons_yellowme"
9
+ spec.version = Commons::VERSION
10
+ spec.date = '2019-12-10'
11
+ spec.summary = "Commons is Yellowme's Rails APIs utilities gem"
12
+ spec.description = "Commons is Yellowme's Rails APIs utilities gem"
13
+ spec.authors = ["Yellowme"]
14
+ spec.email = 'hola@yellowme.mx'
15
+ spec.homepage = 'https://github.com/yellowme/commons-rails'
16
+ spec.license = 'MIT'
17
+
18
+ #spec.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.md"]
19
+ #spec.files = [
20
+ # "lib/commons.rb",
21
+ # "spec/support/shared-examples/capitalizable.rb",
22
+ # "spec/support/shared-examples/undestroyable.rb",
23
+ # "spec/support/shared-examples/stripable.rb"
24
+ # ]
25
+ spec.files = `git ls-files`.split($/)
26
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
27
+ spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
28
+
29
+
30
+ spec.add_dependency "rails", "~> 6.0.1"
31
+ spec.add_dependency 'json', '~> 1.8'
32
+ spec.add_dependency "active_model_serializers", "~> 0.10.10"
33
+ spec.add_dependency "strip_attributes"
34
+ spec.add_dependency "jwt"
35
+ spec.add_dependency "dry-validation"
36
+ spec.add_dependency "phonelib", "~> 0.6.29"
37
+
38
+ spec.add_development_dependency "sqlite3"
39
+ spec.add_development_dependency "rspec-rails"
40
+ spec.add_development_dependency "factory_bot_rails", "~> 5.1.1"
41
+ spec.add_development_dependency "faker"
42
+ spec.add_development_dependency "simplecov"
43
+ end
@@ -1,3 +1,3 @@
1
1
  module Commons
2
- VERSION = '0.11.0'
2
+ VERSION = '0.11.1'
3
3
  end
@@ -0,0 +1,37 @@
1
+ RSpec.describe Commons::Authentication::AuthenticateByJWT, type: :request do
2
+ describe 'when calling /misc/application_parameters' do
3
+ context 'raises error as an unauthenticated user' do
4
+ subject do
5
+ get "/misc/application_parameters",
6
+ params: {}.to_json,
7
+ headers: {
8
+ 'content-type': 'application/json'
9
+ }
10
+ response
11
+ end
12
+
13
+ it do
14
+ is_expected.to have_http_status(:unauthorized)
15
+ end
16
+ end
17
+
18
+ context 'works ok as an authenticated user' do
19
+ let(:user) { create(:user) }
20
+ let(:jwt) { Commons::Authentication::JSONWebToken.encode(user_id: user.id) }
21
+
22
+ subject do
23
+ get "/misc/application_parameters",
24
+ params: {}.to_json,
25
+ headers: {
26
+ 'content-type': 'application/json',
27
+ 'Authorization': 'Bearer ' + jwt
28
+ }
29
+ response
30
+ end
31
+
32
+ it do
33
+ is_expected.to have_http_status(:ok)
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,41 @@
1
+ RSpec.describe Commons::Authentication::JSONWebToken do
2
+ let(:user) { create(:user) }
3
+ let(:exp) { 24.hours.from_now }
4
+ let(:jwt) { Commons::Authentication::JSONWebToken.encode({ user_id: user.id }, exp) }
5
+
6
+ describe 'decode' do
7
+ subject { Commons::Authentication::JSONWebToken.decode(jwt) }
8
+
9
+ context 'works ok' do
10
+ it do
11
+ expect { subject }.not_to raise_error
12
+ expect(subject[:user_id]).not_to be_nil
13
+ expect(subject[:expires_at]).not_to be_nil
14
+ expect(subject[:user_id]).to eq user.id
15
+ expect(subject[:expires_at]).to eq exp.to_i
16
+ end
17
+ end
18
+
19
+ context 'raises error when invalid' do
20
+ let(:jwt) { Faker::Name.last_name }
21
+ it do
22
+ expect { subject }.to raise_error JWT::DecodeError
23
+ end
24
+ end
25
+ end
26
+
27
+ describe 'encode' do
28
+ subject { Commons::Authentication::JSONWebToken.encode({ user_id: user.id }, exp) }
29
+
30
+ context 'works ok' do
31
+ it { expect { subject }.not_to raise_error }
32
+ it do
33
+ token = Commons::Authentication::JSONWebToken.decode(subject)
34
+ expect(token[:user_id]).not_to be_nil
35
+ expect(token[:user_id]).to eq user.id
36
+ expect(token[:expires_at]).not_to be_nil
37
+ expect(token[:expires_at]).to eq exp.to_i
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,24 @@
1
+ RSpec.describe Commons::Concerns::Attributes::Sex do
2
+ let(:sex) { Commons::Concerns::Attributes::Sex::FEMALE }
3
+ let(:user) { build(:user, name: 'rosa del barrio', last_name: 'hernandez', sex: sex) }
4
+
5
+ subject do
6
+ user
7
+ end
8
+
9
+ describe 'works ok!' do
10
+ it 'when valid data' do
11
+ expect(subject.sex).to eq sex
12
+ expect(subject.female_sex?).to be true
13
+ end
14
+ end
15
+
16
+ describe 'fails' do
17
+ subject do
18
+ user = User.new(sex: 'sex')
19
+ end
20
+ it 'when invalid sex' do
21
+ expect{ subject }.to raise_error(ArgumentError)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,42 @@
1
+ RSpec.describe Commons::Concerns::Extensions::Deleted do
2
+ let(:user) { create(:user) }
3
+
4
+ subject do
5
+ user
6
+ end
7
+
8
+ describe 'works ok!' do
9
+ it 'when existing user' do
10
+ expect(subject.deleted?).to eq false
11
+ end
12
+
13
+ it 'when existing user allows save' do
14
+ subject.name = Faker::Name.first_name
15
+ expect{ subject.save }.not_to raise_error
16
+ end
17
+
18
+ it 'when deleted user' do
19
+ # given
20
+ user = subject
21
+ user = UserRepository.instance.soft_delete!(user.id)
22
+ # do
23
+ expect(user.deleted?).to eq true
24
+ end
25
+
26
+ it 'when deleted user denies save' do
27
+ # given
28
+ user = subject
29
+ user = UserRepository.instance.soft_delete!(user.id)
30
+ user.name = Faker::Name.first_name
31
+ # do
32
+ expect{ user.save }.to raise_error(ActiveRecord::RecordInvalid)
33
+ end
34
+
35
+ it 'when model is not deletable' do
36
+ # given
37
+ employee = Employee.new
38
+ # do
39
+ expect{ employee.deleted? }.to raise_error(ActiveModel::MissingAttributeError)
40
+ end
41
+ end
42
+ end