pg_rails 7.0.6 → 7.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +13 -0
  3. data/pg_associable/lib/pg_associable/engine.rb +0 -4
  4. data/pg_associable/spec/pg_associable/helpers_spec.rb +4 -3
  5. data/pg_engine/app/admin/accounts.rb +25 -0
  6. data/pg_engine/{lib/templates/activeadmin → app/admin}/audits.rb +3 -3
  7. data/pg_engine/app/admin/dashboard.rb +34 -0
  8. data/pg_engine/app/admin/user_accounts.rb +26 -0
  9. data/pg_engine/{lib/templates/activeadmin → app/admin}/users.rb +1 -2
  10. data/pg_engine/app/assets/javascripts/active_admin.js +1 -0
  11. data/pg_engine/app/assets/stylesheets/active_admin.scss +17 -0
  12. data/pg_engine/app/controllers/admin/accounts_controller.rb +33 -0
  13. data/pg_engine/app/controllers/admin/user_accounts_controller.rb +33 -0
  14. data/pg_engine/app/controllers/admin/users_controller.rb +47 -0
  15. data/pg_engine/app/controllers/pg_engine/resource_helper.rb +1 -0
  16. data/pg_engine/app/decorators/account_decorator.rb +16 -0
  17. data/pg_engine/app/decorators/user_account_decorator.rb +19 -0
  18. data/pg_engine/app/decorators/user_decorator.rb +20 -0
  19. data/pg_engine/app/helpers/pg_engine/flash_helper.rb +1 -1
  20. data/pg_engine/app/models/account.rb +39 -0
  21. data/pg_engine/app/models/user.rb +61 -0
  22. data/pg_engine/app/models/user_account.rb +46 -0
  23. data/pg_engine/app/policies/account_policy.rb +31 -0
  24. data/pg_engine/app/policies/pg_engine/application_policy.rb +1 -1
  25. data/pg_engine/app/policies/user_account_policy.rb +31 -0
  26. data/pg_engine/app/policies/user_policy.rb +31 -0
  27. data/pg_engine/app/views/admin/accounts/_account.html.slim +1 -0
  28. data/pg_engine/app/views/admin/accounts/_form.html.slim +12 -0
  29. data/pg_engine/app/views/admin/accounts/edit.html.slim +5 -0
  30. data/pg_engine/app/views/admin/accounts/new.html.slim +5 -0
  31. data/pg_engine/app/views/admin/accounts/show.html.slim +27 -0
  32. data/pg_engine/app/views/admin/user_accounts/_form.html.slim +12 -0
  33. data/pg_engine/app/views/admin/user_accounts/_user_account.html.slim +1 -0
  34. data/pg_engine/app/views/admin/user_accounts/edit.html.slim +5 -0
  35. data/pg_engine/app/views/admin/user_accounts/new.html.slim +5 -0
  36. data/pg_engine/app/views/admin/user_accounts/show.html.slim +24 -0
  37. data/pg_engine/app/views/admin/users/_form.html.slim +12 -0
  38. data/pg_engine/app/views/admin/users/_user.html.slim +1 -0
  39. data/pg_engine/app/views/admin/users/edit.html.slim +5 -0
  40. data/pg_engine/app/views/admin/users/new.html.slim +5 -0
  41. data/pg_engine/app/views/admin/users/show.html.slim +27 -0
  42. data/pg_engine/config/initializers/active_admin.rb +355 -0
  43. data/pg_engine/config/initializers/devise.rb +313 -0
  44. data/pg_engine/config/locales/devise.en.yml +65 -0
  45. data/pg_engine/config/routes.rb +11 -0
  46. data/pg_engine/db/migrate/20240205194218_devise_create_users.rb +47 -0
  47. data/pg_engine/db/migrate/20240208234111_unaccent.rb +5 -0
  48. data/pg_engine/db/migrate/20240208234901_install_audited.rb +32 -0
  49. data/pg_engine/db/migrate/20240210025702_create_active_admin_comments.rb +16 -0
  50. data/pg_engine/db/migrate/20240211152951_create_accounts.rb +24 -0
  51. data/pg_engine/db/migrate/20240211153049_create_user_accounts.rb +20 -0
  52. data/pg_engine/db/seeds.rb +5 -0
  53. data/pg_engine/lib/pg_engine/engine.rb +16 -2
  54. data/pg_engine/spec/controllers/admin/accounts_controller_spec.rb +206 -0
  55. data/pg_engine/spec/controllers/admin/user_accounts_controller_spec.rb +189 -0
  56. data/pg_engine/spec/controllers/admin/users_controller_spec.rb +180 -0
  57. data/pg_engine/spec/factories/accounts.rb +11 -0
  58. data/pg_engine/spec/factories/user_accounts.rb +21 -0
  59. data/pg_engine/spec/factories/users.rb +59 -0
  60. data/pg_engine/spec/models/account_spec.rb +13 -0
  61. data/pg_engine/spec/models/user_account_spec.rb +13 -0
  62. data/pg_engine/spec/models/user_spec.rb +13 -0
  63. data/pg_layout/lib/pg_layout/engine.rb +0 -1
  64. data/pg_rails/lib/version.rb +1 -1
  65. data/pg_scaffold/lib/generators/pg_pundit/templates/policy.rb +1 -1
  66. data/pg_scaffold/lib/generators/pg_rspec/scaffold/templates/controller_spec.rb +4 -4
  67. data/pg_scaffold/spec/generators_spec.rb +1 -1
  68. metadata +56 -4
@@ -0,0 +1,206 @@
1
+ # frozen_string_literal: true
2
+
3
+ # generado con pg_rails
4
+
5
+ require 'rails_helper'
6
+
7
+ # This spec was generated by rspec-rails when you ran the scaffold generator.
8
+ # It demonstrates how one might use RSpec to specify the controller code that
9
+ # was generated by Rails when you ran the scaffold generator.
10
+ #
11
+ # It assumes that the implementation code is generated by the rails scaffold
12
+ # generator. If you are using any extension libraries to generate different
13
+ # controller code, this generated spec may or may not pass.
14
+ #
15
+ # It only uses APIs available in rails and/or rspec-rails. There are a number
16
+ # of tools you can use to make these specs even more expressive, but we're
17
+ # sticking to rails and rspec-rails APIs to keep things simple and stable.
18
+ #
19
+ # Compared to earlier versions of this generator, there is very limited use of
20
+ # stubs and message expectations in this spec. Stubs are only used when there
21
+ # is no simpler way to get a handle on the object needed for the example.
22
+ # Message expectations are only used when there is no simpler way to specify
23
+ # that an instance is receiving a specific message.
24
+ #
25
+ # Also compared to earlier versions of this generator, there are no longer any
26
+ # expectations of assigns and templates rendered. These features have been
27
+ # removed from Rails core in Rails 5, but can be added back in via the
28
+ # `rails-controller-testing` gem.
29
+
30
+ RSpec.describe Admin::AccountsController do
31
+ render_views
32
+ # This should return the minimal set of attributes required to create a valid
33
+ # Account. As you add validations to Account, be sure to
34
+ # adjust the attributes here as well.
35
+ let(:valid_attributes) do
36
+ attributes_for(:account)
37
+ end
38
+
39
+ let(:invalid_attributes) do
40
+ {
41
+ plan: nil
42
+ }
43
+ end
44
+
45
+ let(:user) { create :user, :admin }
46
+
47
+ before do
48
+ sign_in user if user.present?
49
+ end
50
+
51
+ describe 'routing' do
52
+ it 'routes GET index correctly' do
53
+ route = { get: '/a/accounts' }
54
+ expect(route).to route_to(controller: 'admin/accounts', action: 'index')
55
+ end
56
+ end
57
+
58
+ describe 'GET #index' do
59
+ subject do
60
+ get :index, params: {}
61
+ end
62
+
63
+ let!(:account) { create :account }
64
+
65
+ it 'returns a success response' do
66
+ subject
67
+ expect(response).to be_successful
68
+ end
69
+
70
+ context 'when user is not logged in' do
71
+ let(:user) { nil }
72
+
73
+ it 'redirects to login path' do
74
+ subject
75
+ expect(response).to redirect_to(new_user_session_path)
76
+ end
77
+ end
78
+
79
+ context 'when está descartado' do
80
+ before { account.discard! }
81
+
82
+ it do
83
+ subject
84
+ expect(assigns(:collection)).not_to include(account)
85
+ end
86
+ end
87
+
88
+ context 'when se pide el excel' do
89
+ subject do
90
+ get :index, params: {}, format: 'xlsx'
91
+ end
92
+
93
+ it 'returns a success response' do
94
+ subject
95
+ expect(response).to be_successful
96
+ end
97
+ end
98
+ end
99
+
100
+ describe 'GET #show' do
101
+ it 'returns a success response' do
102
+ account = create(:account)
103
+ get :show, params: { id: account.to_param }
104
+ expect(response).to be_successful
105
+ end
106
+ end
107
+
108
+ describe 'GET #new' do
109
+ it 'returns a success response' do
110
+ get :new, params: {}
111
+ expect(response).to be_successful
112
+ end
113
+ end
114
+
115
+ describe 'GET #edit' do
116
+ it 'returns a success response' do
117
+ account = create(:account)
118
+ get :edit, params: { id: account.to_param }
119
+ expect(response).to be_successful
120
+ end
121
+ end
122
+
123
+ describe 'POST #create' do
124
+ context 'with valid params' do
125
+ it 'creates a new Account' do
126
+ expect do
127
+ post :create, params: { account: valid_attributes }
128
+ end.to change(Account, :count).by(1)
129
+ end
130
+
131
+ it 'redirects to the created account' do
132
+ post :create, params: { account: valid_attributes }
133
+ expect(response).to redirect_to(Account.last.decorate.target_object)
134
+ end
135
+ end
136
+
137
+ context 'with invalid params' do
138
+ it 'returns a unprocessable_entity response' do
139
+ post :create, params: { account: invalid_attributes }
140
+ expect(response).to have_http_status(:unprocessable_entity)
141
+ end
142
+
143
+ it 'renders the new template' do
144
+ post :create, params: { account: invalid_attributes }
145
+ expect(response).to render_template(:new)
146
+ end
147
+ end
148
+ end
149
+
150
+ describe 'PUT #update' do
151
+ context 'with valid params' do
152
+ let(:new_attributes) do
153
+ attributes_for(:account)
154
+ end
155
+
156
+ it 'updates the requested account' do
157
+ account = create(:account)
158
+ put :update, params: { id: account.to_param, account: new_attributes }
159
+ account.reload
160
+ expect(account.plan).to eq new_attributes[:plan]
161
+ end
162
+
163
+ it 'redirects to the account' do
164
+ account = create(:account)
165
+ put :update, params: { id: account.to_param, account: valid_attributes }
166
+ expect(response).to redirect_to(account.decorate.target_object)
167
+ end
168
+ end
169
+
170
+ context 'with invalid params' do
171
+ it 'returns a unprocessable_entity response' do
172
+ account = create(:account)
173
+ put :update, params: { id: account.to_param, account: invalid_attributes }
174
+ expect(response).to have_http_status(:unprocessable_entity)
175
+ end
176
+
177
+ it 'renders the edit template' do
178
+ account = create(:account)
179
+ put :update, params: { id: account.to_param, account: invalid_attributes }
180
+ expect(response).to render_template(:edit)
181
+ end
182
+ end
183
+ end
184
+
185
+ describe 'DELETE #destroy' do
186
+ subject do
187
+ delete :destroy, params: { id: account.to_param }
188
+ end
189
+
190
+ let!(:account) { create :account }
191
+
192
+ it 'destroys the requested account' do
193
+ expect { subject }.to change(Account.kept, :count).by(-1)
194
+ end
195
+
196
+ it 'setea el discarded_at' do
197
+ subject
198
+ expect(account.reload.discarded_at).to be_present
199
+ end
200
+
201
+ it 'redirects to the accounts list' do
202
+ subject
203
+ expect(response).to redirect_to(admin_accounts_url)
204
+ end
205
+ end
206
+ end
@@ -0,0 +1,189 @@
1
+ # frozen_string_literal: true
2
+
3
+ # generado con pg_rails
4
+
5
+ require 'rails_helper'
6
+
7
+ # This spec was generated by rspec-rails when you ran the scaffold generator.
8
+ # It demonstrates how one might use RSpec to specify the controller code that
9
+ # was generated by Rails when you ran the scaffold generator.
10
+ #
11
+ # It assumes that the implementation code is generated by the rails scaffold
12
+ # generator. If you are using any extension libraries to generate different
13
+ # controller code, this generated spec may or may not pass.
14
+ #
15
+ # It only uses APIs available in rails and/or rspec-rails. There are a number
16
+ # of tools you can use to make these specs even more expressive, but we're
17
+ # sticking to rails and rspec-rails APIs to keep things simple and stable.
18
+ #
19
+ # Compared to earlier versions of this generator, there is very limited use of
20
+ # stubs and message expectations in this spec. Stubs are only used when there
21
+ # is no simpler way to get a handle on the object needed for the example.
22
+ # Message expectations are only used when there is no simpler way to specify
23
+ # that an instance is receiving a specific message.
24
+ #
25
+ # Also compared to earlier versions of this generator, there are no longer any
26
+ # expectations of assigns and templates rendered. These features have been
27
+ # removed from Rails core in Rails 5, but can be added back in via the
28
+ # `rails-controller-testing` gem.
29
+
30
+ RSpec.describe Admin::UserAccountsController do
31
+ render_views
32
+ let(:user) { create :orphan_user }
33
+
34
+ let(:account) { create :account }
35
+
36
+ # This should return the minimal set of attributes required to create a valid
37
+ # UserAccount. As you add validations to UserAccount, be sure to
38
+ # adjust the attributes here as well.
39
+ let(:valid_attributes) do
40
+ attributes_for(:user_account).merge(user_id: user.id, account_id: account.id)
41
+ end
42
+
43
+ let(:invalid_attributes) do
44
+ {
45
+ user_id: nil
46
+ }
47
+ end
48
+
49
+ let(:logged_user) { create :user, :developer }
50
+
51
+ before do
52
+ sign_in logged_user if logged_user.present?
53
+ end
54
+
55
+ describe 'routing' do
56
+ it 'routes GET index correctly' do
57
+ route = { get: '/a/user_accounts' }
58
+ expect(route).to route_to(controller: 'admin/user_accounts', action: 'index')
59
+ end
60
+ end
61
+
62
+ describe 'GET #index' do
63
+ subject do
64
+ get :index, params: {}
65
+ end
66
+
67
+ before { create :user_account }
68
+
69
+ it 'returns a success response' do
70
+ subject
71
+ expect(response).to be_successful
72
+ end
73
+
74
+ context 'when user is not logged in' do
75
+ let(:logged_user) { nil }
76
+
77
+ it 'redirects to login path' do
78
+ subject
79
+ expect(response).to redirect_to(new_user_session_path)
80
+ end
81
+ end
82
+
83
+ context 'when se pide el excel' do
84
+ subject do
85
+ get :index, params: {}, format: 'xlsx'
86
+ end
87
+
88
+ it 'returns a success response' do
89
+ subject
90
+ expect(response).to be_successful
91
+ end
92
+ end
93
+ end
94
+
95
+ describe 'GET #show' do
96
+ it 'returns a success response' do
97
+ user_account = create(:user_account)
98
+ get :show, params: { id: user_account.to_param }
99
+ expect(response).to be_successful
100
+ end
101
+ end
102
+
103
+ describe 'GET #new' do
104
+ it 'returns a success response' do
105
+ get :new, params: {}
106
+ expect(response).to be_successful
107
+ end
108
+ end
109
+
110
+ describe 'GET #edit' do
111
+ it 'returns a success response' do
112
+ user_account = create(:user_account)
113
+ get :edit, params: { id: user_account.to_param }
114
+ expect(response).to be_successful
115
+ end
116
+ end
117
+
118
+ describe 'POST #create' do
119
+ context 'with valid params' do
120
+ it 'creates a new UserAccount' do
121
+ expect do
122
+ post :create, params: { user_account: valid_attributes }
123
+ end.to change(UserAccount, :count).by(1)
124
+ end
125
+
126
+ it 'redirects to the created user_account' do
127
+ post :create, params: { user_account: valid_attributes }
128
+ expect(response).to redirect_to(UserAccount.last.decorate.target_object)
129
+ end
130
+ end
131
+
132
+ context 'with invalid params' do
133
+ it 'returns a unprocessable_entity response' do
134
+ post :create, params: { user_account: invalid_attributes }
135
+ expect(response).to have_http_status(:unprocessable_entity)
136
+ end
137
+
138
+ it 'renders the new template' do
139
+ post :create, params: { user_account: invalid_attributes }
140
+ expect(response).to render_template(:new)
141
+ end
142
+ end
143
+ end
144
+
145
+ describe 'PUT #update' do
146
+ context 'with valid params' do
147
+ let(:new_attributes) do
148
+ attributes_for(:user_account)
149
+ end
150
+
151
+ it 'redirects to the user_account' do
152
+ user_account = create(:user_account)
153
+ put :update, params: { id: user_account.to_param, user_account: valid_attributes }
154
+ expect(response).to redirect_to(user_account.decorate.target_object)
155
+ end
156
+ end
157
+
158
+ context 'with invalid params' do
159
+ it 'returns a unprocessable_entity response' do
160
+ user_account = create(:user_account)
161
+ put :update, params: { id: user_account.to_param, user_account: invalid_attributes }
162
+ expect(response).to have_http_status(:unprocessable_entity)
163
+ end
164
+
165
+ it 'renders the edit template' do
166
+ user_account = create(:user_account)
167
+ put :update, params: { id: user_account.to_param, user_account: invalid_attributes }
168
+ expect(response).to render_template(:edit)
169
+ end
170
+ end
171
+ end
172
+
173
+ describe 'DELETE #destroy' do
174
+ subject do
175
+ delete :destroy, params: { id: user_account.to_param }
176
+ end
177
+
178
+ let!(:user_account) { create :user_account }
179
+
180
+ it 'destroys the requested user_account' do
181
+ expect { subject }.to change(UserAccount, :count).by(-1)
182
+ end
183
+
184
+ it 'redirects to the user_accounts list' do
185
+ subject
186
+ expect(response).to redirect_to(admin_user_accounts_url)
187
+ end
188
+ end
189
+ end
@@ -0,0 +1,180 @@
1
+ # frozen_string_literal: true
2
+
3
+ # generado con pg_rails
4
+
5
+ require 'rails_helper'
6
+
7
+ # This spec was generated by rspec-rails when you ran the scaffold generator.
8
+ # It demonstrates how one might use RSpec to specify the controller code that
9
+ # was generated by Rails when you ran the scaffold generator.
10
+ #
11
+ # It assumes that the implementation code is generated by the rails scaffold
12
+ # generator. If you are using any extension libraries to generate different
13
+ # controller code, this generated spec may or may not pass.
14
+ #
15
+ # It only uses APIs available in rails and/or rspec-rails. There are a number
16
+ # of tools you can use to make these specs even more expressive, but we're
17
+ # sticking to rails and rspec-rails APIs to keep things simple and stable.
18
+ #
19
+ # Compared to earlier versions of this generator, there is very limited use of
20
+ # stubs and message expectations in this spec. Stubs are only used when there
21
+ # is no simpler way to get a handle on the object needed for the example.
22
+ # Message expectations are only used when there is no simpler way to specify
23
+ # that an instance is receiving a specific message.
24
+ #
25
+ # Also compared to earlier versions of this generator, there are no longer any
26
+ # expectations of assigns and templates rendered. These features have been
27
+ # removed from Rails core in Rails 5, but can be added back in via the
28
+ # `rails-controller-testing` gem.
29
+
30
+ RSpec.describe Admin::UsersController do
31
+ render_views
32
+
33
+ # This should return the minimal set of attributes required to create a valid
34
+ # User. As you add validations to User, be sure to
35
+ # adjust the attributes here as well.
36
+ let(:valid_attributes) do
37
+ attributes_for(:user)
38
+ end
39
+
40
+ let(:invalid_attributes) do
41
+ {
42
+ email: nil
43
+ }
44
+ end
45
+
46
+ let(:logger_user) { create :user, :admin }
47
+
48
+ before do
49
+ sign_in logger_user
50
+ end
51
+
52
+ describe 'GET #index' do
53
+ subject do
54
+ get :index, params: {}
55
+ end
56
+
57
+ let!(:user) { create :user }
58
+
59
+ it 'returns a success response' do
60
+ subject
61
+ expect(response).to be_successful
62
+ end
63
+
64
+ context 'when está descartado' do
65
+ before { user.discard! }
66
+
67
+ it do
68
+ subject
69
+ expect(assigns(:collection)).to eq [logger_user]
70
+ end
71
+ end
72
+ end
73
+
74
+ describe 'GET #show' do
75
+ it 'returns a success response' do
76
+ user = create(:user)
77
+ get :show, params: { id: user.to_param }
78
+ expect(response).to be_successful
79
+ end
80
+ end
81
+
82
+ describe 'GET #new' do
83
+ it 'returns a success response' do
84
+ get :new, params: {}
85
+ expect(response).to be_successful
86
+ end
87
+ end
88
+
89
+ describe 'GET #edit' do
90
+ it 'returns a success response' do
91
+ user = create(:user)
92
+ get :edit, params: { id: user.to_param }
93
+ expect(response).to be_successful
94
+ end
95
+ end
96
+
97
+ describe 'POST #create' do
98
+ context 'with valid params' do
99
+ it 'creates a new User' do
100
+ expect do
101
+ post :create, params: { user: valid_attributes }
102
+ end.to change(User, :count).by(1)
103
+ end
104
+
105
+ it 'redirects to the created user' do
106
+ post :create, params: { user: valid_attributes }
107
+ expect(response).to redirect_to(User.last.decorate.target_object)
108
+ end
109
+ end
110
+
111
+ context 'with invalid params' do
112
+ it 'returns a unprocessable_entity response' do
113
+ post :create, params: { user: invalid_attributes }
114
+ expect(response).to have_http_status(:unprocessable_entity)
115
+ end
116
+
117
+ it 'renders the new template' do
118
+ post :create, params: { user: invalid_attributes }
119
+ expect(response).to render_template(:new)
120
+ end
121
+ end
122
+ end
123
+
124
+ describe 'PUT #update' do
125
+ context 'with valid params' do
126
+ let(:new_attributes) do
127
+ attributes_for(:user)
128
+ end
129
+
130
+ it 'updates the requested user' do
131
+ user = create(:user)
132
+ put :update, params: { id: user.to_param, user: new_attributes }
133
+ user.reload
134
+ expect(user.email).to eq new_attributes[:email]
135
+ end
136
+
137
+ it 'redirects to the user' do
138
+ user = create(:user)
139
+ put :update, params: { id: user.to_param, user: valid_attributes }
140
+ expect(response).to redirect_to(user.decorate.target_object)
141
+ end
142
+ end
143
+
144
+ context 'with invalid params' do
145
+ it 'returns a unprocessable_entity response' do
146
+ user = create(:user)
147
+ put :update, params: { id: user.to_param, user: invalid_attributes }
148
+ expect(response).to have_http_status(:unprocessable_entity)
149
+ end
150
+
151
+ it 'renders the edit template' do
152
+ user = create(:user)
153
+ put :update, params: { id: user.to_param, user: invalid_attributes }
154
+ expect(response).to render_template(:edit)
155
+ end
156
+ end
157
+ end
158
+
159
+ describe 'DELETE #destroy' do
160
+ subject do
161
+ delete :destroy, params: { id: user.to_param }
162
+ end
163
+
164
+ let!(:user) { create :user }
165
+
166
+ it 'destroys the requested user' do
167
+ expect { subject }.to change(User.kept, :count).by(-1)
168
+ end
169
+
170
+ it 'setea el discarded_at' do
171
+ subject
172
+ expect(user.reload.discarded_at).to be_present
173
+ end
174
+
175
+ it 'redirects to the users list' do
176
+ subject
177
+ expect(response).to redirect_to(admin_users_url)
178
+ end
179
+ end
180
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ # generado con pg_rails
4
+
5
+ FactoryBot.define do
6
+ factory :account do
7
+ plan { Account.plan.values.sample }
8
+ nombre { Faker::Lorem.sentence }
9
+ hashid { Faker::Lorem.sentence }
10
+ end
11
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ # generado con pg_rails
4
+
5
+ FactoryBot.define do
6
+ factory :user_account do
7
+ association :user
8
+ association :account
9
+ profiles { [UserAccount.profiles.values.sample] }
10
+
11
+ trait :user_existente do
12
+ user { nil }
13
+ user_id { User.pluck(:id).sample }
14
+ end
15
+
16
+ trait :account_existente do
17
+ account { nil }
18
+ account_id { Account.pluck(:id).sample }
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ # == Schema Information
4
+ #
5
+ # Table name: users
6
+ #
7
+ # id :bigint not null, primary key
8
+ # confirmation_sent_at :datetime
9
+ # confirmation_token :string
10
+ # confirmed_at :datetime
11
+ # current_sign_in_at :datetime
12
+ # current_sign_in_ip :string
13
+ # discarded_at :datetime
14
+ # email :string default(""), not null
15
+ # encrypted_password :string default(""), not null
16
+ # failed_attempts :integer default(0), not null
17
+ # last_sign_in_at :datetime
18
+ # last_sign_in_ip :string
19
+ # locked_at :datetime
20
+ # profiles :integer default([]), not null, is an Array
21
+ # remember_created_at :datetime
22
+ # reset_password_sent_at :datetime
23
+ # reset_password_token :string
24
+ # sign_in_count :integer default(0), not null
25
+ # unconfirmed_email :string
26
+ # unlock_token :string
27
+ # created_at :datetime not null
28
+ # updated_at :datetime not null
29
+ #
30
+ # Indexes
31
+ #
32
+ # index_users_on_confirmation_token (confirmation_token) UNIQUE
33
+ # index_users_on_email (email) UNIQUE
34
+ # index_users_on_reset_password_token (reset_password_token) UNIQUE
35
+ # index_users_on_unlock_token (unlock_token) UNIQUE
36
+ #
37
+
38
+ FactoryBot.define do
39
+ factory :orphan_user, class: 'User' do
40
+ email { Faker::Internet.email }
41
+ password { "password#{rand(99_999)}" }
42
+ confirmed_at { Faker::Date.backward }
43
+
44
+ trait :admin do
45
+ developer { true }
46
+ end
47
+
48
+ trait :developer do
49
+ developer { true }
50
+ end
51
+
52
+ factory :user do
53
+ after(:create) do |user, _context|
54
+ account = create :account
55
+ create :user_account, user:, account:
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ # generado con pg_rails
4
+
5
+ require 'rails_helper'
6
+
7
+ RSpec.describe Account do
8
+ let(:account) { create(:account) }
9
+
10
+ it 'se persiste' do
11
+ expect(account).to be_persisted
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ # generado con pg_rails
4
+
5
+ require 'rails_helper'
6
+
7
+ RSpec.describe UserAccount do
8
+ let(:user_account) { create(:user_account) }
9
+
10
+ it 'se persiste' do
11
+ expect(user_account).to be_persisted
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ # generado con pg_rails
4
+
5
+ require 'rails_helper'
6
+
7
+ RSpec.describe User do
8
+ let(:user) { create(:user) }
9
+
10
+ it 'se persiste' do
11
+ expect(user).to be_persisted
12
+ end
13
+ end