|
111 | 111 | is_expected.to include('Brandon')
|
112 | 112 | end
|
113 | 113 | end
|
| 114 | + |
| 115 | + context 'with dot notation' do |
| 116 | + let(:headers) do |
| 117 | + { |
| 118 | + 'X-Inertia' => true, |
| 119 | + 'X-Inertia-Partial-Data' => 'nested.first,nested.deeply_nested.second,nested.deeply_nested.what_about_nil,nested.deeply_nested.what_about_empty_hash', |
| 120 | + 'X-Inertia-Partial-Component' => 'TestComponent', |
| 121 | + } |
| 122 | + end |
| 123 | + |
| 124 | + before { get deeply_nested_props_path, headers: headers } |
| 125 | + |
| 126 | + it 'only renders the dot notated props' do |
| 127 | + expect(response.parsed_body['props']).to eq( |
| 128 | + 'always' => 'always prop', |
| 129 | + 'nested' => { |
| 130 | + 'first' => 'first nested param', |
| 131 | + 'deeply_nested' => { |
| 132 | + 'second' => false, |
| 133 | + 'what_about_nil' => nil, |
| 134 | + 'what_about_empty_hash' => {}, |
| 135 | + 'deeply_nested_always' => 'deeply nested always prop', |
| 136 | + }, |
| 137 | + }, |
| 138 | + ) |
| 139 | + end |
| 140 | + end |
| 141 | + |
| 142 | + context 'with both partial and except dot notation' do |
| 143 | + let(:headers) do |
| 144 | + { |
| 145 | + 'X-Inertia' => true, |
| 146 | + 'X-Inertia-Partial-Component' => 'TestComponent', |
| 147 | + 'X-Inertia-Partial-Data' => 'lazy,nested.deeply_nested', |
| 148 | + 'X-Inertia-Partial-Except' => 'nested.deeply_nested.first', |
| 149 | + } |
| 150 | + end |
| 151 | + |
| 152 | + before { get deeply_nested_props_path, headers: headers } |
| 153 | + |
| 154 | + it 'renders the partial data and excludes the excepted data' do |
| 155 | + expect(response.parsed_body['props']).to eq( |
| 156 | + 'always' => 'always prop', |
| 157 | + 'lazy' => 'lazy param', |
| 158 | + 'nested' => { |
| 159 | + 'deeply_nested' => { |
| 160 | + 'second' => false, |
| 161 | + 'what_about_nil' => nil, |
| 162 | + 'what_about_empty_hash' => {}, |
| 163 | + 'deeply_nested_always' => 'deeply nested always prop', |
| 164 | + 'deeply_nested_lazy' => 'deeply nested lazy prop', |
| 165 | + }, |
| 166 | + }, |
| 167 | + ) |
| 168 | + end |
| 169 | + end |
| 170 | + |
| 171 | + context 'with nonsensical partial data that includes and excludes the same prop and tries to exclude an always prop' do |
| 172 | + let(:headers) do |
| 173 | + { |
| 174 | + 'X-Inertia' => true, |
| 175 | + 'X-Inertia-Partial-Component' => 'TestComponent', |
| 176 | + 'X-Inertia-Partial-Data' => 'lazy', |
| 177 | + 'X-Inertia-Partial-Except' => 'lazy,always', |
| 178 | + } |
| 179 | + end |
| 180 | + |
| 181 | + before { get deeply_nested_props_path, headers: headers } |
| 182 | + |
| 183 | + it 'excludes everything but Always props' do |
| 184 | + expect(response.parsed_body['props']).to eq( |
| 185 | + 'always' => 'always prop', |
| 186 | + 'nested' => { |
| 187 | + 'deeply_nested' => { |
| 188 | + 'deeply_nested_always' => 'deeply nested always prop', |
| 189 | + }, |
| 190 | + }, |
| 191 | + ) |
| 192 | + end |
| 193 | + end |
| 194 | + |
| 195 | + context 'with only props that target transformed data' do |
| 196 | + let(:headers) do |
| 197 | + { |
| 198 | + 'X-Inertia' => true, |
| 199 | + 'X-Inertia-Partial-Component' => 'TestComponent', |
| 200 | + 'X-Inertia-Partial-Data' => 'nested.evaluated.first', |
| 201 | + } |
| 202 | + end |
| 203 | + |
| 204 | + before { get deeply_nested_props_path, headers: headers } |
| 205 | + |
| 206 | + it 'filters out the entire evaluated prop' do |
| 207 | + expect(response.parsed_body['props']).to eq( |
| 208 | + 'always' => 'always prop', |
| 209 | + 'nested' => { |
| 210 | + 'deeply_nested' => { |
| 211 | + 'deeply_nested_always' => 'deeply nested always prop', |
| 212 | + }, |
| 213 | + }, |
| 214 | + ) |
| 215 | + end |
| 216 | + end |
| 217 | + |
| 218 | + context 'with except props that target transformed data' do |
| 219 | + let(:headers) do |
| 220 | + { |
| 221 | + 'X-Inertia' => true, |
| 222 | + 'X-Inertia-Partial-Component' => 'TestComponent', |
| 223 | + 'X-Inertia-Partial-Except' => 'nested.evaluated.first', |
| 224 | + } |
| 225 | + end |
| 226 | + |
| 227 | + before { get deeply_nested_props_path, headers: headers } |
| 228 | + |
| 229 | + it 'renders the entire evaluated prop' do |
| 230 | + expect(response.parsed_body['props']).to eq( |
| 231 | + 'always' => 'always prop', |
| 232 | + 'flat' => 'flat param', |
| 233 | + 'lazy' => 'lazy param', |
| 234 | + 'nested_lazy' => { 'first' => 'first nested lazy param' }, |
| 235 | + 'nested' => { |
| 236 | + 'first' => 'first nested param', |
| 237 | + 'second' => 'second nested param', |
| 238 | + 'evaluated' => { |
| 239 | + 'first' => 'first evaluated nested param', |
| 240 | + 'second' => 'second evaluated nested param', |
| 241 | + }, |
| 242 | + 'deeply_nested' => { |
| 243 | + 'first' => 'first deeply nested param', |
| 244 | + 'second' => false, |
| 245 | + 'what_about_nil' => nil, |
| 246 | + 'what_about_empty_hash' => {}, |
| 247 | + 'deeply_nested_always' => 'deeply nested always prop', |
| 248 | + 'deeply_nested_lazy' => 'deeply nested lazy prop', |
| 249 | + }, |
| 250 | + }, |
| 251 | + ) |
| 252 | + end |
| 253 | + end |
114 | 254 | end
|
115 | 255 |
|
116 | 256 | context 'partial except rendering' do
|
|
0 commit comments