pg_rails 7.6.16 → 7.6.17

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: f1be39ed176491e2f5da66a9a1764f6c2f8c8509c7510999f72007cd0a1bb0f7
4
- data.tar.gz: 591fe03520a040b5651b3a8153d7bdc7bc42afd6c8b6b44cfbf5a6525d883e89
3
+ metadata.gz: a05ebc7aa2578ab2c32a72e68dc56b958aa0787216c6703764af4d906eba4aff
4
+ data.tar.gz: 43e3d8a43d5d4b6b490de9aec4f1b122051905c81c40f699868e2015b2db314f
5
5
  SHA512:
6
- metadata.gz: 06c346252f40b648dc108ada25a3a4ab7dda9cb8ead20964d835aa19231063b165e56c2565d7b854ca8aa073245346c7b269852e4f392ae5d1139acef3cbe629
7
- data.tar.gz: 619cc8ab8f5ef3ab61f8e825b9c3ca3ba8767a77ee35ebe7e0f6dc23add99b33075d8049f89f2022d42417a94b06ec19c81fc5b36fb8271d42132183d32fce08
6
+ metadata.gz: 2c9d7e326b078d50d6b5e7b8ac04f8aecfbe6217d6eb5d6984139cf1a9a9ab4f8f06e423e2b2babbfbd51266100bdd6191960a79d4b7a9a2c351f8647d3493a4
7
+ data.tar.gz: dea6b0686fe63c661a129b17a880d4158fec6fcc0430e96aaaace4444fddffd84818dabd164dee2523906824babded554cb0a10c49ed419da73b8d2c4a44baff
@@ -17,25 +17,25 @@ module Admin
17
17
 
18
18
  # rubocop:disable Metrics/MethodLength
19
19
  def create
20
- @event = SimpleUserNotifier.new(modelo_params)
21
- # @event.message.save!
22
- unless @event.valid?
20
+ @simple_user_notifier = SimpleUserNotifier.new(modelo_params)
21
+ # @simple_user_notifier.message.save!
22
+ unless @simple_user_notifier.valid?
23
23
  render :new, status: :unprocessable_entity
24
24
  return
25
25
  end
26
26
  json_params_for_event = {
27
- message: @event.message,
28
- tooltip: @event.tooltip
27
+ message: @simple_user_notifier.message,
28
+ tooltip: @simple_user_notifier.tooltip
29
29
  }
30
30
  notifier = SimpleUserNotifier.with(json_params_for_event)
31
31
 
32
- case @event.target
32
+ case @simple_user_notifier.target
33
33
  when 'todos'
34
34
  notifier.deliver(User.all)
35
35
  when 'devs'
36
36
  notifier.deliver(User.where(developer: true))
37
37
  when 'user_ids'
38
- notifier.deliver(User.where(email: @event.user_ids.split(',')))
38
+ notifier.deliver(User.where(email: @simple_user_notifier.user_ids.split(',')))
39
39
  else
40
40
  # :nocov:
41
41
  'shouldnt happen'
@@ -46,6 +46,7 @@ module Admin
46
46
  rescue StandardError => e
47
47
  # :nocov:
48
48
  flash.now[:alert] = e.to_s
49
+ # @simple_user_notifier = @simple_user_notifier.decorate
49
50
  render :new, status: :unprocessable_entity
50
51
  # :nocov:
51
52
  end
@@ -0,0 +1,50 @@
1
+ module PgEngine
2
+ module Naming
3
+ def gender
4
+ self.class.model_name.human.downcase.ends_with?('a') ? 'f' : 'm'
5
+ end
6
+
7
+ def self.included(base)
8
+ base.extend(ClassMethods)
9
+ end
10
+
11
+ module ClassMethods
12
+ # This is a per class variable, all subclasses of BaseRecord inherit it
13
+ # BUT **the values are independent between all of them**
14
+ attr_accessor :default_modal, :inline_editable_fields
15
+
16
+ def inline_editable?(attribute)
17
+ inline_editable_fields.present? && inline_editable_fields.include?(attribute.to_sym)
18
+ end
19
+
20
+ def ransackable_associations(_auth_object = nil)
21
+ authorizable_ransackable_associations
22
+ end
23
+
24
+ def ransackable_attributes(_auth_object = nil)
25
+ authorizable_ransackable_attributes
26
+ end
27
+
28
+ def nombre_plural
29
+ model_name.human(count: 2)
30
+ end
31
+
32
+ def nombre_singular
33
+ model_name.human(count: 1)
34
+ end
35
+
36
+ def human_attribute_name(attribute, options = {})
37
+ # Remove suffixes
38
+ if attribute.to_s.ends_with?('_text')
39
+ # Si es un enumerized
40
+ super(attribute[0..-6], options)
41
+ elsif attribute.to_s.ends_with?('_f')
42
+ # Si es un decorated method
43
+ super(attribute[0..-3], options)
44
+ else
45
+ super
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -7,58 +7,17 @@ module PgEngine
7
7
  extend Enumerize
8
8
  include PrintHelper
9
9
  include PostgresHelper
10
+ include Naming
10
11
 
11
12
  self.abstract_class = true
12
13
 
13
14
  before_create :setear_creado_y_actualizado_por
14
15
  before_update :setear_actualizado_por
15
16
 
16
- class << self
17
- # This is a per class variable, all subclasses of BaseRecord inherit it
18
- # BUT **the values are independent between all of them**
19
- attr_accessor :default_modal, :inline_editable_fields
20
-
21
- def inline_editable?(attribute)
22
- inline_editable_fields.present? && inline_editable_fields.include?(attribute.to_sym)
23
- end
24
- end
25
-
26
17
  # ransacker :search do |parent|
27
18
  # parent.table[:nombre]
28
19
  # end
29
20
 
30
- def self.ransackable_associations(_auth_object = nil)
31
- authorizable_ransackable_associations
32
- end
33
-
34
- def self.ransackable_attributes(_auth_object = nil)
35
- authorizable_ransackable_attributes
36
- end
37
-
38
- def gender
39
- self.class.model_name.human.downcase.ends_with?('a') ? 'f' : 'm'
40
- end
41
-
42
- def self.nombre_plural
43
- model_name.human(count: 2)
44
- end
45
-
46
- def self.nombre_singular
47
- model_name.human(count: 1)
48
- end
49
-
50
- def self.human_attribute_name(attribute, options = {})
51
- if attribute.to_s.ends_with?('_text')
52
- # Si es un enumerized
53
- super(attribute[0..-6], options)
54
- elsif attribute.to_s.ends_with?('_f')
55
- # Si es un decorated method
56
- super(attribute[0..-3], options)
57
- else
58
- super
59
- end
60
- end
61
-
62
21
  def actions_component
63
22
  ActionsComponent.new(self)
64
23
  end
@@ -46,4 +46,8 @@ class SimpleUserNotifier < ApplicationNotifier
46
46
  def self.policy_class
47
47
  ApplicationPolicy
48
48
  end
49
+
50
+ def self.decorator_class
51
+ PgEngine::BaseRecordDecorator
52
+ end
49
53
  end
@@ -1,4 +1,4 @@
1
- = pg_form_for @simple_user_notifier do |f|
1
+ = pg_form_for @simple_user_notifier.decorate do |f|
2
2
  - if params[:plain_text]
3
3
  = link_to 'Change to rich text', url_for
4
4
  = f.input :message, as: :text
@@ -27,6 +27,10 @@ module PgEngine
27
27
  ActsAsTenant.without_tenant(&)
28
28
  end
29
29
  end
30
+ Noticed::ApplicationRecord.class_eval do
31
+ extend Enumerize
32
+ include PgEngine::Naming
33
+ end
30
34
  end
31
35
 
32
36
  initializer 'pg_engine.set_exceptions_app' do
@@ -12,4 +12,16 @@ describe PgEngine::BaseRecord do
12
12
  expect(obj).to eq described_class.human_attribute_name('bla')
13
13
  end
14
14
  end
15
+
16
+ describe '#default_modal' do
17
+ it 'the values are independent from each class' do
18
+ model_class = Class.new(described_class)
19
+ another_model_class = Class.new(described_class)
20
+ model_class.default_modal = true
21
+ another_model_class.default_modal = false
22
+ expect(model_class.default_modal).to be true
23
+ expect(another_model_class.default_modal).to be false
24
+ expect(described_class.default_modal).to be_nil
25
+ end
26
+ end
15
27
  end
@@ -16,28 +16,23 @@ describe 'Eventos' do
16
16
  end
17
17
 
18
18
  it 'renders the event index' do
19
- get '/a/eventos'
19
+ get '/a/simple_user_notifiers'
20
20
 
21
- expect(response.body).to include 'New post'
21
+ expect(response.body).to include 'Crear simple user notifier'
22
22
  end
23
23
 
24
24
  describe 'posting events' do
25
25
  subject do
26
- get '/a/eventos/new'
26
+ get '/a/simple_user_notifiers/new'
27
27
  expect(response.body).to include 'Tooltip'
28
- post '/a/eventos', params: {
29
- evento: {
30
- type:,
28
+ post '/a/simple_user_notifiers', params: {
29
+ simple_user_notifier: {
31
30
  message: 'hola',
32
- message_text:,
33
- subject: asunto,
34
31
  user_ids:,
35
- record_type: 'User',
36
- record_id:,
37
32
  target:
38
33
  }
39
34
  }
40
- get "/a/eventos/new?event_id=#{Noticed::Event.last.id}"
35
+ # get "/a/eventos/new?event_id=#{Noticed::Event.last.id}"
41
36
  end
42
37
 
43
38
  let(:record_id) { nil }
@@ -83,10 +78,9 @@ describe 'Eventos' do
83
78
 
84
79
  context 'cuando hay error' do
85
80
  subject do
86
- post '/a/eventos', params: {
87
- evento: {
88
- type:,
89
- message: 'hola',
81
+ post '/a/simple_user_notifiers', params: {
82
+ simple_user_notifier: {
83
+ message: nil,
90
84
  target:
91
85
  }
92
86
  }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PgRails
4
- VERSION = '7.6.16'
4
+ VERSION = '7.6.17'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.6.16
4
+ version: 7.6.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martín Rosso
@@ -743,6 +743,7 @@ files:
743
743
  - pg_engine/app/mailers/pg_engine/base_mailer.rb
744
744
  - pg_engine/app/mailers/pg_engine/user_mailer.rb
745
745
  - pg_engine/app/models/account.rb
746
+ - pg_engine/app/models/concerns/pg_engine/naming.rb
746
747
  - pg_engine/app/models/current.rb
747
748
  - pg_engine/app/models/email.rb
748
749
  - pg_engine/app/models/email_log.rb