trollied 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,5 @@
1
+ # See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file
2
+ #
3
+ # To ban all spiders from the entire site uncomment the next two lines:
4
+ # User-Agent: *
5
+ # Disallow: /
@@ -0,0 +1,54 @@
1
+ body { background-color: #fff; color: #333; }
2
+
3
+ body, p, ol, ul, td {
4
+ font-family: verdana, arial, helvetica, sans-serif;
5
+ font-size: 13px;
6
+ line-height: 18px;
7
+ }
8
+
9
+ pre {
10
+ background-color: #eee;
11
+ padding: 10px;
12
+ font-size: 11px;
13
+ }
14
+
15
+ a { color: #000; }
16
+ a:visited { color: #666; }
17
+ a:hover { color: #fff; background-color:#000; }
18
+
19
+ .fieldWithErrors {
20
+ padding: 2px;
21
+ background-color: red;
22
+ display: table;
23
+ }
24
+
25
+ #errorExplanation {
26
+ width: 400px;
27
+ border: 2px solid red;
28
+ padding: 7px;
29
+ padding-bottom: 12px;
30
+ margin-bottom: 20px;
31
+ background-color: #f0f0f0;
32
+ }
33
+
34
+ #errorExplanation h2 {
35
+ text-align: left;
36
+ font-weight: bold;
37
+ padding: 5px 5px 5px 15px;
38
+ font-size: 12px;
39
+ margin: -7px;
40
+ background-color: #c00;
41
+ color: #fff;
42
+ }
43
+
44
+ #errorExplanation p {
45
+ color: #333;
46
+ margin-bottom: 0;
47
+ padding: 5px;
48
+ }
49
+
50
+ #errorExplanation ul li {
51
+ font-size: 12px;
52
+ list-style: square;
53
+ }
54
+
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ $LOAD_PATH.unshift "#{RAILTIES_PATH}/builtin/rails_info"
4
+ require 'commands/about'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ require 'commands/console'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ require 'commands/dbconsole'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ require 'commands/destroy'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ require 'commands/generate'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../../config/boot', __FILE__)
3
+ require 'commands/performance/benchmarker'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../../config/boot', __FILE__)
3
+ require 'commands/performance/profiler'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ require 'commands/plugin'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ require 'commands/runner'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ require 'commands/server'
@@ -0,0 +1,22 @@
1
+ Factory.define :item do |f|
2
+ f.sequence(:label) { |n| "a label#{n}"}
3
+ f.sequence(:value) { |n| "a value#{n}"}
4
+ end
5
+
6
+ Factory.define :user do |f|
7
+ f.name "Frisky Fitzpatrick"
8
+ end
9
+
10
+ Factory.define :trolley do |f|
11
+ f.association :user
12
+ end
13
+
14
+ Factory.define :order do |f|
15
+ f.association :trolley
16
+ end
17
+
18
+ Factory.define :note do |f|
19
+ f.body "a test body"
20
+ f.association :order
21
+ f.association :user
22
+ end
@@ -0,0 +1,69 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'test_helper'
3
+
4
+ class LineItemsControllerTest < ActionController::TestCase
5
+ context "The line_items controller" do
6
+ setup do
7
+ @item = Factory.create(:item)
8
+ @user = Factory.create(:user)
9
+ @trolley = @user.trolley
10
+ end
11
+
12
+ should "get index" do
13
+ get :index, :item_id => @item.id
14
+ assert_response :success
15
+ assert_not_nil assigns(:line_items)
16
+ end
17
+
18
+ should "get new" do
19
+ get :new, :item_id => @item.id
20
+ assert_response :success
21
+ end
22
+
23
+ should "create line_item" do
24
+ assert_difference('LineItem.count') do
25
+ post :create, :line_item => {}, :item_id => @item.id, :user => @user.id
26
+ end
27
+
28
+ assert_redirected_to :controller => 'trolleys', :action => 'show', :user_id => @user.id
29
+ end
30
+
31
+ context "when there is an existing line_item" do
32
+ setup do
33
+ @order = @user.correct_order(@item)
34
+
35
+ @line_item_1 = @item.line_items.create(:order => @order)
36
+ end
37
+
38
+ should "get index with a line_item" do
39
+ get :index, :item_id => @item.id
40
+ assert assigns(:line_items).size == 1
41
+ end
42
+
43
+ should "show line_item" do
44
+ get :show, :id => @line_item_1.id, :item_id => @item.id
45
+ assert_response :success
46
+ end
47
+
48
+ should "get edit" do
49
+ get :edit, :id => @line_item_1.id, :item_id => @item.id
50
+ assert_response :success
51
+ end
52
+
53
+ should "update line_item" do
54
+ put :update, :id => @line_item_1.id, :item_id => @item.id, :line_item => { :order => Factory.create(:order) }
55
+ assert_redirected_to :controller => 'trolleys', :action => 'show', :user_id => @user.id
56
+ end
57
+
58
+ should "destroy line_item" do
59
+ assert_difference('LineItem.count', -1) do
60
+ delete :destroy, :order_id => @order.id, :id => @line_item_1.id
61
+ end
62
+
63
+ assert_redirected_to :action => 'index', :order_id => @order.id
64
+ end
65
+ end
66
+ end
67
+
68
+ end
69
+
@@ -0,0 +1,75 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'test_helper'
3
+
4
+ class OrdersControllerTest < ActionController::TestCase
5
+ context "The orders controller" do
6
+ setup do
7
+ @item = Factory.create(:item)
8
+ @user = Factory.create(:user)
9
+ @trolley = @user.trolley
10
+ end
11
+
12
+ should "get index" do
13
+ get :index, :trolley_id => @trolley.id, :user_id => @user.id
14
+ assert_response :success
15
+ assert_not_nil assigns(:orders)
16
+ end
17
+
18
+ should "get new" do
19
+ get :new, :trolley_id => @trolley.id, :user_id => @user.id
20
+ assert_response :success
21
+ end
22
+
23
+ should "create order" do
24
+ assert_difference('Order.count') do
25
+ post :create, :order => {}, :user_id => @user.id
26
+ end
27
+
28
+ assert_redirected_to :controller => 'trolleys', :action => 'show', :user_id => @user.id
29
+ end
30
+
31
+ context "when there is an existing order" do
32
+ setup do
33
+ @order = @user.correct_order(@item)
34
+
35
+ @line_item_1 = @item.line_items.create(:order => @order)
36
+ end
37
+
38
+ should "be able to checkout order" do
39
+ post :checkout, :id => @order.id, :trolley_id => @order.trolley.id
40
+
41
+ assert_redirected_to :controller => 'trolleys', :action => 'show', :user_id => @user.id
42
+ end
43
+
44
+ # should "get index with a order" do
45
+ # get :index, :trolley_id => @trolley.id, :user_id => @user.id
46
+ # assert assigns(:orders).size == 1
47
+ # end
48
+
49
+ # should "show order" do
50
+ # get :show, :id => @order.id
51
+ # assert_response :success
52
+ # end
53
+
54
+ # should "get edit" do
55
+ # get :edit, :id => @order.id
56
+ # assert_response :success
57
+ # end
58
+
59
+ # should "update order" do
60
+ # put :update, :id => @order.id, :order => { :order => Factory.create(:order) }
61
+ # assert_redirected_to :controller => 'trolleys', :action => 'show', :user_id => @user.id
62
+ # end
63
+
64
+ # should "destroy order" do
65
+ # assert_difference('Order.count', -1) do
66
+ # delete :destroy, :id => @order_1.id
67
+ # end
68
+
69
+ # assert_redirected_to :controller => 'trolleys', :action => 'show', :user_id => @user.id
70
+ # end
71
+ end
72
+ end
73
+
74
+ end
75
+
@@ -0,0 +1,38 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'test_helper'
3
+
4
+ Webrat.configure do |config|
5
+ config.mode = :rails
6
+ end
7
+
8
+ class TrolliedTest < ActionController::IntegrationTest
9
+ context "A gets_trollied object" do
10
+ include Webrat::HaveTagMatcher
11
+ setup do
12
+ @item = Factory.create(:item)
13
+ @user = Factory.create(:user)
14
+ end
15
+
16
+ should "have an add to cart link on its show page" do
17
+ visit "/items/#{@item.id}"
18
+ assert_have_tag "input", :type => "submit", :value => I18n.t('gets_trollied_helper.add_to_trolley')
19
+ end
20
+
21
+ should "be able to submit add to trolley request and be added to trolley" do
22
+ visit "/items/#{@item.id}"
23
+ click_button "add to cart"
24
+ assert_have_tag "title", :content => I18n.t('trolleys.show.your_title')
25
+ assert_have_tag "a", :href => "/items/#{@item.id}", :content => @item.description_for_purchasing
26
+ end
27
+
28
+ # if an item has been placed in trolley previously, the add to trolley is replaced with link to trolley, and status of item shown
29
+ should "after being added to a trolley, the object on its show page report that it is in the trolley, rather than providing the button to add to trolley" do
30
+ @trolley = @user.trolley
31
+ @trolley.add(@item)
32
+
33
+ visit "/items/#{@item.id}"
34
+ assert_have_tag "div", :content => I18n.t('gets_trollied_helper.in_trolley')
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,79 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'test_helper'
3
+
4
+ Webrat.configure do |config|
5
+ config.mode = :rails
6
+ end
7
+
8
+ class OrderTest < ActionController::IntegrationTest
9
+ include Webrat::HaveTagMatcher
10
+
11
+ context "The orders index page" do
12
+
13
+ context "when there are no orders on the site" do
14
+
15
+ should "return message that there are currently no orders" do
16
+ visit "/orders"
17
+ assert_have_tag "p", :content => I18n.t('orders.index.no_orders')
18
+ end
19
+ end
20
+
21
+ context "when there are orders" do
22
+ setup do
23
+ @item = Factory.create(:item)
24
+ @order = Factory.create(:order)
25
+ @item.place_in(@order.trolley)
26
+ end
27
+
28
+ context "that are current" do
29
+
30
+ should "return message that there are no orders unless state = current" do
31
+ visit "/orders"
32
+ assert_have_tag "p", :content => I18n.t('orders.index.no_orders')
33
+ end
34
+
35
+ should "have link to view current orders" do
36
+ visit "/orders"
37
+ assert_have_tag "a", :content => I18n.t('orders.index.current')
38
+
39
+ click_link I18n.t('orders.index.current')
40
+
41
+ assert_have_tag "a", :content => @item.description_for_purchasing
42
+ end
43
+ end
44
+
45
+ context "that are in_process" do
46
+ setup do
47
+ @order.checkout!
48
+ end
49
+
50
+ should "indicate that there are in_process orders and display them" do
51
+ visit "/orders"
52
+ assert_have_tag "li", :content => I18n.t('orders.index.in_process')
53
+ assert_have_tag "a", :content => @item.description_for_purchasing
54
+ end
55
+ end
56
+
57
+ end
58
+
59
+ context "when a trolley is given" do
60
+ setup do
61
+ @trolley = Factory.create(:trolley)
62
+ end
63
+
64
+ context "when there are no orders in the trolley" do
65
+
66
+ should "return message that there are currently no orders" do
67
+ visit "/orders?trolley_id=#{@trolley.id}"
68
+ assert_have_tag "p", :content => I18n.t('orders.index.no_orders')
69
+ end
70
+ end
71
+
72
+ context "when there are orders" do
73
+
74
+ end
75
+
76
+ end
77
+
78
+ end
79
+ end
@@ -0,0 +1,71 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'test_helper'
3
+
4
+ Webrat.configure do |config|
5
+ config.mode = :rails
6
+ end
7
+
8
+ class TrolleyTest < ActionController::IntegrationTest
9
+ context "A trolley" do
10
+ include Webrat::HaveTagMatcher
11
+ setup do
12
+ @item = Factory.create(:item)
13
+ @user = Factory.create(:user)
14
+ @trolley = @user.trolley
15
+ end
16
+
17
+ context "when there are line items in a current order" do
18
+ setup do
19
+ @item.place_in(@trolley)
20
+ @order = @trolley.selected_order
21
+ @line_item = @order.line_items.first
22
+ end
23
+
24
+ context "lists a current order and" do
25
+
26
+ should "have the line item listed" do
27
+ visit "/user/#{@user.id}/trolley"
28
+ assert_have_tag "a", :href => "/items/#{@item.id}", :content => @item.description_for_purchasing
29
+ end
30
+
31
+ should "have a drop line item link for line item" do
32
+ visit "/user/#{@user.id}/trolley"
33
+ click_link "Delete"
34
+ # assert that we are redirected back to trolley
35
+ assert_have_tag "title", :content => I18n.t('trolleys.show.your_title')
36
+ end
37
+
38
+ should "have a clear all button" do
39
+ visit "/user/#{@user.id}/trolley"
40
+ assert_have_tag "input", :type => "submit", :value => I18n.t('orders.order.destroy')
41
+
42
+ click_button I18n.t('orders.order.destroy')
43
+
44
+ assert_have_tag "p", :content => I18n.t('trolleys.orders.none_pending')
45
+ end
46
+
47
+ should "have a checkout button that moves the order out of current status" do
48
+ visit "/user/#{@user.id}/trolley"
49
+ assert_have_tag "input", :type => "submit", :value => I18n.t('orders.order.checkout')
50
+
51
+ click_button I18n.t('orders.order.checkout')
52
+
53
+ assert_have_tag "p", :content => I18n.t('trolleys.orders.none_pending')
54
+ end
55
+
56
+ should "have a cancel button that moves the order out of current status and marks it as cancelled" do
57
+ @order.checkout!
58
+
59
+ visit "/user/#{@user.id}/trolley"
60
+ assert_have_tag "input", :type => "submit", :value => I18n.t('orders.order.cancel')
61
+
62
+ click_button I18n.t('orders.order.cancel')
63
+
64
+ # cancelled orders are not listed on trolley
65
+ # assert_have_tag "h2", :content => I18n.t('orders.order.cancelled')
66
+ end
67
+
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+ require 'performance_test_help'
3
+
4
+ # Profiling results for each test method are written to tmp/performance.
5
+ class BrowsingTest < ActionController::PerformanceTest
6
+ def test_homepage
7
+ get '/'
8
+ end
9
+ end
@@ -0,0 +1,83 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'test_helper'
3
+
4
+ # This file is not in integration/ because when run with
5
+ # 'rake', it causes segfaults in the test suite
6
+
7
+ # ATTN: Before runnings these tests, be sure to turn
8
+ # off all extensions and popup blockers in Safari
9
+
10
+ class ActiveSupport::TestCase
11
+ self.use_transactional_fixtures = true
12
+ setup do |session|
13
+ session.host! "localhost:3001"
14
+ end
15
+ end
16
+
17
+ Webrat.configure do |config|
18
+ config.mode = :selenium
19
+ config.application_environment = :test
20
+ config.selenium_browser_key = '*safari'
21
+ end
22
+
23
+ class SeleniumTest < ActionController::IntegrationTest
24
+ context "Using Selenium to test javascript functionality" do
25
+
26
+ # DEBUG: This works so if the others don't, try just this one
27
+ # should "be able to visit the homepage" do
28
+ # visit "/"
29
+ # assert_contain "Welcome aboard"
30
+ # end
31
+
32
+ should "be able to translate an item via AJAX" do
33
+ item = create_item
34
+ click_link "Français"
35
+ assert current_url =~ /\/en\/items\/#{item.id}$/
36
+ assert_contain "Translate from English to Français"
37
+ fill_in 'item_translation_label', :with => 'Certains Point'
38
+ click_button 'Create'
39
+ assert_contain 'Translation was successfully created.'
40
+ end
41
+
42
+ should "be able to switch translations" do
43
+ item = create_item
44
+ click_link "Français"
45
+ assert current_url =~ /\/en\/items\/#{item.id}$/
46
+ assert_contain "Translate from English to Français"
47
+ click_link "Suomi"
48
+ assert current_url =~ /\/en\/items\/#{item.id}$/
49
+ assert_contain "Translate from English to Suomi"
50
+ end
51
+
52
+ should "be able to close the translations box" do
53
+ item = create_item
54
+ click_link "Français"
55
+ click_link "[close]"
56
+ assert_not_contain "Translate from English to Français"
57
+ end
58
+
59
+ should "be able to use the auto translate functionality" do
60
+ item = create_item
61
+ visit "/en/items/#{item.id}/translations/new?to_locale=fr"
62
+ click_link '[auto translate]'
63
+ sleep 1 # ugly way to wait for google to do it's thing
64
+ click_button 'Create'
65
+ assert_contain 'Translation was successfully created.'
66
+ assert_contain 'Certains Point'
67
+ end
68
+
69
+ end
70
+
71
+ private
72
+
73
+ def create_item
74
+ visit "/en/items"
75
+ click_link "New item"
76
+ fill_in 'item_label', :with => 'Some Item'
77
+ fill_in 'item_value', :with => '$3.50'
78
+ fill_in 'item_locale', :with => 'en'
79
+ click_button 'Create'
80
+ assert_contain 'Item was successfully created.'
81
+ Item.last
82
+ end
83
+ end
@@ -0,0 +1,54 @@
1
+ # -*- coding: utf-8 -*-
2
+ ENV["RAILS_ENV"] = "test"
3
+ require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
4
+ require 'test_help'
5
+ require 'rubygems'
6
+ require 'shoulda'
7
+ require 'factory_girl'
8
+ require "webrat"
9
+
10
+ require File.expand_path(File.dirname(__FILE__) + "/factories")
11
+
12
+ Webrat.configure do |config|
13
+ config.mode = :rails
14
+ end
15
+
16
+ class ActiveSupport::TestCase
17
+ # Transactional fixtures accelerate your tests by wrapping each test method
18
+ # in a transaction that's rolled back on completion. This ensures that the
19
+ # test database remains unchanged so your fixtures don't have to be reloaded
20
+ # between every test method. Fewer database queries means faster tests.
21
+ #
22
+ # Read Mike Clark's excellent walkthrough at
23
+ # http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting
24
+ #
25
+ # Every Active Record database supports transactions except MyISAM tables
26
+ # in MySQL. Turn off transactional fixtures in this case; however, if you
27
+ # don't care one way or the other, switching from MyISAM to InnoDB tables
28
+ # is recommended.
29
+ #
30
+ # The only drawback to using transactional fixtures is when you actually
31
+ # need to test transactions. Since your test is bracketed by a transaction,
32
+ # any transactions started in your code will be automatically rolled back.
33
+ # self.use_transactional_fixtures = true
34
+
35
+ # Instantiated fixtures are slow, but give you @david where otherwise you
36
+ # would need people(:david). If you don't want to migrate your existing
37
+ # test cases which use the @david style and don't mind the speed hit (each
38
+ # instantiated fixtures translates to a database query per test method),
39
+ # then set this back to true.
40
+ # self.use_instantiated_fixtures = false
41
+
42
+ # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
43
+ #
44
+ # Note: You'll currently still have to declare fixtures explicitly in integration tests
45
+ # -- they do not yet inherit this setting
46
+ # fixtures :all
47
+
48
+ # Add more helper methods to be used by all tests here...
49
+ end
50
+
51
+ def assert_purchasable_item_matches
52
+ assert @order.line_items.size == 1
53
+ assert_equal @item, @order.line_items.first.purchasable_item
54
+ end
@@ -0,0 +1,29 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'test_helper'
3
+
4
+ class GetsTrolliedTest < ActiveSupport::TestCase
5
+ context "A model that can be trollied" do
6
+ setup do
7
+ @item = Factory.create(:item)
8
+ end
9
+
10
+ should "be able to be added to a trolley" do
11
+ @trolley = Factory.create(:trolley)
12
+ @item.place_in(@trolley)
13
+
14
+ assert @trolley.selected_order
15
+
16
+ @order = @trolley.selected_order
17
+
18
+ assert_purchasable_item_matches
19
+ end
20
+
21
+ should "answer description_for_purchasing" do
22
+ assert_respond_to @item, :description_for_purchasing
23
+ end
24
+
25
+ should "return mapped attribute value from description_for_purchasing" do
26
+ assert_equal @item.label, @item.description_for_purchasing
27
+ end
28
+ end
29
+ end