pg_rails 7.0.6 → 7.0.8.pre.alpha
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +13 -0
- data/pg_associable/app/assets/{css → stylesheets}/pg_associable.scss +1 -1
- data/pg_associable/app/helpers/pg_associable/form_builder_methods.rb +2 -19
- data/pg_associable/app/helpers/pg_associable/helpers.rb +2 -1
- data/pg_associable/app/inputs/pg_associable_input.rb +53 -0
- data/pg_associable/app/javascript/asociable_controller.tsx +171 -0
- data/pg_associable/app/{assets/js → javascript}/modal_controller.js +6 -3
- data/pg_associable/app/views/pg_associable/_resultados.html.slim +3 -1
- data/pg_associable/app/views/pg_associable/_resultados_inline.html.slim +5 -2
- data/pg_associable/index.js +2 -4
- data/pg_associable/lib/pg_associable/engine.rb +0 -8
- data/pg_associable/spec/pg_associable/helpers_spec.rb +4 -3
- data/pg_engine/app/admin/accounts.rb +25 -0
- data/pg_engine/{lib/templates/activeadmin → app/admin}/audits.rb +3 -3
- data/pg_engine/app/admin/dashboard.rb +34 -0
- data/pg_engine/app/admin/user_accounts.rb +26 -0
- data/pg_engine/{lib/templates/activeadmin → app/admin}/users.rb +1 -2
- data/pg_engine/app/assets/javascripts/active_admin.js +1 -0
- data/pg_engine/app/assets/stylesheets/active_admin.scss +17 -0
- data/pg_engine/app/controllers/admin/accounts_controller.rb +33 -0
- data/pg_engine/app/controllers/admin/user_accounts_controller.rb +33 -0
- data/pg_engine/app/controllers/admin/users_controller.rb +47 -0
- data/pg_engine/app/controllers/pg_engine/resource_helper.rb +1 -0
- data/pg_engine/app/decorators/account_decorator.rb +16 -0
- data/pg_engine/app/decorators/user_account_decorator.rb +19 -0
- data/pg_engine/app/decorators/user_decorator.rb +20 -0
- data/pg_engine/app/helpers/pg_engine/flash_helper.rb +1 -1
- data/pg_engine/app/models/account.rb +39 -0
- data/pg_engine/app/models/user.rb +61 -0
- data/pg_engine/app/models/user_account.rb +46 -0
- data/pg_engine/app/policies/account_policy.rb +31 -0
- data/pg_engine/app/policies/pg_engine/application_policy.rb +1 -1
- data/pg_engine/app/policies/user_account_policy.rb +31 -0
- data/pg_engine/app/policies/user_policy.rb +31 -0
- data/pg_engine/app/views/admin/accounts/_account.html.slim +1 -0
- data/pg_engine/app/views/admin/accounts/_form.html.slim +12 -0
- data/pg_engine/app/views/admin/accounts/edit.html.slim +5 -0
- data/pg_engine/app/views/admin/accounts/new.html.slim +5 -0
- data/pg_engine/app/views/admin/accounts/show.html.slim +27 -0
- data/pg_engine/app/views/admin/user_accounts/_form.html.slim +12 -0
- data/pg_engine/app/views/admin/user_accounts/_user_account.html.slim +1 -0
- data/pg_engine/app/views/admin/user_accounts/edit.html.slim +5 -0
- data/pg_engine/app/views/admin/user_accounts/new.html.slim +5 -0
- data/pg_engine/app/views/admin/user_accounts/show.html.slim +24 -0
- data/pg_engine/app/views/admin/users/_form.html.slim +12 -0
- data/pg_engine/app/views/admin/users/_user.html.slim +1 -0
- data/pg_engine/app/views/admin/users/edit.html.slim +5 -0
- data/pg_engine/app/views/admin/users/new.html.slim +5 -0
- data/pg_engine/app/views/admin/users/show.html.slim +27 -0
- data/pg_engine/config/initializers/active_admin.rb +352 -0
- data/pg_engine/config/initializers/devise.rb +313 -0
- data/pg_engine/config/locales/devise.en.yml +65 -0
- data/pg_engine/config/routes.rb +11 -0
- data/pg_engine/db/migrate/20240205194218_devise_create_users.rb +47 -0
- data/pg_engine/db/migrate/20240208234111_unaccent.rb +5 -0
- data/pg_engine/db/migrate/20240208234901_install_audited.rb +32 -0
- data/pg_engine/db/migrate/20240210025702_create_active_admin_comments.rb +16 -0
- data/pg_engine/db/migrate/20240211152951_create_accounts.rb +24 -0
- data/pg_engine/db/migrate/20240211153049_create_user_accounts.rb +20 -0
- data/pg_engine/db/seeds.rb +8 -0
- data/pg_engine/lib/pg_engine/engine.rb +16 -2
- data/pg_engine/lib/tasks/auto_anotar_modelos.rake +1 -1
- data/pg_engine/spec/controllers/admin/accounts_controller_spec.rb +206 -0
- data/pg_engine/spec/controllers/admin/user_accounts_controller_spec.rb +189 -0
- data/pg_engine/spec/controllers/admin/users_controller_spec.rb +180 -0
- data/pg_engine/spec/factories/accounts.rb +11 -0
- data/pg_engine/spec/factories/user_accounts.rb +21 -0
- data/pg_engine/spec/factories/users.rb +59 -0
- data/pg_engine/spec/models/account_spec.rb +13 -0
- data/pg_engine/spec/models/user_account_spec.rb +13 -0
- data/pg_engine/spec/models/user_spec.rb +13 -0
- data/pg_layout/app/views/layouts/pg_layout/layout.html.slim +1 -0
- data/pg_layout/app/views/pg_layout/_flash.html.slim +1 -1
- data/pg_layout/lib/pg_layout/engine.rb +0 -1
- data/pg_rails/lib/version.rb +1 -1
- data/pg_rails/scss/pg_rails.scss +1 -1
- data/pg_scaffold/lib/generators/pg_pundit/templates/policy.rb +1 -1
- data/pg_scaffold/lib/generators/pg_rspec/scaffold/templates/controller_spec.rb +4 -4
- data/pg_scaffold/lib/generators/pg_slim/templates/_form.html.slim +1 -1
- data/pg_scaffold/spec/generators_spec.rb +1 -1
- metadata +62 -14
- data/pg_associable/app/assets/js/asociable_controller.js +0 -58
- data/pg_associable/app/assets/js/asociable_inline_controller.js +0 -142
- data/pg_associable/app/inputs/pg_associable/pg_associable_inline_input.rb +0 -39
- data/pg_associable/app/inputs/pg_associable/pg_associable_input.rb +0 -41
- data/pg_associable/lib/pg_associable/simple_form_initializer.rb +0 -34
- data/pg_associable/lib/tasks/pg_associable_tasks.rake +0 -4
@@ -0,0 +1,65 @@
|
|
1
|
+
# Additional translations at https://github.com/heartcombo/devise/wiki/I18n
|
2
|
+
|
3
|
+
en:
|
4
|
+
devise:
|
5
|
+
confirmations:
|
6
|
+
confirmed: "Your email address has been successfully confirmed."
|
7
|
+
send_instructions: "You will receive an email with instructions for how to confirm your email address in a few minutes."
|
8
|
+
send_paranoid_instructions: "If your email address exists in our database, you will receive an email with instructions for how to confirm your email address in a few minutes."
|
9
|
+
failure:
|
10
|
+
already_authenticated: "You are already signed in."
|
11
|
+
inactive: "Your account is not activated yet."
|
12
|
+
invalid: "Invalid %{authentication_keys} or password."
|
13
|
+
locked: "Your account is locked."
|
14
|
+
last_attempt: "You have one more attempt before your account is locked."
|
15
|
+
not_found_in_database: "Invalid %{authentication_keys} or password."
|
16
|
+
timeout: "Your session expired. Please sign in again to continue."
|
17
|
+
unauthenticated: "You need to sign in or sign up before continuing."
|
18
|
+
unconfirmed: "You have to confirm your email address before continuing."
|
19
|
+
mailer:
|
20
|
+
confirmation_instructions:
|
21
|
+
subject: "Confirmation instructions"
|
22
|
+
reset_password_instructions:
|
23
|
+
subject: "Reset password instructions"
|
24
|
+
unlock_instructions:
|
25
|
+
subject: "Unlock instructions"
|
26
|
+
email_changed:
|
27
|
+
subject: "Email Changed"
|
28
|
+
password_change:
|
29
|
+
subject: "Password Changed"
|
30
|
+
omniauth_callbacks:
|
31
|
+
failure: "Could not authenticate you from %{kind} because \"%{reason}\"."
|
32
|
+
success: "Successfully authenticated from %{kind} account."
|
33
|
+
passwords:
|
34
|
+
no_token: "You can't access this page without coming from a password reset email. If you do come from a password reset email, please make sure you used the full URL provided."
|
35
|
+
send_instructions: "You will receive an email with instructions on how to reset your password in a few minutes."
|
36
|
+
send_paranoid_instructions: "If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes."
|
37
|
+
updated: "Your password has been changed successfully. You are now signed in."
|
38
|
+
updated_not_active: "Your password has been changed successfully."
|
39
|
+
registrations:
|
40
|
+
destroyed: "Bye! Your account has been successfully cancelled. We hope to see you again soon."
|
41
|
+
signed_up: "Welcome! You have signed up successfully."
|
42
|
+
signed_up_but_inactive: "You have signed up successfully. However, we could not sign you in because your account is not yet activated."
|
43
|
+
signed_up_but_locked: "You have signed up successfully. However, we could not sign you in because your account is locked."
|
44
|
+
signed_up_but_unconfirmed: "A message with a confirmation link has been sent to your email address. Please follow the link to activate your account."
|
45
|
+
update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and follow the confirmation link to confirm your new email address."
|
46
|
+
updated: "Your account has been updated successfully."
|
47
|
+
updated_but_not_signed_in: "Your account has been updated successfully, but since your password was changed, you need to sign in again."
|
48
|
+
sessions:
|
49
|
+
signed_in: "Signed in successfully."
|
50
|
+
signed_out: "Signed out successfully."
|
51
|
+
already_signed_out: "Signed out successfully."
|
52
|
+
unlocks:
|
53
|
+
send_instructions: "You will receive an email with instructions for how to unlock your account in a few minutes."
|
54
|
+
send_paranoid_instructions: "If your account exists, you will receive an email with instructions for how to unlock it in a few minutes."
|
55
|
+
unlocked: "Your account has been unlocked successfully. Please sign in to continue."
|
56
|
+
errors:
|
57
|
+
messages:
|
58
|
+
already_confirmed: "was already confirmed, please try signing in"
|
59
|
+
confirmation_period_expired: "needs to be confirmed within %{period}, please request a new one"
|
60
|
+
expired: "has expired, please request a new one"
|
61
|
+
not_found: "not found"
|
62
|
+
not_locked: "was not locked"
|
63
|
+
not_saved:
|
64
|
+
one: "1 error prohibited this %{resource} from being saved:"
|
65
|
+
other: "%{count} errors prohibited this %{resource} from being saved:"
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class DeviseCreateUsers < ActiveRecord::Migration[7.1]
|
4
|
+
def change
|
5
|
+
create_table :users do |t|
|
6
|
+
## Database authenticatable
|
7
|
+
t.string :email, null: false, default: ""
|
8
|
+
t.string :encrypted_password, null: false, default: ""
|
9
|
+
|
10
|
+
## Recoverable
|
11
|
+
t.string :reset_password_token
|
12
|
+
t.datetime :reset_password_sent_at
|
13
|
+
|
14
|
+
## Rememberable
|
15
|
+
t.datetime :remember_created_at
|
16
|
+
|
17
|
+
## Trackable
|
18
|
+
t.integer :sign_in_count, default: 0, null: false
|
19
|
+
t.datetime :current_sign_in_at
|
20
|
+
t.datetime :last_sign_in_at
|
21
|
+
t.string :current_sign_in_ip
|
22
|
+
t.string :last_sign_in_ip
|
23
|
+
|
24
|
+
## Confirmable
|
25
|
+
t.string :confirmation_token
|
26
|
+
t.datetime :confirmed_at
|
27
|
+
t.datetime :confirmation_sent_at
|
28
|
+
t.string :unconfirmed_email # Only if using reconfirmable
|
29
|
+
|
30
|
+
## Lockable
|
31
|
+
t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
|
32
|
+
t.string :unlock_token # Only if unlock strategy is :email or :both
|
33
|
+
t.datetime :locked_at
|
34
|
+
|
35
|
+
t.boolean :developer, null: false, default: false
|
36
|
+
|
37
|
+
t.timestamps null: false
|
38
|
+
end
|
39
|
+
|
40
|
+
add_column :users, :discarded_at, :datetime
|
41
|
+
|
42
|
+
add_index :users, :email, unique: true
|
43
|
+
add_index :users, :reset_password_token, unique: true
|
44
|
+
add_index :users, :confirmation_token, unique: true
|
45
|
+
add_index :users, :unlock_token, unique: true
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class InstallAudited < ActiveRecord::Migration[7.1]
|
4
|
+
def self.up
|
5
|
+
create_table :audits, :force => true do |t|
|
6
|
+
t.column :auditable_id, :integer
|
7
|
+
t.column :auditable_type, :string
|
8
|
+
t.column :associated_id, :integer
|
9
|
+
t.column :associated_type, :string
|
10
|
+
t.column :user_id, :integer
|
11
|
+
t.column :user_type, :string
|
12
|
+
t.column :username, :string
|
13
|
+
t.column :action, :string
|
14
|
+
t.column :audited_changes, :jsonb
|
15
|
+
t.column :version, :integer, :default => 0
|
16
|
+
t.column :comment, :string
|
17
|
+
t.column :remote_address, :string
|
18
|
+
t.column :request_uuid, :string
|
19
|
+
t.column :created_at, :datetime
|
20
|
+
end
|
21
|
+
|
22
|
+
add_index :audits, [:auditable_type, :auditable_id, :version], :name => 'auditable_index'
|
23
|
+
add_index :audits, [:associated_type, :associated_id], :name => 'associated_index'
|
24
|
+
add_index :audits, [:user_id, :user_type], :name => 'user_index'
|
25
|
+
add_index :audits, :request_uuid
|
26
|
+
add_index :audits, :created_at
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.down
|
30
|
+
drop_table :audits
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class CreateActiveAdminComments < ActiveRecord::Migration[7.1]
|
2
|
+
def self.up
|
3
|
+
create_table :active_admin_comments do |t|
|
4
|
+
t.string :namespace
|
5
|
+
t.text :body
|
6
|
+
t.references :resource, polymorphic: true
|
7
|
+
t.references :author, polymorphic: true
|
8
|
+
t.timestamps
|
9
|
+
end
|
10
|
+
add_index :active_admin_comments, [:namespace]
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.down
|
14
|
+
drop_table :active_admin_comments
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# generado con pg_rails
|
2
|
+
|
3
|
+
class CreateAccounts < ActiveRecord::Migration[7.1]
|
4
|
+
def change
|
5
|
+
create_table :accounts do |t|
|
6
|
+
t.integer :plan, null: false
|
7
|
+
t.string :nombre, null: false
|
8
|
+
t.string :hashid
|
9
|
+
|
10
|
+
|
11
|
+
t.references :creado_por, index: true
|
12
|
+
t.references :actualizado_por, index: true
|
13
|
+
|
14
|
+
|
15
|
+
t.datetime :discarded_at
|
16
|
+
|
17
|
+
t.timestamps
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
add_foreign_key :accounts, :users, column: 'creado_por_id'
|
22
|
+
add_foreign_key :accounts, :users, column: 'actualizado_por_id'
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# generado con pg_rails
|
2
|
+
|
3
|
+
class CreateUserAccounts < ActiveRecord::Migration[7.1]
|
4
|
+
def change
|
5
|
+
create_table :user_accounts do |t|
|
6
|
+
t.references :user, index: true, null: false, foreign_key: true
|
7
|
+
t.references :account, index: true, null: false, foreign_key: true
|
8
|
+
t.integer :profiles, array: true, null: false, default: []
|
9
|
+
|
10
|
+
t.references :creado_por, index: true
|
11
|
+
t.references :actualizado_por, index: true
|
12
|
+
|
13
|
+
t.timestamps
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
add_foreign_key :user_accounts, :users, column: 'creado_por_id'
|
18
|
+
add_foreign_key :user_accounts, :users, column: 'actualizado_por_id'
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
DatabaseCleaner.clean_with(:truncation, except: %w(ar_internal_metadata users accounts user_accounts))
|
2
|
+
|
3
|
+
MAIL = 'mrosso10@gmail.com'
|
4
|
+
|
5
|
+
unless User.where(email: MAIL).exists?
|
6
|
+
FactoryBot.create :user, email: MAIL, password: 'admin123',
|
7
|
+
confirmed_at: Time.now, developer: true
|
8
|
+
end
|
@@ -2,11 +2,25 @@
|
|
2
2
|
|
3
3
|
module PgEngine
|
4
4
|
class Engine < ::Rails::Engine
|
5
|
-
isolate_namespace PgEngine
|
6
|
-
|
7
5
|
config.i18n.default_locale = :es
|
8
6
|
config.time_zone = 'America/Argentina/Buenos_Aires'
|
9
7
|
|
8
|
+
config.generators do |g|
|
9
|
+
g.test_framework :pg_rspec
|
10
|
+
g.orm :pg_active_record
|
11
|
+
|
12
|
+
g.fallbacks[:pg_rspec] = :rspec
|
13
|
+
g.fallbacks[:pg_active_record] = :active_record
|
14
|
+
end
|
15
|
+
|
16
|
+
if Rails.env.local?
|
17
|
+
initializer 'configurar_factories', after: 'factory_bot.set_factory_paths' do
|
18
|
+
# Para que tome las factories de pg_engine/spec/factories
|
19
|
+
# además de las de dummy/spec/factories
|
20
|
+
FactoryBot.definition_file_paths << "#{root}/spec/factories"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
10
24
|
initializer 'configurar_pg_rails' do
|
11
25
|
# SimpleForm
|
12
26
|
require "#{PgEngine::Engine.root}/config/simple_form/simple_form"
|
@@ -11,7 +11,7 @@ if Rails.env.development?
|
|
11
11
|
'additional_file_patterns' => [],
|
12
12
|
'routes' => 'true',
|
13
13
|
'models' => 'true',
|
14
|
-
'position_in_routes' => '
|
14
|
+
'position_in_routes' => 'after',
|
15
15
|
'position_in_class' => 'before',
|
16
16
|
'position_in_test' => 'before',
|
17
17
|
'position_in_fixture' => 'before',
|
@@ -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
|