tramway-api 1.8.7 → 2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7460f1d97abb9ea3e24e8cf6b5e3bb81fece303364dd906f4a42617ae92ed08b
4
- data.tar.gz: 772e32b2c3c73a501b49fb2a166d99256558e221f71254d47094d6ec2d8d9b10
3
+ metadata.gz: 1d0caeaa1462195c9c7d270d716a7970ce658f6ffbfaf139662bc3c0e382630c
4
+ data.tar.gz: 7c7cef68dfa06f0cb0dcdfd530e28c0a41b42515bb175a9978946ed13c6b7600
5
5
  SHA512:
6
- metadata.gz: d706c1f376c0300a3c8ae6b2a7af4e3ec987b67960301d6aa52a5d69d4475c6e2910d854d91671a5584aebeffed2f3560780d55cd7afc6fb3a13c05041c42987
7
- data.tar.gz: c3e35375b7597d57cc2d96cb6cc37cfd1084327afb23a1931d9a19ca93314b60f8d5f24335f7747f7fdf388860c28213c7c5895c914bddd1b72b748da853278b
6
+ metadata.gz: f5659a1cad529417c3bdccc5766167690654008e0c2e903e6efb638277c4d7fe161ec9bfcb18a91088c3ba58a5204a3f13efbfd5fa6fef4a7746e03e60f6a872
7
+ data.tar.gz: 738e22ab29825ec1ebe351c5a3e5c64b2e92a87fee4e84e8285c16b31a664faefc0ec75a67e65c9c5c8705df2b59d24106c4bd26454abd68dedee5b0b9ec337f
data/README.md CHANGED
@@ -257,7 +257,7 @@ RSpec.describe 'Post creating user', type: :feature do
257
257
 
258
258
  it 'returns created status' do
259
259
  post '/api/v1/user', params: { user: attributes }
260
- expect(response.status).to eq 201
260
+ expect(response[:status]).to eq 201
261
261
  end
262
262
 
263
263
  it 'returns no errors' do
@@ -275,17 +275,17 @@ end
275
275
  require 'rails_helper'
276
276
 
277
277
  RSpec.describe 'Post generate token', type: :feature do
278
- describe 'POST /api/v1/user_token' do
278
+ describe 'POST /api/v1/user_tokens' do
279
279
  let(:user) { create :user, password: '123456789' }
280
280
 
281
281
  it 'returns created status' do
282
- post '/api/v1/user_token', params: { auth: { login: user.email, password: '123456789' } }
282
+ post '/api/v1/user_tokens', params: { auth: { login: user.email, password: '123456789' } }
283
283
 
284
- expect(response.status).to eq 201
284
+ expect(response[:status]).to eq 201
285
285
  end
286
286
 
287
287
  it 'returns token' do
288
- post '/api/v1/user_token', params: { auth: { login: user.email, password: '123456789' } }
288
+ post '/api/v1/user_tokens', params: { auth: { login: user.email, password: '123456789' } }
289
289
 
290
290
  expect(json_response[:auth_token].present?).to be_truthy
291
291
  expect(json_response[:user]).to include_json({ email: user.email, uuid: user.uuid })
@@ -372,13 +372,13 @@ Then write test:
372
372
  it 'returns status' do
373
373
  get '/api/v1/records', params: { model: 'User' }, headers: headers
374
374
 
375
- expect(response.status).to eq 200
375
+ expect(response[:status]).to eq 200
376
376
  end
377
377
 
378
378
  it 'returns needed count' do
379
379
  get '/api/v1/records', params: { model: 'User' }, headers: headers
380
380
 
381
- expect(json_response[:data].size).to eq User.active.count
381
+ expect(json_response[:data].size).to eq User.count
382
382
  end
383
383
  ```
384
384
 
@@ -455,7 +455,7 @@ RSpec.describe 'Post generate token', type: :feature do
455
455
  it 'returns created status' do
456
456
  post '/api/v1/user_token', params: { auth: { login: user.email, password: '123456789' } }
457
457
 
458
- expect(response.status).to eq 201
458
+ expect(response[:status]).to eq 201
459
459
  end
460
460
 
461
461
  it 'returns token' do
@@ -6,37 +6,6 @@ module Tramway
6
6
  include ::Knock::Authenticable
7
7
  protect_from_forgery with: :null_session, if: proc { |c| c.request.format == 'application/json' }
8
8
  rescue_from ActiveRecord::RecordNotFound, with: :not_found if Rails.env.production?
9
- before_action :load_application
10
-
11
- def load_application
12
- if engine_loaded(request).present?
13
- build_application_with_engine engine_loaded request
14
- elsif application_class(request).present?
15
- @application = application_class(request).camelize.constantize.first
16
- else
17
- @application = application_object request
18
- end
19
- end
20
-
21
- private
22
-
23
- def build_application_with_engine(engine_loaded)
24
- engine_module = "::Tramway::#{engine_loaded.camelize}".constantize
25
- @application = "#{engine_module}::#{engine_module.application.to_s.camelize}".constantize.first
26
- @application_engine = engine_loaded
27
- end
28
-
29
- def application_class(request)
30
- Constraints::DomainConstraint.new(request.domain).application_class
31
- end
32
-
33
- def engine_loaded(request)
34
- Constraints::DomainConstraint.new(request.domain).engine_loaded
35
- end
36
-
37
- def application_object(request)
38
- Constraints::DomainConstraint.new(request.domain).application_object
39
- end
40
9
 
41
10
  def not_found
42
11
  render json: { data: [] }, status: :not_found
@@ -66,7 +35,7 @@ module Tramway
66
35
  user_based_model = params[:user_based_model].constantize
67
36
  @entity ||=
68
37
  if user_based_model.respond_to? :from_token_request
69
- user_based_model.active.from_token_request request
38
+ user_based_model.from_token_request request
70
39
  else
71
40
  params[:auth] && find_user_by_auth_attributes
72
41
  end
@@ -74,8 +43,8 @@ module Tramway
74
43
 
75
44
  def find_user_by_auth_attributes
76
45
  user_based_model = params[:user_based_model].constantize
77
- Tramway::Api.auth_attributes[user_based_model].each do |attribute|
78
- object = user_based_model.active.where.not(attribute => nil).find_by(attribute => auth_params[:login])
46
+ Tramway::Api.auth_attributes[params[:user_based_model]].each do |attribute|
47
+ object = user_based_model.where.not(attribute => nil).find_by(attribute => auth_params[:login])
79
48
  return object if object
80
49
  end
81
50
  nil
@@ -87,7 +56,7 @@ module Tramway
87
56
 
88
57
  def current_user
89
58
  Tramway::Api.user_based_models.map do |user_based_model|
90
- send("current_#{user_based_model.name.underscore}") unless user_based_model == User
59
+ send("current_#{user_based_model.constantize.name.underscore}") unless user_based_model == User
91
60
  end.compact.first
92
61
  end
93
62
  end
@@ -89,7 +89,6 @@ module Tramway
89
89
  end
90
90
 
91
91
  def authenticate_user_if_needed
92
- load_application
93
92
  action_is_open = Tramway::Api.action_is_available(
94
93
  action: action_name.to_sym,
95
94
  project: (@application_engine || application_name),
@@ -51,7 +51,7 @@ module Tramway::Api::V1
51
51
  end
52
52
 
53
53
  def destroy
54
- record.remove
54
+ record.destroy
55
55
  render json: record,
56
56
  serializer: serializer_class,
57
57
  include: '*',
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Tramway
4
4
  module Api
5
- VERSION = '1.8.7'
5
+ VERSION = '2.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tramway-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.7
4
+ version: '2.0'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Kalashnikov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-08 00:00:00.000000000 Z
11
+ date: 2022-01-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers
@@ -116,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
118
  requirements: []
119
- rubygems_version: 3.1.4
119
+ rubygems_version: 3.0.3.1
120
120
  signing_key:
121
121
  specification_version: 4
122
122
  summary: Engine for api