office_clerk 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (259) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +73 -0
  3. data/.rubocop.yml +6 -0
  4. data/.travis.yml +9 -0
  5. data/Gemfile +63 -0
  6. data/Gemfile.lock +367 -0
  7. data/Guardfile +28 -0
  8. data/README.md +44 -0
  9. data/Rakefile +6 -0
  10. data/app/assets/images/admin/baskets-2.jpg +0 -0
  11. data/app/assets/images/admin/baskets.jpg +0 -0
  12. data/app/assets/images/admin/categories-2.jpg +0 -0
  13. data/app/assets/images/admin/categories.jpg +0 -0
  14. data/app/assets/images/admin/clerks-2.jpg +0 -0
  15. data/app/assets/images/admin/clerks.jpg +0 -0
  16. data/app/assets/images/admin/orders-2.jpg +0 -0
  17. data/app/assets/images/admin/orders.jpg +0 -0
  18. data/app/assets/images/admin/products-2.jpg +0 -0
  19. data/app/assets/images/admin/products.jpg +0 -0
  20. data/app/assets/images/admin/purchases-2.jpg +0 -0
  21. data/app/assets/images/admin/purchases.jpg +0 -0
  22. data/app/assets/images/admin/suppliers-2.jpg +0 -0
  23. data/app/assets/images/admin/suppliers.jpg +0 -0
  24. data/app/assets/images/alpha.png +0 -0
  25. data/app/assets/images/down-icon.png +0 -0
  26. data/app/assets/images/header.gif +0 -0
  27. data/app/assets/images/hihih.jpg +0 -0
  28. data/app/assets/images/hue.png +0 -0
  29. data/app/assets/images/koe.jpg +0 -0
  30. data/app/assets/images/missing.png +0 -0
  31. data/app/assets/images/saturation.png +0 -0
  32. data/app/assets/images/shop/basket.jpg +0 -0
  33. data/app/assets/images/shop/farfalla-logo.jpg +0 -0
  34. data/app/assets/images/shop/header.gif +0 -0
  35. data/app/assets/images/shop/header.jpg +0 -0
  36. data/app/assets/images/shop/header.png +0 -0
  37. data/app/assets/images/shop/kansi.jpg +0 -0
  38. data/app/assets/images/shop/kansi.png +0 -0
  39. data/app/assets/images/shop/logo.png +0 -0
  40. data/app/assets/images/shop/menu-gourmet.jpg +0 -0
  41. data/app/assets/images/shop/menu-hius.jpg +0 -0
  42. data/app/assets/images/shop/menu-huonetuoksu.jpg +0 -0
  43. data/app/assets/images/shop/menu-info.jpg +0 -0
  44. data/app/assets/images/shop/menu-kasvo.jpg +0 -0
  45. data/app/assets/images/shop/menu-laukut.jpg +0 -0
  46. data/app/assets/images/shop/menu-luomu.jpg +0 -0
  47. data/app/assets/images/shop/menu-men.jpg +0 -0
  48. data/app/assets/images/shop/menu-oljy.jpg +0 -0
  49. data/app/assets/images/shop/menu-tuoksu1.jpg +0 -0
  50. data/app/assets/images/shop/menu-vaatteet.jpg +0 -0
  51. data/app/assets/images/shop/menu-valaisin.jpg +0 -0
  52. data/app/assets/images/shop/menu-vartalo.jpg +0 -0
  53. data/app/assets/images/shop/spacer.gif +0 -0
  54. data/app/assets/images/shop/tausta.jpg +0 -0
  55. data/app/assets/images/shop/tervetuloa.gif +0 -0
  56. data/app/assets/images/shop/valk.png +0 -0
  57. data/app/assets/images/shop/valk3.png +0 -0
  58. data/app/assets/images/shop/violetti-lev.jpg +0 -0
  59. data/app/assets/images/shop/violetti.jpg +0 -0
  60. data/app/assets/images/ui-anim_basic_16x16.gif +0 -0
  61. data/app/assets/images/up-icon.png +0 -0
  62. data/app/assets/javascripts/admin.js +29 -0
  63. data/app/assets/javascripts/shop.js +30 -0
  64. data/app/assets/stylesheets/admin.css.scss +129 -0
  65. data/app/assets/stylesheets/shop-receipt.css.scss +80 -0
  66. data/app/assets/stylesheets/shop.css.scss +403 -0
  67. data/app/controllers/admin_controller.rb +23 -0
  68. data/app/controllers/application_controller.rb +41 -0
  69. data/app/controllers/baskets_controller.rb +176 -0
  70. data/app/controllers/categories_controller.rb +69 -0
  71. data/app/controllers/clerks_controller.rb +64 -0
  72. data/app/controllers/orders_controller.rb +57 -0
  73. data/app/controllers/products_controller.rb +126 -0
  74. data/app/controllers/purchases_controller.rb +72 -0
  75. data/app/controllers/sessions_controller.rb +46 -0
  76. data/app/controllers/shop_controller.rb +90 -0
  77. data/app/controllers/suppliers_controller.rb +63 -0
  78. data/app/helpers/admin_helper.rb +28 -0
  79. data/app/helpers/application_helper.rb +25 -0
  80. data/app/helpers/baskets_helper.rb +4 -0
  81. data/app/helpers/categories_helper.rb +4 -0
  82. data/app/helpers/orders_helper.rb +4 -0
  83. data/app/helpers/products_helper.rb +4 -0
  84. data/app/helpers/purchases_helper.rb +4 -0
  85. data/app/helpers/shop_helper.rb +17 -0
  86. data/app/helpers/suppliers_helper.rb +4 -0
  87. data/app/mailers/.keep +0 -0
  88. data/app/models/basket.rb +114 -0
  89. data/app/models/category.rb +27 -0
  90. data/app/models/clerk.rb +46 -0
  91. data/app/models/item.rb +26 -0
  92. data/app/models/order.rb +72 -0
  93. data/app/models/product.rb +100 -0
  94. data/app/models/purchase.rb +26 -0
  95. data/app/models/supplier.rb +15 -0
  96. data/app/views/addresses/_form_fields.html.haml +4 -0
  97. data/app/views/addresses/show.html.haml +23 -0
  98. data/app/views/baskets/_small.html.haml +25 -0
  99. data/app/views/baskets/edit.html.haml +74 -0
  100. data/app/views/baskets/index.html.haml +55 -0
  101. data/app/views/baskets/show.html.haml +18 -0
  102. data/app/views/categories/_treeview.html.haml +8 -0
  103. data/app/views/categories/_triple.html.haml +12 -0
  104. data/app/views/categories/edit.html.haml +36 -0
  105. data/app/views/categories/index.html.haml +49 -0
  106. data/app/views/categories/show.html.haml +30 -0
  107. data/app/views/clerks/edit.html.haml +20 -0
  108. data/app/views/clerks/index.html.haml +37 -0
  109. data/app/views/clerks/show.html.haml +19 -0
  110. data/app/views/layouts/_admin_menu.html.haml +14 -0
  111. data/app/views/layouts/_google.haml +8 -0
  112. data/app/views/layouts/_messages.html.haml +5 -0
  113. data/app/views/layouts/admin.html.haml +42 -0
  114. data/app/views/layouts/shop.html.haml +96 -0
  115. data/app/views/orders/edit.html.haml +25 -0
  116. data/app/views/orders/index.html.haml +93 -0
  117. data/app/views/orders/show.html.haml +37 -0
  118. data/app/views/products/_line.html.haml +25 -0
  119. data/app/views/products/_name.html.haml +4 -0
  120. data/app/views/products/_online.html.haml +2 -0
  121. data/app/views/products/_triple.html.haml +12 -0
  122. data/app/views/products/edit.html.haml +42 -0
  123. data/app/views/products/index.html.haml +86 -0
  124. data/app/views/products/show.html.haml +94 -0
  125. data/app/views/purchases/edit.html.haml +9 -0
  126. data/app/views/purchases/index.html.haml +52 -0
  127. data/app/views/purchases/show.html.haml +32 -0
  128. data/app/views/sessions/new.html.haml +10 -0
  129. data/app/views/sessions/new_clerk.html.haml +22 -0
  130. data/app/views/shop/_groups.html.haml +8 -0
  131. data/app/views/shop/_menu.html.haml +5 -0
  132. data/app/views/shop/_sub.html.haml +0 -0
  133. data/app/views/shop/checkout.haml +142 -0
  134. data/app/views/shop/group.html.haml +9 -0
  135. data/app/views/shop/main_group.html.haml +9 -0
  136. data/app/views/shop/order.haml +104 -0
  137. data/app/views/shop/product.html.haml +67 -0
  138. data/app/views/shop/product_list.html.haml +50 -0
  139. data/app/views/shop/saved_search.html +6 -0
  140. data/app/views/shop/sub_group.html.haml +19 -0
  141. data/app/views/shop/tuotteista.html.haml +40 -0
  142. data/app/views/shop/welcome.html.haml +103 -0
  143. data/app/views/suppliers/edit.html.haml +10 -0
  144. data/app/views/suppliers/index.html.haml +40 -0
  145. data/app/views/suppliers/show.html.haml +27 -0
  146. data/bin/bundle +3 -0
  147. data/bin/rails +8 -0
  148. data/bin/rake +8 -0
  149. data/bin/rspec +7 -0
  150. data/bin/spring +18 -0
  151. data/config.ru +7 -0
  152. data/config/application.example.yml +13 -0
  153. data/config/application.rb +59 -0
  154. data/config/application.yml +13 -0
  155. data/config/boot.rb +7 -0
  156. data/config/database.yml +25 -0
  157. data/config/environment.rb +6 -0
  158. data/config/environments/development.rb +31 -0
  159. data/config/environments/production.rb +80 -0
  160. data/config/environments/test.rb +36 -0
  161. data/config/i18n-tasks.yml +11 -0
  162. data/config/initializers/attack.rb +32 -0
  163. data/config/initializers/backtrace_silencers.rb +7 -0
  164. data/config/initializers/filter_parameter_logging.rb +4 -0
  165. data/config/initializers/inflections.rb +16 -0
  166. data/config/initializers/migrate.rb +6 -0
  167. data/config/initializers/mime_types.rb +6 -0
  168. data/config/initializers/secret_token.rb +12 -0
  169. data/config/initializers/session_store.rb +3 -0
  170. data/config/initializers/simple_form.rb +149 -0
  171. data/config/initializers/simple_form_bootstrap.rb +48 -0
  172. data/config/initializers/wrap_parameters.rb +14 -0
  173. data/config/locales/config.yml +23 -0
  174. data/config/locales/en.yml +183 -0
  175. data/config/locales/fi.yml +211 -0
  176. data/config/routes.rb +108 -0
  177. data/db/migrate/20131224171442_clerks.rb +15 -0
  178. data/db/migrate/20131226110406_suppliers.rb +9 -0
  179. data/db/migrate/20131226143612_categories.rb +18 -0
  180. data/db/migrate/20131226143747_items.rb +14 -0
  181. data/db/migrate/20131226144134_orders.rb +21 -0
  182. data/db/migrate/20131226144316_baskets.rb +12 -0
  183. data/db/migrate/20131226151151_purchases.rb +11 -0
  184. data/db/migrate/20131226151332_products.rb +27 -0
  185. data/db/schema.rb +138 -0
  186. data/db/seeds.rb +4 -0
  187. data/lib/assets/.keep +0 -0
  188. data/lib/office_clerk.rb +20 -0
  189. data/lib/office_clerk/shipping_method.rb +35 -0
  190. data/lib/tasks/.keep +0 -0
  191. data/lib/tasks/import.rake +33 -0
  192. data/lib/templates/haml/scaffold/_form.html.haml +8 -0
  193. data/office_clerk.gemspec +46 -0
  194. data/public/404.html +58 -0
  195. data/public/422.html +58 -0
  196. data/public/500.html +57 -0
  197. data/public/favicon.ico +0 -0
  198. data/public/humans.txt +20 -0
  199. data/public/robots.txt +5 -0
  200. data/spec/controllers/baskets_controller_spec.rb +112 -0
  201. data/spec/controllers/categories_controller_spec.rb +133 -0
  202. data/spec/controllers/clerks_controller_spec.rb +70 -0
  203. data/spec/controllers/orders_controller_spec.rb +105 -0
  204. data/spec/controllers/products_controller_spec.rb +138 -0
  205. data/spec/controllers/purchases_controller_spec.rb +123 -0
  206. data/spec/controllers/sessions_controller_spec.rb +18 -0
  207. data/spec/controllers/suppliers_controller_spec.rb +137 -0
  208. data/spec/factories/addresses.rb +11 -0
  209. data/spec/factories/baskets.rb +15 -0
  210. data/spec/factories/categories.rb +8 -0
  211. data/spec/factories/clerks.rb +15 -0
  212. data/spec/factories/items.rb +19 -0
  213. data/spec/factories/orders.rb +9 -0
  214. data/spec/factories/products.rb +10 -0
  215. data/spec/factories/purchases.rb +10 -0
  216. data/spec/factories/suppliers.rb +7 -0
  217. data/spec/features/baskets/buttons_spec.rb +35 -0
  218. data/spec/features/baskets/edit_spec.rb +50 -0
  219. data/spec/features/baskets/index_spec.rb +12 -0
  220. data/spec/features/baskets/search_spec.rb +33 -0
  221. data/spec/features/baskets/show_spec.rb +21 -0
  222. data/spec/features/categories_spec.rb +21 -0
  223. data/spec/features/clerks_spec.rb +21 -0
  224. data/spec/features/orders_spec.rb +14 -0
  225. data/spec/features/products/index_spec.rb +30 -0
  226. data/spec/features/products/new_spec.rb +20 -0
  227. data/spec/features/purchases_spec.rb +14 -0
  228. data/spec/features/shops_spec.rb +18 -0
  229. data/spec/features/suppliers_spec.rb +18 -0
  230. data/spec/models/baskets/inventory_spec.rb +34 -0
  231. data/spec/models/baskets/items_spec.rb +37 -0
  232. data/spec/models/baskets/products_spec.rb +31 -0
  233. data/spec/models/category_spec.rb +18 -0
  234. data/spec/models/clerk/email_spec.rb +69 -0
  235. data/spec/models/clerk/password_spec.rb +83 -0
  236. data/spec/models/item_spec.rb +33 -0
  237. data/spec/models/locale_spec.rb +17 -0
  238. data/spec/models/order_spec.rb +19 -0
  239. data/spec/models/product_spec.rb +29 -0
  240. data/spec/models/purchase_spec.rb +8 -0
  241. data/spec/models/supplier_spec.rb +8 -0
  242. data/spec/routing/baskets_routing_spec.rb +35 -0
  243. data/spec/routing/categories_routing_spec.rb +35 -0
  244. data/spec/routing/orders_routing_spec.rb +35 -0
  245. data/spec/routing/products_routing_spec.rb +35 -0
  246. data/spec/routing/purchases_routing_spec.rb +35 -0
  247. data/spec/routing/suppliers_routing_spec.rb +35 -0
  248. data/spec/spec_helper.rb +74 -0
  249. data/spec/support/request_helper.rb +31 -0
  250. data/test/fixtures/baskets.yml +41993 -0
  251. data/test/fixtures/categories.yml +638 -0
  252. data/test/fixtures/clerks.yml +694 -0
  253. data/test/fixtures/items.yml +83651 -0
  254. data/test/fixtures/orders.yml +58918 -0
  255. data/test/fixtures/products.yml +110904 -0
  256. data/test/fixtures/purchases.yml +1755 -0
  257. data/test/fixtures/suppliers.yml +341 -0
  258. data/todo +8 -0
  259. metadata +607 -0
@@ -0,0 +1,137 @@
1
+ require 'spec_helper'
2
+
3
+ describe SuppliersController do
4
+
5
+ # This should return the minimal set of attributes required to create a valid
6
+ # Supplier. As you add validations to Supplier, be sure to
7
+ # adjust the attributes here as well.
8
+ let(:supplier_attributes) do
9
+ {:supplier => attributes_for(:supplier)}
10
+ end
11
+ before :all do
12
+ create :admin unless Clerk.where(:admin => true).first
13
+ end
14
+
15
+ # This should return the minimal set of values that should be in the session
16
+ # in order to pass any filters (e.g. authentication) defined in
17
+ # SuppliersController. Be sure to keep this updated too.
18
+ let(:valid_session) { { :clerk_email => Clerk.where(:admin => true).first.email } }
19
+
20
+ describe "GET index" do
21
+ it "assigns all suppliers as @suppliers" do
22
+ before = Supplier.count
23
+ create :supplier
24
+ get :index, {}, valid_session
25
+ expect(Supplier.count).to be before + 1
26
+ end
27
+ end
28
+
29
+ describe "GET show" do
30
+ it "assigns the requested supplier as @supplier" do
31
+ supplier = create :supplier
32
+ get :show, {:id => supplier.to_param}, valid_session
33
+ expect(assigns(:supplier)).to eq(supplier)
34
+ end
35
+ end
36
+
37
+ describe "GET new" do
38
+ it "assigns a new supplier as @supplier" do
39
+ get :new, {}, valid_session
40
+ expect(assigns(:supplier)).to be_kind_of(Supplier)
41
+ expect(assigns(:supplier)).to be_new_record
42
+ end
43
+ end
44
+
45
+ describe "GET edit" do
46
+ it "assigns the requested supplier as @supplier" do
47
+ supplier = create :supplier
48
+ get :edit, {:id => supplier.to_param}, valid_session
49
+ expect(assigns(:supplier)).to eq(supplier)
50
+ end
51
+ end
52
+
53
+ describe "POST create" do
54
+ describe "with valid params" do
55
+ it "creates a new Supplier" do
56
+ expect {
57
+ post :create, supplier_attributes, valid_session
58
+ }.to change(Supplier, :count).by(1)
59
+ end
60
+
61
+ it "assigns a newly created supplier as @supplier" do
62
+ post :create, supplier_attributes, valid_session
63
+ expect(assigns(:supplier)).to be_kind_of(Supplier)
64
+ expect(assigns(:supplier)).to be_persisted
65
+ end
66
+
67
+ it "redirects to the created supplier" do
68
+ post :create, supplier_attributes , valid_session
69
+ expect(response).to redirect_to(Supplier.unscoped.last)
70
+ end
71
+ end
72
+
73
+ describe "with invalid params" do
74
+ it "assigns a newly created but unsaved supplier as @supplier" do
75
+ # Trigger the behavior that occurs when invalid params are submitted
76
+ allow_any_instance_of(Supplier).to receive(:save).and_return(false)
77
+ post :create, {:supplier => { :name => "" }}, valid_session
78
+ expect(assigns(:supplier)).to be_kind_of(Supplier)
79
+ expect(assigns(:supplier)).to be_new_record
80
+ end
81
+
82
+ it "re-renders the 'new' template" do
83
+ # Trigger the behavior that occurs when invalid params are submitted
84
+ allow_any_instance_of(Supplier).to receive(:save).and_return(false)
85
+ post :create, {:supplier => { :name => "" }}, valid_session
86
+ expect(response).to render_template(:edit)
87
+ end
88
+ end
89
+ end
90
+
91
+ describe "PUT update" do
92
+ describe "with valid params" do
93
+ it "assigns the requested supplier as @supplier" do
94
+ supplier = create :supplier
95
+ attributes = supplier_attributes
96
+ attributes[:id] = supplier.id
97
+ put :update, attributes , valid_session
98
+ expect(response).to redirect_to(supplier)
99
+ expect(assigns(:supplier)).to eq(supplier)
100
+ end
101
+ end
102
+
103
+ describe "with invalid params" do
104
+ it "assigns the supplier as @supplier" do
105
+ supplier = create :supplier
106
+ # Trigger the behavior that occurs when invalid params are submitted
107
+ allow_any_instance_of(Supplier).to receive(:save).and_return(false)
108
+ put :update, {:id => supplier.to_param, :supplier => { :name => "" }}, valid_session
109
+ expect(assigns(:supplier)).to eq(supplier)
110
+ end
111
+
112
+ it "re-renders the 'edit' template" do
113
+ supplier = create :supplier
114
+ # Trigger the behavior that occurs when invalid params are submitted
115
+ allow_any_instance_of(Supplier).to receive(:save).and_return(false)
116
+ put :update, {:id => supplier.to_param, :supplier => { :name => "" }}, valid_session
117
+ expect(response).to render_template(:edit)
118
+ end
119
+ end
120
+ end
121
+
122
+ describe "DELETE destroy" do
123
+ it "destroys the requested supplier" do
124
+ supplier = create :supplier
125
+ expect {
126
+ delete :destroy, {:id => supplier.to_param}, valid_session
127
+ }.to change(Supplier, :count).by(0)
128
+ end
129
+
130
+ it "redirects to the suppliers list" do
131
+ supplier = create :supplier
132
+ delete :destroy, {:id => supplier.to_param}, valid_session
133
+ expect(response).to redirect_to(suppliers_path)
134
+ end
135
+ end
136
+
137
+ end
@@ -0,0 +1,11 @@
1
+ # Read about factories at https://github.com/thoughtbot/factory_girl
2
+
3
+ FactoryGirl.define do
4
+ factory :address do
5
+ first_name "Torsten"
6
+ last_name "Ruger"
7
+ street1 "Fiskarsintie 513"
8
+ city "10480 antskog"
9
+ country "Suomi"
10
+ end
11
+ end
@@ -0,0 +1,15 @@
1
+ # Read about factories at https://github.com/thoughtbot/factory_girl
2
+
3
+ FactoryGirl.define do
4
+ factory :basket do
5
+ factory :basket_with_item do
6
+ items {build_list :item , 1 }
7
+ end
8
+ factory :basket_2_items do
9
+ items {[FactoryGirl.create(:item2) , FactoryGirl.create(:item22)]}
10
+ end
11
+ factory :basket_3_items do
12
+ items {build_list :item_quantity , 3 }
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,8 @@
1
+ # Read about factories at https://github.com/thoughtbot/factory_girl
2
+
3
+ FactoryGirl.define do
4
+ factory :category do
5
+ sequence(:name) {|n| "Gourmet#{n}"}
6
+ sequence(:link) {|n| "gourmet#{n}"}
7
+ end
8
+ end
@@ -0,0 +1,15 @@
1
+ # Read about factories at https://github.com/thoughtbot/factory_girl
2
+
3
+ FactoryGirl.define do
4
+ factory :clerk do
5
+ sequence( :name) { |n| "Test Clerk#{n}" }
6
+ sequence( :email) { |n| "test#{n}@test.com" }
7
+ password 'password'
8
+ password_confirmation 'password'
9
+ # confirmed_at Time.now
10
+ factory :admin do
11
+ sequence( :email) { |n| "admin#{n}@test.com" }
12
+ admin true
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,19 @@
1
+ # Read about factories at https://github.com/thoughtbot/factory_girl
2
+
3
+ FactoryGirl.define do
4
+ factory :item do
5
+ product
6
+ quantity 1
7
+ price {product.price}
8
+ tax 10
9
+ sequence( :name) { |n| "product #{n}" }
10
+ factory :item_quantity do
11
+ quantity 1
12
+ end
13
+ factory :item2 do
14
+ factory :item22 do
15
+ quantity 2
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,9 @@
1
+ # Read about factories at https://github.com/thoughtbot/factory_girl
2
+
3
+ FactoryGirl.define do
4
+ factory :order do
5
+ sequence( :email) { |n| "test#{n}@test.com" }
6
+ shipment_tax 0
7
+ basket
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ # Read about factories at https://github.com/thoughtbot/factory_girl
2
+
3
+ FactoryGirl.define do
4
+ #minimal product
5
+ factory :product do
6
+ sequence( :name) { |n| "product #{n}" }
7
+ sequence :price , 10
8
+ inventory 5
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # Read about factories at https://github.com/thoughtbot/factory_girl
2
+
3
+ FactoryGirl.define do
4
+ factory :purchase do
5
+ name "purchase"
6
+ ordered_on "2013-12-26"
7
+ received_on "2013-12-26"
8
+ basket
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ # Read about factories at https://github.com/thoughtbot/factory_girl
2
+
3
+ FactoryGirl.define do
4
+ factory :supplier do
5
+ supplier_name "MyString"
6
+ end
7
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ # lots of buttons appear and disapear, check that that all works
4
+
5
+ describe "Basket buttons" do
6
+ before(:each) do
7
+ sign_in
8
+ end
9
+ it "should have back and update buttons" do
10
+ visit_path new_basket_path
11
+ expect(page).to have_content I18n.t(:back)
12
+ find_button I18n.t("helpers.submit.update" , :model => I18n.t(:basket))
13
+ find_link I18n.t(:new) + ' ' + I18n.t(:basket)
14
+ find_link I18n.t(:destroy)
15
+ end
16
+ it "creates a new order" do
17
+ basket = create :basket_with_item
18
+ visit_path edit_basket_path basket
19
+ expect(page).not_to have_content I18n.t(:to_order)
20
+ click_link I18n.t(:checkout)
21
+ expect(page).to have_content I18n.t("invoice.header")
22
+ end
23
+ it "goes to purchase" do
24
+ basket = create :basket_2_items
25
+ visit_path edit_basket_path(basket)
26
+ click_on I18n.t(:make_purchase)
27
+ expect(find("h2")).to have_content(I18n.t(:purchase))
28
+ end
29
+ it "finds print link" do
30
+ basket = create :basket_2_items
31
+ visit_path edit_basket_path(basket)
32
+ expect(page).to have_content(I18n.t(:checkout))
33
+ expect(find(".print_order")).to have_content(I18n.t(:checkout))
34
+ end
35
+ end
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+
3
+ # lots of edit possibilities for price/quantity and items
4
+
5
+ describe "edit baskets" do
6
+ before :each do
7
+ sign_in
8
+ end
9
+ it "deletes item" do
10
+ basket = create :basket_with_item
11
+ visit_path edit_basket_path(basket)
12
+ name = basket.items.first.name
13
+ within(".table") { first('a', :text => I18n.t(:delete)).click }
14
+ expect{ find(".table").find(".name" , :minimum => 1) }.to raise_error
15
+ expect(page).not_to have_content(name )
16
+ end
17
+ it "add quantity to item" do
18
+ basket = create :basket_with_item
19
+ visit_path edit_basket_path(basket)
20
+ expect(find( "//table #basket_items_attributes_0_quantity").value).to eq basket.items.first.quantity.to_s
21
+ fill_in "basket_items_attributes_0_quantity" , :with => 2
22
+ find(".commit").click()
23
+ td = find("//table #basket_items_attributes_0_quantity")
24
+ expect(td.value).to eq("2")
25
+ end
26
+ it "change item price" do
27
+ basket = create :basket_with_item
28
+ visit_path edit_basket_path(basket)
29
+ expect(find( "//table #basket_items_attributes_0_price").value).to eq basket.items.first.price.to_s
30
+ fill_in "basket_items_attributes_0_price" , :with => 20
31
+ find(".commit").click()
32
+ td = find("//table #basket_items_attributes_0_price")
33
+ expect(td.value).to eq("20.0")
34
+ end
35
+ it "discounts basket" do
36
+ basket = create :basket_with_item
37
+ total = basket.total_price
38
+ visit discount_basket_path(basket , :discount => "10")
39
+ expect_basket_total total * 0.9
40
+ end
41
+ it "discounts item" do
42
+ basket = create :basket_2_items
43
+ total = basket.total_price - basket.items.first.price*0.1
44
+ visit discount_basket_path(basket , :discount => "10" , :item => basket.items.first)
45
+ expect_basket_total total
46
+ td = find("//table #basket_items_attributes_0_price")
47
+ expect(td.value).to eq((basket.items.first.price*0.9).round(2).to_s)
48
+ end
49
+
50
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Basket index/search page" do
4
+ before(:each) do
5
+ sign_in
6
+ end
7
+ describe "GET /baskets" do
8
+ it "lists baskets" do
9
+ visit_path baskets_path
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Basket search functionality" do
4
+ before(:each) do
5
+ sign_in
6
+ end
7
+ # this adds the product to the basket as it finds exactly one
8
+ it "adds product by entering ean" do
9
+ visit_path new_basket_path
10
+ p = create :product , :ean => "123456Z"
11
+ within ".ean_form" do
12
+ fill_in "ean" , :with => "#{p.ean}"
13
+ click_on I18n.t(:search)
14
+ end
15
+ td = find(".table").find(".name")
16
+ expect(td).to have_content(p.name)
17
+ end
18
+ # this adds the product, but because we enter the name, it has to search and show a second page
19
+ # where we hit add
20
+ it "adds product by entering name" do
21
+ basket = create :basket
22
+ visit_path edit_basket_path basket
23
+ p = create :product
24
+ within ".ean_form" do
25
+ fill_in "ean" , :with => "#{p.name}"
26
+ click_on I18n.t(:search)
27
+ end
28
+ find(:xpath, "//tr[contains(., '#{p.name}')]/td/a", :text => I18n.t(:add_to_basket)).click
29
+ td = find(".table").find(".name")
30
+ expect(td).to have_content(p.name) # added the product, yes!
31
+ end
32
+
33
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe "edit basket screen, no editing" do
4
+ before :each do
5
+ sign_in
6
+ end
7
+ it "renders items" do
8
+ basket = create :basket_2_items
9
+ visit_path edit_basket_path(basket)
10
+ td = find(".table").first(".name")
11
+ expect(td).to have_content(basket.items.first.name)
12
+ end
13
+ it "renders 2 items with amount and total" do
14
+ basket = create :basket_2_items
15
+ visit_path edit_basket_path(basket)
16
+ td = find(".table").first(".name")
17
+ expect(td).to have_content(basket.items.first.name)
18
+ expect(find(".count").text).to include( I18n.t(:count))
19
+ expect_basket_total basket.total_price
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe Category do
4
+ before(:each) do
5
+ sign_in
6
+ end
7
+ it "lists product groups" do
8
+ visit_path categories_path
9
+ end
10
+ it "creates a new group" do
11
+ visit_path new_category_path
12
+ end
13
+ it :edit do
14
+ category = create(:category)
15
+ visit_path edit_category_path(category)
16
+ end
17
+ it "shows" do
18
+ category = create(:category)
19
+ visit_path category_path(category)
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe Clerk do
4
+ before(:each) do
5
+ sign_in
6
+ end
7
+ it "lists product groups" do
8
+ visit_path clerks_path
9
+ end
10
+ it "creates a new group" do
11
+ visit_path new_clerk_path
12
+ end
13
+ it :edit do
14
+ clerk = create(:clerk)
15
+ visit_path edit_clerk_path(clerk)
16
+ end
17
+ it "shows" do
18
+ clerk = create(:clerk)
19
+ visit_path clerk_path(clerk)
20
+ end
21
+ end