2011-08-26 2 views
0

이것은 추적 할 수있는 쉬운 것이어야한다 ... 그러나 그것은 나를 위해 그런 식으로 증명되지 않은 :레일 : 오이 보내는 메일을 두 번

을 나는이 다음 오이 시나리오 :

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 

"메일 수를 얻을 수"의 첫 번째 단계는 0을 반환, 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'문은 메일러를 이중 호출합니다. 왜 잘 모르겠지만, 나는 보석을 제거했다 & 모든 것이 잘 동작했다.

관련 문제