diff options
| author | Xinhui | 2017-07-07 16:04:00 +0200 | 
|---|---|---|
| committer | Xinhui | 2017-07-07 16:04:38 +0200 | 
| commit | c427e5f8b87e715335c91a47f5fd9e0e09234048 (patch) | |
| tree | 948501e0e3533e8414bcce8c7882a14358165bd5 | |
| parent | 6f06b32a423abe8fb6ae7e69589eaa72d5dfe728 (diff) | |
| download | chouette-core-c427e5f8b87e715335c91a47f5fd9e0e09234048.tar.bz2 | |
Refactoring calendar mailer move users query into observer
| -rw-r--r-- | app/mailers/calendar_mailer.rb | 14 | ||||
| -rw-r--r-- | app/models/user.rb | 3 | ||||
| -rw-r--r-- | spec/mailers/calendar_mailer_spec.rb | 2 | 
3 files changed, 7 insertions, 12 deletions
| diff --git a/app/mailers/calendar_mailer.rb b/app/mailers/calendar_mailer.rb index f9189371e..44dcaea88 100644 --- a/app/mailers/calendar_mailer.rb +++ b/app/mailers/calendar_mailer.rb @@ -1,15 +1,9 @@  class CalendarMailer < ApplicationMailer -  def updated calendar -    users = User.all -    users.each do |u| -      mail to: u.email, subject: t('mailers.calendar_mailer.updated.subject') -    end +  def updated calendar, user +    mail to: user.email, subject: t('mailers.calendar_mailer.updated.subject')    end -  def created calendar -    users = User.all -    users.each do |u| -      mail to: u.email, subject: t('mailers.calendar_mailer.created.subject') -    end +  def created calendar, user +    mail to: user.email, subject: t('mailers.calendar_mailer.created.subject')    end  end diff --git a/app/models/user.rb b/app/models/user.rb index 14ab478a8..5a2e4d3ca 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -15,7 +15,6 @@ class User < ActiveRecord::Base    # Setup accessible (or protected) attributes for your model    # attr_accessible :email, :password, :current_password, :password_confirmation, :remember_me, :name, :organisation_attributes    belongs_to :organisation -    accepts_nested_attributes_for :organisation    validates :organisation, :presence => true @@ -28,6 +27,8 @@ class User < ActiveRecord::Base    end    after_destroy :check_destroy_organisation +  scope :with_organisation, -> { where.not(organisation_id: nil) } +    def self.destructive_permissions_for(models)      models.product( %w{create destroy update} ).map{ |model_action| model_action.join('.') }    end diff --git a/spec/mailers/calendar_mailer_spec.rb b/spec/mailers/calendar_mailer_spec.rb index 75241b063..d41092461 100644 --- a/spec/mailers/calendar_mailer_spec.rb +++ b/spec/mailers/calendar_mailer_spec.rb @@ -5,7 +5,7 @@ RSpec.describe CalendarMailer, type: :mailer do    shared_examples 'notify all user' do |type|      let!(:user)    { create(:user) }      let(:calendar) { create(:calendar, shared: true) } -    let(:email)    { CalendarMailer.send(type, calendar) } +    let(:email)    { CalendarMailer.send(type, calendar, user) }      it 'should deliver email to user' do        expect(email).to deliver_to user.email | 
