2011-08-26 3 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 

「メールカウントを取得」の最初のステップはゼロを返し、2はactionmailerの実行秒戻り:: Base.deliveries電子メールがある確認し、同一(includin gオブジェクト識別子)。私の人生のために、そのセカンドセンドがどこから来ているのか分かりません。実際にアプリを使用しているときは、メールは1回だけ送信されます。関連以下のコード:

コントローラー:

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 gem。 support/features/env.rbの 'require'ステートメントは、メーラーをダブルコールしていました。なぜ私は確かではないが、私は宝石をアンインストール&すべて正常に働いた。