should_be_restful and namespaced controller

0 views
Skip to first unread message

MRoderick

unread,
Mar 30, 2008, 5:47:48 AM3/30/08
to shoulda
I am having some trouble getting should_be_restful to work for
namespaced controllers (admin controllers), Shoulda 4.0.1, Rails
2.0.2.

As far as I can tell, James Golicks patch from
http://groups.google.com/group/shoulda/browse_thread/thread/de802b1c70984064/1995e2e69708b144?lnk=gst&q=namespace#1995e2e69708b144
never got implemented in Shoulda.

I've tried handpatching Shoulda 4.0.1, but am still getting the exact
same errors .... it's probably just me, as I am still struggling with
testing.

Here's the error I get for my show action for
Admin::ProductsController

ruby test/functional/admin/products_controller_test.rb
Loaded suite test/functional/admin/products_controller_test
Started
....F.FF
Finished in 0.540747 seconds.

1) Failure:
test: Admin users on GET to :show should assign @product.
(Admin::ProductsControllerTest)
[/Users/morgan/mysecretsite/vendor/plugins/shoulda/lib/shoulda/
controller_tests/controller_tests.rb:344
/Users/morgan/mysecretsite/vendor/plugins/shoulda/lib/shoulda/gem/
shoulda.rb:190
/Users/morgan/mysecretsite/vendor/plugins/shoulda/lib/shoulda/gem/
shoulda.rb:190
test/functional/admin/products_controller_test.rb:14]:
The action isn't assigning to @product.
<nil> is not true.

2) Failure:
test: Admin users on GET to :show should render 'show' template.
(Admin::ProductsControllerTest)
[/Users/morgan/mysecretsite/vendor/plugins/shoulda/lib/shoulda/
controller_tests/controller_tests.rb:375
/Users/morgan/mysecretsite/vendor/plugins/shoulda/lib/shoulda/gem/
shoulda.rb:190
/Users/morgan/mysecretsite/vendor/plugins/shoulda/lib/shoulda/gem/
shoulda.rb:190
test/functional/admin/products_controller_test.rb:14]:
expecting <"show"> but rendering with <"diagnostics.erb">

3) Failure:
test: Admin users on GET to :show should respond with success.
(Admin::ProductsControllerTest)
[/Users/morgan/mysecretsite/vendor/plugins/shoulda/lib/shoulda/
controller_tests/controller_tests.rb:365
/Users/morgan/mysecretsite/vendor/plugins/shoulda/lib/shoulda/gem/
shoulda.rb:190
/Users/morgan/mysecretsite/vendor/plugins/shoulda/lib/shoulda/gem/
shoulda.rb:190
test/functional/admin/products_controller_test.rb:14]:
Expected response to be a <:success>, but was <404>

8 tests, 16 assertions, 3 failures, 0 errors

The fact that I get 404 and diagnostics.erb, tells me that the request
to show is probably going to an undefined route, or is going to the
public routes, which are very different.

For the index action, everything seems to be working just fine.

Now, there's nothing really interesting in the show action:

def show
@product = Product.find(params[:id])

respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @product }
end
end

For completeness, here's my test:

require File.dirname(__FILE__) + '/../../test_helper'

class Admin::ProductsControllerTest < Test::Unit::TestCase
fixtures :categories, :products

def setup
@controller = Admin::ProductsController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
@product = Product.find(:first)
end


context "Admin users" do

should_be_restful do |resource|

setup do
login
end

resource.klass = Product
resource.actions = [:index, :show]
# :new, :edit, :update, :create, :destroy]
resource.formats = [:html]


resource.create.params = {
:name => "my first product",
:description => "my first description",
:price => 100.76,
:category_id => 1,
}
resource.update.params = {
:name => "updated product name",
:description => "my second description",
:price => 1234.56,
:category_id => 1
}

resource.create.redirect = "admin_product_url( @product )"
resource.update.redirect = "admin_product_url( @product )"
resource.destroy.redirect = "admin_products_url"

resource.create.flash = /created/i
resource.update.flash = /updated/i
resource.destroy.flash = nil

end

end

end

Is Shoulda 4.0.1 supposed to be able to handle namespaced controllers?

jko170

unread,
Apr 2, 2008, 12:18:55 PM4/2/08
to shoulda
Yeah has anyone figured this out? I cannot test my namespace
controllers.

On Mar 30, 4:47 am, MRoderick <roderick.mor...@gmail.com> wrote:
> I am having some trouble getting should_be_restful to work for
> namespaced controllers (admin controllers), Shoulda 4.0.1, Rails
> 2.0.2.
>
> As far as I can tell, James Golicks patch fromhttp://groups.google.com/group/shoulda/browse_thread/thread/de802b1c7...

Tammer Saleh

unread,
Apr 5, 2008, 7:49:27 AM4/5/08
to sho...@googlegroups.com
I've created a lighthouse ticket for this here:

http://tammer.lighthouseapp.com/projects/5807-shoulda/tickets/29

What we need is an updated patch which includes tests (the last one
was for an older version of shoulda).

Cheers,
Tammer

MRoderick

unread,
Apr 6, 2008, 9:47:21 AM4/6/08
to shoulda
Super!

I am glad that it wasn't just my brain that wouldn't get around it ;-)

Cheers
/Morgan
Reply all
Reply to author
Forward
0 new messages