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

  • SEARCH
  • Home
  • 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 8816303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:35:27+00:00 2026-06-14T04:35:27+00:00

What is the best way to test logic in a rails 3 layout? Example:

  • 0

What is the best way to test logic in a rails 3 layout?

Example: when a user signs into my site, if they have not completed the onboarding process I show them an alert at the top of the screen on ALL pages. This logic was placed into the application layout. I simply check the logged in user for a particular key. If the key is NOT present I show the alert. As soon as the key is present (meaning they’ve completed the onboarding) I DO NOT show the alert.

Currently I’m attempting to do this with a view test, but I’m getting all sorts of ActionView::Template::Error: undefined methodauthenticate’ for nil:NilClass` errors by including the application layout and I cant seem to test this feature.

I need to make sure I have this under test because if for some reason one of my devs accidentally breaks this feature (view showing up with onboarding is not complete) we need to know immediately upon build.

The code that I’m trying to test in my layout looks like this:

<% if user_signed_in? %>
    <% unless current_user.has_completed_onboarding? %>
      <div class="alert">
        You cannot accept payments from your clients until you set up your payment gateway.
        <%= link_to "Set up your", payment_gateway_path %> payment gateway. Its quick, we promise. :)
      </div>
    <% end %>
<% end %>

I want to make sure that if they onboarding details have NOT been provided that this message will show and if they have been provided, then do not show this message.

  • 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-06-14T04:35:28+00:00Added an answer on June 14, 2026 at 4:35 am

    You can test your layout just like any other view. Just create a file application.html.erb_spec.rb (replace erb by haml if necessary) in spec/views/layouts/, and in that file write up your specs as you normally would, e.g.:

    require 'spec_helper'
    
    describe 'layouts/application' do
    
      context 'signed-in user' do
    
        before { view.stub(:user_signed_in?) { true } }
    
        context 'completed onboarding' do
    
          before do
            user = double('user')
            user.stub(:has_completed_onboarding?) { false }
            assign(:current_user, user)
          end
    
          it "should display alert" do
            render
            rendered.should have_selector('.alert')
          end
    
        end
    
        ...
    
      end
    
      context 'signed-out user' do
        ...
      end
    
      ...
    
    end
    

    I do this with one of my apps and it works no problem, so I don’t see why it wouldn’t work for your case as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just wondering whats the best way to test Python CGI while developing a site?
What's the best practices way to test that a model is valid in rails?
What is the best way to reuse switch logic. I have this switch statement
What's the standard/recommended way to test time-dependent methods? As an example: I have a
What is the best way to test data access layers and business logic in
What is the best way to test web service using NUnit. I want it
What is the best way to test an implementation of a mutex is indeed
Whats the best/easiest way to test for administrative rights in a PowerShell script? I
What is the best way to unit test heavily database dependant .NET middleware? E.g.
What is the best way to integration test EJBs and REST-Resources?

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.