Sha256: 643ec193bfb74922169d6e7f9aed6535f56419ea5f8e5c5348b254a9ec2f3446

Contents?: true

Size: 1010 Bytes

Versions: 3

Compression:

Stored size: 1010 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

3 entries across 3 versions & 1 rubygems

Version Path
action_args-2.5.0 test/controllers/kwargs_controller_test.rb
action_args-2.4.0 test/controllers/kwargs_controller_test.rb
action_args-2.3.2 test/controllers/kwargs_controller_test.rb