2012-03-21 12 views
3

私は、次のRSpecのファイルを持っている:RSpecの要求スペックのテストモデル属性

describe "Cart" do 
    before do 
    @user = FactoryGirl.create(:user) 
    @cart = @user.carts.create! 
    end 

describe "using stripe" do 
    before do 
    @sport = FactoryGirl.create(:sport) 
    end 

    describe "user adds sport to cart" do 
    before do 
     visit sports_path 
     click_link "Add to Cart" 
    end 

    it "should be checkout page" do 
     page.should have_content("Total") 
    end 

    describe "user clicks checkout" do 
     before do 
     click_button "Checkout" 
     end 

     it "should redirect user to sign in form" do 
     page.should have_selector('h2', text: "Sign in") 
     end 

     describe "user logs on" do 
     before do 
      fill_in "Email", with: @user.email 
      fill_in "Password", with: @user.password 
      click_button "Sign in" 
     end 

     it "should be on checkout page" do 
      page.should have_selector('h2', text: "Checkout") 
     end 

     describe "user fills in form", js: true, driver: :webkit do 

      describe "everything valid" do 
      before do 
       fill_in "card-number", with: 4242424242424242 
       fill_in "card-expiry-month", with: 12 
       fill_in "card-expiry-year", with: 2015 
       fill_in "card-cvc", with: 123 
       click_button "Submit Payment" 
      end 

      it "should redirect to confirmation page" do 
       page.should have_content("Confirmation") 
      end 

      it "should have the total price listed" do 
       page.should have_content(@cart.total_price) 
      end 

      it "should create a stripe customer and save that to the stripe_customer_id of the user" do 
       @user.stripe_customer_id.should_not be_nil 
      end 

      describe "should allow user authorize charge" do 
       before do 
       click_button "Confirm and Purchase" 
       end 

       it "should be back to sports page" do 
       page.should have_content("Select a Sport") 
       end 
      end 


      end 
     end 
     end 
    end 
    end 
end 

ので(FactoryGirlによって作成された)ユーザーが自分のサイトから何かを購入。

should create a stripe customer and save that to the stripe_customer_id of the userが失敗しています(@user.stripe_customer_idnil)。

コントローラは、この方法があります

def confirmation 
    @cart = current_cart 
    customer = Stripe::Customer.create(description: current_user.email, card: params[:stripeToken]) 
    current_user.update_attributes(stripe_customer_id: customer.id) 
end 

Iは、他のテストが働いているため、CURRENT_USER(試験用FactoryGirlから同じユーザ)stripe_customer_idで更新されて知っています。

私はデータベースに直接影響を与えていたため、何らかの形でモデルを更新する必要があると仮定しました(@userとcurrent_userは同じdbエントリを参照しますが、同じオブジェクトではありません)。だから、stripe_customer_idがnilだったかどうかをチェックする前に@user.reloadを呼び出してみましたが、テストはまだ失敗しました。

2つの質問:リクエスト仕様でモデル属性をチェックする必要がありますか?そして、失敗するテストをパスする方法がありますか?

おかげ

+0

この仕様の新しいユーザーオブジェクトを読み込もうとしましたか? @user2 = User.find_by_id(@ user.id) –

答えて

1

私はあなたがWebKitのドライバを使用している参照して、その問題は、トランザクションのセットアップにあるかもしれません。 config.use_transactional_fixturesspec_helperでオフにしましたか?また、Capybara Readme(トランザクションとデータベースのセットアップ)

関連する問題