Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6007517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:41:32+00:00 2026-05-23T01:41:32+00:00

Given a controller like this where it creates several instance variables for use by

  • 0

Given a controller like this where it creates several instance variables for use by the view, would you generally test that each of those get set properly? It seems like you would want to, but it also seems a little it could be a bit tricky. What’s the right approach?

class StaffsController < ApplicationController

  def index
   set_index_vars
    @all_staff = Staff.find_staff_for_business_all_inclusive(current_business_id)
    respond_to do |format|
     format.html { render :action => "index", :locals => { :all_staff => @all_staff, :all_services => @all_services, :new_vacation => @new_vacation } }
    end
  end

  def set_index_vars
    @days_of_week = days_of_week
    @first_day_of_week = DefaultsConfig.first_day_of_week

    @all_services = Service.services_for_business(current_business_id)

    @new_vacation = StaffVacation.new
   @has_hit_staff_limit = current_user_plan.has_hit_staff_limit?
  end

end

The code is also posted at https://gist.github.com/1018190

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T01:41:33+00:00Added an answer on May 23, 2026 at 1:41 am

    If you’re going to write a controller spec, then yes, by all means test that the instance variables are assigned. Much of the ‘trickiness’ can come from dependencies on other models/libraries, so stub out those method calls:

    # air code
    Staff.stub(:find_staff_for_business_all_inclusive) {array_of_staff}
    controller.stub(:days_of_week) {['Monday','Tuesday',....etc...]}
    DefaultsConfig.stub(:first_day_of_week) {"Monday"}
    Service.stub(:services_for_business).with(some_value_for_the_current_business_id).\
      and_return(some_relevant_value)
    StaffVacation.stub(:new) {something_meaningful}
    controller.stub_chain(:current_user_plan,:has_hit_staff_limit?) {false}
    
    get :index
    assigns(:days_of_week).should == ['Monday','Tuesday',....etc...]
    # ...etc...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say that I have a UIView which I would like to re-use in multiple
Given a controller method like: def show @model = Model.find(params[:id]) respond_to do |format| format.html
Given an absolute or relative path (in a Unix-like system), I would like to
Given the following code: JE.events = { self: this, controller: { init: function(){ $(.monthheader).click(function
Given the following classes and controller action method: public School { public Int32 ID
Given a specific DateTime value, how do I display relative time, like: 2 hours
Given 2 rgb colors and a rectangular area, I'd like to generate a basic
Given the URL (single line): http://test.example.com/dir/subdir/file.html How can I extract the following parts using
Given a (source) patch file, what's the easiest way to apply this patch on
I am developing a complex form that updates several records of one model at

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.