Sha256: 031ccc7de0dc9381f2a0e50da62fcdf5e44ae61b0e85541c9720f74bcc079ca2

Contents?: true

Size: 1.01 KB

Versions: 3

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

require 'test_helper'

class KwKeyreqBooksControllerTest < 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 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 if RUBY_VERSION >= '2.1'

Version data entries

3 entries across 3 versions & 1 rubygems

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