diff --git a/Gemfile b/Gemfile index b29f6d9..e4c6cc4 100644 --- a/Gemfile +++ b/Gemfile @@ -4,22 +4,18 @@ source 'https://rubygems.org' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '4.2' -# Use SCSS for stylesheets +# Assets gem 'sass-rails', '~> 4.0.3' gem 'bootstrap-sass', '3.2.0.0' - -# Use Uglifier as compressor for JavaScript assets gem 'uglifier', '>= 1.3.0' - -# Use CoffeeScript for .js.coffee assets and views gem 'coffee-rails', '~> 4.0.0' +gem 'jquery-rails' +# Haml for templating! +gem "haml-rails", "~> 0.9" # Responders gem 'responders', '~> 2.0' -# Use jquery as the JavaScript library -gem 'jquery-rails' - # Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks gem 'turbolinks' @@ -35,12 +31,9 @@ group :production do end group :test do - gem 'capybara' - gem 'launchy' gem 'codeclimate-test-reporter', require: nil gem 'rspec-rails' - gem 'factory_girl_rails' - gem 'faker', '1.4.2' + gem 'coveralls', require: false end group :development do @@ -61,6 +54,8 @@ group :development do end group :development, :test do + gem 'factory_girl_rails' + gem 'faker', '1.4.2' gem 'pry-rails' gem 'pry-byebug' end @@ -88,18 +83,9 @@ gem 'cancancan' # Safety first gem 'paper_trail', '~> 4.0.0.beta' -# Windoos sux -gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw] - -# Coveralls -gem 'coveralls', require: false - # Default avatar for users gem 'identicon' -# Slack -gem 'tarumi' - # Run stuff in the background gem 'daemons' gem 'delayed_job', '~> 4.0' diff --git a/Gemfile.lock b/Gemfile.lock index 198ecbb..66cefc1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -36,7 +36,6 @@ GEM minitest (~> 5.1) thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) - addressable (2.3.7) airbrake (4.1.0) builder multi_json @@ -76,12 +75,6 @@ GEM capistrano (~> 3.0) sshkit (~> 1.2) capistrano-stats (1.1.1) - capybara (2.4.4) - mime-types (>= 1.16) - nokogiri (>= 1.3.3) - rack (>= 1.0.0) - rack-test (>= 0.5.4) - xpath (~> 2.0) chunky_png (1.3.4) climate_control (0.0.3) activesupport (>= 3.0) @@ -135,8 +128,21 @@ GEM ffi (1.9.6-x64-mingw32) globalid (0.3.2) activesupport (>= 4.1.0) + haml (4.0.7) + tilt + haml-rails (0.9.0) + actionpack (>= 4.0.1) + activesupport (>= 4.0.1) + haml (>= 4.0.6, < 5.0) + html2haml (>= 1.0.1) + railties (>= 4.0.1) hashie (3.4.0) hike (1.2.3) + html2haml (2.0.0) + erubis (~> 2.7.0) + haml (~> 4.0.0) + nokogiri (~> 1.6.0) + ruby_parser (~> 3.5) httparty (0.13.3) json (~> 1.8) multi_xml (>= 0.5.2) @@ -152,8 +158,6 @@ GEM thor (>= 0.14, < 2.0) json (1.8.2) jwt (1.4.1) - launchy (2.4.3) - addressable (~> 2.3) loofah (2.0.1) nokogiri (>= 1.5.9) mail (2.6.3) @@ -267,6 +271,8 @@ GEM rspec-mocks (~> 3.3.0) rspec-support (~> 3.3.0) rspec-support (3.3.0) + ruby_parser (3.7.1) + sexp_processor (~> 4.1) sass (3.2.19) sass-rails (4.0.5) railties (>= 4.0.0, < 5.0) @@ -276,6 +282,7 @@ GEM sdoc (0.4.1) json (~> 1.7, >= 1.7.7) rdoc (~> 4.0) + sexp_processor (4.6.0) simplecov (0.9.2) docile (~> 1.1.0) multi_json (~> 1.0) @@ -298,9 +305,6 @@ GEM colorize (>= 0.7.0) net-scp (>= 1.1.2) net-ssh (>= 2.8.0) - tarumi (0.0.1) - activesupport - httparty term-ansicolor (1.3.0) tins (~> 1.0) thor (0.19.1) @@ -311,8 +315,6 @@ GEM coffee-rails tzinfo (1.2.2) thread_safe (~> 0.1) - tzinfo-data (1.2015.1) - tzinfo (>= 1.0.0) uglifier (2.7.0) execjs (>= 0.3.0) json (>= 1.8.0) @@ -320,8 +322,6 @@ GEM rack (>= 1.0) will_paginate (3.0.7) win32console (1.3.2) - xpath (2.0.0) - nokogiri (~> 1.3) PLATFORMS ruby @@ -339,7 +339,6 @@ DEPENDENCIES capistrano-rails (~> 1.1) capistrano-rbenv capistrano-rvm - capybara codeclimate-test-reporter coffee-rails (~> 4.0.0) coveralls @@ -349,11 +348,11 @@ DEPENDENCIES devise factory_girl_rails faker (= 1.4.2) + haml-rails (~> 0.9) httparty identicon jbuilder (~> 2.0) jquery-rails - launchy mysql2 omniauth-oauth2 paper_trail (~> 4.0.0.beta) @@ -367,9 +366,7 @@ DEPENDENCIES sdoc (~> 0.4.0) spring sqlite3 - tarumi turbolinks - tzinfo-data uglifier (>= 1.3.0) will_paginate (= 3.0.7) diff --git a/app/models/order.rb b/app/models/order.rb index 25153d4..a2e3b82 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -22,9 +22,9 @@ class Order < ActiveRecord::Base after_create :create_api_job validates :user, presence: true - validates :order_items, presence: true validates :price_cents, presence: true validates_associated :order_items + validate :product_presence accepts_nested_attributes_for :order_items @@ -49,4 +49,8 @@ class Order < ActiveRecord::Base Delayed::Job.enqueue job, priority: priority, run_at: run_at end + + def product_presence + errors.add(:base, "You have to order at least one product.") if order_items.map(&:count).sum.zero? + end end diff --git a/app/views/application/_errors.html.erb b/app/views/application/_errors.html.erb deleted file mode 100644 index a0b3ddf..0000000 --- a/app/views/application/_errors.html.erb +++ /dev/null @@ -1,14 +0,0 @@ -<% if object.errors.any? %> -
-
- <%= pluralize(object.errors.count, "error") %> prohibited this <%= object.class.name.downcase %> from being saved: -
-
- -
-
-<% end %> diff --git a/app/views/application/_errors.html.haml b/app/views/application/_errors.html.haml new file mode 100644 index 0000000..54318b5 --- /dev/null +++ b/app/views/application/_errors.html.haml @@ -0,0 +1,9 @@ +- if object.errors.any? + .panel.panel-danger.form-errors + .panel-heading + = pluralize(object.errors.count, "error") + prohibited this #{object.class.name.downcase} from being saved: + .panel-body + %ul + - object.errors.full_messages.each do |msg| + %li= msg diff --git a/app/views/application/_flash.html.erb b/app/views/application/_flash.html.erb deleted file mode 100644 index 18a7538..0000000 --- a/app/views/application/_flash.html.erb +++ /dev/null @@ -1,32 +0,0 @@ -
- <% if flash[:error] %> -
- - Error! <%= flash[:error] %> -
- <% end %> - <% if flash[:success] %> -
- - Success! <%= raw flash[:success] %> -
- <% end %> - <% if flash[:notice] %> -
- - Notice! <%= flash[:notice] %> -
- <% end %> - <% if flash[:warning] %> -
- - Warning! <%= flash[:warning] %> -
- <% end %> - <% if flash[:alert] %> -
- - Error! <%= flash[:alert] %> -
- <% end %> -
diff --git a/app/views/application/_flash.html.haml b/app/views/application/_flash.html.haml new file mode 100644 index 0000000..bb03eaf --- /dev/null +++ b/app/views/application/_flash.html.haml @@ -0,0 +1,26 @@ +#flash + - if flash[:error] + .alert.alert-danger.alert-dismissable + %button.close{"aria-hidden" => "true", "data-dismiss" => "alert", :type => "button"} × + %strong Error! + = flash[:error] + - if flash[:success] + .alert.alert-success.alert-dismissable + %button.close{"aria-hidden" => "true", "data-dismiss" => "alert", :type => "button"} × + %strong Success! + = raw flash[:success] + - if flash[:notice] + .alert.alert-info.alert-dismissable + %button.close{"aria-hidden" => "true", "data-dismiss" => "alert", :type => "button"} × + %strong Notice! + = flash[:notice] + - if flash[:warning] + .alert.alert-warning.alert-dismissable + %button.close{"aria-hidden" => "true", "data-dismiss" => "alert", :type => "button"} × + %strong Warning! + = flash[:warning] + - if flash[:alert] + .alert.alert-danger.alert-dismissable + %button.close{"aria-hidden" => "true", "data-dismiss" => "alert", :type => "button"} × + %strong Error! + = flash[:alert] diff --git a/app/views/devise/sessions/new.html.erb b/app/views/devise/sessions/new.html.erb deleted file mode 100644 index 067cb71..0000000 --- a/app/views/devise/sessions/new.html.erb +++ /dev/null @@ -1,17 +0,0 @@ -

Sign in

-<%= render partial: 'flash' %> - -
- <%= f_form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %> - <%= f.text_field :name %> - <%= f.password_field :password %> - - <% if devise_mapping.rememberable? %> - <%= f.check_box :remember_me %> - <% end %> - - <%= f.submit "Sign in" %> - <% end %> -
- -<%= render "devise/shared/links" %> diff --git a/app/views/devise/sessions/new.html.haml b/app/views/devise/sessions/new.html.haml new file mode 100644 index 0000000..0ca4b84 --- /dev/null +++ b/app/views/devise/sessions/new.html.haml @@ -0,0 +1,10 @@ +%h2 Sign in += render partial: 'flash' +.sign-in + = f_form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| + = f.text_field :name + = f.password_field :password + - if devise_mapping.rememberable? + = f.check_box :remember_me + = f.submit "Sign in" += render "devise/shared/links" diff --git a/app/views/devise/shared/_links.html.erb b/app/views/devise/shared/_links.html.erb deleted file mode 100644 index e4a4e2d..0000000 --- a/app/views/devise/shared/_links.html.erb +++ /dev/null @@ -1,21 +0,0 @@ -<%- if controller_name != 'sessions' %> - <%= link_to "Log in", new_session_path(resource_name) %>
-<% end -%> - -<%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %> - <%= link_to "Forgot your password?", new_password_path(resource_name) %>
-<% end -%> - -<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %> - <%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %>
-<% end -%> - -<%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %> - <%= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name) %>
-<% end -%> - -<%- if devise_mapping.omniauthable? %> - <%- resource_class.omniauth_providers.each do |provider| %> - <%= link_to "Sign in with #{provider.to_s.titleize}", omniauth_authorize_path(resource_name, provider), class: "btn btn-large btn-primary" %>
- <% end -%> -<% end -%> diff --git a/app/views/devise/shared/_links.html.haml b/app/views/devise/shared/_links.html.haml new file mode 100644 index 0000000..4168feb --- /dev/null +++ b/app/views/devise/shared/_links.html.haml @@ -0,0 +1,16 @@ +- unless controller_name == 'sessions' + = link_to "Log in", new_session_path(resource_name) + %br/ +- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' + = link_to "Forgot your password?", new_password_path(resource_name) + %br/ +- if devise_mapping.confirmable? && controller_name != 'confirmations' + = link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) + %br/ +- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' + = link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name) + %br/ +- if devise_mapping.omniauthable? + - resource_class.omniauth_providers.each do |provider| + = link_to "Sign in with #{provider.to_s.titleize}", omniauth_authorize_path(resource_name, provider), class: "btn btn-large btn-primary" + %br/ diff --git a/app/views/layouts/_footer.html.erb b/app/views/layouts/_footer.html.erb deleted file mode 100644 index 77e2b1a..0000000 --- a/app/views/layouts/_footer.html.erb +++ /dev/null @@ -1,14 +0,0 @@ -<% unless current_user && current_user.koelkast? %> - -<% end %> diff --git a/app/views/layouts/_footer.html.haml b/app/views/layouts/_footer.html.haml new file mode 100644 index 0000000..7759b28 --- /dev/null +++ b/app/views/layouts/_footer.html.haml @@ -0,0 +1,9 @@ +- unless current_user && current_user.koelkast? + %footer.footer + %small + = link_to "Tab", root_path + by #{link_to "Zeus WPI", "//zeus.ugent.be"} + %nav + %ul + %li= mail_to "bestuur@zeus.ugent.be", "Contact" + %li= link_to "Zeus WPI", "//zeus.ugent.be" diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb deleted file mode 100644 index 29011ac..0000000 --- a/app/views/layouts/_header.html.erb +++ /dev/null @@ -1,75 +0,0 @@ - diff --git a/app/views/layouts/_header.html.haml b/app/views/layouts/_header.html.haml new file mode 100644 index 0000000..1c5ca21 --- /dev/null +++ b/app/views/layouts/_header.html.haml @@ -0,0 +1,53 @@ +%nav.navbar.navbar-inverse.navbar-fixed-top{role: "navigation"} + .container-fluid + / Brand and toggle get grouped for better mobile display + .navbar-header + %button.navbar-toggle{"data-target" => ".navbar-collapse", "data-toggle" => "collapse", type: "button"} + %span.icon-bar + %span.icon-bar + %span.icon-bar + = link_to "Tap", root_path, class: "navbar-brand nav-logo" + / Collect the nav links, forms, and other content for toggling + - unless current_user && current_user.koelkast? + .collapse.navbar-collapse + .hidden-xs.navbar-form.navbar-right + .form-group + - if user_signed_in? + = link_to "Logout", destroy_user_session_path, class: "btn btn-default form-control" + - else + = link_to "Login", omniauth_authorize_path("user", "zeuswpi"), class: "btn btn-success form-control" + %ul.nav.navbar-nav.navbar-right + %li= mail_to "tab@zeus.ugent.be", "Send feedback" + - if user_signed_in? + - if can? :manage, :all + %li + = link_to "Place order", orders_path + %li.dropdown + %a.dropdown-toggle{"aria-expanded" => "false", "data-toggle" => "dropdown", href: "#", role: "button"} + Products + %span.caret + %ul.dropdown-menu{role: "menu"} + %li= link_to "List", products_path + %li= link_to "Add product" , new_product_path + %li= link_to "Add stock", new_stock_path + %li.dropdown + %a.dropdown-toggle{"aria-expanded" => "false", "data-toggle" => "dropdown", href: "#", role: "button"} + Users + %span.caret + %ul.dropdown-menu{role: "menu"} + %li= link_to "List" , users_path + %li.dropdown + %a.dropdown-toggle{"data-toggle" => "dropdown", href: "#"} + Logged in as #{current_user.name} + %b.caret + %ul.dropdown-menu + %li= link_to "Edit avatar", edit_user_path(current_user) + %li + %p.navbar-text + Debt: #{euro(current_user.debt)} + .visible-xs.navbar-form + .form-group + - if user_signed_in? + = button_to "Logout", destroy_user_session_path, class: "btn btn-default form-control", method: :delete + - else + = link_to "Login", omniauth_authorize_path("user", "zeuswpi"), class: "btn btn-success form-control" diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb deleted file mode 100644 index f3d6b54..0000000 --- a/app/views/layouts/application.html.erb +++ /dev/null @@ -1,24 +0,0 @@ - - - - Tap - Zeus WPIs drink ordering system - <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> - <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> - <%= csrf_meta_tags %> - - - <% if current_user && current_user.koelkast? && !Rails.env.development? %> - - <% else %> - - <% end %> - <%= render 'layouts/header' %> -
-
- <%= yield %> -
- <%= render 'layouts/footer' %> - <%= debug(params) if Rails.env.development? %> -
- - diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml new file mode 100644 index 0000000..b1fa7ef --- /dev/null +++ b/app/views/layouts/application.html.haml @@ -0,0 +1,14 @@ +!!! +%html + %head + %meta{content: "text/html; charset=UTF-8", "http-equiv" => "Content-Type"}/ + %title Tap - Zeus WPIs drink ordering system + = stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true + = javascript_include_tag 'application', 'data-turbolinks-track' => true + = csrf_meta_tags + %body + = render 'layouts/header' + .container + = yield + = render 'layouts/footer' + = debug(params) if Rails.env.development? diff --git a/app/views/order_items/_order_item.html.erb b/app/views/order_items/_order_item.html.erb deleted file mode 100644 index cb417a5..0000000 --- a/app/views/order_items/_order_item.html.erb +++ /dev/null @@ -1,21 +0,0 @@ -
-
-
-
- <%= image_tag product.avatar %> -
-
-
- <%= kcal_tag product.calories %> -
-

- <%= content_tag :span, product.name %> - <%= content_tag :small, euro(product.price) %> -

- <%= f.counter :count, min: 0, max: product.stock, skip_label: true, wrapper_class: "input-group", class: "row_counter", data: { price: f.object.product.price_cents } %> - <%= f.fields_for :product do |product| %> - <% end %> -
-
-
-
diff --git a/app/views/order_items/_order_item.html.haml b/app/views/order_items/_order_item.html.haml new file mode 100644 index 0000000..63281a3 --- /dev/null +++ b/app/views/order_items/_order_item.html.haml @@ -0,0 +1,14 @@ +.col-md-3.form_products + %div{class: "thumbnail#{' out-of-stock' if product.stock.zero?}"} + .form_row.center + .form_row_image + = image_tag product.avatar + .caption + %h6 + = kcal_tag product.calories + %h4.text-nowrap + = content_tag :span, product.name + = content_tag :small, euro(product.price) + = f.counter :count, min: 0, max: product.stock, skip_label: true, wrapper_class: "input-group", class: "row_counter", data: { price: f.object.product.price_cents } + = f.fields_for :product do |product| + / This is needed for haml diff --git a/app/views/orders/_order.html.erb b/app/views/orders/_order.html.erb deleted file mode 100644 index 7c62b58..0000000 --- a/app/views/orders/_order.html.erb +++ /dev/null @@ -1,13 +0,0 @@ - - - <%= order.created_at.strftime("%d %b %Y at %H:%M") %> - - - - - <%= order.to_sentence %> - - - <%= euro_from_cents(order.price_cents) %> - - diff --git a/app/views/orders/_order.html.haml b/app/views/orders/_order.html.haml new file mode 100644 index 0000000..79b6060 --- /dev/null +++ b/app/views/orders/_order.html.haml @@ -0,0 +1,8 @@ +%tr + %td.order_date + = order.created_at.strftime("%d %b %Y at %H:%M") +%tr + %td + = order.to_sentence + %td + = euro_from_cents(order.price_cents) diff --git a/app/views/orders/_price.html.erb b/app/views/orders/_price.html.erb deleted file mode 100644 index 9e59aaa..0000000 --- a/app/views/orders/_price.html.erb +++ /dev/null @@ -1,10 +0,0 @@ -
- Total price -
- - <%= content_tag :span, "", id: "order_price", class: "input-group-addon" %> - - <%= f.submit "Order!", class: "btn btn-primary big-form-button", skip_wrapper: true %> - -
-
diff --git a/app/views/orders/_price.html.haml b/app/views/orders/_price.html.haml new file mode 100644 index 0000000..51bef93 --- /dev/null +++ b/app/views/orders/_price.html.haml @@ -0,0 +1,7 @@ +.col-md-3.form_total + %strong Total price + .input-group + %span.input-group-addon € + = content_tag :span, "", id: "order_price", class: "input-group-addon" + %span.input-group-btn + = f.submit "Order!", class: "btn btn-primary big-form-button", skip_wrapper: true diff --git a/app/views/orders/new.html.erb b/app/views/orders/new.html.erb deleted file mode 100644 index fcd46ca..0000000 --- a/app/views/orders/new.html.erb +++ /dev/null @@ -1,15 +0,0 @@ -

Order for <%= @user.name %> (Huidige schuld: <%= euro(@user.debt) %>)

- -
- <%= f_form_for [@user, @order] do |f| %> - <%= f.error_messages %> - -
- <%= f.fields_for :order_items do |op_field| %> - <%= render op_field.object, f: op_field, product: op_field.object.product %> - <% end %> -
- - <%= render 'orders/price', f: f %> - <% end %> -
diff --git a/app/views/orders/new.html.haml b/app/views/orders/new.html.haml new file mode 100644 index 0000000..26df01a --- /dev/null +++ b/app/views/orders/new.html.haml @@ -0,0 +1,9 @@ +%h3 + Order for #{@user.name} (Huidige schuld: #{euro(@user.debt)}) +.row + = f_form_for [@user, @order] do |f| + = f.error_messages + .col-md-12 + = f.fields_for :order_items do |op_field| + = render op_field.object, f: op_field, product: op_field.object.product + = render 'orders/price', f: f diff --git a/app/views/orders/overview.html.erb b/app/views/orders/overview.html.erb deleted file mode 100644 index 95aa1bb..0000000 --- a/app/views/orders/overview.html.erb +++ /dev/null @@ -1,7 +0,0 @@ -<%= render partial: 'flash' %> - -
- <% @users.each do |user| %> - <%= render 'users/new_order', user: user %> - <% end %> -
diff --git a/app/views/orders/overview.html.haml b/app/views/orders/overview.html.haml new file mode 100644 index 0000000..5327de7 --- /dev/null +++ b/app/views/orders/overview.html.haml @@ -0,0 +1,4 @@ += render partial: 'flash' +.row + - @users.each do |user| + = render 'users/new_order', user: user diff --git a/app/views/products/_form.html.erb b/app/views/products/_form.html.erb deleted file mode 100644 index be746cd..0000000 --- a/app/views/products/_form.html.erb +++ /dev/null @@ -1,16 +0,0 @@ -
-
- <%= f_form_for @product, html: { multipart: true } do |f| %> - <%= f.error_messages %> - - <%= f.text_field :name %> - <%= f.price_field :price %> - <%= f.collection_select :category, Product.categories.keys %> - <%= f.number_field :stock %> - <%= f.number_field :calories %> - <%= f.file_field :avatar %> - - <%= f.submit %> - <% end %> -
-
diff --git a/app/views/products/_form.html.haml b/app/views/products/_form.html.haml new file mode 100644 index 0000000..258a35b --- /dev/null +++ b/app/views/products/_form.html.haml @@ -0,0 +1,11 @@ +.row + .col-md-6.col-md-offset-3.sign-in + = f_form_for @product, html: { multipart: true } do |f| + = f.error_messages + = f.text_field :name + = f.price_field :price + = f.collection_select :category, Product.categories.keys + = f.number_field :stock + = f.number_field :calories + = f.file_field :avatar + = f.submit diff --git a/app/views/products/_index.html.erb b/app/views/products/_index.html.erb deleted file mode 100644 index ffc0525..0000000 --- a/app/views/products/_index.html.erb +++ /dev/null @@ -1,22 +0,0 @@ -
- - - - -
-
-
- <%= render @products %> -
- <% @categories.each do |o, i| %> -
- <%= render @products.where(category: i) %> -
- <% end %> -
-
diff --git a/app/views/products/_index.html.haml b/app/views/products/_index.html.haml new file mode 100644 index 0000000..e331386 --- /dev/null +++ b/app/views/products/_index.html.haml @@ -0,0 +1,16 @@ +%div{role: "tabpanel"} + / Nav tabs + %ul.nav.nav-tabs{role: "tablist"} + %li.active{role: "presentation"} + %a{"data-toggle" => "tab", href: "#all", role: "tab"} All + - @categories.each do |o, i| + %li{role: "presentation"} + %a{"aria-controls" => o, "data-toggle" => "tab", href: "##{o}", role: "tab"}= o.titleize + / Tab panes + .tab-content + %br/ + #all.tab-pane.active{role: "tabpanel"} + = render @products + - @categories.each do |o, i| + .tab-pane{id: o, role: "tabpanel"} + = render @products.where(category: i) diff --git a/app/views/products/_links.html.erb b/app/views/products/_links.html.erb deleted file mode 100644 index a0cf94b..0000000 --- a/app/views/products/_links.html.erb +++ /dev/null @@ -1,14 +0,0 @@ -<%- if controller_name == 'products' && current_user && current_user.admin? %> - <%= link_to "Edit", edit_product_path(product), class: "btn btn-default" %> - <%= link_to "Delete", product_path(product), method: :delete, class: "btn btn-danger", data: {confirm: 'Are you sure?'} %> -<% end -%> - -<%- if controller_name == 'users' %> -
- <% if current_user.dagschotel != product %> - <%= link_to "Make dagschotel", dagschotel_user_path(current_user, product), class: "btn btn-default" %> - <% else %> - <%= link_to "Huidige dagschotel", dagschotel_user_path(current_user, product), class: "btn btn-success", disabled: true %> - <% end %> -
-<% end -%> diff --git a/app/views/products/_links.html.haml b/app/views/products/_links.html.haml new file mode 100644 index 0000000..e07ba1f --- /dev/null +++ b/app/views/products/_links.html.haml @@ -0,0 +1,9 @@ +- if controller_name == 'products' && current_user && current_user.admin? + = link_to "Edit", edit_product_path(product), class: "btn btn-default" + = link_to "Delete", product_path(product), method: :delete, class: "btn btn-danger", data: {confirm: 'Are you sure?'} +- if controller_name == 'users' + .product_dagschotel + - if current_user.dagschotel != product + = link_to "Make dagschotel", dagschotel_user_path(current_user, product), class: "btn btn-default" + - else + = link_to "Huidige dagschotel", dagschotel_user_path(current_user, product), class: "btn btn-success", disabled: true diff --git a/app/views/products/_product.html.erb b/app/views/products/_product.html.erb deleted file mode 100644 index 095e73a..0000000 --- a/app/views/products/_product.html.erb +++ /dev/null @@ -1,14 +0,0 @@ -
-
-
- <%= image_tag product.avatar %> -
-
- <%= kcal_tag product.calories %> -

<%= product.name %>

-

<%= euro(product.price) %>

-
(In stock: <%= product.stock %>)
- <%= render 'products/links', product: product %> -
-
-
diff --git a/app/views/products/_product.html.haml b/app/views/products/_product.html.haml new file mode 100644 index 0000000..4527712 --- /dev/null +++ b/app/views/products/_product.html.haml @@ -0,0 +1,11 @@ +.col-md-3 + .thumbnail.pic + .form_row_image + = image_tag product.avatar + .caption + = kcal_tag product.calories + %h4= product.name + %h3= euro(product.price) + %h6 + (In stock: #{product.stock}) + = render 'products/links', product: product diff --git a/app/views/products/edit.html.erb b/app/views/products/edit.html.erb deleted file mode 100644 index ef053c9..0000000 --- a/app/views/products/edit.html.erb +++ /dev/null @@ -1,2 +0,0 @@ -

Update product

-<%= render "form" %> diff --git a/app/views/products/edit.html.haml b/app/views/products/edit.html.haml new file mode 100644 index 0000000..4089201 --- /dev/null +++ b/app/views/products/edit.html.haml @@ -0,0 +1,2 @@ +%h1 Update product += render "form" diff --git a/app/views/products/edit.js.erb b/app/views/products/edit.js.erb deleted file mode 100644 index c230148..0000000 --- a/app/views/products/edit.js.erb +++ /dev/null @@ -1 +0,0 @@ -$("#products_row_<%= dom_id(@product) %>").replaceWith("<%= j render "products_list/product_edit_row", product: @product %>") diff --git a/app/views/products/edit.js.haml b/app/views/products/edit.js.haml new file mode 100644 index 0000000..0795e32 --- /dev/null +++ b/app/views/products/edit.js.haml @@ -0,0 +1 @@ +$("#products_row_#{dom_id(@product)}").replaceWith("#{j render "products_list/product_edit_row", product: @product}") diff --git a/app/views/products/index.html.erb b/app/views/products/index.html.erb deleted file mode 100644 index 016ee59..0000000 --- a/app/views/products/index.html.erb +++ /dev/null @@ -1,3 +0,0 @@ -

All products

-<%= render partial: 'flash' %> -<%= render 'products/index' %> diff --git a/app/views/products/index.html.haml b/app/views/products/index.html.haml new file mode 100644 index 0000000..936e312 --- /dev/null +++ b/app/views/products/index.html.haml @@ -0,0 +1,3 @@ +%h1 All products += render partial: 'flash' += render 'products/index' diff --git a/app/views/products/new.html.erb b/app/views/products/new.html.erb deleted file mode 100644 index 0a6fea7..0000000 --- a/app/views/products/new.html.erb +++ /dev/null @@ -1,2 +0,0 @@ -

New product

-<%= render "form" %> diff --git a/app/views/products/new.html.haml b/app/views/products/new.html.haml new file mode 100644 index 0000000..82f9b11 --- /dev/null +++ b/app/views/products/new.html.haml @@ -0,0 +1,2 @@ +%h1 New product += render "form" diff --git a/app/views/products/update.js.erb b/app/views/products/update.js.erb deleted file mode 100644 index 384a31c..0000000 --- a/app/views/products/update.js.erb +++ /dev/null @@ -1,6 +0,0 @@ -<% if @product.errors.any? %> - $('#products-errors').html("<%= j render 'errors', object: @product %>") -<% else %> - $('#products-errors').html('') - $("#products_row_<%= dom_id(@product) %>").replaceWith("<%= j render 'products_list/product_row', product: @product %>"); -<% end %> diff --git a/app/views/products/update.js.haml b/app/views/products/update.js.haml new file mode 100644 index 0000000..2362bcd --- /dev/null +++ b/app/views/products/update.js.haml @@ -0,0 +1,5 @@ +- if @product.errors.any? + $('#products-errors').html("#{j render 'errors', object: @product}") +- else + $('#products-errors').html('') + $("#products_row_#{dom_id(@product)}").replaceWith("#{j render 'products_list/product_row', product: @product}"); diff --git a/app/views/products_list/_product_edit_row.html.erb b/app/views/products_list/_product_edit_row.html.erb deleted file mode 100644 index e043de8..0000000 --- a/app/views/products_list/_product_edit_row.html.erb +++ /dev/null @@ -1,22 +0,0 @@ - - <%= f_form_for product, remote: true do |f| %> - <%= image_tag product.avatar(:small) %> - <%= f.text_field :name, skip_label: true %> - <%= f.price_field :price, skip_label: true %> - <%= f.number_field :stock, skip_label: true %> - <%= f.check_box :deleted, skip_label: true %> - <%= f.number_field :calories, skip_label: true %> - <%= f.button "Update", class: "btn btn-primary" %> - <%= javascript_tag do %> - var id = "#edit_<%= dom_id(product) %>"; - var inputs = $(id).parent().find('input'); - - $(id).parent().find('button').on('click', function(e) { - e.preventDefault(); - $(id).append(inputs.clone()); - $(id).append(''); - $(id).submit(); - }); - <% end %> - <% end %> - diff --git a/app/views/products_list/_product_edit_row.html.haml b/app/views/products_list/_product_edit_row.html.haml new file mode 100644 index 0000000..96535fc --- /dev/null +++ b/app/views/products_list/_product_edit_row.html.haml @@ -0,0 +1,21 @@ +%tr{:id => "products_row_#{dom_id(product)}"} + = f_form_for product, remote: true do |f| + %td= image_tag product.avatar(:small) + %td= f.text_field :name, skip_label: true + %td= f.price_field :price, skip_label: true + %td= f.number_field :stock, skip_label: true + %td= f.check_box :deleted, skip_label: true + %td= f.number_field :calories, skip_label: true + %td= f.button "Update", class: "btn btn-primary" + = javascript_tag do + var id = "#edit_#{dom_id(product)}"; + var inputs = $(id).parent().find('input'); + + $(id).parent().find('button').on('click', function(e) { + e.preventDefault(); + $(id).append(inputs.clone()); + $(id).append(' + %input{:name => "_method", :type => "hidden", :value => "patch"}>/ + '); + $(id).submit(); + }); diff --git a/app/views/products_list/_product_row.html.erb b/app/views/products_list/_product_row.html.erb deleted file mode 100644 index 8b2ad5e..0000000 --- a/app/views/products_list/_product_row.html.erb +++ /dev/null @@ -1,9 +0,0 @@ - - <%= image_tag product.avatar(:small) %> - <%= product.name %> - <%= euro(product.price) %> - <%= product.stock %> - "> - <%= product.calories %> - <%= button_to "Edit", edit_product_path(product), method: :get, class: "btn btn-default", remote: true %> - diff --git a/app/views/products_list/_product_row.html.haml b/app/views/products_list/_product_row.html.haml new file mode 100644 index 0000000..f0aa11d --- /dev/null +++ b/app/views/products_list/_product_row.html.haml @@ -0,0 +1,9 @@ +%tr{:id => "products_row_#{dom_id(product)}"} + %td= image_tag product.avatar(:small) + %td= product.name + %td= euro(product.price) + %td= product.stock + %td + %span{:class => "glyphicon #{product.deleted ? "glyphicon-check" : "glyphicon-unchecked"}"} + %td= product.calories + %td= button_to "Edit", edit_product_path(product), method: :get, class: "btn btn-default", remote: true diff --git a/app/views/products_list/listview.html.erb b/app/views/products_list/listview.html.erb deleted file mode 100644 index 4fe8e39..0000000 --- a/app/views/products_list/listview.html.erb +++ /dev/null @@ -1,21 +0,0 @@ -
-
-
-

Products

- <%= render partial: 'flash' %> - <%= link_to "Add Stock", new_stock_path, class: "btn btn-default" %> - - - - - - - - - - - - <%= render partial: 'products_list/product_row', collection: @products, as: :product %> -
NamePriceStockDeletedKilocalorieën
-
-
diff --git a/app/views/products_list/listview.html.haml b/app/views/products_list/listview.html.haml new file mode 100644 index 0000000..a98332c --- /dev/null +++ b/app/views/products_list/listview.html.haml @@ -0,0 +1,16 @@ +#products-errors +.row.products + .col-md-8.col-md-offset-2 + %h1 Products + = render partial: 'flash' + = link_to "Add Stock", new_stock_path, class: "btn btn-default" + %table#products-table.table.table-striped + %tr + %th + %th Name + %th Price + %th Stock + %th Deleted + %th Kilocalorieën + %th + = render partial: 'products_list/product_row', collection: @products, as: :product diff --git a/app/views/stocks/_errors.html.erb b/app/views/stocks/_errors.html.erb deleted file mode 100644 index 987c686..0000000 --- a/app/views/stocks/_errors.html.erb +++ /dev/null @@ -1,13 +0,0 @@ -<% unless @stock.valid? %> -
-
- <%= "#{pluralize(@stock.errors.count + @stock.stock_entries.map(&:errors).map(&:count).sum, "error")} prohibited this stock from being saved:" %> -
-
- -
-
-<% end %> diff --git a/app/views/stocks/_errors.html.haml b/app/views/stocks/_errors.html.haml new file mode 100644 index 0000000..74cd463 --- /dev/null +++ b/app/views/stocks/_errors.html.haml @@ -0,0 +1,8 @@ +- unless @stock.valid? + .panel.panel-danger.form-errors + .panel-heading + = "#{pluralize(@stock.errors.count + @stock.stock_entries.map(&:errors).map(&:count).sum, "error")} prohibited this stock from being saved:" + .panel-body + %ul + = @stock.errors.full_messages.map{ |m| content_tag(:li, m) }.join.html_safe + = @stock.stock_entries.map{ |se| se.errors.full_messages.map{ |e| "#{se.product.name}: #{e}" } }.flatten.map{ |m| content_tag(:li, m) }.join.html_safe diff --git a/app/views/stocks/new.html.erb b/app/views/stocks/new.html.erb deleted file mode 100644 index 0ab85b0..0000000 --- a/app/views/stocks/new.html.erb +++ /dev/null @@ -1,20 +0,0 @@ -
-
-

Add stock

- <%= f_form_for @stock do |f| %> - <%= render 'stocks/errors' %> - <%= f.fields_for :stock_entries do |se_field| %> -
-
- <%= image_tag se_field.object.product.avatar %> -
-
- <%= se_field.hidden_field :product_id %> - <%= se_field.number_field :count, skip_label: true %> -
-
- <% end %> - <%= f.submit "Insert stock", class: 'btn btn-primary' %> - <% end %> -
-
diff --git a/app/views/stocks/new.html.haml b/app/views/stocks/new.html.haml new file mode 100644 index 0000000..64b1229 --- /dev/null +++ b/app/views/stocks/new.html.haml @@ -0,0 +1,13 @@ +.row + .col-md-6.col-md-offset-3 + %h2 Add stock + = f_form_for @stock do |f| + = render 'stocks/errors' + = f.fields_for :stock_entries do |se_field| + .row + .col-sm-3 + = image_tag se_field.object.product.avatar + .col-sm-9 + = se_field.hidden_field :product_id + = se_field.number_field :count, skip_label: true + = f.submit "Insert stock", class: 'btn btn-primary' diff --git a/app/views/users/_new_order.html.erb b/app/views/users/_new_order.html.erb deleted file mode 100644 index 2c88ec0..0000000 --- a/app/views/users/_new_order.html.erb +++ /dev/null @@ -1,10 +0,0 @@ -
- <% unless user.dagschotel.nil? %> - <%= link_to quickpay_user_path(user) do %> - <%= image_tag user.dagschotel.avatar(:dagschotel), class: "img-circle dagschotel" %> - <% end %> - <% end %> - - <%= link_to image_tag(user.avatar(:large) , class: "img-circle avatar"), new_user_order_path(user) %> - <%= link_to user.name , new_user_order_path(user), class: "btn btn-info", style: get_color_style(user) %> -
diff --git a/app/views/users/_new_order.html.haml b/app/views/users/_new_order.html.haml new file mode 100644 index 0000000..2fa23c3 --- /dev/null +++ b/app/views/users/_new_order.html.haml @@ -0,0 +1,6 @@ +.col-md-2.overviewthumbnail + - unless user.dagschotel.nil? + = link_to quickpay_user_path(user) do + = image_tag user.dagschotel.avatar(:dagschotel), class: "img-circle dagschotel" + = link_to image_tag(user.avatar(:large) , class: "img-circle avatar"), new_user_order_path(user) + = link_to user.name , new_user_order_path(user), class: "btn btn-info", style: get_color_style(user) diff --git a/app/views/users/_sidebar.html.erb b/app/views/users/_sidebar.html.erb deleted file mode 100644 index dd55613..0000000 --- a/app/views/users/_sidebar.html.erb +++ /dev/null @@ -1,32 +0,0 @@ -
-
-

- <%= @user.name %> - <% if can? :edit, @user %> - <%= link_to content_tag(:small, content_tag(:span, "", class: "glyphicon glyphicon-cog")), edit_user_path(@user) %> - <% end %> -

-
- <%= content_tag :div, image_tag(@user.avatar, class: "img-circle img-thumbnail center"), class: "user_avatar center" %> - - <% if can? :edit, @user %> - - <% end %> -
diff --git a/app/views/users/_sidebar.html.haml b/app/views/users/_sidebar.html.haml new file mode 100644 index 0000000..80c6d5b --- /dev/null +++ b/app/views/users/_sidebar.html.haml @@ -0,0 +1,26 @@ +.col-sm-3 + %div + %h2 + = @user.name + - if can? :edit, @user + = link_to content_tag(:small, content_tag(:span, "", class: "glyphicon glyphicon-cog")), edit_user_path(@user) + = content_tag :div, image_tag(@user.avatar, class: "img-circle img-thumbnail center"), class: "user_avatar center" + %ul.list-group + %li.list-group-item.text-muted Orders + %li.list-group-item + %strong Orders placed + %span.badge= @user.orders_count + %li.list-group-item + %strong Products ordered + %span.badge= @user.products_group_by_id.map(&:count).sum + - if can? :create, @user.orders.build + %li.list-group-item= link_to "Place new order", new_user_order_path(@user), class: "btn btn-default btn-block" + - if can? :edit, @user + %ul.list-group + %li.list-group-item.text-muted + - if @user.dagschotel + Huidige dagschotel + \#{image_tag @user.dagschotel.avatar} + \#{link_to "Change dagschotel", edit_dagschotel_user_path(@user), class: "btn btn-default btn-block"} + - else + = link_to "Set dagschotel", edit_dagschotel_user_path(@user), class: "btn btn-default btn-block" diff --git a/app/views/users/_user.html.erb b/app/views/users/_user.html.erb deleted file mode 100644 index d64bd7b..0000000 --- a/app/views/users/_user.html.erb +++ /dev/null @@ -1,11 +0,0 @@ - - <%= user.id %> - <%= image_tag user.avatar(:small) %> - <%= user.name %> - <%= euro(user.debt) %> - <% if current_user.admin? %> - - <%= link_to "Delete", user_path(user), method: :delete, class: "btn btn-danger", data: { confirm: "Are you sure?" } %> - - <% end %> - diff --git a/app/views/users/_user.html.haml b/app/views/users/_user.html.haml new file mode 100644 index 0000000..1e7f1cc --- /dev/null +++ b/app/views/users/_user.html.haml @@ -0,0 +1,8 @@ +%tr + %td= user.id + %td= image_tag user.avatar(:small) + %td= user.name + %td= euro(user.debt) + - if current_user.admin? + %td + = link_to "Delete", user_path(user), method: :delete, class: "btn btn-danger", data: { confirm: "Are you sure?" } diff --git a/app/views/users/edit.html.erb b/app/views/users/edit.html.erb deleted file mode 100644 index f9c87b4..0000000 --- a/app/views/users/edit.html.erb +++ /dev/null @@ -1,20 +0,0 @@ -<%= render 'flash' %> - -
- <%= render 'sidebar' %> -
-

Edit your settings

- <%= f_form_for @user do |f| %> - <%= f.error_messages %> - - <%= f.file_field :avatar %> -

- If you check this option, nobody will be able to order stuff for you through koelkast. - Only on your account things can be ordered. -

- <%= f.check_box :private %> - - <%= f.submit "Update" %> - <% end %> -

-
diff --git a/app/views/users/edit.html.haml b/app/views/users/edit.html.haml new file mode 100644 index 0000000..e132c46 --- /dev/null +++ b/app/views/users/edit.html.haml @@ -0,0 +1,14 @@ += render 'flash' +.row + = render 'sidebar' + .col-sm-9 + %h2 Edit your settings + = f_form_for @user do |f| + = f.error_messages + = f.file_field :avatar + %p + If you check this option, nobody will be able to order stuff for you through koelkast. + Only on your account things can be ordered. + %p + = f.check_box :private + = f.submit "Update" diff --git a/app/views/users/edit_dagschotel.html.erb b/app/views/users/edit_dagschotel.html.erb deleted file mode 100644 index e113e75..0000000 --- a/app/views/users/edit_dagschotel.html.erb +++ /dev/null @@ -1,2 +0,0 @@ -

Choose new Dagschotel

-<%= render 'products/index' %> diff --git a/app/views/users/edit_dagschotel.html.haml b/app/views/users/edit_dagschotel.html.haml new file mode 100644 index 0000000..154245a --- /dev/null +++ b/app/views/users/edit_dagschotel.html.haml @@ -0,0 +1,3 @@ +%h3 + Choose new Dagschotel + = render 'products/index' diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb deleted file mode 100644 index 3a05fa5..0000000 --- a/app/views/users/index.html.erb +++ /dev/null @@ -1,17 +0,0 @@ -
-
-

All users

- <%= render partial: 'flash' %> - - - - - - - - - - <%= render @users %> -
IDNicknameDebt
-
-
diff --git a/app/views/users/index.html.haml b/app/views/users/index.html.haml new file mode 100644 index 0000000..b8f4e11 --- /dev/null +++ b/app/views/users/index.html.haml @@ -0,0 +1,12 @@ +.row.users + .col-md-8.col-md-offset-2 + %h1 All users + = render partial: 'flash' + %table#users-table.table.table-striped + %tr + %th ID + %th + %th Nickname + %th Debt + %th + = render @users diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb deleted file mode 100644 index 3ebadff..0000000 --- a/app/views/users/show.html.erb +++ /dev/null @@ -1,27 +0,0 @@ -<%= render partial: 'flash' %> -
- <%= render 'sidebar' %> -
- <% if (all_orders = @user.all_orders(params[:page])).any? %> -

Previously ordered

- Total: - - - Specifics: - <%= content_tag :ul do %> - <% @user.products_group_by_id.each do |p| %> - <%= content_tag :li, pluralize(p.count, p.name) %> - <% end %> - <% end %> - -

All orders (<%= @user.orders_count %>)

- <%= render all_orders %>
- <%= will_paginate all_orders %> -
- <% end %> -
- diff --git a/app/views/users/show.html.haml b/app/views/users/show.html.haml new file mode 100644 index 0000000..c2b56f5 --- /dev/null +++ b/app/views/users/show.html.haml @@ -0,0 +1,18 @@ += render partial: 'flash' +.row + = render 'sidebar' + #user_info.col-sm-9 + - if (all_orders = @user.all_orders(params[:page])).any? + %h4 Previously ordered + Total: + %ul + %li + = @user.products_group_by_category.map{|c| pluralize(c.count, c.category)}.to_sentence + Specifics: + = content_tag :ul do + - @user.products_group_by_id.each do |p| + = content_tag :li, pluralize(p.count, p.name) + %h4 + All orders (#{@user.orders_count}) + %table.orders= render all_orders + = will_paginate all_orders diff --git a/app/views/welcome/index.html.erb b/app/views/welcome/index.html.erb deleted file mode 100644 index 6babaa1..0000000 --- a/app/views/welcome/index.html.erb +++ /dev/null @@ -1,8 +0,0 @@ -

Login

-<%= render 'flash' %> -If this is the first time you log in, an account will be created for you. - -
-
- <%= link_to "Sign in with Zeus WPI account.", omniauth_authorize_path("user", "zeuswpi"), class: "btn btn-large btn-primary" %>
-
diff --git a/app/views/welcome/index.html.haml b/app/views/welcome/index.html.haml new file mode 100644 index 0000000..b317596 --- /dev/null +++ b/app/views/welcome/index.html.haml @@ -0,0 +1,7 @@ +%h2 Login += render 'flash' +If this is the first time you log in, an account will be created for you. +%div + %br/ + = link_to "Sign in with Zeus WPI account.", omniauth_authorize_path("user", "zeuswpi"), class: "btn btn-large btn-primary" + %br/ diff --git a/db/seeds.rb b/db/seeds.rb index f3a6e0b..4edb1e8 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -5,113 +5,3 @@ # # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) # Mayor.create(name: 'Emanuel', city: cities.first) -require 'faker' -require 'identicon' -DEFAULT_PASSWORD = "password" - -products = [ - { - name: "Twix", - price: 0.4, - category: "food", - stock: 30, - avatar: File.new('public/seeds/products/1.jpg', 'r') - }, - { - name: "M&M Peanuts", - price: 0.6, - category: "food", - stock: 30, - avatar: File.new('public/seeds/products/2.jpg', 'r') - }, - { - name: "Snickers", - price: 0.4, - category: "food", - stock: 30, - avatar: File.new('public/seeds/products/3.jpg', 'r') - }, - { - name: "Fanta", - price: 0.6, - category: "beverages", - stock: 30, - avatar: File.new('public/seeds/products/4.jpg', 'r') - }, - { - name: "Ice Tea", - price: 0.7, - category: "beverages", - stock: 30, - avatar: File.new('public/seeds/products/5.jpg', 'r') - }, - { - name: "Cola", - price: 0.6, - category: "beverages", - stock: 30, - avatar: File.new('public/seeds/products/6.jpg', 'r') - }, - { - name: "Abrikozencake", - price: 0.4, - category: "food", - stock: 30, - avatar: File.new('public/seeds/products/7.jpg', 'r') - }, - { - name: "Kinder Delice", - price: 0.4, - category: "food", - stock: 30, - avatar: File.new('public/seeds/products/8.jpg', 'r') - }, - { - name: "Kinder Bueno", - price: 0.6, - category: "food", - stock: 30, - avatar: File.new('public/seeds/products/9.jpg', 'r') - }, - { - name: "Arizona Ice Tea", - price: 1.0, - category: "beverages", - stock: 30, - avatar: File.new('public/seeds/products/10.png', 'r') - }, - { - name: "Dinosauruskoeken", - price: 0.5, - category: "food", - stock: 30, - avatar: File.new('public/seeds/products/11.jpg', 'r') - }, - { - name: "Chocolade - melk", - price: 0.7, - category: "food", - stock: 30, - avatar: File.new('public/seeds/products/12.jpg', 'r') - } -] - -products.each do |attr| - Product.create name: attr[:name], price: attr[:price], category: attr[:category], stock: attr[:stock], avatar: attr[:avatar] -end - -User.create( - uid: "koelkast", - password: "password", - password_confirmation: "password", - avatar: Identicon.data_url_for("koelkast"), - koelkast: true -) - -20.times do |i| - name = Faker::Name.name - User.create( - uid: name, - avatar: Identicon.data_url_for(name) - ) -end diff --git a/lib/tasks/devseeds.rake b/lib/tasks/devseeds.rake new file mode 100644 index 0000000..221327f --- /dev/null +++ b/lib/tasks/devseeds.rake @@ -0,0 +1,9 @@ +unless Rails.env.production? + require 'factory_girl' + require 'faker' + Dir[Rails.root.join("spec/factories/*.rb")].each {|f| require f} + task :sow => :environment do + FactoryGirl.create_list(:user, 20) + FactoryGirl.create_list(:product, 20) + end +end diff --git a/spec/factories/products.rb b/spec/factories/products.rb index df8f592..54f45aa 100644 --- a/spec/factories/products.rb +++ b/spec/factories/products.rb @@ -22,11 +22,11 @@ require 'identicon' FactoryGirl.define do factory :product do - name { Faker::Name.name } + name { Faker::Name.name } price_cents { rand 120 } - stock { 30 + rand(30) } - calories { rand 20 } - avatar { Identicon.data_url_for name } + stock { 30 + rand(30) } + calories { rand 20 } + avatar { Identicon.data_url_for name } factory :invalid_product do name nil diff --git a/spec/factories/users.rb b/spec/factories/users.rb index a54a545..18b4677 100644 --- a/spec/factories/users.rb +++ b/spec/factories/users.rb @@ -39,6 +39,7 @@ FactoryGirl.define do factory :koelkast do koelkast true + name "koelkast" end end end