trollied 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (144) hide show
  1. data/.document +5 -0
  2. data/.gitignore +21 -0
  3. data/LICENSE +294 -0
  4. data/README.rdoc +96 -0
  5. data/Rakefile +55 -0
  6. data/VERSION +1 -0
  7. data/app/controllers/line_items_controller.rb +168 -0
  8. data/app/controllers/notes_controller.rb +121 -0
  9. data/app/controllers/orders_controller.rb +210 -0
  10. data/app/controllers/trolleys_controller.rb +26 -0
  11. data/app/helpers/gets_trollied_helper.rb +31 -0
  12. data/app/helpers/line_items_helper.rb +5 -0
  13. data/app/helpers/orders_helper.rb +184 -0
  14. data/app/models/line_item.rb +14 -0
  15. data/app/models/note.rb +15 -0
  16. data/app/models/order.rb +29 -0
  17. data/app/models/trolley.rb +51 -0
  18. data/app/views/line_items/_form.html.erb +8 -0
  19. data/app/views/line_items/_line_item.html.erb +12 -0
  20. data/app/views/line_items/new.html.erb +11 -0
  21. data/app/views/notes/_form.html.erb +7 -0
  22. data/app/views/notes/_new.html.erb +14 -0
  23. data/app/views/notes/_note.html.erb +4 -0
  24. data/app/views/notes/index.html.erb +13 -0
  25. data/app/views/notes/new.html.erb +5 -0
  26. data/app/views/orders/_date_pickers.html.erb +15 -0
  27. data/app/views/orders/_order.html.erb +53 -0
  28. data/app/views/orders/index.html.erb +22 -0
  29. data/app/views/orders/show.html.erb +14 -0
  30. data/app/views/trolleys/_orders.html.erb +13 -0
  31. data/app/views/trolleys/show.html.erb +16 -0
  32. data/config/locales/en.yml +115 -0
  33. data/config/routes.rb +8 -0
  34. data/generators/trollied_migrations/USAGE +2 -0
  35. data/generators/trollied_migrations/templates/line_items_migration.rb +16 -0
  36. data/generators/trollied_migrations/templates/notes_migration.rb +15 -0
  37. data/generators/trollied_migrations/templates/orders_migration.rb +15 -0
  38. data/generators/trollied_migrations/templates/trolleys_migration.rb +14 -0
  39. data/generators/trollied_migrations/trollied_migrations_generator.rb +13 -0
  40. data/lib/gets_trollied.rb +38 -0
  41. data/lib/gets_trollied_controller_helpers.rb +29 -0
  42. data/lib/has_trolley.rb +42 -0
  43. data/lib/has_trolley_controller_helpers.rb +43 -0
  44. data/lib/order_status.rb +121 -0
  45. data/lib/trollied.rb +5 -0
  46. data/rails/init.rb +10 -0
  47. data/test/full_2_3_5_app_with_tests/.gitignore +27 -0
  48. data/test/full_2_3_5_app_with_tests/README +1 -0
  49. data/test/full_2_3_5_app_with_tests/Rakefile +10 -0
  50. data/test/full_2_3_5_app_with_tests/app/controllers/application_controller.rb +14 -0
  51. data/test/full_2_3_5_app_with_tests/app/controllers/items_controller.rb +85 -0
  52. data/test/full_2_3_5_app_with_tests/app/controllers/user_controller.rb +2 -0
  53. data/test/full_2_3_5_app_with_tests/app/helpers/application_helper.rb +3 -0
  54. data/test/full_2_3_5_app_with_tests/app/helpers/items_helper.rb +2 -0
  55. data/test/full_2_3_5_app_with_tests/app/helpers/user_helper.rb +2 -0
  56. data/test/full_2_3_5_app_with_tests/app/models/item.rb +4 -0
  57. data/test/full_2_3_5_app_with_tests/app/models/user.rb +3 -0
  58. data/test/full_2_3_5_app_with_tests/app/views/items/edit.html.erb +20 -0
  59. data/test/full_2_3_5_app_with_tests/app/views/items/index.html.erb +22 -0
  60. data/test/full_2_3_5_app_with_tests/app/views/items/new.html.erb +19 -0
  61. data/test/full_2_3_5_app_with_tests/app/views/items/show.html.erb +13 -0
  62. data/test/full_2_3_5_app_with_tests/app/views/layouts/application.html.erb +19 -0
  63. data/test/full_2_3_5_app_with_tests/app/views/layouts/items.html.erb +19 -0
  64. data/test/full_2_3_5_app_with_tests/config/boot.rb +110 -0
  65. data/test/full_2_3_5_app_with_tests/config/database.yml +22 -0
  66. data/test/full_2_3_5_app_with_tests/config/environment.rb +57 -0
  67. data/test/full_2_3_5_app_with_tests/config/environments/development.rb +17 -0
  68. data/test/full_2_3_5_app_with_tests/config/environments/production.rb +28 -0
  69. data/test/full_2_3_5_app_with_tests/config/environments/test.rb +28 -0
  70. data/test/full_2_3_5_app_with_tests/config/initializers/backtrace_silencers.rb +7 -0
  71. data/test/full_2_3_5_app_with_tests/config/initializers/inflections.rb +10 -0
  72. data/test/full_2_3_5_app_with_tests/config/initializers/mime_types.rb +5 -0
  73. data/test/full_2_3_5_app_with_tests/config/initializers/new_rails_defaults.rb +21 -0
  74. data/test/full_2_3_5_app_with_tests/config/initializers/session_store.rb +15 -0
  75. data/test/full_2_3_5_app_with_tests/config/locales/en.yml +4 -0
  76. data/test/full_2_3_5_app_with_tests/config/locales/fr.yml +4 -0
  77. data/test/full_2_3_5_app_with_tests/config/locales/zh.yml +4 -0
  78. data/test/full_2_3_5_app_with_tests/config/locales.yml +5 -0
  79. data/test/full_2_3_5_app_with_tests/config/routes.rb +8 -0
  80. data/test/full_2_3_5_app_with_tests/config.ru +6 -0
  81. data/test/full_2_3_5_app_with_tests/db/migrate/20100407010602_create_items.rb +13 -0
  82. data/test/full_2_3_5_app_with_tests/db/migrate/20110426030509_create_users.rb +13 -0
  83. data/test/full_2_3_5_app_with_tests/db/migrate/20110426033906_create_trolleys.rb +14 -0
  84. data/test/full_2_3_5_app_with_tests/db/migrate/20110426033907_create_orders.rb +15 -0
  85. data/test/full_2_3_5_app_with_tests/db/migrate/20110426033908_create_line_items.rb +16 -0
  86. data/test/full_2_3_5_app_with_tests/db/migrate/20110615234040_create_notes.rb +15 -0
  87. data/test/full_2_3_5_app_with_tests/db/schema.rb +56 -0
  88. data/test/full_2_3_5_app_with_tests/db/seeds.rb +7 -0
  89. data/test/full_2_3_5_app_with_tests/doc/README_FOR_APP +2 -0
  90. data/test/full_2_3_5_app_with_tests/public/404.html +30 -0
  91. data/test/full_2_3_5_app_with_tests/public/422.html +30 -0
  92. data/test/full_2_3_5_app_with_tests/public/500.html +30 -0
  93. data/test/full_2_3_5_app_with_tests/public/favicon.ico +0 -0
  94. data/test/full_2_3_5_app_with_tests/public/images/rails.png +0 -0
  95. data/test/full_2_3_5_app_with_tests/public/index.html +275 -0
  96. data/test/full_2_3_5_app_with_tests/public/javascripts/application.js +2 -0
  97. data/test/full_2_3_5_app_with_tests/public/javascripts/controls.js +963 -0
  98. data/test/full_2_3_5_app_with_tests/public/javascripts/dragdrop.js +973 -0
  99. data/test/full_2_3_5_app_with_tests/public/javascripts/effects.js +1128 -0
  100. data/test/full_2_3_5_app_with_tests/public/javascripts/prototype.js +4320 -0
  101. data/test/full_2_3_5_app_with_tests/public/robots.txt +5 -0
  102. data/test/full_2_3_5_app_with_tests/public/stylesheets/scaffold.css +54 -0
  103. data/test/full_2_3_5_app_with_tests/script/about +4 -0
  104. data/test/full_2_3_5_app_with_tests/script/console +3 -0
  105. data/test/full_2_3_5_app_with_tests/script/dbconsole +3 -0
  106. data/test/full_2_3_5_app_with_tests/script/destroy +3 -0
  107. data/test/full_2_3_5_app_with_tests/script/generate +3 -0
  108. data/test/full_2_3_5_app_with_tests/script/performance/benchmarker +3 -0
  109. data/test/full_2_3_5_app_with_tests/script/performance/profiler +3 -0
  110. data/test/full_2_3_5_app_with_tests/script/plugin +3 -0
  111. data/test/full_2_3_5_app_with_tests/script/runner +3 -0
  112. data/test/full_2_3_5_app_with_tests/script/server +3 -0
  113. data/test/full_2_3_5_app_with_tests/test/factories.rb +22 -0
  114. data/test/full_2_3_5_app_with_tests/test/functional/line_items_controller_test.rb +69 -0
  115. data/test/full_2_3_5_app_with_tests/test/functional/orders_controller_test.rb +75 -0
  116. data/test/full_2_3_5_app_with_tests/test/integration/gets_trollied_test.rb +38 -0
  117. data/test/full_2_3_5_app_with_tests/test/integration/order_test.rb +79 -0
  118. data/test/full_2_3_5_app_with_tests/test/integration/trolley_test.rb +71 -0
  119. data/test/full_2_3_5_app_with_tests/test/performance/browsing_test.rb +9 -0
  120. data/test/full_2_3_5_app_with_tests/test/selenium.rb +83 -0
  121. data/test/full_2_3_5_app_with_tests/test/test_helper.rb +54 -0
  122. data/test/full_2_3_5_app_with_tests/test/unit/gets_trollied_test.rb +29 -0
  123. data/test/full_2_3_5_app_with_tests/test/unit/helpers/gets_trollied_helper_test.rb +75 -0
  124. data/test/full_2_3_5_app_with_tests/test/unit/helpers/orders_helper_test.rb +34 -0
  125. data/test/full_2_3_5_app_with_tests/test/unit/line_item_test.rb +28 -0
  126. data/test/full_2_3_5_app_with_tests/test/unit/note_test.rb +14 -0
  127. data/test/full_2_3_5_app_with_tests/test/unit/order_test.rb +65 -0
  128. data/test/full_2_3_5_app_with_tests/test/unit/trolley_test.rb +80 -0
  129. data/test/full_2_3_5_app_with_tests/tmp/restart.txt +0 -0
  130. data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/init.rb +1 -0
  131. data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/lib/routing_filter/base.rb +31 -0
  132. data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/lib/routing_filter/force_extension.rb +57 -0
  133. data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/lib/routing_filter/locale.rb +70 -0
  134. data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/lib/routing_filter/pagination.rb +33 -0
  135. data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/lib/routing_filter/uuid_token.rb +78 -0
  136. data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/lib/routing_filter.rb +94 -0
  137. data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/spec/force_extension_spec.rb +65 -0
  138. data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/spec/generation_spec.rb +367 -0
  139. data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/spec/pagination_extension_spec.rb +19 -0
  140. data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/spec/recognition_spec.rb +76 -0
  141. data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/spec/routing_filter_spec.rb +114 -0
  142. data/test/full_2_3_5_app_with_tests/vendor/plugins/routing-filter/spec/spec_helper.rb +108 -0
  143. data/test/helper.rb +10 -0
  144. metadata +345 -0
@@ -0,0 +1,12 @@
1
+ <tr>
2
+ <td><%= link_to_purchasable_in(line_item) -%></td>
3
+ <% if can_delete_line_item?(order) -%>
4
+ <td>
5
+ <%= link_to t('line_items.line_item.delete'), { :controller => :orders,
6
+ :action => :destroy,
7
+ :id => line_item,
8
+ :order_id => order,
9
+ :trolley_id => trolley },
10
+ :confirm => t('line_items.line_item.are_you_sure'), :method => :delete %></td>
11
+ <% end -%>
12
+ </tr>
@@ -0,0 +1,11 @@
1
+ <% @button_text = t("line_items.new.confirm")
2
+ @title = t("line_items.new.confirm_order")
3
+ -%>
4
+
5
+ <h1><%= @title -%></h1>
6
+
7
+ <% form_for([@purchasable_item, @line_item]) do |f| %>
8
+
9
+ <%= render :partial => f -%>
10
+
11
+ <% end %>
@@ -0,0 +1,7 @@
1
+ <%= form.error_messages %>
2
+
3
+ <%= form.hidden_field :user_id, :value => user.id -%>
4
+
5
+ <%= form.text_area :body, { :cols => 90, :rows => 5 } %>
6
+
7
+ <%= form.submit t(".send") %>
@@ -0,0 +1,14 @@
1
+ <% note ||= order.notes.new
2
+ add_note_msg = t('.add_note_to_order_for_user')
3
+ add_note_msg = t('.add_note_to_order_for_admin') unless current_user == order.user -%>
4
+
5
+ <div class="note-form" id="note-form-for-<%= order.id -%>">
6
+
7
+ <h4><%= add_note_msg -%></h4>
8
+
9
+ <% form_for([order, note]) do |f| %>
10
+
11
+ <%= render :partial => 'notes/form', :locals => { :form => f, :user => current_user } -%>
12
+
13
+ <% end %>
14
+ </div>
@@ -0,0 +1,4 @@
1
+ <li class="note-body">
2
+ <%= link_to_profile_for(note.user) -%> <%= t '.said' -%>
3
+ <%= note.body -%>
4
+ </li>
@@ -0,0 +1,13 @@
1
+ <% @title = t(".title") -%>
2
+
3
+ <h1><%= @title -%></h1>
4
+
5
+ <% if @notes.size > 0 -%>
6
+ <h2><%= t(".notes") -%></h2>
7
+
8
+ <%= render @notes -%>
9
+
10
+ <% else -%>
11
+ <p><%= t(".no_notes") %></p>
12
+ <% end -%>
13
+
@@ -0,0 +1,5 @@
1
+ <% @title = t(".title") -%>
2
+
3
+ <h1><%= @title -%></h1>
4
+
5
+ <% render :partial => 'new', :locals => { :order => @order, :note =>@note } -%>
@@ -0,0 +1,15 @@
1
+ <% if Order.count > 0 -%>
2
+ <div class="date-form">
3
+ <% form_tag url_for_options_for_orders_index, :method => 'get' do %>
4
+ <%= hidden_field_tag 'state', @state if @state %>
5
+ <%= hidden_field_tag 'user', @user if @user %>
6
+ <%= hidden_field_tag 'trolley_id', @trolley.id if @trolley %>
7
+
8
+ <label><%= t '.from' -%></label>
9
+ <%= text_field_tag 'from', @from, :class => 'date-picker' %>
10
+ <label><%= t '.until' -%></label>
11
+ <%= text_field_tag 'until', @until, :class => 'date-picker' %>
12
+ <%= submit_tag t '.update' %>
13
+ <% end %>
14
+ </div>
15
+ <% end -%>
@@ -0,0 +1,53 @@
1
+ <% trolley ||= order.trolley -%>
2
+
3
+ <fieldset class="order">
4
+
5
+ <% if params[:controller] == 'orders' -%>
6
+ <h3><%= t '.user' -%> <%= link_to_orders_for(order.user) -%></h3>
7
+ <% end -%>
8
+
9
+ <table class="order">
10
+ <tr>
11
+ <th abbr="Line Item"><%= t '.purchasable_item_description' %></th>
12
+ </tr>
13
+
14
+ <%= render :partial => 'line_items/line_item', :collection => order.line_items, :locals => { :order => order, :trolley => trolley } -%>
15
+
16
+ <% if order.current? -%>
17
+ <tr>
18
+ <td><%= button_to_checkout order -%></td>
19
+ <td><%= button_to_clear order -%></td>
20
+ </tr>
21
+ <% end -%>
22
+
23
+ <% if order.in_process? -%>
24
+ <tr>
25
+ <td><%= button_to_cancel order -%></td>
26
+
27
+ <% if can_trigger_fulfilled_without_acceptance? -%>
28
+ <td><%= button_to_fulfilled_without_acceptance order -%></td>
29
+ <% end -%>
30
+ </tr>
31
+ <% end -%>
32
+
33
+ <% if order.ready? && can_trigger_finish? -%>
34
+ <tr>
35
+ <td><%= button_to_finish order -%></td>
36
+ </tr>
37
+ <% end -%>
38
+
39
+ </table>
40
+
41
+ </fieldset>
42
+
43
+ <% if order.notes.size != 0 -%>
44
+ <h3><%= t('.order_notes') -%></h3>
45
+ <% end -%>
46
+
47
+ <ul class="notes" id="notes-for-<%= order.id -%>">
48
+ <% if order.notes.size != 0 -%>
49
+ <%= render :partial => 'notes/note', :collection => order.notes -%>
50
+ <% end -%>
51
+ </ul>
52
+
53
+ <%= render :partial => 'notes/new', :locals => { :order => order, :user => current_user } if order.may_note? -%>
@@ -0,0 +1,22 @@
1
+ <% @title = t("orders.index.title") -%>
2
+
3
+ <h1><%= @title -%></h1>
4
+
5
+ <% if Order.count > 0 -%>
6
+ <h3><%= t '.filters' -%></h3>
7
+ <% end -%>
8
+
9
+ <%= state_links -%>
10
+ <%= render :partial => 'date_pickers' -%>
11
+
12
+ <% if @orders.size > 0 -%>
13
+
14
+ <h2><%= orders_state_headline -%><%= clear_extra_params -%></h2>
15
+
16
+ <%= render :partial => 'orders/order', :collection => @orders, :locals => { :trolley => @trolley, :status => @state } -%>
17
+
18
+ <div id="prev-next"><%= will_paginate @orders, :params => params %></div>
19
+ <% else -%>
20
+ <p><%= t("orders.index.no_orders") %></p>
21
+ <% end -%>
22
+
@@ -0,0 +1,14 @@
1
+ <%
2
+ if current_user == @order.user
3
+ @title = t(".your_order")
4
+ else
5
+ # TODO: interpolate user name
6
+ # (means name method has to be implemented for user model)
7
+ @title = t(".for_user_title", :name => @order.user.trolley_user_display_name)
8
+ end
9
+ -%>
10
+
11
+ <h1><%= @title -%></h1>
12
+
13
+ <%= render @order -%>
14
+
@@ -0,0 +1,13 @@
1
+ <% if @trolley.orders.send("with_state_#{status}".to_sym).size > 0 -%>
2
+
3
+ <h2><%= t("trolleys.orders.#{status}") -%></h2>
4
+
5
+ <%= render :partial => 'orders/order',
6
+ :collection => @trolley.orders.send("with_state_#{status}"),
7
+ :locals => { :trolley => trolley, :status => status } -%>
8
+
9
+ <% elsif status == 'current' -%>
10
+ <h2><%= t("trolleys.orders.current") -%></h2>
11
+ <p><%= t("trolleys.orders.none_pending") %></p>
12
+ <% end -%>
13
+
@@ -0,0 +1,16 @@
1
+ <%
2
+ if current_user == @trollied_user
3
+ @title = t(".your_title")
4
+ else
5
+ # TODO: interpolate user name
6
+ # (means name method has to be implemented for user model)
7
+ @title = t(".for_user_title", :name => @trollied_user.trolley_user_display_name)
8
+ end
9
+ -%>
10
+
11
+ <h1><%= @title -%></h1>
12
+
13
+ <% %w(current user_review ready in_process completed).each do |status| -%>
14
+ <%= render :partial => 'orders', :locals => { :status => status, :trolley => @trolley } -%>
15
+ <% end -%>
16
+
@@ -0,0 +1,115 @@
1
+ en:
2
+ base:
3
+ cart: "cart"
4
+ shopping_cart: "shopping cart"
5
+ line_item:
6
+ already_in_order: "has already been placed"
7
+ line_items:
8
+ new:
9
+ confirm: "Confirm"
10
+ confirm_order: "Confirm Order"
11
+ edit:
12
+ update: "Update"
13
+ form:
14
+ helpers:
15
+ index:
16
+ are_you_sure: "Are you sure?"
17
+ back: "Back"
18
+ delete: "Delete"
19
+ edit: "Edit"
20
+ new: "New Line Item"
21
+ line_item:
22
+ delete: "Delete"
23
+ are_you_sure: "Are you sure?"
24
+ show:
25
+ edit: "Edit"
26
+ translations: "Translations"
27
+ controllers:
28
+ created: "Added to order"
29
+ updated: "Updated in order"
30
+ deleted: "Deleted from order"
31
+ notes:
32
+ controllers:
33
+ created: "Note created."
34
+ form:
35
+ send: "Send"
36
+ note:
37
+ said: "said"
38
+ new:
39
+ add_note_to_order_for_admin: "Add a note about this order for staff."
40
+ add_note_to_order_for_user: "Add a note about this order for the order's owner."
41
+ orders:
42
+ edit:
43
+ update: "Update"
44
+ date_pickers:
45
+ from: "From:"
46
+ until: "Until:"
47
+ update: "Update wth Date Filter"
48
+ form:
49
+ helpers:
50
+ by: "by"
51
+ cancelled_orders: "Cancelled Orders"
52
+ clear_params: "clear extra settings"
53
+ completed_orders: "Completed Orders"
54
+ current_orders: "Current Orders"
55
+ from: "from"
56
+ in_process_orders: "Orders Awaiting processing"
57
+ ready_orders: "Ready Orders"
58
+ until: "until"
59
+ user_review_orders: "Orders needing user attention"
60
+ index:
61
+ are_you_sure: "Are you sure?"
62
+ back: "Back"
63
+ cancelled: "cancelled"
64
+ completed: "completed"
65
+ current: "current"
66
+ delete: "Delete"
67
+ edit: "Edit"
68
+ filters: "Filters:"
69
+ in_process: "Awaiting processing"
70
+ new: "New Order"
71
+ no_orders: "No orders match your criteria."
72
+ ready: "ready"
73
+ title: "Orders"
74
+ user_review: "needing user attention"
75
+ new:
76
+ create: "Create"
77
+ order:
78
+ are_you_sure: "Are you sure?"
79
+ cancel: "Cancel"
80
+ checkout: "Checkout"
81
+ destroy: "Clear all"
82
+ finish: "Mark as completed"
83
+ fulfilled_without_acceptance: "Mark as ready"
84
+ order_notes: "Notes for this order:"
85
+ purchasable_item_description: "Item"
86
+ user: "User:"
87
+ show:
88
+ your_title: "Your Order"
89
+ for_user_title: "Order for {{name}}"
90
+ controllers:
91
+ change_to_cancel: "Order Cancelled"
92
+ change_to_checkout: "Order Checked Out"
93
+ change_to_finish: "Order Completed"
94
+ change_to_fulfilled_without_acceptance: "Order Ready"
95
+ created: "Created order"
96
+ updated: "Updated order"
97
+ deleted: "Deleted order"
98
+ checkout: "Your order has now been placed."
99
+ trolleys:
100
+ helpers:
101
+ orders:
102
+ cancelled: "Cancelled Orders"
103
+ completed: "Completed Orders"
104
+ current: "Current Orders"
105
+ in_process: "Awaiting processing"
106
+ none_pending: "No orders pending."
107
+ ready: "Ready Orders"
108
+ user_review: "Orders needing your attention"
109
+ show:
110
+ your_title: "Your Cart"
111
+ for_user_title: "Cart for {{name}}"
112
+ controllers:
113
+ gets_trollied_helper:
114
+ add_to_trolley: "+ Add to cart"
115
+ in_trolley: "Previously added to cart"
data/config/routes.rb ADDED
@@ -0,0 +1,8 @@
1
+ members = Order.workflow_event_names.inject(Hash.new) do |hash, event_name|
2
+ hash[event_name.to_sym] = :post
3
+ hash
4
+ end
5
+
6
+ ActionController::Routing::Routes.draw do |map|
7
+ map.resources :orders, :member => members, :except => [:new, :create], :has_many => :line_items, :has_many => :notes
8
+ end
@@ -0,0 +1,2 @@
1
+ Description:
2
+ Generates the migrations necessary for using the trollied gem in your Ruby on Rails application. Namely trolley, order, and line item.
@@ -0,0 +1,16 @@
1
+ class CreateLineItems < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :line_items do |t|
4
+ t.integer :order_id, :null => false
5
+ t.integer :purchasable_item_id, :null => false #, :references => nil this may blow up
6
+ t.string :purchasable_item_type, :null => false
7
+
8
+ t.timestamps
9
+ end
10
+
11
+ end
12
+
13
+ def self.down
14
+ drop_table :line_items
15
+ end
16
+ end
@@ -0,0 +1,15 @@
1
+ class CreateNotes < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :notes do |t|
4
+ t.integer :order_id, :user_id, :null => false
5
+ t.string :body, :null => false
6
+
7
+ t.timestamps
8
+ end
9
+
10
+ end
11
+
12
+ def self.down
13
+ drop_table :notes
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ class CreateOrders < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :orders do |t|
4
+ t.integer :trolley_id, :null => false
5
+ t.string :workflow_state, :default => 'current', :null => false
6
+
7
+ t.timestamps
8
+ end
9
+
10
+ end
11
+
12
+ def self.down
13
+ drop_table :orders
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ class CreateTrolleys < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :trolleys do |t|
4
+ t.integer :user_id, :null => false
5
+
6
+ t.timestamps
7
+ end
8
+
9
+ end
10
+
11
+ def self.down
12
+ drop_table :trolleys
13
+ end
14
+ end
@@ -0,0 +1,13 @@
1
+ class TrolliedMigrationsGenerator < Rails::Generator::Base
2
+ def manifest
3
+ record do |m|
4
+ m.migration_template 'trolleys_migration.rb', 'db/migrate', { :migration_file_name => "create_trolleys" }
5
+ m.sleep(1)
6
+ m.migration_template 'orders_migration.rb', 'db/migrate', { :migration_file_name => "create_orders" }
7
+ m.sleep(1)
8
+ m.migration_template 'line_items_migration.rb', 'db/migrate', { :migration_file_name => "create_line_items" }
9
+ m.sleep(1)
10
+ m.migration_template 'notes_migration.rb', 'db/migrate', { :migration_file_name => "create_notes" }
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,38 @@
1
+ # -*- coding: utf-8 -*-
2
+ require "active_record"
3
+
4
+ module GetsTrollied
5
+ def self.included(base)
6
+ base.extend(ClassMethods)
7
+ end
8
+
9
+ module ClassMethods
10
+ def set_up_to_get_trollied(*args)
11
+ options = args.last.is_a?(Hash) ? args.pop : Hash.new
12
+
13
+ # don't allow multiple calls
14
+ return if self.included_modules.include?(GetsTrollied::InstanceMethods)
15
+
16
+ send :include, GetsTrollied::InstanceMethods
17
+
18
+ send :has_many, :line_items, :as => :purchasable_item, :dependent => :destroy
19
+
20
+ cattr_accessor :described_as_when_purchasing
21
+ self.described_as_when_purchasing = options[:described_as] || :name
22
+
23
+ cattr_accessor :as_foreign_key_sym
24
+ self.as_foreign_key_sym = self.name.foreign_key.to_sym
25
+
26
+ end
27
+ end
28
+
29
+ module InstanceMethods
30
+ def place_in(trolley)
31
+ trolley.add(self)
32
+ end
33
+
34
+ def description_for_purchasing
35
+ send(self.class.described_as_when_purchasing)
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,29 @@
1
+ module GetsTrolliedControllerHelpers
2
+ def self.included(klass)
3
+ klass.send :helper_method, :url_for_purchasable_item, :target_action, :target_controller
4
+ end
5
+
6
+ def target_controller(options = {})
7
+ purchasable_item_params_name = options.delete(:purchasable_item_params_name) || @purchasable_item_params_name
8
+ options.delete(:controller) || purchasable_item_params_name.pluralize || params[:controller]
9
+ end
10
+
11
+ def target_action(options = {})
12
+ options.delete(:action) || 'show'
13
+ end
14
+
15
+ def target_id(options = {})
16
+ purchasable_item = options.delete(:purchasable_item) || @purchasable_item
17
+ options.delete(:id) || purchasable_item
18
+ end
19
+
20
+ def url_for_purchasable_item(options = { })
21
+ defaults = {
22
+ :controller => target_controller(options),
23
+ :action => target_action(options),
24
+ :id => target_id(options)
25
+ }
26
+
27
+ url_for(defaults.merge(options))
28
+ end
29
+ end
@@ -0,0 +1,42 @@
1
+ # -*- coding: utf-8 -*-
2
+ require "active_record"
3
+
4
+ module HasTrolley
5
+ def self.included(klass)
6
+ klass.send :has_one, :trolley, :dependent => :destroy
7
+ klass.send :delegate, :correct_order, :to => :trolley
8
+ klass.send :after_create, :create_trolley
9
+ klass.extend ClassMethods
10
+ klass.send :include, InstanceMethods
11
+ end
12
+
13
+ module ClassMethods
14
+ def add_trolleys_for_existing
15
+ all.each { |u| u.create_trolley }
16
+ end
17
+ end
18
+
19
+ module InstanceMethods
20
+ # implement in your application if you have another method name
21
+ # besides these common ones
22
+ # WARNING: potential security issue, definitely override
23
+ # if any of these options are sensitive
24
+ def trolley_user_display_name
25
+ if respond_to?(:display_name)
26
+ display_name
27
+ elsif respond_to?(:name)
28
+ name
29
+ elsif respond_to?(:username)
30
+ username
31
+ elsif respond_to?(:nickname)
32
+ nickname
33
+ end
34
+ end
35
+
36
+ private
37
+
38
+ def create_trolley
39
+ Trolley.create!(:user => self)
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,43 @@
1
+ module HasTrolleyControllerHelpers
2
+ def self.included(klass)
3
+ klass.send :helper_method, :url_for_trolley
4
+ klass.send :include, UrlFor
5
+ end
6
+
7
+ module UrlFor
8
+ # expects user in options or @user or trolley being set
9
+ def url_for_trolley(options = { })
10
+ user = options[:user] || @user
11
+ user = @trolley.user if @trolley && user.blank?
12
+
13
+ trolley = options[:trolley] || @trolley || user.trolley
14
+
15
+ # TODO: Hack, not sure if this is 2.3.5 bug or my ignorance
16
+ # but url_for returns marshalled trolley, in addition to correct url
17
+ url = url_for(:user_id => user.id,
18
+ :controller => :trolleys,
19
+ :action => :show).split(".%23%")[0]
20
+ end
21
+
22
+ # expects order
23
+ # either as instance variables or in options
24
+ def url_for_order(options = { })
25
+ trolley = options[:trolley] || @trolley
26
+ trolley = @order.trolley if @order && trolley.blank?
27
+
28
+ order = options[:order] || @order || trolley.selected_order
29
+
30
+ url_for [trolley.user, trolley, order]
31
+ end
32
+
33
+ def url_for_order_or_trolley
34
+ raise unless @order
35
+
36
+ if @order.user == current_user
37
+ url_for_trolley :trolley => @order.trolley
38
+ else
39
+ url_for_order
40
+ end
41
+ end
42
+ end
43
+ end