Rspec: routing test di controller nested

Ciao,

nel file routes.rb ho

resources :thoughts do
resources :statements, :only => [:create, :destroy]
end

se eseguo rake routes | grep statements ottengo

  thought_statements POST

/thoughts/:thought_id/statements(.:format) {:action=>“create”,
:controller=>“statements”}
thought_statement DELETE
/thoughts/:thought_id/statements/:id(.:format) {:action=>“destroy”,
:controller=>“statements”}

ma non riesco a capire perch il test di queste rotte con rspec fallisce

require “spec_helper”

describe StatementsController do
describe “routing” do

it "recognizes and generates #create" do
  { :post => "/thoughts/1/statements" }.should

route_to(:controller => “statements”, :action => “create”)
end

it "recognizes and generates #destroy" do
  { :delete => "/thoughts/1/statements/1" }.should

route_to(:controller => “statements”, :action => “destroy”, :id =>
“1”)
end

end
end

con

rake spec:routing
FF…

Failures:

Failures:

  1. StatementsController routing recognizes and generates #create
    Failure/Error: { :post => “/thoughts/1/statements” }.should
    route_to(:controller => “statements”, :action => “create”)
    Expected block to return true value.

    ./spec/routing/statements_routing_spec.rb:7:in `block (3

levels) in <top (required)>’

  1. StatementsController routing recognizes and generates #destroy
    Failure/Error: { :delete => “/thoughts/1/statements/1” }.should
    route_to(:controller => “statements”, :action => “destroy”, :id =>
    “1”)
    Expected block to return true value.

    ./spec/routing/statements_routing_spec.rb:11:in `block (3

levels) in <top (required)>’

Qualche suggerimento ?
Grazie mille.
Claudio

Ciao Claudio,
Credo che le spec falliscano rispettivamente a causa dell’id che non
viene passato e della mancanza del thought_id nel secondo caso.

Ti consiglio di eseguire rake routes per verificare i parametri
mancanti.

Luca

Ciao Luca,

grazie della tua risposta
se eseguo rake routes | grep statements ottengo

 thought_statements   POST

/thoughts/:thought_id/statements(.:format) {:action=>“create”,
:controller=>“statements”}
thought_statement DELETE
/thoughts/:thought_id/statements/:id(.:format)
{:action=>“destroy”, :controller=>“statements”}

e mi sembra tutto ok ?

2011/4/16 Luca G. [email protected]:

[email protected]
http://lists.ruby-it.org/mailman/listinfo/ml


Claudio M.

Perfetto!
Grazie mille

On Mon, Apr 18, 2011 at 10:05 AM, Luca G. [email protected]
wrote:

thought_statements POST

Credo che le spec falliscano rispettivamente a causa dell’id che non viene
passato e della mancanza del thought_id nel secondo caso.

[email protected]
http://lists.ruby-it.org/mailman/listinfo/ml


Ml mailing list
[email protected]
http://lists.ruby-it.org/mailman/listinfo/ml


Claudio M.

Prova con:

it “recognizes and generates #create” do
{ :post => “/thoughts/1/statements” }.should route_to(:controller =>
“statements”, :action => “create”, :thought_id => “1”)
end

it “recognizes and generates #destroy” do
{ :delete => “/thoughts/1/statements/1” }.should route_to(:controller =>
“statements”, :action => “destroy”, :thought_id => “1”, :id =>
“1”)
end

Luca

http://about.me/jodosha

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs