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 249KB

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