ctws 0.2.3.beta → 0.3.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +19 -4
- data/app/auth/ctws/authenticate_user.rb +17 -14
- data/app/controllers/concerns/ctws/exception_handler.rb +1 -1
- data/app/controllers/concerns/ctws/response.rb +1 -1
- data/app/controllers/ctws/authentication_controller.rb +2 -2
- data/app/controllers/ctws/users_controller.rb +7 -8
- data/config/initializers/ctws.rb +1 -1
- data/config/locales/ctws_messages_fr.yml +3 -3
- data/lib/ctws.rb +4 -2
- data/lib/ctws/engine.rb +0 -1
- data/lib/ctws/version.rb +4 -1
- data/spec/auth/ctws/authorize_api_request_spec.rb +3 -3
- data/spec/controllers/ctws/ctws_controller_spec.rb +6 -7
- data/spec/dummy/app/models/application_record.rb +1 -0
- data/spec/dummy/app/models/user.rb +11 -0
- data/spec/dummy/config/application.rb +1 -1
- data/spec/dummy/config/initializers/new_framework_defaults.rb +0 -3
- data/spec/dummy/db/schema.rb +12 -19
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/test.log +16539 -0
- data/spec/factories/ctws/ctws_user.rb +4 -4
- data/spec/factories/ctws_min_app_version.rb +2 -2
- data/spec/rails_helper.rb +6 -5
- data/spec/requests/ctws/authentication_spec.rb +7 -7
- data/spec/requests/ctws/users_spec.rb +11 -11
- data/spec/spec_helper.rb +2 -2
- metadata +59 -57
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
FactoryBot.define do
|
2
2
|
factory :ctws_min_app_version, class: Ctws::MinAppVersion do
|
3
3
|
codename { Faker::Lorem.words(3) }
|
4
4
|
description { Faker::Lorem.sentences(1) }
|
@@ -6,4 +6,4 @@ FactoryGirl.define do
|
|
6
6
|
min_version {"#{Faker::Number.digit}.#{Faker::Number.digit}.#{Faker::Number.digit}"}
|
7
7
|
store_uri { Faker::Internet.url }
|
8
8
|
end
|
9
|
-
end
|
9
|
+
end
|
data/spec/rails_helper.rb
CHANGED
@@ -11,7 +11,7 @@ require 'jwt'
|
|
11
11
|
|
12
12
|
# Add additional requires below this line. Rails is not loaded until this point!
|
13
13
|
require 'database_cleaner'
|
14
|
-
require '
|
14
|
+
require 'factory_bot_rails'
|
15
15
|
# Requires supporting ruby files with custom matchers and macros, etc, in
|
16
16
|
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
|
17
17
|
# run as spec files by default. This means that files in spec/support that end
|
@@ -47,9 +47,10 @@ RSpec.configure do |config|
|
|
47
47
|
# examples within a transaction, remove the following line or assign false
|
48
48
|
# instead of true.
|
49
49
|
config.use_transactional_fixtures = true
|
50
|
-
|
51
|
-
# add `
|
52
|
-
config.
|
50
|
+
|
51
|
+
# add `FactoryBot` methods
|
52
|
+
# config.factory_bot.definition_file_paths = ["spec/factories"]
|
53
|
+
config.include FactoryBot::Syntax::Methods
|
53
54
|
|
54
55
|
# start by truncating all the tables but then use the faster transaction strategy the rest of the time.
|
55
56
|
config.before(:suite) do
|
@@ -78,7 +79,7 @@ RSpec.configure do |config|
|
|
78
79
|
# The different available types are documented in the features, such as in
|
79
80
|
# https://relishapp.com/rspec/rspec-rails/docs
|
80
81
|
config.infer_spec_type_from_file_location!
|
81
|
-
|
82
|
+
|
82
83
|
config.include Ctws::RequestSpecHelper
|
83
84
|
config.include Ctws::ControllerSpecHelper
|
84
85
|
# Filter lines from Rails gems in backtraces.
|
@@ -21,27 +21,27 @@ module Ctws
|
|
21
21
|
password: Faker::Internet.password
|
22
22
|
}.to_json
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
# set request.headers to our custom headers
|
26
26
|
# before { allow(request).to receive(:headers).and_return(headers) }
|
27
|
-
|
27
|
+
|
28
28
|
# returns auth token when request is valid
|
29
29
|
context 'When request is valid' do
|
30
30
|
before { post '/ctws/v1/login', params: valid_credentials, headers: headers }
|
31
|
-
|
31
|
+
|
32
32
|
it 'returns an authentication token' do
|
33
33
|
expect(json["data"]["attributes"]["auth_token"]).not_to be_nil
|
34
34
|
end
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
# returns failure message when request is invalid
|
38
38
|
context 'When request is invalid' do
|
39
39
|
before { post '/ctws/v1/login', params: invalid_credentials, headers: headers }
|
40
|
-
|
40
|
+
|
41
41
|
it 'returns a failure message' do
|
42
|
-
expect(json["errors"]["message"]).to match(/Invalid credentials/)
|
42
|
+
expect(json["errors"][0]["message"]).to match(/Invalid credentials/)
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
46
46
|
end
|
47
|
-
end
|
47
|
+
end
|
@@ -7,40 +7,40 @@ module Ctws
|
|
7
7
|
let(:valid_attributes) do
|
8
8
|
attributes_for(:ctws_user, email: ctws_user.email, password_confirmation: ctws_user.password_confirmation)
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
# User signup test suite
|
12
12
|
# http --form POST :3000/ctws/v1/signup email='hola@agusti.cat', password_confirmation: "123456"
|
13
13
|
describe 'POST /ctws/v1/signup' do
|
14
14
|
context 'when valid request' do
|
15
15
|
before { post '/ctws/v1/signup', params: valid_attributes.to_json, headers: headers }
|
16
|
-
|
16
|
+
|
17
17
|
it 'creates a new user' do
|
18
18
|
expect(response).to have_http_status(201)
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
it 'returns success message' do
|
22
|
-
expect(json["data"]["attributes"]["
|
22
|
+
expect(json["data"]["attributes"]["created_at"]).not_to be_nil
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
it 'returns an authentication token' do
|
26
26
|
expect(json["data"]["attributes"]["auth_token"]).not_to be_nil
|
27
27
|
end
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
context 'when invalid request' do
|
31
31
|
before { post '/ctws/v1/signup', params: {}, headers: headers }
|
32
|
-
|
32
|
+
|
33
33
|
it 'does not create a new user' do
|
34
34
|
expect(response).to have_http_status(422)
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
it 'returns failure message' do
|
38
|
-
expect(json["errors"]['message']).not_to be_nil
|
38
|
+
expect(json["errors"][0]['message']).not_to be_nil
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
42
|
-
end
|
42
|
+
end
|
43
43
|
end
|
44
44
|
|
45
45
|
# curl -X POST -H 'Content-Type: application/json' -F "email:agusti.br@coditramuntana.com" -F "password: 123456789" http://localhost:3000/ws/v1/signup
|
46
|
-
# {"success":true,"data":{"message":"Account created successfully","auth_token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxLCJleHAiOjE0OTQ1MTY3NjR9.CWETXkwdlS8jhhu0RHYbYhcBdkpZw1ySoVMCTGgUL6g"}}%
|
46
|
+
# {"success":true,"data":{"message":"Account created successfully","auth_token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxLCJleHAiOjE0OTQ1MTY3NjR9.CWETXkwdlS8jhhu0RHYbYhcBdkpZw1ySoVMCTGgUL6g"}}%
|
data/spec/spec_helper.rb
CHANGED
@@ -2,7 +2,7 @@ ENV['RAILS_ENV'] ||= 'test'
|
|
2
2
|
|
3
3
|
require File.expand_path("../../spec/dummy/config/environment.rb", __FILE__)
|
4
4
|
require 'rspec/rails'
|
5
|
-
require '
|
5
|
+
require 'factory_bot_rails'
|
6
6
|
require 'shoulda-matchers'
|
7
7
|
require 'faker'
|
8
8
|
require 'database_cleaner'
|
@@ -24,4 +24,4 @@ RSpec.configure do |config|
|
|
24
24
|
config.use_transactional_fixtures = true
|
25
25
|
config.infer_base_class_for_anonymous_controllers = false
|
26
26
|
config.order = "random"
|
27
|
-
end
|
27
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ctws
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0.beta
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Agustí B.R.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-05-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -101,19 +101,19 @@ dependencies:
|
|
101
101
|
- !ruby/object:Gem::Version
|
102
102
|
version: '3.6'
|
103
103
|
- !ruby/object:Gem::Dependency
|
104
|
-
name:
|
104
|
+
name: factory_bot_rails
|
105
105
|
requirement: !ruby/object:Gem::Requirement
|
106
106
|
requirements:
|
107
|
-
- - "
|
107
|
+
- - ">="
|
108
108
|
- !ruby/object:Gem::Version
|
109
|
-
version: '
|
109
|
+
version: '0'
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
112
|
version_requirements: !ruby/object:Gem::Requirement
|
113
113
|
requirements:
|
114
|
-
- - "
|
114
|
+
- - ">="
|
115
115
|
- !ruby/object:Gem::Version
|
116
|
-
version: '
|
116
|
+
version: '0'
|
117
117
|
- !ruby/object:Gem::Dependency
|
118
118
|
name: shoulda-matchers
|
119
119
|
requirement: !ruby/object:Gem::Requirement
|
@@ -267,6 +267,7 @@ files:
|
|
267
267
|
- spec/dummy/db/development.sqlite3
|
268
268
|
- spec/dummy/db/migrate/20170622072636_create_users.rb
|
269
269
|
- spec/dummy/db/schema.rb
|
270
|
+
- spec/dummy/db/test.sqlite3
|
270
271
|
- spec/dummy/log/development.log
|
271
272
|
- spec/dummy/log/test.log
|
272
273
|
- spec/dummy/public/404.html
|
@@ -311,76 +312,77 @@ signing_key:
|
|
311
312
|
specification_version: 4
|
312
313
|
summary: Rails gem to be used as Webservice base.
|
313
314
|
test_files:
|
314
|
-
- spec/
|
315
|
-
- spec/
|
316
|
-
- spec/dummy/
|
317
|
-
- spec/dummy/
|
318
|
-
- spec/dummy/
|
319
|
-
- spec/dummy/
|
320
|
-
- spec/dummy/
|
315
|
+
- spec/support/ctws/request_spec_helper.rb
|
316
|
+
- spec/support/ctws/controller_spec_helper.rb
|
317
|
+
- spec/dummy/db/migrate/20170622072636_create_users.rb
|
318
|
+
- spec/dummy/db/schema.rb
|
319
|
+
- spec/dummy/db/development.sqlite3
|
320
|
+
- spec/dummy/db/test.sqlite3
|
321
|
+
- spec/dummy/bin/rake
|
322
|
+
- spec/dummy/bin/setup
|
323
|
+
- spec/dummy/bin/update
|
324
|
+
- spec/dummy/bin/bundle
|
325
|
+
- spec/dummy/bin/rails
|
326
|
+
- spec/dummy/log/development.log
|
327
|
+
- spec/dummy/log/test.log
|
321
328
|
- spec/dummy/config/puma.rb
|
322
329
|
- spec/dummy/config/application.rb
|
330
|
+
- spec/dummy/config/cable.yml
|
331
|
+
- spec/dummy/config/environment.rb
|
332
|
+
- spec/dummy/config/database.yml
|
333
|
+
- spec/dummy/config/environments/development.rb
|
334
|
+
- spec/dummy/config/environments/production.rb
|
335
|
+
- spec/dummy/config/environments/test.rb
|
336
|
+
- spec/dummy/config/spring.rb
|
323
337
|
- spec/dummy/config/routes.rb
|
324
|
-
- spec/dummy/config/
|
325
|
-
- spec/dummy/config/
|
338
|
+
- spec/dummy/config/boot.rb
|
339
|
+
- spec/dummy/config/secrets.yml
|
340
|
+
- spec/dummy/config/initializers/cookies_serializer.rb
|
341
|
+
- spec/dummy/config/initializers/new_framework_defaults.rb
|
342
|
+
- spec/dummy/config/initializers/application_controller_renderer.rb
|
343
|
+
- spec/dummy/config/initializers/wrap_parameters.rb
|
326
344
|
- spec/dummy/config/initializers/backtrace_silencers.rb
|
327
345
|
- spec/dummy/config/initializers/session_store.rb
|
328
|
-
- spec/dummy/config/initializers/wrap_parameters.rb
|
329
|
-
- spec/dummy/config/initializers/new_framework_defaults.rb
|
330
346
|
- spec/dummy/config/initializers/assets.rb
|
331
|
-
- spec/dummy/config/initializers/application_controller_renderer.rb
|
332
|
-
- spec/dummy/config/initializers/cookies_serializer.rb
|
333
347
|
- spec/dummy/config/initializers/filter_parameter_logging.rb
|
334
|
-
- spec/dummy/config/
|
335
|
-
- spec/dummy/config/
|
336
|
-
- spec/dummy/config/environment.rb
|
348
|
+
- spec/dummy/config/initializers/mime_types.rb
|
349
|
+
- spec/dummy/config/initializers/inflections.rb
|
337
350
|
- spec/dummy/config/locales/en.yml
|
338
|
-
- spec/dummy/config
|
339
|
-
- spec/dummy/
|
340
|
-
- spec/dummy/
|
341
|
-
- spec/dummy/
|
342
|
-
- spec/dummy/
|
343
|
-
- spec/dummy/
|
344
|
-
- spec/dummy/
|
351
|
+
- spec/dummy/config.ru
|
352
|
+
- spec/dummy/Rakefile
|
353
|
+
- spec/dummy/public/500.html
|
354
|
+
- spec/dummy/public/apple-touch-icon.png
|
355
|
+
- spec/dummy/public/422.html
|
356
|
+
- spec/dummy/public/favicon.ico
|
357
|
+
- spec/dummy/public/404.html
|
358
|
+
- spec/dummy/public/apple-touch-icon-precomposed.png
|
359
|
+
- spec/dummy/app/jobs/application_job.rb
|
345
360
|
- spec/dummy/app/views/layouts/application.html.erb
|
346
361
|
- spec/dummy/app/views/layouts/mailer.text.erb
|
347
362
|
- spec/dummy/app/views/layouts/mailer.html.erb
|
348
|
-
- spec/dummy/app/helpers/user_helper.rb
|
349
|
-
- spec/dummy/app/helpers/application_helper.rb
|
350
363
|
- spec/dummy/app/mailers/application_mailer.rb
|
364
|
+
- spec/dummy/app/helpers/application_helper.rb
|
365
|
+
- spec/dummy/app/helpers/user_helper.rb
|
366
|
+
- spec/dummy/app/channels/application_cable/channel.rb
|
367
|
+
- spec/dummy/app/channels/application_cable/connection.rb
|
351
368
|
- spec/dummy/app/assets/config/manifest.js
|
352
|
-
- spec/dummy/app/assets/javascripts/application.js
|
353
369
|
- spec/dummy/app/assets/javascripts/cable.js
|
370
|
+
- spec/dummy/app/assets/javascripts/application.js
|
354
371
|
- spec/dummy/app/assets/stylesheets/application.css
|
355
|
-
- spec/dummy/app/controllers/user_controller.rb
|
356
372
|
- spec/dummy/app/controllers/application_controller.rb
|
357
|
-
- spec/dummy/app/
|
358
|
-
- spec/dummy/app/channels/application_cable/connection.rb
|
359
|
-
- spec/dummy/app/jobs/application_job.rb
|
360
|
-
- spec/dummy/app/models/application_record.rb
|
373
|
+
- spec/dummy/app/controllers/user_controller.rb
|
361
374
|
- spec/dummy/app/models/user.rb
|
362
|
-
- spec/dummy/
|
363
|
-
- spec/dummy/bin/bundle
|
364
|
-
- spec/dummy/bin/setup
|
365
|
-
- spec/dummy/bin/rails
|
366
|
-
- spec/dummy/bin/update
|
367
|
-
- spec/dummy/bin/rake
|
368
|
-
- spec/dummy/config.ru
|
369
|
-
- spec/dummy/db/development.sqlite3
|
370
|
-
- spec/dummy/db/migrate/20170622072636_create_users.rb
|
371
|
-
- spec/dummy/db/schema.rb
|
372
|
-
- spec/requests/ctws/users_spec.rb
|
373
|
-
- spec/requests/ctws/min_app_version_spec.rb
|
374
|
-
- spec/requests/ctws/authentication_spec.rb
|
375
|
+
- spec/dummy/app/models/application_record.rb
|
375
376
|
- spec/spec_helper.rb
|
376
|
-
- spec/auth/ctws/authenticate_user_spec.rb
|
377
|
-
- spec/auth/ctws/authorize_api_request_spec.rb
|
378
|
-
- spec/support/ctws/controller_spec_helper.rb
|
379
|
-
- spec/support/ctws/request_spec_helper.rb
|
380
|
-
- spec/rails_helper.rb
|
381
|
-
- spec/factories/ctws_min_app_version.rb
|
382
377
|
- spec/factories/ctws/ctws_user.rb
|
378
|
+
- spec/factories/ctws_min_app_version.rb
|
383
379
|
- spec/controllers/ctws/users_controller_spec.rb
|
384
380
|
- spec/controllers/ctws/ctws_controller_spec.rb
|
385
381
|
- spec/models/ctws/min_app_version_spec.rb
|
386
382
|
- spec/models/ctws/user_spec.rb
|
383
|
+
- spec/requests/ctws/users_spec.rb
|
384
|
+
- spec/requests/ctws/min_app_version_spec.rb
|
385
|
+
- spec/requests/ctws/authentication_spec.rb
|
386
|
+
- spec/rails_helper.rb
|
387
|
+
- spec/auth/ctws/authorize_api_request_spec.rb
|
388
|
+
- spec/auth/ctws/authenticate_user_spec.rb
|