Sha256: 3a36192b4262541e7075a2f044d13fe9112372ea7595609aa671c82b544fa9d6

Contents?: true

Size: 1.94 KB

Versions: 11

Compression:

Stored size: 1.94 KB

Contents

require 'test_helper'

class <%= user_plural_class_name %>ControllerTest < ActionController::TestCase
  context "new action" do
    should "render new template" do
      get :new
      assert_template 'new'
    end
  end

  context "create action" do
    should "render new template when <%= user_singular_name %> is invalid" do
      <%= user_class_name %>.any_instance.stubs(:valid?).returns(false)
      post :create
      assert_template 'new'
    end

    should "redirect when <%= user_singular_name %> is valid" do
      <%= user_class_name %>.any_instance.stubs(:valid?).returns(true)
      post :create
      assert_redirected_to root_url
    <%- unless options[:authlogic] -%>
      assert_equal assigns['<%= user_singular_name %>'].id, session['<%= user_singular_name %>_id']
    <%- end -%>
    end
  end

  context "edit action" do
    should "redirect when not logged in" do
      get :edit, :id => "ignored"
      assert_redirected_to login_url
    end

    should "render edit template" do
      @controller.stubs(:current_<%= user_singular_name %>).returns(<%= user_class_name %>.first)
      get :edit, :id => "ignored"
      assert_template 'edit'
    end
  end

  context "update action" do
    should "redirect when not logged in" do
      put :update, :id => "ignored"
      assert_redirected_to login_url
    end

    should "render edit template when <%= user_singular_name %> is invalid" do
      @controller.stubs(:current_<%= user_singular_name %>).returns(<%= user_class_name %>.first)
      <%= user_class_name %>.any_instance.stubs(:valid?).returns(false)
      put :update, :id => "ignored"
      assert_template 'edit'
    end

    should "redirect when <%= user_singular_name %> is valid" do
      @controller.stubs(:current_<%= user_singular_name %>).returns(<%= user_class_name %>.first)
      <%= user_class_name %>.any_instance.stubs(:valid?).returns(true)
      put :update, :id => "ignored"
      assert_redirected_to root_url
    end
  end
end

Version data entries

11 entries across 11 versions & 4 rubygems

Version Path
kickoff-0.0.2 lib/generators/kickoff/authentication/templates/tests/shoulda/users_controller.rb
nifty-generators-improved-0.5 lib/generators/nifty/authentication/templates/tests/shoulda/users_controller.rb
flockonus-nifty-generators-0.0.12 lib/generators/nifty/authentication/templates/tests/shoulda/users_controller.rb
nifty-generators-0.4.6 lib/generators/nifty/authentication/templates/tests/shoulda/users_controller.rb
flockonus-nifty-generators-0.0.11 lib/generators/nifty/authentication/templates/tests/shoulda/users_controller.rb
flockonus-nifty-generators-0.0.10 lib/generators/nifty/authentication/templates/tests/shoulda/users_controller.rb
flockonus-nifty-generators-0.0.9 lib/generators/nifty/authentication/templates/tests/shoulda/users_controller.rb
nifty-generators-0.4.5 lib/generators/nifty/authentication/templates/tests/shoulda/users_controller.rb
flockonus-nifty-generators-0.0.8 lib/generators/nifty/authentication/templates/tests/shoulda/users_controller.rb
flockonus-nifty-generators-0.0.7 lib/generators/nifty/authentication/templates/tests/shoulda/users_controller.rb
flockonus-nifty-generators-0.0.6 lib/generators/nifty/authentication/templates/tests/shoulda/users_controller.rb