Module: BeyondTheApiTestHelpers::Request::CommonAssertions
- Defined in:
- lib/beyond_the_api_test_helpers/request/common_assertions.rb
Instance Method Summary collapse
- #assert_not_found_request ⇒ Object
- #assert_parameter_missing_request ⇒ Object
- #assert_request_needs_to_be_logged(url, http_method) ⇒ Object
- #json_response_name ⇒ Object
- #meta ⇒ Object
- #request_instance_variables_set(params = {}) ⇒ Object
- #request_instance_variables_set_pluralize(params = {}) ⇒ Object
Instance Method Details
#assert_not_found_request ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/beyond_the_api_test_helpers/request/common_assertions.rb', line 35 def assert_not_found_request response_assertions(status: 404) not_found_obj = @not_found_name ? I18n.t(@not_found_name) : subject.class.model_name.human = I18n.t('api.errors.messages.not_found', obj: not_found_obj) assert_equal , json['error'] end |
#assert_parameter_missing_request ⇒ Object
43 44 45 46 47 48 |
# File 'lib/beyond_the_api_test_helpers/request/common_assertions.rb', line 43 def assert_parameter_missing_request response_assertions(status: 400) = I18n.t('api.errors.messages.parameter_missing', parameter: subject.class.to_s.underscore) assert_equal , json['error'] end |
#assert_request_needs_to_be_logged(url, http_method) ⇒ Object
4 5 6 7 8 9 10 11 |
# File 'lib/beyond_the_api_test_helpers/request/common_assertions.rb', line 4 def assert_request_needs_to_be_logged(url, http_method) assert_i18n_for_all_locales do send(http_method, url, params: @params, headers: @headers) response_assertions(status: 403) assert_equal true, json['redirect_to_login'] assert_equal I18n.t('api.errors.messages.require_user_authentication'), json['error'] end end |
#json_response_name ⇒ Object
17 18 19 |
# File 'lib/beyond_the_api_test_helpers/request/common_assertions.rb', line 17 def json_response_name json[@response_name] end |
#meta ⇒ Object
13 14 15 |
# File 'lib/beyond_the_api_test_helpers/request/common_assertions.rb', line 13 def json['meta'] end |
#request_instance_variables_set(params = {}) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/beyond_the_api_test_helpers/request/common_assertions.rb', line 21 def request_instance_variables_set(params = {}) params.each do |key, value| instance_variable_set("@#{key}", value) end @headers ||= {} @params ||= {} @response_name ||= (@klass || subject.class).to_s.underscore end |
#request_instance_variables_set_pluralize(params = {}) ⇒ Object
30 31 32 33 |
# File 'lib/beyond_the_api_test_helpers/request/common_assertions.rb', line 30 def request_instance_variables_set_pluralize(params = {}) request_instance_variables_set(params) @response_name = @response_name.pluralize end |