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

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