csv_import_magic 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (327) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/Rakefile +36 -0
  4. data/app/assets/javascripts/csv_import_magic/application.js +13 -0
  5. data/app/assets/stylesheets/csv_import_magic/_theme.scss +75 -0
  6. data/app/assets/stylesheets/csv_import_magic/application.scss +1 -0
  7. data/app/controllers/csv_import_magic/base_controller.rb +4 -0
  8. data/app/controllers/csv_import_magic/importers_controller.rb +64 -0
  9. data/app/models/importer.rb +77 -0
  10. data/app/services/csv_import_magic/failure.rb +54 -0
  11. data/app/services/csv_import_magic/importer.rb +53 -0
  12. data/app/views/csv_import_magic/importers/edit.html.erb +43 -0
  13. data/app/views/csv_import_magic/importers/show.html.erb +31 -0
  14. data/app/views/layouts/csv_import_magic.html.erb +31 -0
  15. data/app/workers/csv_import_magic/importer_worker.rb +13 -0
  16. data/config/initializers/initializer.rb +1 -0
  17. data/config/locales/en.yml +71 -0
  18. data/config/routes.rb +3 -0
  19. data/db/migrate/20170111145652_create_companies.rb +15 -0
  20. data/db/migrate/20170111145657_create_importers.rb +15 -0
  21. data/db/migrate/20170112125734_create_user.rb +8 -0
  22. data/lib/csv_import_magic/engine.rb +5 -0
  23. data/lib/csv_import_magic/models.rb +18 -0
  24. data/lib/csv_import_magic/orm/active_record.rb +5 -0
  25. data/lib/csv_import_magic/version.rb +3 -0
  26. data/lib/csv_import_magic.rb +12 -0
  27. data/lib/generators/active_record/csv_import_magic_generator.rb +35 -0
  28. data/lib/generators/active_record/templates/csv_parser.rb +19 -0
  29. data/lib/generators/csv_import_magic/controllers_generator.rb +14 -0
  30. data/lib/generators/csv_import_magic/csv_import_magic_generator.rb +17 -0
  31. data/lib/generators/csv_import_magic/install_generator.rb +58 -0
  32. data/lib/generators/csv_import_magic/orm_helpers.rb +19 -0
  33. data/lib/generators/csv_import_magic/views_generator.rb +65 -0
  34. data/lib/generators/templates/migration.rb +10 -0
  35. data/lib/generators/templates/views/shareds/_csv_importer.html.erb +19 -0
  36. data/spec/controllers/csv_import_magic/importers_controller_spec.rb +106 -0
  37. data/spec/dummy/README.rdoc +28 -0
  38. data/spec/dummy/Rakefile +6 -0
  39. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  40. data/spec/dummy/app/assets/stylesheets/application.css +16 -0
  41. data/spec/dummy/app/controllers/application_controller.rb +7 -0
  42. data/spec/dummy/app/csv_parsers/company_parser.rb +15 -0
  43. data/spec/dummy/app/csv_parsers/foo_parser.rb +9 -0
  44. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  45. data/spec/dummy/app/models/company.rb +5 -0
  46. data/spec/dummy/app/models/user.rb +4 -0
  47. data/spec/dummy/app/views/application/index.html.erb +22 -0
  48. data/spec/dummy/app/views/layouts/application.html.erb +15 -0
  49. data/spec/dummy/bin/bundle +3 -0
  50. data/spec/dummy/bin/rails +4 -0
  51. data/spec/dummy/bin/rake +4 -0
  52. data/spec/dummy/bin/setup +29 -0
  53. data/spec/dummy/config/application.rb +26 -0
  54. data/spec/dummy/config/boot.rb +5 -0
  55. data/spec/dummy/config/database.yml +25 -0
  56. data/spec/dummy/config/environment.rb +5 -0
  57. data/spec/dummy/config/environments/development.rb +41 -0
  58. data/spec/dummy/config/environments/production.rb +79 -0
  59. data/spec/dummy/config/environments/test.rb +42 -0
  60. data/spec/dummy/config/initializers/assets.rb +11 -0
  61. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  62. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  63. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  64. data/spec/dummy/config/initializers/inflections.rb +16 -0
  65. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  66. data/spec/dummy/config/initializers/session_store.rb +3 -0
  67. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  68. data/spec/dummy/config/locales/csv_import_magic.pt-BR.yml +71 -0
  69. data/spec/dummy/config/locales/pt-BR.yml +271 -0
  70. data/spec/dummy/config/routes.rb +5 -0
  71. data/spec/dummy/config/secrets.yml +22 -0
  72. data/spec/dummy/config.ru +4 -0
  73. data/spec/dummy/db/development.sqlite3 +0 -0
  74. data/spec/dummy/db/schema.rb +51 -0
  75. data/spec/dummy/db/test.sqlite3 +0 -0
  76. data/spec/dummy/log/development.log +5489 -0
  77. data/spec/dummy/log/test.log +87086 -0
  78. data/spec/dummy/public/404.html +67 -0
  79. data/spec/dummy/public/422.html +67 -0
  80. data/spec/dummy/public/500.html +66 -0
  81. data/spec/dummy/public/favicon.ico +0 -0
  82. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170117-37276-r4n40q.csv +2 -0
  83. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170117-38136-8h3q2p.csv +2 -0
  84. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170117-38466-1nr5kco.csv +2 -0
  85. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170117-39668-101mi6q.csv +2 -0
  86. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170117-40284-81g0ud.csv +2 -0
  87. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170117-40408-17a0uvl.csv +2 -0
  88. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170117-40523-pj6wl4.csv +2 -0
  89. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170117-42084-10luep0.csv +2 -0
  90. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170117-42191-11tldaf.csv +2 -0
  91. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170117-42321-baundn.csv +2 -0
  92. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170117-42420-1qm2isf.csv +2 -0
  93. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170117-42570-gywnhk.csv +2 -0
  94. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170117-42696-1pg04re.csv +2 -0
  95. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170117-42823-vekf7j.csv +2 -0
  96. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170117-42910-ewzmcp.csv +2 -0
  97. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170117-43235-1fa52ga.csv +2 -0
  98. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170117-43323-p159hh.csv +2 -0
  99. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170117-45345-1r8v081.csv +2 -0
  100. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170117-46182-1dx0tpn.csv +2 -0
  101. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170117-46278-fd4m8e.csv +2 -0
  102. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170117-46382-9y135a.csv +2 -0
  103. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170117-48570-1k4k7t0.csv +2 -0
  104. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170117-56058-b7otnp.csv +2 -0
  105. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170117-56173-187smu1.csv +2 -0
  106. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170117-56280-ax6el0.csv +2 -0
  107. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170117-56372-pyd0uc.csv +2 -0
  108. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170117-56475-16dw7ov.csv +2 -0
  109. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170117-56578-odd4y0.csv +2 -0
  110. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170117-56672-l11ojb.csv +2 -0
  111. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170117-56794-88h4nd.csv +2 -0
  112. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-10138-13br6m2.csv +2 -0
  113. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-19400-ra06q5.csv +2 -0
  114. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-19543-rfxxty.csv +2 -0
  115. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-19652-1neho6l.csv +2 -0
  116. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-19786-rxjv36.csv +2 -0
  117. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-21648-ssn05e.csv +2 -0
  118. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-23496-ddy2xt.csv +2 -0
  119. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-30892-1c27rs4.csv +2 -0
  120. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-30994-qfqs3h.csv +2 -0
  121. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-32470-1mk1udp.csv +2 -0
  122. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-32716-13g9myq.csv +2 -0
  123. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-32807-12b8cgg.csv +2 -0
  124. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-32901-1vp2axx.csv +2 -0
  125. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-32992-1jwfjfd.csv +2 -0
  126. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-33081-1j1d591.csv +2 -0
  127. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-33180-36l1t8.csv +2 -0
  128. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-33299-13p8l1x.csv +2 -0
  129. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-38626-sigf3m.csv +2 -0
  130. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-38797-1kqkwkw.csv +2 -0
  131. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-39057-1x8b2fn.csv +2 -0
  132. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-39157-1087rtq.csv +2 -0
  133. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-39268-168s29f.csv +2 -0
  134. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-39355-s8x1si.csv +2 -0
  135. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-39483-r08bs.csv +2 -0
  136. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-40181-vdjtbv.csv +2 -0
  137. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-42041-w1imo1.csv +2 -0
  138. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-42229-1e22hz4.csv +2 -0
  139. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-42996-9neptt.csv +2 -0
  140. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-43889-584l0q.csv +2 -0
  141. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-44738-ew2i2a.csv +2 -0
  142. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-7981-1uei1o4.csv +2 -0
  143. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-8075-15sar1.csv +2 -0
  144. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-8167-zc1h0z.csv +2 -0
  145. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-8265-bnndjd.csv +2 -0
  146. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-8364-4u0il1.csv +2 -0
  147. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170119-22243-b3wyrt.csv +2 -0
  148. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170119-22711-1uvny32.csv +2 -0
  149. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170119-56031-votbjp.csv +2 -0
  150. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170119-56135-j5mcgr.csv +2 -0
  151. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170119-56240-l2w835.csv +2 -0
  152. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170119-57815-i1ahvu.csv +2 -0
  153. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170119-58056-66wtac.csv +2 -0
  154. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170119-58268-1dty7ny.csv +2 -0
  155. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170119-63803-1mc7fo4.csv +2 -0
  156. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170119-74528-duefru.csv +2 -0
  157. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170119-82684-glhzzy.csv +2 -0
  158. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170119-82810-wamt7d.csv +2 -0
  159. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170119-82946-1vdlbhd.csv +2 -0
  160. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170119-83065-1u153xf.csv +2 -0
  161. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170119-83165-1c32fyg.csv +2 -0
  162. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170119-84188-1wch9sz.csv +2 -0
  163. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170119-86886-1erfhrx.csv +2 -0
  164. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170119-87029-1vof5gs.csv +2 -0
  165. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170120-12481-joulms.csv +2 -0
  166. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170120-12708-h8hiiu.csv +2 -0
  167. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170120-12804-h1kvkh.csv +2 -0
  168. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170120-12985-tjysyw.csv +2 -0
  169. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170120-13084-3zodzd.csv +2 -0
  170. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170120-13449-1bpmult.csv +2 -0
  171. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170120-13540-2g5zwb.csv +2 -0
  172. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170120-15095-wb4mk0.csv +2 -0
  173. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170120-15202-8ib7ha.csv +2 -0
  174. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170120-16523-1s896hk.csv +2 -0
  175. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170120-16637-eboq9e.csv +2 -0
  176. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170120-87818-1j4mz4q.csv +2 -0
  177. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-65471-17j2vti.csv +2 -0
  178. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-65694-1kptcuq.csv +2 -0
  179. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-66245-crezgc.csv +2 -0
  180. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-66415-1krzmy1.csv +2 -0
  181. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-66524-ndzegu.csv +2 -0
  182. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-66655-pjqteu.csv +2 -0
  183. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-66854-r2dyv2.csv +2 -0
  184. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-67000-1t9vfos.csv +2 -0
  185. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-67391-15d0sso.csv +2 -0
  186. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-67538-1gbudl.csv +2 -0
  187. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-67640-p8dmlm.csv +2 -0
  188. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-68349-ziyxe9.csv +2 -0
  189. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-68617-14k1fap.csv +2 -0
  190. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-68815-v1izav.csv +2 -0
  191. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-68984-wcittg.csv +2 -0
  192. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-69642-1hi7zb2.csv +2 -0
  193. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-69802-mq57e0.csv +2 -0
  194. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-73509-mbxhb6.csv +2 -0
  195. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-80682-oask81.csv +2 -0
  196. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-80872-1vkh6vb.csv +2 -0
  197. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-81056-63swkp.csv +2 -0
  198. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-81212-1k8weuv.csv +2 -0
  199. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-81379-6lpon9.csv +2 -0
  200. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-82575-1eioq1a.csv +2 -0
  201. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-84919-1qnjxhv.csv +2 -0
  202. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-85131-1g8jrl5.csv +2 -0
  203. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-85343-yezbz5.csv +2 -0
  204. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-85513-1l2pzgy.csv +2 -0
  205. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-86070-pwkn99.csv +2 -0
  206. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-86277-14ckax5.csv +2 -0
  207. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-86458-1u26pb1.csv +2 -0
  208. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-86599-q2d5io.csv +2 -0
  209. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-86739-hfrzzf.csv +2 -0
  210. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-87110-1ky9gnk.csv +2 -0
  211. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170126-27355-hl9693.csv +2 -0
  212. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170126-27618-1pqa3bs.csv +2 -0
  213. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170126-27755-1di5xra.csv +2 -0
  214. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170126-27974-cx2o7z.csv +2 -0
  215. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170126-28133-1q0tz4z.csv +2 -0
  216. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170126-28419-1ia3064.csv +2 -0
  217. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170126-28556-veg3ez.csv +2 -0
  218. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170126-28784-15yhmp3.csv +2 -0
  219. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170126-29002-igofgq.csv +2 -0
  220. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170126-29143-1v25x8a.csv +2 -0
  221. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170126-29291-1qs4kex.csv +2 -0
  222. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170126-29522-5i1a.csv +2 -0
  223. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170126-29660-165adk7.csv +2 -0
  224. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170126-29945-1lvmnay.csv +2 -0
  225. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170126-30103-9qqoc.csv +2 -0
  226. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170126-30381-1de3q2.csv +2 -0
  227. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170126-30864-1mthr0r.csv +2 -0
  228. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170126-30993-wxw7ja.csv +2 -0
  229. data/spec/dummy/public/system/importers/attachment_errors/000/000/002/original/failures20170119-55532-1ujy7xh.csv +2 -0
  230. data/spec/dummy/public/system/importers/attachment_errors/000/000/003/original/failures20170119-87695-1j8psm5.csv +2 -0
  231. data/spec/dummy/public/system/importers/attachment_errors/000/000/003/original/failures20170125-84785-u7rdmo.csv +2 -0
  232. data/spec/dummy/public/system/importers/attachment_errors/000/000/006/original/failures20170118-40447-4jsf3l.csv +2 -0
  233. data/spec/dummy/public/system/importers/attachment_errors/000/000/007/original/failures20170118-44958-l51x0w.csv +2 -0
  234. data/spec/dummy/public/system/importers/attachments/000/000/001/original/companies.csv +3 -0
  235. data/spec/dummy/public/system/importers/attachments/000/000/001/original/companies_invalid.csv +3 -0
  236. data/spec/dummy/public/system/importers/attachments/000/000/002/original/companies.csv +3 -0
  237. data/spec/dummy/public/system/importers/attachments/000/000/002/original/companies_invalid.csv +3 -0
  238. data/spec/dummy/public/system/importers/attachments/000/000/003/original/companies.csv +3 -0
  239. data/spec/dummy/public/system/importers/attachments/000/000/003/original/companies_invalid.csv +3 -0
  240. data/spec/dummy/public/system/importers/attachments/000/000/004/original/companies.csv +3 -0
  241. data/spec/dummy/public/system/importers/attachments/000/000/005/original/companies.csv +3 -0
  242. data/spec/dummy/public/system/importers/attachments/000/000/006/original/companies_invalid.csv +3 -0
  243. data/spec/dummy/public/system/importers/attachments/000/000/007/original/companies_invalid.csv +3 -0
  244. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/-A/-AzUQ_sdncLrgXJW-mT29l7lXefApIPQNpdCv9ETYkI.cache +0 -0
  245. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/0f/0fmItA1G7uruwRE5HZE9TzG9K4A0NbbxGakdWz0cpDE.cache +0 -0
  246. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/2M/2MSWm1oJk8doLU2cxusKHCU78PUDwQ1lrIlu5gXMx_U.cache +1 -0
  247. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/2k/2kXdUd2P4uN67x_E2mUy-AtGn9Fn_h5rQ0PJZi9HzBU.cache +1 -0
  248. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/4b/4bvq3aQAVWrr_CUPXfVFCwfZMnmX-ecl9ZtwAisBlFI.cache +1 -0
  249. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/6-/6-dQ3OmAEd4QXytW4TS1xdUNozHlLKSCawN0oN1oEYw.cache +1 -0
  250. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/63/63b-SgBWtX-UDgRq-Bsol3W40ijIWiT7uxcHRoVXS-M.cache +1 -0
  251. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/7l/7lUIJIvW1FW_GFVqqnVsKSxpeMaZ3noc0g8Eca5eHhQ.cache +0 -0
  252. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/9S/9S1VAatjEVICqM1Cojv-CKBUvl0oELWaNfTyFr_S700.cache +0 -0
  253. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/A9/A9Vpp3VfKYpkCR6f1lAoM4J-w6QQ3fyn3x3TncKXf7U.cache +3 -0
  254. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Av/AvR3LtLvNoPexMzvvUDPuM1V-yuaMddpBdG1RVgQh9Y.cache +0 -0
  255. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Df/Dfad3HZGzx9mtzeig2tWlnuHQl9vAzoUutfVJwWKC5I.cache +0 -0
  256. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Dh/DhZ6bJZj4K7QCbNBTmMjFy3HDpC58SqfiPPoCCsAro4.cache +1 -0
  257. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Hw/HwRNsYmzR0cy4L_V_8SLZiZ9_G6_8E7XiaDV21i9sjA.cache +0 -0
  258. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/I9/I97QBZ0SyWLebPjfYrwCNlM-Omla1LKRTGiTgmMKi2Q.cache +0 -0
  259. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/J7/J7Ihmq6t6WbnmJaBScToEb-AR0U1NqHePsGdxAdJoLo.cache +0 -0
  260. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/KF/KFqlYW7ohx2fJX05v2au1k6Gw7wuzN7UWz2BN90RsAQ.cache +1 -0
  261. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/LL/LLb4gLbgLgFS-LgcrmKXC--d1IaGB8XM_Yrm48bkwdw.cache +0 -0
  262. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/LX/LXS-BomSubWXJSpkNXCH8m0l2y4sB66BaFb2UuAx14o.cache +1 -0
  263. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Lq/LqbLgHiwEzXq7mJX3Dtq5XicBULM8CtvDJdv4Ye45ZY.cache +1 -0
  264. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Nh/Nhtorvc2xM84CWBcqtMIxoqKR4NCkCksOUQ_3UiyegA.cache +1 -0
  265. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Oy/OyEUtus13InbtOxcvt5WdsbydEkrviBwJXD6z9GQaRA.cache +1 -0
  266. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/P6/P6-U-RxLXuRTDz8kHA2kBc3jUHSnNlbEHBOnUa97wyY.cache +1 -0
  267. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Po/Pos0iHsH-rUXDrrdalDi2H6yWVQTcz2ZPyRmQ_RnBPM.cache +1 -0
  268. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Q1/Q1xmk8Ni14zSYsTX_IvrbX1vbGANki_Udrwx7OBgh9w.cache +0 -0
  269. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Qo/QogFhnK16HrvDyiH323Z3xlwwofVibvzgZDmBjqh5VQ.cache +3 -0
  270. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/RI/RIagqSB7X-LbJU0ZwntNWf_KMkOm3kCkc7zR57rP1Bc.cache +1 -0
  271. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/T4/T4WcrrL47jCKFOb5Q1cmn1keh_w3X2OguI_ifzRpS3k.cache +1 -0
  272. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/TA/TAbsAe1o7EI19gckGhtzbtjqOoSVRRLQrc5n3mnCT28.cache +0 -0
  273. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/TG/TGe7XAuizvtm9LtzDo5fR7GrEnyWPL8nBr2eESxA0x0.cache +0 -0
  274. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/V8/V8kjWO7PZcVGI9mBNq17FYWc_muWwcDQF9xWGfnSOjM.cache +1 -0
  275. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/VV/VVtm8HzHyOByhegKNGl09Ak3sHcSr0e70iHSmy75T6A.cache +0 -0
  276. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Vb/VbBBjIpX-u1j_Fko8QfFQ61-bfDS8BaYgGATVKIfp3I.cache +0 -0
  277. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/WR/WRP18y_66NlZHU4W5qM0P1MN8oS5eAlN9UEZrXh3vd0.cache +1 -0
  278. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Wd/WdUHknjRY-ueTBCEgU4-NzM_BFaTimaeFED6MbFfQLE.cache +0 -0
  279. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/bo/bopbSF0DLQEMLjRvN8Mn4xd-mGx46j9yvENVDA8R9jk.cache +0 -0
  280. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/e4/e4DrxyTxBlZlpP4PQ0zELpYhl4G2eiBksI0_HwQhrVY.cache +0 -0
  281. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/gZ/gZp3uXMHuYQC4hzCr7bQfetKNdJAtbQmg3so2KpW1Dw.cache +2 -0
  282. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/hZ/hZi1k6tpxxCGYxRe7zY74ItcOI8gZrREOpGuA8JSpGg.cache +2 -0
  283. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/iK/IKrFvYc5CMyfkKHP7JFW_bS4-tOG1rVwPFcC-OUpENU.cache +0 -0
  284. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/iK/IkTLxpKuWrwxrM98yl3Ddv4RjOLzyUS5QHQvZ0Cniv8.cache +1 -0
  285. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/iK/iKpMoxBcOmuavL2xUzgc7LQLnT7EKCaZirHx4KMbdw8.cache +1 -0
  286. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/je/jeA_WQ150_Af65U1CnVdHsqqZefOHl2ObGMLRQp--sc.cache +2 -0
  287. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/l1/l1LHMvhocUYdhOc0tOfdy4slQYK2SD4fj6x4mH4wkvI.cache +0 -0
  288. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/lo/loI7P5Fiwnq6YZdxqJFAErc6rV61HWRuL5tVaffS3JY.cache +1 -0
  289. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/m9/m95ShgmvfDO8RuwZpC7gUW0i-FO-k914CWkXd5-LO3I.cache +1 -0
  290. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/my/myHmSL0lcXz8Mgm5gNVoigImnF7acMaTlwl3z_g2lPM.cache +0 -0
  291. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/oo/oocXRRNDTZPTtm859sgr9TxpBrPby6ND88ROtiCfgSU.cache +0 -0
  292. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/p-/p-3_4sMWwoC1eQcdH2fmcIdmlxQBFx6evUCdgfgPyKM.cache +1 -0
  293. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/pE/pEhaat2KBd5SrT7szC_8R1_6hK17FTpvoRFkmCRSD3M.cache +2 -0
  294. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/rn/rnSEYPKQcSZ-D3R7o3aM_1AtiXyLciuL3S3Qa6k_EfI.cache +0 -0
  295. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/sV/sVzlvz069Fh5_GPu0TcrgDBWIHhnwEZ2Rg1AtpEqA9s.cache +0 -0
  296. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/uV/uVH7RdIENZh9BUaGeb6OUciC9H0hTIKsRpAxXMG5R28.cache +1 -0
  297. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/xQ/xQEI_TWc5k3ouSH2fSRrrWRpsLyeG7QQxmcgPjkwbc8.cache +0 -0
  298. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/xQ/xQUUINnLqsr-zxPaIIULgXPE5jh2QtmbdRSYCnhpER4.cache +0 -0
  299. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/xb/xblMCu_z727eCkuWjKJEyre92sVUkcGCpQqGThWe2bk.cache +2 -0
  300. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/yg/ygMyHfDIhhvlowOd5aTDhtXbZCLisqxhDWpdvXd8O5M.cache +0 -0
  301. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/yg/ygrgsR6-nQLxLaFwAquCXfjIZgUTEoYbI5EFH0KlfW0.cache +1 -0
  302. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/yh/yh3Aqjs6HjjQubE9-htvIwUg4cFhMRCl7JyBFYBt0xo.cache +1 -0
  303. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/z0/z0QrtOYRAsWOTFYmpCJqXXyGlHxHUxxKBV3_LMxKV2Y.cache +0 -0
  304. data/spec/examples.txt +50 -0
  305. data/spec/factories/importer.rb +10 -0
  306. data/spec/factories/user.rb +6 -0
  307. data/spec/fixtures/companies.csv +3 -0
  308. data/spec/fixtures/companies_invalid.csv +3 -0
  309. data/spec/lib/csv_import_magic/models_spec.rb +51 -0
  310. data/spec/lib/generators/active_record/csv_import_magic_generator_spec.rb +74 -0
  311. data/spec/lib/generators/active_record/namespaced/csv_import_magic_generator_spec.rb +78 -0
  312. data/spec/lib/generators/csv_import_magic/controllers_generator_spec.rb +34 -0
  313. data/spec/lib/generators/csv_import_magic/install_generator_spec.rb +79 -0
  314. data/spec/lib/generators/csv_import_magic/rails_5/install_generator_spec.rb +62 -0
  315. data/spec/lib/generators/csv_import_magic/views_generator_spec.rb +204 -0
  316. data/spec/models/importer_spec.rb +82 -0
  317. data/spec/rails_helper.rb +61 -0
  318. data/spec/services/csv_import_magic/failure_spec.rb +23 -0
  319. data/spec/services/csv_import_magic/importer_spec.rb +57 -0
  320. data/spec/spec_helper.rb +70 -0
  321. data/spec/support/database_cleaner.rb +12 -0
  322. data/spec/support/factory_girl.rb +12 -0
  323. data/spec/support/paperclip.rb +3 -0
  324. data/spec/support/shoulda_matchers.rb +6 -0
  325. data/spec/support/simplecov.rb +12 -0
  326. data/spec/workers/csv_import_magic/importer_worker_spec.rb +31 -0
  327. metadata +758 -0
@@ -0,0 +1,18 @@
1
+ module CsvImportMagic
2
+ module Models
3
+ def csv_import_magic(options)
4
+ define_method(:csv_parser_names) do
5
+ names_of_parsers = {}
6
+
7
+ options.each do |key, _value|
8
+ names_of_parsers["#{key}_parser"] = "#{key.to_s.classify}Parser".constantize
9
+ end
10
+
11
+ names_of_parsers
12
+ end
13
+
14
+ define_singleton_method(:csv_parser_default_name) { "#{name.to_s.underscore}_parser" }
15
+ define_singleton_method(:columns_names) { |param| options[param.to_s.remove('_parser').to_sym] }
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,5 @@
1
+ require 'orm_adapter/adapters/active_record'
2
+
3
+ ActiveSupport.on_load(:active_record) do
4
+ extend CsvImportMagic::Models
5
+ end
@@ -0,0 +1,3 @@
1
+ module CsvImportMagic
2
+ VERSION = '0.0.1'.freeze
3
+ end
@@ -0,0 +1,12 @@
1
+ require 'paperclip'
2
+ require 'orm_adapter'
3
+ require 'simple_form'
4
+ require 'csv-importer'
5
+ require 'sidekiq'
6
+
7
+ require 'csv_import_magic/engine'
8
+ require 'csv_import_magic/models'
9
+ require 'csv_import_magic/orm/active_record'
10
+
11
+ module CsvImportMagic
12
+ end
@@ -0,0 +1,35 @@
1
+ require 'rails/generators/active_record'
2
+ require 'generators/csv_import_magic/orm_helpers'
3
+
4
+ module ActiveRecord
5
+ module Generators
6
+ class CsvImportMagicGenerator < ActiveRecord::Generators::Base
7
+ source_root File.expand_path('../templates', __FILE__)
8
+ class_option :columns, aliases: '-c', type: :array, required: true, desc: 'Select specific columns yout want parser'
9
+
10
+ include CsvImportMagic::Generators::OrmHelpers
11
+
12
+ def generate_model
13
+ invoke 'active_record:model', [name], migration: false unless model_exists? && behavior == :invoke
14
+
15
+ class_path = if name.match(/\:\:/).present?
16
+ name.to_s.gsub('::', '/')
17
+ else
18
+ name
19
+ end
20
+
21
+ template 'csv_parser.rb', "app/csv_parsers/#{class_path}_parser.rb"
22
+ end
23
+
24
+ def inject_csv_import_magic_content
25
+ content = model_contents(options)
26
+ class_path = [class_name]
27
+
28
+ indent_depth = class_path.size - 1
29
+ content = content.split("\n").map { |line| ' ' * indent_depth + line } .join("\n") << "\n"
30
+
31
+ inject_into_class(model_path, class_path.last, content) if model_exists?
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,19 @@
1
+ class <%= file_path.camelize %>Parser
2
+ include ::CSVImporter
3
+
4
+ model <%= file_path.camelize %>
5
+
6
+ # will update_or_create via :<%= options[:columns].first %>
7
+ identifier :<%= options[:columns].first %>
8
+
9
+ # Examples of columns declaration
10
+ # column :<%= options[:columns].first %>, to: ->(<%= options[:columns].first %>) { <%= options[:columns].first %>.downcase }, required: true
11
+ # column :<%= options[:columns].first %>, as: [ /first.?name/i, /pr(é|e)nom/i ]
12
+ # column :<%= options[:columns].first %>, as: [ /last.?name/i, "nom" ]
13
+ # column :<%= options[:columns].first %>, to: ->(<%= options[:columns].first %>, record) { record.<%= options[:columns].first %> = <%= options[:columns].first %> ? 'a' : 'b' }
14
+ <% options[:columns].map do |column| %>
15
+ column :<%= column.to_sym %>, required: true
16
+ <% end %>
17
+ # or :abort
18
+ # when_invalid :skip
19
+ end
@@ -0,0 +1,14 @@
1
+ require 'rails/generators/base'
2
+
3
+ module CsvImportMagic
4
+ module Generators
5
+ class ControllersGenerator < Rails::Generators::Base
6
+ desc 'Copies CSV Import Magic base controller to your application.'
7
+ source_root File.expand_path('../../../../app/controllers/csv_import_magic', __FILE__)
8
+
9
+ def copy_base_controller
10
+ template 'base_controller.rb', 'app/controllers/csv_import_magic/base_controller.rb'
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,17 @@
1
+ require 'rails/generators/named_base'
2
+
3
+ module CsvImportMagic
4
+ module Generators
5
+ class CsvImportMagicGenerator < Rails::Generators::NamedBase
6
+ include Rails::Generators::ResourceHelpers
7
+
8
+ namespace 'csv_import_magic'
9
+ source_root File.expand_path('../templates', __FILE__)
10
+
11
+ desc 'Generates a model with the given NAME (if one does not exist) with csv_import_magic ' \
12
+ 'configuration plus a migration file.'
13
+
14
+ hook_for :orm
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,58 @@
1
+ require 'rails/generators/base'
2
+
3
+ module CsvImportMagic
4
+ module Generators
5
+ class InstallGenerator < Rails::Generators::Base
6
+ include Rails::Generators::Migration
7
+
8
+ source_root File.expand_path('../../templates', __FILE__)
9
+
10
+ desc 'Creates a routes to your application.'
11
+
12
+ class_option :routes, desc: 'Generate routes', type: :boolean, default: true
13
+
14
+ def add_csv_import_magic_routes
15
+ route "mount CsvImportMagic::Engine => '/csv_import_magic'"
16
+ end
17
+
18
+ def add_importer_migration
19
+ migration_template 'migration.rb', "db/migrate/create_#{table_name}.rb"
20
+ end
21
+
22
+ desc 'Creates a CSV Import Magic locales to your application.'
23
+
24
+ def copy_locale
25
+ template '../../../config/locales/en.yml', 'config/locales/csv_import_magic.en.yml'
26
+ end
27
+
28
+ def self.next_migration_number(_dir)
29
+ Time.now.utc.strftime('%Y%m%d%H%M%S')
30
+ end
31
+
32
+ def table_name
33
+ 'importers'
34
+ end
35
+
36
+ def migration_data
37
+ <<RUBY
38
+ t.attachment :attachment
39
+ t.attachment :attachment_error
40
+ t.string :source
41
+ t.string :parser
42
+ t.string :columns
43
+ t.string :message
44
+ t.string :status, default: 'pending'
45
+ t.references :importable, polymorphic: true
46
+ RUBY
47
+ end
48
+
49
+ def rails5?
50
+ Rails.version.start_with? '5'
51
+ end
52
+
53
+ def migration_version
54
+ "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]" if rails5?
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,19 @@
1
+ module CsvImportMagic
2
+ module Generators
3
+ module OrmHelpers
4
+ def model_contents(options)
5
+ " csv_import_magic :#{options[:columns].join(', :')}"
6
+ end
7
+
8
+ private
9
+
10
+ def model_exists?
11
+ File.exist?(File.join(destination_root, model_path))
12
+ end
13
+
14
+ def model_path
15
+ @model_path ||= File.join('app', 'models', "#{file_path}.rb")
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,65 @@
1
+ require 'rails/generators/base'
2
+
3
+ module CsvImportMagic
4
+ module Generators
5
+ module ViewPathTemplates #:nodoc:
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ argument :scope, required: true, default: nil,
10
+ desc: 'The scope to copy views to'
11
+
12
+ class_option :importable_type, aliases: '-i', type: :string, desc: 'Select specific importable to importer_csv partial form'
13
+ end
14
+
15
+ protected
16
+
17
+ def view_directory(name)
18
+ directory name.to_s, target_path do |content|
19
+ content = content.gsub('source_value', scope)
20
+ content
21
+ end
22
+ end
23
+
24
+ def target_path
25
+ @target_path ||= "app/views/#{plural_scope}"
26
+ end
27
+
28
+ def plural_scope
29
+ @plural_scope ||= scope.presence && scope.underscore.pluralize
30
+ end
31
+ end
32
+
33
+ class LayoutViewsGenerator < Rails::Generators::Base #:nodoc:
34
+ source_root File.expand_path('../../../../app/views', __FILE__)
35
+ desc 'Copies shared Csv Magic Import Layout to your application.'
36
+
37
+ def copy_layout_views
38
+ directory :layouts, 'app/views/layouts'
39
+ end
40
+
41
+ def copy_views
42
+ directory 'csv_import_magic/importers', 'app/views/csv_import_magic/importers'
43
+ end
44
+ end
45
+
46
+ class SharedViewsGenerator < Rails::Generators::Base #:nodoc:
47
+ include ViewPathTemplates
48
+ source_root File.expand_path('../../templates/views', __FILE__)
49
+ desc 'Copies shared Csv Magic Import Partial views to your application.'
50
+ hide!
51
+
52
+ def copy_views
53
+ view_directory :shareds
54
+ end
55
+ end
56
+
57
+ class ViewsGenerator < Rails::Generators::Base
58
+ desc 'Copies CSV Import Magic views to your application.'
59
+ argument :scope, required: true, default: nil, desc: 'The scope to copy views to'
60
+
61
+ invoke LayoutViewsGenerator
62
+ invoke SharedViewsGenerator
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,10 @@
1
+ class Create<%= table_name.camelize %> < ActiveRecord::Migration<%= migration_version %>
2
+ def change
3
+ create_table :<%= table_name %> do |t|
4
+ <%= migration_data -%>
5
+ t.timestamps null: false
6
+ end
7
+
8
+ add_index :<%= table_name %>, [:importable_id, :importable_type]
9
+ end
10
+ end
@@ -0,0 +1,19 @@
1
+ <h1 class="page-title">
2
+ <%= t('csv_import_magic.views.importers.new.title', model_translated: t('activemodel.models.source_value.other')) %>
3
+ <br/>
4
+ <small><%= t('csv_import_magic.views.importers.new.description', model_translated: t('activemodel.models.source_value.other').downcase) %></small>
5
+ </h1>
6
+
7
+ <%= simple_form_for(Importer.new, url: csv_import_magic.importers_path) do |f| %>
8
+ <%= f.input :importable_type, as: :hidden, input_html: { value: '<change this value>' } %>
9
+ <%= f.input :importable_id, as: :hidden, input_html: { value: '<change this value>' } %>
10
+ <%= f.input :source, as: :hidden, input_html: { value: 'source_value' } %>
11
+
12
+ <div class="form-row">
13
+ <%= f.input :attachment, as: :file, hint: t('csv_import_magic.views.importers.new.hint').html_safe, required: true %>
14
+ </div>
15
+
16
+ <div class='form-row actions'>
17
+ <%= f.submit t('csv_import_magic.views.importers.new.buttons.import'), class: 'button button--primary' %>
18
+ </div>
19
+ <% end %>
@@ -0,0 +1,106 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe CsvImportMagic::ImportersController, type: :controller do
4
+ routes { CsvImportMagic::Engine.routes }
5
+
6
+ describe 'POST #create' do
7
+ def do_action
8
+ post :create, importer: { attachment: attachment, importable_type: 'User', importable_id: create(:user).id, source: 'company' }
9
+ end
10
+
11
+ context 'with valid params' do
12
+ let(:attachment) { fixture_file_upload(Rails.root.join('../fixtures/companies.csv')) }
13
+
14
+ it 'create a import for the company' do
15
+ expect { do_action }.to change(Importer, :count).by(1)
16
+ end
17
+
18
+ it 'redirect to edit' do
19
+ do_action
20
+ import = Importer.last
21
+ expect(response).to redirect_to(edit_importer_path(import.id))
22
+ expect(flash[:alert]).to eq('Por favor, informe em quais colunas podemos encontrar as informações que você deseja.')
23
+ end
24
+ end
25
+
26
+ context 'with invalid params' do
27
+ let(:attachment) { nil }
28
+
29
+ it 'render to edit with error' do
30
+ @request.env['HTTP_REFERER'] = 'http://example.com'
31
+ do_action
32
+ expect(response).to redirect_to('http://example.com')
33
+ expect(flash[:error]).to eq('A validação falhou: Anexo CSV não pode ficar em branco')
34
+ end
35
+ end
36
+ end
37
+
38
+ describe 'GET #show' do
39
+ let(:importer) { create :importer }
40
+
41
+ def do_action
42
+ get :show, id: importer.id
43
+ end
44
+
45
+ before { do_action }
46
+
47
+ it 'return OK' do
48
+ is_expected.to respond_with(:success)
49
+ is_expected.to render_template(:show)
50
+ expect(assigns(:importer)).to eq(importer)
51
+ end
52
+ end
53
+
54
+ describe 'GET #edit' do
55
+ let(:importer) { create :importer }
56
+
57
+ def do_action
58
+ get :edit, id: importer.id
59
+ end
60
+
61
+ before { do_action }
62
+
63
+ it 'return OK' do
64
+ is_expected.to respond_with(:success)
65
+ is_expected.to render_template(:edit)
66
+ expect(assigns(:importer)).to eq(importer)
67
+ expect(controller.send(:import_file_csv).headers).to match_array(['bairro', 'cidade ', 'cod', 'estado ', 'nome', 'numero', 'pais', 'rua'])
68
+ end
69
+ end
70
+
71
+ describe 'PUT #update' do
72
+ let(:importer) { create :importer, columns: [] }
73
+
74
+ def do_action(columns)
75
+ put :update, id: importer.id, importer: { columns: columns }
76
+ end
77
+
78
+ context 'with valid columns' do
79
+ it 'update the importer columns list' do
80
+ do_action(%w(neighborhood city cod state name number country street))
81
+ expect(importer.reload.columns).to eq(%w(neighborhood city cod state name number country street))
82
+ end
83
+
84
+ it 'redirect back to employees index' do
85
+ do_action(%w(neighborhood city cod state name number country street))
86
+ expect(response).to redirect_to(importer_path(importer))
87
+ expect(flash[:notice]).to eq('Arquivo enviado para processamento.')
88
+ end
89
+
90
+ it 'enqueue the Importer::EmployeesCSVWorker' do
91
+ expect(CsvImportMagic::ImporterWorker).to receive(:perform_async).with(importer_id: importer.id, resources: nil)
92
+ do_action(%w(neighborhood city cod state name number country street))
93
+ end
94
+ end
95
+
96
+ context 'with invalid columns' do
97
+ it 'render the edit screen' do
98
+ do_action(%w(neighborhood city cod state name name number country street))
99
+ is_expected.to respond_with(:success)
100
+ is_expected.to render_template(:edit)
101
+ expect(assigns(:importer)).to eq(importer)
102
+ expect(flash[:alert]).to eq('Colunas Nome deve ser única')
103
+ end
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,28 @@
1
+ == README
2
+
3
+ This README would normally document whatever steps are necessary to get the
4
+ application up and running.
5
+
6
+ Things you may want to cover:
7
+
8
+ * Ruby version
9
+
10
+ * System dependencies
11
+
12
+ * Configuration
13
+
14
+ * Database creation
15
+
16
+ * Database initialization
17
+
18
+ * How to run the test suite
19
+
20
+ * Services (job queues, cache servers, search engines, etc.)
21
+
22
+ * Deployment instructions
23
+
24
+ * ...
25
+
26
+
27
+ Please feel free to use a different markup language if you do not plan to run
28
+ <tt>rake doc:app</tt>.
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ Rails.application.load_tasks
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,16 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require csv_import_magic/_theme
15
+ *= require_self
16
+ */
@@ -0,0 +1,7 @@
1
+ class ApplicationController < ActionController::Base
2
+ # Prevent CSRF attacks by raising an exception.
3
+ # For APIs, you may want to use :null_session instead.
4
+ protect_from_forgery with: :exception
5
+
6
+ def index; end
7
+ end
@@ -0,0 +1,15 @@
1
+ class CompanyParser
2
+ include ::CSVImporter
3
+
4
+ model Company
5
+
6
+ identifier :name
7
+
8
+ column :name, required: true
9
+ column :number, required: true
10
+ column :city, required: true
11
+ column :state, required: true
12
+ column :street
13
+ column :neighborhood
14
+ column :country
15
+ end
@@ -0,0 +1,9 @@
1
+ class FooParser
2
+ include ::CSVImporter
3
+
4
+ model Company
5
+
6
+ identifier :name
7
+
8
+ column :name, required: true
9
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,5 @@
1
+ class Company < ActiveRecord::Base
2
+ csv_import_magic company: [:name, :street, :number, :neighborhood, :city, :state, :country]
3
+
4
+ validates_numericality_of :number
5
+ end
@@ -0,0 +1,4 @@
1
+ class User < ActiveRecord::Base
2
+ has_many :importers, as: :importable
3
+ has_many :companies
4
+ end
@@ -0,0 +1,22 @@
1
+ <% User.destroy_all %>
2
+ <% User.create(name: 'foo', email: 'foo@bar.commm') %>
3
+
4
+ <h1 class="page-title">
5
+ <%= t('csv_import_magic.views.importers.new.title', model_translated: t('activemodel.models.company.other')) %>
6
+ <br/>
7
+ <small><%= t('csv_import_magic.views.importers.new.description', model_translated: t('activemodel.models.company.other').downcase) %></small>
8
+ </h1>
9
+
10
+ <%= simple_form_for(Importer.new, url: csv_import_magic.importers_path) do |f| %>
11
+ <%= f.input :importable_type, as: :hidden, input_html: { value: 'User' } %>
12
+ <%= f.input :importable_id, as: :hidden, input_html: { value: User.first.id } %>
13
+ <%= f.input :source, as: :hidden, input_html: { value: 'company' } %>
14
+
15
+ <div class="form-row">
16
+ <%= f.input :attachment, as: :file, hint: t('csv_import_magic.views.importers.new.hint').html_safe, required: true %>
17
+ </div>
18
+
19
+ <div class='form-row actions'>
20
+ <%= f.submit t('csv_import_magic.views.importers.new.buttons.import'), class: 'button button--primary' %>
21
+ </div>
22
+ <% end %>
@@ -0,0 +1,15 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
6
+ <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+ <h1>IMPORTER</h1>
11
+
12
+ <%= yield %>
13
+
14
+ </body>
15
+ </html>
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
+ load Gem.bin_path('bundler', 'bundle')
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
3
+ require_relative '../config/boot'
4
+ require 'rails/commands'
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../config/boot'
3
+ require 'rake'
4
+ Rake.application.run
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ require 'pathname'
3
+
4
+ # path to your application root.
5
+ APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
6
+
7
+ Dir.chdir APP_ROOT do
8
+ # This script is a starting point to setup your application.
9
+ # Add necessary setup steps to this file:
10
+
11
+ puts '== Installing dependencies =='
12
+ system 'gem install bundler --conservative'
13
+ system 'bundle check || bundle install'
14
+
15
+ # puts "\n== Copying sample files =="
16
+ # unless File.exist?("config/database.yml")
17
+ # system "cp config/database.yml.sample config/database.yml"
18
+ # end
19
+
20
+ puts "\n== Preparing database =="
21
+ system 'bin/rake db:setup'
22
+
23
+ puts "\n== Removing old logs and tempfiles =="
24
+ system 'rm -f log/*'
25
+ system 'rm -rf tmp/cache'
26
+
27
+ puts "\n== Restarting application server =="
28
+ system 'touch tmp/restart.txt'
29
+ end
@@ -0,0 +1,26 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require 'rails/all'
4
+
5
+ Bundler.require(*Rails.groups)
6
+ require 'csv_import_magic'
7
+
8
+ module Dummy
9
+ class Application < Rails::Application
10
+ # Settings in config/environments/* take precedence over those specified here.
11
+ # Application configuration should go into files in config/initializers
12
+ # -- all .rb files in that directory are automatically loaded.
13
+
14
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
15
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
16
+ # config.time_zone = 'Central Time (US & Canada)'
17
+
18
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
19
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
20
+ config.i18n.default_locale = :'pt-BR'
21
+
22
+ # Do not swallow errors in after_commit/after_rollback callbacks.
23
+ config.active_record.raise_in_transactional_callbacks = true
24
+ # config.autoload_paths << Rails.root.join('app/csv_parsers')
25
+ end
26
+ end
@@ -0,0 +1,5 @@
1
+ # Set up gems listed in the Gemfile.
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__)
3
+
4
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
5
+ $LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__)