Hi,

I have a Queues controller and and QueueItems controller in my rails
application. In routes I have defined as below
`match 'queues/:queue_id/next', :to=> 'queueitems#next'`
In my QueueItems Controller I have a next action and it assigns an
instance variable.

     def next
     @queue = "Regular"
     #other stuffs related to regular
     end

How do I test this in Rspec. I am pretty very new to Rspec. Please help.
I tried like the below

     describe "next " do
       it "routes /queues/:queue_id/next" do
         { :get => "/queues/regular_queue/next" }.should route_to(
           :controller => "queue_items",
           :action => "next",
           :queue_id => "regular_queue",
           :format => "json"
             )
         assigns(:queue).should_not be_nil
         expect(response).to be_success
       end

But it is not at all coming inside my next action in controller.

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/e4fceb598e27968b4515aeacb1c1a9e9%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Ruby rails at Apr 26, 2014 at 3:14 pm
    Hi,

    I have a Queues controller and and QueueItems controller in my rails
    application. In routes I have defined as below
    `match 'queues/:queue_id/next', :to=> 'queueitems#next'`
    In my QueueItems Controller I have a next action and it assigns an
    instance variable.

         def next
         @queue = "Regular"
         #other stuffs related to regular
         end

    How do I test this in Rspec. I am pretty very new to Rspec. Please help.
    I tried like the below

         describe "next " do
           it "routes /queues/:queue_id/next" do
             { :get => "/queues/regular_queue/next" }.should route_to(
               :controller => "queue_items",
               :action => "next",
               :queue_id => "regular_queue",
               :format => "json"
                 )
             assigns(:queue).should_not be_nil
             expect(response).to be_success
           end

    But it is not at all coming inside my next action in controller.

    --
    Posted via http://www.ruby-forum.com/.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/11310e947a8b612c198d3e47729f8b81%40ruby-forum.com.
    For more options, visit https://groups.google.com/d/optout.
  • Frederick Cheung at Apr 26, 2014 at 6:26 pm

    On Saturday, April 26, 2014 4:09:15 PM UTC+1, Ruby-Forum.com User wrote:
    How do I test this in Rspec. I am pretty very new to Rspec. Please help.
    I tried like the below

    describe "next " do
    it "routes /queues/:queue_id/next" do
    { :get => "/queues/regular_queue/next" }.should route_to(
    :controller => "queue_items",
    :action => "next",
    :queue_id => "regular_queue",
    :format => "json"
    )
    assigns(:queue).should_not be_nil
    expect(response).to be_success
    end

    But it is not at all coming inside my next action in controller.

    What you've written there is a routing spec - it's just testing that your
    routes file maps that path to the correct controller/action. It's not
    making a request at all. For that you want a controller spec (these should
    be in spec/controllers/ for rspec to detect this as a controller spec.
    You'd want something along these lines

    describe QueueItemsController do
       describe 'GET next' do
         it 'should assign queue' do
           get :next
           assigns(:queue).should == 'Regular'
         end
       end
    end

    Fred

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/8ef5bfc9-bfbc-44e8-a9be-822920b90a21%40googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Ruby rails at Apr 26, 2014 at 6:35 pm

    Frederick Cheung wrote in post #1144184:
    On Saturday, April 26, 2014 4:09:15 PM UTC+1, Ruby-Forum.com User wrote:
    :format => "json"
    )
    assigns(:queue).should_not be_nil
    expect(response).to be_success
    end

    But it is not at all coming inside my next action in controller.

    What you've written there is a routing spec - it's just testing that
    your
    routes file maps that path to the correct controller/action. It's not
    making a request at all. For that you want a controller spec (these
    should
    be in spec/controllers/ for rspec to detect this as a controller spec.
    You'd want something along these lines

    describe QueueItemsController do
    describe 'GET next' do
    it 'should assign queue' do
    get :next
    assigns(:queue).should == 'Regular'
    end
    end
    end

    Fred
    Hi Fred,

    I tried the above code by putting it in the
    spec/controllers/queue_items_constroller_spec.rb file
    But it shows the routing error as
    Failure/Error: get :next
          ActionController::RoutingError:
            No route matches {:controller=>"queue_items", :action=>"next"}
    In the routes file I have defined as
       match '/queues/:queue_id/next', :to => 'queue_items#next',
    :format=>'json'

    --
    Posted via http://www.ruby-forum.com/.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/f3c7a70e39b16fc143733d353cb49723%40ruby-forum.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedApr 26, '14 at 3:09p
activeApr 26, '14 at 6:35p
posts4
users2
websiterubyonrails.org
irc#RubyOnRails

2 users in discussion

Ruby rails: 3 posts Frederick Cheung: 1 post

People

Translate

site design / logo © 2022 Grokbase