Sha256: ed93815a110cbd1e96cbf3542cc7538e2e5ee9cd8f7f3924f7a71cded153742a

Contents?: true

Size: 1.39 KB

Versions: 6

Compression:

Stored size: 1.39 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 "/"
      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 "/"
      assert_equal <%= user_class_name %>.first.id, session['<%= user_singular_name %>_id']
    end
  <%- end -%>
  end
end

Version data entries

6 entries across 6 versions & 3 rubygems

Version Path
niftier-generators-0.1.2 lib/generators/niftier/authentication/templates/tests/shoulda/sessions_controller.rb
niftier-generators-0.1.1 lib/generators/niftier/authentication/templates/tests/shoulda/sessions_controller.rb
niftier-generators-0.1.0 lib/generators/niftier/authentication/templates/tests/shoulda/sessions_controller.rb
corntrace-nifty-generators-0.4.1 lib/generators/nifty/authentication/templates/tests/shoulda/sessions_controller.rb
corntrace-nifty-generators-0.4.0 lib/generators/nifty/authentication/templates/tests/shoulda/sessions_controller.rb
nifty-generators-0.4.0 lib/generators/nifty/authentication/templates/tests/shoulda/sessions_controller.rb