Google Groups Home
Help | Sign in
should_be_restful and namespaced controller
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
MRoderick  
View profile
 More options Mar 30, 5:47 am
From: MRoderick <roderick.mor...@gmail.com>
Date: Sun, 30 Mar 2008 02:47:48 -0700 (PDT)
Local: Sun, Mar 30 2008 5:47 am
Subject: should_be_restful and namespaced controller
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/de802b1c7...
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?


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
jko170  
View profile
 More options Apr 2, 12:18 pm
From: jko170 <jko...@gmail.com>
Date: Wed, 2 Apr 2008 09:18:55 -0700 (PDT)
Local: Wed, Apr 2 2008 12:18 pm
Subject: Re: should_be_restful and namespaced controller
Yeah has anyone figured this out? I cannot test my namespace
controllers.

On Mar 30, 4:47 am, MRoderick <roderick.mor...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tammer Saleh  
View profile
 More options Apr 5, 7:49 am
From: Tammer Saleh <tsa...@gmail.com>
Date: Sat, 5 Apr 2008 12:49:27 +0100
Local: Sat, Apr 5 2008 7:49 am
Subject: Re: should_be_restful and namespaced controller
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

On Apr 2, 2008, at 5:18 PM, jko170 wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
MRoderick  
View profile
 More options Apr 6, 9:47 am
From: MRoderick <roderick.mor...@gmail.com>
Date: Sun, 6 Apr 2008 06:47:21 -0700 (PDT)
Local: Sun, Apr 6 2008 9:47 am
Subject: Re: should_be_restful and namespaced controller
Super!

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

Cheers
/Morgan

On Apr 5, 1:49 pm, Tammer Saleh <tsa...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google