2016-11-19 10 views
0

投稿を送信するためにユーザーが支払う必要のあるRoRアプリケーションの機能テストを作成しようとしています。ユーザーの旅は、Rails、stripe feature testエラー - paramが見つからないか、値が空です。charge

  1. ユーザーが記事を作成し、ボタンを選択する「支払いに進んで」
  2. ユーザーは、その後、彼らは「カード番号」「カードの確認」と「カードの有効期限」、ユーザーに埋めることができ、課金ページに取られます「支払い」ボタンを押します。支払いはStripeによって処理されます。これはポップアップウィジェットではなくカスタムフォームです。
  3. 成功した場合、ユーザーは

彼らのライブポストにリダイレクトされ、私はポストモデルと電荷モデルを持っています。ポストは一切ありません。投稿はbelongs_to投稿です。支払いは一括払いであり、定期購読ではありません。

マイポストコントローラ(唯一のアクションを作成します):

def create 
    @post = Post.new(post_params) 
    @post.user = current_user 
    @amount = 500 
    if @post.save 
    redirect_to new_post_charge_path(@post.id) 
    else 
    flash[:error] = "There was an error saving the post. Please try again." 
    render :new 
    end 
end 

マイ充電コントローラ(唯一のアクションを作成します):

def create 
    @charge = Charge.new(charge_params) 
    @post = Post.find(params[:post_id]); 
    @charge.post = @post 

    if @charge.save 
     Stripe::Charge.create(
     :amount => 500, 
     :currency => "gbp", 
     :source => params[:charge][:token], 
     :description => "Wikipost #{@post.id}, #{current_user.email}", 
     :receipt_email => current_user.email 
    ) 
     @post.stripe_card_token = @charge.stripe 
     @post.live = true 
     @post.save 

     redirect_to @post, notice: 'Post published successfully' 
    else 
     redirect_to new_post_charge_path(@post.id) 
    end 

    rescue Stripe::CardError => e 
     flash[:error] = e.message 
     return redirect_to new_post_charge_path(@post.id) 
    end 

私はRSpecの/カピバラでテストしていと機能を記述しようとしています以下のようにテストしますが、「paramが見つからないか、値が空です」というエラーが表示され続けます。

require 'rails_helper' 

feature 'Publish post' do 

    before do 
    @user = create(:user) 
    end 

    scenario 'successfully as a registered user', :js => true do 
    sign_in_as(@user) 
    click_link 'New post' 

    expect(current_path).to eq('/posts/new') 
    fill_in 'post_title', with: 'My new post' 
    fill_in 'textarea1', with: 'Ipsum lorem.....' 

    click_button 'Proceed to Payment' 

    expect(page).to have_content('Billing') 

    within 'form#new_charge' do 
     fill_card_details 
     click_button 'Proceed to Payment' 
    end 

    expect(page).to have_content('My new post - published') 
    end 

エラーを修正するか、このユーザーの旅程のテストを作成する最良の方法はありますか?

答えて

1

ストライプの資格情報がテスト環境で設定されていないようです。 fake_stripe gemを使用して、ストライプサーバーへのラウンドトリップを行わないようにすることもできます。

さらにexpect(current_path).to eq('/posts/new')は、新しいパスをチェックするときに待機動作が使用できるようになりますし、テスト妙を削減する

expect(page).to have_current_path('/posts/new') 

のように記述する必要があります。

関連する問題