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
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,294 @@
1
+ Copyright (C) 2011 Horowhenua Library Trust
2
+
3
+ This program (kete_translatable_content) is free software; you can redistribute it and/or modify
4
+ it under the terms of the GNU General Public License as published by
5
+ the Free Software Foundation; either version 2 of the License, or
6
+ (at your option) any later version.
7
+
8
+ This program is distributed in the hope that it will be useful,
9
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ GNU General Public License for more details.
12
+
13
+ You should have received a copy of the GNU General Public License along
14
+ with this program; if not, write to the Free Software Foundation, Inc.,
15
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16
+
17
+ GNU GENERAL PUBLIC LICENSE
18
+ Version 2, June 1991
19
+
20
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
21
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22
+ Everyone is permitted to copy and distribute verbatim copies
23
+ of this license document, but changing it is not allowed.
24
+
25
+ Preamble
26
+
27
+ The licenses for most software are designed to take away your
28
+ freedom to share and change it. By contrast, the GNU General Public
29
+ License is intended to guarantee your freedom to share and change free
30
+ software--to make sure the software is free for all its users. This
31
+ General Public License applies to most of the Free Software
32
+ Foundation's software and to any other program whose authors commit to
33
+ using it. (Some other Free Software Foundation software is covered by
34
+ the GNU Lesser General Public License instead.) You can apply it to
35
+ your programs, too.
36
+
37
+ When we speak of free software, we are referring to freedom, not
38
+ price. Our General Public Licenses are designed to make sure that you
39
+ have the freedom to distribute copies of free software (and charge for
40
+ this service if you wish), that you receive source code or can get it
41
+ if you want it, that you can change the software or use pieces of it
42
+ in new free programs; and that you know you can do these things.
43
+
44
+ To protect your rights, we need to make restrictions that forbid
45
+ anyone to deny you these rights or to ask you to surrender the rights.
46
+ These restrictions translate to certain responsibilities for you if you
47
+ distribute copies of the software, or if you modify it.
48
+
49
+ For example, if you distribute copies of such a program, whether
50
+ gratis or for a fee, you must give the recipients all the rights that
51
+ you have. You must make sure that they, too, receive or can get the
52
+ source code. And you must show them these terms so they know their
53
+ rights.
54
+
55
+ We protect your rights with two steps: (1) copyright the software, and
56
+ (2) offer you this license which gives you legal permission to copy,
57
+ distribute and/or modify the software.
58
+
59
+ Also, for each author's protection and ours, we want to make certain
60
+ that everyone understands that there is no warranty for this free
61
+ software. If the software is modified by someone else and passed on, we
62
+ want its recipients to know that what they have is not the original, so
63
+ that any problems introduced by others will not reflect on the original
64
+ authors' reputations.
65
+
66
+ Finally, any free program is threatened constantly by software
67
+ patents. We wish to avoid the danger that redistributors of a free
68
+ program will individually obtain patent licenses, in effect making the
69
+ program proprietary. To prevent this, we have made it clear that any
70
+ patent must be licensed for everyone's free use or not licensed at all.
71
+
72
+ The precise terms and conditions for copying, distribution and
73
+ modification follow.
74
+
75
+ GNU GENERAL PUBLIC LICENSE
76
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
77
+
78
+ 0. This License applies to any program or other work which contains
79
+ a notice placed by the copyright holder saying it may be distributed
80
+ under the terms of this General Public License. The "Program", below,
81
+ refers to any such program or work, and a "work based on the Program"
82
+ means either the Program or any derivative work under copyright law:
83
+ that is to say, a work containing the Program or a portion of it,
84
+ either verbatim or with modifications and/or translated into another
85
+ language. (Hereinafter, translation is included without limitation in
86
+ the term "modification".) Each licensee is addressed as "you".
87
+
88
+ Activities other than copying, distribution and modification are not
89
+ covered by this License; they are outside its scope. The act of
90
+ running the Program is not restricted, and the output from the Program
91
+ is covered only if its contents constitute a work based on the
92
+ Program (independent of having been made by running the Program).
93
+ Whether that is true depends on what the Program does.
94
+
95
+ 1. You may copy and distribute verbatim copies of the Program's
96
+ source code as you receive it, in any medium, provided that you
97
+ conspicuously and appropriately publish on each copy an appropriate
98
+ copyright notice and disclaimer of warranty; keep intact all the
99
+ notices that refer to this License and to the absence of any warranty;
100
+ and give any other recipients of the Program a copy of this License
101
+ along with the Program.
102
+
103
+ You may charge a fee for the physical act of transferring a copy, and
104
+ you may at your option offer warranty protection in exchange for a fee.
105
+
106
+ 2. You may modify your copy or copies of the Program or any portion
107
+ of it, thus forming a work based on the Program, and copy and
108
+ distribute such modifications or work under the terms of Section 1
109
+ above, provided that you also meet all of these conditions:
110
+
111
+ a) You must cause the modified files to carry prominent notices
112
+ stating that you changed the files and the date of any change.
113
+
114
+ b) You must cause any work that you distribute or publish, that in
115
+ whole or in part contains or is derived from the Program or any
116
+ part thereof, to be licensed as a whole at no charge to all third
117
+ parties under the terms of this License.
118
+
119
+ c) If the modified program normally reads commands interactively
120
+ when run, you must cause it, when started running for such
121
+ interactive use in the most ordinary way, to print or display an
122
+ announcement including an appropriate copyright notice and a
123
+ notice that there is no warranty (or else, saying that you provide
124
+ a warranty) and that users may redistribute the program under
125
+ these conditions, and telling the user how to view a copy of this
126
+ License. (Exception: if the Program itself is interactive but
127
+ does not normally print such an announcement, your work based on
128
+ the Program is not required to print an announcement.)
129
+
130
+ These requirements apply to the modified work as a whole. If
131
+ identifiable sections of that work are not derived from the Program,
132
+ and can be reasonably considered independent and separate works in
133
+ themselves, then this License, and its terms, do not apply to those
134
+ sections when you distribute them as separate works. But when you
135
+ distribute the same sections as part of a whole which is a work based
136
+ on the Program, the distribution of the whole must be on the terms of
137
+ this License, whose permissions for other licensees extend to the
138
+ entire whole, and thus to each and every part regardless of who wrote it.
139
+
140
+ Thus, it is not the intent of this section to claim rights or contest
141
+ your rights to work written entirely by you; rather, the intent is to
142
+ exercise the right to control the distribution of derivative or
143
+ collective works based on the Program.
144
+
145
+ In addition, mere aggregation of another work not based on the Program
146
+ with the Program (or with a work based on the Program) on a volume of
147
+ a storage or distribution medium does not bring the other work under
148
+ the scope of this License.
149
+
150
+ 3. You may copy and distribute the Program (or a work based on it,
151
+ under Section 2) in object code or executable form under the terms of
152
+ Sections 1 and 2 above provided that you also do one of the following:
153
+
154
+ a) Accompany it with the complete corresponding machine-readable
155
+ source code, which must be distributed under the terms of Sections
156
+ 1 and 2 above on a medium customarily used for software interchange; or,
157
+
158
+ b) Accompany it with a written offer, valid for at least three
159
+ years, to give any third party, for a charge no more than your
160
+ cost of physically performing source distribution, a complete
161
+ machine-readable copy of the corresponding source code, to be
162
+ distributed under the terms of Sections 1 and 2 above on a medium
163
+ customarily used for software interchange; or,
164
+
165
+ c) Accompany it with the information you received as to the offer
166
+ to distribute corresponding source code. (This alternative is
167
+ allowed only for noncommercial distribution and only if you
168
+ received the program in object code or executable form with such
169
+ an offer, in accord with Subsection b above.)
170
+
171
+ The source code for a work means the preferred form of the work for
172
+ making modifications to it. For an executable work, complete source
173
+ code means all the source code for all modules it contains, plus any
174
+ associated interface definition files, plus the scripts used to
175
+ control compilation and installation of the executable. However, as a
176
+ special exception, the source code distributed need not include
177
+ anything that is normally distributed (in either source or binary
178
+ form) with the major components (compiler, kernel, and so on) of the
179
+ operating system on which the executable runs, unless that component
180
+ itself accompanies the executable.
181
+
182
+ If distribution of executable or object code is made by offering
183
+ access to copy from a designated place, then offering equivalent
184
+ access to copy the source code from the same place counts as
185
+ distribution of the source code, even though third parties are not
186
+ compelled to copy the source along with the object code.
187
+
188
+ 4. You may not copy, modify, sublicense, or distribute the Program
189
+ except as expressly provided under this License. Any attempt
190
+ otherwise to copy, modify, sublicense or distribute the Program is
191
+ void, and will automatically terminate your rights under this License.
192
+ However, parties who have received copies, or rights, from you under
193
+ this License will not have their licenses terminated so long as such
194
+ parties remain in full compliance.
195
+
196
+ 5. You are not required to accept this License, since you have not
197
+ signed it. However, nothing else grants you permission to modify or
198
+ distribute the Program or its derivative works. These actions are
199
+ prohibited by law if you do not accept this License. Therefore, by
200
+ modifying or distributing the Program (or any work based on the
201
+ Program), you indicate your acceptance of this License to do so, and
202
+ all its terms and conditions for copying, distributing or modifying
203
+ the Program or works based on it.
204
+
205
+ 6. Each time you redistribute the Program (or any work based on the
206
+ Program), the recipient automatically receives a license from the
207
+ original licensor to copy, distribute or modify the Program subject to
208
+ these terms and conditions. You may not impose any further
209
+ restrictions on the recipients' exercise of the rights granted herein.
210
+ You are not responsible for enforcing compliance by third parties to
211
+ this License.
212
+
213
+ 7. If, as a consequence of a court judgment or allegation of patent
214
+ infringement or for any other reason (not limited to patent issues),
215
+ conditions are imposed on you (whether by court order, agreement or
216
+ otherwise) that contradict the conditions of this License, they do not
217
+ excuse you from the conditions of this License. If you cannot
218
+ distribute so as to satisfy simultaneously your obligations under this
219
+ License and any other pertinent obligations, then as a consequence you
220
+ may not distribute the Program at all. For example, if a patent
221
+ license would not permit royalty-free redistribution of the Program by
222
+ all those who receive copies directly or indirectly through you, then
223
+ the only way you could satisfy both it and this License would be to
224
+ refrain entirely from distribution of the Program.
225
+
226
+ If any portion of this section is held invalid or unenforceable under
227
+ any particular circumstance, the balance of the section is intended to
228
+ apply and the section as a whole is intended to apply in other
229
+ circumstances.
230
+
231
+ It is not the purpose of this section to induce you to infringe any
232
+ patents or other property right claims or to contest validity of any
233
+ such claims; this section has the sole purpose of protecting the
234
+ integrity of the free software distribution system, which is
235
+ implemented by public license practices. Many people have made
236
+ generous contributions to the wide range of software distributed
237
+ through that system in reliance on consistent application of that
238
+ system; it is up to the author/donor to decide if he or she is willing
239
+ to distribute software through any other system and a licensee cannot
240
+ impose that choice.
241
+
242
+ This section is intended to make thoroughly clear what is believed to
243
+ be a consequence of the rest of this License.
244
+
245
+ 8. If the distribution and/or use of the Program is restricted in
246
+ certain countries either by patents or by copyrighted interfaces, the
247
+ original copyright holder who places the Program under this License
248
+ may add an explicit geographical distribution limitation excluding
249
+ those countries, so that distribution is permitted only in or among
250
+ countries not thus excluded. In such case, this License incorporates
251
+ the limitation as if written in the body of this License.
252
+
253
+ 9. The Free Software Foundation may publish revised and/or new versions
254
+ of the General Public License from time to time. Such new versions will
255
+ be similar in spirit to the present version, but may differ in detail to
256
+ address new problems or concerns.
257
+
258
+ Each version is given a distinguishing version number. If the Program
259
+ specifies a version number of this License which applies to it and "any
260
+ later version", you have the option of following the terms and conditions
261
+ either of that version or of any later version published by the Free
262
+ Software Foundation. If the Program does not specify a version number of
263
+ this License, you may choose any version ever published by the Free Software
264
+ Foundation.
265
+
266
+ 10. If you wish to incorporate parts of the Program into other free
267
+ programs whose distribution conditions are different, write to the author
268
+ to ask for permission. For software which is copyrighted by the Free
269
+ Software Foundation, write to the Free Software Foundation; we sometimes
270
+ make exceptions for this. Our decision will be guided by the two goals
271
+ of preserving the free status of all derivatives of our free software and
272
+ of promoting the sharing and reuse of software generally.
273
+
274
+ NO WARRANTY
275
+
276
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
277
+ FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
278
+ OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
279
+ PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
280
+ OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
281
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
282
+ TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
283
+ PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
284
+ REPAIR OR CORRECTION.
285
+
286
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
287
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
288
+ REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
289
+ INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
290
+ OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
291
+ TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
292
+ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
293
+ PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
294
+ POSSIBILITY OF SUCH DAMAGES.
data/README.rdoc ADDED
@@ -0,0 +1,96 @@
1
+ = trollied
2
+
3
+ http://en.wiktionary.org/wiki/trollied
4
+
5
+ Extendable Ruby on Rails engine for adding shopping cart functionality to a Rails application. It does not assume shipping, price, or having a quantity. However, it does allow for more than one order per user placed in a trolley. Meant to be well suited to ordering digital records.
6
+
7
+ == Requirements
8
+
9
+ Relies on there being a User model with a corresponding users table and current_user method available to get the user of a current session. Also assumes will_paginate is installed either as a plugin or a gem in your Rails app.
10
+
11
+ == Set up
12
+
13
+ Currently only tested against Rails 2.3.5. Feel free to submit a pull request with Rails 3 support.
14
+
15
+ Install the gem:
16
+
17
+ gem install trollied
18
+
19
+ After installing the gem do the following to your app:
20
+
21
+ In the Rails::Initializer.run config block in config/environment.rb:
22
+
23
+ config.gem "trollied"
24
+
25
+ Now you need to run the migration generator to add the tables, etc. that Trollied needs to work. Do this in your apps's root directory.
26
+
27
+ $ script/generate trollied_migrations
28
+ $ rake db:migrate # add environment if necessary, i.e. rake db:migrate RAILS_ENV=production
29
+
30
+ If you are like me and use automatic foreign key constraints, this may fail for the line items migration because of it having a polymorphic. Alter this:
31
+
32
+ t.integer :purchasable_item_id, :null => false
33
+
34
+ to
35
+
36
+ t.integer :purchasable_item_id, :null => false, :references => nil
37
+
38
+ and rerun the db:migrate command.
39
+
40
+ Decide which models can be trollied and do the following for each:
41
+
42
+ class SomeModel < ActiveRecord::Base
43
+ include GetsTrollied
44
+ set_up_to_get_trollied :described_as => :the_attribute_that_describes_the_instance_such_as_title_or_name
45
+ end
46
+
47
+ In your user model, you'll also need to declare it has a trolley:
48
+
49
+ class User < ActiveRecord::Base
50
+ include HasTrolley
51
+ end
52
+
53
+ You'll also need to add a trolley for each existing user in your system (new users are handled automatically). Here's the command that can be run from your console:
54
+
55
+ User.add_trolleys_for_existing
56
+
57
+ Next you need to create corresponding nested routes for your controllers and your user account controller. Something like this in config/routes.rb:
58
+
59
+
60
+ ActionController::Routing::Routes.draw do |map|
61
+ map.resources :user do |user|
62
+ user.resource :trolley, :only => :show do |trolley|
63
+ trolley.resources :orders, :shallow => true
64
+ end
65
+ end
66
+
67
+ map.resources :items, :has_many => :line_items
68
+ end
69
+
70
+ Then you need to adjust any templates that you want the user be able to add an instance of the model to his or her trolley from. Add this method in the template.
71
+
72
+ link_to_place_in_trolley(@instance_of_model)
73
+
74
+ Alternatively, you can use this if you want to prevent duplicate orders:
75
+
76
+ in_trolley_status_or_button_to_place_in_trolley(@instance_of_model)
77
+
78
+ You'll also need to implement a helper that provides a link to the appropriate profile page for a user.
79
+
80
+ i.e.:
81
+
82
+ link_to_profile_for(user)
83
+
84
+ == Note on Patches/Pull Requests
85
+
86
+ * Fork the project.
87
+ * Make your feature addition or bug fix.
88
+ * Add tests for it. This is important so I don't break it in a
89
+ future version unintentionally.
90
+ * Commit, do not mess with rakefile, version, or history.
91
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
92
+ * Send me a pull request. Bonus points for topic branches.
93
+
94
+ == Copyright
95
+
96
+ Copyright (c) 2011 Walter McGinnis. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,55 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "trollied"
8
+ gem.summary = %Q{Extendable Ruby on Rails engine for adding shopping cart functionality to a Rails application. It does not assume shipping, price, or having a quantity.}
9
+ gem.description = %Q{Extendable Ruby on Rails engine for adding shopping cart functionality to a Rails application. It does not assume shipping, price, or having a quantity. However, it does allow for more than one order per user placed in a trolley. Meant to be well suited to ordering digital records.}
10
+ gem.email = "walter@katipo.co.nz"
11
+ gem.homepage = "http://github.com/kete/trollied"
12
+ gem.authors = ["Walter McGinnis"]
13
+ gem.add_dependency "workflow", ">= 0.8.0"
14
+ gem.add_dependency "will_paginate", "<= 2.3.15"
15
+ gem.add_development_dependency "shoulda", ">= 2.10.3"
16
+ gem.add_development_dependency "factory_girl", "= 1.2.3"
17
+ gem.add_development_dependency "webrat", ">= 0.5.3"
18
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
19
+ end
20
+ Jeweler::GemcutterTasks.new
21
+ rescue LoadError
22
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
23
+ end
24
+
25
+ require 'rake/testtask'
26
+ Rake::TestTask.new(:test) do |test|
27
+ puts "This gem includes a full rails app for running tests (and staging development not yet extracted to the gem proper). Run tests there by changing to test/full_[RAIlS_VERSION_#_with_underscores]_app_with_tests and doing 'rake test'."
28
+ end
29
+
30
+ begin
31
+ require 'rcov/rcovtask'
32
+ Rcov::RcovTask.new do |test|
33
+ test.libs << 'test'
34
+ test.pattern = 'test/**/test_*.rb'
35
+ test.verbose = true
36
+ end
37
+ rescue LoadError
38
+ task :rcov do
39
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
40
+ end
41
+ end
42
+
43
+ task :test => :check_dependencies
44
+
45
+ task :default => :test
46
+
47
+ require 'rake/rdoctask'
48
+ Rake::RDocTask.new do |rdoc|
49
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
50
+
51
+ rdoc.rdoc_dir = 'rdoc'
52
+ rdoc.title = "trollied #{version}"
53
+ rdoc.rdoc_files.include('README*')
54
+ rdoc.rdoc_files.include('lib/**/*.rb')
55
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,168 @@
1
+ class LineItemsController < ApplicationController
2
+ # Prevents the following error from showing up, common in Rails engines
3
+ # A copy of ApplicationController has been removed from the module tree but is still active!
4
+ unloadable
5
+
6
+ before_filter :get_order, :only => [:index, :destroy]
7
+ before_filter :get_purchasable_item_key_and_class
8
+ before_filter :get_purchasable_item
9
+ before_filter :get_user
10
+ before_filter :get_line_item, :except => [:new, :index, :create]
11
+
12
+ # GET /line_items
13
+ # GET /line_items.xml
14
+ def index
15
+ @line_items = @order ? @order.line_items : @purchasable_item.line_items
16
+
17
+ respond_to do |format|
18
+ format.html # index.html.erb
19
+ # format.xml { render :xml => @line_items }
20
+ end
21
+ end
22
+
23
+ # GET /line_items/1
24
+ # GET /line_items/1.xml
25
+ def show
26
+ respond_to do |format|
27
+ format.html # show.html.erb
28
+ # format.xml { render :xml => @line_item }
29
+ end
30
+ end
31
+
32
+ # GET /line_items/new
33
+ # GET /line_items/new.xml
34
+ def new
35
+ @line_item = @purchasable_item.line_items.new
36
+
37
+ respond_to do |format|
38
+ format.html # new.html.erb
39
+ # format.js { render :layout => false } # needs to come after html for IE to work
40
+ # format.xml { render :xml => @line_item }
41
+ end
42
+ end
43
+
44
+ # GET /line_items/1/edit
45
+ def edit
46
+ end
47
+
48
+ # POST /line_items
49
+ # POST /line_items.xml
50
+ def create
51
+ line_item_params = params[:line_item] || params[@purchasable_item_params_name + '_line_item'] || Hash.new
52
+
53
+ @order = @user.correct_order(@purchasable_item)
54
+
55
+ @trolley = @order.trolley
56
+
57
+ line_item_params[:order] = @order
58
+
59
+ @line_item = @purchasable_item.line_items.new(line_item_params)
60
+
61
+ respond_to do |format|
62
+ if @line_item.save
63
+ flash[:notice] = t('line_items.controllers.created')
64
+ # we redirect to purchasable_item object in the new purchasable_item version
65
+ # assumes controller name is tableized version of class
66
+ format.html { redirect_to url_for_trolley }
67
+ # TODO: adjust :location accordingly for being a nested route
68
+ # format.xml { render :xml => @line_item, :status => :created, :location => @line_item }
69
+ else
70
+ format.html { render :action => "new" }
71
+ # format.xml { render :xml => @line_item.errors, :status => :unprocessable_entity }
72
+ end
73
+ end
74
+ end
75
+
76
+ # PUT /line_items/1
77
+ # PUT /line_items/1.xml
78
+ def update
79
+ respond_to do |format|
80
+ line_item_params = params[:line_item] || params[@purchasable_item_params_name + '_line_item']
81
+ if @line_item.update_attributes(line_item_params)
82
+ flash[:notice] = t('line_items.controllers.updated')
83
+ format.html { redirect_to url_for_trolley }
84
+ # format.xml { head :ok }
85
+ else
86
+ format.html { render :action => "edit" }
87
+ # format.xml { render :xml => @line_item.errors, :status => :unprocessable_entity }
88
+ end
89
+ end
90
+ end
91
+
92
+ # DELETE /line_items/1
93
+ # DELETE /line_items/1.xml
94
+ def destroy
95
+ return_to = if params[:return_to_purchasable_item].present? && params[:return_to_purchasable_item]
96
+ url_for_purchasable_item
97
+ elsif params[:trolley_id].present?
98
+ @trolley = Trolley.find(params[:trolley_id])
99
+ url_for_trolley
100
+ else
101
+ { :action => :index }
102
+ end
103
+
104
+ @line_item.destroy
105
+
106
+ respond_to do |format|
107
+ flash[:notice] = t('line_items.controllers.deleted')
108
+ format.html { redirect_to return_to }
109
+ # format.xml { head :ok }
110
+ end
111
+ end
112
+
113
+ protected
114
+ # accepts line_item.locale or line_item.id for lookup
115
+ # line_item.locale should be unique within the scope of @purchasable_item
116
+ def get_line_item
117
+ @line_item ||= @purchasable_item.line_items.find(params[:id])
118
+ end
119
+
120
+ def get_purchasable_item
121
+ @purchasable_item ||= @purchasable_item_class.present? ? @purchasable_item_class.find(params[@purchasable_item_key]) : nil
122
+ end
123
+
124
+ # TODO: allow passing in user_id, but after permission check?
125
+ def get_user
126
+ # @user = params[:user].present? ? User.find(params[:user]) : current_user
127
+ @user = current_user
128
+ end
129
+
130
+ def get_order
131
+ @order = params[:order_id].present? ? Order.find(params[:order_id]) : nil
132
+ end
133
+
134
+ # assuming nested routing under purchasable_item controller, this should return exactly one params key
135
+ # and its matching class
136
+ # if it is nested routing under orders controller, this should get order
137
+ # and if params[:id] is present, get line item, etc.
138
+ # however, if order is present, but params[:id] is not, other instance variables will not be set
139
+ def get_purchasable_item_key_and_class
140
+ if @order && params[:id]
141
+ @line_item = @order.line_items.find(params[:id])
142
+ @purchasable_item = @line_item.purchasable_item
143
+ @purchasable_item_class = @purchasable_item.class
144
+ @purchasable_item_key = @purchasable_item.class.as_foreign_key_sym
145
+ @purchasable_item_params_name = @purchasable_item_key.to_s.sub('_id', '')
146
+ else
147
+ purchasable_item_keys = params.keys.select { |key| key.to_s.include?('_id') }
148
+
149
+ purchasable_item_keys.each do |key|
150
+ key = key.to_s
151
+ if key != 'line_item_id' && request
152
+ key_singular = key.sub('_id', '')
153
+
154
+ # make sure this is found in the request url
155
+ # thus making this a nested route
156
+ # assumes plural version for controller name
157
+ # TODO: make this assumption overridable
158
+ if request.path.split('/').include?(key_singular.pluralize)
159
+ @purchasable_item_class = key_singular.camelize.constantize
160
+ @purchasable_item_key = key.to_sym
161
+ @purchasable_item_params_name = key_singular
162
+ break
163
+ end
164
+ end
165
+ end
166
+ end
167
+ end
168
+ end