के साथ समाप्त होता है मुझे एक्शनमेलर की mail
विधि ओवरराइड करने की आवश्यकता है। इस विधि सुरक्षित है तो उपवर्ग में, मैं भी mail
पद्धति के रूप में संरक्षित परिभाषित:ईमेल पता भेजने से बचने का प्रयास करते समय ईमेल पता ".old"
protected
def mail(headers={}, &block)
#add a check to avoid sending emails that end with ".old"
unless headers[:to] =~ /\.old$/
super(headers, &block)
end
end
इस तरह, एक निवर्तमान ईमेल पता .old
साथ समाप्त होता है जब, विधि शून्य लौटना चाहिए और एक ईमेल भेज नहीं।
लेकिन, मेरा इकाई परीक्षण में, ऐसा लगता है कि एक ईमेल अभी भी अपने इकाई परीक्षण ActionMailer::Base.deliveries
यहाँ जा रहा है है:
describe 'BaseNotifier' do
class TestNotifier < BaseNotifier
def mailer(to, from, subject)
mail(:to => to,
:from => from,
:subject => subject)
end
end
before(:each) do
ActionMailer::Base.delivery_method = :test
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.deliveries.clear
end
it "should not send emails to a user with an email that ends in '.old'" do
TestNotifier.mailer("[email protected]", "[email protected]", "test email").deliver
puts "what do we have here " + ActionMailer::Base.deliveries.first.to_s
ActionMailer::Base.deliveries.length.should == 0
end
end
मैं एक परीक्षण वर्ग बना सकते हैं और वर्ग उपवर्ग जहां मेल है ओवरराइड (इस तरह यह सिस्टम में इस्तेमाल किया जाएगा)। मैं फिर एक ईमेल करता हूं और .deliver
विधि को कॉल करता हूं।
अद्यतन: मुझे लगता है कि वितरण विधि समस्या नहीं है। जब मैं ऐसा करता हूं: puts TestNotifier.mailer("[email protected]", "[email protected]", "test email")
मुझे नीचे जैसा ही ईमेल संदेश मिलता है। मैं भी इस तरह से मेल विधि ओवरराइड करने की कोशिश की:
def mail(headers={}, &block)
#add a check to avoid sending emails that end with ".old"
unless headers[:to] =~ /\.old$/
super(headers, &block)
else
super({:to=>nil, :from=>nil, :boundary =>nil, :date => nil, :message =>nil, :subject =>nil, :mime_version => nil,
:content_type => nil, :charset =>nil, :content_transfer_encoding => nil}, &block)
end
end
जो मुझे इस लाइन पर undefined method 'ascii_only?' for nil:NilClass
के साथ एक विफलता देता है: TestNotifier.mailer("[email protected]", "[email protected]", "test email").deliver
अद्यतन: मैं भी अधिरोहित mail
विधि के साथ ऐसा करने की कोशिश की है:
# एक वर्ग बनाएं जो कुछ भी करने के लिए वितरण विधि को ओवरराइड करता है। कक्षा NonSendingEmail; डिफ डिलीवरी; समाप्त; (हेडर = {}, & ब्लॉक) एक चेक #Add ईमेल कि के साथ समाप्त भेजने से बचने का अंत
डीईएफ़ मेल ".old" जब तक हेडर [: करने के लिए] = ~ /.old$/ सुपर (हेडर , & ब्लॉक) बाकी NonSendingEmail.new अंत अंत
लेकिन मैं अभी भी एक ही परिणाम हो रही है।
ऐसा लगता है कि मैं जो करना चाहता हूं उसके पास कुछ भी उत्पन्न नहीं हुआ है। डिलिवरीज सरणी से ईमेल यहां दिया गया है:deliver
विधि एक खाली ईमेल उत्पन्न कर रहा है?
Date: Thu, 19 Jan 2012 00:00:00 +0000
Message-ID: <[email protected]>
Mime-Version: 1.0
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
मुझे लगता है कि समस्या यह है कि instanciate ** इसकी मेलर वर्ग रेल है ** और आपकी नहीं हैं, तो अपने मेलर वर्ग शायद यह भी नहीं –
प्रयोग किया जाता है @ आग-ड्रैगन-राजभाषा विभाग, जब/जहां रेल का दृष्टांत करता है इसकी मेलर कक्षा? जब आप कहते हैं कि मेरी मेलर क्लास का उपयोग नहीं किया जा सकता है तो कौन सा मेलर वर्ग का मतलब है? 'TestNotifier.mailer'? या ओवरराइड 'मेल' विधि? – Ramy
नहीं, मेरा मतलब है एक्शनमेलर क्लास, मुझे वास्तव में पता नहीं है कि यह कहां से निकाला गया है, लेकिन हो सकता है कि रेल एक्शनमेलर क्लास को अस्थिर रखें, न कि YourActionMailer.new। ध्यान रखें कि मैं ** ** का अनुमान लगा रहा हूं अन्यथा मैं इसे उत्तर के रूप में पोस्ट कर दूंगा, लेकिन उम्मीद है कि यह टिप्पणी आपको –