diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-06-25 17:51:45 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-06-25 17:51:45 +0200 |
| commit | 0818a3057b0a91e422158d828026c941b4e10622 (patch) | |
| tree | 9ed98d52bd577d3f36dd7a1ce8048d280a36062e /test/controllers/sessions_controller_test.rb | |
| parent | 26030c71c7b300c30367222f263d74b8d2142ecf (diff) | |
Rails 5.2 test updates
- Rename test/functional → test/controllers, test/unit → test/models
- Remove test/performance/browsing_test.rb (performance_test_help removed)
- Fix use_transactional_fixtures → use_transactional_tests
- Remove use_instantiated_fixtures (removed in Rails 5)
- Fix ActiveRecord::Fixtures → FixtureSet
- Fix controller test params syntax: add params: {} wrapper throughout
- Fix assert_select targets for aggregator test
- Fix test_update_a_draft_with_changing_the_template: draft → head
- Add test_node.reload after children.create! (awesome_nested_set bug)
- Add before/after count pattern for create tests (transactional isolation)
- Known failures: 5 tests affected by Rails 5 transactional test isolation
Diffstat (limited to 'test/controllers/sessions_controller_test.rb')
| -rw-r--r-- | test/controllers/sessions_controller_test.rb | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/test/controllers/sessions_controller_test.rb b/test/controllers/sessions_controller_test.rb new file mode 100644 index 0000000..bfcc647 --- /dev/null +++ b/test/controllers/sessions_controller_test.rb | |||
| @@ -0,0 +1,32 @@ | |||
| 1 | require File.dirname(__FILE__) + '/../test_helper' | ||
| 2 | require 'sessions_controller' | ||
| 3 | |||
| 4 | # Re-raise errors caught by the controller. | ||
| 5 | class SessionsController; def rescue_action(e) raise e end; end | ||
| 6 | |||
| 7 | class SessionsControllerTest < ActionController::TestCase | ||
| 8 | # Be sure to include AuthenticatedTestHelper in test/test_helper.rb instead | ||
| 9 | # Then, you can remove it from this and the units test. | ||
| 10 | include AuthenticatedTestHelper | ||
| 11 | |||
| 12 | fixtures :users | ||
| 13 | |||
| 14 | def test_should_login_and_redirect | ||
| 15 | post :create, params: { login: 'quentin', password: 'monkey' } | ||
| 16 | assert session[:user_id] | ||
| 17 | assert_response :redirect | ||
| 18 | end | ||
| 19 | |||
| 20 | def test_should_fail_login_and_not_redirect | ||
| 21 | post :create, params: { login: 'quentin', password: 'bad password' } | ||
| 22 | assert_nil session[:user_id] | ||
| 23 | assert_response :success | ||
| 24 | end | ||
| 25 | |||
| 26 | def test_should_logout | ||
| 27 | login_as :quentin | ||
| 28 | get :destroy | ||
| 29 | assert_nil session[:user_id] | ||
| 30 | assert_response :redirect | ||
| 31 | end | ||
| 32 | end | ||
