office_clerk 0.0.1 → 0.1

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 (77) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +14 -9
  3. data/README.md +1 -0
  4. data/app/assets/images/shop/ikkuna.jpg +0 -0
  5. data/app/assets/images/shop/violetti-lev.jpg +0 -0
  6. data/app/assets/javascripts/admin.js +2 -2
  7. data/app/assets/javascripts/shop.js +2 -1
  8. data/app/assets/stylesheets/shop-receipt.css.scss +1 -1
  9. data/app/assets/stylesheets/shop.css.scss +52 -31
  10. data/app/controllers/application_controller.rb +11 -5
  11. data/app/controllers/baskets_controller.rb +3 -27
  12. data/app/controllers/categories_controller.rb +2 -1
  13. data/app/controllers/clerks_controller.rb +3 -8
  14. data/app/controllers/manage_controller.rb +7 -0
  15. data/app/controllers/orders_controller.rb +16 -2
  16. data/app/controllers/products_controller.rb +20 -40
  17. data/app/controllers/purchases_controller.rb +2 -1
  18. data/app/controllers/sessions_controller.rb +15 -22
  19. data/app/helpers/admin_helper.rb +6 -8
  20. data/app/helpers/orders_helper.rb +6 -0
  21. data/app/models/basket.rb +1 -2
  22. data/app/models/category.rb +2 -0
  23. data/app/models/product.rb +43 -17
  24. data/app/models/purchase.rb +7 -6
  25. data/app/views/baskets/edit.html.haml +6 -8
  26. data/app/views/baskets/show.html.haml +1 -1
  27. data/app/views/clerks/edit.html.haml +1 -1
  28. data/app/views/layouts/_admin_menu.html.haml +2 -0
  29. data/app/views/layouts/admin.html.haml +9 -4
  30. data/app/views/layouts/shop.html.haml +8 -5
  31. data/app/views/manage/all.haml +3 -0
  32. data/app/views/orders/ship.haml +91 -0
  33. data/app/views/orders/show.html.haml +12 -4
  34. data/app/views/products/_head.haml +12 -0
  35. data/app/views/products/_line.html.haml +4 -8
  36. data/app/views/products/_online.html.haml +1 -1
  37. data/app/views/products/edit.html.haml +1 -7
  38. data/app/views/products/index.html.haml +4 -1
  39. data/app/views/products/show.html.haml +4 -18
  40. data/app/views/purchases/show.html.haml +3 -3
  41. data/app/views/sessions/{new.html.haml → sign_in.haml} +1 -1
  42. data/app/views/sessions/{new_clerk.html.haml → sign_up.haml} +2 -2
  43. data/app/views/shop/checkout.haml +3 -3
  44. data/app/views/shop/liikkeemme.html.haml +59 -0
  45. data/app/views/shop/order.haml +20 -15
  46. data/app/views/shop/product_list.html.haml +16 -13
  47. data/app/views/shop/tilaushistoria.html.haml +221 -0
  48. data/app/views/shop/toimitusehdot.html.haml +99 -0
  49. data/config/locales/config.yml +2 -1
  50. data/config/locales/en.yml +4 -5
  51. data/config/locales/fi.yml +13 -6
  52. data/config/routes.rb +11 -12
  53. data/lib/office_clerk/shipping_method.rb +1 -1
  54. data/office_clerk.gemspec +1 -1
  55. data/spec/controllers/products_controller_spec.rb +3 -3
  56. data/spec/controllers/sessions_controller_spec.rb +11 -3
  57. data/spec/factories/orders.rb +7 -1
  58. data/spec/factories/products.rb +16 -0
  59. data/spec/factories/purchases.rb +8 -4
  60. data/spec/features/baskets/buttons_spec.rb +1 -2
  61. data/spec/features/baskets/index_spec.rb +10 -4
  62. data/spec/features/clerks_spec.rb +22 -6
  63. data/spec/features/orders_spec.rb +18 -0
  64. data/spec/features/products/edit_spec.rb +32 -0
  65. data/spec/features/products/header_spec.rb +48 -0
  66. data/spec/features/products/index_spec.rb +4 -18
  67. data/spec/features/purchases_spec.rb +19 -0
  68. data/spec/features/sessions_spec.rb +58 -0
  69. data/spec/features/shop_spec.rb +63 -0
  70. data/spec/features/suppliers_spec.rb +2 -0
  71. data/spec/models/product_spec.rb +54 -8
  72. data/spec/models/purchase_spec.rb +20 -1
  73. data/spec/models/shipping_spec.rb +25 -0
  74. metadata +22 -9
  75. data/app/views/products/_name.html.haml +0 -4
  76. data/spec/features/products/new_spec.rb +0 -20
  77. data/spec/features/shops_spec.rb +0 -18
data/config/routes.rb CHANGED
@@ -1,20 +1,12 @@
1
1
  OfficeClerk::Application.routes.draw do
2
- resources :shops
3
2
 
4
3
  root :to => 'shop#group'
5
4
 
6
- get "sign_out" => "sessions#destroy", :as => "sign_out"
7
- get "sign_in" => "sessions#new", :as => "sign_in"
8
- get "sign_up" => "sessios#new_clerk", :as => "sign_up"
9
- # root :to => "clerks#new"
5
+ get "sign_out" => "sessions#sign_out"
6
+ get "sign_in" => "sessions#sign_in"
7
+ post "create_session" => "sessions#create"
8
+ match "sign_up" => "sessions#sign_up" , :via => [:get ,:post]
10
9
 
11
- resources :sessions do
12
- member do
13
- get :new_clerk
14
- get :create_clerk
15
- end
16
- end
17
-
18
10
  resources :purchases do
19
11
  collection do
20
12
  match "search" => "purchases#index", :via => [:get, :post]
@@ -43,6 +35,11 @@ OfficeClerk::Application.routes.draw do
43
35
  collection do
44
36
  match "search" => "orders#index", :via => [:get, :post]
45
37
  end
38
+ member do
39
+ get :pay
40
+ get :ship
41
+ patch :ship
42
+ end
46
43
  end
47
44
 
48
45
  resources :items do
@@ -92,6 +89,8 @@ OfficeClerk::Application.routes.draw do
92
89
  member do
93
90
  end
94
91
  end
92
+
93
+ match "manage/all" => "manage#all", :via => [:get, :post]
95
94
 
96
95
  #shop
97
96
  get 'group/:link' => 'shop#group', :as => :shop_group
@@ -29,7 +29,7 @@ module OfficeClerk
29
29
  super(data)
30
30
  end
31
31
  def price_for(basket)
32
- 0
32
+ 0.0
33
33
  end
34
34
  end
35
35
  end
data/office_clerk.gemspec CHANGED
@@ -5,7 +5,7 @@ $LOAD_PATH.unshift lib unless $LOAD_PATH.include?(lib)
5
5
  Gem::Specification.new do |s|
6
6
  s.platform = Gem::Platform::RUBY
7
7
  s.name = 'office_clerk'
8
- s.version = "0.0.1"
8
+ s.version = "0.1"
9
9
  s.summary = 'Backend of rubyclerks'
10
10
  s.description = s.summary
11
11
  s.required_ruby_version = '>= 1.9.3'
@@ -122,16 +122,16 @@ describe ProductsController do
122
122
 
123
123
  describe "DELETE destroy" do
124
124
  it "deletes the requested product" do
125
- product = Product.create! valid_attributes
125
+ product = create :product_without_inventory
126
126
  before = Product.count
127
127
  delete :delete, {:id => product.to_param}, valid_session
128
128
  expect(Product.count).to be before - 1
129
129
  end
130
130
 
131
- it "redirects to the products list" do
131
+ it "does not delete with inventory" do
132
132
  product = Product.create! valid_attributes
133
133
  delete :delete, {:id => product.to_param}, valid_session
134
- expect(response).to redirect_to(products_path)
134
+ expect(response).to redirect_to(product_path(product))
135
135
  end
136
136
  end
137
137
 
@@ -3,11 +3,11 @@ require File.dirname(__FILE__) + '/../spec_helper'
3
3
  describe SessionsController do
4
4
 
5
5
  it "new action should render new template" do
6
- get :new
7
- expect(response).to render_template(:new)
6
+ get :sign_in
7
+ expect(response).to render_template(:sign_in)
8
8
  end
9
9
 
10
- it "create action should redirect when authentication is valid" do
10
+ it "create action should redirect to root for user if authentication is valid" do
11
11
  allow_any_instance_of(Clerk).to receive(:valid_password?).and_return(true)
12
12
  clerk = create :clerk
13
13
  email = Clerk.where(:admin=>false).first.email
@@ -15,4 +15,12 @@ describe SessionsController do
15
15
  expect(response).to redirect_to(root_path)
16
16
  expect(session['clerk_email']).to eq email
17
17
  end
18
+ it "create action should redirect to baskets for admin if authentication is valid" do
19
+ allow_any_instance_of(Clerk).to receive(:valid_password?).and_return(true)
20
+ clerk = create :admin
21
+ email = Clerk.where(:admin=>true).first.email
22
+ post :create , :email => email
23
+ expect(response).to redirect_to(baskets_path)
24
+ expect(session['clerk_email']).to eq email
25
+ end
18
26
  end
@@ -4,6 +4,12 @@ FactoryGirl.define do
4
4
  factory :order do
5
5
  sequence( :email) { |n| "test#{n}@test.com" }
6
6
  shipment_tax 0
7
- basket
7
+ basket { create :basket_with_item }
8
+ factory :order_ordered do
9
+ ordered_on "2013-12-26"
10
+ factory :order_paid do
11
+ paid_on "2013-12-26"
12
+ end
13
+ end
8
14
  end
9
15
  end
@@ -6,5 +6,21 @@ FactoryGirl.define do
6
6
  sequence( :name) { |n| "product #{n}" }
7
7
  sequence :price , 10
8
8
  inventory 5
9
+ factory :shop_product do
10
+ online true
11
+ after(:create) do |prod|
12
+ cat = create :category , :online => true
13
+ prod.category = cat
14
+ prod.save!
15
+ end
16
+ end
17
+ factory :product_line do
18
+ after(:create) do |prod|
19
+ create :product , :product_id => prod.id
20
+ end
21
+ end
22
+ factory :product_without_inventory do
23
+ inventory 0
24
+ end
9
25
  end
10
26
  end
@@ -2,9 +2,13 @@
2
2
 
3
3
  FactoryGirl.define do
4
4
  factory :purchase do
5
- name "purchase"
6
- ordered_on "2013-12-26"
7
- received_on "2013-12-26"
8
- basket
5
+ sequence( :name) { |n| "purchase #{n}" }
6
+ basket { create :basket_with_item }
7
+ factory :purchase_ordered do
8
+ ordered_on "2013-12-26"
9
+ factory :purchase_received do
10
+ received_on "2013-12-26"
11
+ end
12
+ end
9
13
  end
10
14
  end
@@ -8,7 +8,6 @@ describe "Basket buttons" do
8
8
  end
9
9
  it "should have back and update buttons" do
10
10
  visit_path new_basket_path
11
- expect(page).to have_content I18n.t(:back)
12
11
  find_button I18n.t("helpers.submit.update" , :model => I18n.t(:basket))
13
12
  find_link I18n.t(:new) + ' ' + I18n.t(:basket)
14
13
  find_link I18n.t(:destroy)
@@ -18,7 +17,7 @@ describe "Basket buttons" do
18
17
  visit_path edit_basket_path basket
19
18
  expect(page).not_to have_content I18n.t(:to_order)
20
19
  click_link I18n.t(:checkout)
21
- expect(page).to have_content I18n.t("invoice.header")
20
+ expect(page.title).to include I18n.t("receipt.header")
22
21
  end
23
22
  it "goes to purchase" do
24
23
  basket = create :basket_2_items
@@ -4,9 +4,15 @@ describe "Basket index/search page" do
4
4
  before(:each) do
5
5
  sign_in
6
6
  end
7
- describe "GET /baskets" do
8
- it "lists baskets" do
9
- visit_path baskets_path
10
- end
7
+ it "empty page works" do
8
+ visit_path baskets_path
9
+ end
10
+ it "lists baskets" do
11
+ create :basket
12
+ create :basket_with_item
13
+ create :purchase_received
14
+ create :order_ordered
15
+ create :order_paid
16
+ visit_path baskets_path
11
17
  end
12
18
  end
@@ -4,18 +4,34 @@ describe Clerk do
4
4
  before(:each) do
5
5
  sign_in
6
6
  end
7
- it "lists product groups" do
7
+ it "lists clerks" do
8
8
  visit_path clerks_path
9
9
  end
10
- it "creates a new group" do
10
+ it "shows" do
11
+ clerk = create(:clerk)
12
+ visit_path clerk_path(clerk)
13
+ end
14
+ it "creates a new clerk ok" do
11
15
  visit_path new_clerk_path
16
+ fill_in :clerk_email , :with => "some@valid.it"
17
+ fill_in :clerk_password , :with => "my_password"
18
+ fill_in :clerk_password_confirmation , :with => "my_password"
19
+ click_button :submit
20
+ expect(page.current_url).to include("/clerks/")
12
21
  end
13
- it :edit do
22
+ it "edits a clerk" do
14
23
  clerk = create(:clerk)
15
24
  visit_path edit_clerk_path(clerk)
25
+ fill_in :clerk_name , :with => "my name"
26
+ click_button :submit
27
+ ensure_path clerk_path(clerk)
16
28
  end
17
- it "shows" do
18
- clerk = create(:clerk)
19
- visit_path clerk_path(clerk)
29
+ it "does not creates a new clerk if passwords mismatch" do
30
+ visit_path new_clerk_path
31
+ fill_in :clerk_email , :with => "some@valid.it"
32
+ fill_in :clerk_password , :with => "my_password"
33
+ fill_in :clerk_password_confirmation , :with => "my_other_password"
34
+ click_button :submit
35
+ ensure_path clerks_path
20
36
  end
21
37
  end
@@ -11,4 +11,22 @@ describe "Orders" do
11
11
  order = create :order
12
12
  visit_path order_path order
13
13
  end
14
+ it "creates order from basket" do
15
+ basket = create(:basket_with_item)
16
+ visit_path edit_basket_path(basket)
17
+ find(".make_order").click
18
+ ensure_path order_path(basket.reload.kori)
19
+ end
20
+ it "orders a order" do
21
+ order = create(:order_ordered)
22
+ visit_path order_path(order)
23
+ find(".pay_now").click
24
+ end
25
+ it "inventories a order" do
26
+ order = create(:order_paid)
27
+ visit_path order_path(order)
28
+ start = order.basket.items.first.product.inventory
29
+ find(".ship_now").click
30
+ # expect(order.basket.items.first.product.inventory).to be order.basket.items.first.quantity
31
+ end
14
32
  end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ feature "new product" do
4
+ before :each do
5
+ sign_in
6
+ end
7
+ it "renders new and fails without data" do
8
+ visit_path new_product_path
9
+ click_button( I18n.t(:create))
10
+ expect(page.current_path).to eq products_path
11
+ expect(page).to have_content I18n.t("errors.messages.not_a_number")
12
+ expect(Product.count).to eq 0
13
+ end
14
+ it "submits ok with correct data" do
15
+ visit_path new_product_path
16
+ fill_in "product_name", :with => 'product 12'
17
+ fill_in "product_price", :with => '12'
18
+ click_button( I18n.t(:create))
19
+ expect(page).to have_content I18n.t(:create_success)
20
+ expect(Product.count).to eq 1
21
+ end
22
+ it "renders product edit" do
23
+ product = create :product
24
+ visit_path edit_product_path(product)
25
+ click_button( I18n.t(:product))
26
+ ensure_path product_path(product)
27
+ end
28
+ it "renders product barcode" do
29
+ product = create :product
30
+ visit_path barcode_product_path(product)
31
+ end
32
+ end
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ describe "header texts" do
4
+ before :each do
5
+ sign_in
6
+ end
7
+ it "product new" do
8
+ visit_path new_product_path
9
+ expect(page).to have_content I18n.t(:product)
10
+ expect(page).to have_content I18n.t(:new)
11
+ end
12
+ it "edits product" do
13
+ product = create :product
14
+ visit_path edit_product_path product
15
+ expect(page).to have_content I18n.t(:product)
16
+ expect(page).to have_content I18n.t(:edit)
17
+ end
18
+ it "edits product line" do
19
+ product = create :product_line
20
+ visit_path edit_product_path product
21
+ expect(page).to have_content I18n.t(:product_line)
22
+ expect(page).to have_content I18n.t(:edit)
23
+ end
24
+ it "edits product item" do
25
+ product = create :product_line
26
+ visit_path edit_product_path product.products.first
27
+ expect(page).to have_content I18n.t(:product_item)
28
+ expect(page).to have_content I18n.t(:edit)
29
+ end
30
+ it "shows product" do
31
+ product = create :product
32
+ visit_path product_path product
33
+ expect(page).to have_content I18n.t(:product)
34
+ expect(page).to have_content I18n.t(:show)
35
+ end
36
+ it "shows product line" do
37
+ product = create :product_line
38
+ visit_path product_path product
39
+ expect(page).to have_content I18n.t(:product_line)
40
+ expect(page).to have_content I18n.t(:show)
41
+ end
42
+ it "shows product item" do
43
+ product = create :product_line
44
+ visit_path product_path product.products.first
45
+ expect(page).to have_content I18n.t(:product_item)
46
+ expect(page).to have_content I18n.t(:show)
47
+ end
48
+ end
@@ -3,28 +3,14 @@ require 'spec_helper'
3
3
  describe "GET /products" do
4
4
  before :each do
5
5
  sign_in
6
- visit_path products_path
7
6
  end
8
- it "lists products" do
7
+ it "lists no products" do
8
+ visit_path products_path
9
9
  end
10
- end
11
- describe "product filtering" do
12
- before :each do
13
- 20.times { create :product }
14
- sign_in
15
- visit products_path
16
- end
17
10
  it "filters by price" do
11
+ 10.times { create :product }
12
+ visit products_path
18
13
  fill_in "q[price_lteq]", :with => '10'
19
14
  click_button( I18n.t(:filter))
20
15
  end
21
16
  end
22
- describe "edit product" do
23
- before :each do
24
- sign_in
25
- end
26
- it "renders" do
27
- product = create :product
28
- visit_path edit_product_path(product)
29
- end
30
- end
@@ -11,4 +11,23 @@ describe "Purchases" do
11
11
  purchase = create(:purchase)
12
12
  visit_path purchase_path(purchase)
13
13
  end
14
+ it "orders a purchase" do
15
+ purchase = create(:purchase)
16
+ visit_path purchase_path(purchase)
17
+ find(".order_link").click
18
+ end
19
+ it "orders a purchase" do
20
+ purchase = create(:purchase_ordered)
21
+ visit_path purchase_path(purchase)
22
+ start = purchase.basket.items.first.product.inventory
23
+ find(".receive_link").click
24
+ expect(purchase.basket.items.first.product.inventory).to be start + purchase.basket.items.first.quantity
25
+ end
26
+ it "inventories a purchase" do
27
+ purchase = create(:purchase_ordered)
28
+ start = purchase.basket.items.first.product.inventory
29
+ visit_path purchase_path(purchase)
30
+ find(".inventory_link").click
31
+ expect(purchase.basket.items.first.product.inventory).to be purchase.basket.items.first.quantity
32
+ end
14
33
  end
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Sessions" do
4
+ it "redirect to sign in when accessing admin" do
5
+ visit suppliers_path
6
+ ensure_path sign_in_path
7
+ end
8
+ it "signs in with account" do
9
+ user = create :clerk
10
+ visit_path sign_in_path
11
+ fill_in(:email , :with => user.email)
12
+ fill_in(:password , :with => "password")
13
+ click_button( I18n.t(:sign_in))
14
+ ensure_path root_path
15
+ end
16
+ it "goes to baskets for admins" do
17
+ user = create :admin
18
+ visit_path sign_in_path
19
+ fill_in(:email , :with => user.email)
20
+ fill_in(:password , :with => "password")
21
+ click_button( I18n.t(:sign_in))
22
+ ensure_path baskets_path
23
+ end
24
+ it "doesnt sign in without password" do
25
+ user = create :clerk
26
+ visit_path sign_in_path
27
+ fill_in(:email , :with => user.email)
28
+ click_button( I18n.t(:sign_in))
29
+ ensure_path sign_in_path
30
+ end
31
+ it "does not sign in without account" do
32
+ visit_path sign_in_path
33
+ fill_in(:email , :with => "random@email")
34
+ click_button( I18n.t(:sign_in))
35
+ ensure_path sign_in_path
36
+ end
37
+ it "signs out" do
38
+ sign_in
39
+ visit sign_out_path
40
+ ensure_path root_path
41
+ end
42
+ it "signs up needs confirmation" do
43
+ visit_path sign_up_path
44
+ fill_in(:clerk_email , :with => "some@mail.me")
45
+ fill_in(:clerk_password , :with => "password")
46
+ find(".submit").click
47
+ ensure_path sign_up_path
48
+ expect(page).to have_content("invalid")
49
+ end
50
+ it "signs up" do
51
+ visit_path sign_up_path
52
+ fill_in(:clerk_email , :with => "some@mail.me")
53
+ fill_in(:clerk_password , :with => "password")
54
+ fill_in(:clerk_password_confirmation , :with => "password")
55
+ find(".submit").click
56
+ ensure_path root_path
57
+ end
58
+ end