Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

issues_controller_test.rb 229KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2019 Jean-Philippe Lang
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. require File.expand_path('../../test_helper', __FILE__)
  19. class IssuesControllerTest < Redmine::ControllerTest
  20. fixtures :projects,
  21. :users, :email_addresses, :user_preferences,
  22. :roles,
  23. :members,
  24. :member_roles,
  25. :issues,
  26. :issue_statuses,
  27. :issue_relations,
  28. :versions,
  29. :trackers,
  30. :projects_trackers,
  31. :issue_categories,
  32. :enabled_modules,
  33. :enumerations,
  34. :attachments,
  35. :workflows,
  36. :custom_fields,
  37. :custom_values,
  38. :custom_fields_projects,
  39. :custom_fields_trackers,
  40. :time_entries,
  41. :journals,
  42. :journal_details,
  43. :queries,
  44. :repositories,
  45. :changesets,
  46. :watchers, :groups_users
  47. include Redmine::I18n
  48. def setup
  49. User.current = nil
  50. end
  51. def test_index
  52. with_settings :default_language => "en" do
  53. get :index
  54. assert_response :success
  55. # links to visible issues
  56. assert_select 'a[href="/issues/1"]', :text => /Cannot print recipes/
  57. assert_select 'a[href="/issues/5"]', :text => /Subproject issue/
  58. # private projects hidden
  59. assert_select 'a[href="/issues/6"]', 0
  60. assert_select 'a[href="/issues/4"]', 0
  61. # project column
  62. assert_select 'th', :text => /Project/
  63. end
  64. end
  65. def test_index_should_not_list_issues_when_module_disabled
  66. EnabledModule.where("name = 'issue_tracking' AND project_id = 1").delete_all
  67. get :index
  68. assert_response :success
  69. assert_select 'a[href="/issues/1"]', 0
  70. assert_select 'a[href="/issues/5"]', :text => /Subproject issue/
  71. end
  72. def test_index_should_list_visible_issues_only
  73. get(:index, :params => {:per_page => 100})
  74. assert_response :success
  75. Issue.open.each do |issue|
  76. assert_select "tr#issue-#{issue.id}", issue.visible? ? 1 : 0
  77. end
  78. end
  79. def test_index_with_project
  80. Setting.display_subprojects_issues = 0
  81. get(:index, :params => {:project_id => 1})
  82. assert_response :success
  83. # query form
  84. assert_select 'form#query_form' do
  85. assert_select 'div#query_form_with_buttons.hide-when-print' do
  86. assert_select 'div#query_form_content' do
  87. assert_select 'fieldset#filters.collapsible'
  88. assert_select 'fieldset#options'
  89. end
  90. assert_select 'p.buttons'
  91. end
  92. end
  93. assert_select 'a[href="/issues/1"]', :text => /Cannot print recipes/
  94. assert_select 'a[href="/issues/5"]', 0
  95. end
  96. def test_index_with_project_and_subprojects
  97. Setting.display_subprojects_issues = 1
  98. get(:index, :params => {:project_id => 1})
  99. assert_response :success
  100. assert_select 'a[href="/issues/1"]', :text => /Cannot print recipes/
  101. assert_select 'a[href="/issues/5"]', :text => /Subproject issue/
  102. assert_select 'a[href="/issues/6"]', 0
  103. end
  104. def test_index_with_project_and_subprojects_should_show_private_subprojects_with_permission
  105. @request.session[:user_id] = 2
  106. Setting.display_subprojects_issues = 1
  107. get(:index, :params => {:project_id => 1})
  108. assert_response :success
  109. assert_select 'a[href="/issues/1"]', :text => /Cannot print recipes/
  110. assert_select 'a[href="/issues/5"]', :text => /Subproject issue/
  111. assert_select 'a[href="/issues/6"]', :text => /Issue of a private subproject/
  112. end
  113. def test_index_with_project_and_default_filter
  114. get(
  115. :index,
  116. :params => {
  117. :project_id => 1,
  118. :set_filter => 1
  119. }
  120. )
  121. assert_response :success
  122. # default filter
  123. assert_query_filters [['status_id', 'o', '']]
  124. end
  125. def test_index_with_project_and_filter
  126. get(
  127. :index,
  128. :params => {
  129. :project_id => 1,
  130. :set_filter => 1,
  131. :f => ['tracker_id'],
  132. :op => {
  133. 'tracker_id' => '='
  134. },
  135. :v => {
  136. 'tracker_id' => ['1']
  137. }
  138. }
  139. )
  140. assert_response :success
  141. assert_query_filters [['tracker_id', '=', '1']]
  142. end
  143. def test_index_with_short_filters
  144. to_test = {
  145. 'status_id' => {
  146. 'o' => {:op => 'o', :values => ['']},
  147. 'c' => {:op => 'c', :values => ['']},
  148. '7' => {:op => '=', :values => ['7']},
  149. '7|3|4' => {:op => '=', :values => ['7', '3', '4']},
  150. '=7' => {:op => '=', :values => ['7']},
  151. '!3' => {:op => '!', :values => ['3']},
  152. '!7|3|4' => {:op => '!', :values => ['7', '3', '4']}
  153. },
  154. 'subject' => {
  155. 'This is a subject' => {:op => '=', :values => ['This is a subject']},
  156. 'o' => {:op => '=', :values => ['o']},
  157. '~This is part of a subject' => {:op => '~', :values => ['This is part of a subject']},
  158. '!~This is part of a subject' => {:op => '!~', :values => ['This is part of a subject']}
  159. },
  160. 'tracker_id' => {
  161. '3' => {:op => '=', :values => ['3']},
  162. '=3' => {:op => '=', :values => ['3']}
  163. },
  164. 'start_date' => {
  165. '2011-10-12' => {:op => '=', :values => ['2011-10-12']},
  166. '=2011-10-12' => {:op => '=', :values => ['2011-10-12']},
  167. '>=2011-10-12' => {:op => '>=', :values => ['2011-10-12']},
  168. '<=2011-10-12' => {:op => '<=', :values => ['2011-10-12']},
  169. '><2011-10-01|2011-10-30' => {:op => '><', :values => ['2011-10-01', '2011-10-30']},
  170. '<t+2' => {:op => '<t+', :values => ['2']},
  171. '>t+2' => {:op => '>t+', :values => ['2']},
  172. 't+2' => {:op => 't+', :values => ['2']},
  173. 't' => {:op => 't', :values => ['']},
  174. 'w' => {:op => 'w', :values => ['']},
  175. '>t-2' => {:op => '>t-', :values => ['2']},
  176. '<t-2' => {:op => '<t-', :values => ['2']},
  177. 't-2' => {:op => 't-', :values => ['2']}
  178. },
  179. 'created_on' => {
  180. '>=2011-10-12' => {:op => '>=', :values => ['2011-10-12']},
  181. '<t-2' => {:op => '<t-', :values => ['2']},
  182. '>t-2' => {:op => '>t-', :values => ['2']},
  183. 't-2' => {:op => 't-', :values => ['2']}
  184. },
  185. 'cf_1' => {
  186. 'c' => {:op => '=', :values => ['c']},
  187. '!c' => {:op => '!', :values => ['c']},
  188. '!*' => {:op => '!*', :values => ['']},
  189. '*' => {:op => '*', :values => ['']}
  190. },
  191. 'estimated_hours' => {
  192. '=13.4' => {:op => '=', :values => ['13.4']},
  193. '>=45' => {:op => '>=', :values => ['45']},
  194. '<=125' => {:op => '<=', :values => ['125']},
  195. '><10.5|20.5' => {:op => '><', :values => ['10.5', '20.5']},
  196. '!*' => {:op => '!*', :values => ['']},
  197. '*' => {:op => '*', :values => ['']}
  198. }
  199. }
  200. default_filter = {'status_id' => {:operator => 'o', :values => ['']}}
  201. to_test.each do |field, expression_and_expected|
  202. expression_and_expected.each do |filter_expression, expected|
  203. get(:index, :params => {:set_filter => 1, field => filter_expression})
  204. assert_response :success
  205. expected_with_default =
  206. default_filter.
  207. merge({field => {:operator => expected[:op], :values => expected[:values]}})
  208. assert_query_filters(
  209. expected_with_default.map {|f, v| [f, v[:operator], v[:values]]}
  210. )
  211. end
  212. end
  213. end
  214. def test_index_with_project_and_empty_filters
  215. get(
  216. :index,
  217. :params => {
  218. :project_id => 1,
  219. :set_filter => 1,
  220. :fields => ['']
  221. }
  222. )
  223. assert_response :success
  224. # no filter
  225. assert_query_filters []
  226. end
  227. def test_index_with_project_custom_field_filter
  228. field =
  229. ProjectCustomField.
  230. create!(:name => 'Client', :is_filter => true, :field_format => 'string')
  231. CustomValue.create!(:custom_field => field, :customized => Project.find(3), :value => 'Foo')
  232. CustomValue.create!(:custom_field => field, :customized => Project.find(5), :value => 'Foo')
  233. filter_name = "project.cf_#{field.id}"
  234. @request.session[:user_id] = 1
  235. get(
  236. :index,
  237. :params => {
  238. :set_filter => 1,
  239. :f => [filter_name],
  240. :op => {
  241. filter_name => '='
  242. },
  243. :v => {
  244. filter_name => ['Foo']
  245. },
  246. :c => ['project']
  247. }
  248. )
  249. assert_response :success
  250. assert_equal [3, 5], issues_in_list.map(&:project_id).uniq.sort
  251. end
  252. def test_index_with_project_status_filter
  253. project = Project.find(2)
  254. project.close
  255. project.save
  256. get(
  257. :index,
  258. :params => {
  259. :set_filter => 1,
  260. :f => ['project.status'],
  261. :op => {'project.status' => '='},
  262. :v => {'project.status' => ['1']}
  263. }
  264. )
  265. assert_response :success
  266. issues = issues_in_list.map(&:id).uniq.sort
  267. assert_include 1, issues
  268. assert_not_include 4, issues
  269. end
  270. def test_index_with_query
  271. get(
  272. :index,
  273. :params => {
  274. :project_id => 1,
  275. :query_id => 5
  276. }
  277. )
  278. assert_response :success
  279. assert_select '#sidebar .queries' do
  280. # assert only query is selected in sidebar
  281. assert_select 'a.query.selected', 1
  282. # assert link properties
  283. assert_select(
  284. 'a.query.selected[href=?]',
  285. '/projects/ecookbook/issues?query_id=5',
  286. :text => "Open issues by priority and tracker"
  287. )
  288. # assert only one clear link exists
  289. assert_select 'a.icon-clear-query', 1
  290. # assert clear link properties
  291. assert_select(
  292. 'a.icon-clear-query[title=?][href=?]',
  293. 'Clear',
  294. '/projects/ecookbook/issues?set_filter=1&sort=',
  295. 1
  296. )
  297. end
  298. end
  299. def test_index_with_query_grouped_by_tracker
  300. get(
  301. :index,
  302. :params => {
  303. :project_id => 1,
  304. :query_id => 6
  305. }
  306. )
  307. assert_response :success
  308. assert_select 'tr.group span.count'
  309. end
  310. def test_index_with_query_grouped_and_sorted_by_category
  311. get(
  312. :index,
  313. :params => {
  314. :project_id => 1,
  315. :set_filter => 1,
  316. :group_by => "category",
  317. :sort => "category"
  318. }
  319. )
  320. assert_response :success
  321. assert_select 'tr.group span.count'
  322. end
  323. def test_index_with_query_grouped_and_sorted_by_fixed_version
  324. get(
  325. :index,
  326. :params => {
  327. :project_id => 1,
  328. :set_filter => 1,
  329. :group_by => "fixed_version",
  330. :sort => "fixed_version"
  331. }
  332. )
  333. assert_response :success
  334. assert_select 'tr.group span.count'
  335. end
  336. def test_index_with_query_grouped_and_sorted_by_fixed_version_in_reverse_order
  337. get(
  338. :index,
  339. :params => {
  340. :project_id => 1,
  341. :set_filter => 1,
  342. :group_by => "fixed_version",
  343. :sort => "fixed_version:desc"
  344. }
  345. )
  346. assert_response :success
  347. assert_select 'tr.group span.count'
  348. end
  349. def test_index_grouped_by_due_date
  350. set_tmp_attachments_directory
  351. Issue.destroy_all
  352. Issue.generate!(:due_date => '2018-08-10')
  353. Issue.generate!(:due_date => '2018-08-10')
  354. Issue.generate!
  355. get(
  356. :index,
  357. :params => {
  358. :set_filter => 1,
  359. :group_by => "due_date"
  360. }
  361. )
  362. assert_response :success
  363. assert_select 'tr.group span.name', :value => '2018-08-10' do
  364. assert_select '~ span.count', :value => '2'
  365. end
  366. assert_select 'tr.group span.name', :value => '(blank)' do
  367. assert_select '~ span.count', :value => '1'
  368. end
  369. end
  370. def test_index_grouped_by_created_on_if_time_zone_is_utc
  371. # TODO: test fails with mysql
  372. skip if mysql?
  373. skip unless IssueQuery.new.groupable_columns.detect {|c| c.name == :created_on}
  374. @request.session[:user_id] = 2
  375. User.find(2).pref.update(time_zone: 'UTC')
  376. get(
  377. :index,
  378. :params => {
  379. :set_filter => 1,
  380. :group_by => 'created_on'
  381. }
  382. )
  383. assert_response :success
  384. assert_select 'tr.group span.name', :text => '07/19/2006' do
  385. assert_select '+ span.count', :text => '2'
  386. end
  387. end
  388. def test_index_grouped_by_created_on_if_time_zone_is_nil
  389. skip unless IssueQuery.new.groupable_columns.detect {|c| c.name == :created_on}
  390. current_user = User.find(2)
  391. @request.session[:user_id] = current_user.id
  392. current_user.pref.update(time_zone: nil)
  393. get(
  394. :index,
  395. :params => {
  396. :set_filter => 1,
  397. :group_by => 'created_on'
  398. }
  399. )
  400. assert_response :success
  401. # group_name depends on localtime
  402. group_name = format_date(Issue.second.created_on.localtime)
  403. assert_select 'tr.group span.name', :text => group_name do
  404. assert_select '+ span.count', :text => '2'
  405. end
  406. end
  407. def test_index_grouped_by_created_on_as_pdf
  408. skip unless IssueQuery.new.groupable_columns.detect {|c| c.name == :created_on}
  409. get(
  410. :index,
  411. :params => {
  412. :set_filter => 1,
  413. :group_by => 'created_on',
  414. :format => 'pdf'
  415. }
  416. )
  417. assert_response :success
  418. assert_equal 'application/pdf', response.media_type
  419. end
  420. def test_index_with_query_grouped_by_list_custom_field
  421. get(
  422. :index,
  423. :params => {
  424. :project_id => 1,
  425. :query_id => 9
  426. }
  427. )
  428. assert_response :success
  429. assert_select 'tr.group span.count'
  430. end
  431. def test_index_with_query_grouped_by_key_value_custom_field
  432. cf = IssueCustomField.
  433. create!(
  434. :name => 'Key',
  435. :is_for_all => true,
  436. :tracker_ids => [1, 2, 3],
  437. :field_format => 'enumeration'
  438. )
  439. cf.enumerations << valueb = CustomFieldEnumeration.new(:name => 'Value B', :position => 1)
  440. cf.enumerations << valuea = CustomFieldEnumeration.new(:name => 'Value A', :position => 2)
  441. CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => valueb.id)
  442. CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => valueb.id)
  443. CustomValue.create!(:custom_field => cf, :customized => Issue.find(3), :value => valuea.id)
  444. CustomValue.create!(:custom_field => cf, :customized => Issue.find(5), :value => '')
  445. get(
  446. :index,
  447. :params => {
  448. :project_id => 1,
  449. :set_filter => 1,
  450. :group_by => "cf_#{cf.id}"
  451. }
  452. )
  453. assert_response :success
  454. assert_select 'tr.group', 3
  455. assert_select 'tr.group' do
  456. assert_select 'span.name', :text => 'Value B'
  457. assert_select 'span.count', :text => '2'
  458. end
  459. assert_select 'tr.group' do
  460. assert_select 'span.name', :text => 'Value A'
  461. assert_select 'span.count', :text => '1'
  462. end
  463. end
  464. def test_index_with_query_grouped_by_user_custom_field
  465. cf = IssueCustomField.
  466. create!(
  467. :name => 'User',
  468. :is_for_all => true,
  469. :tracker_ids => [1, 2, 3],
  470. :field_format => 'user'
  471. )
  472. CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => '2')
  473. CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => '3')
  474. CustomValue.create!(:custom_field => cf, :customized => Issue.find(3), :value => '3')
  475. CustomValue.create!(:custom_field => cf, :customized => Issue.find(5), :value => '')
  476. get(
  477. :index,
  478. :params => {
  479. :project_id => 1,
  480. :set_filter => 1,
  481. :group_by => "cf_#{cf.id}"
  482. }
  483. )
  484. assert_response :success
  485. assert_select 'tr.group', 3
  486. assert_select 'tr.group' do
  487. assert_select 'a', :text => 'John Smith'
  488. assert_select 'span.count', :text => '1'
  489. end
  490. assert_select 'tr.group' do
  491. assert_select 'a', :text => 'Dave Lopper'
  492. assert_select 'span.count', :text => '2'
  493. end
  494. end
  495. def test_index_grouped_by_boolean_custom_field_should_distinguish_blank_and_false_values
  496. cf = IssueCustomField.
  497. create!(
  498. :name => 'Bool',
  499. :is_for_all => true,
  500. :tracker_ids => [1, 2, 3],
  501. :field_format => 'bool'
  502. )
  503. CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => '1')
  504. CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => '0')
  505. CustomValue.create!(:custom_field => cf, :customized => Issue.find(3), :value => '')
  506. with_settings :default_language => 'en' do
  507. get(
  508. :index,
  509. :params => {
  510. :project_id => 1,
  511. :set_filter => 1,
  512. :group_by => "cf_#{cf.id}"
  513. }
  514. )
  515. assert_response :success
  516. end
  517. assert_select 'tr.group', 3
  518. assert_select 'tr.group', :text => /Yes/
  519. assert_select 'tr.group', :text => /No/
  520. assert_select 'tr.group', :text => /blank/
  521. end
  522. def test_index_grouped_by_boolean_custom_field_with_false_group_in_first_position_should_show_the_group
  523. cf = IssueCustomField.
  524. create!(
  525. :name => 'Bool',
  526. :is_for_all => true,
  527. :tracker_ids => [1, 2, 3],
  528. :field_format => 'bool',
  529. :is_filter => true
  530. )
  531. CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => '0')
  532. CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => '0')
  533. with_settings :default_language => 'en' do
  534. get(
  535. :index,
  536. :params => {
  537. :project_id => 1,
  538. :set_filter => 1, "cf_#{cf.id}" => "*",
  539. :group_by => "cf_#{cf.id}"
  540. }
  541. )
  542. assert_response :success
  543. end
  544. assert_equal [1, 2], issues_in_list.map(&:id).sort
  545. assert_select 'tr.group', 1
  546. assert_select 'tr.group', :text => /No/
  547. end
  548. def test_index_with_query_grouped_by_tracker_in_normal_order
  549. 3.times {|i| Issue.generate!(:tracker_id => (i + 1))}
  550. get(
  551. :index,
  552. :params => {
  553. :set_filter => 1,
  554. :group_by => 'tracker',
  555. :sort => 'id:desc'
  556. }
  557. )
  558. assert_response :success
  559. assert_equal ["Bug", "Feature request", "Support request"],
  560. css_select("tr.issue td.tracker").map(&:text).uniq
  561. end
  562. def test_index_with_query_grouped_by_tracker_in_reverse_order
  563. 3.times {|i| Issue.generate!(:tracker_id => (i + 1))}
  564. get(
  565. :index,
  566. :params => {
  567. :set_filter => 1,
  568. :group_by => 'tracker',
  569. :c => ['tracker', 'subject'],
  570. :sort => 'id:desc,tracker:desc'
  571. }
  572. )
  573. assert_response :success
  574. assert_equal ["Bug", "Feature request", "Support request"].reverse,
  575. css_select("tr.issue td.tracker").map(&:text).uniq
  576. end
  577. def test_index_with_query_id_and_project_id_should_set_session_query
  578. get(
  579. :index,
  580. :params => {
  581. :project_id => 1,
  582. :query_id => 4
  583. }
  584. )
  585. assert_response :success
  586. assert_kind_of Hash, session[:issue_query]
  587. assert_equal 4, session[:issue_query][:id]
  588. assert_equal 1, session[:issue_query][:project_id]
  589. end
  590. def test_index_with_invalid_query_id_should_respond_404
  591. get(
  592. :index,
  593. :params => {
  594. :project_id => 1,
  595. :query_id => 999
  596. }
  597. )
  598. assert_response 404
  599. end
  600. def test_index_with_cross_project_query_in_session_should_show_project_issues
  601. q = IssueQuery.
  602. create!(
  603. :name => "cross_project_query", :user_id => 2,
  604. :project => nil, :column_names => ['project']
  605. )
  606. @request.session[:issue_query] = {:id => q.id, :project_id => 1}
  607. with_settings :display_subprojects_issues => '0' do
  608. get(:index, :params => {:project_id => 1})
  609. end
  610. assert_response :success
  611. assert_select 'h2', :text => q.name
  612. assert_equal ["eCookbook"], css_select("tr.issue td.project").map(&:text).uniq
  613. end
  614. def test_private_query_should_not_be_available_to_other_users
  615. q = IssueQuery.
  616. create!(
  617. :name => "private", :user => User.find(2),
  618. :visibility => IssueQuery::VISIBILITY_PRIVATE,
  619. :project => nil
  620. )
  621. @request.session[:user_id] = 3
  622. get(:index, :params => {:query_id => q.id})
  623. assert_response 403
  624. end
  625. def test_private_query_should_be_available_to_its_user
  626. q = IssueQuery.
  627. create!(
  628. :name => "private", :user => User.find(2),
  629. :visibility => IssueQuery::VISIBILITY_PRIVATE,
  630. :project => nil
  631. )
  632. @request.session[:user_id] = 2
  633. get(:index, :params => {:query_id => q.id})
  634. assert_response :success
  635. end
  636. def test_public_query_should_be_available_to_other_users
  637. q = IssueQuery.
  638. create!(
  639. :name => "public", :user => User.find(2),
  640. :visibility => IssueQuery::VISIBILITY_PUBLIC,
  641. :project => nil
  642. )
  643. @request.session[:user_id] = 3
  644. get(:index, :params => {:query_id => q.id})
  645. assert_response :success
  646. end
  647. def test_index_should_omit_page_param_in_export_links
  648. get(:index, :params => {:page => 2})
  649. assert_response :success
  650. assert_select 'a.atom[href="/issues.atom"]'
  651. assert_select 'a.csv[href="/issues.csv"]'
  652. assert_select 'a.pdf[href="/issues.pdf"]'
  653. assert_select 'form#csv-export-form[action="/issues.csv"]'
  654. end
  655. def test_index_should_not_warn_when_not_exceeding_export_limit
  656. with_settings :issues_export_limit => 200 do
  657. get :index
  658. assert_select '#csv-export-options p.icon-warning', 0
  659. end
  660. end
  661. def test_index_should_warn_when_exceeding_export_limit
  662. with_settings :issues_export_limit => 2 do
  663. get :index
  664. assert_select '#csv-export-options p.icon-warning', :text => %r{limit: 2}
  665. end
  666. end
  667. def test_index_should_include_query_params_as_hidden_fields_in_csv_export_form
  668. get(
  669. :index,
  670. :params => {
  671. :project_id => 1,
  672. :set_filter => "1",
  673. :tracker_id => "2",
  674. :sort => 'status',
  675. :c => ["status", "priority"]
  676. }
  677. )
  678. assert_select '#csv-export-form[action=?]', '/projects/ecookbook/issues.csv'
  679. assert_select '#csv-export-form[method=?]', 'get'
  680. assert_select '#csv-export-form' do
  681. assert_select 'input[name=?][value=?]', 'set_filter', '1'
  682. assert_select 'input[name=?][value=?]', 'f[]', 'tracker_id'
  683. assert_select 'input[name=?][value=?]', 'op[tracker_id]', '='
  684. assert_select 'input[name=?][value=?]', 'v[tracker_id][]', '2'
  685. assert_select 'input[name=?][value=?]', 'c[]', 'status'
  686. assert_select 'input[name=?][value=?]', 'c[]', 'priority'
  687. assert_select 'input[name=?][value=?]', 'sort', 'status'
  688. end
  689. get(
  690. :index,
  691. :params => {
  692. :project_id => 1,
  693. :set_filter => "1",
  694. :f => ['']
  695. }
  696. )
  697. assert_select '#csv-export-form input[name=?][value=?]', 'f[]', ''
  698. end
  699. def test_index_csv
  700. get(:index, :params => {:format => 'csv'})
  701. assert_response :success
  702. assert_equal 'text/csv', @response.media_type
  703. assert response.body.starts_with?("#,")
  704. lines = response.body.chomp.split("\n")
  705. # default columns + id and project
  706. assert_equal Setting.issue_list_default_columns.size + 2, lines[0].split(',').size
  707. end
  708. def test_index_csv_with_project
  709. get(
  710. :index,
  711. :params => {
  712. :project_id => 1,
  713. :format => 'csv'
  714. }
  715. )
  716. assert_response :success
  717. assert_equal 'text/csv', @response.media_type
  718. end
  719. def test_index_csv_without_any_filters
  720. @request.session[:user_id] = 1
  721. Issue.
  722. create!(
  723. :project_id => 1, :tracker_id => 1,
  724. :status_id => 5, :subject => 'Closed issue', :author_id => 1
  725. )
  726. get(
  727. :index,
  728. :params => {
  729. :set_filter => 1,
  730. :f => [''],
  731. :format => 'csv'
  732. }
  733. )
  734. assert_response :success
  735. # -1 for headers
  736. assert_equal Issue.count, response.body.chomp.split("\n").size - 1
  737. end
  738. def test_index_csv_with_description
  739. Issue.generate!(:description => 'test_index_csv_with_description')
  740. with_settings :default_language => 'en' do
  741. get(
  742. :index,
  743. :params => {
  744. :format => 'csv',
  745. :c => [:tracker, :description]
  746. }
  747. )
  748. assert_response :success
  749. end
  750. assert_equal 'text/csv', response.media_type
  751. headers = response.body.chomp.split("\n").first.split(',')
  752. assert_include 'Description', headers
  753. assert_include 'test_index_csv_with_description', response.body
  754. end
  755. def test_index_csv_with_spent_time_column
  756. issue = Issue.
  757. create!(
  758. :project_id => 1, :tracker_id => 1,
  759. :subject => 'test_index_csv_with_spent_time_column',
  760. :author_id => 2
  761. )
  762. TimeEntry.
  763. create!(
  764. :project => issue.project, :issue => issue,
  765. :hours => 7.33, :user => User.find(2),
  766. :spent_on => Date.today
  767. )
  768. get(
  769. :index,
  770. :params => {
  771. :format => 'csv',
  772. :set_filter => '1',
  773. :c => %w(subject spent_hours)
  774. }
  775. )
  776. assert_response :success
  777. assert_equal 'text/csv', @response.media_type
  778. lines = @response.body.chomp.split("\n")
  779. assert_include "#{issue.id},#{issue.subject},7.33", lines
  780. end
  781. def test_index_csv_with_all_columns
  782. get(
  783. :index,
  784. :params => {
  785. :format => 'csv',
  786. :c => ['all_inline']
  787. }
  788. )
  789. assert_response :success
  790. assert_equal 'text/csv', @response.media_type
  791. assert_match /\A#,/, response.body
  792. lines = response.body.chomp.split("\n")
  793. assert_equal IssueQuery.new.available_inline_columns.size, lines[0].split(',').size
  794. end
  795. def test_index_csv_with_multi_column_field
  796. CustomField.find(1).update_attribute :multiple, true
  797. issue = Issue.find(1)
  798. issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
  799. issue.save!
  800. get(
  801. :index,
  802. :params => {
  803. :format => 'csv',
  804. :c => ['tracker', "cf_1"]
  805. }
  806. )
  807. assert_response :success
  808. lines = @response.body.chomp.split("\n")
  809. assert lines.detect {|line| line.include?('"MySQL, Oracle"')}
  810. end
  811. def test_index_csv_should_format_float_custom_fields_with_csv_decimal_separator
  812. field =
  813. IssueCustomField.
  814. create!(
  815. :name => 'Float',
  816. :is_for_all => true,
  817. :tracker_ids => [1],
  818. :field_format => 'float'
  819. )
  820. issue =
  821. Issue.
  822. generate!(
  823. :project_id => 1, :tracker_id => 1,
  824. :custom_field_values => {field.id => '185.6'}
  825. )
  826. with_settings :default_language => 'fr' do
  827. get(
  828. :index,
  829. :params => {
  830. :format => 'csv',
  831. :c => ['id', 'tracker', "cf_#{field.id}"]
  832. }
  833. )
  834. assert_response :success
  835. issue_line =
  836. response.body.chomp.split("\n").
  837. map {|line| line.split(';')}.
  838. detect {|line| line[0]==issue.id.to_s}
  839. assert_include '185,60', issue_line
  840. end
  841. with_settings :default_language => 'en' do
  842. get(
  843. :index,
  844. :params => {
  845. :format => 'csv',
  846. :c => ['id', 'tracker', "cf_#{field.id}"]
  847. }
  848. )
  849. assert_response :success
  850. issue_line = response.body.chomp.
  851. split("\n").map {|line| line.split(',')}.
  852. detect {|line| line[0]==issue.id.to_s}
  853. assert_include '185.60', issue_line
  854. end
  855. end
  856. def test_index_csv_should_fill_parent_column_with_parent_id
  857. Issue.delete_all
  858. parent = Issue.generate!
  859. child = Issue.generate!(:parent_issue_id => parent.id)
  860. with_settings :default_language => 'en' do
  861. get(
  862. :index,
  863. :params => {
  864. :format => 'csv',
  865. :c => %w(parent)
  866. }
  867. )
  868. end
  869. lines = response.body.split("\n")
  870. assert_include "#{child.id},#{parent.id}", lines
  871. end
  872. def test_index_csv_big_5
  873. with_settings :default_language => "zh-TW" do
  874. str_utf8 = '一月'
  875. str_big5 = (+"\xa4@\xa4\xeb").force_encoding('Big5')
  876. issue = Issue.generate!(:subject => str_utf8)
  877. get(
  878. :index, :params => {
  879. :project_id => 1,
  880. :subject => str_utf8,
  881. :format => 'csv'
  882. }
  883. )
  884. assert_equal 'text/csv', @response.media_type
  885. lines = @response.body.chomp.split("\n")
  886. header = lines[0]
  887. status = (+"\xaa\xac\xbaA").force_encoding('Big5')
  888. assert_include status, header
  889. issue_line = lines.find {|l| l =~ /^#{issue.id},/}
  890. assert_include str_big5, issue_line
  891. end
  892. end
  893. def test_index_csv_cannot_convert_should_be_replaced_big_5
  894. with_settings :default_language => "zh-TW" do
  895. str_utf8 = '以内'
  896. issue = Issue.generate!(:subject => str_utf8)
  897. get(
  898. :index, :params => {
  899. :project_id => 1,
  900. :subject => str_utf8,
  901. :c => ['status', 'subject'],
  902. :format => 'csv',
  903. :set_filter => 1
  904. }
  905. )
  906. assert_equal 'text/csv', @response.media_type
  907. lines = @response.body.chomp.split("\n")
  908. header = lines[0]
  909. issue_line = lines.find {|l| l =~ /^#{issue.id},/}
  910. s1 = (+"\xaa\xac\xbaA").force_encoding('Big5') # status
  911. assert header.include?(s1)
  912. s2 = issue_line.split(",")[2]
  913. s3 = (+"\xa5H?").force_encoding('Big5') # subject
  914. assert_equal s3, s2
  915. end
  916. end
  917. def test_index_csv_tw
  918. with_settings :default_language => "zh-TW" do
  919. str1 = "test_index_csv_tw"
  920. issue = Issue.generate!(:subject => str1, :estimated_hours => '1234.5')
  921. get(
  922. :index,
  923. :params => {
  924. :project_id => 1,
  925. :subject => str1,
  926. :c => ['estimated_hours', 'subject'],
  927. :format => 'csv',
  928. :set_filter => 1
  929. }
  930. )
  931. assert_equal 'text/csv', @response.media_type
  932. lines = @response.body.chomp.split("\n")
  933. assert_include "#{issue.id},1234.50,#{str1}", lines
  934. end
  935. end
  936. def test_index_csv_fr
  937. with_settings :default_language => "fr" do
  938. str1 = "test_index_csv_fr"
  939. issue = Issue.generate!(:subject => str1, :estimated_hours => '1234.5')
  940. get(
  941. :index,
  942. :params => {
  943. :project_id => 1,
  944. :subject => str1,
  945. :c => ['estimated_hours', 'subject'],
  946. :format => 'csv',
  947. :set_filter => 1
  948. }
  949. )
  950. assert_equal 'text/csv', @response.media_type
  951. lines = @response.body.chomp.split("\n")
  952. assert_include "#{issue.id};1234,50;#{str1}", lines
  953. end
  954. end
  955. def test_index_csv_should_not_change_selected_columns
  956. get(
  957. :index,
  958. :params => {
  959. :set_filter => 1,
  960. :c => ["subject", "due_date"],
  961. :project_id => "ecookbook"
  962. }
  963. )
  964. assert_response :success
  965. assert_equal [:subject, :due_date], session[:issue_query][:column_names]
  966. get(
  967. :index,
  968. :params => {
  969. :set_filter => 1,
  970. :c =>["all_inline"],
  971. :project_id => "ecookbook",
  972. :format => 'csv'
  973. }
  974. )
  975. assert_response :success
  976. assert_equal [:subject, :due_date], session[:issue_query][:column_names]
  977. end
  978. def test_index_pdf
  979. ["en", "zh", "zh-TW", "ja", "ko", "ar"].each do |lang|
  980. with_settings :default_language => lang do
  981. get :index
  982. assert_response :success
  983. get(:index, :params => {:format => 'pdf'})
  984. assert_response :success
  985. assert_equal 'application/pdf', @response.media_type
  986. get(
  987. :index,
  988. :params => {
  989. :project_id => 1,
  990. :format => 'pdf'
  991. }
  992. )
  993. assert_response :success
  994. assert_equal 'application/pdf', @response.media_type
  995. get(
  996. :index,
  997. :params => {
  998. :project_id => 1,
  999. :query_id => 6,
  1000. :format => 'pdf'
  1001. }
  1002. )
  1003. assert_response :success
  1004. assert_equal 'application/pdf', @response.media_type
  1005. end
  1006. end
  1007. end
  1008. def test_index_pdf_with_query_grouped_by_list_custom_field
  1009. get(
  1010. :index,
  1011. :params => {
  1012. :project_id => 1,
  1013. :query_id => 9,
  1014. :format => 'pdf'
  1015. }
  1016. )
  1017. assert_response :success
  1018. assert_equal 'application/pdf', @response.media_type
  1019. end
  1020. def test_index_atom
  1021. get(
  1022. :index,
  1023. :params => {
  1024. :project_id => 'ecookbook',
  1025. :format => 'atom'
  1026. }
  1027. )
  1028. assert_response :success
  1029. assert_equal 'application/atom+xml', response.media_type
  1030. assert_select 'feed' do
  1031. assert_select 'link[rel=self][href=?]', 'http://test.host/projects/ecookbook/issues.atom'
  1032. assert_select 'link[rel=alternate][href=?]', 'http://test.host/projects/ecookbook/issues'
  1033. assert_select 'entry link[href=?]', 'http://test.host/issues/1'
  1034. end
  1035. end
  1036. def test_index_should_include_back_url_input
  1037. get(
  1038. :index,
  1039. :params => {
  1040. :project_id => 'ecookbook',
  1041. :foo => 'bar'
  1042. }
  1043. )
  1044. assert_response :success
  1045. assert_select 'input[name=back_url][value=?]', '/projects/ecookbook/issues?foo=bar'
  1046. end
  1047. def test_index_sort
  1048. get(:index, :params => {:sort => 'tracker,id:desc'})
  1049. assert_response :success
  1050. assert_equal(
  1051. issues_in_list.sort_by {|issue| [issue.tracker.position, -issue.id]},
  1052. issues_in_list
  1053. )
  1054. assert_select 'table.issues.sort-by-tracker.sort-asc'
  1055. end
  1056. def test_index_sort_by_field_not_included_in_columns
  1057. with_settings :issue_list_default_columns => %w(subject author) do
  1058. get(:index, :params => {:sort => 'tracker'})
  1059. assert_response :success
  1060. end
  1061. end
  1062. def test_index_sort_by_assigned_to
  1063. get(:index, :params => {:sort => 'assigned_to'})
  1064. assert_response :success
  1065. assignees = issues_in_list.map(&:assigned_to).compact
  1066. assert_equal assignees.sort, assignees
  1067. assert_select 'table.issues.sort-by-assigned-to.sort-asc'
  1068. end
  1069. def test_index_sort_by_assigned_to_desc
  1070. get(:index, :params => {:sort => 'assigned_to:desc'})
  1071. assert_response :success
  1072. assignees = issues_in_list.map(&:assigned_to).compact
  1073. assert_equal assignees.sort.reverse, assignees
  1074. assert_select 'table.issues.sort-by-assigned-to.sort-desc'
  1075. end
  1076. def test_index_group_by_assigned_to
  1077. get(
  1078. :index,
  1079. :params => {
  1080. :group_by => 'assigned_to',
  1081. :sort => 'priority'
  1082. }
  1083. )
  1084. assert_response :success
  1085. end
  1086. def test_index_sort_by_author
  1087. get(
  1088. :index,
  1089. :params => {
  1090. :sort => 'author',
  1091. :c => ['author']
  1092. }
  1093. )
  1094. assert_response :success
  1095. authors = issues_in_list.map(&:author)
  1096. assert_equal authors.sort, authors
  1097. end
  1098. def test_index_sort_by_author_desc
  1099. get(:index, :params => {:sort => 'author:desc'})
  1100. assert_response :success
  1101. authors = issues_in_list.map(&:author)
  1102. assert_equal authors.sort.reverse, authors
  1103. end
  1104. def test_index_group_by_author
  1105. get(
  1106. :index,
  1107. :params => {
  1108. :group_by => 'author',
  1109. :sort => 'priority'
  1110. }
  1111. )
  1112. assert_response :success
  1113. end
  1114. def test_index_sort_by_last_updated_by
  1115. get(:index, :params => {:sort => 'last_updated_by'})
  1116. assert_response :success
  1117. assert_select 'table.issues.sort-by-last-updated-by.sort-asc'
  1118. end
  1119. def test_index_sort_by_last_updated_by_desc
  1120. get(:index, :params => {:sort => 'last_updated_by:desc'})
  1121. assert_response :success
  1122. assert_select 'table.issues.sort-by-last-updated-by.sort-desc'
  1123. end
  1124. def test_index_sort_by_spent_hours
  1125. get(:index, :params => {:sort => 'spent_hours:desc'})
  1126. assert_response :success
  1127. hours = issues_in_list.map(&:spent_hours)
  1128. assert_equal hours.sort.reverse, hours
  1129. end
  1130. def test_index_sort_by_spent_hours_should_sort_by_visible_spent_hours
  1131. TimeEntry.delete_all
  1132. TimeEntry.generate!(:issue => Issue.generate!(:project_id => 1), :hours => 3)
  1133. TimeEntry.generate!(:issue => Issue.generate!(:project_id => 3), :hours => 4)
  1134. get(
  1135. :index,
  1136. :params => {
  1137. :sort => "spent_hours:desc",
  1138. :c => ['subject', 'spent_hours']
  1139. }
  1140. )
  1141. assert_response :success
  1142. assert_equal ['4.00', '3.00', '0.00'], columns_values_in_list('spent_hours')[0..2]
  1143. Project.find(3).disable_module!(:time_tracking)
  1144. get(
  1145. :index,
  1146. :params => {
  1147. :sort => "spent_hours:desc",
  1148. :c => ['subject', 'spent_hours']
  1149. }
  1150. )
  1151. assert_response :success
  1152. assert_equal ['3.00', '0.00', '0.00'], columns_values_in_list('spent_hours')[0..2]
  1153. end
  1154. def test_index_sort_by_total_spent_hours
  1155. get(:index, :params => {:sort => 'total_spent_hours:desc'})
  1156. assert_response :success
  1157. hours = issues_in_list.map(&:total_spent_hours)
  1158. assert_equal hours.sort.reverse, hours
  1159. end
  1160. def test_index_sort_by_total_estimated_hours
  1161. get(:index, :params => {:sort => 'total_estimated_hours:desc'})
  1162. assert_response :success
  1163. hours = issues_in_list.map(&:total_estimated_hours)
  1164. # Removes nil because the position of NULL is database dependent
  1165. hours.compact!
  1166. assert_equal hours.sort.reverse, hours
  1167. end
  1168. def test_index_sort_by_user_custom_field
  1169. cf = IssueCustomField.
  1170. create!(
  1171. :name => 'User',
  1172. :is_for_all => true,
  1173. :tracker_ids => [1, 2, 3],
  1174. :field_format => 'user'
  1175. )
  1176. CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => '2')
  1177. CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => '3')
  1178. CustomValue.create!(:custom_field => cf, :customized => Issue.find(3), :value => '3')
  1179. CustomValue.create!(:custom_field => cf, :customized => Issue.find(5), :value => '')
  1180. get(
  1181. :index,
  1182. :params => {
  1183. :project_id => 1,
  1184. :set_filter => 1,
  1185. :sort => "cf_#{cf.id},id"
  1186. }
  1187. )
  1188. assert_response :success
  1189. assert_equal(
  1190. [2, 3, 1],
  1191. issues_in_list.select {|issue| issue.custom_field_value(cf).present?}.map(&:id)
  1192. )
  1193. end
  1194. def test_index_with_columns
  1195. columns = ['tracker', 'subject', 'assigned_to', 'buttons']
  1196. get(
  1197. :index,
  1198. :params => {
  1199. :set_filter => 1,
  1200. :c => columns
  1201. }
  1202. )
  1203. assert_response :success
  1204. # query should use specified columns + id and checkbox
  1205. assert_select 'table.issues thead' do
  1206. assert_select 'th', columns.size + 2
  1207. assert_select 'th.tracker'
  1208. assert_select 'th.subject'
  1209. assert_select 'th.assigned_to'
  1210. assert_select 'th.buttons'
  1211. end
  1212. # columns should be stored in session
  1213. assert_kind_of Hash, session[:issue_query]
  1214. assert_kind_of Array, session[:issue_query][:column_names]
  1215. assert_equal columns, session[:issue_query][:column_names].map(&:to_s)
  1216. # ensure only these columns are kept in the selected columns list
  1217. assert_select 'select[name=?] option', 'c[]' do
  1218. assert_select 'option', 3
  1219. assert_select 'option[value=tracker]'
  1220. assert_select 'option[value=project]', 0
  1221. end
  1222. end
  1223. def test_index_without_project_should_implicitly_add_project_column_to_default_columns
  1224. with_settings :issue_list_default_columns => ['tracker', 'subject', 'assigned_to'] do
  1225. get(:index, :params => {:set_filter => 1})
  1226. end
  1227. # query should use specified columns
  1228. assert_equal ["#", "Project", "Tracker", "Subject", "Assignee"], columns_in_issues_list
  1229. end
  1230. def test_index_without_project_and_explicit_default_columns_should_not_add_project_column
  1231. with_settings :issue_list_default_columns => ['tracker', 'subject', 'assigned_to'] do
  1232. columns = ['id', 'tracker', 'subject', 'assigned_to']
  1233. get(
  1234. :index,
  1235. :params => {
  1236. :set_filter => 1,
  1237. :c => columns
  1238. }
  1239. )
  1240. end
  1241. # query should use specified columns
  1242. assert_equal ["#", "Tracker", "Subject", "Assignee"], columns_in_issues_list
  1243. end
  1244. def test_index_with_default_columns_should_respect_default_columns_order
  1245. columns = ['assigned_to', 'subject', 'status', 'tracker']
  1246. with_settings :issue_list_default_columns => columns do
  1247. get(
  1248. :index,
  1249. :params => {
  1250. :project_id => 1,
  1251. :set_filter => 1
  1252. }
  1253. )
  1254. assert_equal ["#", "Assignee", "Subject", "Status", "Tracker"], columns_in_issues_list
  1255. end
  1256. end
  1257. def test_index_with_custom_field_column
  1258. columns = %w(tracker subject cf_2)
  1259. get(
  1260. :index,
  1261. :params => {
  1262. :set_filter => 1,
  1263. :c => columns
  1264. }
  1265. )
  1266. assert_response :success
  1267. # query should use specified columns
  1268. assert_equal ["#", "Tracker", "Subject", "Searchable field"], columns_in_issues_list
  1269. assert_select 'table.issues' do
  1270. assert_select 'th.cf_2.string'
  1271. assert_select 'td.cf_2.string'
  1272. end
  1273. end
  1274. def test_index_with_multi_custom_field_column
  1275. field = CustomField.find(1)
  1276. field.update_attribute :multiple, true
  1277. issue = Issue.find(1)
  1278. issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
  1279. issue.save!
  1280. get(
  1281. :index,
  1282. :params => {
  1283. :set_filter => 1,
  1284. :c => %w(tracker subject cf_1)
  1285. }
  1286. )
  1287. assert_response :success
  1288. assert_select 'table.issues td.cf_1', :text => 'MySQL, Oracle'
  1289. end
  1290. def test_index_with_multi_user_custom_field_column
  1291. field =
  1292. IssueCustomField.
  1293. create!(
  1294. :name => 'Multi user', :field_format => 'user',
  1295. :multiple => true,
  1296. :tracker_ids => [1], :is_for_all => true
  1297. )
  1298. issue = Issue.find(1)
  1299. issue.custom_field_values = {field.id => ['2', '3']}
  1300. issue.save!
  1301. get(
  1302. :index,
  1303. :params => {
  1304. :set_filter => 1,
  1305. :c => ['tracker', 'subject', "cf_#{field.id}"]
  1306. }
  1307. )
  1308. assert_response :success
  1309. assert_select "table.issues td.cf_#{field.id}" do
  1310. assert_select 'a', 2
  1311. assert_select 'a[href=?]', '/users/2', :text => 'John Smith'
  1312. assert_select 'a[href=?]', '/users/3', :text => 'Dave Lopper'
  1313. end
  1314. end
  1315. def test_index_with_date_column
  1316. with_settings :date_format => '%d/%m/%Y' do
  1317. Issue.find(1).update_attribute :start_date, '1987-08-24'
  1318. get(
  1319. :index,
  1320. :params => {
  1321. :set_filter => 1,
  1322. :c => %w(start_date)
  1323. }
  1324. )
  1325. assert_select 'table.issues' do
  1326. assert_select 'th.start_date'
  1327. assert_select 'td.start_date', :text => '24/08/1987'
  1328. end
  1329. end
  1330. end
  1331. def test_index_with_done_ratio_column
  1332. Issue.find(1).update_attribute :done_ratio, 40
  1333. get(
  1334. :index,
  1335. :params => {
  1336. :set_filter => 1,
  1337. :c => %w(done_ratio)
  1338. }
  1339. )
  1340. assert_select 'table.issues td.done_ratio' do
  1341. assert_select 'table.progress' do
  1342. assert_select 'td.closed[style=?]', 'width: 40%;'
  1343. end
  1344. end
  1345. end
  1346. def test_index_with_spent_hours_column
  1347. Issue.expects(:load_visible_spent_hours).once
  1348. get(
  1349. :index,
  1350. :params => {
  1351. :set_filter => 1,
  1352. :c => %w(subject spent_hours)
  1353. }
  1354. )
  1355. assert_select 'table.issues tr#issue-3 td.spent_hours', :text => '1.00'
  1356. end
  1357. def test_index_with_total_spent_hours_column
  1358. Issue.expects(:load_visible_total_spent_hours).once
  1359. get(
  1360. :index,
  1361. :params => {
  1362. :set_filter => 1,
  1363. :c => %w(subject total_spent_hours)
  1364. }
  1365. )
  1366. assert_select 'table.issues tr#issue-3 td.total_spent_hours', :text => '1.00'
  1367. end
  1368. def test_index_with_total_estimated_hours_column
  1369. get(
  1370. :index,
  1371. :params => {
  1372. :set_filter => 1,
  1373. :c => %w(subject total_estimated_hours)
  1374. }
  1375. )
  1376. assert_select 'table.issues td.total_estimated_hours'
  1377. end
  1378. def test_index_should_not_show_spent_hours_column_without_permission
  1379. Role.anonymous.remove_permission! :view_time_entries
  1380. get(
  1381. :index,
  1382. :params => {
  1383. :set_filter => 1,
  1384. :c => %w(subject spent_hours)
  1385. }
  1386. )
  1387. assert_select 'td.spent_hours', 0
  1388. end
  1389. def test_index_with_fixed_version_column
  1390. get(
  1391. :index,
  1392. :params => {
  1393. :set_filter => 1,
  1394. :c => %w(fixed_version)
  1395. }
  1396. )
  1397. assert_select 'table.issues td.fixed_version' do
  1398. assert_select 'a[href=?]', '/versions/2', :text => 'eCookbook - 1.0'
  1399. end
  1400. end
  1401. def test_index_with_relations_column
  1402. IssueRelation.delete_all
  1403. IssueRelation.
  1404. create!(
  1405. :relation_type => "relates",
  1406. :issue_from => Issue.find(1), :issue_to => Issue.find(7)
  1407. )
  1408. IssueRelation.
  1409. create!(
  1410. :relation_type => "relates",
  1411. :issue_from => Issue.find(8), :issue_to => Issue.find(1)
  1412. )
  1413. IssueRelation.
  1414. create!(
  1415. :relation_type => "blocks",
  1416. :issue_from => Issue.find(1), :issue_to => Issue.find(11)
  1417. )
  1418. IssueRelation.
  1419. create!(
  1420. :relation_type => "blocks", :issue_from => Issue.find(12),
  1421. :issue_to => Issue.find(2)
  1422. )
  1423. get(
  1424. :index,
  1425. :params => {
  1426. :set_filter => 1,
  1427. :c => %w(subject relations)
  1428. }
  1429. )
  1430. assert_response :success
  1431. assert_select "tr#issue-1 td.relations" do
  1432. assert_select "span", 3
  1433. assert_select "span", :text => "Related to #7"
  1434. assert_select "span", :text => "Related to #8"
  1435. assert_select "span", :text => "Blocks #11"
  1436. end
  1437. assert_select "tr#issue-2 td.relations" do
  1438. assert_select "span", 1
  1439. assert_select "span", :text => "Blocked by #12"
  1440. end
  1441. assert_select "tr#issue-3 td.relations" do
  1442. assert_select "span", 0
  1443. end
  1444. get(
  1445. :index,
  1446. :params => {
  1447. :set_filter => 1,
  1448. :c => %w(relations),
  1449. :format => 'csv'
  1450. }
  1451. )
  1452. assert_response :success
  1453. assert_equal 'text/csv', response.media_type
  1454. lines = response.body.chomp.split("\n")
  1455. assert_include '1,"Related to #7, Related to #8, Blocks #11"', lines
  1456. assert_include '2,Blocked by #12', lines
  1457. assert_include '3,""', lines
  1458. get(
  1459. :index,
  1460. :params => {
  1461. :set_filter => 1,
  1462. :c => %w(subject relations),
  1463. :format => 'pdf'
  1464. }
  1465. )
  1466. assert_response :success
  1467. assert_equal 'application/pdf', response.media_type
  1468. end
  1469. def test_index_with_description_column
  1470. get(
  1471. :index,
  1472. :params => {
  1473. :set_filter => 1,
  1474. :c => %w(subject description)
  1475. }
  1476. )
  1477. assert_select 'table.issues thead th', 4 # columns: chekbox + id + subject
  1478. assert_select 'td.description[colspan="4"]', :text => 'Unable to print recipes'
  1479. get(
  1480. :index,
  1481. :params => {
  1482. :set_filter => 1,
  1483. :c => %w(subject description),
  1484. :format => 'pdf'
  1485. }
  1486. )
  1487. assert_response :success
  1488. assert_equal 'application/pdf', response.media_type
  1489. end
  1490. def test_index_with_last_notes_column
  1491. get(
  1492. :index,
  1493. :params => {
  1494. :set_filter => 1,
  1495. :c => %w(subject last_notes)
  1496. }
  1497. )
  1498. assert_response :success
  1499. assert_select 'table.issues thead th', 4 # columns: chekbox + id + subject
  1500. assert_select 'td.last_notes[colspan="4"]', :text => 'Some notes with Redmine links: #2, r2.'
  1501. assert_select(
  1502. 'td.last_notes[colspan="4"]',
  1503. :text => 'A comment with inline image: and a reference to #1 and r2.'
  1504. )
  1505. get(
  1506. :index,
  1507. :params => {
  1508. :set_filter => 1,
  1509. :c => %w(subject last_notes),
  1510. :format => 'pdf'
  1511. }
  1512. )
  1513. assert_response :success
  1514. assert_equal 'application/pdf', response.media_type
  1515. end
  1516. def test_index_with_last_notes_column_should_display_private_notes_with_permission_only
  1517. journal = Journal.
  1518. create!(
  1519. :journalized => Issue.find(2),
  1520. :notes => 'Public notes', :user_id => 1
  1521. )
  1522. journal = Journal.
  1523. create!(
  1524. :journalized => Issue.find(2),
  1525. :notes => 'Privates notes', :private_notes => true,
  1526. :user_id => 1
  1527. )
  1528. @request.session[:user_id] = 2
  1529. get(
  1530. :index,
  1531. :params => {
  1532. :set_filter => 1,
  1533. :c => %w(subject last_notes)
  1534. }
  1535. )
  1536. assert_response :success
  1537. assert_select 'td.last_notes[colspan="4"]', :text => 'Privates notes'
  1538. Role.find(1).remove_permission! :view_private_notes
  1539. get(
  1540. :index,
  1541. :params => {
  1542. :set_filter => 1,
  1543. :c => %w(subject last_notes)
  1544. }
  1545. )
  1546. assert_response :success
  1547. assert_select 'td.last_notes[colspan="4"]', :text => 'Public notes'
  1548. end
  1549. def test_index_with_description_and_last_notes_columns_should_display_column_name
  1550. get(
  1551. :index,
  1552. :params => {
  1553. :set_filter => 1,
  1554. :c => %w(subject last_notes description)
  1555. }
  1556. )
  1557. assert_response :success
  1558. assert_select 'td.last_notes[colspan="4"] span', :text => 'Last notes'
  1559. assert_select 'td.description[colspan="4"] span', :text => 'Description'
  1560. end
  1561. def test_index_with_full_width_layout_custom_field_column_should_show_column_as_block_column
  1562. field = IssueCustomField.
  1563. create!(
  1564. :name => 'Long text', :field_format => 'text',
  1565. :full_width_layout => '1',
  1566. :tracker_ids => [1], :is_for_all => true
  1567. )
  1568. issue = Issue.find(1)
  1569. issue.custom_field_values = {field.id => 'This is a long text'}
  1570. issue.save!
  1571. get(
  1572. :index,
  1573. :params => {
  1574. :set_filter => 1,
  1575. :c => ['subject', 'description', "cf_#{field.id}"]
  1576. }
  1577. )
  1578. assert_response :success
  1579. assert_select 'td.description[colspan="4"] span', :text => 'Description'
  1580. assert_select "td.cf_#{field.id} span", :text => 'Long text'
  1581. end
  1582. def test_index_with_parent_column
  1583. Issue.delete_all
  1584. parent = Issue.generate!
  1585. child = Issue.generate!(:parent_issue_id => parent.id)
  1586. get(:index, :params => {:c => %w(parent)})
  1587. assert_select 'td.parent', :text => "#{parent.tracker} ##{parent.id}"
  1588. assert_select 'td.parent a[title=?]', parent.subject
  1589. end
  1590. def test_index_with_parent_subject_column
  1591. Issue.delete_all
  1592. parent = Issue.generate!
  1593. child = Issue.generate!(:parent_issue_id => parent.id)
  1594. get(:index, :params => {:c => %w(parent.subject)})
  1595. assert_select 'table.issues' do
  1596. assert_select 'th.parent-subject', :text => l(:field_parent_issue_subject)
  1597. assert_select "tr#issue-#{child.id}" do
  1598. assert_select 'td.parent-subject', :text => parent.subject
  1599. end
  1600. end
  1601. end
  1602. def test_index_with_last_updated_by_column
  1603. get(
  1604. :index, :params => {
  1605. :c => %w(subject last_updated_by),
  1606. :issue_id => '1,2,3',
  1607. :sort => 'id',
  1608. :set_filter => '1'
  1609. }
  1610. )
  1611. assert_select 'td.last_updated_by'
  1612. assert_equal ["John Smith", "John Smith", ""], css_select('td.last_updated_by').map(&:text)
  1613. end
  1614. def test_index_with_attachments_column
  1615. get(
  1616. :index,
  1617. :params => {
  1618. :c => %w(subject attachments),
  1619. :set_filter => '1',
  1620. :sort => 'id'
  1621. }
  1622. )
  1623. assert_response :success
  1624. assert_select 'td.attachments'
  1625. assert_select 'tr#issue-2' do
  1626. assert_select 'td.attachments' do
  1627. assert_select 'span:nth-of-type(1)' do
  1628. assert_select 'a[href=?]', '/attachments/4', :text => 'source.rb'
  1629. assert_select 'a[href=?].icon-download', '/attachments/download/4/source.rb'
  1630. end
  1631. assert_select 'span:nth-of-type(2)' do
  1632. assert_select 'a[href=?]', '/attachments/10', :text => 'picture.jpg'
  1633. assert_select 'a[href=?].icon-download', '/attachments/download/10/picture.jpg'
  1634. end
  1635. end
  1636. end
  1637. end
  1638. def test_index_with_attachments_column_as_csv
  1639. get(
  1640. :index,
  1641. :params => {
  1642. :c => %w(subject attachments),
  1643. :set_filter => '1',
  1644. :sort => 'id',
  1645. :format => 'csv'
  1646. }
  1647. )
  1648. assert_response :success
  1649. assert_include "\"source.rb\npicture.jpg\"", response.body
  1650. end
  1651. def test_index_with_estimated_hours_total
  1652. Issue.delete_all
  1653. Issue.generate!(:estimated_hours => 5.5)
  1654. Issue.generate!(:estimated_hours => 1.1)
  1655. get(:index, :params => {:t => %w(estimated_hours)})
  1656. assert_response :success
  1657. assert_select '.query-totals'
  1658. assert_select '.total-for-estimated-hours span.value', :text => '6.60'
  1659. assert_select 'input[type=checkbox][name=?][value=estimated_hours][checked=checked]', 't[]'
  1660. end
  1661. def test_index_with_grouped_query_and_estimated_hours_total
  1662. Issue.delete_all
  1663. Issue.generate!(:estimated_hours => 5.5, :category_id => 1)
  1664. Issue.generate!(:estimated_hours => 2.3, :category_id => 1)
  1665. Issue.generate!(:estimated_hours => 1.1, :category_id => 2)
  1666. Issue.generate!(:estimated_hours => 4.6)
  1667. get(
  1668. :index,
  1669. :params => {
  1670. :t => %w(estimated_hours),
  1671. :group_by => 'category'
  1672. }
  1673. )
  1674. assert_response :success
  1675. assert_select '.query-totals'
  1676. assert_select '.query-totals .total-for-estimated-hours span.value', :text => '13.50'
  1677. assert_select 'tr.group', :text => /Printing/ do
  1678. assert_select '.total-for-estimated-hours span.value', :text => '7.80'
  1679. end
  1680. assert_select 'tr.group', :text => /Recipes/ do
  1681. assert_select '.total-for-estimated-hours span.value', :text => '1.10'
  1682. end
  1683. assert_select 'tr.group', :text => /blank/ do
  1684. assert_select '.total-for-estimated-hours span.value', :text => '4.60'
  1685. end
  1686. end
  1687. def test_index_with_int_custom_field_total
  1688. field = IssueCustomField.generate!(:field_format => 'int', :is_for_all => true)
  1689. CustomValue.create!(:customized => Issue.find(1), :custom_field => field, :value => '2')
  1690. CustomValue.create!(:customized => Issue.find(2), :custom_field => field, :value => '7')
  1691. get(:index, :params => {:t => ["cf_#{field.id}"]})
  1692. assert_response :success
  1693. assert_select '.query-totals'
  1694. assert_select ".total-for-cf-#{field.id} span.value", :text => '9'
  1695. end
  1696. def test_index_with_spent_time_total_should_sum_visible_spent_time_only
  1697. TimeEntry.delete_all
  1698. TimeEntry.generate!(:issue => Issue.generate!(:project_id => 1), :hours => 3)
  1699. TimeEntry.generate!(:issue => Issue.generate!(:project_id => 3), :hours => 4)
  1700. get :index, :params => {:t => ["spent_hours"]}
  1701. assert_response :success
  1702. assert_select ".total-for-spent-hours span.value", :text => '7.00'
  1703. Project.find(3).disable_module!(:time_tracking)
  1704. get :index, :params => {:t => ["spent_hours"]}
  1705. assert_response :success
  1706. assert_select ".total-for-spent-hours span.value", :text => '3.00'
  1707. end
  1708. def test_index_totals_should_default_to_settings
  1709. with_settings :issue_list_default_totals => ['estimated_hours'] do
  1710. get :index
  1711. assert_response :success
  1712. assert_select '.total-for-estimated-hours span.value'
  1713. assert_select '.query-totals>span', 1
  1714. end
  1715. end
  1716. def test_index_send_html_if_query_is_invalid
  1717. get(
  1718. :index,
  1719. :params => {
  1720. :f => ['start_date'],
  1721. :op => {
  1722. :start_date => '='
  1723. }
  1724. }
  1725. )
  1726. assert_equal 'text/html', @response.media_type
  1727. assert_select_error /Start date cannot be blank/i
  1728. end
  1729. def test_index_send_nothing_if_query_is_invalid
  1730. get(
  1731. :index,
  1732. :params => {
  1733. :f => ['start_date'],
  1734. :op => {
  1735. :start_date => '='
  1736. },
  1737. :format => 'csv'
  1738. }
  1739. )
  1740. assert_equal 'text/csv', @response.media_type
  1741. assert @response.body.blank?
  1742. end
  1743. def test_index_should_include_new_issue_link
  1744. @request.session[:user_id] = 2
  1745. get(:index, :params => {:project_id => 1})
  1746. assert_select(
  1747. '#content a.new-issue[href="/projects/ecookbook/issues/new"]',
  1748. :text => 'New issue'
  1749. )
  1750. end
  1751. def test_index_should_not_include_new_issue_link_for_project_without_trackers
  1752. Project.find(1).trackers.clear
  1753. @request.session[:user_id] = 2
  1754. get(:index, :params => {:project_id => 1})
  1755. assert_select '#content a.new-issue', 0
  1756. end
  1757. def test_index_should_not_include_new_issue_link_for_users_with_copy_issues_permission_only
  1758. role = Role.find(1)
  1759. role.remove_permission! :add_issues
  1760. role.add_permission! :copy_issues
  1761. @request.session[:user_id] = 2
  1762. get(:index, :params => {:project_id => 1})
  1763. assert_select '#content a.new-issue', 0
  1764. end
  1765. def test_index_without_project_should_include_new_issue_link
  1766. @request.session[:user_id] = 2
  1767. get :index
  1768. assert_select '#content a.new-issue[href="/issues/new"]', :text => 'New issue'
  1769. end
  1770. def test_index_should_not_include_new_issue_tab_when_disabled
  1771. with_settings :new_item_menu_tab => '0' do
  1772. @request.session[:user_id] = 2
  1773. get(:index, :params => {:project_id => 1})
  1774. assert_select '#main-menu a.new-issue', 0
  1775. end
  1776. end
  1777. def test_index_should_include_new_issue_tab_when_enabled
  1778. with_settings :new_item_menu_tab => '1' do
  1779. @request.session[:user_id] = 2
  1780. get(:index, :params => {:project_id => 1})
  1781. assert_select(
  1782. '#main-menu a.new-issue[href="/projects/ecookbook/issues/new"]',
  1783. :text => 'New issue'
  1784. )
  1785. end
  1786. end
  1787. def test_new_should_have_new_issue_tab_as_current_menu_item
  1788. with_settings :new_item_menu_tab => '1' do
  1789. @request.session[:user_id] = 2
  1790. get(:new, :params => {:project_id => 1})
  1791. assert_select '#main-menu a.new-issue.selected'
  1792. end
  1793. end
  1794. def test_index_should_not_include_new_issue_tab_for_project_without_trackers
  1795. with_settings :new_item_menu_tab => '1' do
  1796. Project.find(1).trackers.clear
  1797. @request.session[:user_id] = 2
  1798. get(:index, :params => {:project_id => 1})
  1799. assert_select '#main-menu a.new-issue', 0
  1800. end
  1801. end
  1802. def test_index_should_not_include_new_issue_tab_for_users_with_copy_issues_permission_only
  1803. with_settings :new_item_menu_tab => '1' do
  1804. role = Role.find(1)
  1805. role.remove_permission! :add_issues
  1806. role.add_permission! :copy_issues
  1807. @request.session[:user_id] = 2
  1808. get(:index, :params => {:project_id => 1})
  1809. assert_select '#main-menu a.new-issue', 0
  1810. end
  1811. end
  1812. def test_show_by_anonymous
  1813. get(:show, :params => {:id => 1})
  1814. assert_response :success
  1815. assert_select 'div.issue div.description', :text => /Unable to print recipes/
  1816. # anonymous role is allowed to add a note
  1817. assert_select 'form#issue-form' do
  1818. assert_select 'fieldset' do
  1819. assert_select 'legend', :text => 'Notes'
  1820. assert_select 'textarea[name=?]', 'issue[notes]'
  1821. end
  1822. end
  1823. assert_select 'title', :text => "Bug #1: Cannot print recipes - eCookbook - Redmine"
  1824. end
  1825. def test_show_by_manager
  1826. @request.session[:user_id] = 2
  1827. get(:show, :params => {:id => 1})
  1828. assert_select 'a', :text => /Quote/
  1829. assert_select 'form#issue-form' do
  1830. assert_select 'fieldset' do
  1831. assert_select 'legend', :text => 'Change properties'
  1832. assert_select 'input[name=?]', 'issue[subject]'
  1833. end
  1834. assert_select 'fieldset' do
  1835. assert_select 'legend', :text => 'Log time'
  1836. assert_select 'input[name=?]', 'time_entry[hours]'
  1837. end
  1838. assert_select 'fieldset' do
  1839. assert_select 'legend', :text => 'Notes'
  1840. assert_select 'textarea[name=?]', 'issue[notes]'
  1841. end
  1842. end
  1843. end
  1844. def test_show_should_display_update_form
  1845. @request.session[:user_id] = 2
  1846. get(:show, :params => {:id => 1})
  1847. assert_response :success
  1848. assert_select 'form#issue-form' do
  1849. assert_select 'input[name=?]', 'issue[is_private]'
  1850. assert_select 'select[name=?]', 'issue[project_id]'
  1851. assert_select 'select[name=?]', 'issue[tracker_id]'
  1852. assert_select 'input[name=?]', 'issue[subject]'
  1853. assert_select 'textarea[name=?]', 'issue[description]'
  1854. assert_select 'select[name=?]', 'issue[status_id]'
  1855. assert_select 'select[name=?]', 'issue[priority_id]'
  1856. assert_select 'select[name=?]', 'issue[assigned_to_id]'
  1857. assert_select 'select[name=?]', 'issue[category_id]'
  1858. assert_select 'select[name=?]', 'issue[fixed_version_id]'
  1859. assert_select 'input[name=?]', 'issue[parent_issue_id]'
  1860. assert_select 'input[name=?]', 'issue[start_date]'
  1861. assert_select 'input[name=?]', 'issue[due_date]'
  1862. assert_select 'select[name=?]', 'issue[done_ratio]'
  1863. assert_select 'input[name=?]', 'issue[custom_field_values][2]'
  1864. assert_select 'input[name=?]', 'issue[watcher_user_ids][]', 0
  1865. assert_select 'textarea[name=?]', 'issue[notes]'
  1866. end
  1867. end
  1868. def test_show_should_display_update_form_with_minimal_permissions
  1869. Role.find(1).update_attribute :permissions, [:view_issues, :add_issue_notes]
  1870. WorkflowTransition.where(:role_id => 1).delete_all
  1871. @request.session[:user_id] = 2
  1872. get(:show, :params => {:id => 1})
  1873. assert_response :success
  1874. assert_select 'form#issue-form' do
  1875. assert_select 'input[name=?]', 'issue[is_private]', 0
  1876. assert_select 'select[name=?]', 'issue[project_id]', 0
  1877. assert_select 'select[name=?]', 'issue[tracker_id]', 0
  1878. assert_select 'input[name=?]', 'issue[subject]', 0
  1879. assert_select 'textarea[name=?]', 'issue[description]', 0
  1880. assert_select 'select[name=?]', 'issue[status_id]', 0
  1881. assert_select 'select[name=?]', 'issue[priority_id]', 0
  1882. assert_select 'select[name=?]', 'issue[assigned_to_id]', 0
  1883. assert_select 'select[name=?]', 'issue[category_id]', 0
  1884. assert_select 'select[name=?]', 'issue[fixed_version_id]', 0
  1885. assert_select 'input[name=?]', 'issue[parent_issue_id]', 0
  1886. assert_select 'input[name=?]', 'issue[start_date]', 0
  1887. assert_select 'input[name=?]', 'issue[due_date]', 0
  1888. assert_select 'select[name=?]', 'issue[done_ratio]', 0
  1889. assert_select 'input[name=?]', 'issue[custom_field_values][2]', 0
  1890. assert_select 'input[name=?]', 'issue[watcher_user_ids][]', 0
  1891. assert_select 'textarea[name=?]', 'issue[notes]'
  1892. end
  1893. end
  1894. def test_show_should_not_display_update_form_without_permissions
  1895. Role.find(1).update_attribute :permissions, [:view_issues]
  1896. @request.session[:user_id] = 2
  1897. get(:show, :params => {:id => 1})
  1898. assert_response :success
  1899. assert_select 'form#issue-form', 0
  1900. end
  1901. def test_update_form_should_not_display_inactive_enumerations
  1902. assert !IssuePriority.find(15).active?
  1903. @request.session[:user_id] = 2
  1904. get(:show, :params => {:id => 1})
  1905. assert_response :success
  1906. assert_select 'form#issue-form' do
  1907. assert_select 'select[name=?]', 'issue[priority_id]' do
  1908. assert_select 'option[value="4"]'
  1909. assert_select 'option[value="15"]', 0
  1910. end
  1911. end
  1912. end
  1913. def test_update_form_should_allow_attachment_upload
  1914. @request.session[:user_id] = 2
  1915. get(:show, :params => {:id => 1})
  1916. assert_select 'form#issue-form[method=post][enctype="multipart/form-data"]' do
  1917. assert_select 'input[type=file][name=?]', 'attachments[dummy][file]'
  1918. end
  1919. end
  1920. def test_update_form_should_render_assign_to_me_link_when_issue_can_be_assigned_to_the_current_user
  1921. @request.session[:user_id] = 1
  1922. get :show, :params => {
  1923. :id => 10
  1924. }
  1925. assert_select 'form#issue-form #attributes' do
  1926. assert_select 'a[class=?][data-id=?]', 'assign-to-me-link', '1', 1
  1927. end
  1928. end
  1929. def test_update_form_should_not_render_assign_to_me_link_when_issue_cannot_be_assigned_to_the_current_user
  1930. @request.session[:user_id] = 1
  1931. get :show, :params => {
  1932. :id => 2
  1933. }
  1934. assert_select 'form#issue-form #attributes' do
  1935. assert_select 'a[class=?]', 'assign-to-me-link', 0
  1936. end
  1937. end
  1938. def test_update_form_should_not_show_assign_to_me_link_when_issue_is_assigned_to_the_current_user
  1939. issue = Issue.find(10)
  1940. issue.assigned_to_id = 1
  1941. issue.save!
  1942. @request.session[:user_id] = 1
  1943. get :show, :params => {
  1944. :id => 10
  1945. }
  1946. assert_select 'form#issue-form #attributes' do
  1947. assert_select 'a[class=?]', 'assign-to-me-link hidden', 1
  1948. end
  1949. end
  1950. def test_show_should_deny_anonymous_access_without_permission
  1951. Role.anonymous.remove_permission!(:view_issues)
  1952. get(:show, :params => {:id => 1})
  1953. assert_response :redirect
  1954. end
  1955. def test_show_should_deny_anonymous_access_to_private_issue
  1956. Issue.where(:id => 1).update_all(["is_private = ?", true])
  1957. get(:show, :params => {:id => 1})
  1958. assert_response :redirect
  1959. end
  1960. def test_show_should_deny_non_member_access_without_permission
  1961. Role.non_member.remove_permission!(:view_issues)
  1962. @request.session[:user_id] = 9
  1963. get(:show, :params => {:id => 1})
  1964. assert_response 403
  1965. end
  1966. def test_show_should_deny_non_member_access_to_private_issue
  1967. Issue.where(:id => 1).update_all(["is_private = ?", true])
  1968. @request.session[:user_id] = 9
  1969. get(:show, :params => {:id => 1})
  1970. assert_response 403
  1971. end
  1972. def test_show_should_deny_member_access_without_permission
  1973. Role.find(1).remove_permission!(:view_issues)
  1974. @request.session[:user_id] = 2
  1975. get(:show, :params => {:id => 1})
  1976. assert_response 403
  1977. end
  1978. def test_show_should_deny_member_access_to_private_issue_without_permission
  1979. Issue.where(:id => 1).update_all(["is_private = ?", true])
  1980. @request.session[:user_id] = 3
  1981. get(:show, :params => {:id => 1})
  1982. assert_response 403
  1983. end
  1984. def test_show_should_allow_author_access_to_private_issue
  1985. Issue.where(:id => 1).update_all(["is_private = ?, author_id = 3", true])
  1986. @request.session[:user_id] = 3
  1987. get(:show, :params => {:id => 1})
  1988. assert_response :success
  1989. end
  1990. def test_show_should_allow_assignee_access_to_private_issue
  1991. Issue.where(:id => 1).update_all(["is_private = ?, assigned_to_id = 3", true])
  1992. @request.session[:user_id] = 3
  1993. get(:show, :params => {:id => 1})
  1994. assert_response :success
  1995. end
  1996. def test_show_should_allow_member_access_to_private_issue_with_permission
  1997. Issue.where(:id => 1).update_all(["is_private = ?", true])
  1998. User.find(3).roles_for_project(Project.find(1)).first.update_attribute :issues_visibility, 'all'
  1999. @request.session[:user_id] = 3
  2000. get(:show, :params => {:id => 1})
  2001. assert_response :success
  2002. end
  2003. def test_show_should_format_related_issues_dates
  2004. with_settings :date_format => '%d/%m/%Y' do
  2005. issue = Issue.generate!(:start_date => '2018-11-29', :due_date => '2018-12-01')
  2006. IssueRelation.
  2007. create!(
  2008. :issue_from => Issue.find(1), :issue_to => issue,
  2009. :relation_type => 'relates'
  2010. )
  2011. get(:show, :params => {:id => 1})
  2012. assert_response :success
  2013. assert_select '#relations td.start_date', :text => '29/11/2018'
  2014. assert_select '#relations td.due_date', :text => '01/12/2018'
  2015. end
  2016. end
  2017. def test_show_should_not_disclose_relations_to_invisible_issues
  2018. Setting.cross_project_issue_relations = '1'
  2019. IssueRelation.
  2020. create!(
  2021. :issue_from => Issue.find(1),
  2022. :issue_to => Issue.find(2),
  2023. :relation_type => 'relates'
  2024. )
  2025. # Relation to a private project issue
  2026. IssueRelation.
  2027. create!(
  2028. :issue_from => Issue.find(1),
  2029. :issue_to => Issue.find(4),
  2030. :relation_type => 'relates'
  2031. )
  2032. get(:show, :params => {:id => 1})
  2033. assert_response :success
  2034. assert_select 'div#relations' do
  2035. assert_select 'a', :text => /#2$/
  2036. assert_select 'a', :text => /#4$/, :count => 0
  2037. end
  2038. end
  2039. def test_show_should_list_subtasks
  2040. Issue.
  2041. create!(
  2042. :project_id => 1, :author_id => 1, :tracker_id => 1,
  2043. :parent_issue_id => 1, :subject => 'Child Issue'
  2044. )
  2045. get(:show, :params => {:id => 1})
  2046. assert_response :success
  2047. assert_select 'div#issue_tree' do
  2048. assert_select 'td.subject', :text => /Child Issue/
  2049. end
  2050. end
  2051. def test_show_should_list_parents
  2052. issue = Issue.
  2053. create!(
  2054. :project_id => 1, :author_id => 1,
  2055. :tracker_id => 1, :parent_issue_id => 1,
  2056. :subject => 'Child Issue'
  2057. )
  2058. get(:show, :params => {:id => issue.id})
  2059. assert_response :success
  2060. assert_select 'div.subject' do
  2061. assert_select 'h3', 'Child Issue'
  2062. assert_select 'a[href="/issues/1"]'
  2063. end
  2064. end
  2065. def test_show_should_not_display_prev_next_links_without_query_in_session
  2066. get(:show, :params => {:id => 1})
  2067. assert_response :success
  2068. assert_select 'div.next-prev-links', 0
  2069. end
  2070. def test_show_should_display_prev_next_links_with_query_in_session
  2071. @request.session[:issue_query] =
  2072. {
  2073. :filters => {
  2074. 'status_id' => {
  2075. :values => [''], :operator => 'o'
  2076. }
  2077. },
  2078. :project_id => nil,
  2079. :sort => [['id', 'asc']]
  2080. }
  2081. with_settings :display_subprojects_issues => '0' do
  2082. get(:show, :params => {:id => 3})
  2083. end
  2084. assert_response :success
  2085. count = Issue.open.visible.count
  2086. # Previous and next issues for all projects
  2087. assert_select 'div.next-prev-links' do
  2088. assert_select 'a[href="/issues/2"]', :text => /Previous/
  2089. assert_select 'a[href="/issues/5"]', :text => /Next/
  2090. assert_select 'span.position', :text => "3 of #{count}"
  2091. end
  2092. end
  2093. def test_show_should_display_prev_next_links_with_saved_query_in_session
  2094. query =
  2095. IssueQuery.create!(
  2096. :name => 'test',
  2097. :visibility => IssueQuery::VISIBILITY_PUBLIC,
  2098. :user_id => 1,
  2099. :filters => {'status_id' => {:values => ['5'], :operator => '='}},
  2100. :sort_criteria => [['id', 'asc']]
  2101. )
  2102. @request.session[:issue_query] = {:id => query.id, :project_id => nil}
  2103. get(:show, :params => {:id => 11})
  2104. assert_response :success
  2105. # Previous and next issues for all projects
  2106. assert_select 'div.next-prev-links' do
  2107. assert_select 'a[href="/issues/8"]', :text => /Previous/
  2108. assert_select 'a[href="/issues/12"]', :text => /Next/
  2109. end
  2110. end
  2111. def test_show_should_display_prev_next_links_with_query_and_sort_on_association
  2112. @request.session[:issue_query] =
  2113. {
  2114. :filters => {
  2115. 'status_id' => {
  2116. :values => [''], :operator => 'o'
  2117. }
  2118. },
  2119. :project_id => nil
  2120. }
  2121. %w(project tracker status priority author assigned_to category fixed_version).
  2122. each do |assoc_sort|
  2123. @request.session[:issue_query][:sort] = [[assoc_sort, 'asc']]
  2124. get(:show, :params => {:id => 3})
  2125. assert_response :success, "Wrong response status for #{assoc_sort} sort"
  2126. assert_select 'div.next-prev-links' do
  2127. assert_select 'a', :text => /(Previous|Next)/
  2128. end
  2129. end
  2130. end
  2131. def test_show_should_display_prev_next_links_with_project_query_in_session
  2132. @request.session[:issue_query] =
  2133. {
  2134. :filters => {
  2135. 'status_id' => {:values => [''], :operator => 'o'}
  2136. },
  2137. :project_id => 1, :sort => [['id', 'asc']]
  2138. }
  2139. with_settings :display_subprojects_issues => '0' do
  2140. get(:show, :params => {:id => 3})
  2141. end
  2142. assert_response :success
  2143. # Previous and next issues inside project
  2144. assert_select 'div.next-prev-links' do
  2145. assert_select 'a[href="/issues/2"]', :text => /Previous/
  2146. assert_select 'a[href="/issues/7"]', :text => /Next/
  2147. end
  2148. end
  2149. def test_show_should_not_display_prev_link_for_first_issue
  2150. @request.session[:issue_query] =
  2151. {
  2152. :filters => {
  2153. 'status_id' => {:values => [''], :operator => 'o'}
  2154. },
  2155. :project_id => 1, :sort => [['id', 'asc']]
  2156. }
  2157. with_settings :display_subprojects_issues => '0' do
  2158. get(:show, :params => {:id => 1})
  2159. end
  2160. assert_response :success
  2161. assert_select 'div.next-prev-links' do
  2162. assert_select 'a', :text => /Previous/, :count => 0
  2163. assert_select 'a[href="/issues/2"]', :text => /Next/
  2164. end
  2165. end
  2166. def test_show_should_not_display_prev_next_links_for_issue_not_in_query_results
  2167. @request.session[:issue_query] =
  2168. {
  2169. :filters => {
  2170. 'status_id' => {:values => [''], :operator => 'c'}
  2171. },
  2172. :project_id => 1,
  2173. :sort => [['id', 'asc']]
  2174. }
  2175. get(:show, :params => {:id => 1})
  2176. assert_response :success
  2177. assert_select 'a', :text => /Previous/, :count => 0
  2178. assert_select 'a', :text => /Next/, :count => 0
  2179. end
  2180. def test_show_show_should_display_prev_next_links_with_query_sort_by_user_custom_field
  2181. cf = IssueCustomField.
  2182. create!(
  2183. :name => 'User',
  2184. :is_for_all => true,
  2185. :tracker_ids => [1, 2, 3],
  2186. :field_format => 'user'
  2187. )
  2188. CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => '2')
  2189. CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => '3')
  2190. CustomValue.create!(:custom_field => cf, :customized => Issue.find(3), :value => '3')
  2191. CustomValue.create!(:custom_field => cf, :customized => Issue.find(5), :value => '')
  2192. query =
  2193. IssueQuery.create!(
  2194. :name => 'test',
  2195. :visibility => IssueQuery::VISIBILITY_PUBLIC,
  2196. :user_id => 1, :filters => {},
  2197. :sort_criteria => [["cf_#{cf.id}", 'asc'], ['id', 'asc']]
  2198. )
  2199. @request.session[:issue_query] = {:id => query.id, :project_id => nil}
  2200. get(:show, :params => {:id => 3})
  2201. assert_response :success
  2202. assert_select 'div.next-prev-links' do
  2203. assert_select 'a[href="/issues/2"]', :text => /Previous/
  2204. assert_select 'a[href="/issues/1"]', :text => /Next/
  2205. end
  2206. end
  2207. def test_show_should_display_prev_next_links_when_request_has_previous_and_next_issue_ids_params
  2208. get(
  2209. :show,
  2210. :params => {
  2211. :id => 1,
  2212. :prev_issue_id => 1,
  2213. :next_issue_id => 3,
  2214. :issue_position => 2,
  2215. :issue_count => 4
  2216. }
  2217. )
  2218. assert_response :success
  2219. assert_select 'div.next-prev-links' do
  2220. assert_select 'a[href="/issues/1"]', :text => /Previous/
  2221. assert_select 'a[href="/issues/3"]', :text => /Next/
  2222. assert_select 'span.position', :text => "2 of 4"
  2223. end
  2224. end
  2225. def test_show_should_display_category_field_if_categories_are_defined
  2226. Issue.update_all :category_id => nil
  2227. get(:show, :params => {:id => 1})
  2228. assert_response :success
  2229. assert_select '.attributes .category'
  2230. end
  2231. def test_show_should_not_display_category_field_if_no_categories_are_defined
  2232. Project.find(1).issue_categories.delete_all
  2233. get(:show, :params => {:id => 1})
  2234. assert_response :success
  2235. assert_select 'table.attributes .category', 0
  2236. end
  2237. def test_show_should_display_link_to_the_assignee
  2238. get(:show, :params => {:id => 2})
  2239. assert_response :success
  2240. assert_select '.assigned-to' do
  2241. assert_select 'a[href="/users/3"]'
  2242. end
  2243. end
  2244. def test_show_should_display_visible_changesets_from_other_projects
  2245. project = Project.find(2)
  2246. issue = project.issues.first
  2247. issue.changeset_ids = [102]
  2248. issue.save!
  2249. # changesets from other projects should be displayed even if repository
  2250. # is disabled on issue's project
  2251. project.disable_module! :repository
  2252. @request.session[:user_id] = 2
  2253. get(
  2254. :issue_tab,
  2255. :params => {
  2256. :id => issue.id,
  2257. :name => 'changesets'
  2258. },
  2259. :xhr => true
  2260. )
  2261. assert_select 'a[href=?]', '/projects/ecookbook/repository/10/revisions/3'
  2262. end
  2263. def test_show_should_display_watchers
  2264. @request.session[:user_id] = 2
  2265. issue = Issue.find(1)
  2266. issue.add_watcher User.find(2)
  2267. issue.add_watcher Group.find(10)
  2268. get(:show, :params => {:id => 1})
  2269. assert_select 'div#watchers ul' do
  2270. assert_select 'li.user-2' do
  2271. assert_select 'a[href="/users/2"]'
  2272. assert_select 'a[class*=delete]'
  2273. end
  2274. assert_select "li.user-10" do
  2275. assert_select 'a[href="/users/10"]', false
  2276. assert_select 'a[class*=delete]'
  2277. end
  2278. end
  2279. end
  2280. def test_show_should_display_watchers_with_gravatars
  2281. @request.session[:user_id] = 2
  2282. issue = Issue.find(1)
  2283. issue.add_watcher User.find(2)
  2284. issue.add_watcher Group.find(10)
  2285. with_settings :gravatar_enabled => '1' do
  2286. get(:show, :params => {:id => 1})
  2287. end
  2288. assert_select 'div#watchers ul' do
  2289. assert_select 'li.user-2' do
  2290. assert_select 'img.gravatar[title=?]', 'John Smith'
  2291. assert_select 'a[href="/users/2"]'
  2292. assert_select 'a[class*=delete]'
  2293. end
  2294. assert_select "li.user-10" do
  2295. assert_select 'img.gravatar[title=?]', 'A Team'
  2296. assert_select 'a[href="/users/10"]', false
  2297. assert_select 'a[class*=delete]'
  2298. end
  2299. end
  2300. end
  2301. def test_show_with_thumbnails_enabled_should_display_thumbnails
  2302. @request.session[:user_id] = 2
  2303. with_settings :thumbnails_enabled => '1' do
  2304. get(:show, :params => {:id => 14})
  2305. assert_response :success
  2306. end
  2307. assert_select 'div.thumbnails' do
  2308. assert_select 'a[href="/attachments/16"]' do
  2309. assert_select 'img[src="/attachments/thumbnail/16"]'
  2310. end
  2311. end
  2312. end
  2313. def test_show_with_thumbnails_disabled_should_not_display_thumbnails
  2314. @request.session[:user_id] = 2
  2315. with_settings :thumbnails_enabled => '0' do
  2316. get(:show, :params => {:id => 14})
  2317. assert_response :success
  2318. end
  2319. assert_select 'div.thumbnails', 0
  2320. end
  2321. def test_show_with_multi_custom_field
  2322. field = CustomField.find(1)
  2323. field.update_attribute :multiple, true
  2324. issue = Issue.find(1)
  2325. issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
  2326. issue.save!
  2327. get(:show, :params => {:id => 1})
  2328. assert_response :success
  2329. assert_select ".cf_1 .value", :text => 'MySQL, Oracle'
  2330. end
  2331. def test_show_with_full_width_layout_custom_field_should_show_field_under_description
  2332. field =
  2333. IssueCustomField.
  2334. create!(
  2335. :name => 'Long text',
  2336. :field_format => 'text', :full_width_layout => '1',
  2337. :tracker_ids => [1], :is_for_all => true
  2338. )
  2339. issue = Issue.find(1)
  2340. issue.custom_field_values = {field.id => 'This is a long text'}
  2341. issue.save!
  2342. get(:show, :params => {:id => 1})
  2343. assert_response :success
  2344. # long text custom field should not be render in the attributes div
  2345. assert_select "div.attributes div.attribute.cf_#{field.id} p strong", 0, :text => 'Long text'
  2346. assert_select(
  2347. "div.attributes div.attribute.cf_#{field.id} div.value",
  2348. 0,
  2349. :text => 'This is a long text'
  2350. )
  2351. # long text custom field should be render under description field
  2352. assert_select "div.description ~ div.attribute.cf_#{field.id} p strong", :text => 'Long text'
  2353. assert_select(
  2354. "div.description ~ div.attribute.cf_#{field.id} div.value",
  2355. :text => 'This is a long text'
  2356. )
  2357. end
  2358. def test_show_custom_fields_with_full_text_formatting_should_be_rendered_using_wiki_class
  2359. half_field =
  2360. IssueCustomField.
  2361. create!(
  2362. :name => 'Half width field', :field_format => 'text',
  2363. :tracker_ids => [1], :is_for_all => true, :text_formatting => 'full'
  2364. )
  2365. full_field =
  2366. IssueCustomField.
  2367. create!(
  2368. :name => 'Full width field',
  2369. :field_format => 'text', :full_width_layout => '1',
  2370. :tracker_ids => [1], :is_for_all => true, :text_formatting => 'full'
  2371. )
  2372. issue = Issue.find(1)
  2373. issue.custom_field_values =
  2374. {full_field.id => 'This is a long text',
  2375. half_field.id => 'This is a short text'}
  2376. issue.save!
  2377. get(:show, :params => {:id => 1})
  2378. assert_response :success
  2379. assert_select "div.attribute.cf_#{half_field.id} div.value div.wiki", 1
  2380. assert_select "div.attribute.cf_#{full_field.id} div.value div.wiki", 1
  2381. end
  2382. def test_show_with_multi_user_custom_field
  2383. field =
  2384. IssueCustomField.
  2385. create!(
  2386. :name => 'Multi user',
  2387. :field_format => 'user', :multiple => true,
  2388. :tracker_ids => [1], :is_for_all => true
  2389. )
  2390. issue = Issue.find(1)
  2391. issue.custom_field_values = {field.id => ['2', '3']}
  2392. issue.save!
  2393. get(:show, :params => {:id => 1})
  2394. assert_response :success
  2395. assert_select ".cf_#{field.id} .value", :text => 'Dave Lopper, John Smith' do
  2396. assert_select 'a', :text => 'Dave Lopper'
  2397. assert_select 'a', :text => 'John Smith'
  2398. end
  2399. end
  2400. def test_show_should_not_display_default_value_for_new_custom_field
  2401. prior = Issue.generate!
  2402. field =
  2403. IssueCustomField.
  2404. generate!(
  2405. :name => 'WithDefault', :field_format => 'string',
  2406. :default_value => 'DEFAULT'
  2407. )
  2408. after = Issue.generate!
  2409. get :show, :params => {:id => prior.id}
  2410. assert_response :success
  2411. assert_select ".cf_#{field.id} .value", :text => ''
  2412. get :show, :params => {:id => after.id}
  2413. assert_response :success
  2414. assert_select ".cf_#{field.id} .value", :text => 'DEFAULT'
  2415. end
  2416. def test_show_should_display_private_notes_with_permission_only
  2417. journal =
  2418. Journal.
  2419. create!(
  2420. :journalized => Issue.find(2),
  2421. :notes => 'Privates notes',
  2422. :private_notes => true,
  2423. :user_id => 1
  2424. )
  2425. @request.session[:user_id] = 2
  2426. get(:show, :params => {:id => 2})
  2427. assert_response :success
  2428. assert_select "#change-#{journal.id}", 1
  2429. Role.find(1).remove_permission! :view_private_notes
  2430. get(:show, :params => {:id => 2})
  2431. assert_response :success
  2432. assert_select "#change-#{journal.id}", 0
  2433. end
  2434. def test_show_should_display_private_notes_created_by_current_user
  2435. User.find(3).roles_for_project(Project.find(1)).each do |role|
  2436. role.remove_permission! :view_private_notes
  2437. end
  2438. visible =
  2439. Journal.
  2440. create!(
  2441. :journalized => Issue.find(2),
  2442. :notes => 'Private notes',
  2443. :private_notes => true, :user_id => 3
  2444. )
  2445. not_visible =
  2446. Journal.create!(
  2447. :journalized => Issue.find(2),
  2448. :notes => 'Private notes',
  2449. :private_notes => true, :user_id => 1
  2450. )
  2451. @request.session[:user_id] = 3
  2452. get(:show, :params => {:id => 2})
  2453. assert_response :success
  2454. assert_select "#change-#{visible.id}", 1
  2455. assert_select "#change-#{not_visible.id}", 0
  2456. end
  2457. def test_show_atom
  2458. get(
  2459. :show,
  2460. :params => {
  2461. :id => 2,
  2462. :format => 'atom'
  2463. }
  2464. )
  2465. assert_response :success
  2466. assert_equal 'application/atom+xml', response.media_type
  2467. # Inline image
  2468. assert_select(
  2469. 'content',
  2470. :text => Regexp.new(Regexp.quote('http://test.host/attachments/download/10'))
  2471. )
  2472. end
  2473. def test_show_export_to_pdf
  2474. issue = Issue.find(3)
  2475. assert issue.relations.select{|r| r.other_issue(issue).visible?}.present?
  2476. get(
  2477. :show,
  2478. :params => {
  2479. :id => 3,
  2480. :format => 'pdf'
  2481. }
  2482. )
  2483. assert_response :success
  2484. assert_equal 'application/pdf', @response.media_type
  2485. assert @response.body.starts_with?('%PDF')
  2486. end
  2487. def test_export_to_pdf_with_utf8_u_fffd
  2488. issue = Issue.generate!(:subject => "�")
  2489. ["en", "zh", "zh-TW", "ja", "ko", "ar"].each do |lang|
  2490. with_settings :default_language => lang do
  2491. get(
  2492. :show,
  2493. :params => {
  2494. :id => issue.id,
  2495. :format => 'pdf'
  2496. }
  2497. )
  2498. assert_response :success
  2499. assert_equal 'application/pdf', @response.media_type
  2500. assert @response.body.starts_with?('%PDF')
  2501. end
  2502. end
  2503. end
  2504. def test_show_export_to_pdf_with_ancestors
  2505. issue = Issue.generate!(:project_id => 1, :author_id => 2,
  2506. :tracker_id => 1, :subject => 'child',
  2507. :parent_issue_id => 1)
  2508. get(
  2509. :show,
  2510. :params => {
  2511. :id => issue.id,
  2512. :format => 'pdf'
  2513. }
  2514. )
  2515. assert_response :success
  2516. assert_equal 'application/pdf', @response.media_type
  2517. assert @response.body.starts_with?('%PDF')
  2518. end
  2519. def test_show_export_to_pdf_with_descendants
  2520. c1 = Issue.generate!(:project_id => 1, :author_id => 2, :tracker_id => 1,
  2521. :subject => 'child', :parent_issue_id => 1)
  2522. c2 = Issue.generate!(:project_id => 1, :author_id => 2, :tracker_id => 1,
  2523. :subject => 'child', :parent_issue_id => 1)
  2524. c3 = Issue.generate!(:project_id => 1, :author_id => 2, :tracker_id => 1,
  2525. :subject => 'child', :parent_issue_id => c1.id)
  2526. get(
  2527. :show,
  2528. :params => {
  2529. :id => 1,
  2530. :format => 'pdf'
  2531. }
  2532. )
  2533. assert_response :success
  2534. assert_equal 'application/pdf', @response.media_type
  2535. assert @response.body.starts_with?('%PDF')
  2536. end
  2537. def test_show_export_to_pdf_with_journals
  2538. get(
  2539. :show,
  2540. :params => {
  2541. :id => 1,
  2542. :format => 'pdf'
  2543. }
  2544. )
  2545. assert_response :success
  2546. assert_equal 'application/pdf', @response.media_type
  2547. assert @response.body.starts_with?('%PDF')
  2548. end
  2549. def test_show_export_to_pdf_with_private_journal
  2550. Journal.create!(
  2551. :journalized => Issue.find(1),
  2552. :notes => 'Private notes',
  2553. :private_notes => true,
  2554. :user_id => 3
  2555. )
  2556. @request.session[:user_id] = 3
  2557. get(
  2558. :show,
  2559. :params => {
  2560. :id => 1,
  2561. :format => 'pdf'
  2562. }
  2563. )
  2564. assert_response :success
  2565. assert_equal 'application/pdf', @response.media_type
  2566. assert @response.body.starts_with?('%PDF')
  2567. end
  2568. def test_show_export_to_pdf_with_changesets
  2569. [[100], [100, 101], [100, 101, 102]].each do |cs|
  2570. issue1 = Issue.find(3)
  2571. issue1.changesets = Changeset.find(cs)
  2572. issue1.save!
  2573. issue = Issue.find(3)
  2574. assert_equal issue.changesets.count, cs.size
  2575. get(
  2576. :show,
  2577. :params => {
  2578. :id => 3,
  2579. :format => 'pdf'
  2580. }
  2581. )
  2582. assert_response :success
  2583. assert_equal 'application/pdf', @response.media_type
  2584. assert @response.body.starts_with?('%PDF')
  2585. end
  2586. end
  2587. def test_show_invalid_should_respond_with_404
  2588. get(:show, :params => {:id => 999})
  2589. assert_response 404
  2590. end
  2591. def test_show_on_active_project_should_display_edit_links
  2592. @request.session[:user_id] = 1
  2593. get(:show, :params => {:id => 1})
  2594. assert_response :success
  2595. assert_select 'a', :text => 'Edit'
  2596. assert_select 'a', :text => 'Delete'
  2597. end
  2598. def test_show_on_closed_project_should_not_display_edit_links
  2599. Issue.find(1).project.close
  2600. @request.session[:user_id] = 1
  2601. get(:show, :params => {:id => 1})
  2602. assert_response :success
  2603. assert_select 'a', :text => 'Edit', :count => 0
  2604. assert_select 'a', :text => 'Delete', :count => 0
  2605. end
  2606. def test_show_should_not_display_history_tabs_for_issue_without_journals
  2607. @request.session[:user_id] = 1
  2608. get :show, :params => {:id => 5}
  2609. assert_response :success
  2610. assert_select '#history div.tabs', 0
  2611. assert_select '#history p.nodata', :text => 'No data to display'
  2612. end
  2613. def test_show_display_only_all_and_notes_tabs_for_issue_with_notes_only
  2614. @request.session[:user_id] = 1
  2615. get :show, :params => {:id => 6}
  2616. assert_response :success
  2617. assert_select '#history' do
  2618. assert_select 'div.tabs ul a', 2
  2619. assert_select 'div.tabs a[id=?]', 'tab-history', :text => 'History'
  2620. assert_select 'div.tabs a[id=?]', 'tab-notes', :text => 'Notes'
  2621. end
  2622. end
  2623. def test_show_display_only_all_and_history_tabs_for_issue_with_history_changes_only
  2624. journal = Journal.create!(:journalized => Issue.find(5), :user_id => 1)
  2625. detail =
  2626. JournalDetail.
  2627. create!(
  2628. :journal => journal, :property => 'attr',
  2629. :prop_key => 'description',
  2630. :old_value => 'Foo', :value => 'Bar'
  2631. )
  2632. @request.session[:user_id] = 1
  2633. get :show, :params => {:id => 5}
  2634. assert_response :success
  2635. assert_select '#history' do
  2636. assert_select 'div.tabs ul a', 2
  2637. assert_select 'div.tabs a[id=?]', 'tab-history', :text => 'History'
  2638. assert_select 'div.tabs a[id=?]', 'tab-properties', :text => 'Property changes'
  2639. end
  2640. end
  2641. def test_show_display_all_notes_and_history_tabs_for_issue_with_notes_and_history_changes
  2642. journal = Journal.create!(:journalized => Issue.find(6), :user_id => 1)
  2643. detail =
  2644. JournalDetail.
  2645. create!(
  2646. :journal => journal, :property => 'attr',
  2647. :prop_key => 'description',
  2648. :old_value => 'Foo', :value => 'Bar'
  2649. )
  2650. @request.session[:user_id] = 1
  2651. get :show, :params => {:id => 6}
  2652. assert_response :success
  2653. assert_select '#history' do
  2654. assert_select 'div.tabs ul a', 3
  2655. assert_select 'div.tabs a[id=?]', 'tab-history', :text => 'History'
  2656. assert_select 'div.tabs a[id=?]', 'tab-notes', :text => 'Notes'
  2657. assert_select 'div.tabs a[id=?]', 'tab-properties', :text => 'Property changes'
  2658. end
  2659. end
  2660. def test_show_display_changesets_tab_for_issue_with_changesets
  2661. project = Project.find(2)
  2662. issue = Issue.find(9)
  2663. issue.changeset_ids = [102]
  2664. issue.save!
  2665. @request.session[:user_id] = 2
  2666. get :show, :params => {:id => issue.id}
  2667. assert_select '#history' do
  2668. assert_select 'div.tabs ul a', 1
  2669. assert_select 'div.tabs a[id=?]', 'tab-changesets', :text => 'Associated revisions'
  2670. end
  2671. end
  2672. def test_show_should_display_spent_time_tab_for_issue_with_time_entries
  2673. @request.session[:user_id] = 1
  2674. get :show, :params => {:id => 3}
  2675. assert_response :success
  2676. assert_select '#history' do
  2677. assert_select 'div.tabs ul a', 1
  2678. assert_select 'div.tabs a[id=?]', 'tab-time_entries', :text => 'Spent time'
  2679. end
  2680. get(
  2681. :issue_tab,
  2682. :params => {
  2683. :id => 3,
  2684. :name => 'time_entries'
  2685. },
  2686. :xhr => true
  2687. )
  2688. assert_response :success
  2689. assert_select 'div[id=?]', 'time-entry-3' do
  2690. assert_select 'a[title=?][href=?]', 'Edit', '/time_entries/3/edit'
  2691. assert_select 'a[title=?][href=?]', 'Delete', '/time_entries/3'
  2692. assert_select 'ul[class=?]', 'details', :text => /1.00 h/
  2693. end
  2694. end
  2695. def test_get_new
  2696. @request.session[:user_id] = 2
  2697. get(
  2698. :new,
  2699. :params => {
  2700. :project_id => 1,
  2701. :tracker_id => 1
  2702. }
  2703. )
  2704. assert_response :success
  2705. assert_select 'form#issue-form[action=?]', '/projects/ecookbook/issues'
  2706. assert_select 'form#issue-form' do
  2707. assert_select 'input[name=?]', 'issue[is_private]'
  2708. assert_select 'select[name=?]', 'issue[project_id]'
  2709. assert_select 'select[name=?]', 'issue[tracker_id]'
  2710. assert_select 'input[name=?]', 'issue[subject]'
  2711. assert_select 'textarea[name=?]', 'issue[description]'
  2712. assert_select 'select[name=?]', 'issue[status_id]'
  2713. assert_select 'select[name=?]', 'issue[priority_id]'
  2714. assert_select 'select[name=?]', 'issue[assigned_to_id]'
  2715. assert_select 'select[name=?]', 'issue[category_id]'
  2716. assert_select 'select[name=?]', 'issue[fixed_version_id]'
  2717. assert_select 'input[name=?]', 'issue[parent_issue_id]'
  2718. assert_select 'input[name=?]', 'issue[start_date]'
  2719. assert_select 'input[name=?]', 'issue[due_date]'
  2720. assert_select 'select[name=?]', 'issue[done_ratio]'
  2721. assert_select 'input[name=?][value=?]', 'issue[custom_field_values][2]', 'Default string'
  2722. assert_select 'input[name=?]', 'issue[watcher_user_ids][]'
  2723. end
  2724. # Be sure we don't display inactive IssuePriorities
  2725. assert ! IssuePriority.find(15).active?
  2726. assert_select 'select[name=?]', 'issue[priority_id]' do
  2727. assert_select 'option[value="15"]', 0
  2728. end
  2729. end
  2730. def test_get_new_should_show_project_selector_for_project_with_subprojects
  2731. @request.session[:user_id] = 2
  2732. get(
  2733. :new,
  2734. :params => {
  2735. :project_id => 1,
  2736. :tracker_id => 1
  2737. }
  2738. )
  2739. assert_response :success
  2740. assert_select 'select[name="issue[project_id]"]' do
  2741. assert_select 'option', 3
  2742. assert_select 'option[selected=selected]', :text => 'eCookbook'
  2743. assert_select 'option[value=?]', '5', :text => '  » Private child of eCookbook'
  2744. assert_select 'option[value=?]', '3', :text => '  » eCookbook Subproject 1'
  2745. # user_id 2 is not allowed to add issues on project_id 4 (it's not a member)
  2746. assert_select 'option[value=?]', '4', 0
  2747. end
  2748. end
  2749. def test_get_new_should_not_show_project_selector_for_project_without_subprojects
  2750. @request.session[:user_id] = 2
  2751. get(
  2752. :new,
  2753. :params => {
  2754. :project_id => 2,
  2755. :tracker_id => 1
  2756. }
  2757. )
  2758. assert_response :success
  2759. assert_select 'select[name="issue[project_id]"]', 0
  2760. end
  2761. def test_get_new_with_minimal_permissions
  2762. Role.find(1).update_attribute :permissions, [:add_issues]
  2763. WorkflowTransition.where(:role_id => 1).delete_all
  2764. @request.session[:user_id] = 2
  2765. get(
  2766. :new,
  2767. :params => {
  2768. :project_id => 1,
  2769. :tracker_id => 1
  2770. }
  2771. )
  2772. assert_response :success
  2773. assert_select 'form#issue-form' do
  2774. assert_select 'input[name=?]', 'issue[is_private]', 0
  2775. assert_select 'select[name=?]', 'issue[project_id]'
  2776. assert_select 'select[name=?]', 'issue[tracker_id]'
  2777. assert_select 'input[name=?]', 'issue[subject]'
  2778. assert_select 'textarea[name=?]', 'issue[description]'
  2779. assert_select 'select[name=?]', 'issue[status_id]'
  2780. assert_select 'select[name=?]', 'issue[priority_id]'
  2781. assert_select 'select[name=?]', 'issue[assigned_to_id]'
  2782. assert_select 'select[name=?]', 'issue[category_id]'
  2783. assert_select 'select[name=?]', 'issue[fixed_version_id]'
  2784. assert_select 'input[name=?]', 'issue[parent_issue_id]', 0
  2785. assert_select 'input[name=?]', 'issue[start_date]'
  2786. assert_select 'input[name=?]', 'issue[due_date]'
  2787. assert_select 'select[name=?]', 'issue[done_ratio]'
  2788. assert_select 'input[name=?][value=?]', 'issue[custom_field_values][2]', 'Default string'
  2789. assert_select 'input[name=?]', 'issue[watcher_user_ids][]', 0
  2790. end
  2791. end
  2792. def test_new_without_project_id
  2793. @request.session[:user_id] = 2
  2794. get :new
  2795. assert_response :success
  2796. assert_select 'form#issue-form[action=?]', '/issues'
  2797. assert_select 'form#issue-form' do
  2798. assert_select 'select[name=?]', 'issue[project_id]'
  2799. end
  2800. end
  2801. def test_new_with_me_assigned_to_id
  2802. @request.session[:user_id] = 2
  2803. get(
  2804. :new,
  2805. :params => {
  2806. :issue => {:assigned_to_id => 'me'}
  2807. }
  2808. )
  2809. assert_response :success
  2810. assert_select 'select[name=?]', 'issue[assigned_to_id]' do
  2811. assert_select 'option[value="2"][selected=selected]'
  2812. end
  2813. end
  2814. def test_new_should_select_default_status
  2815. @request.session[:user_id] = 2
  2816. get(:new, :params => {:project_id => 1})
  2817. assert_response :success
  2818. assert_select 'select[name=?]', 'issue[status_id]' do
  2819. assert_select 'option[value="1"][selected=selected]'
  2820. end
  2821. assert_select 'input[name=was_default_status][value="1"]'
  2822. end
  2823. def test_new_should_propose_allowed_statuses
  2824. WorkflowTransition.delete_all
  2825. WorkflowTransition.create!(:tracker_id => 1, :role_id => 1,
  2826. :old_status_id => 0, :new_status_id => 1)
  2827. WorkflowTransition.create!(:tracker_id => 1, :role_id => 1,
  2828. :old_status_id => 0, :new_status_id => 3)
  2829. @request.session[:user_id] = 2
  2830. get(:new, :params => {:project_id => 1})
  2831. assert_response :success
  2832. assert_select 'select[name=?]', 'issue[status_id]' do
  2833. assert_select 'option[value="1"]'
  2834. assert_select 'option[value="3"]'
  2835. assert_select 'option', 2
  2836. assert_select 'option[value="1"][selected=selected]'
  2837. end
  2838. end
  2839. def test_new_should_propose_allowed_statuses_without_default_status_allowed
  2840. WorkflowTransition.delete_all
  2841. WorkflowTransition.create!(:tracker_id => 1, :role_id => 1,
  2842. :old_status_id => 0, :new_status_id => 2)
  2843. assert_equal 1, Tracker.find(1).default_status_id
  2844. @request.session[:user_id] = 2
  2845. get(:new, :params => {:project_id => 1})
  2846. assert_response :success
  2847. assert_select 'select[name=?]', 'issue[status_id]' do
  2848. assert_select 'option[value="2"]'
  2849. assert_select 'option', 1
  2850. assert_select 'option[value="2"][selected=selected]'
  2851. end
  2852. end
  2853. def test_new_should_propose_allowed_trackers
  2854. role = Role.find(1)
  2855. role.set_permission_trackers 'add_issues', [1, 3]
  2856. role.save!
  2857. @request.session[:user_id] = 2
  2858. get(:new, :params => {:project_id => 1})
  2859. assert_response :success
  2860. assert_select 'select[name=?]', 'issue[tracker_id]' do
  2861. assert_select 'option', 2
  2862. assert_select 'option[value="1"]'
  2863. assert_select 'option[value="3"]'
  2864. end
  2865. end
  2866. def test_new_should_default_to_first_tracker
  2867. @request.session[:user_id] = 2
  2868. get(:new, :params => {:project_id => 1})
  2869. assert_response :success
  2870. assert_select 'select[name=?]', 'issue[tracker_id]' do
  2871. assert_select 'option', 3
  2872. assert_select 'option[value="1"][selected=selected]'
  2873. end
  2874. end
  2875. def test_new_with_parent_issue_id_should_default_to_first_tracker_without_disabled_parent_field
  2876. tracker = Tracker.find(1)
  2877. tracker.core_fields -= ['parent_issue_id']
  2878. tracker.save!
  2879. @request.session[:user_id] = 2
  2880. get(
  2881. :new,
  2882. :params => {
  2883. :project_id => 1,
  2884. :issue => {
  2885. :parent_issue_id => 1
  2886. }
  2887. }
  2888. )
  2889. assert_response :success
  2890. assert_select 'select[name=?]', 'issue[tracker_id]' do
  2891. assert_select 'option', 2
  2892. assert_select 'option[value="2"][selected=selected]'
  2893. assert_select 'option[value="1"]', 0
  2894. end
  2895. end
  2896. def test_new_without_allowed_trackers_should_respond_with_403
  2897. role = Role.find(1)
  2898. role.set_permission_trackers 'add_issues', []
  2899. role.save!
  2900. @request.session[:user_id] = 2
  2901. get(:new, :params => {:project_id => 1})
  2902. assert_response 403
  2903. end
  2904. def test_new_without_projects_should_respond_with_403
  2905. Project.delete_all
  2906. @request.session[:user_id] = 2
  2907. get :new
  2908. assert_response 403
  2909. assert_select_error /no projects/
  2910. end
  2911. def test_new_without_enabled_trackers_on_projects_should_respond_with_403
  2912. Project.all.each {|p| p.trackers.clear}
  2913. @request.session[:user_id] = 2
  2914. get :new
  2915. assert_response 403
  2916. assert_select_error /no projects/
  2917. end
  2918. def test_new_should_preselect_default_version
  2919. version = Version.generate!(:project_id => 1)
  2920. Project.find(1).update_attribute :default_version_id, version.id
  2921. @request.session[:user_id] = 2
  2922. get(:new, :params => {:project_id => 1})
  2923. assert_response :success
  2924. assert_select 'select[name=?]', 'issue[fixed_version_id]' do
  2925. assert_select 'option[value=?][selected=selected]', version.id.to_s
  2926. end
  2927. end
  2928. def test_get_new_with_list_custom_field
  2929. @request.session[:user_id] = 2
  2930. get(
  2931. :new,
  2932. :params => {
  2933. :project_id => 1,
  2934. :tracker_id => 1
  2935. }
  2936. )
  2937. assert_response :success
  2938. assert_select 'select.list_cf[name=?]', 'issue[custom_field_values][1]' do
  2939. assert_select 'option', 4
  2940. assert_select 'option[value=MySQL]', :text => 'MySQL'
  2941. end
  2942. end
  2943. def test_get_new_with_multi_custom_field
  2944. field = IssueCustomField.find(1)
  2945. field.update_attribute :multiple, true
  2946. @request.session[:user_id] = 2
  2947. get(
  2948. :new,
  2949. :params => {
  2950. :project_id => 1,
  2951. :tracker_id => 1
  2952. }
  2953. )
  2954. assert_response :success
  2955. assert_select 'select[name=?][multiple=multiple]', 'issue[custom_field_values][1][]' do
  2956. assert_select 'option', 3
  2957. assert_select 'option[value=MySQL]', :text => 'MySQL'
  2958. end
  2959. assert_select 'input[name=?][type=hidden][value=?]', 'issue[custom_field_values][1][]', ''
  2960. end
  2961. def test_get_new_with_multi_user_custom_field
  2962. field =
  2963. IssueCustomField.
  2964. create!(
  2965. :name => 'Multi user', :field_format => 'user', :multiple => true,
  2966. :tracker_ids => [1], :is_for_all => true
  2967. )
  2968. @request.session[:user_id] = 2
  2969. get(
  2970. :new,
  2971. :params => {
  2972. :project_id => 1,
  2973. :tracker_id => 1
  2974. }
  2975. )
  2976. assert_response :success
  2977. assert_select 'select[name=?][multiple=multiple]', "issue[custom_field_values][#{field.id}][]" do
  2978. assert_select 'option', Project.find(1).users.count + 1 # users + 'me'
  2979. assert_select 'option[value="2"]', :text => 'John Smith'
  2980. end
  2981. assert_select 'input[name=?][type=hidden][value=?]', "issue[custom_field_values][#{field.id}][]", ''
  2982. end
  2983. def test_get_new_with_date_custom_field
  2984. field = IssueCustomField.create!(:name => 'Date', :field_format => 'date',
  2985. :tracker_ids => [1], :is_for_all => true)
  2986. @request.session[:user_id] = 2
  2987. get(
  2988. :new,
  2989. :params => {
  2990. :project_id => 1,
  2991. :tracker_id => 1
  2992. }
  2993. )
  2994. assert_response :success
  2995. assert_select 'input[name=?]', "issue[custom_field_values][#{field.id}]"
  2996. end
  2997. def test_get_new_with_text_custom_field
  2998. field = IssueCustomField.create!(:name => 'Text', :field_format => 'text',
  2999. :tracker_ids => [1], :is_for_all => true)
  3000. @request.session[:user_id] = 2
  3001. get(
  3002. :new,
  3003. :params => {
  3004. :project_id => 1,
  3005. :tracker_id => 1
  3006. }
  3007. )
  3008. assert_response :success
  3009. assert_select 'textarea[name=?]', "issue[custom_field_values][#{field.id}]"
  3010. end
  3011. def test_get_new_without_default_start_date_is_creation_date
  3012. with_settings :default_issue_start_date_to_creation_date => 0 do
  3013. @request.session[:user_id] = 2
  3014. get(
  3015. :new,
  3016. :params => {
  3017. :project_id => 1,
  3018. :tracker_id => 1
  3019. }
  3020. )
  3021. assert_response :success
  3022. assert_select 'input[name=?]', 'issue[start_date]'
  3023. assert_select 'input[name=?][value]', 'issue[start_date]', 0
  3024. end
  3025. end
  3026. def test_get_new_with_default_start_date_is_creation_date
  3027. with_settings :default_issue_start_date_to_creation_date => 1 do
  3028. @request.session[:user_id] = 2
  3029. get(
  3030. :new,
  3031. :params => {
  3032. :project_id => 1,
  3033. :tracker_id => 1
  3034. }
  3035. )
  3036. assert_response :success
  3037. assert_select 'input[name=?][value=?]', 'issue[start_date]',
  3038. Date.today.to_s
  3039. end
  3040. end
  3041. def test_get_new_form_should_allow_attachment_upload
  3042. @request.session[:user_id] = 2
  3043. get(
  3044. :new,
  3045. :params => {
  3046. :project_id => 1,
  3047. :tracker_id => 1
  3048. }
  3049. )
  3050. assert_response :success
  3051. assert_select 'form[id=issue-form][method=post][enctype="multipart/form-data"]' do
  3052. assert_select 'input[name=?][type=file]', 'attachments[dummy][file]'
  3053. end
  3054. end
  3055. def test_get_new_should_prefill_the_form_from_params
  3056. @request.session[:user_id] = 2
  3057. get(
  3058. :new,
  3059. :params => {
  3060. :project_id => 1,
  3061. :issue => {
  3062. :tracker_id => 3,
  3063. :description => 'Prefilled',
  3064. :custom_field_values => {
  3065. '2' => 'Custom field value'
  3066. }
  3067. }
  3068. }
  3069. )
  3070. assert_select 'select[name=?]', 'issue[tracker_id]' do
  3071. assert_select 'option[value="3"][selected=selected]'
  3072. end
  3073. assert_select 'textarea[name=?]', 'issue[description]', :text => /Prefilled/
  3074. assert_select 'input[name=?][value=?]', 'issue[custom_field_values][2]', 'Custom field value'
  3075. end
  3076. def test_get_new_should_mark_required_fields
  3077. cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string',
  3078. :is_for_all => true, :tracker_ids => [1, 2])
  3079. cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string',
  3080. :is_for_all => true, :tracker_ids => [1, 2])
  3081. WorkflowPermission.delete_all
  3082. WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1,
  3083. :field_name => 'due_date', :rule => 'required')
  3084. WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1,
  3085. :field_name => cf2.id.to_s, :rule => 'required')
  3086. @request.session[:user_id] = 2
  3087. get(:new, :params => {:project_id => 1})
  3088. assert_response :success
  3089. assert_select 'label[for=issue_start_date]' do
  3090. assert_select 'span[class=required]', 0
  3091. end
  3092. assert_select 'label[for=issue_due_date]' do
  3093. assert_select 'span[class=required]'
  3094. end
  3095. assert_select 'label[for=?]', "issue_custom_field_values_#{cf1.id}" do
  3096. assert_select 'span[class=required]', 0
  3097. end
  3098. assert_select 'label[for=?]', "issue_custom_field_values_#{cf2.id}" do
  3099. assert_select 'span[class=required]'
  3100. end
  3101. end
  3102. def test_get_new_should_not_display_readonly_fields
  3103. cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string',
  3104. :is_for_all => true, :tracker_ids => [1, 2])
  3105. cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string',
  3106. :is_for_all => true, :tracker_ids => [1, 2])
  3107. WorkflowPermission.delete_all
  3108. WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1,
  3109. :role_id => 1, :field_name => 'due_date', :rule => 'readonly')
  3110. WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1,
  3111. :role_id => 1, :field_name => cf2.id.to_s, :rule => 'readonly')
  3112. @request.session[:user_id] = 2
  3113. get(:new, :params => {:project_id => 1})
  3114. assert_response :success
  3115. assert_select 'input[name=?]', 'issue[start_date]'
  3116. assert_select 'input[name=?]', 'issue[due_date]', 0
  3117. assert_select 'input[name=?]', "issue[custom_field_values][#{cf1.id}]"
  3118. assert_select 'input[name=?]', "issue[custom_field_values][#{cf2.id}]", 0
  3119. end
  3120. def test_new_with_tracker_set_as_readonly_should_accept_status
  3121. WorkflowPermission.delete_all
  3122. [1, 2].each do |status_id|
  3123. WorkflowPermission.
  3124. create!(
  3125. :tracker_id => 1,
  3126. :old_status_id => status_id,
  3127. :role_id => 1,
  3128. :field_name => 'tracker_id',
  3129. :rule => 'readonly'
  3130. )
  3131. end
  3132. @request.session[:user_id] = 2
  3133. get(
  3134. :new,
  3135. :params => {
  3136. :project_id => 1,
  3137. :issue => {
  3138. :status_id => 2
  3139. }
  3140. }
  3141. )
  3142. assert_select 'select[name=?]', 'issue[tracker_id]', 0
  3143. assert_select 'select[name=?]', 'issue[status_id]' do
  3144. assert_select 'option[value=?][selected=selected]', '2'
  3145. end
  3146. end
  3147. def test_get_new_without_tracker_id
  3148. @request.session[:user_id] = 2
  3149. get(
  3150. :new,
  3151. :params => {
  3152. :project_id => 1
  3153. }
  3154. )
  3155. assert_response :success
  3156. assert_select 'select[name=?]', 'issue[tracker_id]' do
  3157. assert_select 'option[value=?][selected=selected]', Project.find(1).trackers.first.id.to_s
  3158. end
  3159. end
  3160. def test_get_new_with_no_default_status_should_display_an_error
  3161. @request.session[:user_id] = 2
  3162. IssueStatus.delete_all
  3163. get(
  3164. :new,
  3165. :params => {
  3166. :project_id => 1
  3167. }
  3168. )
  3169. assert_response 500
  3170. assert_select_error /No default issue/
  3171. end
  3172. def test_get_new_with_no_tracker_should_display_an_error
  3173. @request.session[:user_id] = 2
  3174. Tracker.delete_all
  3175. get(
  3176. :new,
  3177. :params => {
  3178. :project_id => 1
  3179. }
  3180. )
  3181. assert_response 500
  3182. assert_select_error /No tracker/
  3183. end
  3184. def test_new_with_invalid_project_id
  3185. @request.session[:user_id] = 1
  3186. get(
  3187. :new,
  3188. :params => {
  3189. :project_id => 'invalid'
  3190. }
  3191. )
  3192. assert_response 404
  3193. end
  3194. def test_new_with_parent_id_should_only_propose_valid_trackers
  3195. @request.session[:user_id] = 2
  3196. t = Tracker.find(3)
  3197. assert !t.disabled_core_fields.include?('parent_issue_id')
  3198. get(
  3199. :new,
  3200. :params => {
  3201. :project_id => 1, :issue => {:parent_issue_id => 1}
  3202. }
  3203. )
  3204. assert_response :success
  3205. assert_select 'option', text: /#{t.name}/, count: 1
  3206. t.core_fields = Tracker::CORE_FIELDS - ['parent_issue_id']
  3207. t.save!
  3208. assert t.disabled_core_fields.include?('parent_issue_id')
  3209. get(
  3210. :new,
  3211. :params => {
  3212. :project_id => 1, :issue => {:parent_issue_id => 1}
  3213. }
  3214. )
  3215. assert_response :success
  3216. assert_select 'option', text: /#{t.name}/, count: 0
  3217. end
  3218. def test_get_new_should_show_trackers_description
  3219. @request.session[:user_id] = 2
  3220. get :new, :params => {
  3221. :project_id => 1,
  3222. :issue => {
  3223. :tracker_id => 1
  3224. }
  3225. }
  3226. assert_response :success
  3227. assert_select 'form#issue-form' do
  3228. assert_select 'a[title=?]', 'View all trackers description', :text => 'View all trackers description'
  3229. assert_select 'select[name=?][title=?]', 'issue[tracker_id]', 'Description for Bug tracker'
  3230. end
  3231. assert_select 'div#trackers_description' do
  3232. assert_select 'h3', 1, :text => 'Trackers description'
  3233. # only Bug and Feature have descriptions
  3234. assert_select 'dt', 2, :text => 'Bug'
  3235. assert_select 'dd', 2, :text => 'Description for Bug tracker'
  3236. end
  3237. end
  3238. def test_get_new_should_not_show_trackers_description_for_trackers_without_description
  3239. Tracker.update_all(:description => '')
  3240. @request.session[:user_id] = 2
  3241. get :new, :params => {
  3242. :project_id => 1,
  3243. :issue => {
  3244. :tracker_id => 1
  3245. }
  3246. }
  3247. assert_response :success
  3248. assert_select 'form#issue-form' do
  3249. assert_select 'a[title=?]', 'View all trackers description', 0
  3250. assert_select 'select[name=?][title=?]', 'issue[tracker_id]', ''
  3251. end
  3252. assert_select 'div#trackers_description', 0
  3253. end
  3254. def test_update_form_for_new_issue
  3255. @request.session[:user_id] = 2
  3256. post(
  3257. :new,
  3258. :params => {
  3259. :project_id => 1,
  3260. :issue => {
  3261. :tracker_id => 2,
  3262. :subject => 'This is the test_new issue',
  3263. :description => 'This is the description',
  3264. :priority_id => 5
  3265. }
  3266. },
  3267. :xhr => true
  3268. )
  3269. assert_response :success
  3270. assert_equal 'text/javascript', response.media_type
  3271. assert_include 'This is the test_new issue', response.body
  3272. end
  3273. def test_update_form_for_new_issue_should_propose_transitions_based_on_initial_status
  3274. @request.session[:user_id] = 2
  3275. WorkflowTransition.delete_all
  3276. WorkflowTransition.create!(:role_id => 1, :tracker_id => 1,
  3277. :old_status_id => 0, :new_status_id => 2)
  3278. WorkflowTransition.create!(:role_id => 1, :tracker_id => 1,
  3279. :old_status_id => 0, :new_status_id => 5)
  3280. WorkflowTransition.create!(:role_id => 1, :tracker_id => 1,
  3281. :old_status_id => 5, :new_status_id => 4)
  3282. post(
  3283. :new,
  3284. :params => {
  3285. :project_id => 1,
  3286. :issue => {
  3287. :tracker_id => 1,
  3288. :status_id => 5,
  3289. :subject => 'This is an issue'
  3290. }
  3291. }
  3292. )
  3293. assert_select 'select[name=?]', 'issue[status_id]' do
  3294. assert_select 'option[value=?][selected=selected]', '5'
  3295. assert_select 'option[value=?]', '2'
  3296. assert_select 'option', :count => 2
  3297. end
  3298. end
  3299. def test_update_form_with_default_status_should_ignore_submitted_status_id_if_equals
  3300. @request.session[:user_id] = 2
  3301. tracker = Tracker.find(2)
  3302. tracker.update! :default_status_id => 2
  3303. tracker.generate_transitions! 2 => 1, :clear => true
  3304. post(
  3305. :new,
  3306. :params => {
  3307. :project_id => 1,
  3308. :issue => {
  3309. :tracker_id => 2,
  3310. :status_id => 1
  3311. },
  3312. :was_default_status => 1
  3313. }
  3314. )
  3315. assert_response :success
  3316. assert_select 'select[name=?]', 'issue[status_id]' do
  3317. assert_select 'option[value=?][selected=selected]', '2'
  3318. end
  3319. end
  3320. def test_update_form_for_new_issue_should_ignore_version_when_changing_project
  3321. version = Version.generate!(:project_id => 1)
  3322. Project.find(1).update_attribute :default_version_id, version.id
  3323. @request.session[:user_id] = 2
  3324. post(
  3325. :new,
  3326. :params => {
  3327. :issue => {
  3328. :project_id => 1,
  3329. :fixed_version_id => ''
  3330. },
  3331. :form_update_triggered_by => 'issue_project_id'
  3332. }
  3333. )
  3334. assert_response :success
  3335. assert_select 'select[name=?]', 'issue[project_id]' do
  3336. assert_select 'option[value=?][selected=selected]', '1'
  3337. end
  3338. assert_select 'select[name=?]', 'issue[fixed_version_id]' do
  3339. assert_select 'option[value=?][selected=selected]', version.id.to_s
  3340. end
  3341. end
  3342. def test_post_create
  3343. @request.session[:user_id] = 2
  3344. assert_difference 'Issue.count' do
  3345. assert_no_difference 'Journal.count' do
  3346. post(
  3347. :create,
  3348. :params => {
  3349. :project_id => 1,
  3350. :issue => {
  3351. :tracker_id => 3,
  3352. :status_id => 2,
  3353. :subject => 'This is the test_new issue',
  3354. :description => 'This is the description',
  3355. :priority_id => 5,
  3356. :start_date => '2010-11-07',
  3357. :estimated_hours => '',
  3358. :custom_field_values => {
  3359. '2' => 'Value for field 2'
  3360. }
  3361. }
  3362. }
  3363. )
  3364. end
  3365. end
  3366. assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
  3367. issue = Issue.find_by_subject('This is the test_new issue')
  3368. assert_not_nil issue
  3369. assert_equal 2, issue.author_id
  3370. assert_equal 3, issue.tracker_id
  3371. assert_equal 2, issue.status_id
  3372. assert_equal Date.parse('2010-11-07'), issue.start_date
  3373. assert_nil issue.estimated_hours
  3374. v = issue.custom_values.where(:custom_field_id => 2).first
  3375. assert_not_nil v
  3376. assert_equal 'Value for field 2', v.value
  3377. end
  3378. def test_post_new_with_group_assignment
  3379. group = Group.find(11)
  3380. project = Project.find(1)
  3381. project.members << Member.new(:principal => group, :roles => [Role.givable.first])
  3382. with_settings :issue_group_assignment => '1' do
  3383. @request.session[:user_id] = 2
  3384. assert_difference 'Issue.count' do
  3385. post(
  3386. :create,
  3387. :params => {
  3388. :project_id => project.id,
  3389. :issue => {
  3390. :tracker_id => 3,
  3391. :status_id => 1,
  3392. :subject => 'This is the test_new_with_group_assignment issue',
  3393. :assigned_to_id => group.id
  3394. }
  3395. }
  3396. )
  3397. end
  3398. end
  3399. assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
  3400. issue = Issue.find_by_subject('This is the test_new_with_group_assignment issue')
  3401. assert_not_nil issue
  3402. assert_equal group, issue.assigned_to
  3403. end
  3404. def test_post_create_without_start_date_and_default_start_date_is_not_creation_date
  3405. with_settings :default_issue_start_date_to_creation_date => 0 do
  3406. @request.session[:user_id] = 2
  3407. assert_difference 'Issue.count' do
  3408. post(
  3409. :create,
  3410. :params => {
  3411. :project_id => 1,
  3412. :issue => {
  3413. :tracker_id => 3,
  3414. :status_id => 2,
  3415. :subject => 'This is the test_new issue',
  3416. :description => 'This is the description',
  3417. :priority_id => 5,
  3418. :estimated_hours => '',
  3419. :custom_field_values => {
  3420. '2' => 'Value for field 2'
  3421. }
  3422. }
  3423. }
  3424. )
  3425. end
  3426. assert_redirected_to :controller => 'issues', :action => 'show',
  3427. :id => Issue.last.id
  3428. issue = Issue.find_by_subject('This is the test_new issue')
  3429. assert_not_nil issue
  3430. assert_nil issue.start_date
  3431. end
  3432. end
  3433. def test_post_create_without_start_date_and_default_start_date_is_creation_date
  3434. with_settings :default_issue_start_date_to_creation_date => 1 do
  3435. @request.session[:user_id] = 2
  3436. assert_difference 'Issue.count' do
  3437. post(
  3438. :create,
  3439. :params => {
  3440. :project_id => 1,
  3441. :issue => {
  3442. :tracker_id => 3,
  3443. :status_id => 2,
  3444. :subject => 'This is the test_new issue',
  3445. :description => 'This is the description',
  3446. :priority_id => 5,
  3447. :estimated_hours => '',
  3448. :custom_field_values => {
  3449. '2' => 'Value for field 2'
  3450. }
  3451. }
  3452. }
  3453. )
  3454. end
  3455. assert_redirected_to :controller => 'issues', :action => 'show',
  3456. :id => Issue.last.id
  3457. issue = Issue.find_by_subject('This is the test_new issue')
  3458. assert_not_nil issue
  3459. assert_equal Date.today, issue.start_date
  3460. end
  3461. end
  3462. def test_post_create_and_continue
  3463. @request.session[:user_id] = 2
  3464. assert_difference 'Issue.count' do
  3465. post(
  3466. :create,
  3467. :params => {
  3468. :project_id => 1,
  3469. :issue => {
  3470. :tracker_id => 3,
  3471. :subject => 'This is first issue',
  3472. :priority_id => 5
  3473. },
  3474. :continue => ''
  3475. }
  3476. )
  3477. end
  3478. issue = Issue.order('id DESC').first
  3479. assert_redirected_to :controller => 'issues',
  3480. :action => 'new', :project_id => 'ecookbook',
  3481. :issue => {:tracker_id => 3}
  3482. assert_not_nil flash[:notice], "flash was not set"
  3483. assert_select_in flash[:notice],
  3484. 'a[href=?][title=?]', "/issues/#{issue.id}",
  3485. "This is first issue", :text => "##{issue.id}"
  3486. end
  3487. def test_post_create_without_custom_fields_param
  3488. @request.session[:user_id] = 2
  3489. assert_difference 'Issue.count' do
  3490. post(
  3491. :create,
  3492. :params => {
  3493. :project_id => 1,
  3494. :issue => {
  3495. :tracker_id => 1,
  3496. :subject => 'This is the test_new issue',
  3497. :description => 'This is the description',
  3498. :priority_id => 5
  3499. }
  3500. }
  3501. )
  3502. end
  3503. assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
  3504. end
  3505. def test_post_create_with_multi_custom_field
  3506. field = IssueCustomField.find_by_name('Database')
  3507. field.update_attribute(:multiple, true)
  3508. @request.session[:user_id] = 2
  3509. assert_difference 'Issue.count' do
  3510. post(
  3511. :create,
  3512. :params => {
  3513. :project_id => 1,
  3514. :issue => {
  3515. :tracker_id => 1,
  3516. :subject => 'This is the test_new issue',
  3517. :description => 'This is the description',
  3518. :priority_id => 5,
  3519. :custom_field_values => {
  3520. '1' => ['', 'MySQL', 'Oracle']
  3521. }
  3522. }
  3523. }
  3524. )
  3525. end
  3526. assert_response 302
  3527. issue = Issue.order('id DESC').first
  3528. assert_equal ['MySQL', 'Oracle'], issue.custom_field_value(1).sort
  3529. end
  3530. def test_post_create_with_empty_multi_custom_field
  3531. field = IssueCustomField.find_by_name('Database')
  3532. field.update_attribute(:multiple, true)
  3533. @request.session[:user_id] = 2
  3534. assert_difference 'Issue.count' do
  3535. post(
  3536. :create,
  3537. :params => {
  3538. :project_id => 1,
  3539. :issue => {
  3540. :tracker_id => 1,
  3541. :subject => 'This is the test_new issue',
  3542. :description => 'This is the description',
  3543. :priority_id => 5,
  3544. :custom_field_values => {
  3545. '1' => ['']
  3546. }
  3547. }
  3548. }
  3549. )
  3550. end
  3551. assert_response 302
  3552. issue = Issue.order('id DESC').first
  3553. assert_equal [''], issue.custom_field_value(1).sort
  3554. end
  3555. def test_post_create_with_multi_user_custom_field
  3556. field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true,
  3557. :tracker_ids => [1], :is_for_all => true)
  3558. @request.session[:user_id] = 2
  3559. assert_difference 'Issue.count' do
  3560. post(
  3561. :create,
  3562. :params => {
  3563. :project_id => 1,
  3564. :issue => {
  3565. :tracker_id => 1,
  3566. :subject => 'This is the test_new issue',
  3567. :description => 'This is the description',
  3568. :priority_id => 5,
  3569. :custom_field_values => {
  3570. field.id.to_s => ['', '2', '3']
  3571. }
  3572. }
  3573. }
  3574. )
  3575. end
  3576. assert_response 302
  3577. issue = Issue.order('id DESC').first
  3578. assert_equal ['2', '3'], issue.custom_field_value(field).sort
  3579. end
  3580. def test_post_create_with_required_custom_field_and_without_custom_fields_param
  3581. field = IssueCustomField.find_by_name('Database')
  3582. field.update_attribute(:is_required, true)
  3583. @request.session[:user_id] = 2
  3584. assert_no_difference 'Issue.count' do
  3585. post(
  3586. :create,
  3587. :params => {
  3588. :project_id => 1,
  3589. :issue => {
  3590. :tracker_id => 1,
  3591. :subject => 'This is the test_new issue',
  3592. :description => 'This is the description',
  3593. :priority_id => 5
  3594. }
  3595. }
  3596. )
  3597. end
  3598. assert_response :success
  3599. assert_select_error /Database cannot be blank/
  3600. end
  3601. def test_create_should_validate_required_fields
  3602. cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
  3603. cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
  3604. WorkflowPermission.delete_all
  3605. WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => 'due_date', :rule => 'required')
  3606. WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => cf2.id.to_s, :rule => 'required')
  3607. @request.session[:user_id] = 2
  3608. assert_no_difference 'Issue.count' do
  3609. post(
  3610. :create,
  3611. :params => {
  3612. :project_id => 1,
  3613. :issue => {
  3614. :tracker_id => 2,
  3615. :status_id => 1,
  3616. :subject => 'Test',
  3617. :start_date => '',
  3618. :due_date => '',
  3619. :custom_field_values => {
  3620. cf1.id.to_s => '', cf2.id.to_s => ''
  3621. }
  3622. }
  3623. }
  3624. )
  3625. assert_response :success
  3626. end
  3627. assert_select_error /Due date cannot be blank/i
  3628. assert_select_error /Bar cannot be blank/i
  3629. end
  3630. def test_create_should_validate_required_list_fields
  3631. cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'list', :is_for_all => true, :tracker_ids => [1, 2], :multiple => false, :possible_values => ['a', 'b'])
  3632. cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'list', :is_for_all => true, :tracker_ids => [1, 2], :multiple => true, :possible_values => ['a', 'b'])
  3633. WorkflowPermission.delete_all
  3634. WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => cf1.id.to_s, :rule => 'required')
  3635. WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => cf2.id.to_s, :rule => 'required')
  3636. @request.session[:user_id] = 2
  3637. assert_no_difference 'Issue.count' do
  3638. post(
  3639. :create,
  3640. :params => {
  3641. :project_id => 1,
  3642. :issue => {
  3643. :tracker_id => 2,
  3644. :status_id => 1,
  3645. :subject => 'Test',
  3646. :start_date => '',
  3647. :due_date => '',
  3648. :custom_field_values => {
  3649. cf1.id.to_s => '', cf2.id.to_s => ['']
  3650. }
  3651. }
  3652. }
  3653. )
  3654. assert_response :success
  3655. end
  3656. assert_select_error /Foo cannot be blank/i
  3657. assert_select_error /Bar cannot be blank/i
  3658. end
  3659. def test_create_should_ignore_readonly_fields
  3660. cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
  3661. cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
  3662. WorkflowPermission.delete_all
  3663. WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => 'due_date', :rule => 'readonly')
  3664. WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => cf2.id.to_s, :rule => 'readonly')
  3665. @request.session[:user_id] = 2
  3666. assert_difference 'Issue.count' do
  3667. post(
  3668. :create,
  3669. :params => {
  3670. :project_id => 1,
  3671. :issue => {
  3672. :tracker_id => 2,
  3673. :status_id => 1,
  3674. :subject => 'Test',
  3675. :start_date => '2012-07-14',
  3676. :due_date => '2012-07-16',
  3677. :custom_field_values => {
  3678. cf1.id.to_s => 'value1', cf2.id.to_s => 'value2'
  3679. }
  3680. }
  3681. }
  3682. )
  3683. assert_response 302
  3684. end
  3685. issue = Issue.order('id DESC').first
  3686. assert_equal Date.parse('2012-07-14'), issue.start_date
  3687. assert_nil issue.due_date
  3688. assert_equal 'value1', issue.custom_field_value(cf1)
  3689. assert_nil issue.custom_field_value(cf2)
  3690. end
  3691. def test_create_should_ignore_unallowed_trackers
  3692. role = Role.find(1)
  3693. role.set_permission_trackers :add_issues, [3]
  3694. role.save!
  3695. @request.session[:user_id] = 2
  3696. issue = new_record(Issue) do
  3697. post(
  3698. :create,
  3699. :params => {
  3700. :project_id => 1,
  3701. :issue => {
  3702. :tracker_id => 1,
  3703. :status_id => 1,
  3704. :subject => 'Test'
  3705. }
  3706. }
  3707. )
  3708. assert_response 302
  3709. end
  3710. assert_equal 3, issue.tracker_id
  3711. end
  3712. def test_post_create_with_watchers
  3713. @request.session[:user_id] = 2
  3714. ActionMailer::Base.deliveries.clear
  3715. with_settings :notified_events => %w(issue_added) do
  3716. assert_difference 'Watcher.count', 3 do
  3717. post(
  3718. :create,
  3719. :params => {
  3720. :project_id => 1,
  3721. :issue => {
  3722. :tracker_id => 1,
  3723. :subject => 'This is a new issue with watchers',
  3724. :description => 'This is the description',
  3725. :priority_id => 5,
  3726. :watcher_user_ids => ['2', '3', '10']
  3727. }
  3728. }
  3729. )
  3730. end
  3731. end
  3732. issue = Issue.find_by_subject('This is a new issue with watchers')
  3733. assert_not_nil issue
  3734. assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
  3735. # Watchers added
  3736. assert_equal [2, 3, 10], issue.watcher_user_ids.sort
  3737. assert issue.watched_by?(User.find(3))
  3738. assert issue.watched_by?(Group.find(10))
  3739. # Watchers notified
  3740. assert_equal 3, ActionMailer::Base.deliveries.size
  3741. mail = ActionMailer::Base.deliveries[1]
  3742. assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail)
  3743. mail = ActionMailer::Base.deliveries[2]
  3744. assert [mail.bcc, mail.cc].flatten.include?(User.find(8).mail)
  3745. end
  3746. def test_post_create_subissue
  3747. @request.session[:user_id] = 2
  3748. assert_difference 'Issue.count' do
  3749. post(
  3750. :create,
  3751. :params => {
  3752. :project_id => 1,
  3753. :issue => {
  3754. :tracker_id => 1,
  3755. :subject => 'This is a child issue',
  3756. :parent_issue_id => '2'
  3757. }
  3758. }
  3759. )
  3760. assert_response 302
  3761. end
  3762. issue = Issue.order('id DESC').first
  3763. assert_equal Issue.find(2), issue.parent
  3764. end
  3765. def test_post_create_subissue_with_sharp_parent_id
  3766. @request.session[:user_id] = 2
  3767. assert_difference 'Issue.count' do
  3768. post(
  3769. :create,
  3770. :params => {
  3771. :project_id => 1,
  3772. :issue => {
  3773. :tracker_id => 1,
  3774. :subject => 'This is a child issue',
  3775. :parent_issue_id => '#2'
  3776. }
  3777. }
  3778. )
  3779. assert_response 302
  3780. end
  3781. issue = Issue.order('id DESC').first
  3782. assert_equal Issue.find(2), issue.parent
  3783. end
  3784. def test_post_create_subissue_with_non_visible_parent_id_should_not_validate
  3785. @request.session[:user_id] = 2
  3786. assert_no_difference 'Issue.count' do
  3787. post(
  3788. :create,
  3789. :params => {
  3790. :project_id => 1,
  3791. :issue => {
  3792. :tracker_id => 1,
  3793. :subject => 'This is a child issue',
  3794. :parent_issue_id => '4'
  3795. }
  3796. }
  3797. )
  3798. assert_response :success
  3799. assert_select 'input[name=?][value=?]', 'issue[parent_issue_id]', '4'
  3800. assert_select_error /Parent task is invalid/i
  3801. end
  3802. end
  3803. def test_post_create_subissue_with_non_numeric_parent_id_should_not_validate
  3804. @request.session[:user_id] = 2
  3805. assert_no_difference 'Issue.count' do
  3806. post(
  3807. :create,
  3808. :params => {
  3809. :project_id => 1,
  3810. :issue => {
  3811. :tracker_id => 1,
  3812. :subject => 'This is a child issue',
  3813. :parent_issue_id => '01ABC'
  3814. }
  3815. }
  3816. )
  3817. assert_response :success
  3818. assert_select 'input[name=?][value=?]', 'issue[parent_issue_id]', '01ABC'
  3819. assert_select_error /Parent task is invalid/i
  3820. end
  3821. end
  3822. def test_post_create_private
  3823. @request.session[:user_id] = 2
  3824. assert_difference 'Issue.count' do
  3825. post(
  3826. :create,
  3827. :params => {
  3828. :project_id => 1,
  3829. :issue => {
  3830. :tracker_id => 1,
  3831. :subject => 'This is a private issue',
  3832. :is_private => '1'
  3833. }
  3834. }
  3835. )
  3836. end
  3837. issue = Issue.order('id DESC').first
  3838. assert issue.is_private?
  3839. end
  3840. def test_post_create_private_with_set_own_issues_private_permission
  3841. role = Role.find(1)
  3842. role.remove_permission! :set_issues_private
  3843. role.add_permission! :set_own_issues_private
  3844. @request.session[:user_id] = 2
  3845. assert_difference 'Issue.count' do
  3846. post(
  3847. :create,
  3848. :params => {
  3849. :project_id => 1,
  3850. :issue => {
  3851. :tracker_id => 1,
  3852. :subject => 'This is a private issue',
  3853. :is_private => '1'
  3854. }
  3855. }
  3856. )
  3857. end
  3858. issue = Issue.order('id DESC').first
  3859. assert issue.is_private?
  3860. end
  3861. def test_create_without_project_id
  3862. @request.session[:user_id] = 2
  3863. assert_difference 'Issue.count' do
  3864. post(
  3865. :create,
  3866. :params => {
  3867. :issue => {
  3868. :project_id => 3,
  3869. :tracker_id => 2,
  3870. :subject => 'Foo'
  3871. }
  3872. }
  3873. )
  3874. assert_response 302
  3875. end
  3876. issue = Issue.order('id DESC').first
  3877. assert_equal 3, issue.project_id
  3878. assert_equal 2, issue.tracker_id
  3879. end
  3880. def test_create_without_project_id_and_continue_should_redirect_without_project_id
  3881. @request.session[:user_id] = 2
  3882. assert_difference 'Issue.count' do
  3883. post(
  3884. :create,
  3885. :params => {
  3886. :issue => {
  3887. :project_id => 3,
  3888. :tracker_id => 2,
  3889. :subject => 'Foo'
  3890. },
  3891. :continue => '1'
  3892. }
  3893. )
  3894. assert_redirected_to '/issues/new?issue%5Bproject_id%5D=3&issue%5Btracker_id%5D=2'
  3895. end
  3896. end
  3897. def test_create_without_project_id_should_be_denied_without_permission
  3898. Role.non_member.remove_permission! :add_issues
  3899. Role.anonymous.remove_permission! :add_issues
  3900. @request.session[:user_id] = 2
  3901. assert_no_difference 'Issue.count' do
  3902. post(
  3903. :create,
  3904. :params => {
  3905. :issue => {
  3906. :project_id => 3,
  3907. :tracker_id => 2,
  3908. :subject => 'Foo'
  3909. }
  3910. }
  3911. )
  3912. assert_response 422
  3913. end
  3914. end
  3915. def test_create_without_project_id_with_failure_should_not_set_project
  3916. @request.session[:user_id] = 2
  3917. post(
  3918. :create,
  3919. :params => {
  3920. :issue => {
  3921. :project_id => 3,
  3922. :tracker_id => 2,
  3923. :subject => ''
  3924. }
  3925. }
  3926. )
  3927. assert_response :success
  3928. # no project menu
  3929. assert_select '#main-menu a.overview', 0
  3930. end
  3931. def test_post_create_should_send_a_notification
  3932. ActionMailer::Base.deliveries.clear
  3933. @request.session[:user_id] = 2
  3934. with_settings :notified_events => %w(issue_added) do
  3935. assert_difference 'Issue.count' do
  3936. post(
  3937. :create,
  3938. :params => {
  3939. :project_id => 1,
  3940. :issue => {
  3941. :tracker_id => 3,
  3942. :subject => 'This is the test_new issue',
  3943. :description => 'This is the description',
  3944. :priority_id => 5,
  3945. :estimated_hours => '',
  3946. :custom_field_values => {
  3947. '2' => 'Value for field 2'
  3948. }
  3949. }
  3950. }
  3951. )
  3952. end
  3953. assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
  3954. assert_equal 2, ActionMailer::Base.deliveries.size
  3955. end
  3956. end
  3957. def test_post_create_should_preserve_fields_values_on_validation_failure
  3958. @request.session[:user_id] = 2
  3959. post(
  3960. :create,
  3961. :params => {
  3962. :project_id => 1,
  3963. :issue => {
  3964. :tracker_id => 1,
  3965. :subject => '', # empty subject
  3966. :description => 'This is a description',
  3967. :priority_id => 6,
  3968. :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}
  3969. }
  3970. }
  3971. )
  3972. assert_response :success
  3973. assert_select 'textarea[name=?]', 'issue[description]', :text => 'This is a description'
  3974. assert_select 'select[name=?]', 'issue[priority_id]' do
  3975. assert_select 'option[value="6"][selected=selected]', :text => 'High'
  3976. end
  3977. # Custom fields
  3978. assert_select 'select[name=?]', 'issue[custom_field_values][1]' do
  3979. assert_select 'option[value=Oracle][selected=selected]', :text => 'Oracle'
  3980. end
  3981. assert_select 'input[name=?][value=?]', 'issue[custom_field_values][2]', 'Value for field 2'
  3982. end
  3983. def test_post_create_with_failure_should_preserve_watchers
  3984. assert !User.find(8).member_of?(Project.find(1))
  3985. @request.session[:user_id] = 2
  3986. post(
  3987. :create,
  3988. :params => {
  3989. :project_id => 1,
  3990. :issue => {
  3991. :tracker_id => 1,
  3992. :watcher_user_ids => ['3', '8']
  3993. }
  3994. }
  3995. )
  3996. assert_response :success
  3997. assert_select 'input[name=?][value="2"]:not(checked)', 'issue[watcher_user_ids][]'
  3998. assert_select 'input[name=?][value="3"][checked=checked]', 'issue[watcher_user_ids][]'
  3999. assert_select 'input[name=?][value="8"][checked=checked]', 'issue[watcher_user_ids][]'
  4000. end
  4001. def test_post_create_should_ignore_non_safe_attributes
  4002. @request.session[:user_id] = 2
  4003. assert_nothing_raised do
  4004. post(
  4005. :create,
  4006. :params => {
  4007. :project_id => 1,
  4008. :issue => {
  4009. :tracker => "A param can not be a Tracker"
  4010. }
  4011. }
  4012. )
  4013. end
  4014. end
  4015. def test_post_create_with_attachment
  4016. set_tmp_attachments_directory
  4017. @request.session[:user_id] = 2
  4018. assert_difference 'Issue.count' do
  4019. assert_difference 'Attachment.count' do
  4020. assert_no_difference 'Journal.count' do
  4021. post(
  4022. :create,
  4023. :params => {
  4024. :project_id => 1,
  4025. :issue => {
  4026. :tracker_id => '1',
  4027. :subject => 'With attachment'
  4028. },
  4029. :attachments => {
  4030. '1' => {
  4031. 'file' => uploaded_test_file('testfile.txt', 'text/plain'),
  4032. 'description' => 'test file'
  4033. }
  4034. }
  4035. }
  4036. )
  4037. end
  4038. end
  4039. end
  4040. issue = Issue.order('id DESC').first
  4041. attachment = Attachment.order('id DESC').first
  4042. assert_equal issue, attachment.container
  4043. assert_equal 2, attachment.author_id
  4044. assert_equal 'testfile.txt', attachment.filename
  4045. assert_equal 'text/plain', attachment.content_type
  4046. assert_equal 'test file', attachment.description
  4047. assert_equal 59, attachment.filesize
  4048. assert File.exists?(attachment.diskfile)
  4049. assert_equal 59, File.size(attachment.diskfile)
  4050. end
  4051. def test_post_create_with_attachment_should_notify_with_attachments
  4052. ActionMailer::Base.deliveries.clear
  4053. set_tmp_attachments_directory
  4054. @request.session[:user_id] = 2
  4055. with_settings :notified_events => %w(issue_added) do
  4056. assert_difference 'Issue.count' do
  4057. post(
  4058. :create,
  4059. :params => {
  4060. :project_id => 1,
  4061. :issue => {
  4062. :tracker_id => '1',
  4063. :subject => 'With attachment'
  4064. },
  4065. :attachments => {
  4066. '1' => {
  4067. 'file' => uploaded_test_file('testfile.txt', 'text/plain'),
  4068. 'description' => 'test file'
  4069. }
  4070. }
  4071. }
  4072. )
  4073. end
  4074. end
  4075. assert_not_nil ActionMailer::Base.deliveries.last
  4076. assert_select_email do
  4077. assert_select 'a[href^=?]', 'http://localhost:3000/attachments/download', 'testfile.txt'
  4078. end
  4079. end
  4080. def test_post_create_with_failure_should_save_attachments
  4081. set_tmp_attachments_directory
  4082. @request.session[:user_id] = 2
  4083. assert_no_difference 'Issue.count' do
  4084. assert_difference 'Attachment.count' do
  4085. post(
  4086. :create,
  4087. :params => {
  4088. :project_id => 1,
  4089. :issue => {
  4090. :tracker_id => '1',
  4091. :subject => ''
  4092. },
  4093. :attachments => {
  4094. '1' => {
  4095. 'file' => uploaded_test_file('testfile.txt', 'text/plain'),
  4096. 'description' => 'test file'
  4097. }
  4098. }
  4099. }
  4100. )
  4101. assert_response :success
  4102. end
  4103. end
  4104. attachment = Attachment.order('id DESC').first
  4105. assert_equal 'testfile.txt', attachment.filename
  4106. assert File.exists?(attachment.diskfile)
  4107. assert_nil attachment.container
  4108. assert_select 'input[name=?][value=?]', 'attachments[p0][token]', attachment.token
  4109. assert_select 'input[name=?][value=?]', 'attachments[p0][filename]', 'testfile.txt'
  4110. end
  4111. def test_post_create_with_failure_should_keep_saved_attachments
  4112. set_tmp_attachments_directory
  4113. attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
  4114. @request.session[:user_id] = 2
  4115. assert_no_difference 'Issue.count' do
  4116. assert_no_difference 'Attachment.count' do
  4117. post(
  4118. :create,
  4119. :params => {
  4120. :project_id => 1,
  4121. :issue => {
  4122. :tracker_id => '1',
  4123. :subject => ''
  4124. },
  4125. :attachments => {
  4126. 'p0' => {
  4127. 'token' => attachment.token
  4128. }
  4129. }
  4130. }
  4131. )
  4132. assert_response :success
  4133. end
  4134. end
  4135. assert_select 'input[name=?][value=?]', 'attachments[p0][token]', attachment.token
  4136. assert_select 'input[name=?][value=?]', 'attachments[p0][filename]', 'testfile.txt'
  4137. end
  4138. def test_post_create_should_attach_saved_attachments
  4139. set_tmp_attachments_directory
  4140. attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
  4141. @request.session[:user_id] = 2
  4142. assert_difference 'Issue.count' do
  4143. assert_no_difference 'Attachment.count' do
  4144. post(
  4145. :create,
  4146. :params => {
  4147. :project_id => 1,
  4148. :issue => {
  4149. :tracker_id => '1',
  4150. :subject => 'Saved attachments'
  4151. },
  4152. :attachments => {
  4153. 'p0' => {
  4154. 'token' => attachment.token
  4155. }
  4156. }
  4157. }
  4158. )
  4159. assert_response 302
  4160. end
  4161. end
  4162. issue = Issue.order('id DESC').first
  4163. assert_equal 1, issue.attachments.count
  4164. attachment.reload
  4165. assert_equal issue, attachment.container
  4166. end
  4167. def setup_without_workflow_privilege
  4168. WorkflowTransition.where(["role_id = ?", Role.anonymous.id]).delete_all
  4169. Role.anonymous.add_permission! :add_issues, :add_issue_notes
  4170. end
  4171. private :setup_without_workflow_privilege
  4172. test "without workflow privilege #new should propose default status only" do
  4173. setup_without_workflow_privilege
  4174. get(:new, :params => {:project_id => 1})
  4175. assert_response :success
  4176. assert_select 'select[name=?]', 'issue[status_id]' do
  4177. assert_select 'option', 1
  4178. assert_select 'option[value=?][selected=selected]', '1'
  4179. end
  4180. end
  4181. test "without workflow privilege #create should accept default status" do
  4182. setup_without_workflow_privilege
  4183. assert_difference 'Issue.count' do
  4184. post(
  4185. :create,
  4186. :params => {
  4187. :project_id => 1,
  4188. :issue => {
  4189. :tracker_id => 1,
  4190. :subject => 'This is an issue',
  4191. :status_id => 1
  4192. }
  4193. }
  4194. )
  4195. end
  4196. issue = Issue.order('id').last
  4197. assert_not_nil issue.default_status
  4198. assert_equal issue.default_status, issue.status
  4199. end
  4200. test "without workflow privilege #create should ignore unauthorized status" do
  4201. setup_without_workflow_privilege
  4202. assert_difference 'Issue.count' do
  4203. post(
  4204. :create,
  4205. :params => {
  4206. :project_id => 1,
  4207. :issue => {
  4208. :tracker_id => 1,
  4209. :subject => 'This is an issue',
  4210. :status_id => 3
  4211. }
  4212. }
  4213. )
  4214. end
  4215. issue = Issue.order('id').last
  4216. assert_not_nil issue.default_status
  4217. assert_equal issue.default_status, issue.status
  4218. end
  4219. test "without workflow privilege #update should ignore status change" do
  4220. setup_without_workflow_privilege
  4221. assert_difference 'Journal.count' do
  4222. put(
  4223. :update,
  4224. :params => {
  4225. :id => 1,
  4226. :issue => {
  4227. :status_id => 3,
  4228. :notes => 'just trying'
  4229. }
  4230. }
  4231. )
  4232. end
  4233. assert_equal 1, Issue.find(1).status_id
  4234. end
  4235. test "without workflow privilege #update ignore attributes changes" do
  4236. setup_without_workflow_privilege
  4237. assert_difference 'Journal.count' do
  4238. put(
  4239. :update,
  4240. :params => {
  4241. :id => 1,
  4242. :issue => {
  4243. :subject => 'changed',
  4244. :assigned_to_id => 2,
  4245. :notes => 'just trying'
  4246. }
  4247. }
  4248. )
  4249. end
  4250. issue = Issue.find(1)
  4251. assert_equal "Cannot print recipes", issue.subject
  4252. assert_nil issue.assigned_to
  4253. end
  4254. def setup_with_workflow_privilege
  4255. WorkflowTransition.where(["role_id = ?", Role.anonymous.id]).delete_all
  4256. WorkflowTransition.create!(:role => Role.anonymous, :tracker_id => 1,
  4257. :old_status_id => 1, :new_status_id => 3)
  4258. WorkflowTransition.create!(:role => Role.anonymous, :tracker_id => 1,
  4259. :old_status_id => 1, :new_status_id => 4)
  4260. Role.anonymous.add_permission! :add_issues, :add_issue_notes
  4261. end
  4262. private :setup_with_workflow_privilege
  4263. def setup_with_workflow_privilege_and_edit_issues_permission
  4264. setup_with_workflow_privilege
  4265. Role.anonymous.add_permission! :add_issues, :edit_issues
  4266. end
  4267. private :setup_with_workflow_privilege_and_edit_issues_permission
  4268. test "with workflow privilege and :edit_issues permission should accept authorized status" do
  4269. setup_with_workflow_privilege_and_edit_issues_permission
  4270. assert_difference 'Journal.count' do
  4271. put(
  4272. :update,
  4273. :params => {
  4274. :id => 1,
  4275. :issue => {
  4276. :status_id => 3,
  4277. :notes => 'just trying'
  4278. }
  4279. }
  4280. )
  4281. end
  4282. assert_equal 3, Issue.find(1).status_id
  4283. end
  4284. test "with workflow privilege and :edit_issues permission should ignore unauthorized status" do
  4285. setup_with_workflow_privilege_and_edit_issues_permission
  4286. assert_difference 'Journal.count' do
  4287. put(
  4288. :update,
  4289. :params => {
  4290. :id => 1,
  4291. :issue => {
  4292. :status_id => 2,
  4293. :notes => 'just trying'
  4294. }
  4295. }
  4296. )
  4297. end
  4298. assert_equal 1, Issue.find(1).status_id
  4299. end
  4300. test "with workflow privilege and :edit_issues permission should accept authorized attributes changes" do
  4301. setup_with_workflow_privilege_and_edit_issues_permission
  4302. assert_difference 'Journal.count' do
  4303. put(
  4304. :update,
  4305. :params => {
  4306. :id => 1,
  4307. :issue => {
  4308. :subject => 'changed',
  4309. :assigned_to_id => 2,
  4310. :notes => 'just trying'
  4311. }
  4312. }
  4313. )
  4314. end
  4315. issue = Issue.find(1)
  4316. assert_equal "changed", issue.subject
  4317. assert_equal 2, issue.assigned_to_id
  4318. end
  4319. def test_new_as_copy
  4320. orig = Issue.find(1)
  4321. @request.session[:user_id] = 2
  4322. get(
  4323. :new,
  4324. :params => {
  4325. :project_id => 1,
  4326. :copy_from => orig.id
  4327. }
  4328. )
  4329. assert_response :success
  4330. assert_select 'form[id=issue-form][action="/projects/ecookbook/issues"]' do
  4331. assert_select 'select[name=?]', 'issue[project_id]' do
  4332. assert_select 'option[value="1"][selected=selected]', :text => 'eCookbook'
  4333. assert_select 'option[value="2"]:not([selected])', :text => 'OnlineStore'
  4334. end
  4335. assert_select 'input[name=?][value=?]', 'issue[subject]', orig.subject
  4336. assert_select 'input[name=copy_from][value="1"]'
  4337. end
  4338. end
  4339. def test_new_as_copy_without_add_issues_permission_should_not_propose_current_project_as_target
  4340. user = setup_user_with_copy_but_not_add_permission
  4341. @request.session[:user_id] = user.id
  4342. get(
  4343. :new,
  4344. :params => {
  4345. :project_id => 1,
  4346. :copy_from => 1
  4347. }
  4348. )
  4349. assert_response :success
  4350. assert_select 'select[name=?]', 'issue[project_id]' do
  4351. assert_select 'option[value="1"]', 0
  4352. assert_select 'option[value="2"]', :text => 'OnlineStore'
  4353. end
  4354. end
  4355. def test_new_as_copy_with_attachments_should_show_copy_attachments_checkbox
  4356. @request.session[:user_id] = 2
  4357. issue = Issue.find(3)
  4358. assert issue.attachments.count > 0
  4359. get(
  4360. :new,
  4361. :params => {
  4362. :project_id => 1,
  4363. :copy_from => 3
  4364. }
  4365. )
  4366. assert_select 'input[name=copy_attachments][type=checkbox][checked=checked][value="1"]'
  4367. end
  4368. def test_new_as_copy_without_attachments_should_not_show_copy_attachments_checkbox
  4369. @request.session[:user_id] = 2
  4370. issue = Issue.find(3)
  4371. issue.attachments.delete_all
  4372. get(
  4373. :new,
  4374. :params => {
  4375. :project_id => 1,
  4376. :copy_from => 3
  4377. }
  4378. )
  4379. assert_select 'input[name=copy_attachments]', 0
  4380. end
  4381. def test_new_as_copy_should_preserve_parent_id
  4382. @request.session[:user_id] = 2
  4383. issue = Issue.generate!(:parent_issue_id => 2)
  4384. get(
  4385. :new,
  4386. :params => {
  4387. :project_id => 1,
  4388. :copy_from => issue.id
  4389. }
  4390. )
  4391. assert_select 'input[name=?][value="2"]', 'issue[parent_issue_id]'
  4392. end
  4393. def test_new_as_copy_with_subtasks_should_show_copy_subtasks_checkbox
  4394. @request.session[:user_id] = 2
  4395. issue = Issue.generate_with_descendants!
  4396. get(
  4397. :new,
  4398. :params => {
  4399. :project_id => 1,
  4400. :copy_from => issue.id
  4401. }
  4402. )
  4403. assert_select 'input[type=checkbox][name=copy_subtasks][checked=checked][value="1"]'
  4404. end
  4405. def test_new_as_copy_should_preserve_watchers
  4406. @request.session[:user_id] = 2
  4407. issue = Issue.find(1)
  4408. user = User.generate!
  4409. Watcher.create!(:watchable => issue, :user => user)
  4410. Watcher.create!(:watchable => issue, :user => Group.find(10))
  4411. get(
  4412. :new,
  4413. :params => {
  4414. :project_id => 1,
  4415. :copy_from => 1
  4416. }
  4417. )
  4418. assert_select 'input[type=checkbox][name=?][checked=checked]', 'issue[watcher_user_ids][]', 2
  4419. assert_select 'input[type=checkbox][name=?][checked=checked][value=?]', 'issue[watcher_user_ids][]', user.id.to_s
  4420. assert_select 'input[type=checkbox][name=?][checked=checked][value=?]', 'issue[watcher_user_ids][]', '10'
  4421. assert_select 'input[type=hidden][name=?][value=?]', 'issue[watcher_user_ids][]', '', 1
  4422. end
  4423. def test_new_as_copy_should_not_propose_locked_watchers
  4424. @request.session[:user_id] = 2
  4425. issue = Issue.find(1)
  4426. user = User.generate!
  4427. user2 = User.generate!
  4428. Watcher.create!(:watchable => issue, :user => user)
  4429. Watcher.create!(:watchable => issue, :user => user2)
  4430. user2.status = User::STATUS_LOCKED
  4431. user2.save!
  4432. get(
  4433. :new,
  4434. :params => {
  4435. :project_id => 1,
  4436. :copy_from => 1
  4437. }
  4438. )
  4439. assert_select 'input[type=checkbox][name=?][checked=checked]', 'issue[watcher_user_ids][]', 1
  4440. assert_select 'input[type=checkbox][name=?][checked=checked][value=?]', 'issue[watcher_user_ids][]', user.id.to_s
  4441. assert_select 'input[type=checkbox][name=?][checked=checked][value=?]', 'issue[watcher_user_ids][]', user2.id.to_s, 0
  4442. assert_select 'input[type=hidden][name=?][value=?]', 'issue[watcher_user_ids][]', '', 1
  4443. end
  4444. def test_new_as_copy_with_invalid_issue_should_respond_with_404
  4445. @request.session[:user_id] = 2
  4446. get(
  4447. :new,
  4448. :params => {
  4449. :project_id => 1,
  4450. :copy_from => 99999
  4451. }
  4452. )
  4453. assert_response 404
  4454. end
  4455. def test_create_as_copy_on_different_project
  4456. @request.session[:user_id] = 2
  4457. assert_difference 'Issue.count' do
  4458. post(
  4459. :create,
  4460. :params => {
  4461. :project_id => 1,
  4462. :copy_from => 1,
  4463. :issue => {
  4464. :project_id => '2',
  4465. :tracker_id => '3',
  4466. :status_id => '1',
  4467. :subject => 'Copy'
  4468. }
  4469. }
  4470. )
  4471. end
  4472. issue = Issue.order('id DESC').first
  4473. assert_redirected_to "/issues/#{issue.id}"
  4474. assert_equal 2, issue.project_id
  4475. assert_equal 3, issue.tracker_id
  4476. assert_equal 'Copy', issue.subject
  4477. end
  4478. def test_create_as_copy_should_allow_status_to_be_set_to_default
  4479. copied = Issue.generate! :status_id => 2
  4480. assert_equal 2, copied.reload.status_id
  4481. @request.session[:user_id] = 2
  4482. assert_difference 'Issue.count' do
  4483. post(
  4484. :create,
  4485. :params => {
  4486. :project_id => 1,
  4487. :copy_from => copied.id,
  4488. :issue => {
  4489. :project_id => '1',
  4490. :tracker_id => '1',
  4491. :status_id => '1'
  4492. },
  4493. :was_default_status => '1'
  4494. }
  4495. )
  4496. end
  4497. issue = Issue.order('id DESC').first
  4498. assert_equal 1, issue.status_id
  4499. end
  4500. def test_create_as_copy_should_fail_without_add_issue_permission_on_original_tracker
  4501. role = Role.find(2)
  4502. role.set_permission_trackers :add_issues, [1, 3]
  4503. role.save!
  4504. Role.non_member.remove_permission! :add_issues
  4505. issue = Issue.generate!(:project_id => 1, :tracker_id => 2)
  4506. @request.session[:user_id] = 3
  4507. assert_no_difference 'Issue.count' do
  4508. post(
  4509. :create,
  4510. :params => {
  4511. :project_id => 1,
  4512. :copy_from => issue.id,
  4513. :issue => {
  4514. :project_id => '1'
  4515. }
  4516. }
  4517. )
  4518. end
  4519. assert_select_error 'Tracker is invalid'
  4520. end
  4521. def test_create_as_copy_should_copy_attachments
  4522. @request.session[:user_id] = 2
  4523. issue = Issue.find(3)
  4524. count = issue.attachments.count
  4525. assert count > 0
  4526. assert_difference 'Issue.count' do
  4527. assert_difference 'Attachment.count', count do
  4528. post(
  4529. :create,
  4530. :params => {
  4531. :project_id => 1,
  4532. :copy_from => 3,
  4533. :issue => {
  4534. :project_id => '1',
  4535. :tracker_id => '3',
  4536. :status_id => '1',
  4537. :subject => 'Copy with attachments'
  4538. },
  4539. :copy_attachments => '1'
  4540. }
  4541. )
  4542. end
  4543. end
  4544. copy = Issue.order('id DESC').first
  4545. assert_equal count, copy.attachments.count
  4546. assert_equal issue.attachments.map(&:filename).sort, copy.attachments.map(&:filename).sort
  4547. end
  4548. def test_create_as_copy_without_copy_attachments_option_should_not_copy_attachments
  4549. @request.session[:user_id] = 2
  4550. issue = Issue.find(3)
  4551. count = issue.attachments.count
  4552. assert count > 0
  4553. assert_difference 'Issue.count' do
  4554. assert_no_difference 'Attachment.count' do
  4555. post(
  4556. :create,
  4557. :params => {
  4558. :project_id => 1,
  4559. :copy_from => 3,
  4560. :issue => {
  4561. :project_id => '1',
  4562. :tracker_id => '3',
  4563. :status_id => '1',
  4564. :subject => 'Copy with attachments'
  4565. }
  4566. }
  4567. )
  4568. end
  4569. end
  4570. copy = Issue.order('id DESC').first
  4571. assert_equal 0, copy.attachments.count
  4572. end
  4573. def test_create_as_copy_with_attachments_should_also_add_new_files
  4574. set_tmp_attachments_directory
  4575. @request.session[:user_id] = 2
  4576. issue = Issue.find(3)
  4577. count = issue.attachments.count
  4578. assert count > 0
  4579. assert_difference 'Issue.count' do
  4580. assert_difference 'Attachment.count', count + 1 do
  4581. post(
  4582. :create,
  4583. :params => {
  4584. :project_id => 1,
  4585. :copy_from => 3,
  4586. :issue => {
  4587. :project_id => '1',
  4588. :tracker_id => '3',
  4589. :status_id => '1',
  4590. :subject => 'Copy with attachments'
  4591. },
  4592. :copy_attachments => '1',
  4593. :attachments => {
  4594. '1' => {
  4595. 'file' => uploaded_test_file('testfile.txt', 'text/plain'),
  4596. 'description' => 'test file'
  4597. }
  4598. }
  4599. }
  4600. )
  4601. end
  4602. end
  4603. copy = Issue.order('id DESC').first
  4604. assert_equal count + 1, copy.attachments.count
  4605. end
  4606. def test_create_as_copy_should_add_relation_with_copied_issue
  4607. @request.session[:user_id] = 2
  4608. assert_difference 'Issue.count' do
  4609. assert_difference 'IssueRelation.count' do
  4610. post(
  4611. :create,
  4612. :params => {
  4613. :project_id => 1,
  4614. :copy_from => 1,
  4615. :link_copy => '1',
  4616. :issue => {
  4617. :project_id => '1',
  4618. :tracker_id => '3',
  4619. :status_id => '1',
  4620. :subject => 'Copy'
  4621. }
  4622. }
  4623. )
  4624. end
  4625. end
  4626. copy = Issue.order('id DESC').first
  4627. assert_equal 1, copy.relations.size
  4628. end
  4629. def test_create_as_copy_should_allow_not_to_add_relation_with_copied_issue
  4630. @request.session[:user_id] = 2
  4631. assert_difference 'Issue.count' do
  4632. assert_no_difference 'IssueRelation.count' do
  4633. post(
  4634. :create,
  4635. :params => {
  4636. :project_id => 1,
  4637. :copy_from => 1,
  4638. :issue => {
  4639. :subject => 'Copy'
  4640. }
  4641. }
  4642. )
  4643. end
  4644. end
  4645. end
  4646. def test_create_as_copy_should_always_add_relation_with_copied_issue_by_setting
  4647. with_settings :link_copied_issue => 'yes' do
  4648. @request.session[:user_id] = 2
  4649. assert_difference 'Issue.count' do
  4650. assert_difference 'IssueRelation.count' do
  4651. post(
  4652. :create,
  4653. :params => {
  4654. :project_id => 1,
  4655. :copy_from => 1,
  4656. :issue => {
  4657. :subject => 'Copy'
  4658. }
  4659. }
  4660. )
  4661. end
  4662. end
  4663. end
  4664. end
  4665. def test_create_as_copy_should_never_add_relation_with_copied_issue_by_setting
  4666. with_settings :link_copied_issue => 'no' do
  4667. @request.session[:user_id] = 2
  4668. assert_difference 'Issue.count' do
  4669. assert_no_difference 'IssueRelation.count' do
  4670. post(
  4671. :create,
  4672. :params => {
  4673. :project_id => 1,
  4674. :copy_from => 1,
  4675. :link_copy => '1',
  4676. :issue => {
  4677. :subject => 'Copy'
  4678. }
  4679. }
  4680. )
  4681. end
  4682. end
  4683. end
  4684. end
  4685. def test_create_as_copy_should_copy_subtasks
  4686. @request.session[:user_id] = 2
  4687. issue = Issue.generate_with_descendants!
  4688. count = issue.descendants.count
  4689. assert_difference 'Issue.count', count + 1 do
  4690. post(
  4691. :create,
  4692. :params => {
  4693. :project_id => 1,
  4694. :copy_from => issue.id,
  4695. :issue => {
  4696. :project_id => '1',
  4697. :tracker_id => '3',
  4698. :status_id => '1',
  4699. :subject => 'Copy with subtasks'
  4700. },
  4701. :copy_subtasks => '1'
  4702. }
  4703. )
  4704. end
  4705. copy = Issue.where(:parent_id => nil).order('id DESC').first
  4706. assert_equal count, copy.descendants.count
  4707. assert_equal issue.descendants.map(&:subject).sort, copy.descendants.map(&:subject).sort
  4708. end
  4709. def test_create_as_copy_to_a_different_project_should_copy_subtask_custom_fields
  4710. issue = Issue.generate! {|i| i.custom_field_values = {'2' => 'Foo'}}
  4711. child = Issue.generate!(:parent_issue_id => issue.id) {|i| i.custom_field_values = {'2' => 'Bar'}}
  4712. @request.session[:user_id] = 1
  4713. assert_difference 'Issue.count', 2 do
  4714. post(
  4715. :create,
  4716. :params => {
  4717. :project_id => 'ecookbook',
  4718. :copy_from => issue.id,
  4719. :issue => {
  4720. :project_id => '2',
  4721. :tracker_id => 1,
  4722. :status_id => '1',
  4723. :subject => 'Copy with subtasks',
  4724. :custom_field_values => {
  4725. '2' => 'Foo'
  4726. }
  4727. },
  4728. :copy_subtasks => '1'
  4729. }
  4730. )
  4731. end
  4732. child_copy, issue_copy = Issue.order(:id => :desc).limit(2).to_a
  4733. assert_equal 2, issue_copy.project_id
  4734. assert_equal 'Foo', issue_copy.custom_field_value(2)
  4735. assert_equal 'Bar', child_copy.custom_field_value(2)
  4736. end
  4737. def test_create_as_copy_without_copy_subtasks_option_should_not_copy_subtasks
  4738. @request.session[:user_id] = 2
  4739. issue = Issue.generate_with_descendants!
  4740. assert_difference 'Issue.count', 1 do
  4741. post(
  4742. :create,
  4743. :params => {
  4744. :project_id => 1,
  4745. :copy_from => 3,
  4746. :issue => {
  4747. :project_id => '1',
  4748. :tracker_id => '3',
  4749. :status_id => '1',
  4750. :subject => 'Copy with subtasks'
  4751. }
  4752. }
  4753. )
  4754. end
  4755. copy = Issue.where(:parent_id => nil).order('id DESC').first
  4756. assert_equal 0, copy.descendants.count
  4757. end
  4758. def test_create_as_copy_with_failure
  4759. @request.session[:user_id] = 2
  4760. post(
  4761. :create,
  4762. :params => {
  4763. :project_id => 1,
  4764. :copy_from => 1,
  4765. :issue => {
  4766. :project_id => '2',
  4767. :tracker_id => '3',
  4768. :status_id => '1',
  4769. :subject => ''
  4770. }
  4771. }
  4772. )
  4773. assert_response :success
  4774. assert_select 'form#issue-form[action="/projects/ecookbook/issues"]' do
  4775. assert_select 'select[name=?]', 'issue[project_id]' do
  4776. assert_select 'option[value="1"]:not([selected])', :text => 'eCookbook'
  4777. assert_select 'option[value="2"][selected=selected]', :text => 'OnlineStore'
  4778. end
  4779. assert_select 'input[name=copy_from][value="1"]'
  4780. end
  4781. end
  4782. def test_create_as_copy_on_project_without_permission_should_ignore_target_project
  4783. @request.session[:user_id] = 2
  4784. assert !User.find(2).member_of?(Project.find(4))
  4785. assert_difference 'Issue.count' do
  4786. post(
  4787. :create,
  4788. :params => {
  4789. :project_id => 1,
  4790. :copy_from => 1,
  4791. :issue => {
  4792. :project_id => '4',
  4793. :tracker_id => '3',
  4794. :status_id => '1',
  4795. :subject => 'Copy'
  4796. }
  4797. }
  4798. )
  4799. end
  4800. issue = Issue.order('id DESC').first
  4801. assert_equal 1, issue.project_id
  4802. end
  4803. def test_create_as_copy_with_watcher_user_ids_should_copy_watchers
  4804. @request.session[:user_id] = 2
  4805. copied = Issue.generate!
  4806. copied.add_watcher User.find(2)
  4807. copied.add_watcher User.find(3)
  4808. assert_difference 'Issue.count' do
  4809. post(
  4810. :create,
  4811. :params => {
  4812. :project_id => 1,
  4813. :copy_from => copied.id,
  4814. :issue => {
  4815. :subject => 'Copy cleared watchers',
  4816. :watcher_user_ids => ['', '3', '10']
  4817. }
  4818. }
  4819. )
  4820. end
  4821. issue = Issue.order('id DESC').first
  4822. assert_equal [3, 10], issue.watcher_user_ids
  4823. end
  4824. def test_create_as_copy_without_watcher_user_ids_should_not_copy_watchers
  4825. @request.session[:user_id] = 2
  4826. copied = Issue.generate!
  4827. copied.add_watcher User.find(2)
  4828. copied.add_watcher User.find(3)
  4829. assert_difference 'Issue.count' do
  4830. post(
  4831. :create,
  4832. :params => {
  4833. :project_id => 1,
  4834. :copy_from => copied.id,
  4835. :issue => {
  4836. :subject => 'Copy cleared watchers',
  4837. :watcher_user_ids => ['']
  4838. }
  4839. }
  4840. )
  4841. end
  4842. issue = Issue.order('id DESC').first
  4843. assert_equal [], issue.watcher_user_ids
  4844. end
  4845. def test_get_edit
  4846. @request.session[:user_id] = 2
  4847. get(:edit, :params => {:id => 1})
  4848. assert_response :success
  4849. assert_select 'select[name=?]', 'issue[project_id]'
  4850. # Be sure we don't display inactive IssuePriorities
  4851. assert ! IssuePriority.find(15).active?
  4852. assert_select 'select[name=?]', 'issue[priority_id]' do
  4853. assert_select 'option[value="15"]', 0
  4854. end
  4855. end
  4856. def test_edit_should_hide_project_if_user_is_not_allowed_to_change_project
  4857. WorkflowPermission.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :field_name => 'project_id', :rule => 'readonly')
  4858. @request.session[:user_id] = 2
  4859. get(:edit, :params => {:id => 1})
  4860. assert_response :success
  4861. assert_select 'select[name=?]', 'issue[project_id]', 0
  4862. end
  4863. def test_edit_should_not_hide_project_when_user_changes_the_project_even_if_project_is_readonly_on_target_project
  4864. WorkflowPermission.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :field_name => 'project_id', :rule => 'readonly')
  4865. issue = Issue.generate!(:project_id => 2)
  4866. @request.session[:user_id] = 2
  4867. get(
  4868. :edit,
  4869. :params => {
  4870. :id => issue.id,
  4871. :issue => {
  4872. :project_id => 1
  4873. }
  4874. }
  4875. )
  4876. assert_response :success
  4877. assert_select 'select[name=?]', 'issue[project_id]'
  4878. end
  4879. def test_get_edit_should_display_the_time_entry_form_with_log_time_permission
  4880. @request.session[:user_id] = 2
  4881. Role.find_by_name('Manager').update_attribute :permissions, [:view_issues, :edit_issues, :log_time]
  4882. get(:edit, :params => {:id => 1})
  4883. assert_select 'input[name=?]', 'time_entry[hours]'
  4884. end
  4885. def test_get_edit_should_not_display_the_time_entry_form_without_log_time_permission
  4886. @request.session[:user_id] = 2
  4887. Role.find_by_name('Manager').remove_permission! :log_time
  4888. get(:edit, :params => {:id => 1})
  4889. assert_select 'input[name=?]', 'time_entry[hours]', 0
  4890. end
  4891. def test_get_edit_with_params
  4892. @request.session[:user_id] = 2
  4893. get(
  4894. :edit,
  4895. :params => {
  4896. :id => 1,
  4897. :issue => {
  4898. :status_id => 5,
  4899. :priority_id => 7
  4900. },
  4901. :time_entry => {
  4902. :hours => '2.5',
  4903. :comments => 'test_get_edit_with_params',
  4904. :activity_id => 10
  4905. }
  4906. }
  4907. )
  4908. assert_response :success
  4909. assert_select 'select[name=?]', 'issue[status_id]' do
  4910. assert_select 'option[value="5"][selected=selected]', :text => 'Closed'
  4911. end
  4912. assert_select 'select[name=?]', 'issue[priority_id]' do
  4913. assert_select 'option[value="7"][selected=selected]', :text => 'Urgent'
  4914. end
  4915. assert_select 'input[name=?][value="2.50"]', 'time_entry[hours]'
  4916. assert_select 'select[name=?]', 'time_entry[activity_id]' do
  4917. assert_select 'option[value="10"][selected=selected]', :text => 'Development'
  4918. end
  4919. assert_select 'input[name=?][value=test_get_edit_with_params]', 'time_entry[comments]'
  4920. end
  4921. def test_get_edit_with_multi_custom_field
  4922. field = CustomField.find(1)
  4923. field.update_attribute :multiple, true
  4924. issue = Issue.find(1)
  4925. issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
  4926. issue.save!
  4927. @request.session[:user_id] = 2
  4928. get(:edit, :params => {:id => 1})
  4929. assert_response :success
  4930. assert_select 'select[name=?][multiple=multiple]', 'issue[custom_field_values][1][]' do
  4931. assert_select 'option', 3
  4932. assert_select 'option[value=MySQL][selected=selected]'
  4933. assert_select 'option[value=Oracle][selected=selected]'
  4934. assert_select 'option[value=PostgreSQL]:not([selected])'
  4935. end
  4936. end
  4937. def test_get_edit_with_me_assigned_to_id
  4938. @request.session[:user_id] = 2
  4939. get(
  4940. :edit,
  4941. :params => {
  4942. :id => 1,
  4943. :issue => {:assigned_to_id => 'me'}
  4944. }
  4945. )
  4946. assert_response :success
  4947. assert_select 'select[name=?]', 'issue[assigned_to_id]' do
  4948. assert_select 'option[value="2"][selected=selected]'
  4949. end
  4950. end
  4951. def test_update_form_for_existing_issue
  4952. @request.session[:user_id] = 2
  4953. patch(
  4954. :edit,
  4955. :params => {
  4956. :id => 1,
  4957. :issue => {
  4958. :tracker_id => 2,
  4959. :subject => 'This is the test_new issue',
  4960. :description => 'This is the description',
  4961. :priority_id => 5
  4962. }
  4963. },
  4964. :xhr => true
  4965. )
  4966. assert_response :success
  4967. assert_equal 'text/javascript', response.media_type
  4968. assert_include 'This is the test_new issue', response.body
  4969. end
  4970. def test_update_form_for_existing_issue_should_keep_issue_author
  4971. @request.session[:user_id] = 3
  4972. patch(
  4973. :edit,
  4974. :params => {
  4975. :id => 1,
  4976. :issue => {
  4977. :subject => 'Changed'
  4978. }
  4979. }
  4980. )
  4981. assert_response :success
  4982. assert_equal User.find(2), Issue.find(1).author
  4983. end
  4984. def test_update_form_for_existing_issue_should_propose_transitions_based_on_initial_status
  4985. @request.session[:user_id] = 2
  4986. WorkflowTransition.delete_all
  4987. WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 1)
  4988. WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 5)
  4989. WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 5, :new_status_id => 4)
  4990. patch(
  4991. :edit,
  4992. :params => {
  4993. :id => 2,
  4994. :issue => {
  4995. :tracker_id => 2,
  4996. :status_id => 5,
  4997. :subject => 'This is an issue'
  4998. }
  4999. }
  5000. )
  5001. assert_select 'select[name=?]', 'issue[status_id]' do
  5002. assert_select 'option[value="1"]'
  5003. assert_select 'option[value="2"]'
  5004. assert_select 'option[value="5"][selected=selected]'
  5005. assert_select 'option', 3
  5006. end
  5007. end
  5008. def test_update_form_for_existing_issue_with_project_change
  5009. @request.session[:user_id] = 2
  5010. patch(
  5011. :edit,
  5012. :params => {
  5013. :id => 1,
  5014. :issue => {
  5015. :project_id => 2,
  5016. :tracker_id => 2,
  5017. :subject => 'This is the test_new issue',
  5018. :description => 'This is the description',
  5019. :priority_id => 5
  5020. }
  5021. }
  5022. )
  5023. assert_response :success
  5024. assert_select 'select[name=?]', 'issue[project_id]' do
  5025. assert_select 'option[value="2"][selected=selected]'
  5026. end
  5027. assert_select 'select[name=?]', 'issue[tracker_id]' do
  5028. assert_select 'option[value="2"][selected=selected]'
  5029. end
  5030. assert_select 'input[name=?][value=?]', 'issue[subject]', 'This is the test_new issue'
  5031. end
  5032. def test_update_form_should_keep_category_with_same_when_changing_project
  5033. source = Project.generate!
  5034. target = Project.generate!
  5035. source_category = IssueCategory.create!(:name => 'Foo', :project => source)
  5036. target_category = IssueCategory.create!(:name => 'Foo', :project => target)
  5037. issue = Issue.generate!(:project => source, :category => source_category)
  5038. @request.session[:user_id] = 1
  5039. patch(
  5040. :edit,
  5041. :params => {
  5042. :id => issue.id,
  5043. :issue => {
  5044. :project_id => target.id,
  5045. :category_id => source_category.id
  5046. }
  5047. }
  5048. )
  5049. assert_response :success
  5050. assert_select 'select[name=?]', 'issue[category_id]' do
  5051. assert_select 'option[value=?][selected=selected]', target_category.id.to_s
  5052. end
  5053. end
  5054. def test_update_form_should_propose_default_status_for_existing_issue
  5055. @request.session[:user_id] = 2
  5056. WorkflowTransition.delete_all
  5057. WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 3)
  5058. patch(:edit, :params => {:id => 2})
  5059. assert_response :success
  5060. assert_select 'select[name=?]', 'issue[status_id]' do
  5061. assert_select 'option[value="2"]'
  5062. assert_select 'option[value="3"]'
  5063. assert_select 'option', 2
  5064. end
  5065. end
  5066. def test_put_update_without_custom_fields_param
  5067. @request.session[:user_id] = 2
  5068. issue = Issue.find(1)
  5069. assert_equal '125', issue.custom_value_for(2).value
  5070. assert_difference('Journal.count') do
  5071. assert_difference('JournalDetail.count') do
  5072. put(
  5073. :update,
  5074. :params => {
  5075. :id => 1,
  5076. :issue => {
  5077. :subject => 'New subject'
  5078. }
  5079. }
  5080. )
  5081. end
  5082. end
  5083. assert_redirected_to :action => 'show', :id => '1'
  5084. issue.reload
  5085. assert_equal 'New subject', issue.subject
  5086. # Make sure custom fields were not cleared
  5087. assert_equal '125', issue.custom_value_for(2).value
  5088. end
  5089. def test_put_update_with_project_change
  5090. @request.session[:user_id] = 2
  5091. ActionMailer::Base.deliveries.clear
  5092. with_settings :notified_events => %w(issue_updated) do
  5093. assert_difference('Journal.count') do
  5094. assert_difference('JournalDetail.count', 3) do
  5095. put(
  5096. :update,
  5097. :params => {
  5098. :id => 1,
  5099. :issue => {
  5100. :project_id => '2',
  5101. :tracker_id => '1', # no change
  5102. :priority_id => '6',
  5103. :category_id => '3'
  5104. }
  5105. }
  5106. )
  5107. end
  5108. end
  5109. end
  5110. assert_redirected_to :action => 'show', :id => '1'
  5111. issue = Issue.find(1)
  5112. assert_equal 2, issue.project_id
  5113. assert_equal 1, issue.tracker_id
  5114. assert_equal 6, issue.priority_id
  5115. assert_equal 3, issue.category_id
  5116. mail = ActionMailer::Base.deliveries.last
  5117. assert_not_nil mail
  5118. assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
  5119. assert_mail_body_match "Project changed from eCookbook to OnlineStore", mail
  5120. end
  5121. def test_put_update_trying_to_move_issue_to_project_without_tracker_should_not_error
  5122. target = Project.generate!(:tracker_ids => [])
  5123. assert target.trackers.empty?
  5124. issue = Issue.generate!
  5125. @request.session[:user_id] = 1
  5126. put(
  5127. :update,
  5128. :params => {
  5129. :id => issue.id,
  5130. :issue => {
  5131. :project_id => target.id
  5132. }
  5133. }
  5134. )
  5135. assert_response 302
  5136. end
  5137. def test_put_update_with_tracker_change
  5138. @request.session[:user_id] = 2
  5139. ActionMailer::Base.deliveries.clear
  5140. with_settings :notified_events => %w(issue_updated) do
  5141. assert_difference('Journal.count') do
  5142. assert_difference('JournalDetail.count', 3) do
  5143. put(
  5144. :update,
  5145. :params => {
  5146. :id => 1,
  5147. :issue => {
  5148. :project_id => '1',
  5149. :tracker_id => '2',
  5150. :priority_id => '6'
  5151. }
  5152. }
  5153. )
  5154. end
  5155. end
  5156. end
  5157. assert_redirected_to :action => 'show', :id => '1'
  5158. issue = Issue.find(1)
  5159. assert_equal 1, issue.project_id
  5160. assert_equal 2, issue.tracker_id
  5161. assert_equal 6, issue.priority_id
  5162. assert_equal 1, issue.category_id
  5163. mail = ActionMailer::Base.deliveries.last
  5164. assert_not_nil mail
  5165. assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
  5166. assert_mail_body_match "Tracker changed from Bug to Feature request", mail
  5167. end
  5168. def test_put_update_with_custom_field_change
  5169. @request.session[:user_id] = 2
  5170. issue = Issue.find(1)
  5171. assert_equal '125', issue.custom_value_for(2).value
  5172. with_settings :notified_events => %w(issue_updated) do
  5173. assert_difference('Journal.count') do
  5174. assert_difference('JournalDetail.count', 3) do
  5175. put(
  5176. :update,
  5177. :params => {
  5178. :id => 1,
  5179. :issue => {
  5180. :subject => 'Custom field change',
  5181. :priority_id => '6',
  5182. :category_id => '1', # no change
  5183. :custom_field_values => {'2' => 'New custom value'}
  5184. }
  5185. }
  5186. )
  5187. end
  5188. end
  5189. end
  5190. assert_redirected_to :action => 'show', :id => '1'
  5191. issue.reload
  5192. assert_equal 'New custom value', issue.custom_value_for(2).value
  5193. mail = ActionMailer::Base.deliveries.last
  5194. assert_not_nil mail
  5195. assert_mail_body_match "Searchable field changed from 125 to New custom value", mail
  5196. end
  5197. def test_put_update_with_multi_custom_field_change
  5198. field = CustomField.find(1)
  5199. field.update_attribute :multiple, true
  5200. issue = Issue.find(1)
  5201. issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
  5202. issue.save!
  5203. @request.session[:user_id] = 2
  5204. assert_difference('Journal.count') do
  5205. assert_difference('JournalDetail.count', 3) do
  5206. put(
  5207. :update,
  5208. :params => {
  5209. :id => 1,
  5210. :issue => {
  5211. :subject => 'Custom field change',
  5212. :custom_field_values => {
  5213. '1' => ['', 'Oracle', 'PostgreSQL']
  5214. }
  5215. }
  5216. }
  5217. )
  5218. end
  5219. end
  5220. assert_redirected_to :action => 'show', :id => '1'
  5221. assert_equal ['Oracle', 'PostgreSQL'], Issue.find(1).custom_field_value(1).sort
  5222. end
  5223. def test_put_update_with_status_and_assignee_change
  5224. issue = Issue.find(1)
  5225. assert_equal 1, issue.status_id
  5226. @request.session[:user_id] = 2
  5227. with_settings :notified_events => %w(issue_updated) do
  5228. assert_difference('TimeEntry.count', 0) do
  5229. put(
  5230. :update,
  5231. :params => {
  5232. :id => 1,
  5233. :issue => {
  5234. :status_id => 2,
  5235. :assigned_to_id => 3,
  5236. :notes => 'Assigned to dlopper'
  5237. },
  5238. :time_entry => {
  5239. :hours => '',
  5240. :comments => '',
  5241. :activity_id => TimeEntryActivity.first
  5242. }
  5243. }
  5244. )
  5245. end
  5246. end
  5247. assert_redirected_to :action => 'show', :id => '1'
  5248. issue.reload
  5249. assert_equal 2, issue.status_id
  5250. j = Journal.order('id DESC').first
  5251. assert_equal 'Assigned to dlopper', j.notes
  5252. assert_equal 2, j.details.size
  5253. mail = ActionMailer::Base.deliveries.last
  5254. assert_mail_body_match "Status changed from New to Assigned", mail
  5255. # subject should contain the new status
  5256. assert mail.subject.include?("(#{IssueStatus.find(2).name})")
  5257. end
  5258. def test_put_update_with_note_only
  5259. notes = 'Note added by IssuesControllerTest#test_update_with_note_only'
  5260. with_settings :notified_events => %w(issue_updated) do
  5261. # anonymous user
  5262. put(
  5263. :update,
  5264. :params => {
  5265. :id => 1,
  5266. :issue => {
  5267. :notes => notes
  5268. }
  5269. }
  5270. )
  5271. end
  5272. assert_redirected_to :action => 'show', :id => '1'
  5273. j = Journal.order('id DESC').first
  5274. assert_equal notes, j.notes
  5275. assert_equal 0, j.details.size
  5276. assert_equal User.anonymous, j.user
  5277. mail = ActionMailer::Base.deliveries.last
  5278. assert_mail_body_match notes, mail
  5279. end
  5280. def test_put_update_with_private_note_only
  5281. notes = 'Private note'
  5282. @request.session[:user_id] = 2
  5283. assert_difference 'Journal.count' do
  5284. put(
  5285. :update,
  5286. :params => {
  5287. :id => 1,
  5288. :issue => {
  5289. :notes => notes,
  5290. :private_notes => '1'
  5291. }
  5292. }
  5293. )
  5294. assert_redirected_to :action => 'show', :id => '1'
  5295. end
  5296. j = Journal.order('id DESC').first
  5297. assert_equal notes, j.notes
  5298. assert_equal true, j.private_notes
  5299. end
  5300. def test_put_update_with_private_note_and_changes
  5301. notes = 'Private note'
  5302. @request.session[:user_id] = 2
  5303. assert_difference 'Journal.count', 2 do
  5304. put(
  5305. :update,
  5306. :params => {
  5307. :id => 1,
  5308. :issue => {
  5309. :subject => 'New subject',
  5310. :notes => notes,
  5311. :private_notes => '1'
  5312. }
  5313. }
  5314. )
  5315. assert_redirected_to :action => 'show', :id => '1'
  5316. end
  5317. j = Journal.order('id DESC').first
  5318. assert_equal notes, j.notes
  5319. assert_equal true, j.private_notes
  5320. assert_equal 0, j.details.count
  5321. j = Journal.order('id DESC').offset(1).first
  5322. assert_nil j.notes
  5323. assert_equal false, j.private_notes
  5324. assert_equal 1, j.details.count
  5325. end
  5326. def test_put_update_with_note_and_spent_time
  5327. @request.session[:user_id] = 2
  5328. spent_hours_before = Issue.find(1).spent_hours
  5329. assert_difference('TimeEntry.count') do
  5330. put(
  5331. :update,
  5332. :params => {
  5333. :id => 1,
  5334. :issue => {
  5335. :notes => '2.5 hours added'
  5336. },
  5337. :time_entry => {
  5338. :hours => '2.5',
  5339. :comments => 'test_put_update_with_note_and_spent_time',
  5340. :activity_id => TimeEntryActivity.first.id
  5341. }
  5342. }
  5343. )
  5344. end
  5345. assert_redirected_to :action => 'show', :id => '1'
  5346. issue = Issue.find(1)
  5347. j = Journal.order('id DESC').first
  5348. assert_equal '2.5 hours added', j.notes
  5349. assert_equal 0, j.details.size
  5350. t = issue.time_entries.find_by_comments('test_put_update_with_note_and_spent_time')
  5351. assert_not_nil t
  5352. assert_equal 2.5, t.hours
  5353. assert_equal spent_hours_before + 2.5, issue.spent_hours
  5354. end
  5355. def test_put_update_should_preserve_parent_issue_even_if_not_visible
  5356. parent = Issue.generate!(:project_id => 1, :is_private => true)
  5357. issue = Issue.generate!(:parent_issue_id => parent.id)
  5358. assert !parent.visible?(User.find(3))
  5359. @request.session[:user_id] = 3
  5360. get(:edit, :params => {:id => issue.id})
  5361. assert_select 'input[name=?][value=?]', 'issue[parent_issue_id]', parent.id.to_s
  5362. put(
  5363. :update,
  5364. :params => {
  5365. :id => issue.id,
  5366. :issue => {
  5367. :subject => 'New subject',
  5368. :parent_issue_id => parent.id.to_s
  5369. }
  5370. }
  5371. )
  5372. assert_response 302
  5373. assert_equal parent, issue.parent
  5374. end
  5375. def test_put_update_with_attachment_only
  5376. set_tmp_attachments_directory
  5377. # Delete all fixtured journals, a race condition can occur causing the wrong
  5378. # journal to get fetched in the next find.
  5379. Journal.delete_all
  5380. JournalDetail.delete_all
  5381. with_settings :notified_events => %w(issue_updated) do
  5382. # anonymous user
  5383. assert_difference 'Attachment.count' do
  5384. put(
  5385. :update,
  5386. :params => {
  5387. :id => 1,
  5388. :issue => {
  5389. :notes => ''
  5390. },
  5391. :attachments => {
  5392. '1' => {
  5393. 'file' => uploaded_test_file('testfile.txt', 'text/plain'),
  5394. 'description' => 'test file'
  5395. }
  5396. }
  5397. }
  5398. )
  5399. end
  5400. end
  5401. assert_redirected_to :action => 'show', :id => '1'
  5402. j = Issue.find(1).journals.reorder('id DESC').first
  5403. assert j.notes.blank?
  5404. assert_equal 1, j.details.size
  5405. assert_equal 'testfile.txt', j.details.first.value
  5406. assert_equal User.anonymous, j.user
  5407. attachment = Attachment.order('id DESC').first
  5408. assert_equal Issue.find(1), attachment.container
  5409. assert_equal User.anonymous, attachment.author
  5410. assert_equal 'testfile.txt', attachment.filename
  5411. assert_equal 'text/plain', attachment.content_type
  5412. assert_equal 'test file', attachment.description
  5413. assert_equal 59, attachment.filesize
  5414. assert File.exists?(attachment.diskfile)
  5415. assert_equal 59, File.size(attachment.diskfile)
  5416. mail = ActionMailer::Base.deliveries.last
  5417. assert_mail_body_match 'testfile.txt', mail
  5418. end
  5419. def test_put_update_with_failure_should_save_attachments
  5420. set_tmp_attachments_directory
  5421. @request.session[:user_id] = 2
  5422. assert_no_difference 'Journal.count' do
  5423. assert_difference 'Attachment.count' do
  5424. put(
  5425. :update,
  5426. :params => {
  5427. :id => 1,
  5428. :issue => {
  5429. :subject => ''
  5430. },
  5431. :attachments => {
  5432. '1' => {
  5433. 'file' => uploaded_test_file('testfile.txt', 'text/plain'),
  5434. 'description' => 'test file'
  5435. }
  5436. }
  5437. }
  5438. )
  5439. assert_response :success
  5440. end
  5441. end
  5442. attachment = Attachment.order('id DESC').first
  5443. assert_equal 'testfile.txt', attachment.filename
  5444. assert File.exists?(attachment.diskfile)
  5445. assert_nil attachment.container
  5446. assert_select 'input[name=?][value=?]', 'attachments[p0][token]', attachment.token
  5447. assert_select 'input[name=?][value=?]', 'attachments[p0][filename]', 'testfile.txt'
  5448. end
  5449. def test_put_update_with_failure_should_keep_saved_attachments
  5450. set_tmp_attachments_directory
  5451. attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
  5452. @request.session[:user_id] = 2
  5453. assert_no_difference 'Journal.count' do
  5454. assert_no_difference 'Attachment.count' do
  5455. put(
  5456. :update,
  5457. :params => {
  5458. :id => 1,
  5459. :issue => {
  5460. :subject => ''
  5461. },
  5462. :attachments => {
  5463. 'p0' => {
  5464. 'token' => attachment.token
  5465. }
  5466. }
  5467. }
  5468. )
  5469. assert_response :success
  5470. end
  5471. end
  5472. assert_select 'input[name=?][value=?]', 'attachments[p0][token]', attachment.token
  5473. assert_select 'input[name=?][value=?]', 'attachments[p0][filename]', 'testfile.txt'
  5474. end
  5475. def test_put_update_should_attach_saved_attachments
  5476. set_tmp_attachments_directory
  5477. attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
  5478. @request.session[:user_id] = 2
  5479. assert_difference 'Journal.count' do
  5480. assert_difference 'JournalDetail.count' do
  5481. assert_no_difference 'Attachment.count' do
  5482. put(
  5483. :update,
  5484. :params => {
  5485. :id => 1,
  5486. :issue => {
  5487. :notes => 'Attachment added'
  5488. },
  5489. :attachments => {
  5490. 'p0' => {
  5491. 'token' => attachment.token
  5492. }
  5493. }
  5494. }
  5495. )
  5496. assert_redirected_to '/issues/1'
  5497. end
  5498. end
  5499. end
  5500. attachment.reload
  5501. assert_equal Issue.find(1), attachment.container
  5502. journal = Journal.order('id DESC').first
  5503. assert_equal 1, journal.details.size
  5504. assert_equal 'testfile.txt', journal.details.first.value
  5505. end
  5506. def test_put_update_with_attachment_that_fails_to_save
  5507. set_tmp_attachments_directory
  5508. # anonymous user
  5509. with_settings :attachment_max_size => 0 do
  5510. put(
  5511. :update,
  5512. :params => {
  5513. :id => 1,
  5514. :issue => {
  5515. :notes => ''
  5516. },
  5517. :attachments => {
  5518. '1' => {
  5519. 'file' => uploaded_test_file('testfile.txt', 'text/plain')
  5520. }
  5521. }
  5522. }
  5523. )
  5524. assert_redirected_to :action => 'show', :id => '1'
  5525. assert_equal '1 file(s) could not be saved.', flash[:warning]
  5526. end
  5527. end
  5528. def test_put_update_with_attachment_deletion_should_create_a_single_journal
  5529. set_tmp_attachments_directory
  5530. ActionMailer::Base.deliveries.clear
  5531. @request.session[:user_id] = 2
  5532. journal = new_record(Journal) do
  5533. assert_difference 'Attachment.count', -2 do
  5534. put(
  5535. :update,
  5536. :params => {
  5537. :id => 3,
  5538. :issue => {
  5539. :notes => 'Removing attachments',
  5540. :deleted_attachment_ids => ['1', '5']
  5541. }
  5542. }
  5543. )
  5544. end
  5545. end
  5546. assert_equal 'Removing attachments', journal.notes
  5547. assert_equal 2, journal.details.count
  5548. assert_select_email do
  5549. assert_select 'ul.journal.details li', 2
  5550. assert_select 'del', :text => 'error281.txt'
  5551. assert_select 'del', :text => 'changeset_iso8859-1.diff'
  5552. end
  5553. end
  5554. def test_put_update_with_attachment_deletion_and_failure_should_preserve_selected_attachments
  5555. set_tmp_attachments_directory
  5556. @request.session[:user_id] = 2
  5557. assert_no_difference 'Journal.count' do
  5558. assert_no_difference 'Attachment.count' do
  5559. put(
  5560. :update,
  5561. :params => {
  5562. :id => 3,
  5563. :issue => {
  5564. :subject => '',
  5565. :notes => 'Removing attachments',
  5566. :deleted_attachment_ids => ['1', '5']
  5567. }
  5568. }
  5569. )
  5570. end
  5571. end
  5572. assert_select 'input[name=?][value="1"][checked=checked]', 'issue[deleted_attachment_ids][]'
  5573. assert_select 'input[name=?][value="5"][checked=checked]', 'issue[deleted_attachment_ids][]'
  5574. assert_select 'input[name=?][value="6"]:not([checked])', 'issue[deleted_attachment_ids][]'
  5575. end
  5576. def test_put_update_with_no_change
  5577. issue = Issue.find(1)
  5578. issue.journals.clear
  5579. ActionMailer::Base.deliveries.clear
  5580. put(
  5581. :update,
  5582. :params => {
  5583. :id => 1,
  5584. :issue => {
  5585. :notes => ''
  5586. }
  5587. }
  5588. )
  5589. assert_redirected_to :action => 'show', :id => '1'
  5590. issue.reload
  5591. assert issue.journals.empty?
  5592. # No email should be sent
  5593. assert ActionMailer::Base.deliveries.empty?
  5594. end
  5595. def test_put_update_should_send_a_notification
  5596. @request.session[:user_id] = 2
  5597. ActionMailer::Base.deliveries.clear
  5598. issue = Issue.find(1)
  5599. old_subject = issue.subject
  5600. new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
  5601. with_settings :notified_events => %w(issue_updated) do
  5602. put(
  5603. :update,
  5604. :params => {
  5605. :id => 1,
  5606. :issue => {
  5607. :subject => new_subject,
  5608. :priority_id => '6',
  5609. :category_id => '1' # no change
  5610. }
  5611. }
  5612. )
  5613. assert_equal 2, ActionMailer::Base.deliveries.size
  5614. end
  5615. end
  5616. def test_put_update_with_invalid_spent_time_hours_only
  5617. @request.session[:user_id] = 2
  5618. notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
  5619. assert_no_difference('Journal.count') do
  5620. put(
  5621. :update,
  5622. :params => {
  5623. :id => 1,
  5624. :issue => {
  5625. :notes => notes
  5626. },
  5627. :time_entry => {
  5628. "comments"=>"", "activity_id"=>"", "hours"=>"2z"
  5629. }
  5630. }
  5631. )
  5632. end
  5633. assert_response :success
  5634. assert_select_error /Activity cannot be blank/
  5635. assert_select 'textarea[name=?]', 'issue[notes]', :text => notes
  5636. assert_select 'input[name=?][value=?]', 'time_entry[hours]', '2z'
  5637. end
  5638. def test_put_update_with_invalid_spent_time_comments_only
  5639. @request.session[:user_id] = 2
  5640. notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
  5641. assert_no_difference('Journal.count') do
  5642. put(
  5643. :update,
  5644. :params => {
  5645. :id => 1,
  5646. :issue => {
  5647. :notes => notes
  5648. },
  5649. :time_entry => {
  5650. "comments"=>"this is my comment", "activity_id"=>"", "hours"=>""
  5651. }
  5652. }
  5653. )
  5654. end
  5655. assert_response :success
  5656. assert_select_error /Activity cannot be blank/
  5657. assert_select_error /Hours cannot be blank/
  5658. assert_select 'textarea[name=?]', 'issue[notes]', :text => notes
  5659. assert_select 'input[name=?][value=?]', 'time_entry[comments]', 'this is my comment'
  5660. end
  5661. def test_put_update_should_allow_fixed_version_to_be_set_to_a_subproject
  5662. issue = Issue.find(2)
  5663. @request.session[:user_id] = 2
  5664. put(
  5665. :update,
  5666. :params => {
  5667. :id => issue.id,
  5668. :issue => {
  5669. :fixed_version_id => 4
  5670. }
  5671. }
  5672. )
  5673. assert_response :redirect
  5674. issue.reload
  5675. assert_equal 4, issue.fixed_version_id
  5676. assert_not_equal issue.project_id, issue.fixed_version.project_id
  5677. end
  5678. def test_put_update_should_redirect_back_using_the_back_url_parameter
  5679. issue = Issue.find(2)
  5680. @request.session[:user_id] = 2
  5681. put(
  5682. :update,
  5683. :params => {
  5684. :id => issue.id,
  5685. :issue => {
  5686. :fixed_version_id => 4
  5687. },
  5688. :back_url => '/issues'
  5689. }
  5690. )
  5691. assert_response :redirect
  5692. assert_redirected_to '/issues'
  5693. end
  5694. def test_put_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
  5695. issue = Issue.find(2)
  5696. @request.session[:user_id] = 2
  5697. put(
  5698. :update,
  5699. :params => {
  5700. :id => issue.id,
  5701. :issue => {
  5702. :fixed_version_id => 4
  5703. },
  5704. :back_url => 'http://google.com'
  5705. }
  5706. )
  5707. assert_response :redirect
  5708. assert_redirected_to :controller => 'issues', :action => 'show', :id => issue.id
  5709. end
  5710. def test_put_update_should_redirect_with_previous_and_next_issue_ids_params
  5711. @request.session[:user_id] = 2
  5712. put(
  5713. :update,
  5714. :params => {
  5715. :id => 11,
  5716. :issue => {
  5717. :status_id => 6,
  5718. :notes => 'Notes'
  5719. },
  5720. :prev_issue_id => 8,
  5721. :next_issue_id => 12,
  5722. :issue_position => 2,
  5723. :issue_count => 3
  5724. }
  5725. )
  5726. assert_redirected_to '/issues/11?issue_count=3&issue_position=2&next_issue_id=12&prev_issue_id=8'
  5727. end
  5728. def test_update_with_permission_on_tracker_should_be_allowed
  5729. role = Role.find(1)
  5730. role.set_permission_trackers :edit_issues, [1]
  5731. role.save!
  5732. issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :subject => 'Original subject')
  5733. @request.session[:user_id] = 2
  5734. put(
  5735. :update,
  5736. :params => {
  5737. :id => issue.id,
  5738. :issue => {
  5739. :subject => 'Changed subject'
  5740. }
  5741. }
  5742. )
  5743. assert_response 302
  5744. assert_equal 'Changed subject', issue.reload.subject
  5745. end
  5746. def test_update_without_permission_on_tracker_should_be_denied
  5747. role = Role.find(1)
  5748. role.set_permission_trackers :edit_issues, [1]
  5749. role.save!
  5750. issue = Issue.generate!(:project_id => 1, :tracker_id => 2, :subject => 'Original subject')
  5751. @request.session[:user_id] = 2
  5752. put(
  5753. :update,
  5754. :params => {
  5755. :id => issue.id,
  5756. :issue => {
  5757. :subject => 'Changed subject'
  5758. }
  5759. }
  5760. )
  5761. assert_response 302
  5762. assert_equal 'Original subject', issue.reload.subject
  5763. end
  5764. def test_update_with_me_assigned_to_id
  5765. @request.session[:user_id] = 2
  5766. issue = Issue.find(1)
  5767. assert_not_equal 2, issue.assigned_to_id
  5768. put(
  5769. :update,
  5770. :params => {
  5771. :id => issue.id,
  5772. :issue => {
  5773. :assigned_to_id => 'me'
  5774. }
  5775. }
  5776. )
  5777. assert_response 302
  5778. assert_equal 2, issue.reload.assigned_to_id
  5779. end
  5780. def test_get_bulk_edit
  5781. @request.session[:user_id] = 2
  5782. get(:bulk_edit, :params => {:ids => [1, 3]})
  5783. assert_response :success
  5784. assert_select 'ul#bulk-selection' do
  5785. assert_select 'li', 2
  5786. assert_select 'li a', :text => 'Bug #1'
  5787. end
  5788. assert_select 'form#bulk_edit_form[action=?]', '/issues/bulk_update' do
  5789. assert_select 'input[name=?]', 'ids[]', 2
  5790. assert_select 'input[name=?][value="1"][type=hidden]', 'ids[]'
  5791. assert_select 'select[name=?]', 'issue[project_id]'
  5792. assert_select 'input[name=?]', 'issue[parent_issue_id]'
  5793. # Project specific custom field, date type
  5794. field = CustomField.find(9)
  5795. assert !field.is_for_all?
  5796. assert_equal 'date', field.field_format
  5797. assert_select 'input[name=?]', 'issue[custom_field_values][9]'
  5798. # System wide custom field
  5799. assert CustomField.find(1).is_for_all?
  5800. assert_select 'select[name=?]', 'issue[custom_field_values][1]'
  5801. # Be sure we don't display inactive IssuePriorities
  5802. assert ! IssuePriority.find(15).active?
  5803. assert_select 'select[name=?]', 'issue[priority_id]' do
  5804. assert_select 'option[value="15"]', 0
  5805. end
  5806. end
  5807. end
  5808. def test_get_bulk_edit_on_different_projects
  5809. @request.session[:user_id] = 2
  5810. get(:bulk_edit, :params => {:ids => [1, 2, 6]})
  5811. assert_response :success
  5812. # Can not set issues from different projects as children of an issue
  5813. assert_select 'input[name=?]', 'issue[parent_issue_id]', 0
  5814. # Project specific custom field, date type
  5815. field = CustomField.find(9)
  5816. assert !field.is_for_all?
  5817. assert !field.project_ids.include?(Issue.find(6).project_id)
  5818. assert_select 'input[name=?]', 'issue[custom_field_values][9]', 0
  5819. end
  5820. def test_get_bulk_edit_with_user_custom_field
  5821. field =
  5822. IssueCustomField.
  5823. create!(
  5824. :name => 'Tester',
  5825. :field_format => 'user',
  5826. :is_for_all => true,
  5827. :tracker_ids => [1, 2, 3]
  5828. )
  5829. @request.session[:user_id] = 2
  5830. get(:bulk_edit, :params => {:ids => [1, 2]})
  5831. assert_response :success
  5832. assert_select 'select.user_cf[name=?]', "issue[custom_field_values][#{field.id}]" do
  5833. assert_select 'option', Project.find(1).users.count + 3 # "no change" + "none" + "me" options
  5834. end
  5835. end
  5836. def test_get_bulk_edit_with_version_custom_field
  5837. field =
  5838. IssueCustomField.
  5839. create!(
  5840. :name => 'Affected version',
  5841. :field_format => 'version',
  5842. :is_for_all => true,
  5843. :tracker_ids => [1, 2, 3]
  5844. )
  5845. @request.session[:user_id] = 2
  5846. get(:bulk_edit, :params => {:ids => [1, 2]})
  5847. assert_response :success
  5848. assert_select 'select.version_cf[name=?]', "issue[custom_field_values][#{field.id}]" do
  5849. assert_select 'option', Project.find(1).shared_versions.count + 2 # "no change" + "none" options
  5850. end
  5851. end
  5852. def test_get_bulk_edit_with_multi_custom_field
  5853. field = CustomField.find(1)
  5854. field.update_attribute :multiple, true
  5855. @request.session[:user_id] = 2
  5856. get(:bulk_edit, :params => {:ids => [1, 3]})
  5857. assert_response :success
  5858. assert_select 'select[name=?]', 'issue[custom_field_values][1][]' do
  5859. assert_select 'option', field.possible_values.size + 1 # "none" options
  5860. end
  5861. end
  5862. def test_bulk_edit_should_propose_to_clear_text_custom_fields
  5863. @request.session[:user_id] = 2
  5864. get(:bulk_edit, :params => {:ids => [1, 3]})
  5865. assert_response :success
  5866. assert_select 'input[name=?][value=?]', 'issue[custom_field_values][2]', '__none__'
  5867. end
  5868. def test_bulk_edit_should_only_propose_statuses_allowed_for_all_issues
  5869. WorkflowTransition.delete_all
  5870. WorkflowTransition.create!(:role_id => 1, :tracker_id => 1,
  5871. :old_status_id => 1, :new_status_id => 1)
  5872. WorkflowTransition.create!(:role_id => 1, :tracker_id => 1,
  5873. :old_status_id => 1, :new_status_id => 3)
  5874. WorkflowTransition.create!(:role_id => 1, :tracker_id => 1,
  5875. :old_status_id => 1, :new_status_id => 4)
  5876. WorkflowTransition.create!(:role_id => 1, :tracker_id => 2,
  5877. :old_status_id => 2, :new_status_id => 1)
  5878. WorkflowTransition.create!(:role_id => 1, :tracker_id => 2,
  5879. :old_status_id => 2, :new_status_id => 3)
  5880. WorkflowTransition.create!(:role_id => 1, :tracker_id => 2,
  5881. :old_status_id => 2, :new_status_id => 5)
  5882. @request.session[:user_id] = 2
  5883. get(:bulk_edit, :params => {:ids => [1, 2]})
  5884. assert_select 'select[name=?]', 'issue[status_id]' do
  5885. assert_select 'option[value=""]'
  5886. assert_select 'option[value="1"]'
  5887. assert_select 'option[value="3"]'
  5888. assert_select 'option', 3 # 2 statuses + "no change" option
  5889. end
  5890. end
  5891. def test_bulk_edit_should_propose_target_project_open_shared_versions
  5892. @request.session[:user_id] = 2
  5893. post(
  5894. :bulk_edit,
  5895. :params => {
  5896. :ids => [1, 2, 6],
  5897. :issue => {
  5898. :project_id => 1
  5899. }
  5900. }
  5901. )
  5902. assert_response :success
  5903. expected_versions = Project.find(1).shared_versions.open.to_a.sort
  5904. assert_select 'select[name=?]', 'issue[fixed_version_id]' do
  5905. expected_versions.each do |version|
  5906. assert_select 'option[value=?]', version.id.to_s
  5907. end
  5908. assert_select 'option[value=""]'
  5909. assert_select 'option[value="none"]'
  5910. assert_select 'option', expected_versions.size + 2
  5911. end
  5912. end
  5913. def test_bulk_edit_should_propose_target_project_categories
  5914. @request.session[:user_id] = 2
  5915. post(
  5916. :bulk_edit,
  5917. :params => {
  5918. :ids => [1, 2, 6],
  5919. :issue => {
  5920. :project_id => 1
  5921. }
  5922. }
  5923. )
  5924. assert_response :success
  5925. expected_categories = Project.find(1).issue_categories.sort
  5926. assert_select 'select[name=?]', 'issue[category_id]' do
  5927. expected_categories.each do |category|
  5928. assert_select 'option[value=?]', category.id.to_s
  5929. end
  5930. assert_select 'option[value=""]'
  5931. assert_select 'option[value="none"]'
  5932. assert_select 'option', expected_categories.size + 2
  5933. end
  5934. end
  5935. def test_bulk_edit_should_only_propose_issues_trackers_custom_fields
  5936. IssueCustomField.delete_all
  5937. field1 = IssueCustomField.generate!(:tracker_ids => [1], :is_for_all => true)
  5938. field2 = IssueCustomField.generate!(:tracker_ids => [2], :is_for_all => true)
  5939. @request.session[:user_id] = 2
  5940. issue_ids = Issue.where(:project_id => 1, :tracker_id => 1).limit(2).ids
  5941. get(
  5942. :bulk_edit,
  5943. :params => {
  5944. :ids => issue_ids
  5945. }
  5946. )
  5947. assert_response :success
  5948. assert_select 'input[name=?]', "issue[custom_field_values][#{field1.id}]"
  5949. assert_select 'input[name=?]', "issue[custom_field_values][#{field2.id}]", 0
  5950. end
  5951. def test_bulk_edit_should_propose_target_tracker_custom_fields
  5952. IssueCustomField.delete_all
  5953. field1 = IssueCustomField.generate!(:tracker_ids => [1], :is_for_all => true)
  5954. field2 = IssueCustomField.generate!(:tracker_ids => [2], :is_for_all => true)
  5955. @request.session[:user_id] = 2
  5956. issue_ids = Issue.where(:project_id => 1, :tracker_id => 1).limit(2).ids
  5957. get(
  5958. :bulk_edit,
  5959. :params => {
  5960. :ids => issue_ids,
  5961. :issue => {
  5962. :tracker_id => 2
  5963. }
  5964. }
  5965. )
  5966. assert_response :success
  5967. assert_select 'input[name=?]', "issue[custom_field_values][#{field1.id}]", 0
  5968. assert_select 'input[name=?]', "issue[custom_field_values][#{field2.id}]"
  5969. end
  5970. def test_bulk_edit_should_warn_about_custom_field_values_about_to_be_cleared
  5971. CustomField.destroy_all
  5972. cleared = IssueCustomField.generate!(:name => 'Cleared', :tracker_ids => [2], :is_for_all => true)
  5973. CustomValue.create!(:customized => Issue.find(2), :custom_field => cleared, :value => 'foo')
  5974. not_cleared = IssueCustomField.generate!(:name => 'Not cleared', :tracker_ids => [2, 3], :is_for_all => true)
  5975. CustomValue.create!(:customized => Issue.find(2), :custom_field => not_cleared, :value => 'bar')
  5976. @request.session[:user_id] = 2
  5977. get(
  5978. :bulk_edit,
  5979. :params => {
  5980. :ids => [1, 2],
  5981. :issue => {
  5982. :tracker_id => 3
  5983. }
  5984. }
  5985. )
  5986. assert_response :success
  5987. assert_select '.warning', :text => /automatic deletion of values/
  5988. assert_select '.warning span', :text => 'Cleared (1)'
  5989. assert_select '.warning span', :text => /Not cleared/, :count => 0
  5990. end
  5991. def test_bulk_update
  5992. @request.session[:user_id] = 2
  5993. # update issues priority
  5994. post(
  5995. :bulk_update,
  5996. :params => {
  5997. :ids => [1, 2],
  5998. :notes => 'Bulk editing',
  5999. :issue => {
  6000. :priority_id => 7,
  6001. :assigned_to_id => '',
  6002. :custom_field_values => {
  6003. '2' => ''
  6004. }
  6005. }
  6006. }
  6007. )
  6008. assert_response 302
  6009. # check that the issues were updated
  6010. assert_equal [7, 7], Issue.where(:id =>[1, 2]).collect {|i| i.priority.id}
  6011. issue = Issue.find(1)
  6012. journal = issue.journals.reorder('created_on DESC').first
  6013. assert_equal '125', issue.custom_value_for(2).value
  6014. assert_equal 'Bulk editing', journal.notes
  6015. assert_equal 1, journal.details.size
  6016. end
  6017. def test_bulk_update_with_group_assignee
  6018. group = Group.find(11)
  6019. project = Project.find(1)
  6020. project.members << Member.new(:principal => group, :roles => [Role.givable.first])
  6021. @request.session[:user_id] = 2
  6022. # update issues assignee
  6023. with_settings :issue_group_assignment => '1' do
  6024. post(
  6025. :bulk_update,
  6026. :params => {
  6027. :ids => [1, 2],
  6028. :notes => 'Bulk editing',
  6029. :issue => {
  6030. :priority_id => '',
  6031. :assigned_to_id => group.id,
  6032. :custom_field_values => {
  6033. '2' => ''
  6034. }
  6035. }
  6036. }
  6037. )
  6038. assert_response 302
  6039. assert_equal [group, group], Issue.where(:id => [1, 2]).collect {|i| i.assigned_to}
  6040. end
  6041. end
  6042. def test_bulk_update_on_different_projects
  6043. @request.session[:user_id] = 2
  6044. # update issues priority
  6045. post(
  6046. :bulk_update,
  6047. :params => {
  6048. :ids => [1, 2, 6],
  6049. :notes => 'Bulk editing',
  6050. :issue => {
  6051. :priority_id => 7,
  6052. :assigned_to_id => '',
  6053. :custom_field_values => {
  6054. '2' => ''
  6055. }
  6056. }
  6057. }
  6058. )
  6059. assert_response 302
  6060. # check that the issues were updated
  6061. assert_equal [7, 7, 7], Issue.find([1, 2, 6]).map(&:priority_id)
  6062. issue = Issue.find(1)
  6063. journal = issue.journals.reorder('created_on DESC').first
  6064. assert_equal '125', issue.custom_value_for(2).value
  6065. assert_equal 'Bulk editing', journal.notes
  6066. assert_equal 1, journal.details.size
  6067. end
  6068. def test_bulk_update_on_different_projects_without_rights
  6069. @request.session[:user_id] = 3
  6070. user = User.find(3)
  6071. action = {:controller => "issues", :action => "bulk_update"}
  6072. assert user.allowed_to?(action, Issue.find(1).project)
  6073. assert ! user.allowed_to?(action, Issue.find(6).project)
  6074. post(
  6075. :bulk_update,
  6076. :params => {
  6077. :ids => [1, 6],
  6078. :notes => 'Bulk should fail',
  6079. :issue => {
  6080. :priority_id => 7,
  6081. :assigned_to_id => '',
  6082. :custom_field_values => {
  6083. '2' => ''
  6084. }
  6085. }
  6086. }
  6087. )
  6088. assert_response 403
  6089. assert_not_equal "Bulk should fail", Journal.last.notes
  6090. end
  6091. def test_bulk_update_should_send_a_notification
  6092. @request.session[:user_id] = 2
  6093. ActionMailer::Base.deliveries.clear
  6094. with_settings :notified_events => %w(issue_updated) do
  6095. post(
  6096. :bulk_update,
  6097. :params => {
  6098. :ids => [1, 2],
  6099. :notes => 'Bulk editing',
  6100. :issue => {
  6101. :priority_id => 7,
  6102. :assigned_to_id => '',
  6103. :custom_field_values => {'2' => ''}
  6104. }
  6105. }
  6106. )
  6107. assert_response 302
  6108. # 4 emails for 2 members and 2 issues
  6109. # 1 email for a watcher of issue #2
  6110. assert_equal 5, ActionMailer::Base.deliveries.size
  6111. end
  6112. end
  6113. def test_bulk_update_project
  6114. @request.session[:user_id] = 2
  6115. post(
  6116. :bulk_update,
  6117. :params => {
  6118. :ids => [1, 2],
  6119. :issue => {
  6120. :project_id => '2'
  6121. }
  6122. }
  6123. )
  6124. assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
  6125. # Issues moved to project 2
  6126. assert_equal 2, Issue.find(1).project_id
  6127. assert_equal 2, Issue.find(2).project_id
  6128. # No tracker change
  6129. assert_equal 1, Issue.find(1).tracker_id
  6130. assert_equal 2, Issue.find(2).tracker_id
  6131. end
  6132. def test_bulk_update_project_on_single_issue_should_follow_when_needed
  6133. @request.session[:user_id] = 2
  6134. post(
  6135. :bulk_update,
  6136. :params => {
  6137. :id => 1,
  6138. :issue => {
  6139. :project_id => '2'
  6140. },
  6141. :follow => '1'
  6142. }
  6143. )
  6144. assert_redirected_to '/issues/1'
  6145. end
  6146. def test_bulk_update_project_on_multiple_issues_should_follow_when_needed
  6147. @request.session[:user_id] = 2
  6148. post(
  6149. :bulk_update,
  6150. :params => {
  6151. :id => [1, 2],
  6152. :issue => {
  6153. :project_id => '2'
  6154. },
  6155. :follow => '1'
  6156. }
  6157. )
  6158. assert_redirected_to '/projects/onlinestore/issues'
  6159. end
  6160. def test_bulk_update_tracker
  6161. @request.session[:user_id] = 2
  6162. post(
  6163. :bulk_update, :params => {
  6164. :ids => [1, 2],
  6165. :issue => {
  6166. :tracker_id => '2'
  6167. }
  6168. }
  6169. )
  6170. assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
  6171. assert_equal 2, Issue.find(1).tracker_id
  6172. assert_equal 2, Issue.find(2).tracker_id
  6173. end
  6174. def test_bulk_update_status
  6175. @request.session[:user_id] = 2
  6176. # update issues priority
  6177. post(
  6178. :bulk_update,
  6179. :params => {
  6180. :ids => [1, 2],
  6181. :notes => 'Bulk editing status',
  6182. :issue => {
  6183. :priority_id => '',
  6184. :assigned_to_id => '',
  6185. :status_id => '5'
  6186. }
  6187. }
  6188. )
  6189. assert_response 302
  6190. issue = Issue.find(1)
  6191. assert issue.closed?
  6192. end
  6193. def test_bulk_update_priority
  6194. @request.session[:user_id] = 2
  6195. post(
  6196. :bulk_update,
  6197. :params => {
  6198. :ids => [1, 2],
  6199. :issue => {
  6200. :priority_id => 6
  6201. }
  6202. }
  6203. )
  6204. assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
  6205. assert_equal 6, Issue.find(1).priority_id
  6206. assert_equal 6, Issue.find(2).priority_id
  6207. end
  6208. def test_bulk_update_with_notes
  6209. @request.session[:user_id] = 2
  6210. post(
  6211. :bulk_update,
  6212. :params => {
  6213. :ids => [1, 2],
  6214. :notes => 'Moving two issues'
  6215. }
  6216. )
  6217. assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
  6218. assert_equal 'Moving two issues', Issue.find(1).journals.sort_by(&:id).last.notes
  6219. assert_equal 'Moving two issues', Issue.find(2).journals.sort_by(&:id).last.notes
  6220. assert_equal false, Issue.find(1).journals.sort_by(&:id).last.private_notes
  6221. assert_equal false, Issue.find(2).journals.sort_by(&:id).last.private_notes
  6222. end
  6223. def test_bulk_update_with_private_notes
  6224. @request.session[:user_id] = 2
  6225. post(
  6226. :bulk_update,
  6227. :params => {
  6228. :ids => [1, 2],
  6229. :notes => 'Moving two issues',
  6230. :issue => {:private_notes => 'true'}
  6231. }
  6232. )
  6233. assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
  6234. assert_equal 'Moving two issues', Issue.find(1).journals.sort_by(&:id).last.notes
  6235. assert_equal 'Moving two issues', Issue.find(2).journals.sort_by(&:id).last.notes
  6236. assert_equal true, Issue.find(1).journals.sort_by(&:id).last.private_notes
  6237. assert_equal true, Issue.find(2).journals.sort_by(&:id).last.private_notes
  6238. end
  6239. def test_bulk_update_parent_id
  6240. IssueRelation.delete_all
  6241. @request.session[:user_id] = 2
  6242. post(
  6243. :bulk_update,
  6244. :params => {
  6245. :ids => [1, 3],
  6246. :notes => 'Bulk editing parent',
  6247. :issue => {
  6248. :priority_id => '',
  6249. :assigned_to_id => '',
  6250. :status_id => '',
  6251. :parent_issue_id => '2'
  6252. }
  6253. }
  6254. )
  6255. assert_response 302
  6256. parent = Issue.find(2)
  6257. assert_equal parent.id, Issue.find(1).parent_id
  6258. assert_equal parent.id, Issue.find(3).parent_id
  6259. assert_equal [1, 3], parent.children.collect(&:id).sort
  6260. end
  6261. def test_bulk_update_estimated_hours
  6262. @request.session[:user_id] = 2
  6263. post(
  6264. :bulk_update,
  6265. :params => {
  6266. :ids => [1, 2],
  6267. :issue => {
  6268. :estimated_hours => 4.25
  6269. }
  6270. }
  6271. )
  6272. assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
  6273. assert_equal 4.25, Issue.find(1).estimated_hours
  6274. assert_equal 4.25, Issue.find(2).estimated_hours
  6275. end
  6276. def test_bulk_update_custom_field
  6277. @request.session[:user_id] = 2
  6278. # update issues priority
  6279. post(
  6280. :bulk_update,
  6281. :params => {
  6282. :ids => [1, 2],
  6283. :notes => 'Bulk editing custom field',
  6284. :issue => {
  6285. :priority_id => '',
  6286. :assigned_to_id => '',
  6287. :custom_field_values => {
  6288. '2' => '777'
  6289. }
  6290. }
  6291. }
  6292. )
  6293. assert_response 302
  6294. issue = Issue.find(1)
  6295. journal = issue.journals.reorder('created_on DESC').first
  6296. assert_equal '777', issue.custom_value_for(2).value
  6297. assert_equal 1, journal.details.size
  6298. assert_equal '125', journal.details.first.old_value
  6299. assert_equal '777', journal.details.first.value
  6300. end
  6301. def test_bulk_update_custom_field_to_blank
  6302. @request.session[:user_id] = 2
  6303. post(
  6304. :bulk_update,
  6305. :params => {
  6306. :ids => [1, 3],
  6307. :notes => 'Bulk editing custom field',
  6308. :issue => {
  6309. :priority_id => '',
  6310. :assigned_to_id => '',
  6311. :custom_field_values => {
  6312. '1' => '__none__'
  6313. }
  6314. }
  6315. }
  6316. )
  6317. assert_response 302
  6318. assert_equal '', Issue.find(1).custom_field_value(1)
  6319. assert_equal '', Issue.find(3).custom_field_value(1)
  6320. end
  6321. def test_bulk_update_multi_custom_field
  6322. field = CustomField.find(1)
  6323. field.update_attribute :multiple, true
  6324. @request.session[:user_id] = 2
  6325. post(
  6326. :bulk_update,
  6327. :params => {
  6328. :ids => [1, 2, 3],
  6329. :notes => 'Bulk editing multi custom field',
  6330. :issue => {
  6331. :priority_id => '',
  6332. :assigned_to_id => '',
  6333. :custom_field_values => {
  6334. '1' => ['MySQL', 'Oracle']
  6335. }
  6336. }
  6337. }
  6338. )
  6339. assert_response 302
  6340. assert_equal ['MySQL', 'Oracle'], Issue.find(1).custom_field_value(1).sort
  6341. assert_equal ['MySQL', 'Oracle'], Issue.find(3).custom_field_value(1).sort
  6342. # the custom field is not associated with the issue tracker
  6343. assert_nil Issue.find(2).custom_field_value(1)
  6344. end
  6345. def test_bulk_update_multi_custom_field_to_blank
  6346. field = CustomField.find(1)
  6347. field.update_attribute :multiple, true
  6348. @request.session[:user_id] = 2
  6349. post(
  6350. :bulk_update,
  6351. :params => {
  6352. :ids => [1, 3],
  6353. :notes => 'Bulk editing multi custom field',
  6354. :issue => {
  6355. :priority_id => '',
  6356. :assigned_to_id => '',
  6357. :custom_field_values => {
  6358. '1' => ['__none__']
  6359. }
  6360. }
  6361. }
  6362. )
  6363. assert_response 302
  6364. assert_equal [''], Issue.find(1).custom_field_value(1)
  6365. assert_equal [''], Issue.find(3).custom_field_value(1)
  6366. end
  6367. def test_bulk_update_unassign
  6368. assert_not_nil Issue.find(2).assigned_to
  6369. @request.session[:user_id] = 2
  6370. # unassign issues
  6371. post(
  6372. :bulk_update,
  6373. :params => {
  6374. :ids => [1, 2],
  6375. :notes => 'Bulk unassigning',
  6376. :issue => {
  6377. :assigned_to_id => 'none'
  6378. }
  6379. }
  6380. )
  6381. assert_response 302
  6382. # check that the issues were updated
  6383. assert_nil Issue.find(2).assigned_to
  6384. end
  6385. def test_post_bulk_update_should_allow_fixed_version_to_be_set_to_a_subproject
  6386. @request.session[:user_id] = 2
  6387. post(
  6388. :bulk_update,
  6389. :params => {
  6390. :ids => [1, 2],
  6391. :issue => {
  6392. :fixed_version_id => 4
  6393. }
  6394. }
  6395. )
  6396. assert_response :redirect
  6397. issues = Issue.find([1, 2])
  6398. issues.each do |issue|
  6399. assert_equal 4, issue.fixed_version_id
  6400. assert_not_equal issue.project_id, issue.fixed_version.project_id
  6401. end
  6402. end
  6403. def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter
  6404. @request.session[:user_id] = 2
  6405. post(
  6406. :bulk_update,
  6407. :params => {
  6408. :ids => [1, 2],
  6409. :back_url => '/issues'
  6410. }
  6411. )
  6412. assert_response :redirect
  6413. assert_redirected_to '/issues'
  6414. end
  6415. def test_post_bulk_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
  6416. @request.session[:user_id] = 2
  6417. post(
  6418. :bulk_update,
  6419. :params => {
  6420. :ids => [1, 2],
  6421. :back_url => 'http://google.com'
  6422. }
  6423. )
  6424. assert_response :redirect
  6425. assert_redirected_to(
  6426. :controller => 'issues', :action => 'index',
  6427. :project_id => Project.find(1).identifier
  6428. )
  6429. end
  6430. def test_bulk_update_with_all_failures_should_show_errors
  6431. @request.session[:user_id] = 2
  6432. post(
  6433. :bulk_update,
  6434. :params => {
  6435. :ids => [1, 2],
  6436. :issue => {
  6437. :start_date => 'foo'
  6438. }
  6439. }
  6440. )
  6441. assert_response :success
  6442. assert_select '#errorExplanation span', :text => 'Failed to save 2 issue(s) on 2 selected: #1, #2.'
  6443. assert_select '#errorExplanation ul li', :text => 'Start date is not a valid date: #1, #2'
  6444. end
  6445. def test_bulk_update_with_some_failures_should_show_errors
  6446. issue1 = Issue.generate!(:start_date => '2013-05-12')
  6447. issue2 = Issue.generate!(:start_date => '2013-05-15')
  6448. issue3 = Issue.generate!
  6449. @request.session[:user_id] = 2
  6450. post(
  6451. :bulk_update,
  6452. :params => {
  6453. :ids => [issue1.id, issue2.id, issue3.id],
  6454. :issue => {
  6455. :due_date => '2013-05-01'
  6456. }
  6457. }
  6458. )
  6459. assert_response :success
  6460. assert_select '#errorExplanation span',
  6461. :text => "Failed to save 2 issue(s) on 3 selected: ##{issue1.id}, ##{issue2.id}."
  6462. assert_select '#errorExplanation ul li',
  6463. :text => "Due date must be greater than start date: ##{issue1.id}, ##{issue2.id}"
  6464. assert_select '#bulk-selection li', 2
  6465. end
  6466. def test_bulk_update_with_failure_should_preserved_form_values
  6467. @request.session[:user_id] = 2
  6468. post(
  6469. :bulk_update,
  6470. :params => {
  6471. :ids => [1, 2],
  6472. :issue => {
  6473. :tracker_id => '2',
  6474. :start_date => 'foo'
  6475. }
  6476. }
  6477. )
  6478. assert_response :success
  6479. assert_select 'select[name=?]', 'issue[tracker_id]' do
  6480. assert_select 'option[value="2"][selected=selected]'
  6481. end
  6482. assert_select 'input[name=?][value=?]', 'issue[start_date]', 'foo'
  6483. end
  6484. def test_get_bulk_copy
  6485. @request.session[:user_id] = 2
  6486. get(
  6487. :bulk_edit,
  6488. :params => {
  6489. :ids => [1, 2, 3],
  6490. :copy => '1'
  6491. }
  6492. )
  6493. assert_response :success
  6494. assert_select '#bulk-selection li', 3
  6495. assert_select 'select[name=?]', 'issue[project_id]' do
  6496. assert_select 'option[value=""]'
  6497. end
  6498. assert_select 'input[name=copy_attachments]'
  6499. end
  6500. def test_get_bulk_copy_without_add_issues_permission_should_not_propose_current_project_as_target
  6501. user = setup_user_with_copy_but_not_add_permission
  6502. @request.session[:user_id] = user.id
  6503. get(
  6504. :bulk_edit,
  6505. :params => {
  6506. :ids => [1, 2, 3],
  6507. :copy => '1'
  6508. }
  6509. )
  6510. assert_response :success
  6511. assert_select 'select[name=?]', 'issue[project_id]' do
  6512. assert_select 'option[value=""]', 0
  6513. assert_select 'option[value="2"]'
  6514. end
  6515. end
  6516. def test_bulk_copy_to_another_project
  6517. @request.session[:user_id] = 2
  6518. issue_ids = [1, 2]
  6519. assert_difference 'Issue.count', issue_ids.size do
  6520. assert_no_difference 'Project.find(1).issues.count' do
  6521. post(
  6522. :bulk_update,
  6523. :params => {
  6524. :ids => issue_ids,
  6525. :issue => {
  6526. :project_id => '2'
  6527. },
  6528. :copy => '1'
  6529. }
  6530. )
  6531. end
  6532. end
  6533. assert_redirected_to '/projects/ecookbook/issues'
  6534. copies = Issue.order('id DESC').limit(issue_ids.size)
  6535. copies.each do |copy|
  6536. assert_equal 2, copy.project_id
  6537. end
  6538. end
  6539. def test_bulk_copy_without_add_issues_permission_should_be_allowed_on_project_with_permission
  6540. user = setup_user_with_copy_but_not_add_permission
  6541. @request.session[:user_id] = user.id
  6542. assert_difference 'Issue.count', 3 do
  6543. post(
  6544. :bulk_update,
  6545. :params => {
  6546. :ids => [1, 2, 3],
  6547. :issue => {
  6548. :project_id => '2'
  6549. },
  6550. :copy => '1'
  6551. }
  6552. )
  6553. assert_response 302
  6554. end
  6555. end
  6556. def test_bulk_copy_on_same_project_without_add_issues_permission_should_be_denied
  6557. user = setup_user_with_copy_but_not_add_permission
  6558. @request.session[:user_id] = user.id
  6559. post(
  6560. :bulk_update,
  6561. :params => {
  6562. :ids => [1, 2, 3],
  6563. :issue => {
  6564. :project_id => ''
  6565. },
  6566. :copy => '1'
  6567. }
  6568. )
  6569. assert_response 403
  6570. end
  6571. def test_bulk_copy_on_different_project_without_add_issues_permission_should_be_denied
  6572. user = setup_user_with_copy_but_not_add_permission
  6573. @request.session[:user_id] = user.id
  6574. post(
  6575. :bulk_update,
  6576. :params => {
  6577. :ids => [1, 2, 3],
  6578. :issue => {
  6579. :project_id => '1'
  6580. },
  6581. :copy => '1'
  6582. }
  6583. )
  6584. assert_response 403
  6585. end
  6586. def test_bulk_copy_should_allow_not_changing_the_issue_attributes
  6587. @request.session[:user_id] = 2
  6588. issues = [
  6589. Issue.create!(:project_id => 1, :tracker_id => 1, :status_id => 1,
  6590. :priority_id => 2, :subject => 'issue 1', :author_id => 1,
  6591. :assigned_to_id => nil),
  6592. Issue.create!(:project_id => 2, :tracker_id => 3, :status_id => 2,
  6593. :priority_id => 1, :subject => 'issue 2', :author_id => 2,
  6594. :assigned_to_id => 2)
  6595. ]
  6596. assert_difference 'Issue.count', issues.size do
  6597. post(
  6598. :bulk_update,
  6599. :params => {
  6600. :ids => issues.map(&:id),
  6601. :copy => '1',
  6602. :issue => {
  6603. :project_id => '',
  6604. :tracker_id => '',
  6605. :assigned_to_id => '',
  6606. :status_id => '',
  6607. :start_date => '',
  6608. :due_date => ''
  6609. }
  6610. }
  6611. )
  6612. end
  6613. copies = Issue.order('id DESC').limit(issues.size)
  6614. issues.each do |orig|
  6615. copy = copies.detect {|c| c.subject == orig.subject}
  6616. assert_not_nil copy
  6617. assert_equal orig.project_id, copy.project_id
  6618. assert_equal orig.tracker_id, copy.tracker_id
  6619. assert_equal 1, copy.status_id
  6620. if orig.assigned_to_id
  6621. assert_equal orig.assigned_to_id, copy.assigned_to_id
  6622. else
  6623. assert_nil copy.assigned_to_id
  6624. end
  6625. assert_equal orig.priority_id, copy.priority_id
  6626. end
  6627. end
  6628. def test_bulk_copy_should_allow_changing_the_issue_attributes
  6629. # Fixes random test failure with Mysql
  6630. # where Issue.where(:project_id => 2).limit(2).order('id desc')
  6631. # doesn't return the expected results
  6632. Issue.where("project_id=2").delete_all
  6633. @request.session[:user_id] = 2
  6634. assert_difference 'Issue.count', 2 do
  6635. assert_no_difference 'Project.find(1).issues.count' do
  6636. post(
  6637. :bulk_update,
  6638. :params => {
  6639. :ids => [1, 2],
  6640. :copy => '1',
  6641. :issue => {
  6642. :project_id => '2',
  6643. :tracker_id => '',
  6644. :assigned_to_id => '2',
  6645. :status_id => '1',
  6646. :start_date => '2009-12-01',
  6647. :due_date => '2009-12-31'
  6648. }
  6649. }
  6650. )
  6651. end
  6652. end
  6653. copied_issues = Issue.where(:project_id => 2).limit(2).order('id desc').to_a
  6654. assert_equal 2, copied_issues.size
  6655. copied_issues.each do |issue|
  6656. assert_equal 2, issue.project_id, "Project is incorrect"
  6657. assert_equal 2, issue.assigned_to_id, "Assigned to is incorrect"
  6658. assert_equal 1, issue.status_id, "Status is incorrect"
  6659. assert_equal '2009-12-01', issue.start_date.to_s, "Start date is incorrect"
  6660. assert_equal '2009-12-31', issue.due_date.to_s, "Due date is incorrect"
  6661. end
  6662. end
  6663. def test_bulk_copy_should_allow_adding_a_note
  6664. @request.session[:user_id] = 2
  6665. assert_difference 'Issue.count', 1 do
  6666. post(
  6667. :bulk_update,
  6668. :params => {
  6669. :ids => [1],
  6670. :copy => '1',
  6671. :notes => 'Copying one issue',
  6672. :issue => {
  6673. :project_id => '',
  6674. :tracker_id => '',
  6675. :status_id => '3',
  6676. :start_date => '2009-12-01',
  6677. :due_date => '2009-12-31'
  6678. }
  6679. }
  6680. )
  6681. end
  6682. issue = Issue.order('id DESC').first
  6683. assert_equal 1, issue.journals.size
  6684. journal = issue.journals.first
  6685. assert_equal 'Copying one issue', journal.notes
  6686. end
  6687. def test_bulk_copy_should_allow_not_copying_the_attachments
  6688. attachment_count = Issue.find(3).attachments.size
  6689. assert attachment_count > 0
  6690. @request.session[:user_id] = 2
  6691. assert_difference 'Issue.count', 1 do
  6692. assert_no_difference 'Attachment.count' do
  6693. post(
  6694. :bulk_update,
  6695. :params => {
  6696. :ids => [3],
  6697. :copy => '1',
  6698. :copy_attachments => '0',
  6699. :issue => {
  6700. :project_id => ''
  6701. }
  6702. }
  6703. )
  6704. end
  6705. end
  6706. end
  6707. def test_bulk_copy_should_allow_copying_the_attachments
  6708. attachment_count = Issue.find(3).attachments.size
  6709. assert attachment_count > 0
  6710. @request.session[:user_id] = 2
  6711. assert_difference 'Issue.count', 1 do
  6712. assert_difference 'Attachment.count', attachment_count do
  6713. post(
  6714. :bulk_update,
  6715. :params => {
  6716. :ids => [3],
  6717. :copy => '1',
  6718. :copy_attachments => '1',
  6719. :issue => {
  6720. :project_id => ''
  6721. }
  6722. }
  6723. )
  6724. end
  6725. end
  6726. end
  6727. def test_bulk_copy_should_add_relations_with_copied_issues
  6728. @request.session[:user_id] = 2
  6729. assert_difference 'Issue.count', 2 do
  6730. assert_difference 'IssueRelation.count', 2 do
  6731. post(
  6732. :bulk_update,
  6733. :params => {
  6734. :ids => [1, 3],
  6735. :copy => '1',
  6736. :link_copy => '1',
  6737. :issue => {
  6738. :project_id => '1'
  6739. }
  6740. }
  6741. )
  6742. end
  6743. end
  6744. end
  6745. def test_bulk_copy_should_allow_not_copying_the_subtasks
  6746. issue = Issue.generate_with_descendants!
  6747. @request.session[:user_id] = 2
  6748. assert_difference 'Issue.count', 1 do
  6749. post(
  6750. :bulk_update,
  6751. :params => {
  6752. :ids => [issue.id],
  6753. :copy => '1',
  6754. :copy_subtasks => '0',
  6755. :issue => {
  6756. :project_id => ''
  6757. }
  6758. }
  6759. )
  6760. end
  6761. end
  6762. test "bulk copy should allow copying the subtasks" do
  6763. issue = Issue.generate_with_descendants!
  6764. count = issue.descendants.count
  6765. @request.session[:user_id] = 2
  6766. assert_difference 'Issue.count', count+1 do
  6767. post(
  6768. :bulk_update,
  6769. :params => {
  6770. :ids => [issue.id],
  6771. :copy => '1',
  6772. :copy_subtasks => '1',
  6773. :issue => {
  6774. :project_id => ''
  6775. }
  6776. }
  6777. )
  6778. end
  6779. copy = Issue.where(:parent_id => nil).order("id DESC").first
  6780. assert_equal count, copy.descendants.count
  6781. end
  6782. test "issue bulk copy copy watcher" do
  6783. issue = Issue.find(1)
  6784. Watcher.create!(:watchable => issue, :user => User.find(3))
  6785. Watcher.create!(:watchable => issue, :user => Group.find(10))
  6786. @request.session[:user_id] = 2
  6787. assert_difference 'Issue.count' do
  6788. post(
  6789. :bulk_update,
  6790. :params => {
  6791. :ids => [1],
  6792. :copy => '1',
  6793. :copy_watchers => '1',
  6794. :issue => {
  6795. :project_id => ''
  6796. }
  6797. }
  6798. )
  6799. end
  6800. copy = Issue.order(:id => :desc).first
  6801. assert_equal 2, copy.watchers.count
  6802. assert_equal [3, 10], copy.watcher_user_ids
  6803. end
  6804. def test_bulk_copy_should_not_copy_selected_subtasks_twice
  6805. issue = Issue.generate_with_descendants!
  6806. count = issue.descendants.count
  6807. @request.session[:user_id] = 2
  6808. assert_difference 'Issue.count', count+1 do
  6809. post(
  6810. :bulk_update,
  6811. :params => {
  6812. :ids => issue.self_and_descendants.map(&:id),
  6813. :copy => '1',
  6814. :copy_subtasks => '1',
  6815. :issue => {
  6816. :project_id => ''
  6817. }
  6818. }
  6819. )
  6820. end
  6821. copy = Issue.where(:parent_id => nil).order("id DESC").first
  6822. assert_equal count, copy.descendants.count
  6823. end
  6824. def test_bulk_copy_to_another_project_should_follow_when_needed
  6825. @request.session[:user_id] = 2
  6826. post(
  6827. :bulk_update,
  6828. :params => {
  6829. :ids => [1],
  6830. :copy => '1',
  6831. :issue => {
  6832. :project_id => 2
  6833. },
  6834. :follow => '1'
  6835. }
  6836. )
  6837. issue = Issue.order('id DESC').first
  6838. assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
  6839. end
  6840. def test_bulk_copy_with_all_failures_should_display_errors
  6841. @request.session[:user_id] = 2
  6842. post(
  6843. :bulk_update,
  6844. :params => {
  6845. :ids => [1, 2],
  6846. :copy => '1',
  6847. :issue => {
  6848. :start_date => 'foo'
  6849. }
  6850. }
  6851. )
  6852. assert_response :success
  6853. end
  6854. def test_destroy_issue_with_no_time_entries_should_delete_the_issues
  6855. set_tmp_attachments_directory
  6856. assert_nil TimeEntry.find_by_issue_id(2)
  6857. @request.session[:user_id] = 2
  6858. assert_difference 'Issue.count', -1 do
  6859. delete(:destroy, :params => {:id => 2})
  6860. end
  6861. assert_redirected_to :action => 'index', :project_id => 'ecookbook'
  6862. assert_nil Issue.find_by_id(2)
  6863. end
  6864. def test_destroy_issues_with_time_entries_should_show_the_reassign_form
  6865. set_tmp_attachments_directory
  6866. @request.session[:user_id] = 2
  6867. with_settings :timelog_required_fields => [] do
  6868. assert_no_difference 'Issue.count' do
  6869. delete(
  6870. :destroy,
  6871. :params => {
  6872. :ids => [1, 3]
  6873. }
  6874. )
  6875. end
  6876. end
  6877. assert_response :success
  6878. assert_select 'form' do
  6879. assert_select 'input[name=_method][value=delete]'
  6880. assert_select 'input[name=todo][value=destroy]'
  6881. assert_select 'input[name=todo][value=nullify]'
  6882. assert_select 'input[name=todo][value=reassign]'
  6883. end
  6884. end
  6885. def test_destroy_issues_with_time_entries_should_not_show_the_nullify_option_when_issue_is_required_for_time_entries
  6886. set_tmp_attachments_directory
  6887. with_settings :timelog_required_fields => ['issue_id'] do
  6888. @request.session[:user_id] = 2
  6889. assert_no_difference 'Issue.count' do
  6890. delete(
  6891. :destroy,
  6892. :params => {
  6893. :ids => [1, 3]
  6894. }
  6895. )
  6896. end
  6897. assert_response :success
  6898. assert_select 'form' do
  6899. assert_select 'input[name=_method][value=delete]'
  6900. assert_select 'input[name=todo][value=destroy]'
  6901. assert_select 'input[name=todo][value=nullify]', 0
  6902. assert_select 'input[name=todo][value=reassign]'
  6903. end
  6904. end
  6905. end
  6906. def test_destroy_issues_with_time_entries_should_show_hours_on_issues_and_descendants
  6907. parent = Issue.generate_with_child!
  6908. TimeEntry.generate!(:issue => parent)
  6909. TimeEntry.generate!(:issue => parent.children.first)
  6910. leaf = Issue.generate!
  6911. TimeEntry.generate!(:issue => leaf)
  6912. @request.session[:user_id] = 2
  6913. delete(
  6914. :destroy,
  6915. :params => {
  6916. :ids => [parent.id, leaf.id]
  6917. }
  6918. )
  6919. assert_response :success
  6920. assert_select 'p', :text => /3\.00 hours were reported/
  6921. end
  6922. def test_destroy_issues_and_destroy_time_entries
  6923. set_tmp_attachments_directory
  6924. @request.session[:user_id] = 2
  6925. assert_difference 'Issue.count', -2 do
  6926. assert_difference 'TimeEntry.count', -3 do
  6927. delete(
  6928. :destroy,
  6929. :params => {
  6930. :ids => [1, 3],
  6931. :todo => 'destroy'
  6932. }
  6933. )
  6934. end
  6935. end
  6936. assert_redirected_to :action => 'index', :project_id => 'ecookbook'
  6937. assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
  6938. assert_nil TimeEntry.find_by_id([1, 2])
  6939. end
  6940. def test_destroy_issues_and_assign_time_entries_to_project
  6941. set_tmp_attachments_directory
  6942. @request.session[:user_id] = 2
  6943. with_settings :timelog_required_fields => [] do
  6944. assert_difference 'Issue.count', -2 do
  6945. assert_no_difference 'TimeEntry.count' do
  6946. delete(
  6947. :destroy,
  6948. :params => {
  6949. :ids => [1, 3],
  6950. :todo => 'nullify'
  6951. }
  6952. )
  6953. end
  6954. end
  6955. end
  6956. assert_redirected_to :action => 'index', :project_id => 'ecookbook'
  6957. assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
  6958. assert_nil TimeEntry.find(1).issue_id
  6959. assert_nil TimeEntry.find(2).issue_id
  6960. end
  6961. def test_destroy_issues_and_reassign_time_entries_to_another_issue
  6962. set_tmp_attachments_directory
  6963. @request.session[:user_id] = 2
  6964. assert_difference 'Issue.count', -2 do
  6965. assert_no_difference 'TimeEntry.count' do
  6966. delete(
  6967. :destroy,
  6968. :params => {
  6969. :ids => [1, 3],
  6970. :todo => 'reassign',
  6971. :reassign_to_id => 2
  6972. }
  6973. )
  6974. end
  6975. end
  6976. assert_redirected_to :action => 'index', :project_id => 'ecookbook'
  6977. assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
  6978. assert_equal 2, TimeEntry.find(1).issue_id
  6979. assert_equal 2, TimeEntry.find(2).issue_id
  6980. end
  6981. def test_destroy_issues_with_time_entries_should_reassign_time_entries_of_issues_and_descendants
  6982. parent = Issue.generate_with_child!
  6983. TimeEntry.generate!(:issue => parent)
  6984. TimeEntry.generate!(:issue => parent.children.first)
  6985. leaf = Issue.generate!
  6986. TimeEntry.generate!(:issue => leaf)
  6987. target = Issue.generate!
  6988. @request.session[:user_id] = 2
  6989. assert_difference 'Issue.count', -3 do
  6990. assert_no_difference 'TimeEntry.count' do
  6991. delete(
  6992. :destroy,
  6993. :params => {
  6994. :ids => [parent.id, leaf.id],
  6995. :todo => 'reassign',
  6996. :reassign_to_id => target.id
  6997. }
  6998. )
  6999. assert_response 302
  7000. end
  7001. end
  7002. assert_equal 3, target.time_entries.count
  7003. end
  7004. def test_destroy_issues_and_reassign_time_entries_to_an_invalid_issue_should_fail
  7005. set_tmp_attachments_directory
  7006. @request.session[:user_id] = 2
  7007. assert_no_difference 'Issue.count' do
  7008. assert_no_difference 'TimeEntry.count' do
  7009. # try to reassign time to an issue of another project
  7010. delete(
  7011. :destroy,
  7012. :params => {
  7013. :ids => [1, 3],
  7014. :todo => 'reassign',
  7015. :reassign_to_id => 4
  7016. }
  7017. )
  7018. end
  7019. end
  7020. assert_response :success
  7021. end
  7022. def test_destroy_issues_and_reassign_time_entries_to_an_issue_to_delete_should_fail
  7023. set_tmp_attachments_directory
  7024. @request.session[:user_id] = 2
  7025. assert_no_difference 'Issue.count' do
  7026. assert_no_difference 'TimeEntry.count' do
  7027. delete(
  7028. :destroy,
  7029. :params => {
  7030. :ids => [1, 3],
  7031. :todo => 'reassign',
  7032. :reassign_to_id => 3
  7033. }
  7034. )
  7035. end
  7036. end
  7037. assert_response :success
  7038. assert_select '#flash_error', :text => I18n.t(:error_cannot_reassign_time_entries_to_an_issue_about_to_be_deleted)
  7039. end
  7040. def test_destroy_issues_and_nullify_time_entries_should_fail_when_issue_is_required_for_time_entries
  7041. set_tmp_attachments_directory
  7042. @request.session[:user_id] = 2
  7043. with_settings :timelog_required_fields => ['issue_id'] do
  7044. assert_no_difference 'Issue.count' do
  7045. assert_no_difference 'TimeEntry.count' do
  7046. delete(
  7047. :destroy,
  7048. :params => {
  7049. :ids => [1, 3],
  7050. :todo => 'nullify'
  7051. }
  7052. )
  7053. end
  7054. end
  7055. end
  7056. assert_response :success
  7057. assert_select '#flash_error', :text => 'Issue cannot be blank'
  7058. end
  7059. def test_destroy_issues_from_different_projects
  7060. set_tmp_attachments_directory
  7061. @request.session[:user_id] = 2
  7062. assert_difference 'Issue.count', -3 do
  7063. delete(
  7064. :destroy,
  7065. :params => {
  7066. :ids => [1, 2, 6],
  7067. :todo => 'destroy'
  7068. }
  7069. )
  7070. end
  7071. assert_redirected_to :controller => 'issues', :action => 'index'
  7072. assert !(Issue.find_by_id(1) || Issue.find_by_id(2) || Issue.find_by_id(6))
  7073. end
  7074. def test_destroy_parent_and_child_issues
  7075. parent = Issue.create!(:project_id => 1, :author_id => 1,
  7076. :tracker_id => 1, :subject => 'Parent Issue')
  7077. child = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1,
  7078. :subject => 'Child Issue', :parent_issue_id => parent.id)
  7079. assert child.is_descendant_of?(parent.reload)
  7080. @request.session[:user_id] = 2
  7081. assert_difference 'Issue.count', -2 do
  7082. delete(
  7083. :destroy,
  7084. :params => {
  7085. :ids => [parent.id, child.id],
  7086. :todo => 'destroy'
  7087. }
  7088. )
  7089. end
  7090. assert_response 302
  7091. end
  7092. def test_destroy_invalid_should_respond_with_404
  7093. @request.session[:user_id] = 2
  7094. assert_no_difference 'Issue.count' do
  7095. delete(:destroy, :params => {:id => 999})
  7096. end
  7097. assert_response 404
  7098. end
  7099. def test_destroy_with_permission_on_tracker_should_be_allowed
  7100. role = Role.find(1)
  7101. role.set_permission_trackers :delete_issues, [1]
  7102. role.save!
  7103. issue = Issue.generate!(:project_id => 1, :tracker_id => 1)
  7104. @request.session[:user_id] = 2
  7105. assert_difference 'Issue.count', -1 do
  7106. delete(:destroy, :params => {:id => issue.id})
  7107. end
  7108. assert_response 302
  7109. end
  7110. def test_destroy_without_permission_on_tracker_should_be_denied
  7111. role = Role.find(1)
  7112. role.set_permission_trackers :delete_issues, [2]
  7113. role.save!
  7114. issue = Issue.generate!(:project_id => 1, :tracker_id => 1)
  7115. @request.session[:user_id] = 2
  7116. assert_no_difference 'Issue.count' do
  7117. delete(:destroy, :params => {:id => issue.id})
  7118. end
  7119. assert_response 403
  7120. end
  7121. def test_default_search_scope
  7122. get :index
  7123. assert_select 'div#quick-search form' do
  7124. assert_select 'input[name=issues][value="1"][type=hidden]'
  7125. end
  7126. end
  7127. def setup_user_with_copy_but_not_add_permission
  7128. Role.all.each {|r| r.remove_permission! :add_issues}
  7129. Role.find_by_name('Manager').add_permission! :add_issues
  7130. user = User.generate!
  7131. User.add_to_project(user, Project.find(1), Role.find_by_name('Developer'))
  7132. User.add_to_project(user, Project.find(2), Role.find_by_name('Manager'))
  7133. user
  7134. end
  7135. def test_cancel_edit_link_for_issue_show_action_should_have_onclick_action
  7136. @request.session[:user_id] = 1
  7137. get(:show, :params => {:id => 1})
  7138. assert_response :success
  7139. assert_select 'a[href=?][onclick=?]', "/issues/1", "$('#update').hide(); return false;", :text => 'Cancel'
  7140. end
  7141. def test_cancel_edit_link_for_issue_edit_action_should_not_have_onclick_action
  7142. @request.session[:user_id] = 1
  7143. get(:edit, :params => {:id => 1})
  7144. assert_response :success
  7145. assert_select 'a[href=?][onclick=?]', "/issues/1", "", :text => 'Cancel'
  7146. end
  7147. def test_show_should_display_author_gravatar_only_when_not_assigned
  7148. issue = Issue.find(1)
  7149. assert_nil issue.assigned_to_id
  7150. @request.session[:user_id] = 1
  7151. with_settings :gravatar_enabled => '1' do
  7152. get :show, :params => {:id => issue.id}
  7153. assert_select 'div.gravatar-with-child' do
  7154. assert_select 'img.gravatar', 1
  7155. end
  7156. end
  7157. end
  7158. def test_show_should_display_author_and_assignee_gravatars_when_assigned
  7159. issue = Issue.find(1)
  7160. issue.assigned_to_id = 2
  7161. issue.save!
  7162. @request.session[:user_id] = 1
  7163. with_settings :gravatar_enabled => '1' do
  7164. get :show, :params => {:id => issue.id}
  7165. assert_select 'div.gravatar-with-child' do
  7166. assert_select 'img.gravatar', 2
  7167. assert_select 'img.gravatar-child', 1
  7168. end
  7169. end
  7170. end
  7171. end