You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

issues_controller_test.rb 255KB

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