office_clerk 0.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.
- checksums.yaml +7 -0
- data/.gitignore +73 -0
- data/.rubocop.yml +6 -0
- data/.travis.yml +9 -0
- data/Gemfile +63 -0
- data/Gemfile.lock +367 -0
- data/Guardfile +28 -0
- data/README.md +44 -0
- data/Rakefile +6 -0
- data/app/assets/images/admin/baskets-2.jpg +0 -0
- data/app/assets/images/admin/baskets.jpg +0 -0
- data/app/assets/images/admin/categories-2.jpg +0 -0
- data/app/assets/images/admin/categories.jpg +0 -0
- data/app/assets/images/admin/clerks-2.jpg +0 -0
- data/app/assets/images/admin/clerks.jpg +0 -0
- data/app/assets/images/admin/orders-2.jpg +0 -0
- data/app/assets/images/admin/orders.jpg +0 -0
- data/app/assets/images/admin/products-2.jpg +0 -0
- data/app/assets/images/admin/products.jpg +0 -0
- data/app/assets/images/admin/purchases-2.jpg +0 -0
- data/app/assets/images/admin/purchases.jpg +0 -0
- data/app/assets/images/admin/suppliers-2.jpg +0 -0
- data/app/assets/images/admin/suppliers.jpg +0 -0
- data/app/assets/images/alpha.png +0 -0
- data/app/assets/images/down-icon.png +0 -0
- data/app/assets/images/header.gif +0 -0
- data/app/assets/images/hihih.jpg +0 -0
- data/app/assets/images/hue.png +0 -0
- data/app/assets/images/koe.jpg +0 -0
- data/app/assets/images/missing.png +0 -0
- data/app/assets/images/saturation.png +0 -0
- data/app/assets/images/shop/basket.jpg +0 -0
- data/app/assets/images/shop/farfalla-logo.jpg +0 -0
- data/app/assets/images/shop/header.gif +0 -0
- data/app/assets/images/shop/header.jpg +0 -0
- data/app/assets/images/shop/header.png +0 -0
- data/app/assets/images/shop/kansi.jpg +0 -0
- data/app/assets/images/shop/kansi.png +0 -0
- data/app/assets/images/shop/logo.png +0 -0
- data/app/assets/images/shop/menu-gourmet.jpg +0 -0
- data/app/assets/images/shop/menu-hius.jpg +0 -0
- data/app/assets/images/shop/menu-huonetuoksu.jpg +0 -0
- data/app/assets/images/shop/menu-info.jpg +0 -0
- data/app/assets/images/shop/menu-kasvo.jpg +0 -0
- data/app/assets/images/shop/menu-laukut.jpg +0 -0
- data/app/assets/images/shop/menu-luomu.jpg +0 -0
- data/app/assets/images/shop/menu-men.jpg +0 -0
- data/app/assets/images/shop/menu-oljy.jpg +0 -0
- data/app/assets/images/shop/menu-tuoksu1.jpg +0 -0
- data/app/assets/images/shop/menu-vaatteet.jpg +0 -0
- data/app/assets/images/shop/menu-valaisin.jpg +0 -0
- data/app/assets/images/shop/menu-vartalo.jpg +0 -0
- data/app/assets/images/shop/spacer.gif +0 -0
- data/app/assets/images/shop/tausta.jpg +0 -0
- data/app/assets/images/shop/tervetuloa.gif +0 -0
- data/app/assets/images/shop/valk.png +0 -0
- data/app/assets/images/shop/valk3.png +0 -0
- data/app/assets/images/shop/violetti-lev.jpg +0 -0
- data/app/assets/images/shop/violetti.jpg +0 -0
- data/app/assets/images/ui-anim_basic_16x16.gif +0 -0
- data/app/assets/images/up-icon.png +0 -0
- data/app/assets/javascripts/admin.js +29 -0
- data/app/assets/javascripts/shop.js +30 -0
- data/app/assets/stylesheets/admin.css.scss +129 -0
- data/app/assets/stylesheets/shop-receipt.css.scss +80 -0
- data/app/assets/stylesheets/shop.css.scss +403 -0
- data/app/controllers/admin_controller.rb +23 -0
- data/app/controllers/application_controller.rb +41 -0
- data/app/controllers/baskets_controller.rb +176 -0
- data/app/controllers/categories_controller.rb +69 -0
- data/app/controllers/clerks_controller.rb +64 -0
- data/app/controllers/orders_controller.rb +57 -0
- data/app/controllers/products_controller.rb +126 -0
- data/app/controllers/purchases_controller.rb +72 -0
- data/app/controllers/sessions_controller.rb +46 -0
- data/app/controllers/shop_controller.rb +90 -0
- data/app/controllers/suppliers_controller.rb +63 -0
- data/app/helpers/admin_helper.rb +28 -0
- data/app/helpers/application_helper.rb +25 -0
- data/app/helpers/baskets_helper.rb +4 -0
- data/app/helpers/categories_helper.rb +4 -0
- data/app/helpers/orders_helper.rb +4 -0
- data/app/helpers/products_helper.rb +4 -0
- data/app/helpers/purchases_helper.rb +4 -0
- data/app/helpers/shop_helper.rb +17 -0
- data/app/helpers/suppliers_helper.rb +4 -0
- data/app/mailers/.keep +0 -0
- data/app/models/basket.rb +114 -0
- data/app/models/category.rb +27 -0
- data/app/models/clerk.rb +46 -0
- data/app/models/item.rb +26 -0
- data/app/models/order.rb +72 -0
- data/app/models/product.rb +100 -0
- data/app/models/purchase.rb +26 -0
- data/app/models/supplier.rb +15 -0
- data/app/views/addresses/_form_fields.html.haml +4 -0
- data/app/views/addresses/show.html.haml +23 -0
- data/app/views/baskets/_small.html.haml +25 -0
- data/app/views/baskets/edit.html.haml +74 -0
- data/app/views/baskets/index.html.haml +55 -0
- data/app/views/baskets/show.html.haml +18 -0
- data/app/views/categories/_treeview.html.haml +8 -0
- data/app/views/categories/_triple.html.haml +12 -0
- data/app/views/categories/edit.html.haml +36 -0
- data/app/views/categories/index.html.haml +49 -0
- data/app/views/categories/show.html.haml +30 -0
- data/app/views/clerks/edit.html.haml +20 -0
- data/app/views/clerks/index.html.haml +37 -0
- data/app/views/clerks/show.html.haml +19 -0
- data/app/views/layouts/_admin_menu.html.haml +14 -0
- data/app/views/layouts/_google.haml +8 -0
- data/app/views/layouts/_messages.html.haml +5 -0
- data/app/views/layouts/admin.html.haml +42 -0
- data/app/views/layouts/shop.html.haml +96 -0
- data/app/views/orders/edit.html.haml +25 -0
- data/app/views/orders/index.html.haml +93 -0
- data/app/views/orders/show.html.haml +37 -0
- data/app/views/products/_line.html.haml +25 -0
- data/app/views/products/_name.html.haml +4 -0
- data/app/views/products/_online.html.haml +2 -0
- data/app/views/products/_triple.html.haml +12 -0
- data/app/views/products/edit.html.haml +42 -0
- data/app/views/products/index.html.haml +86 -0
- data/app/views/products/show.html.haml +94 -0
- data/app/views/purchases/edit.html.haml +9 -0
- data/app/views/purchases/index.html.haml +52 -0
- data/app/views/purchases/show.html.haml +32 -0
- data/app/views/sessions/new.html.haml +10 -0
- data/app/views/sessions/new_clerk.html.haml +22 -0
- data/app/views/shop/_groups.html.haml +8 -0
- data/app/views/shop/_menu.html.haml +5 -0
- data/app/views/shop/_sub.html.haml +0 -0
- data/app/views/shop/checkout.haml +142 -0
- data/app/views/shop/group.html.haml +9 -0
- data/app/views/shop/main_group.html.haml +9 -0
- data/app/views/shop/order.haml +104 -0
- data/app/views/shop/product.html.haml +67 -0
- data/app/views/shop/product_list.html.haml +50 -0
- data/app/views/shop/saved_search.html +6 -0
- data/app/views/shop/sub_group.html.haml +19 -0
- data/app/views/shop/tuotteista.html.haml +40 -0
- data/app/views/shop/welcome.html.haml +103 -0
- data/app/views/suppliers/edit.html.haml +10 -0
- data/app/views/suppliers/index.html.haml +40 -0
- data/app/views/suppliers/show.html.haml +27 -0
- data/bin/bundle +3 -0
- data/bin/rails +8 -0
- data/bin/rake +8 -0
- data/bin/rspec +7 -0
- data/bin/spring +18 -0
- data/config.ru +7 -0
- data/config/application.example.yml +13 -0
- data/config/application.rb +59 -0
- data/config/application.yml +13 -0
- data/config/boot.rb +7 -0
- data/config/database.yml +25 -0
- data/config/environment.rb +6 -0
- data/config/environments/development.rb +31 -0
- data/config/environments/production.rb +80 -0
- data/config/environments/test.rb +36 -0
- data/config/i18n-tasks.yml +11 -0
- data/config/initializers/attack.rb +32 -0
- data/config/initializers/backtrace_silencers.rb +7 -0
- data/config/initializers/filter_parameter_logging.rb +4 -0
- data/config/initializers/inflections.rb +16 -0
- data/config/initializers/migrate.rb +6 -0
- data/config/initializers/mime_types.rb +6 -0
- data/config/initializers/secret_token.rb +12 -0
- data/config/initializers/session_store.rb +3 -0
- data/config/initializers/simple_form.rb +149 -0
- data/config/initializers/simple_form_bootstrap.rb +48 -0
- data/config/initializers/wrap_parameters.rb +14 -0
- data/config/locales/config.yml +23 -0
- data/config/locales/en.yml +183 -0
- data/config/locales/fi.yml +211 -0
- data/config/routes.rb +108 -0
- data/db/migrate/20131224171442_clerks.rb +15 -0
- data/db/migrate/20131226110406_suppliers.rb +9 -0
- data/db/migrate/20131226143612_categories.rb +18 -0
- data/db/migrate/20131226143747_items.rb +14 -0
- data/db/migrate/20131226144134_orders.rb +21 -0
- data/db/migrate/20131226144316_baskets.rb +12 -0
- data/db/migrate/20131226151151_purchases.rb +11 -0
- data/db/migrate/20131226151332_products.rb +27 -0
- data/db/schema.rb +138 -0
- data/db/seeds.rb +4 -0
- data/lib/assets/.keep +0 -0
- data/lib/office_clerk.rb +20 -0
- data/lib/office_clerk/shipping_method.rb +35 -0
- data/lib/tasks/.keep +0 -0
- data/lib/tasks/import.rake +33 -0
- data/lib/templates/haml/scaffold/_form.html.haml +8 -0
- data/office_clerk.gemspec +46 -0
- data/public/404.html +58 -0
- data/public/422.html +58 -0
- data/public/500.html +57 -0
- data/public/favicon.ico +0 -0
- data/public/humans.txt +20 -0
- data/public/robots.txt +5 -0
- data/spec/controllers/baskets_controller_spec.rb +112 -0
- data/spec/controllers/categories_controller_spec.rb +133 -0
- data/spec/controllers/clerks_controller_spec.rb +70 -0
- data/spec/controllers/orders_controller_spec.rb +105 -0
- data/spec/controllers/products_controller_spec.rb +138 -0
- data/spec/controllers/purchases_controller_spec.rb +123 -0
- data/spec/controllers/sessions_controller_spec.rb +18 -0
- data/spec/controllers/suppliers_controller_spec.rb +137 -0
- data/spec/factories/addresses.rb +11 -0
- data/spec/factories/baskets.rb +15 -0
- data/spec/factories/categories.rb +8 -0
- data/spec/factories/clerks.rb +15 -0
- data/spec/factories/items.rb +19 -0
- data/spec/factories/orders.rb +9 -0
- data/spec/factories/products.rb +10 -0
- data/spec/factories/purchases.rb +10 -0
- data/spec/factories/suppliers.rb +7 -0
- data/spec/features/baskets/buttons_spec.rb +35 -0
- data/spec/features/baskets/edit_spec.rb +50 -0
- data/spec/features/baskets/index_spec.rb +12 -0
- data/spec/features/baskets/search_spec.rb +33 -0
- data/spec/features/baskets/show_spec.rb +21 -0
- data/spec/features/categories_spec.rb +21 -0
- data/spec/features/clerks_spec.rb +21 -0
- data/spec/features/orders_spec.rb +14 -0
- data/spec/features/products/index_spec.rb +30 -0
- data/spec/features/products/new_spec.rb +20 -0
- data/spec/features/purchases_spec.rb +14 -0
- data/spec/features/shops_spec.rb +18 -0
- data/spec/features/suppliers_spec.rb +18 -0
- data/spec/models/baskets/inventory_spec.rb +34 -0
- data/spec/models/baskets/items_spec.rb +37 -0
- data/spec/models/baskets/products_spec.rb +31 -0
- data/spec/models/category_spec.rb +18 -0
- data/spec/models/clerk/email_spec.rb +69 -0
- data/spec/models/clerk/password_spec.rb +83 -0
- data/spec/models/item_spec.rb +33 -0
- data/spec/models/locale_spec.rb +17 -0
- data/spec/models/order_spec.rb +19 -0
- data/spec/models/product_spec.rb +29 -0
- data/spec/models/purchase_spec.rb +8 -0
- data/spec/models/supplier_spec.rb +8 -0
- data/spec/routing/baskets_routing_spec.rb +35 -0
- data/spec/routing/categories_routing_spec.rb +35 -0
- data/spec/routing/orders_routing_spec.rb +35 -0
- data/spec/routing/products_routing_spec.rb +35 -0
- data/spec/routing/purchases_routing_spec.rb +35 -0
- data/spec/routing/suppliers_routing_spec.rb +35 -0
- data/spec/spec_helper.rb +74 -0
- data/spec/support/request_helper.rb +31 -0
- data/test/fixtures/baskets.yml +41993 -0
- data/test/fixtures/categories.yml +638 -0
- data/test/fixtures/clerks.yml +694 -0
- data/test/fixtures/items.yml +83651 -0
- data/test/fixtures/orders.yml +58918 -0
- data/test/fixtures/products.yml +110904 -0
- data/test/fixtures/purchases.yml +1755 -0
- data/test/fixtures/suppliers.yml +341 -0
- data/todo +8 -0
- metadata +607 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe ClerksController do
|
|
4
|
+
|
|
5
|
+
before :all do
|
|
6
|
+
create :admin unless Clerk.where(:admin => true).first
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
# This should return the minimal set of values that should be in the session
|
|
10
|
+
# in order to pass any filters (e.g. authentication) defined in
|
|
11
|
+
# SuppliersController. Be sure to keep this updated too.
|
|
12
|
+
let(:valid_session) { { :clerk_email => Clerk.where(:admin => true).first.email } }
|
|
13
|
+
|
|
14
|
+
it "new action should render new template" do
|
|
15
|
+
get :new
|
|
16
|
+
#gets redirected response.should render_template(:new)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "create action should render new template when model is invalid" do
|
|
20
|
+
allow_any_instance_of(Clerk).to receive(:valid?).and_return(false)
|
|
21
|
+
post :create
|
|
22
|
+
#gets redirected response.should render_template("new")
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "create action should redirect when model is valid" do
|
|
26
|
+
allow_any_instance_of(Clerk).to receive(:valid?).and_return(true)
|
|
27
|
+
post :create
|
|
28
|
+
expect(response).to redirect_to(sign_in_path)
|
|
29
|
+
# session['clerk_email'].should == assigns['clerk'].email
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it "edit action should redirect when not logged in" do
|
|
33
|
+
get :edit, :id => "ignored"
|
|
34
|
+
expect(response).to redirect_to(sign_in_path)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it "edit action should render edit template" do
|
|
38
|
+
allow(@controller).to receive(:current_clerk).and_return(Clerk.first)
|
|
39
|
+
# get :edit, :id => "ignored"
|
|
40
|
+
# response.should render_template(:edit)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it "update action should redirect when not logged in" do
|
|
44
|
+
put :update, :id => "ignored"
|
|
45
|
+
expect(response).to redirect_to(sign_in_path)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# it "update action should render edit template when clerk is invalid" do
|
|
49
|
+
# @controller.stub(:current_clerk).and_return(Clerk.first)
|
|
50
|
+
# Clerk.any_instance.stub(:valid?).and_return(false)
|
|
51
|
+
# put :update_clerk, :id => "ignored"
|
|
52
|
+
# response.should render_template(:edit)
|
|
53
|
+
# end
|
|
54
|
+
|
|
55
|
+
# it "update action should redirect when clerk is valid" do
|
|
56
|
+
# @controller.stub(:current_clerk).and_return(Clerk.first)
|
|
57
|
+
# Clerk.any_instance.stub(:valid?).and_return(true)
|
|
58
|
+
# put :update_clerk, :id => "ignored"
|
|
59
|
+
# response.should redirect_to(root_path)
|
|
60
|
+
# end
|
|
61
|
+
|
|
62
|
+
describe "GET 'show'" do
|
|
63
|
+
it "should be successful" do
|
|
64
|
+
clerk = create :clerk
|
|
65
|
+
sign_in
|
|
66
|
+
visit_path clerk_path(clerk)
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
end
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe OrdersController do
|
|
4
|
+
|
|
5
|
+
before :all do
|
|
6
|
+
create :admin unless Clerk.where(:admin => true).first
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
# This should return the minimal set of values that should be in the session
|
|
10
|
+
# in order to pass any filters (e.g. authentication) defined in
|
|
11
|
+
# SuppliersController. Be sure to keep this updated too.
|
|
12
|
+
let(:valid_session) { { :clerk_email => Clerk.where(:admin => true).first.email } }
|
|
13
|
+
|
|
14
|
+
describe "GET index" do
|
|
15
|
+
it "assigns all orders as @orders" do
|
|
16
|
+
|
|
17
|
+
count_before = Order.count
|
|
18
|
+
basket = create :order
|
|
19
|
+
get :index, {}, valid_session
|
|
20
|
+
expect(assigns(:order_scope).count).to be count_before + 1
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
describe "GET show" do
|
|
25
|
+
it "assigns the requested order as @order" do
|
|
26
|
+
order = create :order
|
|
27
|
+
get :show, {:id => order.to_param}, valid_session
|
|
28
|
+
expect(assigns(:order)).to eq(order)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
describe "GET new" do
|
|
33
|
+
it "assigns a new order as @order" do
|
|
34
|
+
get :new, {}, valid_session
|
|
35
|
+
expect(assigns(:order)).to be_kind_of(Order)
|
|
36
|
+
expect(assigns(:order)).to be_new_record
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
describe "GET edit" do
|
|
41
|
+
it "assigns the requested order as @order" do
|
|
42
|
+
order = create :order
|
|
43
|
+
get :edit, {:id => order.to_param}, valid_session
|
|
44
|
+
expect(assigns(:order)).to eq(order)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
describe "POST create" do
|
|
49
|
+
describe "with valid params" do
|
|
50
|
+
it "creates a new Order" do
|
|
51
|
+
expect {
|
|
52
|
+
post :create, {:order => attributes_for(:order)}, valid_session
|
|
53
|
+
}.to change(Order, :count).by(1)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it "assigns a newly created order as @order" do
|
|
57
|
+
post :create, {:order => attributes_for(:order)}, valid_session
|
|
58
|
+
expect(assigns(:order)).to be_kind_of(Order)
|
|
59
|
+
expect(assigns(:order)).to be_persisted
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
it "redirects to the created order" do
|
|
63
|
+
post :create, {:order => attributes_for(:order)}, valid_session
|
|
64
|
+
expect(response).to redirect_to(Order.first)
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
describe "with invalid params" do
|
|
69
|
+
it "assigns a newly created but unsaved order as @order" do
|
|
70
|
+
# Trigger the behavior that occurs when invalid params are submitted
|
|
71
|
+
allow_any_instance_of(Order).to receive(:save).and_return(false)
|
|
72
|
+
post :create, {:order => { :paid_on => ""}}, valid_session
|
|
73
|
+
expect(assigns(:order)).to be_kind_of(Order)
|
|
74
|
+
expect(assigns(:order)).to be_new_record
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
it "re-renders the 'new' template" do
|
|
78
|
+
# Trigger the behavior that occurs when invalid params are submitted
|
|
79
|
+
allow_any_instance_of(Order).to receive(:save).and_return(false)
|
|
80
|
+
post :create, {:order => { :paid_on => ""}}, valid_session
|
|
81
|
+
expect(response).to render_template(:edit)
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
describe "PUT update" do
|
|
87
|
+
describe "with valid params" do
|
|
88
|
+
it "assigns the requested order as @order" do
|
|
89
|
+
order = create :order
|
|
90
|
+
put :update, {:id => order.to_param, :order => attributes_for(:order)}, valid_session
|
|
91
|
+
expect(assigns(:order)).to eq(order)
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
describe "with invalid params" do
|
|
96
|
+
it "assigns the order as @order" do
|
|
97
|
+
order = create :order
|
|
98
|
+
# Trigger the behavior that occurs when invalid params are submitted
|
|
99
|
+
#allow(order).to receive(:save).and_return(false)
|
|
100
|
+
put :update, {:id => order.to_param, :order => { :paid_on => ""}}, valid_session
|
|
101
|
+
expect(assigns(:order)).to eq(order)
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe ProductsController do
|
|
4
|
+
|
|
5
|
+
# This should return the minimal set of attributes required to create a valid
|
|
6
|
+
# Product. As you add validations to Product, be sure to
|
|
7
|
+
# adjust the attributes here as well.
|
|
8
|
+
let(:valid_attributes) { attributes_for :product }
|
|
9
|
+
|
|
10
|
+
before :all do
|
|
11
|
+
create :admin unless Clerk.where(:admin => true).first
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# This should return the minimal set of values that should be in the session
|
|
15
|
+
# in order to pass any filters (e.g. authentication) defined in
|
|
16
|
+
# SuppliersController. Be sure to keep this updated too.
|
|
17
|
+
let(:valid_session) { { :clerk_email => Clerk.where(:admin => true).first.email } }
|
|
18
|
+
|
|
19
|
+
describe "GET index" do
|
|
20
|
+
it "assigns all products as @products" do
|
|
21
|
+
product = Product.create! valid_attributes
|
|
22
|
+
get :index, {}, valid_session
|
|
23
|
+
# assigns(:products).to eq([product])
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
describe "GET show" do
|
|
28
|
+
it "assigns the requested product as @product" do
|
|
29
|
+
product = Product.create! valid_attributes
|
|
30
|
+
get :show, {:id => product.to_param}, valid_session
|
|
31
|
+
expect(assigns(:product)).to eq(product)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
describe "GET new" do
|
|
36
|
+
it "assigns a new product as @product" do
|
|
37
|
+
get :new, {}, valid_session
|
|
38
|
+
expect(assigns(:product)).to be_kind_of(Product)
|
|
39
|
+
expect(assigns(:product)).to be_new_record
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
describe "GET edit" do
|
|
44
|
+
it "assigns the requested product as @product" do
|
|
45
|
+
product = Product.create! valid_attributes
|
|
46
|
+
get :edit, {:id => product.to_param}, valid_session
|
|
47
|
+
expect(assigns(:product)).to eq(product)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
describe "POST create" do
|
|
52
|
+
describe "with valid params" do
|
|
53
|
+
it "creates a new Product" do
|
|
54
|
+
expect {
|
|
55
|
+
post :create, {:product => valid_attributes}, valid_session
|
|
56
|
+
}.to change(Product, :count).by(1)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it "assigns a newly created product as @product" do
|
|
60
|
+
post :create, {:product => valid_attributes}, valid_session
|
|
61
|
+
expect(assigns(:product)).to be_kind_of(Product)
|
|
62
|
+
expect(assigns(:product)).to be_persisted
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it "redirects to the created product" do
|
|
66
|
+
post :create, {:product => valid_attributes}, valid_session
|
|
67
|
+
expect(response).to redirect_to(Product.first)
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
describe "with invalid params" do
|
|
72
|
+
it "assigns a newly created but unsaved product as @product" do
|
|
73
|
+
# Trigger the behavior that occurs when invalid params are submitted
|
|
74
|
+
allow_any_instance_of(Product).to receive(:save).and_return(false)
|
|
75
|
+
post :create, {:product => { :name => "" }}, valid_session
|
|
76
|
+
expect(assigns(:product)).to be_kind_of(Product)
|
|
77
|
+
expect(assigns(:product)).to be_new_record
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
it "re-renders the 'new' template" do
|
|
81
|
+
# Trigger the behavior that occurs when invalid params are submitted
|
|
82
|
+
allow_any_instance_of(Product).to receive(:save).and_return(false)
|
|
83
|
+
post :create, {:product => { :name => "" }}, valid_session
|
|
84
|
+
expect(response).to render_template(:edit)
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
describe "PUT update" do
|
|
90
|
+
describe "with valid params" do
|
|
91
|
+
it "assigns the requested product as @product" do
|
|
92
|
+
product = Product.create! valid_attributes
|
|
93
|
+
put :update, {:id => product.to_param, :product => valid_attributes}, valid_session
|
|
94
|
+
expect(assigns(:product)).to eq(product)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
it "redirects to the product" do
|
|
98
|
+
product = Product.create! valid_attributes
|
|
99
|
+
put :update, {:id => product.to_param, :product => valid_attributes}, valid_session
|
|
100
|
+
expect(response).to redirect_to(product)
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
describe "with invalid params" do
|
|
105
|
+
it "assigns the product as @product" do
|
|
106
|
+
product = Product.create! valid_attributes
|
|
107
|
+
# Trigger the behavior that occurs when invalid params are submitted
|
|
108
|
+
allow_any_instance_of(Product).to receive(:save).and_return(false)
|
|
109
|
+
put :update, {:id => product.to_param, :product => { :name => "" }}, valid_session
|
|
110
|
+
expect(assigns(:product)).to eq(product)
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
it "re-renders the 'edit' template" do
|
|
114
|
+
product = Product.create! valid_attributes
|
|
115
|
+
# Trigger the behavior that occurs when invalid params are submitted
|
|
116
|
+
allow_any_instance_of(Product).to receive(:save).and_return(false)
|
|
117
|
+
put :update, {:id => product.to_param, :product => { :name => "" }}, valid_session
|
|
118
|
+
expect(response).to render_template(:edit)
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
describe "DELETE destroy" do
|
|
124
|
+
it "deletes the requested product" do
|
|
125
|
+
product = Product.create! valid_attributes
|
|
126
|
+
before = Product.count
|
|
127
|
+
delete :delete, {:id => product.to_param}, valid_session
|
|
128
|
+
expect(Product.count).to be before - 1
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
it "redirects to the products list" do
|
|
132
|
+
product = Product.create! valid_attributes
|
|
133
|
+
delete :delete, {:id => product.to_param}, valid_session
|
|
134
|
+
expect(response).to redirect_to(products_path)
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
end
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe PurchasesController do
|
|
4
|
+
|
|
5
|
+
# This should return the minimal set of attributes required to create a valid
|
|
6
|
+
# Purchase. As you add validations to Purchase, be sure to
|
|
7
|
+
# adjust the attributes here as well.
|
|
8
|
+
let(:valid_attributes) { attributes_for :purchase }
|
|
9
|
+
|
|
10
|
+
before :all do
|
|
11
|
+
create :admin unless Clerk.where(:admin => true).first
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# This should return the minimal set of values that should be in the session
|
|
15
|
+
# in order to pass any filters (e.g. authentication) defined in
|
|
16
|
+
# SuppliersController. Be sure to keep this updated too.
|
|
17
|
+
let(:valid_session) { { :clerk_email => Clerk.where(:admin => true).first.email } }
|
|
18
|
+
|
|
19
|
+
describe "GET index" do
|
|
20
|
+
it "assigns all purchases as @purchases" do
|
|
21
|
+
count_before = Purchase.count
|
|
22
|
+
purchase = create :purchase
|
|
23
|
+
get :index, {}, valid_session
|
|
24
|
+
expect(assigns(:purchases).count).to be count_before + 1
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
describe "GET show" do
|
|
29
|
+
it "assigns the requested purchase as @purchase" do
|
|
30
|
+
purchase = Purchase.create! valid_attributes
|
|
31
|
+
get :show, {:id => purchase.to_param}, valid_session
|
|
32
|
+
expect(assigns(:purchase)).to eq(purchase)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
describe "GET new" do
|
|
37
|
+
it "assigns a new purchase as @purchase" do
|
|
38
|
+
get :new, {}, valid_session
|
|
39
|
+
expect(assigns(:purchase)).to be_kind_of(Purchase)
|
|
40
|
+
expect(assigns(:purchase)).to be_new_record
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
describe "GET edit" do
|
|
45
|
+
it "assigns the requested purchase as @purchase" do
|
|
46
|
+
purchase = Purchase.create! valid_attributes
|
|
47
|
+
get :edit, {:id => purchase.to_param}, valid_session
|
|
48
|
+
expect(assigns(:purchase)).to eq(purchase)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
describe "POST create" do
|
|
53
|
+
describe "with valid params" do
|
|
54
|
+
it "creates a new Purchase" do
|
|
55
|
+
expect {
|
|
56
|
+
post :create, {:purchase => valid_attributes}, valid_session
|
|
57
|
+
}.to change(Purchase, :count).by(1)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it "assigns a newly created purchase as @purchase" do
|
|
61
|
+
post :create, {:purchase => valid_attributes}, valid_session
|
|
62
|
+
expect(assigns(:purchase)).to be_kind_of(Purchase)
|
|
63
|
+
expect(assigns(:purchase)).to be_persisted
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
it "redirects to the created purchase" do
|
|
67
|
+
post :create, {:purchase => valid_attributes}, valid_session
|
|
68
|
+
expect(response).to redirect_to(Purchase.last)
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
describe "with invalid params" do
|
|
73
|
+
it "assigns a newly created but unsaved purchase as @purchase" do
|
|
74
|
+
# Trigger the behavior that occurs when invalid params are submitted
|
|
75
|
+
allow_any_instance_of(Purchase).to receive(:save).and_return(false)
|
|
76
|
+
post :create, {:purchase => { :supplier_id => nil }}, valid_session
|
|
77
|
+
expect(assigns(:purchase)).to be_kind_of(Purchase)
|
|
78
|
+
expect(assigns(:purchase)).to be_new_record
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
it "re-renders the 'new' template" do
|
|
82
|
+
# Trigger the behavior that occurs when invalid params are submitted
|
|
83
|
+
allow_any_instance_of(Purchase).to receive(:save).and_return(false)
|
|
84
|
+
post :create, {:purchase => { :supplier_id => nil }}, valid_session
|
|
85
|
+
expect(response).to render_template(:edit)
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
describe "PUT update" do
|
|
91
|
+
describe "with valid params" do
|
|
92
|
+
it "assigns the requested purchase as @purchase" do
|
|
93
|
+
purchase = Purchase.create! valid_attributes
|
|
94
|
+
put :update, {:id => purchase.to_param, :purchase => valid_attributes}, valid_session
|
|
95
|
+
expect(assigns(:purchase)).to eq(purchase)
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
it "redirects to the purchase" do
|
|
99
|
+
purchase = Purchase.create! valid_attributes
|
|
100
|
+
put :update, {:id => purchase.to_param, :purchase => valid_attributes}, valid_session
|
|
101
|
+
expect(response).to redirect_to(purchase)
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
describe "with invalid params" do
|
|
106
|
+
it "assigns the purchase as @purchase" do
|
|
107
|
+
purchase = Purchase.create! valid_attributes
|
|
108
|
+
# Trigger the behavior that occurs when invalid params are submitted
|
|
109
|
+
allow_any_instance_of(Purchase).to receive(:save).and_return(false)
|
|
110
|
+
put :update, {:id => purchase.to_param, :purchase => { :supplier_id => nil }}, valid_session
|
|
111
|
+
expect(assigns(:purchase)).to eq(purchase)
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
it "re-renders the 'edit' template" do
|
|
115
|
+
purchase = Purchase.create! valid_attributes
|
|
116
|
+
# Trigger the behavior that occurs when invalid params are submitted
|
|
117
|
+
allow_any_instance_of(Purchase).to receive(:save).and_return(false)
|
|
118
|
+
put :update, {:id => purchase.to_param, :purchase => { :supplier_id => nil }}, valid_session
|
|
119
|
+
expect(response).to render_template(:edit)
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
|
2
|
+
|
|
3
|
+
describe SessionsController do
|
|
4
|
+
|
|
5
|
+
it "new action should render new template" do
|
|
6
|
+
get :new
|
|
7
|
+
expect(response).to render_template(:new)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it "create action should redirect when authentication is valid" do
|
|
11
|
+
allow_any_instance_of(Clerk).to receive(:valid_password?).and_return(true)
|
|
12
|
+
clerk = create :clerk
|
|
13
|
+
email = Clerk.where(:admin=>false).first.email
|
|
14
|
+
post :create , :email => email
|
|
15
|
+
expect(response).to redirect_to(root_path)
|
|
16
|
+
expect(session['clerk_email']).to eq email
|
|
17
|
+
end
|
|
18
|
+
end
|