使用 minitest,测试这个 build_plan 方法的最佳方法是什么?
我目前的尝试是尝试验证 @account.plan 是否已设置,但我不太清楚如何做到这一点。这是我应该尝试做的,还是别的什么?
account_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