2012-06-11 51 views
1

使用minitest,測試此build_plan方法的最佳方法是什麼?使用minitest測試Rails控制器方法

我目前的嘗試是嘗試驗證@ account.plan正在設置,但我不能完全弄清楚如何做到這一點。這是我應該試圖做的,還是別的?

accounts_controller.rb

class AccountsController < ApplicationController 

    before_filter :build_plan, :only => [:new, :create] 

    def build_plan 
    redirect_to '/app/signup' and return unless @plan = SubscriptionPlan.find_by_name(params[:plan]) 
    @plan.discount = @discount 
    @account.plan = @plan 
    end 
end 

account_integration_test.rb

require 'minitest_helper' 

describe "Account integration" do 

    before do 
    @account = Factory.build(:account) 
    end 

    def fill_in_info 
    fill_in 'First name', :with => @account.admin.first 
    fill_in 'Last name', :with => @account.admin.last 
    fill_in 'Email', :with => @account.admin.email 
    end 

    describe "register" do 
    it "should set plan" do 
     visit signup_path(:plan => "small_group") 
     fill_in_info 
     click_button 'Create Account' 
     @account.plan.must_be_kind_of SubscriptionPlan #this doesn't work -- @account.plan is nil 
    end 
    end 
end 

回答

相關問題