Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tscolari/958218 to your computer and use it in GitHub Desktop.
Save tscolari/958218 to your computer and use it in GitHub Desktop.
This is a set of tests for default CRUD routing in rails. Also works with namespaces.
shared_examples_for "default crud routing" do
let(:random_id_for_routing) {rand(2000)}
let(:controller_name) {described_class.to_s.underscore.gsub(/_controller/, '')}
it "should route to index action" do
{:get => "/#{controller_name}"}.should route_to(
:controller => controller_name,
:action => 'index'
)
end
it "should route to show action" do
{:get => "/#{controller_name}/#{random_id_for_routing}"}.should route_to(
:controller => controller_name,
:action => 'show',
:id => "#{random_id_for_routing}"
)
end
it "should route to destroy action" do
{:delete => "/#{controller_name}/#{random_id_for_routing}"}.should route_to(
:controller => controller_name,
:action => 'destroy',
:id => "#{random_id_for_routing}"
)
end
it "should route to new action" do
{:get => "/#{controller_name}/new"}.should route_to(
:controller => controller_name,
:action => 'new'
)
end
it "should route to edit action" do
{:get => "/#{controller_name}/#{random_id_for_routing}/edit"}.should route_to(
:controller => controller_name,
:action => 'edit',
:id => "#{random_id_for_routing}"
)
end
it "should route to create action" do
{:post => "/#{controller_name}"}.should route_to(
:controller => controller_name,
:action => 'create'
)
end
it "should route to update action" do
{:put => "/#{controller_name}/#{random_id_for_routing}"}.should route_to(
:controller => controller_name,
:action => 'update',
:id => "#{random_id_for_routing}"
)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment