2016-10-19 4 views
0

私は MailForm Gem を使用して、自分のアプリケーションの連絡フォームを作成しています。すべてがうまくいっているように見えます。第三は、メッセージRails MailForm Gemのcaptcha検証でテストに合格しない

FAIL["test_should_not_send_contact_email_with_captcha_filled", ContactsControllerTest, 5.2574800989968935] 
    test_should_not_send_contact_email_with_captcha_filled#ContactsControllerTest (5.26s) 
    Expected: 0 
     Actual: 1 
    test/controllers/contacts_controller_test.rb:35:in `block in <class:ContactsControllerTest>' 

私のモデルはこのようになりますと失敗しながら、最初の2つのテストに合格

class ContactsControllerTest < ActionDispatch::IntegrationTest 
    def setup 
    ActionMailer::Base.deliveries.clear 
    end 

    test "should send contact email" do 
    get contact_path 
    post contacts_path, params: { contact: { 
       name: "interested customer", 
       email: "[email protected]", 
       subject: "we are interested!", 
       message: "we are so interested!!!" 
    }} 
    assert_equal 1, ActionMailer::Base.deliveries.size 
    assert_redirected_to root_path 
    end 

    test "should not send invalid contact email" do 
    get contact_path 
    post contacts_path, params: { contact: { 
       name: "", 
       email: "", 
       subject: "", 
       message: "" 
    }} 
    assert_equal 0, ActionMailer::Base.deliveries.size 
    assert_template 'contacts/new' 

    end 

    test "should not send contact email with captcha filled" do 
    get contact_path 
    post contacts_path, params: { contact: { 
       name: "interested customer", 
       email: "[email protected]", 
       subject: "we are interested!", 
       message: "we are so interested!!!", 
       nickname: "not_blank" 
    }} 
    assert_equal 0, ActionMailer::Base.deliveries.size 
    assert_template 'contacts/new' 
    end 

class Contact < MailForm::Base 
    attribute :name,  :validate => true 
    attribute :email,  :validate => /\A([\w\.%\+\-]+)@([\w\-]+\.)+ ([\w]{2,})\z/i 
    attribute :subject 
    attribute :message 
    attribute :nickname, :captcha => true 

    def headers 
    { 
     :subject => "Contact: #{subject}" , 
     :to => "[email protected]", 
     :from => %("#{name}" <#{email}>) 
    } 
    end 
end 

私の最初の考えは、キャプチャの検証がメールの送信を停止していないということでした。誰かが私が見逃していることを指摘できたら、私はそれを感謝します。

答えて

0

ニックネームが指定されていても、mailformモデルは有効です。メールが送信されないようにするスパムかどうかを確認できます。 これを使用して、スパム検出が機能するかどうかを確認します(rspecを使用):

it 'should be marked spam if it contains :nickname' do 
expect(FactoryGirl.build(:contact_with_nickname)).to be_spam 
end 
関連する問題