Sha256: e9d240bca6f1aba7ae2ec78bb6588173f3911cb4f48274cbea69c85066c6d3ab

Contents?: true

Size: 1009 Bytes

Versions: 4

Compression:

Stored size: 1009 Bytes

Contents

# frozen_string_literal: true
require 'test_helper'

class KwBooksControllerTest < ActionController::TestCase
  sub_test_case 'GET index (having an optional parameter)' do
    test 'without giving any kw parameter (not even giving :required one)' do
      assert_raises(ActionController::BadRequest) { get :index }
    end

    test 'without giving any optional kw parameter' do
      get :index, params: {author_name: 'nari'}
      assert 200, response.code
    end

    test 'with kw parameter defaults to non-nil value' do
      get :index, params: {author_name: 'nari', page: 3}
      body = eval response.body
      assert_equal 'nari', body[:author_name]
      assert_equal '3', body[:page]
      assert_nil body[:q]
    end

    test 'with kw parameter defaults to nil' do
      get :index, params: {author_name: 'nari', q: 'Rails'}
      body = eval response.body
      assert_equal 'nari', body[:author_name]
      assert_equal '1', body[:page]
      assert_equal 'Rails', body[:q]
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
action_args-2.3.1 test/controllers/kwargs_controller_test.rb
action_args-2.3.0 test/controllers/kwargs_controller_test.rb
action_args-2.2.1 test/controllers/kwargs_controller_test.rb
action_args-2.2.0 test/controllers/kwargs_controller_test.rb