Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #454 from liquid/master

Use to_param in scaffold spec templates
  • Loading branch information...
commit d05c3efdcc8ac8ad366c64fbfa8b6689c8e0eee5 2 parents 37da9b0 + 412b38a
@dchelimsky dchelimsky authored
View
2  features/Upgrade.md
@@ -36,7 +36,7 @@ is what you need to change:
## Controller specs
-### islation from view templates
+### isolation from view templates
By default, controller specs do _not_ render view templates. This keeps
controller specs isolated from the content of views and their requirements.
View
18 lib/generators/rspec/scaffold/templates/controller_spec.rb
@@ -40,7 +40,7 @@ def valid_attributes
describe "GET show" do
it "assigns the requested <%= ns_file_name %> as @<%= ns_file_name %>" do
<%= file_name %> = <%= class_name %>.create! valid_attributes
- get :show, :id => <%= file_name %>.id
+ get :show, :id => <%= file_name %>.to_param
assigns(:<%= ns_file_name %>).should eq(<%= file_name %>)
end
end
@@ -55,7 +55,7 @@ def valid_attributes
describe "GET edit" do
it "assigns the requested <%= ns_file_name %> as @<%= ns_file_name %>" do
<%= file_name %> = <%= class_name %>.create! valid_attributes
- get :edit, :id => <%= file_name %>.id
+ get :edit, :id => <%= file_name %>.to_param
assigns(:<%= ns_file_name %>).should eq(<%= file_name %>)
end
end
@@ -106,18 +106,18 @@ def valid_attributes
# receives the :update_attributes message with whatever params are
# submitted in the request.
<%= class_name %>.any_instance.should_receive(:update_attributes).with(<%= params %>)
- put :update, :id => <%= file_name %>.id, :<%= ns_file_name %> => <%= params %>
+ put :update, :id => <%= file_name %>.to_param, :<%= ns_file_name %> => <%= params %>
end
it "assigns the requested <%= ns_file_name %> as @<%= ns_file_name %>" do
<%= file_name %> = <%= class_name %>.create! valid_attributes
- put :update, :id => <%= file_name %>.id, :<%= ns_file_name %> => valid_attributes
+ put :update, :id => <%= file_name %>.to_param, :<%= ns_file_name %> => valid_attributes
assigns(:<%= ns_file_name %>).should eq(<%= file_name %>)
end
it "redirects to the <%= ns_file_name %>" do
<%= file_name %> = <%= class_name %>.create! valid_attributes
- put :update, :id => <%= file_name %>.id, :<%= ns_file_name %> => valid_attributes
+ put :update, :id => <%= file_name %>.to_param, :<%= ns_file_name %> => valid_attributes
response.should redirect_to(<%= file_name %>)
end
end
@@ -127,7 +127,7 @@ def valid_attributes
<%= file_name %> = <%= class_name %>.create! valid_attributes
# Trigger the behavior that occurs when invalid params are submitted
<%= class_name %>.any_instance.stub(:save).and_return(false)
- put :update, :id => <%= file_name %>.id, :<%= ns_file_name %> => {}
+ put :update, :id => <%= file_name %>.to_param, :<%= ns_file_name %> => {}
assigns(:<%= ns_file_name %>).should eq(<%= file_name %>)
end
@@ -135,7 +135,7 @@ def valid_attributes
<%= file_name %> = <%= class_name %>.create! valid_attributes
# Trigger the behavior that occurs when invalid params are submitted
<%= class_name %>.any_instance.stub(:save).and_return(false)
- put :update, :id => <%= file_name %>.id, :<%= ns_file_name %> => {}
+ put :update, :id => <%= file_name %>.to_param, :<%= ns_file_name %> => {}
response.should render_template("edit")
end
end
@@ -145,13 +145,13 @@ def valid_attributes
it "destroys the requested <%= ns_file_name %>" do
<%= file_name %> = <%= class_name %>.create! valid_attributes
expect {
- delete :destroy, :id => <%= file_name %>.id
+ delete :destroy, :id => <%= file_name %>.to_param
}.to change(<%= class_name %>, :count).by(-1)
end
it "redirects to the <%= table_name %> list" do
<%= file_name %> = <%= class_name %>.create! valid_attributes
- delete :destroy, :id => <%= file_name %>.id
+ delete :destroy, :id => <%= file_name %>.to_param
response.should redirect_to(<%= index_helper %>_url)
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.