maquina-generators 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/generators/maquina/clave/clave_generator.rb +3 -0
- data/lib/generators/maquina/clave/templates/app/controllers/registration/verifications_controller.rb.tt +9 -4
- data/lib/generators/maquina/clave/templates/app/models/account.rb.tt +5 -0
- data/lib/generators/maquina/clave/templates/app/models/current.rb.tt +1 -0
- data/lib/generators/maquina/clave/templates/app/models/user.rb.tt +4 -0
- data/lib/generators/maquina/clave/templates/migration_create_accounts.rb.tt +9 -0
- data/lib/generators/maquina/clave/templates/migration_create_users.rb.tt +2 -0
- data/lib/generators/maquina/registration/templates/app/models/account.rb.tt +1 -1
- data/lib/generators/maquina/registration/templates/app/models/user.rb.tt +1 -1
- data/lib/generators/maquina/registration/templates/app/views/registrations/new.html.erb.tt +2 -2
- data/lib/generators/maquina/registration/templates/config/locales/registration.en.yml +1 -0
- data/lib/generators/maquina/registration/templates/config/locales/registration.es.yml +1 -0
- data/lib/maquina_generators/version.rb +1 -1
- data/test/generators/maquina/clave_generator_test.rb +10 -1
- data/test/generators/maquina/registration_generator_test.rb +2 -2
- data/test/tmp/config/application.rb +1 -4
- metadata +3 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ca10b8ebcd86d74709ad16f64e6366457b53fc9a55da72a997f9084c5819d267
|
|
4
|
+
data.tar.gz: 3147bb48486e66744e0b2af74ab06368a7b6e782a77b8c3946069f6c6178d76f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6d3ab8cb8656f06fa0c1ced220473bf6bfc76c7931ea70133a91405fdc28b866d2f840f35ced6f9056a382b812a4c03898e2b94ec40f7ab76c39297900789b39
|
|
7
|
+
data.tar.gz: 7c5cec9099144f5a9216afe62df79d5c5561d23886accd332017d2e491bf29fe25d787129288f743ec0784d19ff9c85cfe15274f00976c60c554fe018d84007e
|
|
@@ -34,6 +34,7 @@ module Maquina
|
|
|
34
34
|
|
|
35
35
|
# 1. Models
|
|
36
36
|
def create_models
|
|
37
|
+
template "app/models/account.rb.tt", "app/models/account.rb"
|
|
37
38
|
template "app/models/current.rb.tt", "app/models/current.rb"
|
|
38
39
|
template "app/models/session.rb.tt", "app/models/session.rb"
|
|
39
40
|
template "app/models/email_verification.rb.tt", "app/models/email_verification.rb"
|
|
@@ -146,6 +147,8 @@ module Maquina
|
|
|
146
147
|
|
|
147
148
|
# 12. Migrations
|
|
148
149
|
def add_migrations
|
|
150
|
+
migration_template "migration_create_accounts.rb.tt",
|
|
151
|
+
"db/migrate/create_accounts.rb"
|
|
149
152
|
migration_template "migration_create_users.rb.tt",
|
|
150
153
|
"db/migrate/create_users.rb"
|
|
151
154
|
migration_template "migration_create_sessions.rb.tt",
|
|
@@ -34,10 +34,15 @@ class Registration::VerificationsController < ApplicationController
|
|
|
34
34
|
return
|
|
35
35
|
end
|
|
36
36
|
|
|
37
|
-
user =
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
user = nil
|
|
38
|
+
ActiveRecord::Base.transaction do
|
|
39
|
+
account = Account.create!
|
|
40
|
+
user = account.users.create!(
|
|
41
|
+
email_address: @verification.email,
|
|
42
|
+
locale: @verification.locale || I18n.default_locale.to_s,
|
|
43
|
+
role: :admin
|
|
44
|
+
)
|
|
45
|
+
end
|
|
41
46
|
|
|
42
47
|
@verification.mark_verified!
|
|
43
48
|
session.delete(:pending_verification_id)
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
class User < ApplicationRecord
|
|
2
|
+
belongs_to :account
|
|
2
3
|
has_many :sessions, dependent: :destroy
|
|
3
4
|
|
|
5
|
+
enum :role, {member: "member", admin: "admin"}, default: "member"
|
|
6
|
+
|
|
4
7
|
normalizes :email_address, with: ->(e) { e.strip.downcase }
|
|
5
8
|
|
|
6
9
|
validates :email_address, uniqueness: true
|
|
10
|
+
validates :name, allow_blank: true, length: { maximum: 100 }
|
|
7
11
|
validate :email_cannot_contain_plus
|
|
8
12
|
|
|
9
13
|
scope :active, -> { where(blocked_at: nil) }
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
class CreateUsers < ActiveRecord::Migration<%= migration_version %>
|
|
2
2
|
def change
|
|
3
3
|
create_table :users do |t|
|
|
4
|
+
t.references :account, null: false, foreign_key: true
|
|
4
5
|
t.string :email_address, null: false
|
|
5
6
|
t.string :name
|
|
7
|
+
t.string :role, null: false, default: "member"
|
|
6
8
|
t.string :locale
|
|
7
9
|
t.datetime :blocked_at
|
|
8
10
|
t.text :blocked_reason
|
|
@@ -6,7 +6,7 @@ class User < ApplicationRecord
|
|
|
6
6
|
|
|
7
7
|
normalizes :email_address, with: ->(e) { e.strip.downcase }
|
|
8
8
|
|
|
9
|
-
validates :name,
|
|
9
|
+
validates :name, allow_blank: true, length: { maximum: 100 }
|
|
10
10
|
|
|
11
11
|
enum :role, {member: "member", admin: "admin"}, default: "member"
|
|
12
12
|
end
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
<%%= form_with url: registrations_path, method: :post, class: "space-y-6" do |form| %>
|
|
9
9
|
<div>
|
|
10
10
|
<%%= form.label :account_name, t(".account_name"), class: "block text-sm font-medium text-foreground mb-2", data: { component: "label" } %>
|
|
11
|
+
<span class="text-xs text-muted-foreground"><%%= t(".optional") %></span>
|
|
11
12
|
<%%= form.text_field :account_name,
|
|
12
|
-
required: true,
|
|
13
13
|
autofocus: true,
|
|
14
14
|
value: @account_name,
|
|
15
15
|
placeholder: t(".account_name_placeholder"),
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
|
|
20
20
|
<div>
|
|
21
21
|
<%%= form.label :name, t(".name"), class: "block text-sm font-medium text-foreground mb-2", data: { component: "label" } %>
|
|
22
|
+
<span class="text-xs text-muted-foreground"><%%= t(".optional") %></span>
|
|
22
23
|
<%%= form.text_field :name,
|
|
23
|
-
required: true,
|
|
24
24
|
value: @user.name,
|
|
25
25
|
placeholder: t(".name_placeholder"),
|
|
26
26
|
data: { component: "input" },
|
|
@@ -15,6 +15,7 @@ es:
|
|
|
15
15
|
submit: "Registrarse"
|
|
16
16
|
have_account: "Ya tienes cuenta?"
|
|
17
17
|
sign_in: "Inicia sesion"
|
|
18
|
+
optional: "(opcional)"
|
|
18
19
|
create:
|
|
19
20
|
success: "Tu cuenta ha sido creada. Bienvenido!"
|
|
20
21
|
rate_limited: "Demasiados intentos. Por favor, espera unos minutos e intenta de nuevo."
|
|
@@ -30,10 +30,15 @@ class Maquina::Generators::ClaveGeneratorTest < Rails::Generators::TestCase
|
|
|
30
30
|
test "generates model files" do
|
|
31
31
|
run_generator
|
|
32
32
|
|
|
33
|
+
assert_file "app/models/account.rb", /class Account < ApplicationRecord/
|
|
34
|
+
assert_file "app/models/account.rb", /has_many :users/
|
|
33
35
|
assert_file "app/models/current.rb", /class Current < ActiveSupport::CurrentAttributes/
|
|
36
|
+
assert_file "app/models/current.rb", /delegate :account, to: :user/
|
|
34
37
|
assert_file "app/models/session.rb", /class Session < ApplicationRecord/
|
|
35
38
|
assert_file "app/models/email_verification.rb", /class EmailVerification < ApplicationRecord/
|
|
36
39
|
assert_file "app/models/user.rb", /class User < ApplicationRecord/
|
|
40
|
+
assert_file "app/models/user.rb", /belongs_to :account/
|
|
41
|
+
assert_file "app/models/user.rb", /enum :role/
|
|
37
42
|
end
|
|
38
43
|
|
|
39
44
|
test "generates controller files" do
|
|
@@ -107,7 +112,11 @@ class Maquina::Generators::ClaveGeneratorTest < Rails::Generators::TestCase
|
|
|
107
112
|
test "generates migrations" do
|
|
108
113
|
run_generator
|
|
109
114
|
|
|
110
|
-
assert_migration "db/migrate/
|
|
115
|
+
assert_migration "db/migrate/create_accounts.rb"
|
|
116
|
+
assert_migration "db/migrate/create_users.rb" do |migration|
|
|
117
|
+
assert_match(/t\.references :account, null: false, foreign_key: true/, migration)
|
|
118
|
+
assert_match(/t\.string :role, null: false, default: "member"/, migration)
|
|
119
|
+
end
|
|
111
120
|
assert_migration "db/migrate/create_sessions.rb"
|
|
112
121
|
assert_migration "db/migrate/create_email_verifications.rb"
|
|
113
122
|
end
|
|
@@ -32,7 +32,7 @@ class Maquina::Generators::RegistrationGeneratorTest < Rails::Generators::TestCa
|
|
|
32
32
|
|
|
33
33
|
assert_file "app/models/account.rb", /class Account < ApplicationRecord/
|
|
34
34
|
assert_file "app/models/account.rb", /has_many :users/
|
|
35
|
-
assert_file "app/models/account.rb", /validates :name,
|
|
35
|
+
assert_file "app/models/account.rb", /validates :name, allow_blank: true/
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
test "generates user model with account association and role" do
|
|
@@ -42,7 +42,7 @@ class Maquina::Generators::RegistrationGeneratorTest < Rails::Generators::TestCa
|
|
|
42
42
|
assert_file "app/models/user.rb", /has_secure_password/
|
|
43
43
|
assert_file "app/models/user.rb", /belongs_to :account/
|
|
44
44
|
assert_file "app/models/user.rb", /enum :role/
|
|
45
|
-
assert_file "app/models/user.rb", /validates :name,
|
|
45
|
+
assert_file "app/models/user.rb", /validates :name, allow_blank: true/
|
|
46
46
|
end
|
|
47
47
|
|
|
48
48
|
test "generates current model with account delegation" do
|
|
@@ -3,10 +3,7 @@ require "rails/all"
|
|
|
3
3
|
|
|
4
4
|
module TestApp
|
|
5
5
|
class Application < Rails::Application
|
|
6
|
-
|
|
7
|
-
# Use Solid Queue as the Active Job backend in all environments except test
|
|
8
|
-
config.active_job.queue_adapter = :solid_queue unless Rails.env.test?
|
|
9
|
-
config.solid_queue.connects_to = {database: {writing: :queue}}
|
|
10
6
|
config.load_defaults 7.2
|
|
7
|
+
config.active_job.queue_adapter = :solid_queue unless Rails.env.test?
|
|
11
8
|
end
|
|
12
9
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: maquina-generators
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.4.
|
|
4
|
+
version: 0.4.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Mario Alberto Chavez
|
|
@@ -84,6 +84,7 @@ files:
|
|
|
84
84
|
- lib/generators/maquina/clave/templates/app/helpers/authentication_helper.rb.tt
|
|
85
85
|
- lib/generators/maquina/clave/templates/app/jobs/authentication_cleanup_job.rb.tt
|
|
86
86
|
- lib/generators/maquina/clave/templates/app/mailers/verification_mailer.rb.tt
|
|
87
|
+
- lib/generators/maquina/clave/templates/app/models/account.rb.tt
|
|
87
88
|
- lib/generators/maquina/clave/templates/app/models/current.rb.tt
|
|
88
89
|
- lib/generators/maquina/clave/templates/app/models/email_verification.rb.tt
|
|
89
90
|
- lib/generators/maquina/clave/templates/app/models/session.rb.tt
|
|
@@ -96,6 +97,7 @@ files:
|
|
|
96
97
|
- lib/generators/maquina/clave/templates/app/views/verification_mailer/verification_code.text.erb.tt
|
|
97
98
|
- lib/generators/maquina/clave/templates/config/locales/clave.en.yml
|
|
98
99
|
- lib/generators/maquina/clave/templates/config/locales/clave.es.yml
|
|
100
|
+
- lib/generators/maquina/clave/templates/migration_create_accounts.rb.tt
|
|
99
101
|
- lib/generators/maquina/clave/templates/migration_create_email_verifications.rb.tt
|
|
100
102
|
- lib/generators/maquina/clave/templates/migration_create_sessions.rb.tt
|
|
101
103
|
- lib/generators/maquina/clave/templates/migration_create_users.rb.tt
|