|
| 1 | +require File.expand_path('../../test_helper', __FILE__) |
| 2 | + |
| 3 | +def set_content_type_header! |
| 4 | + @request.headers['Content-Type'] = JSONAPI::MEDIA_TYPE |
| 5 | +end |
| 6 | + |
| 7 | +class WidgetsControllerTest < ActionController::TestCase |
| 8 | + def teardown |
| 9 | + Widget.delete_all |
| 10 | + Indicator.delete_all |
| 11 | + Agency.delete_all |
| 12 | + end |
| 13 | + |
| 14 | + def test_fetch_widgets_sort_by_agency_name |
| 15 | + agency_1 = Agency.create! name: 'beta' |
| 16 | + agency_2 = Agency.create! name: 'alpha' |
| 17 | + indicator_1 = Indicator.create! import_id: 'foobar', name: 'bar', agency: agency_1 |
| 18 | + indicator_2 = Indicator.create! import_id: 'foobar2', name: 'foo', agency: agency_2 |
| 19 | + Widget.create! name: 'bar', indicator: indicator_1 |
| 20 | + widget = Widget.create! name: 'foo', indicator: indicator_2 |
| 21 | + assert_cacheable_get :index, params: {sort: 'indicator.agency.name'} |
| 22 | + assert_response :success |
| 23 | + assert_equal widget.id.to_s, json_response['data'].first['id'] |
| 24 | + end |
| 25 | +end |
| 26 | + |
| 27 | +class IndicatorsControllerTest < ActionController::TestCase |
| 28 | + def teardown |
| 29 | + Widget.delete_all |
| 30 | + Indicator.delete_all |
| 31 | + Agency.delete_all |
| 32 | + end |
| 33 | + |
| 34 | + def test_fetch_indicators_sort_by_widgets_name |
| 35 | + agency = Agency.create! name: 'test' |
| 36 | + indicator_1 = Indicator.create! import_id: 'bar', name: 'bar', agency: agency |
| 37 | + indicator_2 = Indicator.create! import_id: 'foo', name: 'foo', agency: agency |
| 38 | + Widget.create! name: 'omega', indicator: indicator_1 |
| 39 | + Widget.create! name: 'beta', indicator: indicator_1 |
| 40 | + Widget.create! name: 'alpha', indicator: indicator_2 |
| 41 | + Widget.create! name: 'zeta', indicator: indicator_2 |
| 42 | + assert_cacheable_get :index, params: {sort: 'widgets.name'} |
| 43 | + assert_response :success |
| 44 | + assert_equal indicator_2.id.to_s, json_response['data'].first['id'] |
| 45 | + assert_equal 2, json_response['data'].size |
| 46 | + end |
| 47 | +end |
0 commit comments