add tests for avatar upload

This commit is contained in:
Felix Van der Jeugt 2016-02-05 20:51:19 +01:00
parent 60827e1492
commit 7e1d6735d3
3 changed files with 203 additions and 1 deletions

View file

@ -45,10 +45,11 @@ describe UsersController, type: :controller do
end
context 'successful' do
it 'should update attributes' do
it 'should update privacy' do
new_private = !(@user.private)
put :update, id: @user, user: { private: new_private }
expect(@user.reload.private).to be new_private
expect(flash[:success]).to be_present
end
it 'should update dagschotel' do
@ -56,6 +57,25 @@ describe UsersController, type: :controller do
put :update, id: @user, user: { dagschotel_id: product.id }
expect(@user.reload.dagschotel).to eq(product)
end
it 'should accept real images' do
file = fixture_file_upload('files/real-image.png', 'image/png')
put :update, id: @user, user: { avatar: file }
expect(flash[:success]).to be_present
end
end
context 'danger zone' do
it 'should warn for NOPs' do
put :update, id: @user, user: {}
expect(flash[:notice]).to be_present
end
it 'should not accept unreal images' do
file = fixture_file_upload('files/unreal-image.svg', 'image/svg+xml')
put :update, id: @user, user: { avatar: file }
expect(flash[:error]).to be_present
end
end
end

BIN
spec/fixtures/files/real-image.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 KiB

182
spec/fixtures/files/unreal-image.svg vendored Normal file
View file

@ -0,0 +1,182 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="126.86385mm"
height="129.21333mm"
viewBox="0 0 449.51759 457.84252"
id="svg2"
version="1.1"
inkscape:version="0.91 r13725"
sodipodi:docname="unreal-image.svg"
inkscape:export-filename="/home/felix/real-image.png"
inkscape:export-xdpi="179.99899"
inkscape:export-ydpi="179.99899">
<defs
id="defs4">
<clipPath
id="clipPath3464"
clipPathUnits="userSpaceOnUse">
<rect
y="719.15387"
x="594.10657"
height="446.3454"
width="308.96982"
id="rect3466"
style="opacity:1;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" />
</clipPath>
<clipPath
id="clipPath4382"
clipPathUnits="userSpaceOnUse">
<path
inkscape:connector-curvature="0"
id="path4384"
d="M 548.67975,395.83302 527.01742,668.18928 383.49652,551.67654 Z"
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#ff00ff;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate" />
</clipPath>
</defs>
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="0.98994949"
inkscape:cx="92.586293"
inkscape:cy="194.15587"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="false"
fit-margin-top="0"
fit-margin-left="0"
fit-margin-right="0"
fit-margin-bottom="0"
inkscape:window-width="1366"
inkscape:window-height="750"
inkscape:window-x="0"
inkscape:window-y="18"
inkscape:window-maximized="0" />
<metadata
id="metadata7">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(-312.13672,-477.34107)">
<path
style="opacity:1;fill:#ff0000;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:8.19999981;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
d="M 536.89454,486.67773 A 224.75894,224.25386 0 0 1 761.6543,710.92969 224.75894,224.25386 0 0 1 536.89454,935.18359 224.75894,224.25386 0 0 1 312.13672,710.92969 224.75894,224.25386 0 0 1 536.89454,486.67773 Z m 0,41.57227 a 183.09261,182.68115 0 0 0 -183.0918,182.67969 183.09261,182.68115 0 0 0 37.25195,110.07226 l 266.25,-247.38867 A 183.09261,182.68115 0 0 0 536.89454,528.25 Z M 687.72071,607.40234 422.67383,853.67188 A 183.09261,182.68115 0 0 0 536.89454,893.61133 183.09261,182.68115 0 0 0 719.98829,710.92969 183.09261,182.68115 0 0 0 687.72071,607.40234 Z"
id="path3424"
inkscape:connector-curvature="0" />
<g
id="g4319"
transform="matrix(0.73397676,-0.47399264,0.47399264,0.73397676,-954.18931,1157.9347)">
<path
sodipodi:nodetypes="sscscsss"
inkscape:connector-curvature="0"
id="path4375"
d="m 1553.5714,420.93363 c 9.4724,-29.88909 32.5886,-50.12241 55,-69.28571 116.6944,-99.78194 210.8943,-55.73979 211.4286,129.28571 46.3223,-48.79389 77.2317,-19.18981 58.1158,32.12244 -10.5068,28.20331 -40.7796,73.82504 -65.2587,42.16328 -62.0208,162.28798 -235.737,208.55449 -267.3237,-47.83444 -1.7694,-14.36211 6.7176,-27.24112 9.825,-42.52646 3.1074,-15.28534 -6.1587,-30.1303 -1.787,-43.92482 z"
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#fde4c0;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate" />
<path
sodipodi:nodetypes="csscsssssssscccsscscc"
inkscape:connector-curvature="0"
id="path4377"
d="m 1670.7923,572.03467 c -50.5207,33.76022 -8.3119,37.60242 25.2538,54.04316 28.196,13.81062 99.2973,-30.43844 105.0559,-101.52033 3.3,-40.73397 5.4518,-103.50329 -22.7284,-126.77414 21.5796,-72.65894 -76.1354,-62.97728 -140.9163,-4.04062 -25.0183,22.76124 -83.4945,16.5469 -113.6422,-1.51522 -36.6935,-21.98388 1.1908,-66.07832 22.7284,-103.03557 22.1267,-37.96823 67.2527,-56.43278 110.1067,-66.16499 40.8909,-9.2864 83.2045,-11.80845 122.2284,3.53554 35.4133,13.92432 67.3444,39.43455 90.4087,69.70052 12.1279,15.91482 21.5079,35.58644 22.7284,55.55839 0.8196,13.41208 -8.69,25.59117 -10.6066,38.89088 -3.6028,25.0006 15.0034,56.65263 -1.5152,75.76144 -10.6707,-18.14265 -29.2988,-9.01153 -37.8808,-3.03046 3.235,15.35278 -16.5636,18.12386 -21.2131,21.2132 -3.6829,27.67231 -9.5078,56.9544 -18.1828,83.33759 -4.3151,13.12344 1.3963,28.48048 -7.071,39.39594 -116.2362,149.84241 -217.7047,69.61537 -227.7894,-7.57614 28.549,47.29288 45.9995,-5.84767 43.9416,-13.63706 -2.0717,-7.84195 -8.6487,-9.21001 -21.7183,-10.6066 18.4303,-17.61195 66.4229,-17.31534 80.8122,-3.53553 z"
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#000000;fill-opacity:0.5;fill-rule:evenodd;stroke:#000000;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate" />
<path
sodipodi:nodetypes="cssc"
inkscape:connector-curvature="0"
id="path4379"
d="m 1766.5043,432.88616 c 2.215,-5.64195 -82.4917,-59.51648 -107.3287,-20.70813 -6.5923,10.30059 23.9911,8.83883 36.618,2.27284 20.7808,-10.80604 46.7181,6.58855 70.7107,18.43529 z"
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#412e07;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate" />
<path
sodipodi:nodetypes="sssss"
inkscape:connector-curvature="0"
id="path4383"
d="m 1606.3951,422.53209 c 0.9746,0.26564 3.0419,-10.7985 -0.7576,-12.6269 -13.3466,-6.42269 -33.9737,-6.37661 -46.2145,3.03045 -5.2135,4.00656 -11.5833,22.61999 -6.3135,18.68782 16.7402,-12.49106 36.5189,-13.66139 53.2856,-9.09137 z"
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#412e07;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate" />
<path
sodipodi:nodetypes="ssss"
inkscape:connector-curvature="0"
id="path4387"
d="m 1591.7479,515.21359 c 14.1075,14.22657 49.0657,3.82144 60.1041,0.50507 15.1813,-4.56107 -49.5692,-30.78806 -60.1041,-23.99112 -6.5784,4.24424 -5.5124,17.92713 0,23.48605 z"
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#dbc5a8;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate" />
<path
sodipodi:nodetypes="ccc"
inkscape:connector-curvature="0"
id="path4385"
d="m 1703.8748,575.5702 c -2.4889,-69.03002 -123.0085,-77.59424 -128.0368,-13.38452 15.3659,-35.35707 90.9439,-39.17136 128.0368,13.38452 z"
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#000000;fill-opacity:0.54878049;fill-rule:evenodd;stroke:none;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate" />
<path
sodipodi:nodetypes="ccc"
inkscape:connector-curvature="0"
id="path4389"
d="m 1740.4928,449.0486 c -24.6033,-10.63023 -51.0204,-30.4158 -68.9429,-7.32361 26.5755,-2.18034 46.6746,3.96609 68.9429,7.32361 z"
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#ffffff;fill-opacity:0.5;fill-rule:evenodd;stroke:#000000;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate" />
<path
sodipodi:nodetypes="ccc"
inkscape:connector-curvature="0"
id="path4391"
d="m 1569.0194,453.08921 c 13.0385,-6.5504 28.1346,-10.35723 44.1942,-12.87945 -21.763,-7.42614 -37.5676,-4.92176 -44.1942,12.87945 z"
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#ffffff;fill-opacity:0.5;fill-rule:evenodd;stroke:#000000;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate" />
<path
id="path4393"
d="m 1692.625,430.99805 c -0.4456,-0.005 -0.8864,0.018 -1.3281,0.0332 a 8.8388348,8.2706242 0 0 0 -1.3125,4.31641 8.8388348,8.2706242 0 0 0 3.1347,6.3164 c 3.3473,0.24118 6.6228,0.57417 9.834,0.99024 a 8.8388348,8.2706242 0 0 0 4.709,-7.30664 8.8388348,8.2706242 0 0 0 -0.1152,-1.3125 c -5.1307,-1.80358 -10.1386,-2.98665 -14.9219,-3.03711 z"
style="opacity:1;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.89999998;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
inkscape:connector-curvature="0" />
<path
id="path4395"
d="m 1593.0137,436.28906 c -3.7184,0.008 -7.1081,0.56414 -10.1407,1.71485 a 8.4600277,8.1443548 0 0 0 -0.9746,3.78515 8.4600277,8.1443548 0 0 0 1.9786,5.22071 c 4.7738,-1.58078 9.7433,-2.90152 14.8437,-4.04688 a 8.4600277,8.1443548 0 0 0 0.098,-1.17383 8.4600277,8.1443548 0 0 0 -2.0743,-5.33008 c -1.2763,-0.11078 -2.522,-0.17238 -3.7304,-0.16992 z"
style="opacity:1;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.89999998;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
inkscape:connector-curvature="0" />
<path
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#412e07;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
d="m 1778.3736,397.78336 c 21.5796,-72.65894 -76.1354,-62.97728 -140.9163,-4.04062 -25.0183,22.76124 -83.4945,16.5469 -113.6422,-1.51522 -36.6935,-21.98388 1.1908,-66.07832 22.7284,-103.03557 22.1267,-37.96823 67.2527,-56.43278 110.1067,-66.16499 40.8909,-9.2864 83.2045,-11.80845 122.2284,3.53554 35.4133,13.92432 67.3444,39.43455 90.4087,69.70052 12.1279,15.91482 21.5079,35.58644 22.7284,55.55839 0.8196,13.41208 -8.69,25.59117 -10.6066,38.89088 -3.6028,25.0006 15.0034,56.65263 -1.5152,75.76144 -10.6707,-18.14265 -29.2988,-9.01153 -37.8808,-3.03046 3.235,15.35278 -16.5636,18.12386 -21.2131,21.2132 -6.0301,-19.16512 -6.4252,-54.01108 -42.4264,-86.87311 z"
id="path3509"
inkscape:connector-curvature="0"
sodipodi:nodetypes="csssssssscccc" />
<path
sodipodi:nodetypes="ccc"
inkscape:connector-curvature="0"
id="path4313"
d="m 1586.4898,572.50642 c 0.7234,-29.83178 65.7458,-27.32174 97.4388,-6.92993 -36.3381,-4.32443 -72.3868,-8.00354 -97.4388,6.92993 z"
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#ea715f;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:0.60000002;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate" />
<path
sodipodi:nodetypes="ccc"
inkscape:connector-curvature="0"
id="path4315"
d="m 1586.0714,571.64792 c -11.3479,-50.2996 92.1132,-27.13496 97.7092,-6.61612 -21.6104,-12.90451 -91.5268,-28.56781 -97.7092,6.61612 z"
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#ea715f;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:0.60000002;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate" />
<path
sodipodi:nodetypes="cssc"
inkscape:connector-curvature="0"
id="path4317"
d="m 1841.4286,480.57649 c 0,0 45.0956,-28.29135 22.1428,27.14286 -4.4669,10.78817 -20.2915,-0.68531 -24.8214,13.21428 -2.2136,6.79224 24.1712,14.25368 -4.4643,28.57143"
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:8.19999981;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.48780488;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate" />
</g>
<path
inkscape:connector-curvature="0"
id="path4627"
d="m 422.67383,853.67188 265.04688,-246.26954 -30.41602,-33.78906 -266.25,247.38867 z"
style="opacity:1;fill:#ff0000;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:8.19999981;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
sodipodi:nodetypes="ccccc" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 17 KiB