nimbleshop_core 0.0.1.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (359) hide show
  1. data/README.md +13 -0
  2. data/Rakefile +15 -0
  3. data/app/assets/images/engines/nimbleshop_authorizedotnet/american_express.png +0 -0
  4. data/app/assets/images/engines/nimbleshop_authorizedotnet/authorize_net_big.png +0 -0
  5. data/app/assets/images/engines/nimbleshop_authorizedotnet/authorizedotnet_big.png +0 -0
  6. data/app/assets/images/engines/nimbleshop_authorizedotnet/discover.png +0 -0
  7. data/app/assets/images/engines/nimbleshop_authorizedotnet/mastercard.png +0 -0
  8. data/app/assets/images/engines/nimbleshop_authorizedotnet/visa.png +0 -0
  9. data/app/assets/images/engines/nimbleshop_cod/cod_small.png +0 -0
  10. data/app/assets/images/engines/nimbleshop_paypalwp/paypal_big.png +0 -0
  11. data/app/assets/images/engines/nimbleshop_paypalwp/paypal_small.png +0 -0
  12. data/app/assets/images/engines/nimbleshop_splitable/splitable.png +0 -0
  13. data/app/assets/images/engines/nimbleshop_splitable/splitable_big.png +0 -0
  14. data/app/assets/images/engines/nimbleshop_splitable/splitable_small.png +0 -0
  15. data/app/assets/javascripts/admin/products/edit.js.coffee +19 -0
  16. data/app/assets/javascripts/admin/shipping_methods/edit.js.coffee +6 -0
  17. data/app/assets/javascripts/admin.js +25 -0
  18. data/app/assets/javascripts/fadeout_success.js.coffee +2 -0
  19. data/app/assets/javascripts/payment_method.js.coffee +19 -0
  20. data/app/assets/javascripts/product-group-condition.js.coffee +33 -0
  21. data/app/assets/javascripts/remove_deletion_of_product_pictures.js.coffee +5 -0
  22. data/app/assets/javascripts/shipit.js.coffee +10 -0
  23. data/app/assets/javascripts/twitter_bootstrap.js.coffee +4 -0
  24. data/app/assets/stylesheets/admin.css +9 -0
  25. data/app/assets/stylesheets/admin_bootstrap_and_overrides.css.less +38 -0
  26. data/app/assets/stylesheets/admin_custom.css +104 -0
  27. data/app/assets/twitter/bootstrap/glyphicons-halflings-white.png +0 -0
  28. data/app/assets/twitter/bootstrap/glyphicons-halflings.png +0 -0
  29. data/app/controllers/admin/custom_fields_controller.rb +56 -0
  30. data/app/controllers/admin/link_groups_controller.rb +76 -0
  31. data/app/controllers/admin/main_controller.rb +9 -0
  32. data/app/controllers/admin/navigations_controller.rb +49 -0
  33. data/app/controllers/admin/orders_controller.rb +47 -0
  34. data/app/controllers/admin/payment_methods_controller.rb +26 -0
  35. data/app/controllers/admin/product_groups_controller.rb +70 -0
  36. data/app/controllers/admin/products_controller.rb +71 -0
  37. data/app/controllers/admin/shipments_controller.rb +19 -0
  38. data/app/controllers/admin/shipping_methods_controller.rb +93 -0
  39. data/app/controllers/admin/shipping_zones_controller.rb +62 -0
  40. data/app/controllers/admin/shops_controller.rb +33 -0
  41. data/app/controllers/admin_controller.rb +38 -0
  42. data/app/helpers/admin_helper.rb +83 -0
  43. data/app/helpers/nimbleshop_helper.rb +43 -0
  44. data/app/helpers/payment_method_helper.rb +52 -0
  45. data/app/mailers/admin_mailer.rb +22 -0
  46. data/app/mailers/mailer.rb +31 -0
  47. data/app/models/address.rb +69 -0
  48. data/app/models/country_shipping_zone.rb +36 -0
  49. data/app/models/creditcard.rb +95 -0
  50. data/app/models/custom_field.rb +8 -0
  51. data/app/models/custom_field_answer/field.rb +101 -0
  52. data/app/models/custom_field_answer.rb +17 -0
  53. data/app/models/line_item.rb +48 -0
  54. data/app/models/link.rb +3 -0
  55. data/app/models/link_group.rb +8 -0
  56. data/app/models/navigation.rb +7 -0
  57. data/app/models/order.rb +158 -0
  58. data/app/models/payment_method.rb +20 -0
  59. data/app/models/payment_transaction.rb +11 -0
  60. data/app/models/picture.rb +30 -0
  61. data/app/models/product.rb +76 -0
  62. data/app/models/product_group.rb +65 -0
  63. data/app/models/product_group_condition.rb +8 -0
  64. data/app/models/regional_shipping_zone.rb +25 -0
  65. data/app/models/shipment.rb +19 -0
  66. data/app/models/shipment_carrier.rb +3 -0
  67. data/app/models/shipping_cost_calculator.rb +9 -0
  68. data/app/models/shipping_method.rb +103 -0
  69. data/app/models/shipping_zone.rb +9 -0
  70. data/app/models/shop.rb +26 -0
  71. data/app/models/tax_calculator.rb +18 -0
  72. data/app/observers/order_observer.rb +53 -0
  73. data/app/uploaders/picture_uploader.rb +65 -0
  74. data/app/views/admin/custom_fields/_form.html.erb +45 -0
  75. data/app/views/admin/custom_fields/edit.html.erb +7 -0
  76. data/app/views/admin/custom_fields/index.html.erb +31 -0
  77. data/app/views/admin/custom_fields/new.html.erb +7 -0
  78. data/app/views/admin/link_groups/_form.html.erb +31 -0
  79. data/app/views/admin/link_groups/_link_group.html.erb +50 -0
  80. data/app/views/admin/link_groups/_link_group_title.html.erb +5 -0
  81. data/app/views/admin/link_groups/edit.html.erb +8 -0
  82. data/app/views/admin/link_groups/index.html.erb +29 -0
  83. data/app/views/admin/link_groups/new.html.erb +9 -0
  84. data/app/views/admin/mailer/new_order_notification.text.erb +31 -0
  85. data/app/views/admin/main/index.html.erb +5 -0
  86. data/app/views/admin/navigations/new.html.erb +29 -0
  87. data/app/views/admin/orders/_line_item.html.erb +11 -0
  88. data/app/views/admin/orders/_line_items.html.erb +39 -0
  89. data/app/views/admin/orders/_payment_info.html.erb +20 -0
  90. data/app/views/admin/orders/_shipping_info.html.erb +40 -0
  91. data/app/views/admin/orders/index.html.erb +33 -0
  92. data/app/views/admin/orders/show.html.erb +40 -0
  93. data/app/views/admin/payment_methods/index.html.erb +6 -0
  94. data/app/views/admin/product_groups/_condition.html.mustache +20 -0
  95. data/app/views/admin/product_groups/_form.html.erb +72 -0
  96. data/app/views/admin/product_groups/edit.html.erb +7 -0
  97. data/app/views/admin/product_groups/index.html.erb +30 -0
  98. data/app/views/admin/product_groups/new.html.erb +7 -0
  99. data/app/views/admin/product_groups/show.html.erb +9 -0
  100. data/app/views/admin/products/_custom_field_answer.html.erb +9 -0
  101. data/app/views/admin/products/_form.html.erb +69 -0
  102. data/app/views/admin/products/_handle_pictures.html.erb +32 -0
  103. data/app/views/admin/products/_pictures.html.erb +33 -0
  104. data/app/views/admin/products/edit.html.erb +26 -0
  105. data/app/views/admin/products/index.html.erb +34 -0
  106. data/app/views/admin/products/new.html.erb +9 -0
  107. data/app/views/admin/shipping_methods/_form.html.erb +58 -0
  108. data/app/views/admin/shipping_methods/_shipping_method.html.erb +31 -0
  109. data/app/views/admin/shipping_methods/edit.html.erb +18 -0
  110. data/app/views/admin/shipping_methods/new.html.erb +7 -0
  111. data/app/views/admin/shipping_zones/_form.html.erb +31 -0
  112. data/app/views/admin/shipping_zones/_shipping_method.html.erb +13 -0
  113. data/app/views/admin/shipping_zones/_shipping_zone.html.erb +47 -0
  114. data/app/views/admin/shipping_zones/edit.html.erb +8 -0
  115. data/app/views/admin/shipping_zones/index.html.erb +16 -0
  116. data/app/views/admin/shipping_zones/new.html.erb +8 -0
  117. data/app/views/admin/shops/edit.html.erb +119 -0
  118. data/app/views/layouts/_admin_footer.html.erb +23 -0
  119. data/app/views/layouts/_admin_sidebar.html.erb +0 -0
  120. data/app/views/layouts/_container.html.erb +33 -0
  121. data/app/views/layouts/_top_nav_bar.html.erb +30 -0
  122. data/app/views/layouts/admin.html.erb +35 -0
  123. data/app/views/layouts/payment_method.html.erb +12 -0
  124. data/app/views/mailer/order_notification_to_buyer.text.erb +31 -0
  125. data/app/views/mailer/shipment_notification_to_buyer.text.erb +34 -0
  126. data/config/initializers/001_settings_application.rb +10 -0
  127. data/config/initializers/002_load_core_extensions.rb +8 -0
  128. data/config/initializers/field_with_error.rb +2 -0
  129. data/config/initializers/strip_and_nullify.rb +13 -0
  130. data/config/initializers/time_formats.rb +1 -0
  131. data/config/locales/en.yml +61 -0
  132. data/config/routes.rb +56 -0
  133. data/db/development.sqlite3 +0 -0
  134. data/db/migrate/20111022144421_create_product_groups.rb +12 -0
  135. data/db/migrate/20111022144426_create_products.rb +16 -0
  136. data/db/migrate/20111022144653_create_orders.rb +21 -0
  137. data/db/migrate/20111022144725_create_line_items.rb +15 -0
  138. data/db/migrate/20111022234951_create_shops.rb +20 -0
  139. data/db/migrate/20111026193227_create_link_groups.rb +12 -0
  140. data/db/migrate/20111026193435_create_navigations.rb +10 -0
  141. data/db/migrate/20111031135810_create_links.rb +10 -0
  142. data/db/migrate/20111106193938_create_custom_fields.rb +10 -0
  143. data/db/migrate/20111106195112_create_custom_field_answers.rb +14 -0
  144. data/db/migrate/20111106201548_create_product_group_conditions.rb +12 -0
  145. data/db/migrate/20111107035350_create_creditcard_transactions.rb +15 -0
  146. data/db/migrate/20111109190754_create_addresses.rb +24 -0
  147. data/db/migrate/20111125173344_create_pictures.rb +16 -0
  148. data/db/migrate/20111201024408_create_shipping_methods.rb +16 -0
  149. data/db/migrate/20111202143154_create_shipping_zones.rb +17 -0
  150. data/db/migrate/20111203034020_create_payment_methods.rb +14 -0
  151. data/db/migrate/20111221190000_create_preferences.rb +14 -0
  152. data/db/migrate/20120105234047_create_shipments.rb +11 -0
  153. data/db/migrate/20120105234553_create_shipment_carriers.rb +11 -0
  154. data/db/migrate/20120606165355_create_delayed_jobs.rb +22 -0
  155. data/db/production.sqlite3 +0 -0
  156. data/db/schema.rb +265 -0
  157. data/db/seeds.rb +1 -0
  158. data/db/test.sqlite3 +0 -0
  159. data/lib/assets/javascripts/loading_state_for_buttons.js.coffee +3 -0
  160. data/lib/assets/javascripts/show_help_on_hover.js.coffee +2 -0
  161. data/lib/assets/javascripts/utils/autoresize.js.coffee +3 -0
  162. data/lib/assets/javascripts/utils/focus.js.coffee +3 -0
  163. data/lib/assets/javascripts/utils/formatNumber.js.coffee +25 -0
  164. data/lib/assets/javascripts/utils/formatPrice.js.coffee +24 -0
  165. data/lib/generators/nimbleshop/app/app_generator.rb +84 -0
  166. data/lib/generators/nimbleshop/app/templates/config/application.yml +61 -0
  167. data/lib/generators/nimbleshop/app/templates/config/initializers/airbrake.rb +3 -0
  168. data/lib/generators/nimbleshop/app/templates/config/initializers/cache_images.rb +4 -0
  169. data/lib/generators/nimbleshop/app/templates/config/initializers/carrierwave.rb +36 -0
  170. data/lib/generators/nimbleshop/app/templates/config/initializers/delayed_job.rb +15 -0
  171. data/lib/generators/nimbleshop/app/templates/config/initializers/setup_email.rb +24 -0
  172. data/lib/nimbleshop/core_ext/activerecord_base.rb +18 -0
  173. data/lib/nimbleshop/core_ext/filelessio.rb +4 -0
  174. data/lib/nimbleshop/core_ext/force_ssl.rb +26 -0
  175. data/lib/nimbleshop/core_ext/mustache_templater_handler.rb +10 -0
  176. data/lib/nimbleshop/engine.rb +23 -0
  177. data/lib/nimbleshop/permalink/builder.rb +46 -0
  178. data/lib/nimbleshop/processor/base.rb +51 -0
  179. data/lib/nimbleshop/processor.rb +3 -0
  180. data/lib/nimbleshop/product_group_search/base_field.rb +19 -0
  181. data/lib/nimbleshop/product_group_search/core_field_strategy.rb +31 -0
  182. data/lib/nimbleshop/product_group_search/custom_field_strategy.rb +39 -0
  183. data/lib/nimbleshop/product_group_search/date_field.rb +16 -0
  184. data/lib/nimbleshop/product_group_search/extension.rb +46 -0
  185. data/lib/nimbleshop/product_group_search/number_field.rb +17 -0
  186. data/lib/nimbleshop/product_group_search/text_field.rb +33 -0
  187. data/lib/nimbleshop/product_group_search.rb +74 -0
  188. data/lib/nimbleshop/sampledata/data.rb +246 -0
  189. data/lib/nimbleshop/sampledata/pictures/product1/pic1.jpg +0 -0
  190. data/lib/nimbleshop/sampledata/pictures/product2/pic1.jpg +0 -0
  191. data/lib/nimbleshop/sampledata/pictures/product2/pic2.jpg +0 -0
  192. data/lib/nimbleshop/sampledata/pictures/product3/pic1.jpg +0 -0
  193. data/lib/nimbleshop/sampledata/pictures/product3/pic2.jpg +0 -0
  194. data/lib/nimbleshop/sampledata/pictures/product3/pic3.jpg +0 -0
  195. data/lib/nimbleshop/sampledata/pictures/product3/pic4.jpg +0 -0
  196. data/lib/nimbleshop/sampledata/pictures/product3/pic5.jpg +0 -0
  197. data/lib/nimbleshop/sampledata/pictures/product4/pic1.jpg +0 -0
  198. data/lib/nimbleshop/sampledata/pictures/product4/pic2.jpg +0 -0
  199. data/lib/nimbleshop/sampledata/pictures/product5/pic1.jpg +0 -0
  200. data/lib/nimbleshop/sampledata/pictures/product5/pic2.jpg +0 -0
  201. data/lib/nimbleshop/sampledata/pictures/product6/pic1.jpg +0 -0
  202. data/lib/nimbleshop/sampledata/pictures/product6/pic10.jpg +0 -0
  203. data/lib/nimbleshop/sampledata/pictures/product6/pic11.jpg +0 -0
  204. data/lib/nimbleshop/sampledata/pictures/product6/pic12.jpg +0 -0
  205. data/lib/nimbleshop/sampledata/pictures/product6/pic13.jpg +0 -0
  206. data/lib/nimbleshop/sampledata/pictures/product6/pic14.jpg +0 -0
  207. data/lib/nimbleshop/sampledata/pictures/product6/pic15.jpg +0 -0
  208. data/lib/nimbleshop/sampledata/pictures/product6/pic16.jpg +0 -0
  209. data/lib/nimbleshop/sampledata/pictures/product6/pic17.jpg +0 -0
  210. data/lib/nimbleshop/sampledata/pictures/product6/pic2.jpg +0 -0
  211. data/lib/nimbleshop/sampledata/pictures/product6/pic3.jpg +0 -0
  212. data/lib/nimbleshop/sampledata/pictures/product6/pic4.jpg +0 -0
  213. data/lib/nimbleshop/sampledata/pictures/product6/pic5.jpg +0 -0
  214. data/lib/nimbleshop/sampledata/pictures/product6/pic6.jpg +0 -0
  215. data/lib/nimbleshop/sampledata/pictures/product6/pic7.jpg +0 -0
  216. data/lib/nimbleshop/sampledata/pictures/product6/pic8.jpg +0 -0
  217. data/lib/nimbleshop/sampledata/pictures/product6/pic9.jpg +0 -0
  218. data/lib/nimbleshop/sampledata/pictures/product7/pic1.jpg +0 -0
  219. data/lib/nimbleshop/sampledata/pictures/product7/pic2.jpg +0 -0
  220. data/lib/nimbleshop/sampledata/pictures/product7/pic3.jpg +0 -0
  221. data/lib/nimbleshop/sampledata/pictures/product8/pic1.jpg +0 -0
  222. data/lib/nimbleshop/sampledata/pictures/product8/pic2.jpg +0 -0
  223. data/lib/nimbleshop/sampledata/pictures/product8/pic3.jpg +0 -0
  224. data/lib/nimbleshop/sampledata/pictures/product8/pic4.jpg +0 -0
  225. data/lib/nimbleshop/sampledata/pictures/product8/pic5.jpg +0 -0
  226. data/lib/nimbleshop/sampledata/pictures/product8/pic6.jpg +0 -0
  227. data/lib/nimbleshop/sampledata/pictures/product8/pic7.jpg +0 -0
  228. data/lib/nimbleshop/sampledata/pictures/product8/pic8.jpg +0 -0
  229. data/lib/nimbleshop/sampledata/pictures/product9/pic1.jpg +0 -0
  230. data/lib/nimbleshop/sampledata/pictures/product9/pic2.jpg +0 -0
  231. data/lib/nimbleshop/util.rb +60 -0
  232. data/lib/nimbleshop/version.rb +18 -0
  233. data/lib/nimbleshop_core.rb +23 -0
  234. data/lib/tasks/localhost2public.rake +8 -0
  235. data/lib/tasks/setup.rake +26 -0
  236. data/test/factories/address_factory.rb +31 -0
  237. data/test/factories/creditcard_factory.rb +30 -0
  238. data/test/factories/custom_field_answer_factory.rb +6 -0
  239. data/test/factories/custom_field_factory.rb +21 -0
  240. data/test/factories/line_item_factory.rb +7 -0
  241. data/test/factories/link_factory.rb +6 -0
  242. data/test/factories/link_group_factory.rb +5 -0
  243. data/test/factories/navigation_factory.rb +6 -0
  244. data/test/factories/order_factory.rb +49 -0
  245. data/test/factories/payment_method_factory.rb +6 -0
  246. data/test/factories/payment_transaction_factory.rb +42 -0
  247. data/test/factories/picture_factory.rb +11 -0
  248. data/test/factories/product_group_condition_factory.rb +40 -0
  249. data/test/factories/product_group_factory.rb +5 -0
  250. data/test/factories/products_factory.rb +11 -0
  251. data/test/factories/shipment_carrier_factory.rb +6 -0
  252. data/test/factories/shipment_factory.rb +6 -0
  253. data/test/factories/shipping_method_factory.rb +15 -0
  254. data/test/factories/shipping_zone_factory.rb +5 -0
  255. data/test/factories/shop_factory.rb +8 -0
  256. data/test/fixtures/files/avatar.png +0 -0
  257. data/test/fixtures/link_groups.yml +13 -0
  258. data/test/fixtures/payment_methods.yml +39 -0
  259. data/test/fixtures/shops.yml +15 -0
  260. data/test/helpers/admin_helper_test.rb +37 -0
  261. data/test/helpers/nimbleshop_helper_test.rb +17 -0
  262. data/test/integration/admin/link_groups_acceptance_test.rb +39 -0
  263. data/test/integration/admin/orders_acceptance_test.rb +63 -0
  264. data/test/integration/admin/payment_methods_acceptance_test.rb +13 -0
  265. data/test/integration/admin/product_groups_acceptance_test.rb +89 -0
  266. data/test/integration/admin/products_acceptance_test.rb +105 -0
  267. data/test/integration/admin/shipping_methods_acceptance_test.rb +63 -0
  268. data/test/integration/admin/shipping_zones_acceptance_test.rb +16 -0
  269. data/test/integration/admin/shops_acceptance_test.rb +44 -0
  270. data/test/integration/checkout/cart_acceptance_test.rb +113 -0
  271. data/test/integration/checkout/payment_confirmation_acceptance_test.rb +24 -0
  272. data/test/integration/checkout/paypal_acceptance_test.rb +34 -0
  273. data/test/integration/checkout/shipping_address_acceptance_test.rb +91 -0
  274. data/test/integration/checkout/shipping_method_acceptance_test.rb +51 -0
  275. data/test/integration/homepage_acceptance_test.rb +24 -0
  276. data/test/integration/products_acceptance_test.rb +12 -0
  277. data/test/integration/static_pages_acceptance_test.rb +13 -0
  278. data/test/mailers/mailer_test.rb +25 -0
  279. data/test/rails_app/Gemfile +27 -0
  280. data/test/rails_app/Gemfile.lock +218 -0
  281. data/test/rails_app/Rakefile +10 -0
  282. data/test/rails_app/app/controllers/application_controller.rb +6 -0
  283. data/test/rails_app/app/helpers/application_helper.rb +3 -0
  284. data/test/rails_app/app/views/layouts/application.html.erb +10 -0
  285. data/test/rails_app/config/application.rb +25 -0
  286. data/test/rails_app/config/application.yml +61 -0
  287. data/test/rails_app/config/boot.rb +5 -0
  288. data/test/rails_app/config/database.yml +18 -0
  289. data/test/rails_app/config/environment.rb +5 -0
  290. data/test/rails_app/config/environments/development.rb +18 -0
  291. data/test/rails_app/config/environments/production.rb +33 -0
  292. data/test/rails_app/config/environments/test.rb +33 -0
  293. data/test/rails_app/config/initializers/backtrace_silencers.rb +7 -0
  294. data/test/rails_app/config/initializers/inflections.rb +2 -0
  295. data/test/rails_app/config/initializers/secret_token.rb +2 -0
  296. data/test/rails_app/config/routes.rb +10 -0
  297. data/test/rails_app/config.ru +4 -0
  298. data/test/rails_app/db/development.sqlite3 +0 -0
  299. data/test/rails_app/db/migrate/20100401102949_create_tables.rb +74 -0
  300. data/test/rails_app/db/schema.rb +52 -0
  301. data/test/rails_app/log/development.log +94 -0
  302. data/test/rails_app/log/test.log +0 -0
  303. data/test/rails_app/public/404.html +26 -0
  304. data/test/rails_app/public/422.html +26 -0
  305. data/test/rails_app/public/500.html +26 -0
  306. data/test/rails_app/public/favicon.ico +0 -0
  307. data/test/rails_app/script/rails +10 -0
  308. data/test/support/address_test_helper.rb +24 -0
  309. data/test/support/checkout_test_helper.rb +40 -0
  310. data/test/support/dbify_sql_helper.rb +12 -0
  311. data/test/support/images/cookware.jpg +0 -0
  312. data/test/support/must_be_like.rb +24 -0
  313. data/test/support/shipping_method_test_helper.rb +5 -0
  314. data/test/support/wait_for_ajax.rb +4 -0
  315. data/test/test_helper.rb +65 -0
  316. data/test/unit/address_test.rb +33 -0
  317. data/test/unit/country_shipping_zone_test.rb +17 -0
  318. data/test/unit/creditcard_test.rb +33 -0
  319. data/test/unit/custom_field_answer/field_test.rb +93 -0
  320. data/test/unit/order_test.rb +70 -0
  321. data/test/unit/payment_method/authorizedotnet_test.rb +21 -0
  322. data/test/unit/payment_method/paypalwp_test.rb +17 -0
  323. data/test/unit/payment_method/splitable_test.rb +18 -0
  324. data/test/unit/picture_test.rb +24 -0
  325. data/test/unit/processor/authorize_net_test.rb +236 -0
  326. data/test/unit/processor/paypal_test.rb +40 -0
  327. data/test/unit/processor/splitable_test.rb +123 -0
  328. data/test/unit/product_group_condition_test.rb +188 -0
  329. data/test/unit/product_group_test.rb +109 -0
  330. data/test/unit/product_test.rb +60 -0
  331. data/test/unit/shipping_cost_calculator_test.rb +19 -0
  332. data/test/unit/shipping_method_test.rb +197 -0
  333. data/test/unit/shop_test.rb +11 -0
  334. data/test/unit/tax_calculator_test.rb +13 -0
  335. data/test/vcr_cassettes/authorize_net/authorize-failure.yml +38 -0
  336. data/test/vcr_cassettes/authorize_net/authorize-success.yml +38 -0
  337. data/test/vcr_cassettes/authorize_net/capture-failure.yml +38 -0
  338. data/test/vcr_cassettes/authorize_net/capture-success.yml +38 -0
  339. data/test/vcr_cassettes/authorize_net/purchase-failure.yml +38 -0
  340. data/test/vcr_cassettes/authorize_net/purchase-success.yml +38 -0
  341. data/test/vcr_cassettes/authorize_net/refund-failure.yml +38 -0
  342. data/test/vcr_cassettes/authorize_net/refund-success.yml +38 -0
  343. data/test/vcr_cassettes/authorize_net/void-authorize.yml +38 -0
  344. data/test/vcr_cassettes/authorize_net/void-failure.yml +38 -0
  345. data/test/vcr_cassettes/authorize_net/void-success.yml +38 -0
  346. data/test/vcr_cassettes/splitable/split-create-failure.yml +48 -0
  347. data/test/vcr_cassettes/splitable/split-create-success.yml +50 -0
  348. data/test/vcr_cassettes/splitable/split-draft-create-failure.yml +50 -0
  349. data/test/vcr_cassettes/splitable/split-draft-create-success.yml +50 -0
  350. data/vendor/assets/javascripts/accounting.js +406 -0
  351. data/vendor/assets/javascripts/autoresize.js +275 -0
  352. data/vendor/assets/javascripts/jquery-1.7.1.js +9267 -0
  353. data/vendor/assets/javascripts/jquery-form.js +980 -0
  354. data/vendor/assets/javascripts/jquery-json.js +193 -0
  355. data/vendor/assets/javascripts/jquery-ui-1.8.16.js +11768 -0
  356. data/vendor/assets/javascripts/jquery-ujs.js +374 -0
  357. data/vendor/assets/javascripts/mustache.js +436 -0
  358. data/vendor/assets/javascripts/nested_form.js +51 -0
  359. metadata +740 -0
@@ -0,0 +1,17 @@
1
+ require 'test_helper'
2
+
3
+ class PaymentMethodPaypalwpTest < ActiveSupport::TestCase
4
+
5
+ test "validations" do
6
+ pm = NimbleshopPaypalwp::Paypalwp.new(name: 'Paypalwp', description: 'this is description')
7
+ refute pm.valid?
8
+ assert_equal ["Merchant email can't be blank", "Merchant email is invalid"], pm.errors.full_messages.sort
9
+ end
10
+
11
+ test "should save the record" do
12
+ pm = NimbleshopPaypalwp::Paypalwp.new(name: 'Paypalwp', merchant_email: 'merchant@example.com', description: 'this is description')
13
+ assert pm.save
14
+ assert_match /paypalwp/, pm.permalink
15
+ end
16
+
17
+ end
@@ -0,0 +1,18 @@
1
+ require 'test_helper'
2
+
3
+ class PaymentMethodSplitableTest < ActiveSupport::TestCase
4
+
5
+ test "validations" do
6
+ pm = NimbleshopSplitable::Splitable.new(name: 'Splitable', description: 'this is description')
7
+ refute pm.valid?
8
+ assert_equal ["Api key can't be blank"], pm.errors.full_messages.sort
9
+ end
10
+
11
+ test "should save the record" do
12
+ pm = NimbleshopSplitable::Splitable.new(name: 'Splitable', description: 'this is description')
13
+ pm.api_key = 'FWERSDEED093d'
14
+ assert pm.save
15
+ assert_match /splitable/, pm.permalink
16
+ end
17
+
18
+ end
@@ -0,0 +1,24 @@
1
+ require 'test_helper'
2
+
3
+ class PictureTest < ActiveSupport::TestCase
4
+
5
+ test 'validity of factory' do
6
+ create :picture
7
+ assert_equal 1, Picture.count
8
+ end
9
+
10
+ test "attaching picture to a product" do
11
+ product = create :product
12
+ assert_difference 'product.pictures(true).size' do
13
+ file = File.expand_path('../../fixtures/files/avatar.png', __FILE__)
14
+ product.attach_picture('avatar.png', file)
15
+ end
16
+ end
17
+
18
+ test 'deleting product should not delete picture' do
19
+ product = create :product
20
+ assert_no_difference 'Picture.count' do
21
+ product.destroy
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,236 @@
1
+ require 'test_helper'
2
+
3
+ module Processor
4
+ class NimbleshopAuthorizeNetAuthorizeTest < ActiveRecord::TestCase
5
+ setup do
6
+ @order = create(:order)
7
+ @order.stubs(:total_amount).returns(100.48)
8
+ @processor = NimbleshopAuthorizedotnet::Processor.new(@order)
9
+ end
10
+
11
+ test "when authorization succeeds" do
12
+ creditcard = build(:creditcard)
13
+
14
+ playcasette('authorize.net/authorize-success') do
15
+ assert_equal true, @processor.authorize(creditcard: creditcard)
16
+ end
17
+
18
+ @order.reload
19
+
20
+ transaction = @order.payment_transactions.last
21
+ assert_equal 'authorized', transaction.operation
22
+ assert_equal true, transaction.success
23
+ assert_equal NimbleshopAuthorizedotnet::Authorizedotnet.first, @order.payment_method
24
+ assert @order.authorized?
25
+ end
26
+
27
+ test "authorization fails when credit card number is not entered" do
28
+ creditcard = build(:creditcard, number: nil)
29
+ assert_equal false, @processor.authorize(creditcard: creditcard)
30
+ assert_equal 'Please enter credit card number', @processor.errors.first
31
+
32
+ @order.reload
33
+
34
+ assert_nil @order.payment_method
35
+ assert @order.abandoned?
36
+ end
37
+
38
+ test "authorization fails with invalid credit card number" do
39
+ creditcard = build(:creditcard, number: 2)
40
+
41
+ playcasette('authorize.net/authorize-failure') do
42
+ assert_equal false, @processor.authorize(creditcard: creditcard)
43
+ assert_equal 'Credit card was declined. Please try again!', @processor.errors.first
44
+ end
45
+
46
+ @order.reload
47
+
48
+ assert_nil @order.payment_method
49
+ assert @order.abandoned?
50
+ end
51
+ end
52
+
53
+ class AuthorizeNetCaptureTest < ActiveRecord::TestCase
54
+ setup do
55
+ @order = create(:order, payment_method: NimbleshopAuthorizedotnet::Authorizedotnet.first)
56
+ @order.stubs(:total_amount).returns(100.48)
57
+ @processor = NimbleshopAuthorizedotnet::Processor.new(@order)
58
+ creditcard = build(:creditcard)
59
+
60
+ playcasette('authorize.net/authorize-success') do
61
+ @processor.authorize(creditcard: creditcard)
62
+ end
63
+
64
+ @tsx_id = @order.payment_transactions.last.transaction_gid
65
+ end
66
+
67
+ test "when capture succeeds" do
68
+ creditcard = build(:creditcard)
69
+
70
+ playcasette('authorize.net/capture-success') do
71
+ assert_equal true, @processor.capture(transaction_gid: @tsx_id)
72
+ end
73
+
74
+ @order.reload
75
+ transaction = @order.payment_transactions.last
76
+ assert_equal 'captured', transaction.operation
77
+ assert_equal true, transaction.success
78
+ assert @order.purchased?
79
+ end
80
+
81
+ test "when capture fails" do
82
+ creditcard = build(:creditcard, number: 2)
83
+
84
+ playcasette('authorize.net/capture-failure') do
85
+ assert_equal false, @processor.capture(transaction_gid: @tsx_id)
86
+ assert_equal 'Capture failed', @processor.errors.first
87
+ end
88
+
89
+ @order.reload
90
+
91
+ transaction = @order.payment_transactions.last
92
+
93
+ assert_equal false, transaction.success
94
+ assert_equal 'captured', transaction.operation
95
+ assert @order.authorized?
96
+ end
97
+ end
98
+
99
+ class AuthorizeNetRefundTest < ActiveRecord::TestCase
100
+ setup do
101
+ @order = create(:order)
102
+ @order.stubs(:total_amount).returns(100.48)
103
+ @processor = NimbleshopAuthorizedotnet::Processor.new(@order)
104
+ creditcard = build(:creditcard)
105
+
106
+ playcasette('authorize.net/purchase-success') do
107
+ assert_equal true, @processor.purchase(creditcard: creditcard)
108
+ end
109
+
110
+ assert @order.reload.purchased?
111
+
112
+ @transaction = @order.payment_transactions.last
113
+ end
114
+
115
+ test "when refund succeeds" do
116
+
117
+ playcasette('authorize.net/refund-success') do
118
+ assert_equal true, @processor.refund(transaction_gid: @transaction.transaction_gid,
119
+ card_number: @transaction.metadata[:card_number])
120
+ end
121
+
122
+ @order.reload
123
+ transaction = @order.payment_transactions.last
124
+
125
+ assert_equal 'refunded', transaction.operation
126
+ assert_equal true, transaction.success
127
+ assert_equal NimbleshopAuthorizedotnet::Authorizedotnet.first, @order.payment_method
128
+ assert @order.refunded?
129
+ end
130
+
131
+ test "when refund fails" do
132
+
133
+ playcasette('authorize.net/refund-failure') do
134
+ assert_equal false, @processor.refund(transaction_gid: @transaction.transaction_gid, card_number: '1234')
135
+ end
136
+
137
+ @order.reload
138
+
139
+ transaction = @order.payment_transactions.last
140
+
141
+ assert_equal 'refunded', transaction.operation
142
+ assert_equal false, transaction.success
143
+ end
144
+ end
145
+
146
+ class AuthorizeNetVoidTest < ActiveRecord::TestCase
147
+ setup do
148
+ @order = create(:order)
149
+ @order.stubs(:total_amount).returns(100.48)
150
+ @processor = NimbleshopAuthorizedotnet::Processor.new(@order)
151
+ creditcard = build(:creditcard)
152
+
153
+ playcasette('authorize.net/authorize-success') do
154
+ assert_equal true, @processor.authorize(creditcard: creditcard)
155
+ end
156
+
157
+ @tsx_id = @order.payment_transactions.last.transaction_gid
158
+ end
159
+
160
+ test "when capture succeeds" do
161
+ playcasette('authorize.net/void-success') do
162
+ assert_equal true, @processor.void(transaction_gid: @tsx_id)
163
+ end
164
+
165
+ @order.reload
166
+ transaction = @order.payment_transactions.last
167
+
168
+ assert_equal 'voided', transaction.operation
169
+ assert_equal true, transaction.success
170
+ assert_equal NimbleshopAuthorizedotnet::Authorizedotnet.first, @order.payment_method
171
+ assert @order.voided?
172
+ end
173
+
174
+ test "when capture fails" do
175
+ playcasette('authorize.net/void-failure') do
176
+ assert_equal false, @processor.void(transaction_gid: @tsx_id)
177
+ end
178
+
179
+ @order.reload
180
+
181
+ transaction = @order.payment_transactions.last
182
+
183
+ assert_equal 'voided', transaction.operation
184
+ assert_equal false, transaction.success
185
+ end
186
+ end
187
+
188
+ class AuthorizeNetPurchaseTest < ActiveRecord::TestCase
189
+ setup do
190
+ @order = create(:order)
191
+ @order.stubs(:total_amount).returns(100.48)
192
+ @processor = NimbleshopAuthorizedotnet::Processor.new(@order)
193
+ end
194
+
195
+ test "when purchase succeeds" do
196
+ creditcard = build(:creditcard)
197
+
198
+ playcasette('authorize.net/purchase-success') do
199
+ assert_equal true, @processor.purchase(creditcard: creditcard)
200
+ end
201
+
202
+ @order.reload
203
+
204
+ transaction = @order.payment_transactions.last
205
+ assert_equal 'purchased', transaction.operation
206
+ assert_equal true, transaction.success
207
+ assert @order.purchased?
208
+ end
209
+
210
+ test "purchase fails when credit card number is not entered " do
211
+ creditcard = build(:creditcard, number: nil)
212
+
213
+ playcasette('authorize.net/purchase-failure') do
214
+ assert_equal false, @processor.purchase(creditcard: creditcard)
215
+ assert_equal 'Please enter credit card number', @processor.errors.first
216
+ end
217
+
218
+ assert @order.abandoned?
219
+ end
220
+
221
+ test "purchase fails when invalid credit card number is entered" do
222
+ creditcard = build(:creditcard, number: 2)
223
+
224
+ playcasette('authorize.net/purchase-failure') do
225
+ assert_equal false, @processor.purchase(creditcard: creditcard)
226
+ assert_equal 'Credit card was declined. Please try again!', @processor.errors.first
227
+ end
228
+
229
+ transaction = @order.payment_transactions.last
230
+
231
+ assert_equal false, transaction.success
232
+ assert_equal 'purchased', transaction.operation
233
+ assert @order.abandoned?
234
+ end
235
+ end
236
+ end
@@ -0,0 +1,40 @@
1
+ require 'test_helper'
2
+
3
+ module Processor
4
+ class PaypalAuthorizeTest < ActiveRecord::TestCase
5
+ def raw1
6
+ "mc_gross=152.73&invoice=54145619&protection_eligibility=Ineligible&item_number1=&payer_id=Q96HQCW3NMN8A&tax=1.73&payment_date=19%3A48%3A59+Apr+22%2C+2012+PDT&payment_status=Completed&charset=windows-1252&mc_shipping=0.00&mc_handling=10.00&first_name=buyer&mc_fee=4.73&notify_version=3.4&custom=&payer_status=verified&business=seller_1323037155_biz%40bigbinary.com&num_cart_items=1&mc_handling1=0.00&verify_sign=AAmQuqWvZCTtQW5vSunjl6MYb9xfACAPVvn0EpIPnon.Cyn5sYgI-bZB&payer_email=nimble_1333550340_per%40hotmail.com&mc_shipping1=0.00&tax1=0.00&txn_id=2LY704674J0179216&payment_type=instant&last_name=again&item_name1=Colorful+shoes&receiver_email=seller_1323037155_biz%40bigbinary.com&payment_fee=4.73&quantity1=1&receiver_id=EULE94DW3YTH4&txn_type=cart&mc_gross_1=141.00&mc_currency=USD&residence_country=US&test_ipn=1&transaction_subject=Shopping+CartColorful+shoes&payment_gross=152.73&ipn_track_id=72a7efbc940b7"
7
+ end
8
+
9
+ def raw_post(order_id, total)
10
+ "mc_gross=#{total}&invoice=#{order_id}&protection_eligibility=Ineligible&item_number1=&payer_id=UU9QTKRET6CCA&tax=0.23&payment_date=13%3A46%3A50+Apr+01%2C+2012+PDT&payment_status=Completed&charset=windows-1252&mc_shipping=0.00&mc_handling=0.00&first_name=venkata&mc_fee=0.63&notify_version=3.4&custom=&payer_status=verified&business=pvdsub_1332777111_biz%40hotmail.com&num_cart_items=1&mc_handling1=0.00&verify_sign=A97HaEBl1Z9n6y3FnK2ES7ntmCFAA42qVBV1tGxSqeM5XnO3fijruk.r&payer_email=pvdsub_1332813592_per%40hotmail.com&mc_shipping1=0.00&tax1=0.00&txn_id=48D08257JB6543456&payment_type=instant&last_name=pasupuleti&item_name1=Handmade+vibrant+bangles&receiver_email=pvdsub_1332777111_biz%40hotmail.com&payment_fee=0.63&quantity1=1&receiver_id=DT54LCN8WQM8S&txn_type=cart&mc_gross_1=11.00&mc_currency=USD&residence_country=US&test_ipn=1&transaction_subject=Shopping+CartHandmade+vibrant+bangles&payment_gross=11.23&ipn_track_id=b1f9dd1a56ae8"
11
+ end
12
+
13
+ setup do
14
+ @order = create(:order)
15
+ end
16
+
17
+ test "when authorization succeeds" do
18
+ processor = NimbleshopPaypalwp::Processor.new(raw_post: raw_post(@order.number, @order.total_amount))
19
+ playcasette('paypal/authorize-success') do
20
+ assert_equal true, processor.authorize
21
+ end
22
+
23
+ @order.reload
24
+
25
+ transaction = @order.payment_transactions.last
26
+ assert_equal 'authorized', transaction.operation
27
+ assert_equal true, transaction.success
28
+ assert_equal true, @order.authorized?
29
+ assert_equal "April 01, 2012 at 08:46 pm", @order.purchased_at.to_s(:long)
30
+ assert_equal NimbleshopPaypalwp::Paypalwp.first, @order.payment_method
31
+ assert_equal transaction.amount, @order.total_amount_in_cents
32
+ end
33
+
34
+ test "when authorization fails" do
35
+ processor = NimbleshopPaypalwp::Processor.new(raw_post: raw_post(@order.number, 10.48))
36
+ assert_equal false, processor.authorize
37
+ assert_nil @order.payment_method
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,123 @@
1
+ require 'test_helper'
2
+
3
+ module Processor
4
+ class SpllitableCreateTest < ActiveRecord::TestCase
5
+ setup do
6
+ @product = create(:product, price: 10)
7
+ @order = create(:order)
8
+ @request = stub(protocol: 'https', host_with_port: 'localhost:3000' )
9
+ end
10
+
11
+ test "when successful" do
12
+ @order.add(@product)
13
+ processor = NimbleshopSplitable::Processor.new(order: @order)
14
+
15
+ expected = "https://nimbleshop.splitable-draft.com/cws/0a0722b80ce3b662039884060ca49aaa7a1bb4135ea92fa47dc8"
16
+
17
+ playcasette('splitable/split-draft-create-success') do
18
+ error, split_url = processor.create_split(request: @request)
19
+ assert_nil error, "must be have no errors"
20
+ assert_equal expected, split_url
21
+ assert_equal NimbleshopSplitable::Splitable.first, @order.payment_method
22
+ assert @order.pending?
23
+ end
24
+ end
25
+
26
+ test "when failed" do
27
+ processor = NimbleshopSplitable::Processor.new(order: @order)
28
+
29
+ playcasette('splitable/split-draft-create-failure') do
30
+ error, split_url = processor.create_split(request: @request)
31
+ assert_nil split_url, "must not create split url"
32
+ assert_equal "Order must have atleast one line item", error
33
+ end
34
+ end
35
+ end
36
+
37
+ class SpllitablePaidTest < ActiveRecord::TestCase
38
+ def callback_params(order)
39
+ {
40
+ invoice: order.number,
41
+ payment_status: "paid",
42
+ api_secret: "82746e2d66cb8993",
43
+ transaction_id: "852973493383974"
44
+ }
45
+ end
46
+
47
+ setup do
48
+ @product = create(:product, price: 10)
49
+ @order = create(:order)
50
+ end
51
+
52
+ test "when transaction is paid" do
53
+ processor = NimbleshopSplitable::Processor.new(order: @order)
54
+ playcasette('splitable/split-draft-create-success') do
55
+ processor.create_split(request: @request)
56
+ end
57
+
58
+ assert @order.pending?
59
+
60
+ options = callback_params(@order)
61
+ processor = NimbleshopSplitable::Processor.new(invoice: options[:invoice])
62
+
63
+
64
+ processor.acknowledge(options)
65
+ transaction = @order.payment_transactions.last
66
+
67
+ assert_equal 'purchased', transaction.operation
68
+ assert_equal '852973493383974', transaction.transaction_gid
69
+ @order.reload
70
+ assert @order.purchased?
71
+ end
72
+ end
73
+
74
+ class SpllitableVoidTest < ActiveRecord::TestCase
75
+ def callback_params(order)
76
+ {
77
+ invoice: order.number,
78
+ payment_status: "cancelled",
79
+ api_secret: "82746e2d66cb8993",
80
+ transaction_id: "852973493383974"
81
+ }
82
+ end
83
+
84
+ setup do
85
+ @order = create(:order)
86
+ end
87
+
88
+ test "when transaction is cancelled" do
89
+ processor = NimbleshopSplitable::Processor.new(order: @order)
90
+ playcasette('splitable/split-draft-create-success') do
91
+ processor.create_split(request: @request)
92
+ end
93
+
94
+ assert @order.pending?
95
+
96
+ options = callback_params(@order)
97
+ processor = NimbleshopSplitable::Processor.new(invoice: options[:invoice])
98
+ assert processor.acknowledge(options)
99
+ transaction = @order.payment_transactions.last
100
+
101
+ assert_equal 'voided', transaction.operation
102
+ assert_equal '852973493383974', transaction.transaction_gid
103
+ @order.reload
104
+ assert @order.voided?
105
+ end
106
+
107
+ test "when an invalid order number is used" do
108
+ options = callback_params(@order)
109
+ processor = NimbleshopSplitable::Processor.new(invoice: '123')
110
+
111
+ assert_equal false, processor.acknowledge(options)
112
+ assert_equal ["Unknown invoice number"], processor.errors
113
+ end
114
+
115
+ test "when payment_status is blank" do
116
+ options = callback_params(@order).merge(payment_status: nil)
117
+ processor = NimbleshopSplitable::Processor.new(invoice: options[:invoice])
118
+
119
+ assert_equal false, processor.acknowledge(options)
120
+ assert_equal ["Parameter payment_status is blank"], processor.errors
121
+ end
122
+ end
123
+ end
@@ -0,0 +1,188 @@
1
+ require "test_helper"
2
+
3
+ class ProductGroupConditonTest < ActiveSupport::TestCase
4
+
5
+ test "valid operators for number" do
6
+ condition = build(:number_group_condition)
7
+
8
+ %w(lt gt lteq gteq).each do | operator |
9
+ condition.operator = operator
10
+ assert condition.valid?
11
+ end
12
+
13
+ %w(contains starts ends).each do | operator |
14
+ condition.operator = operator
15
+ refute condition.valid?
16
+ assert_equal ["is invalid"], condition.errors[:operator]
17
+ end
18
+ end
19
+
20
+ test "valid operators for text" do
21
+ condition = build(:text_group_condition)
22
+
23
+ %w(contains starts ends eq).each do | operator |
24
+ condition.operator = operator
25
+ assert condition.valid?
26
+ end
27
+
28
+ %w(lt gt lteq gteq).each do | operator |
29
+ condition.operator = operator
30
+ refute condition.valid?
31
+ end
32
+ end
33
+
34
+ test "valid operators for date" do
35
+ condition = build(:date_group_condition)
36
+
37
+ %w(lt gt lteq gteq).each do | operator |
38
+ condition.operator = operator
39
+ assert condition.valid?
40
+ end
41
+
42
+ %w(contains starts ends).each do | operator |
43
+ condition.operator = operator
44
+ refute condition.valid?
45
+ end
46
+ end
47
+
48
+ end
49
+
50
+
51
+ class ProductGroupConditionNumber < ActiveSupport::TestCase
52
+ setup do
53
+ @condition = build(:number_group_condition)
54
+ @product_group = ProductGroup.new
55
+ @condition.value = "4"
56
+ @product_group.product_group_conditions = [ @condition ]
57
+ end
58
+
59
+ test 'less than condition' do
60
+ @condition.operator = "lt"
61
+ expected = %{
62
+ SELECT products.* FROM "products" INNER JOIN "custom_field_answers" "answers0" ON "answers0"."product_id" = "products"."id" WHERE "answers0"."number_value" < 4.0 AND "products"."status" = 'active'
63
+ }
64
+ assert_must_be_like expected, @product_group.product_group_conditions.to_search_sql
65
+ end
66
+
67
+ test 'less than equal condition' do
68
+ @condition.operator = "lteq"
69
+ expected = %{
70
+ SELECT products.* FROM "products" INNER JOIN "custom_field_answers" "answers0" ON "answers0"."product_id" = "products"."id" WHERE "answers0"."number_value" <= 4.0 AND "products"."status" = 'active'
71
+ }
72
+ assert_must_be_like expected, @product_group.product_group_conditions.to_search_sql
73
+ end
74
+
75
+ test 'greater than operation' do
76
+ @condition.operator = "gt"
77
+ expected = %{
78
+ SELECT products.* FROM "products" INNER JOIN "custom_field_answers" "answers0" ON "answers0"."product_id" = "products"."id" WHERE "answers0"."number_value" > 4.0 AND "products"."status" = 'active'
79
+ }
80
+ assert_must_be_like expected, @product_group.product_group_conditions.to_search_sql
81
+ end
82
+
83
+ test 'greater than equal condition' do
84
+ @condition.operator = "gteq"
85
+ expected = %{
86
+ SELECT products.* FROM "products" INNER JOIN "custom_field_answers" "answers0" ON "answers0"."product_id" = "products"."id" WHERE "answers0"."number_value" >= 4.0 AND "products"."status" = 'active'
87
+ }
88
+ assert_must_be_like expected, @product_group.product_group_conditions.to_search_sql
89
+ end
90
+
91
+ test 'equal operation' do
92
+ @condition.operator = "eq"
93
+ expected = %{
94
+ SELECT products.* FROM "products" INNER JOIN "custom_field_answers" "answers0" ON "answers0"."product_id" = "products"."id" WHERE "answers0"."number_value" = 4.0 AND "products"."status" = 'active'
95
+ }
96
+ assert_must_be_like expected, @product_group.product_group_conditions.to_search_sql
97
+ end
98
+ end
99
+
100
+ class ProductGroupConditionWithMultipleConditions < ActiveSupport::TestCase
101
+
102
+ include DbifySqlHelper
103
+
104
+ setup do
105
+ @condition1 = build :number_group_condition
106
+ @condition2 = build :text_group_condition
107
+ @product_group = ProductGroup.new
108
+
109
+ @condition1.value = "4.34"
110
+ @condition2.value = "george"
111
+ end
112
+
113
+ test "should handle less than operation and contains" do
114
+ @condition1.operator = "lt"
115
+ @condition2.operator = "contains"
116
+ @product_group.product_group_conditions = [ @condition1, @condition2 ]
117
+ search_sql = @product_group.product_group_conditions.to_search_sql
118
+ expected_sql = %{
119
+ SELECT products.* FROM "products" INNER JOIN "custom_field_answers" "answers0" ON "answers0"."product_id" = "products"."id" INNER JOIN "custom_field_answers" "answers1" ON "answers1"."product_id" = "products"."id" WHERE "answers0"."number_value" < 4.34 AND "answers1"."value" LIKE '%george%' AND "products"."status" = 'active'
120
+ }
121
+ assert_must_be_like dbify_sql(expected_sql), search_sql
122
+ end
123
+
124
+ test "should handle less than equal operation and starts with" do
125
+ @condition1.operator = "lteq"
126
+ @condition2.operator = "starts"
127
+ @product_group.product_group_conditions = [ @condition1, @condition2 ]
128
+ search_sql = @product_group.product_group_conditions.to_search_sql
129
+
130
+ expected_sql = %{
131
+ SELECT products.* FROM "products" INNER JOIN "custom_field_answers" "answers0" ON "answers0"."product_id" = "products"."id" INNER JOIN "custom_field_answers" "answers1" ON "answers1"."product_id" = "products"."id" WHERE "answers0"."number_value" <= 4.34 AND "answers1"."value" LIKE 'george%' AND "products"."status" = 'active'
132
+ }
133
+ assert_must_be_like dbify_sql(expected_sql), search_sql
134
+ end
135
+
136
+ test "should handle greater than operation and ends with" do
137
+ @condition1.operator = "gt"
138
+ @condition2.operator = "ends"
139
+ @product_group.product_group_conditions = [ @condition1, @condition2 ]
140
+ search_sql = @product_group.product_group_conditions.to_search_sql
141
+ expected_sql = %{
142
+ SELECT products.* FROM "products" INNER JOIN "custom_field_answers" "answers0" ON "answers0"."product_id" = "products"."id" INNER JOIN "custom_field_answers" "answers1" ON "answers1"."product_id" = "products"."id" WHERE "answers0"."number_value" > 4.34 AND "answers1"."value" LIKE '%george' AND "products"."status" = 'active'
143
+ }
144
+ assert_must_be_like dbify_sql(expected_sql), search_sql
145
+ end
146
+
147
+ test "should handle greater than equal operation" do
148
+ @condition1.operator = "gteq"
149
+ @condition2.operator = "eq"
150
+ @product_group.product_group_conditions = [ @condition1, @condition2 ]
151
+ search_sql = @product_group.product_group_conditions.to_search_sql
152
+ expected_sql = %{
153
+ SELECT products.* FROM "products" INNER JOIN "custom_field_answers" "answers0" ON "answers0"."product_id" = "products"."id" INNER JOIN "custom_field_answers" "answers1" ON "answers1"."product_id" = "products"."id" WHERE "answers0"."number_value" >= 4.34 AND "answers1"."value" LIKE 'george' AND "products"."status" = 'active'
154
+ }
155
+ assert_must_be_like dbify_sql(expected_sql), search_sql
156
+ end
157
+
158
+ test "should handle equal operation and equal" do
159
+ @condition1.operator = "eq"
160
+ @condition2.operator = "eq"
161
+ @product_group.product_group_conditions = [ @condition1, @condition2 ]
162
+ search_sql = @product_group.product_group_conditions.to_search_sql
163
+ expected_sql = %{
164
+ SELECT products.* FROM "products" INNER JOIN "custom_field_answers" "answers0" ON "answers0"."product_id" = "products"."id" INNER JOIN "custom_field_answers" "answers1" ON "answers1"."product_id" = "products"."id" WHERE "answers0"."number_value" = 4.34 AND "answers1"."value" LIKE 'george' AND "products"."status" = 'active'
165
+ }
166
+
167
+ assert_must_be_like dbify_sql(expected_sql), search_sql
168
+ end
169
+
170
+ test "with price_group_condition search" do
171
+ @condition3 = create :price_group_condition
172
+ @condition1.value = "4.34"
173
+ @condition2.value = "george"
174
+ @condition3.value = "19.99"
175
+ @condition1.operator = "lt"
176
+ @condition2.operator = "starts"
177
+ @condition3.operator = "gteq"
178
+ @product_group.product_group_conditions = [ @condition1, @condition2, @condition3 ]
179
+ search_sql = @product_group.product_group_conditions.to_search_sql
180
+
181
+ expected_sql = %{
182
+ SELECT products.* FROM "products" INNER JOIN "custom_field_answers" "answers0" ON "answers0"."product_id" = "products"."id" INNER JOIN "custom_field_answers" "answers1" ON "answers1"."product_id" = "products"."id" WHERE "answers0"."number_value" < 4.34 AND "answers1"."value" LIKE 'george%' AND "products"."price" >= 19.99 AND "products"."status" = 'active'
183
+ }
184
+
185
+ assert_must_be_like dbify_sql(expected_sql), search_sql
186
+ end
187
+
188
+ end