Skip to content

Instantly share code, notes, and snippets.

@jrep
Created December 13, 2011 22:57
Show Gist options
  • Save jrep/1474343 to your computer and use it in GitHub Desktop.
Save jrep/1474343 to your computer and use it in GitHub Desktop.
adding non-ralisy urls, routes, classes
# Existing requests (all working):
POST /1/organizations => creates a new Organization
GET /1/organizations => show Organizations
GET /1/organizations/13 => show Organizations[13]
# and so on.
# Current routes.rb:
scope '/1' do
resources :organizations
end
# Current tests
spec/controllers/organizations_controller_spec.rb:
describe OrganizationsController do
describe '#index' do
it 'should work' do
get '/1/organizations/13'
resonse.should be_ok
end
end
end
# Current controllers
app/controllers/organizations_controller.rb:
class OrganizationsController < ActionController::Base
def show
end
end
# New requests (trying to add):
# Note that there is no "partner" entity; this is only URL padding to avoid collisions with the first block.
POST /1/partner/subscriptions => creates a new Subscription
GET /1/partner/subscriptions/13 => show Subscriptions[13]
POST /1/partner/resources => creates a new Resource
GET /1/partner/resources/13 => show Resources[13]
# Attempted routes.rb:
scope '/1' do
resources :organizations # existing
scope '/partner' do
match 'subscriptions(/:action)' => 'partner_subscriptions#show'
end
end
# Attempted tests:
spec/controllers/partner_subscriptions_controller_spec.rb:
describe PartnerSubscriptionController do
describe '#subscriptions' do
it 'should work' do
get '/1/partner/subscriptions'
response.should be_ok
end
end
end
# Attempted controller
app/controllers/partner_subscriptions_controller.rb:
class PartnerSubscriptionsController < ActionController::Base
def show
end
end
# but this doesn't work
% rspec spec
1) PartnerSubscriptionsController GET /1/partner/subscriptions should work
Failure/Error: get '/1/partner/subscriptions'
AbstractController::ActionNotFound:
The action '/1/partner/subscriptions' could not be found for PartnerSubscriptionsController
# ./spec/controllers/partner_subscriptions_controller_spec.rb:18:in `block (3 levels) in <top (required)>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment