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 6332987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:22:35+00:00 2026-05-24T18:22:35+00:00

I’m using Ryan Bates’s nifty:authentication , and starting testing with Rspec. Fought with this

  • 0

I’m using Ryan Bates’s nifty:authentication, and starting testing with Rspec. Fought with this for weeks, and still don’t understand what’s happening.

My controller simply calls

before_filter :login_required, :except => [:login]

Which is defined in lib/controller_authentication

def self.included(controller)
    controller.send :helper_method, :current_account, :logged_in?, :redirect_to_target_or_default
  end

  def current_account
    @current_account ||= Account.find(session[:account_id]) if session[:account_id]
  end

  def logged_in?
    current_account
  end

  def login_required
    unless logged_in?
      store_target_location
      redirect_to login_url, :alert => "You must first answer me these riddles three log in or sign up before accessing this page."
    end
  end

  def redirect_to_target_or_default(default, *args)
    redirect_to(session[:return_to] || default, *args)
    session[:return_to] = nil
  end

  private

  def store_target_location
    session[:return_to] = request.url
  end
end

The app works as intended, but the testing fails every time. No matter what I try, I get the redirect_to login_url, :alert => "You must first ...log in" page.

Things I’ve tried:

controller.stub!( :login_required )
ControllerAuthentication.stub!(:current_account).and_return(Account.where(:username => 'ej0c').first)
#ControllerAuthentication.stub!(:logged_in?).and_return(Account.where(:username => 'ej0c').first)
ControllerAuthentication.stub!(:login_required).and_return(true)
MyDigisController.stub!( :login_required ).and_return(true)

Which I think means I’m missing the whole theory of the thing. How can I make my login work?


I tried as Punit suggests below:
[pre]

require 'spec_helper'

describe "View event details" do

  it "Should show a table of events" do
     @account = Account.where(:username => 'ej0c').first
     puts @account.inspect
     controller.stub!(:current_account).and_return(@account)
     controller.stub!(:logged_in?).and_return(true)
     session[:account_id] = @account.id
      visit '/my_digis/66/custom_events'
      page.should have_content('Events')

  end
end

@account.inspect displayed nicely, but I also got

An expectation of :current_account was set on nil. Called from C:/Users/Ed/webapps/whendidji3/spec/con
.rb:8:in `block (2 levels) in <top (required)>'. Use allow_message_expectations_on_nil to disable warn
An expectation of :logged_in? was set on nil. Called from C:/Users/Ed/webapps/whendidji3/spec/controll
:in `block (2 levels) in <top (required)>'. Use allow_message_expectations_on_nil to disable warnings.

Thanks for any detailed explanations, as I’ve searched high an low to understand what’s goin on.

  • 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-24T18:22:36+00:00Added an answer on May 24, 2026 at 6:22 pm

    OK, the answer was that I needed a request spec.

    I’d begun with a request spec, but it wasn’t in the requests folder, and the questions I asked got it morphed into a half-request/half-controller spec, none of which works.

    The strange thing about rspec is that it will complain if a capybara method is badly formed,…but it won’t mention that the thing just plain doesn’t work where you put it!

    My working spec, located in specs/requests/my_digis_spec.rb is

    require 'spec_helper'
    
    describe "MyDigis" do
    
       before :each do
    @account = Account.where(:username => 'me').first
    visit login_path
        fill_in 'Username or Email Address', :with => @account.email
        fill_in 'Password', :with => 'password'
      click_button('Log in')
    

    end

    it "Shows list of digis" do
      visit my_digis_path
      page.should have_content('Your Custom Event groups')
    end
    
    it "Lets you modify didji list" do
      visit my_digis_path
      click_button('Modify events')
      page.should have_content('Events for my_digi')
    end
    

    end

    As easy as advertised, just took me 5 weeks to get the login part. Thanks.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We're building an app, our first using Rails 3, and we're having to build

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.