[Git][noosfero/noosfero][master-1.x] 6 commits: Add migrate to validate phone fields

Rodrigo Souto gitlab at mg.gitlab.com
Tue Jul 31 16:37:55 BRT 2018


Rodrigo Souto pushed to branch master-1.x at Noosfero / noosfero


Commits:
8dac00b5 by Iasmin Mendes at 2018-07-16T14:48:56Z
Add migrate to validate phone fields

- - - - -
1afd6fbe by Iasmin Mendes at 2018-07-24T14:47:52Z
Validate person before sending the emails

- - - - -
96056bb2 by Iasmin Mendes at 2018-07-24T14:50:36Z
Remove recreation from job in PersonNotifier after failure

- - - - -
864c6343 by Iasmin Mendes at 2018-07-24T16:00:42Z
Change test to validate if don't create a new job when failed

- - - - -
a1152bce by Iasmin Mendes at 2018-07-31T15:37:59Z
Fix phone length

- - - - -
55ccdd52 by Rodrigo Souto at 2018-07-31T19:37:52Z
Merge branch 'invalid_person' into 'master-1.x'

Validate old phone fields and check person before send notifications

See merge request noosfero/noosfero!1578
- - - - -


3 changed files:

- app/models/person_notifier.rb
- + db/migrate/20180716142038_change_phone_fields_to_valid_format.rb
- test/unit/person_notifier_test.rb


Changes:

=====================================
app/models/person_notifier.rb
=====================================
@@ -34,8 +34,12 @@ class PersonNotifier
       notifications = @person.tracked_notifications.where("created_at > ?", notify_from)
       tasks = Task.to(@person).without_spam.pending.where("created_at > ?", notify_from).order_by('created_at', 'asc')
 
-      Noosfero.with_locale @person.environment.default_language do
-        Mailer::content_summary(@person, notifications, tasks).deliver unless notifications.empty? && tasks.empty?
+      if @person.valid?
+        Noosfero.with_locale @person.environment.default_language do
+          unless notifications.empty? && tasks.empty?
+            Mailer::content_summary(@person, notifications, tasks).deliver
+          end
+        end
       end
       @person.settings[:last_notification] = DateTime.now
       @person.save!
@@ -66,11 +70,6 @@ class PersonNotifier
       Person.find(person_id).notifier.notify
     end
 
-    def failure(job)
-      person = Person.find(person_id)
-      person.notifier.dispatch_notification_mail
-    end
-
   end
 
   class Mailer < ApplicationMailer


=====================================
db/migrate/20180716142038_change_phone_fields_to_valid_format.rb
=====================================
@@ -0,0 +1,20 @@
+class ChangePhoneFieldsToValidFormat < ActiveRecord::Migration
+  def change
+    Person.find_each do |person|
+      unless person.valid?
+        Person::PHONE_FIELDS.each do |field|
+          phone = person.send(field)
+          if phone.present? && phone !~ Person::PHONE_FORMAT
+            field = field.to_s + "="
+            phone = phone.gsub(/\D/, '')
+            phone = phone.rjust(5, '0') if phone.length < 5
+            phone = phone[0, 15] if phone.length > 15
+            person.send(field, phone)
+          end
+        end
+        p person.name
+        person.save(validate: false)
+      end
+    end
+  end
+end


=====================================
test/unit/person_notifier_test.rb
=====================================
@@ -246,15 +246,15 @@ class PersonNotifierTest < ActiveSupport::TestCase
     assert_equal 1, Delayed::Job.count
   end
 
-  should 'NotifyJob failed jobs create a new NotifyJob on failure' do
+  should 'don\'t create a new NotifyJob on failure' do
     Delayed::Worker.max_attempts = 1
     Delayed::Job.enqueue(PersonNotifier::NotifyJob.new(@member.id))
 
     PersonNotifier.any_instance.stubs(:notify).raises('error')
 
-    process_delayed_job_queue
-    jobs = PersonNotifier::NotifyJob.find(@member.id)
-    refute jobs.select {|j| !j.failed? && j.last_error.nil? }.empty?
+    assert_no_difference 'job_count(PersonNotifier::NotifyJob)' do
+      process_delayed_job_queue
+    end
   end
 
   should 'render image tags for both internal and external src' do



View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/dad2ebed930f4e56f417c6f0e0c48534f01b7408...55ccdd52a7d905563d3df928f4e648f7b328d472

-- 
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/dad2ebed930f4e56f417c6f0e0c48534f01b7408...55ccdd52a7d905563d3df928f4e648f7b328d472
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20180731/2468897e/attachment-0001.html>


More information about the Noosfero-dev mailing list