Class: BugTest

Inherits:
Minitest::Test
  • Object
show all
Includes:
Rack::Test::Methods
Defined in:
lib/bug_report_templates/rails_5_latest.rb,
lib/bug_report_templates/rails_5_master.rb

Overview

Replace this with the code necessary to make your test fail.

Instance Method Summary collapse

Instance Method Details

#json_api_headersObject



89
90
91
# File 'lib/bug_report_templates/rails_5_latest.rb', line 89

def json_api_headers
  {'Accept' => JSONAPI::MEDIA_TYPE, 'CONTENT_TYPE' => JSONAPI::MEDIA_TYPE}
end

#test_create_your_modelsObject



106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/bug_report_templates/rails_5_latest.rb', line 106

def test_create_your_models
  json_request = {
      'data' => {
          type: 'your_models',
          attributes: {
              name: 'Jane Doe'
          }
      }
  }
  post '/your_models', json_request.to_json, json_api_headers
  assert last_response.created?
  refute_nil YourModel.find_by(name: 'Jane Doe')
end

#test_index_your_modelsObject



93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/bug_report_templates/rails_5_latest.rb', line 93

def test_index_your_models
  record = YourModel.create! name: 'John Doe'
  get '/your_models', nil, json_api_headers
  assert last_response.ok?
  json_response = JSON.parse(last_response.body)
  refute_nil json_response['data']
  refute_empty json_response['data']
  refute_empty json_response['data'].first
  assert record.id.to_s, json_response['data'].first['id']
  assert 'your_models', json_response['data'].first['type']
  assert({'name' => 'John Doe'}, json_response['data'].first['attributes'])
end