Dmitry Suzdalev wrote in post #1020600:
>
> Can anybody hint my why does this happen? I'm only starting learning
> about
> RoR :) Earlier it seemed to me that these 'get/post' methods of TestCase
> do
> respect routes.rb...
>
> Am I missing something obvious? :)
>

With this controller:


class PagesController < ApplicationController
  def index
  end

  def home
  end

  def contact
  end

end



...and this single route:



T2App::Application.routes.draw do
  root :to => "pages#index"
end



...and these tests:



require 'spec_helper'

describe PagesController do

  describe "POST 'contact'" do
    it "should be successful" do
      post 'contact'
      response.should be_success
    end
  end

  describe "GET 'contact'" do
    it "should be successful" do
      get 'contact'
      response.should be_success
    end
  end

end



I get these results:



$ bundle exec rspec spec/
No DRb server is running. Running in local process instead ...
FF

Failures:

  1) PagesController POST 'contact' should be successful
     Failure/Error: post 'contact'
     ActionController::RoutingError:
       No route matches {:controller=>"pages", :action=>"contact"}
     # ./spec/controllers/pages_controller_spec.rb:6:in `block (3 
levels) in <top (required)>'

  2) PagesController GET 'contact' should be successful
     Failure/Error: get 'contact'
     ActionController::RoutingError:
       No route matches {:controller=>"pages", :action=>"contact"}
     # ./spec/controllers/pages_controller_spec.rb:21:in `block (3 
levels) in <top (required)>'

Finished in 0.09563 seconds
2 examples, 2 failures

Failed examples:

rspec ./spec/controllers/pages_controller_spec.rb:5 # PagesController 
POST 'contact' should be successful
rspec ./spec/controllers/pages_controller_spec.rb:20 # PagesController 
GET 'contact' should be successful



If I add a 'post' route to routes.db:



T2App::Application.routes.draw do
  root :to => "pages#index"

  post "pages/contact"

end



I get these results:


$ bundle exec rspec spec/
No DRb server is running. Running in local process instead ...
..

Finished in 0.11245 seconds
2 examples, 0 failures



I I change the 'post' route to a 'get' route:


T2App::Application.routes.draw do
  root :to => "pages#index"

  get "pages/contact"
end



I get these results:


$ bundle exec rspec spec/
No DRb server is running. Running in local process instead ...
..

Finished in 0.11352 seconds
2 examples, 0 failures




So to me it looks like if you define a get route or a post route, then 
rspec allows both get and post requests.

-- 
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 post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to