1

Using minitest, what's the best way to test this build_plan method?

My current attempt is to try to verify that @account.plan is getting set, but I can't quite figure out how to do that. Is this what I should be trying to do, or something else?

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
99miles
  • 10,942
  • 18
  • 78
  • 123

1 Answers1

0

For acceptance tests make sure you have the correct (presumably Capybara) DSL included in 'minitest_helper' e.g.

class MiniTest::Spec

  include Capybara::DSL
  ...
end

It's worth reading a few other StackOverflow posts to get the right helper setup. This one Has anyone used Minitest::Spec withing a Rails functional test? was helpful to me.

Here's a Gist of my test helper for functional tests (I have yet to add the Capybara module as above) https://gist.github.com/2990759

Community
  • 1
  • 1
Steventux
  • 29
  • 3