Sha256: 09c2758671d78d5eec8a21e1351fcb9e4fcf0faaa1bcefd23eaa6ba63446ebe8

Contents?: true

Size: 1.4 KB

Versions: 5

Compression:

Stored size: 1.4 KB

Contents

require 'test_helper'

class <%= session_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
  <%- if options.authlogic? -%>
    should "render new template when authentication is invalid" do
      post :create, :<%= session_singular_name %> => { :username => "foo", :password => "badpassword" }
      assert_template 'new'
      assert_nil <%= session_class_name %>.find
    end
    
    should "redirect when authentication is valid" do
      post :create, :<%= session_singular_name %> => { :username => "foo", :password => "secret" }
      assert_redirected_to root_url
      assert_equal <%= user_plural_name %>(:foo), <%= session_class_name %>.find.<%= user_singular_name %>
    end
  <%- else -%>
    should "render new template when authentication is invalid" do
      <%= user_class_name %>.stubs(:authenticate).returns(nil)
      post :create
      assert_template 'new'
      assert_nil session['<%= user_singular_name %>_id']
    end
    
    should "redirect when authentication is valid" do
      <%= user_class_name %>.stubs(:authenticate).returns(<%= user_class_name %>.first)
      post :create
      assert_redirected_to root_url
      assert_equal <%= user_class_name %>.first.id, session['<%= user_singular_name %>_id']
    end
  <%- end -%>
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
very_nifty_generators-0.2.1 lib/generators/nifty/authentication/templates/tests/shoulda/sessions_controller.rb
very_nifty_generators-0.2.0 lib/generators/nifty/authentication/templates/tests/shoulda/sessions_controller.rb
very_nifty_generators-0.1.2 lib/generators/nifty/authentication/templates/tests/shoulda/sessions_controller.rb
very_nifty_generators-0.1.1 lib/generators/nifty/authentication/templates/tests/shoulda/sessions_controller.rb
very_nifty_generators-0.1.0 lib/generators/nifty/authentication/templates/tests/shoulda/sessions_controller.rb