Sha256: cd6f2d4133ae9433b5f802cd9257f4f2f8acf409a3cf9ca2455db5c784e6d4da

Contents?: true

Size: 1.92 KB

Versions: 1

Compression:

Stored size: 1.92 KB

Contents

require File.dirname(__FILE__) + '/../spec_helper'
 
describe <%= controller_class_name %>Controller do
<% if options[:fixtures] -%>
  fixtures :all
<% end %>
  integrate_views
  
  it "index action should render index template" do
    get :index
    response.should render_template(:index)
  end
  
  it "show action should render show template" do
    get :show, :id => <%= class_name %>.first
    response.should render_template(:show)
  end
  
  it "new action should render new template" do
    get :new
    response.should render_template(:new)
  end
  
  it "create action should render new template when model is invalid" do
    <%= resource_instance %> = <%= class_name %>.new
    <%= resource_instance %>.stub!(:valid?).and_return(false)
    <%= class_name %>.stub!(:new).and_return(<%= resource_instance %>)
    lambda {
      post :create, :<%= singular_name %> => {}      
    }.should change(<%= class_name %>, :count).by(0)
  end
  
  it "create action should redirect when model is valid" do
    <%= resource_instance %> = <%= class_name %>.new
    <%= resource_instance %>.stub!(:valid?).and_return(true)
    <%= class_name %>.stub!(:new).and_return(<%= resource_instance %>)
    lambda {
      post :create, :<%= singular_name %> => {}      
    }.should change(<%= class_name %>, :count).by(1)
  end
  
  it "edit action should render edit template" do
    get :edit, :id => <%= class_name %>.first
    response.should render_template(:edit)
  end
  
  it "update action should redirect when model is valid" do
    put :update, :id => <%= class_name %>.first, :<%= singular_name %> => {}
    response.should redirect_to(<%= singular_name %>_url(assigns[:<%= singular_name %>]))
  end
  
  it "destroy action should destroy model and redirect to index action" do
    lambda {
      delete :destroy, :id => <%= class_name %>.first
    }.should change(<%= class_name %>, :count).by(-1)
    response.should redirect_to(<%= plural_name %>_url)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
akitaonrails-dry_scaffold-0.3.3 generators/dry_scaffold/templates/controllers/tests/rspec/functional_test.rb