continuing the refactor of the admin section

This commit is contained in:
2012-12-05 01:14:13 +01:00
parent d8eef4a047
commit fe7c061d37
47 changed files with 752 additions and 123 deletions
@@ -87,16 +87,14 @@ describe <%= controller_class_name %> do
context "valid attributes" do
it "located the requested <%= model_name %>" do
put :update, id: @<%= model_name %>, <%= model_name %>: attributes_for(:<%= model_name %>)
@<%= model_name %>.reload
assigns(:<%= model_name %>).should eq(@<%= model_name %>)
end
it "changes @<%= model_name %>'s attributes" do
attributes = attributes_for(:<%= model_name %>)
attribute_to_change = attributes.keys.find{|k| k !~ /_id$/}
attributes[attribute_to_change] = "ChangedByTest"
put :update, id: @<%= model_name %>, <%= model_name %>: attributes
put :update, id: @<%= model_name %>, <%= model_name %>: attributes_for(:<%= model_name %>, <%= required_attribute_name %>: "ChangedByTest")
@<%= model_name %>.reload
@<%= model_name %>.send(attribute_to_change).should eq("ChangedByTest")
@<%= model_name %>.<%= required_attribute_name %>.should eq("ChangedByTest")
end
it "redirects to the updated <%= model_name %>" do
@@ -104,5 +102,34 @@ describe <%= controller_class_name %> do
response.should redirect_to <%= controller_namespace_path.present? ? "[#{controller_namespace_path.split('/').map{|n| ":#{n}"}.join(', ')}, @#{model_name}]" : "@#{model_name}" %>
end
end
context "invalid attributes" do
it "locates the requested <%= model_name %>" do
put :update, id: @<%= model_name %>, <%= model_name %>: {<%= required_attribute_name %>: ''}
assigns(:<%= model_name %>).should eq(@<%= model_name %>)
end
it "re-renders the edit method" do
put :update, id: @<%= model_name %>, <%= model_name %>: {<%= required_attribute_name %>: ''}
response.should render_template :edit
end
end
end
describe 'DELETE destroy' do
before :each do
@<%= model_name %> = create :<%= model_name %>
end
it "deletes the <%= model_name %>" do
expect{
delete :destroy, id: @<%= model_name %>
}.to change(<%= model_name.classify %>, :count).by(-1)
end
it "redirects to <%= model_plural_name %>#index" do
delete :destroy, id: @<%= model_name %>
response.should redirect_to <%= controller_namespace_path.present? ? "[#{controller_namespace_path.split('/').map{|n| ":#{n}"}.join(', ')}, :#{model_plural_name}]" : "#{model_plural_name}_path" %>
end
end
end