Sha256: eb92ea4acc2b3934eaddd028d54798d36674fb2ddf23dea484238e9cd965b784

Contents?: true

Size: 1.87 KB

Versions: 5

Compression:

Stored size: 1.87 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
      assert_equal assigns['<%= user_singular_name %>'].id, session['<%= user_singular_name %>_id']
    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

5 entries across 5 versions & 1 rubygems

Version Path
zoo-generators-0.1.5 lib/generators/zoo/authentication/templates/tests/shoulda/users_controller.rb
zoo-generators-0.1.4 lib/generators/zoo/authentication/templates/tests/shoulda/users_controller.rb
zoo-generators-0.1.3 lib/generators/zoo/authentication/templates/tests/shoulda/users_controller.rb
zoo-generators-0.1.2 lib/generators/zoo/authentication/templates/tests/shoulda/users_controller.rb
zoo-generators-0.1.1 lib/generators/zoo/authentication/templates/tests/shoulda/users_controller.rb