From 9e80553797975a60eb1fc072728f59d686ddd972 Mon Sep 17 00:00:00 2001 From: Celso Fernandes Date: Mon, 12 Mar 2018 17:20:42 -0300 Subject: [PATCH] Failing test to discuss the collection error on index --- database.sqlite3 | Bin 83968 -> 84992 bytes test/model_validations_test.rb | 34 +++++++++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/database.sqlite3 b/database.sqlite3 index 3f0a7b3d2dc63726fa619d9d91c3089fddd5e225..a3e1400369d4a0407a56c6dd985c4b4c39ad890b 100644 GIT binary patch delta 2226 zcmZ{m-)kII6vywqvy+KoTa%hJDNz_H+E$x%?#%r$ccEz}rZGa}kF@@vAiC5w4TfFG zrW;$UQxxe;I}52JZ2Kzci%*(@&xL{yg7^pc;ERufe}Xe}yUE@54g(9r=X}pE&N;I; zcFY@h&7Enp0{}RG$36o)KY#d>aiC*R^e_4meSoImU%OM42!iAZM3wS;r*YqbSgOir5MXpnwa89$}QWE>Mgbvj8Flb6$-%G98S z`J8HFv4SinFXftWAdVwA#@aXqIh&j?!3#mKQ2)qYZEUQst+$#wYwS}(wLOw#E;(+3 z$sl;+(?+;;S?hsO>alV%pByv6bP%l8FEuvp_q2u-bEa(?F34i?V%F?5txTL$dw?+^ zp0;n2{4)HH!EcQi#w2RDnrrQ$dsS#mqx$C7dV8xqGD5*>i?v%{(?e2Jb>!2Op)CO{#tOI3ar8{N4);(f@ z6ZzUMx3=w-dh@D%p;6y#>onYVv)#~>(Hvzf3|3Gr`vvFI>gZjBYP(~@J!q`Pm9OUy z{W^aLKE%&H4c-UFLnAWI85a5-eTA0L2>b(n3*UibseNuPj4P$L!1I}#rJ=bnl8D$S z*K#+1blQT57!_KriAyMVv`a3@LJWJOr{Up&Yl1oUsCEJ*5i#i9ISt2;7sJXOO2uAn z>KIERqENAB!l8ont5K~b5z&{5H5J0mTKA}S)mjn}eW6mEf2;*)7nuLJ|>ma_b|#zh8y+cz(u)(Cz+s8|XK5 zJKKP56pDDHbTG4oJ^hwSBI2jYwS)-$T=Ie}#lt2z7Npc33!nHZQ>@O=;04Tyh^^AV sMEHBBb?`1pBI2RPv>)&P9UvtC%J#de29`v`=3`<->$!wzH<1+Ne-l61-T(jq delta 697 zcmY+BPiqrF7{+IIb~mYRu}$-*NfZ}6X$kDk?C$KASi3f2p^7zB^dh)Otc7;BCTS#| z3Le_S98z-F-ULAqJeeE>Z-IUg4+Did7kHe;du{FmBWEDs495?K=VYu z1M^>Bd_l8qv?TqMK1;jO68t@0l#e00$11~fwH)u%p{6>9Ni7-&b(k**US(wkRDHi0 zyll1gXIxTkm)OMRydZdmEh?bo`;Ycp-Pco-;}VQH&)A$jR*FwtF7iQ%f?QT7+2y-Ns{q)rrWchtTHQB?}s-JMRiqgG~kecD? zrn79>%Nwkh0W|=8e?5AuKMcaYzSRoa9i1Popcn?RowUxvwFEaE?m7n!KPn)aFjd^VtvZ{aWtZS`JQ36{0hM&XUjX2zkf7^!DZW$9<^( E0g!d6ivR!s diff --git a/test/model_validations_test.rb b/test/model_validations_test.rb index 8c2957ca..9028c55c 100644 --- a/test/model_validations_test.rb +++ b/test/model_validations_test.rb @@ -4,12 +4,18 @@ class ModelValidationsTest < MiniTest::Spec class Album include ActiveModel::Validations - attr_accessor :title, :artist, :other_attribute + attr_accessor :title, :artist, :other_attribute, :tracks validates :title, :artist, presence: true validates :other_attribute, presence: true end + class Track + include ActiveModel::Validations + + attr_accessor :title + end + class AlbumRating include ActiveModel::Validations @@ -40,6 +46,17 @@ class CompositeForm < Reform::Form copy_validations_from album: Album, album_rating: AlbumRating end + class AlbumTracksForm < Reform::Form + # property :title + # validates :title, presence: true + + collection :tracks, populate_if_empty: Track do + property :title + + validates :title, presence: true + end + end + let(:album) { Album.new } describe 'non-composite form' do @@ -79,4 +96,17 @@ class CompositeForm < Reform::Form end -end \ No newline at end of file + describe 'validate correct position on collection' do + let(:album) { Album.new } + let(:track1) { Track.new } + let(:track2) { Track.new } + + let(:nested_form) { AlbumTracksForm.new(album) } + + it 'is not valid when title is not present' do + album.tracks = [track1, track2] + nested_form.validate(artist_name: 'test', title: nil, tracks: [{title: 'Track 1'}, {title: nil}]).must_equal false + nested_form.errors[:'tracks.title'][1].must_equal ['can\'t be blank'] + end + end +end