2011-08-26 78 views
0

這應該是一個容易追查......但事實證明並沒有對我這樣:的Rails:黃瓜發送郵件兩次

我有以下黃瓜場景:

Scenario: Send mail 
    Given I am a guest 
    When I go to the new_contact page 
    And I fill in "contact_name" with "Test User" 
    And get mail count 
    And I fill in "contact_email" with "[email protected]" 
    And I fill in "contact_message" with "Test Message" 
    And I fill in "contact_phone_num" with "123456789" 
    And I press "Send Message" 
    And get mail count 

除了「接收郵件數」的所有默認的步驟,只是返回:

puts ActionMailer::Base.deliveries.count 

的「收郵件數」的第一步返回零,第二個返回2.運行的ActionMailer :: Base.deliveries確認電子郵件相同(包括g對象標識符)。在我的生活中,我不能確定第二次寄出的來源。實際使用應用程序時,郵件只能通過一次。以下相關代碼:

控制器:

class ContactsController < ApplicationController 

    def new 
    @contact = Contact.new 
    @pagetitle = "Contact Us" 
    if (current_user) then 
     @contact.name = "#{current_user.first_name} #{current_user.last_name}" 
     @contact.email = current_user.email 
    end 
    end 

    def create 
    @contact = Contact.new(params[:contact]) 
     if @contact.save 
     contactmailer = ContactMailer 
     puts 'here now' 
     contactmailer.contact_message(@contact).deliver 
     redirect_to contact_thanks_url, notice: 'Contact was successfully created.' 
     else 
     render action: "new" 
     end 
    end 

    def thanks 

    end 
end 

梅勒:

class ContactMailer < ActionMailer::Base 

    def contact_message(contact) 
    @contact = contact 
    mail(:to => ENV['MANAGER_EMAIL'], :from => @contact.email, :subject => t(:business_name), :content_type => 'text/plain') 
    end 

end 

黃瓜配置文件:萬一有人

BC::Application.configure do 
    require 'ruby-debug' 
    config.cache_classes = true 
    config.use_transactional_fixtures = true 

    config.serve_static_assets = true 
    config.static_cache_control = "public, max-age=3600" 

    config.whiny_nils = true 

    config.consider_all_requests_local  = true 
    config.action_controller.perform_caching = false 

    config.action_dispatch.show_exceptions = false 

    config.action_controller.allow_forgery_protection = false 

    config.action_mailer.delivery_method = :test 

    config.active_support.deprecation = :stderr 

    config.action_mailer.default_url_options = { :host => 'localhost:3000' } 
    config.action_mailer.raise_delivery_errors = true 
    config.action_mailer.perform_deliveries = true 

    ENV['MANAGER_EMAIL'] = '[email protected]' 

end 

回答

1

回答是否有同樣的問題:

鄂麥l_spec寶石。 support/features/env.rb中的'require'語句是雙重調用郵件程序。爲什麼我不確定,但我卸載了寶石&一切工作正常。