|
45 | 45 | ] |
46 | 46 | ) |
47 | 47 | end |
| 48 | + |
| 49 | + it 'warns when using camelCase' do |
| 50 | + attrs = { distinctAttribute: 'title' } |
| 51 | + |
| 52 | + expect do |
| 53 | + described_class.transform_attributes(attrs) |
| 54 | + end.to output(include('Attributes will be expected to be snake_case', 'distinctAttribute')).to_stderr |
| 55 | + end |
| 56 | + |
| 57 | + it 'warns when using camelCase in an array' do |
| 58 | + attrs = [ |
| 59 | + { 'index_uid' => 'movies', 'q' => 'prince' }, |
| 60 | + { 'indexUid' => 'books', 'q' => 'prince' } |
| 61 | + ] |
| 62 | + |
| 63 | + expect do |
| 64 | + described_class.transform_attributes(attrs) |
| 65 | + end.to output(include('Attributes will be expected to be snake_case', 'indexUid')).to_stderr |
| 66 | + end |
48 | 67 | end |
49 | 68 |
|
50 | 69 | describe '.version_error_handler' do |
51 | 70 | it 'spawns same error message' do |
52 | 71 | expect do |
53 | | - MeiliSearch::Utils.version_error_handler(:my_method) do |
| 72 | + described_class.version_error_handler(:my_method) do |
54 | 73 | raise MeiliSearch::ApiError.new(405, 'I came from Meili server', {}) |
55 | 74 | end |
56 | 75 | end.to raise_error(MeiliSearch::ApiError, /I came from Meili server/) |
57 | 76 | end |
58 | 77 |
|
59 | 78 | it 'spawns message with version hint' do |
60 | 79 | expect do |
61 | | - MeiliSearch::Utils.version_error_handler(:my_method) do |
| 80 | + described_class.version_error_handler(:my_method) do |
62 | 81 | raise MeiliSearch::ApiError.new(405, 'I came from Meili server', {}) |
63 | 82 | end |
64 | 83 | end.to raise_error(MeiliSearch::ApiError, /that `my_method` call requires/) |
65 | 84 | end |
66 | 85 |
|
67 | 86 | it 'adds hints to all error types' do |
68 | 87 | expect do |
69 | | - MeiliSearch::Utils.version_error_handler(:my_method) do |
| 88 | + described_class.version_error_handler(:my_method) do |
70 | 89 | raise MeiliSearch::CommunicationError, 'I am an error' |
71 | 90 | end |
72 | 91 | end.to raise_error(MeiliSearch::CommunicationError, /that `my_method` call requires/) |
|
77 | 96 | attrs = { attributesToHighlight: ['field'] } |
78 | 97 |
|
79 | 98 | expect do |
80 | | - Utils.warn_on_non_conforming_attribute_names(attrs) |
| 99 | + described_class.warn_on_non_conforming_attribute_names(attrs) |
81 | 100 | end.to output(include('Attributes will be expected to be snake_case', 'attributesToHighlight')).to_stderr |
82 | 101 | end |
83 | 102 |
|
84 | 103 | it 'warns when using a mixed case' do |
85 | 104 | attrs = { distinct_ATTribute: 'title' } |
86 | 105 |
|
87 | 106 | expect do |
88 | | - Utils.warn_on_non_conforming_attribute_names(attrs) |
| 107 | + described_class.warn_on_non_conforming_attribute_names(attrs) |
89 | 108 | end.to output(include('Attributes will be expected to be snake_case', 'distinct_ATTribute')).to_stderr |
90 | 109 | end |
91 | 110 |
|
92 | 111 | it 'does not warn when using snake_case' do |
93 | 112 | attrs = { q: 'query', attributes_to_highlight: ['field'] } |
94 | 113 |
|
95 | 114 | expect do |
96 | | - Utils.warn_on_non_conforming_attribute_names(attrs) |
| 115 | + described_class.warn_on_non_conforming_attribute_names(attrs) |
97 | 116 | end.not_to output.to_stderr |
98 | 117 | end |
99 | 118 | end |
|
0 commit comments