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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:46:38+00:00 2026-06-14T17:46:38+00:00

I’m running in to problems testing a custom post action in my Rails 3.2.8

  • 0

I’m running in to problems testing a custom post action in my Rails 3.2.8 application. I think it had something to do with transactional fixtures being set to true but could do with some help diagnosing.

I have this in my spec_helper.rb

config.use_transactional_fixtures = true

And my controller spec looks like this:

require 'spec_helper'   
describe Api::V1::NasController do       
  login_user        
  describe "GET #nas" do      
    it "posts to startup as new (state) controller" do
      @location = FactoryGirl.create(:location_full)
      @location.users << @current_user
      nas = FactoryGirl.create(:nas, location_id: @location.id )   
      nas.update_attributes!(:state => 'initialised')
      post :start_up, :token => nas.token, :key => nas.key
      response.should be_success
    end   
  end   
end

I can see the post happening in my server log however the test fails with:

   1) Api::V1::NasController GET #nas posts to startup as new (state) controller
 Failure/Error: post :start_up, :token => @nas.token, :key => @nas.key
 NoMethodError:
   undefined method `slice' for nil:NilClass
 # ./app/helpers/nas_helper.rb:26:in `queue'
 # ./app/controllers/api/v1/nas_controller.rb:99:in `start_up'
 # ./spec/controllers/api/v1/nas_controller_spec.rb:16:in `block (3 levels) in <top (required)>'

I have a before filter in my controller which takes the token and key and gives head unauthorised if it can’t find the Nas.

In this test, the Nas is actually found and it moves into the controller action:

def start_up
   @token = params[:token]
   @nas = Nas.find_by_token("#{@token}")
   if @nas
   [ do some stuff ]
   ....
   NasSync.enqueue(@nas)   
   ...       
end

It’s failing at NasSync.enqueue(@nas) which in turn calls the following helper method (from a resque worker which I omitted):

 def self.queue(nas)  
   node = Nas.find(nas.id).nasname.slice(0..3)
   .....
 end

In the ‘real’ world, I can post successfully to this url – it’s just in the test environment that it fails.

 node = Nas.find(nas.id).nasname.slice(0..3)

Isn’t finding a Nas to slice.

I can’t figure out why it can’t find the Nas, if it gets so far without failing. If I hardcode the node, the test passes.

Is there a specific reason why the nas isn’t being sent over to the helper??

Any suggestions / help appreciated.

— UPDATE —

I’ve turned off transactional fixtures, sorted the mess that was left and am still stuck with the error:

 undefined method `slice' for nil:NilClass
  • 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-14T17:46:39+00:00Added an answer on June 14, 2026 at 5:46 pm

    Whilst it wasn’t actually transactional fixtures directly causing the problem, turning them off finally pin pointed the issue. Which was actually a tiny bug in my code.

    Life within transactions was easy, straight forward and probably quite blinkered. Things passed, when they probably shouldn’t

    Turning them off meant I needed to scrap my messy seeds and create the data as and when I needed it.

    Lazy coding leads to headaches and more work.

    I also realise now that one should have more faith in their abilities and trust the tests that have been written. In this case, that tiny little bug could have caused some big issues. 3 days well spent.

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

Sidebar

Related Questions

Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am currently running into a problem where an element is coming back from
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to create an if statement in PHP that prevents a single post
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

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.