web47core 0.0.8 → 0.0.9

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.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +0 -14
  3. data/Gemfile.lock +30 -9
  4. data/README.md +27 -4
  5. data/lib/app/models/concerns/app47_logger.rb +175 -0
  6. data/lib/app/models/concerns/core_account.rb +51 -0
  7. data/lib/app/models/concerns/standard_model.rb +104 -6
  8. data/lib/app/models/email_notification.rb +253 -0
  9. data/lib/app/models/email_template.rb +6 -0
  10. data/lib/app/models/notification.rb +276 -0
  11. data/lib/app/models/notification_template.rb +20 -0
  12. data/lib/app/models/slack_notification.rb +89 -0
  13. data/lib/app/models/sms_notification.rb +56 -0
  14. data/lib/app/models/smtp_configuration.rb +148 -0
  15. data/lib/app/models/template.rb +21 -0
  16. data/lib/templates/email/notification_failure.liquid +10 -0
  17. data/lib/templates/email/notification_failure.subject.liquid +1 -0
  18. data/lib/templates/slack/error_message.liquid +1 -0
  19. data/lib/web47core.rb +10 -2
  20. data/test/factories/account_factories.rb +9 -0
  21. data/test/factories/notification_factories.rb +14 -0
  22. data/test/models/app47_logger_test.rb +88 -0
  23. data/test/models/concerns/{formable_test.rb → standard_model_test.rb} +24 -5
  24. data/test/models/email_notification_test.rb +297 -0
  25. data/test/models/notification_test.rb +127 -0
  26. data/test/models/slack_notification_test.rb +50 -0
  27. data/test/notification_test_helper.rb +146 -0
  28. data/test/rails_setup.rb +4 -0
  29. data/test/test_helper.rb +10 -4
  30. data/test/test_models_helper.rb +14 -0
  31. data/web47core.gemspec +5 -2
  32. metadata +87 -14
  33. data/lib/app/models/concerns/auto_clear_cache.rb +0 -34
  34. data/lib/app/models/concerns/formable.rb +0 -111
  35. data/test/models/concerns/auto_clear_cache_test.rb +0 -27
@@ -1,111 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- #
4
- # For models that are updated via forms, we need an easy and consistent way to
5
- # return a list of allowed parameters for a given model. While doing Model.attribute_names
6
- # is working for most forms, it DOES NOT deal with relationships at all.
7
- #
8
- # This mix is should be included in those models, and the model then calls
9
- # Model.allowed_param_names to retrieve a complete (dynamic) list of
10
- # * Attribute names
11
- # * Many to many relationships (has_many_and_belongs_to)
12
- # * One to many relationships (belongs to)
13
- #
14
- module Formable
15
- extend ActiveSupport::Concern
16
- #
17
- # Include the class methods into the model
18
- #
19
- def self.included(base)
20
- base.class_eval do
21
- base.extend ClassMethods
22
- end
23
- end
24
-
25
- #
26
- # Public: Add to class methods
27
- #
28
- module ClassMethods
29
- #
30
- # Return the complete list of key names that would appear in the form.
31
- #
32
- def allowed_param_names(filter_names = [])
33
- # Always filter out the mongoid reserved items
34
- filter_names += %w[created_at updated_at _type _id]
35
- associations = all_associations
36
- # filter out the relationship names so we don't have dups
37
- associations.each { |association| filter_names << association.keys.first }
38
- (field_names + associations).delete_if { |name| filter_names.include?(name) }
39
- rescue StandardError
40
- attribute_names.delete_if { |name| filter_names.include?(name) }
41
- end
42
-
43
- #
44
- # allow the model to filter out a name if they want to, meaning the model
45
- # can return a subset of attribute names
46
- #
47
- def field_names
48
- attribute_names
49
- end
50
-
51
- #
52
- # gather up the collections we care about and return them. For now, the
53
- # many to many associations are the ones that need some extra help.
54
- #
55
- def all_associations
56
- many_to_many_associations
57
- end
58
-
59
- #
60
- # Return a collection of many to many assocations. We basically
61
- # need to turn the current value returned by attribute names
62
- #
63
- # relationship_ids
64
- #
65
- # to
66
- #
67
- # { relationship_ids => [] }
68
- #
69
- # Telling the permit command to accept the value as an array of items.
70
- #
71
- def many_to_many_associations
72
- associations = []
73
- reflect_on_all_associations.each do |association|
74
- next unless association.macro == :has_and_belongs_to_many
75
-
76
- associations << { association.key => [] }
77
- end
78
- associations
79
- end
80
- end
81
-
82
- #
83
- # Remove updates for secure fields that come across as blank to start with and get removed on update
84
- #
85
- def update(params)
86
- super(remove_blank_secure_fields(params))
87
- end
88
-
89
- alias :update_attributes :update
90
-
91
- #
92
- # Remove updates for secure fields that come across as blank to start with and get removed on update
93
- #
94
- def update!(params)
95
- super(remove_blank_secure_fields(params))
96
- end
97
-
98
- alias :update_attributes! :update!
99
-
100
- #
101
- # List of secure fields, to add fields in concrete class, simply override this method
102
- #
103
- def secure_fields
104
- []
105
- end
106
-
107
- def remove_blank_secure_fields(params)
108
- secure_fields.each { |field| params.delete(field) if params[field].blank? }
109
- params
110
- end
111
- end
@@ -1,27 +0,0 @@
1
- require 'test_helper'
2
-
3
- # TODO: CMS add tests for clearing by account id as well as id
4
- class AutoClearCacheTest < ActiveSupport::TestCase
5
- setup do
6
- @model = TestAutoClearCache.new
7
- assert @model.save
8
- @model.update_cache
9
- end
10
-
11
- context 'Remove cache on save' do
12
- should 'return the original url' do
13
- assert Rails.cache.exist? @model.id.to_s
14
- assert @model.save
15
- refute Rails.cache.exist? @model.id.to_s
16
- end
17
- end
18
- end
19
-
20
- class TestAutoClearCache
21
- include Mongoid::Document
22
- include AutoClearCache
23
-
24
- def update_cache(value = 'abc123')
25
- Rails.cache.write id.to_s, value, expires_in: 60
26
- end
27
- end