diff --git a/.travis.yml b/.travis.yml index 003c0985..78539279 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: ruby rvm: - - 1.9.3 + - 2.0.0 services: - redis-server env: COVERALLS=1 diff --git a/Gemfile b/Gemfile index 90d804a9..32448123 100644 --- a/Gemfile +++ b/Gemfile @@ -1,19 +1,17 @@ # A sample Gemfile source "https://rubygems.org" -ruby "1.9.3" +ruby "2.0.0" -gem "rails", '~> 3.2.9' +gem "rails", '~> 4.0.0' + + +gem 'sass-rails', '~> 4.0.0' +gem 'coffee-rails', '~> 4.0.0' +gem 'less-rails' +gem 'uglifier', '>= 1.0.3' +# See https://github.com/sstephenson/execjs#readme for more supported runtimes +gem 'therubyracer', platforms: :ruby -# Gems used only for assets and not required -# in production environments by default. -group :assets do - gem 'sass-rails', '~> 3.2.3' - gem 'coffee-rails', '~> 3.2.1' - gem 'less-rails' - gem 'uglifier', '>= 1.0.3' - # See https://github.com/sstephenson/execjs#readme for more supported runtimes - gem 'therubyracer', platforms: :ruby -end gem 'jquery-rails' gem 'select2-rails' @@ -27,19 +25,20 @@ gem 'prawn' gem 'haml-rails' gem 'kaminari' gem 'simple_form' -gem 'client_side_validations' -gem 'client_side_validations-simple_form' +gem 'client_side_validations', git: 'git://github.com/bcardarella/client_side_validations.git', branch: '4-0-beta' +gem 'client_side_validations-simple_form', git: 'git://github.com/saveritemedical/client_side_validations-simple_form.git' gem 'inherited_resources' gem 'localize_input', git: "git://github.com/bennibu/localize_input.git" gem 'daemons' gem 'twitter-bootstrap-rails' gem 'simple-navigation' gem 'simple-navigation-bootstrap' -gem 'meta_search' +gem 'ransack' gem 'acts_as_tree' -gem "rails-settings-cached", "0.2.4" +gem "rails-settings-cached", "0.3.1" gem 'resque' gem 'whenever', require: false # For defining cronjobs, see config/schedule.rb +gem 'protected_attributes' # we use the git version of acts_as_versioned, and need to include it in this Gemfile gem 'acts_as_versioned', git: 'git://github.com/technoweenie/acts_as_versioned.git' diff --git a/Gemfile.lock b/Gemfile.lock index bc6145a0..a5a00b98 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,3 +1,10 @@ +GIT + remote: git://github.com/bcardarella/client_side_validations.git + revision: 9461cb92e1dfb64895d590c6d435cdf48fcede45 + branch: 4-0-beta + specs: + client_side_validations (3.2.2) + GIT remote: git://github.com/bennibu/localize_input.git revision: 5eb188d2525a073d09e142cf8b0b04e6ace6e7b0 @@ -19,6 +26,14 @@ GIT i18n-js (2.1.2) i18n +GIT + remote: git://github.com/saveritemedical/client_side_validations-simple_form.git + revision: b97c938be745de1134169026425aa0c990b8b072 + specs: + client_side_validations-simple_form (2.1.0) + client_side_validations (~> 3.2.1) + simple_form (>= 2.1.0, < 4.0) + GIT remote: git://github.com/technoweenie/acts_as_versioned.git revision: 63b1fc8529d028fae632fe80ec0cb25df56cd76b @@ -33,42 +48,40 @@ PATH acts_as_versioned content_for_in_controllers diffy - rails (~> 3.2.15) + rails wikicloth GEM remote: https://rubygems.org/ specs: - actionmailer (3.2.17) - actionpack (= 3.2.17) + actionmailer (4.0.3) + actionpack (= 4.0.3) mail (~> 2.5.4) - actionpack (3.2.17) - activemodel (= 3.2.17) - activesupport (= 3.2.17) - builder (~> 3.0.0) + actionpack (4.0.3) + activesupport (= 4.0.3) + builder (~> 3.1.0) erubis (~> 2.7.0) - journey (~> 1.0.4) - rack (~> 1.4.5) - rack-cache (~> 1.2) - rack-test (~> 0.6.1) - sprockets (~> 2.2.1) - activemodel (3.2.17) - activesupport (= 3.2.17) - builder (~> 3.0.0) - activerecord (3.2.17) - activemodel (= 3.2.17) - activesupport (= 3.2.17) - arel (~> 3.0.2) - tzinfo (~> 0.3.29) - activeresource (3.2.17) - activemodel (= 3.2.17) - activesupport (= 3.2.17) - activesupport (3.2.17) + rack (~> 1.5.2) + rack-test (~> 0.6.2) + activemodel (4.0.3) + activesupport (= 4.0.3) + builder (~> 3.1.0) + activerecord (4.0.3) + activemodel (= 4.0.3) + activerecord-deprecated_finders (~> 1.0.2) + activesupport (= 4.0.3) + arel (~> 4.0.0) + activerecord-deprecated_finders (1.0.3) + activesupport (4.0.3) i18n (~> 0.6, >= 0.6.4) - multi_json (~> 1.0) + minitest (~> 4.2) + multi_json (~> 1.3) + thread_safe (~> 0.1) + tzinfo (~> 0.3.37) acts_as_tree (1.5.0) activerecord (>= 3.0.0) - arel (3.0.3) + arel (4.0.2) + atomic (1.1.14) better_errors (1.1.0) coderay (>= 1.0.0) erubis (>= 2.6.6) @@ -76,7 +89,7 @@ GEM debug_inspector (>= 0.0.1) bootstrap-datepicker-rails (1.3.0.1) railties (>= 3.0) - builder (3.0.4) + builder (3.1.4) bullet (4.8.0) activesupport uniform_notifier (>= 1.4.0) @@ -99,14 +112,10 @@ GEM childprocess (0.5.1) ffi (~> 1.0, >= 1.0.11) chronic (0.10.2) - client_side_validations (3.2.6) - client_side_validations-simple_form (2.1.0) - client_side_validations (~> 3.2.5) - simple_form (~> 2.1.0) coderay (1.1.0) - coffee-rails (3.2.2) + coffee-rails (4.0.1) coffee-script (>= 2.2.0) - railties (~> 3.2.0) + railties (>= 4.0.0, < 5.0) coffee-script (2.2.0) coffee-script-source execjs @@ -143,11 +152,11 @@ GEM ffi (1.9.3) haml (4.0.5) tilt - haml-rails (0.4) - actionpack (>= 3.1, < 4.1) - activesupport (>= 3.1, < 4.1) - haml (>= 3.1, < 4.1) - railties (>= 3.1, < 4.1) + haml-rails (0.5.3) + actionpack (>= 4.0.1) + activesupport (>= 4.0.1) + haml (>= 3.1, < 5.0) + railties (>= 4.0.1) has_scope (0.6.0.rc) actionpack (>= 3.2, < 5) activesupport (>= 3.2, < 5) @@ -160,7 +169,6 @@ GEM responders (~> 1.0.0.rc) iso (0.2.0) i18n - journey (1.0.4) jquery-rails (3.1.0) railties (>= 3.0, < 5.0) thor (>= 0.14, < 2.0) @@ -177,73 +185,68 @@ GEM mail (2.5.4) mime-types (~> 1.16) treetop (~> 1.4.8) - mailcatcher (0.5.12) - activesupport (~> 3.0) - eventmachine (~> 1.0.0) - haml (>= 3.1, < 5) - mail (~> 2.3) - sinatra (~> 1.2) - skinny (~> 0.2.3) - sqlite3 (~> 1.3) - thin (~> 1.5.0) - meta_search (1.1.3) - actionpack (~> 3.1) - activerecord (~> 3.1) - activesupport (~> 3.1) - polyamorous (~> 0.5.0) + mailcatcher (0.2.4) + eventmachine + haml + i18n + json + mail + sinatra + skinny (>= 0.1.2) + sqlite3-ruby + thin mime-types (1.25.1) mini_portile (0.5.2) + minitest (4.7.5) mono_logger (1.1.0) multi_json (1.8.4) mysql2 (0.3.15) net-scp (1.1.2) net-ssh (>= 2.6.5) - net-ssh (2.7.0) + net-ssh (2.8.0) nokogiri (1.6.1) mini_portile (~> 0.5.0) pdf-core (0.1.6) - polyamorous (0.5.0) - activerecord (~> 3.0) + polyamorous (0.6.4) + activerecord (>= 3.0) polyglot (0.3.4) prawn (0.15.0) pdf-core (~> 0.1.3) ttfunk (~> 1.1.0) + protected_attributes (1.0.5) + activemodel (>= 4.0.1, < 5.0) quiet_assets (1.0.2) railties (>= 3.1, < 5.0) - rack (1.4.5) - rack-cache (1.2) - rack (>= 0.4) + rack (1.5.2) rack-protection (1.5.2) rack - rack-ssl (1.3.3) - rack rack-test (0.6.2) rack (>= 1.0) - rails (3.2.17) - actionmailer (= 3.2.17) - actionpack (= 3.2.17) - activerecord (= 3.2.17) - activeresource (= 3.2.17) - activesupport (= 3.2.17) - bundler (~> 1.0) - railties (= 3.2.17) + rails (4.0.3) + actionmailer (= 4.0.3) + actionpack (= 4.0.3) + activerecord (= 4.0.3) + activesupport (= 4.0.3) + bundler (>= 1.3.0, < 2.0) + railties (= 4.0.3) + sprockets-rails (~> 2.0.0) rails-assets-listjs (0.2.0.beta.4) railties (>= 3.1) - rails-i18n (3.0.0) - i18n (~> 0.5) - rails (>= 3.0.0, < 4.0.0) - rails-settings-cached (0.2.4) - rails (>= 3.0.0) - railties (3.2.17) - actionpack (= 3.2.17) - activesupport (= 3.2.17) - rack-ssl (~> 1.3.2) + rails-i18n (4.0.1) + i18n (~> 0.6) + rails (~> 4.0) + rails-settings-cached (0.3.1) + rails (>= 4.0.0.beta1) + railties (4.0.3) + actionpack (= 4.0.3) + activesupport (= 4.0.3) rake (>= 0.8.7) - rdoc (~> 3.4) - thor (>= 0.14.6, < 2.0) + thor (>= 0.18.1, < 2.0) rake (10.1.1) - rdoc (3.12.2) - json (~> 1.4) + ransack (1.1.0) + actionpack (>= 3.0) + activerecord (>= 3.0) + polyamorous (~> 0.6.0) redis (3.0.7) redis-namespace (1.4.1) redis (~> 3.0.4) @@ -280,10 +283,10 @@ GEM ruby-prof (0.14.2) rubyzip (1.1.0) sass (3.2.14) - sass-rails (3.2.6) - railties (~> 3.2.0) + sass-rails (4.0.1) + railties (>= 4.0.0, < 5.0) sass (>= 3.1.10) - tilt (~> 1.3) + sprockets-rails (~> 2.0.0) select2-rails (3.5.2) thor (~> 0.14) selenium-webdriver (2.39.0) @@ -296,9 +299,9 @@ GEM simple-navigation-bootstrap (1.0.0) railties (>= 3.1) simple-navigation (>= 3.7.0) - simple_form (2.1.1) - actionpack (~> 3.0) - activemodel (~> 3.0) + simple_form (3.0.1) + actionpack (>= 4.0.0, < 4.1) + activemodel (>= 4.0.0, < 4.1) simplecov (0.8.2) docile (~> 1.1.0) multi_json @@ -311,12 +314,18 @@ GEM skinny (0.2.3) eventmachine (~> 1.0.0) thin (~> 1.5.0) - sprockets (2.2.2) + sprockets (2.10.1) hike (~> 1.2) multi_json (~> 1.0) rack (~> 1.0) tilt (~> 1.1, != 1.3.0) + sprockets-rails (2.0.1) + actionpack (>= 3.0) + activesupport (>= 3.0) + sprockets (~> 2.8) sqlite3 (1.3.8) + sqlite3-ruby (1.3.3) + sqlite3 (>= 1.3.3) sshkit (1.3.0) net-scp (>= 1.1.2) net-ssh @@ -331,6 +340,8 @@ GEM eventmachine (>= 0.12.6) rack (>= 1.0.0) thor (0.18.1) + thread_safe (0.1.3) + atomic tilt (1.4.1) tins (1.0.0) treetop (1.4.15) @@ -375,9 +386,9 @@ DEPENDENCIES capistrano-rails capistrano-rvm! capybara - client_side_validations - client_side_validations-simple_form - coffee-rails (~> 3.2.1) + client_side_validations! + client_side_validations-simple_form! + coffee-rails (~> 4.0.0) connection_pool coveralls daemons @@ -395,21 +406,22 @@ DEPENDENCIES less-rails localize_input! mailcatcher - meta_search mysql2 prawn + protected_attributes quiet_assets - rails (~> 3.2.9) + rails (~> 4.0.0) rails-assets-listjs (= 0.2.0.beta.4) rails-i18n - rails-settings-cached (= 0.2.4) + rails-settings-cached (= 0.3.1) + ransack resque rspec-core rspec-expectations rspec-rails rspec-rerun ruby-prof - sass-rails (~> 3.2.3) + sass-rails (~> 4.0.0) select2-rails selenium-webdriver simple-navigation diff --git a/app/controllers/admin/base_controller.rb b/app/controllers/admin/base_controller.rb index e614e7ac..3d403f0e 100644 --- a/app/controllers/admin/base_controller.rb +++ b/app/controllers/admin/base_controller.rb @@ -3,8 +3,8 @@ class Admin::BaseController < ApplicationController def index @user = self.current_user - @groups = Group.find(:all, :limit => 10, :order => 'created_on DESC', :conditions => {:deleted_at => nil}) - @users = User.find(:all, :limit => 10, :order => 'created_on DESC') + @groups = Group.where(deleted_at: nil).order('created_on DESC').limit(10) + @users = User.order('created_on DESC').limit(10) end end diff --git a/app/controllers/admin/workgroups_controller.rb b/app/controllers/admin/workgroups_controller.rb index 6498d01a..77d73177 100644 --- a/app/controllers/admin/workgroups_controller.rb +++ b/app/controllers/admin/workgroups_controller.rb @@ -15,6 +15,6 @@ class Admin::WorkgroupsController < Admin::BaseController @workgroup.destroy redirect_to admin_workgroups_url, notice: t('admin.workgroups.destroy.notice') rescue => error - redirect_to admin_workgroups_url, alert: t('admin.workgroups.destroy.error') + redirect_to admin_workgroups_url, alert: t('admin.workgroups.destroy.error', error: error.message) end end diff --git a/app/controllers/articles_controller.rb b/app/controllers/articles_controller.rb index 3c3de22a..c8176fb0 100644 --- a/app/controllers/articles_controller.rb +++ b/app/controllers/articles_controller.rb @@ -199,11 +199,11 @@ class ArticlesController < ApplicationController # renders a view to import articles in local database # def shared - # build array of keywords, required for meta search _all suffix - params[:search][:name_contains_all] = params[:search][:name_contains_all].split(' ') if params[:search] + # build array of keywords, required for ransack _all suffix + params[:q][:name_cont_all] = params[:q][:name_cont_all].split(' ') if params[:q] # Build search with meta search plugin - @search = @supplier.shared_supplier.shared_articles.search(params[:search]) - @articles = @search.page(params[:page]).per(10) + @search = @supplier.shared_supplier.shared_articles.search(params[:q]) + @articles = @search.result.page(params[:page]).per(10) render :layout => false end diff --git a/app/controllers/deliveries_controller.rb b/app/controllers/deliveries_controller.rb index 3f18899f..102a4201 100644 --- a/app/controllers/deliveries_controller.rb +++ b/app/controllers/deliveries_controller.rb @@ -4,7 +4,7 @@ class DeliveriesController < ApplicationController before_filter :find_supplier, :exclude => :fill_new_stock_article_form def index - @deliveries = @supplier.deliveries.all :order => 'delivered_on DESC' + @deliveries = @supplier.deliveries.order('delivered_on DESC') end def show diff --git a/app/controllers/finance/balancing_controller.rb b/app/controllers/finance/balancing_controller.rb index 61f73cef..e4f6e137 100644 --- a/app/controllers/finance/balancing_controller.rb +++ b/app/controllers/finance/balancing_controller.rb @@ -16,13 +16,13 @@ class Finance::BalancingController < Finance::BaseController sort_param = params['sort'] || 'name' @articles = case sort_param when 'name' then - OrderArticle.sort_by_name(@articles) + @articles.order('articles.name ASC') when 'name_reverse' then - OrderArticle.sort_by_name(@articles).reverse + @articles.order('articles.name DESC') when 'order_number' then - OrderArticle.sort_by_order_number(@articles) + @articles.order('articles.order_number ASC') when 'order_number_reverse' then - OrderArticle.sort_by_order_number(@articles).reverse + @articles.order('articles.order_number DESC') else @articles end diff --git a/app/controllers/foodcoop/workgroups_controller.rb b/app/controllers/foodcoop/workgroups_controller.rb index cad728e4..35eb2d50 100644 --- a/app/controllers/foodcoop/workgroups_controller.rb +++ b/app/controllers/foodcoop/workgroups_controller.rb @@ -4,7 +4,7 @@ class Foodcoop::WorkgroupsController < ApplicationController :except => [:index] def index - @workgroups = Workgroup.all :order => "name" + @workgroups = Workgroup.order("name") end def edit diff --git a/app/controllers/group_orders_controller.rb b/app/controllers/group_orders_controller.rb index 5869d3ff..68e289e5 100644 --- a/app/controllers/group_orders_controller.rb +++ b/app/controllers/group_orders_controller.rb @@ -74,8 +74,7 @@ class GroupOrdersController < ApplicationController end def ensure_open_order - @order = Order.find((params[:order_id] || params[:group_order][:order_id]), - :include => [:supplier, :order_articles]) + @order = Order.includes([:supplier, :order_articles]).find(params[:order_id] || params[:group_order][:order_id]) unless @order.open? flash[:notice] = I18n.t('group_orders.errors.closed') redirect_to :action => 'index' diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index f390163e..f5533937 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -21,7 +21,7 @@ class OrdersController < ApplicationController else sort = "ends DESC" end - @orders = Order.closed.page(params[:page]).per(@per_page).includes(:supplier).order(sort) + @orders = Order.closed.includes(:supplier).order(sort).page(params[:page]).per(@per_page) end # Gives a view for the results to a specific order @@ -145,7 +145,7 @@ class OrdersController < ApplicationController text += "****** " + I18n.t('orders.fax.articles') + "\n\n" text += I18n.t('orders.fax.number') + " " + I18n.t('orders.fax.amount') + " " + I18n.t('orders.fax.name') + "\n" # now display all ordered articles - @order.order_articles.ordered.all(:include => [:article, :article_price]).each do |oa| + @order.order_articles.ordered.includes([:article, :article_price]).each do |oa| number = oa.article.order_number (8 - number.size).times { number += " " } quantity = oa.units_to_order.to_i.to_s diff --git a/app/documents/order_fax.rb b/app/documents/order_fax.rb index 766a784c..9340fb97 100644 --- a/app/documents/order_fax.rb +++ b/app/documents/order_fax.rb @@ -58,7 +58,7 @@ class OrderFax < OrderPdf # Articles total = 0 data = [I18n.t('documents.order_fax.rows')] - data += @order.order_articles.ordered.all(include: :article).collect do |a| + data += @order.order_articles.ordered.includes(:article).collect do |a| subtotal = a.units_to_order * a.price.unit_quantity * a.price.price total += subtotal [a.article.order_number, diff --git a/app/documents/order_matrix.rb b/app/documents/order_matrix.rb index 52270a12..52b7965b 100644 --- a/app/documents/order_matrix.rb +++ b/app/documents/order_matrix.rb @@ -60,13 +60,13 @@ class OrderMatrix < OrderPdf # Collect group results groups_data = [header] - @order.group_orders.includes(:ordergroup).all.each do |group_order| + @order.group_orders.includes(:ordergroup).each do |group_order| group_result = [group_order.ordergroup.name.truncate(20)] for order_article in current_order_articles # get the Ordergroup result for this order_article - goa = order_article.group_order_articles.first conditions: { group_order_id: group_order.id } + goa = order_article.group_order_articles.where(group_order_id: group_order.id).first group_result << ((goa.nil? || goa.result == 0) ? "" : goa.result.to_i) end groups_data << group_result diff --git a/app/helpers/articles_helper.rb b/app/helpers/articles_helper.rb index ee8f58e1..d2042f1c 100644 --- a/app/helpers/articles_helper.rb +++ b/app/helpers/articles_helper.rb @@ -14,6 +14,6 @@ module ArticlesHelper # Flatten search params, used in import from external database def search_params - Hash[params[:search].map { |k,v| [k, (v.is_a?(Array) ? v.join(" ") : v)] }] + Hash[params[:q].map { |k,v| [k, (v.is_a?(Array) ? v.join(" ") : v)] }] end -end \ No newline at end of file +end diff --git a/app/helpers/orders_helper.rb b/app/helpers/orders_helper.rb index 14131732..d1590504 100644 --- a/app/helpers/orders_helper.rb +++ b/app/helpers/orders_helper.rb @@ -13,7 +13,7 @@ module OrdersHelper def options_for_suppliers_to_select options = [[I18n.t('helpers.orders.option_choose')]] - options += Supplier.all.map {|s| [ s.name, url_for(action: "new", supplier_id: s)] } + options += Supplier.map {|s| [ s.name, url_for(action: "new", supplier_id: s)] } options += [[I18n.t('helpers.orders.option_stock'), url_for(action: 'new', supplier_id: 0)]] options_for_select(options) end @@ -98,7 +98,7 @@ module OrdersHelper if group_orders.count == 0 return txt else - desc = group_orders.all.map {|g| g.ordergroup.name}.join(', ') + desc = group_orders.includes(:ordergroup).map {|g| g.ordergroup.name}.join(', ') content_tag(:abbr, txt, title: desc).html_safe end end diff --git a/app/inputs/delta_input.rb b/app/inputs/delta_input.rb index 20a10805..39e4e76f 100644 --- a/app/inputs/delta_input.rb +++ b/app/inputs/delta_input.rb @@ -3,6 +3,7 @@ class DeltaInput < SimpleForm::Inputs::StringInput # for now, need to pass id or it won't work def input + @input_html_options[:type] = 'text' @input_html_options[:data] ||= {} @input_html_options[:data][:delta] ||= 1 @input_html_options[:autocomplete] ||= 'off' diff --git a/app/models/article.rb b/app/models/article.rb index 3132f5d0..7fd6fa32 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -7,11 +7,11 @@ class Article < ActiveRecord::Base # Associations belongs_to :supplier belongs_to :article_category - has_many :article_prices, :order => "created_at DESC" + has_many :article_prices, -> { order("created_at DESC") } scope :undeleted, -> { where(deleted_at: nil) } scope :available, -> { undeleted.where(availability: true) } - scope :not_in_stock, :conditions => {:type => nil} + scope :not_in_stock, -> { where(type: nil) } # Validations validates_presence_of :name, :unit, :price, :tax, :deposit, :unit_quantity, :supplier_id, :article_category @@ -44,7 +44,7 @@ class Article < ActiveRecord::Base # If the article is used in an open Order, the Order will be returned. def in_open_order @in_open_order ||= begin - order_articles = OrderArticle.all(:conditions => ['order_id IN (?)', Order.open.collect(&:id)]) + order_articles = OrderArticle.where(order_id: Order.open.collect(&:id)) order_article = order_articles.detect {|oa| oa.article_id == id } order_article ? order_article.order : nil end diff --git a/app/models/delivery.rb b/app/models/delivery.rb index 91ee4ca8..0ef7b62d 100644 --- a/app/models/delivery.rb +++ b/app/models/delivery.rb @@ -2,12 +2,9 @@ class Delivery < ActiveRecord::Base belongs_to :supplier has_one :invoice - has_many :stock_changes, - :dependent => :destroy, - :include => 'stock_article', - :order => 'articles.name ASC' + has_many :stock_changes, -> { includes(:stock_article).order('articles.name ASC') }, :dependent => :destroy - scope :recent, :order => 'created_at DESC', :limit => 10 + scope :recent, -> { order('created_at DESC').limit(10) } validates_presence_of :supplier_id, :delivered_on validate :stock_articles_must_be_unique diff --git a/app/models/group.rb b/app/models/group.rb index 9c861abd..50f6d63e 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -17,7 +17,7 @@ class Group < ActiveRecord::Base # Returns all NONmembers and a checks for possible multiple Ordergroup-Memberships def non_members - User.natural_order.all.reject { |u| users.include?(u) } + User.natural_order.reject { |u| users.include?(u) } end def user_tokens=(ids) diff --git a/app/models/group_order.rb b/app/models/group_order.rb index 2a37d970..5bfba726 100644 --- a/app/models/group_order.rb +++ b/app/models/group_order.rb @@ -14,10 +14,10 @@ class GroupOrder < ActiveRecord::Base validates_numericality_of :price validates_uniqueness_of :ordergroup_id, :scope => :order_id # order groups can only order once per order - scope :in_open_orders, joins(:order).merge(Order.open) - scope :in_finished_orders, joins(:order).merge(Order.finished_not_closed) + scope :in_open_orders, -> { joins(:order).merge(Order.open) } + scope :in_finished_orders, -> { joins(:order).merge(Order.finished_not_closed) } - scope :ordered, :include => :ordergroup, :order => 'groups.name' + scope :ordered, -> { includes(:ordergroup).order('groups.name') } # Generate some data for the javascript methods in ordering view def load_data @@ -55,7 +55,7 @@ class GroupOrder < ActiveRecord::Base def save_group_order_articles for order_article in order.order_articles # Find the group_order_article, create a new one if necessary... - group_order_article = group_order_articles.find_or_create_by_order_article_id(order_article.id) + group_order_article = group_order_articles.where(order_article_id: order_article.id).first_or_create # Get ordered quantities and update group_order_articles/_quantities... quantities = group_order_articles_attributes.fetch(order_article.id.to_s, {:quantity => 0, :tolerance => 0}) diff --git a/app/models/group_order_article.rb b/app/models/group_order_article.rb index 74bb6210..50b8c044 100644 --- a/app/models/group_order_article.rb +++ b/app/models/group_order_article.rb @@ -13,18 +13,18 @@ class GroupOrderArticle < ActiveRecord::Base validates_inclusion_of :tolerance, :in => 0..99 validates_uniqueness_of :order_article_id, :scope => :group_order_id # just once an article per group order - scope :ordered, :conditions => 'group_order_articles.result > 0 OR group_order_articles.quantity > 0 OR group_order_articles.tolerance > 0', :include => {:group_order => :ordergroup}, :order => 'groups.name' + scope :ordered, -> { includes(:group_order => :ordergroup).where('group_order_articles.result > 0 OR group_order_articles.quantity > 0 OR group_order_articles.tolerance > 0').order('groups.name') } localize_input_of :result # Setter used in group_order_article#new # We have to create an group_order, if the ordergroup wasn't involved in the order yet def ordergroup_id=(id) - self.group_order = GroupOrder.find_or_initialize_by_order_id_and_ordergroup_id(order_article.order_id, id) + self.group_order = GroupOrder.where(order_id: order_article.order_id, ordergroup_id: id).first_or_initialize end def ordergroup_id - group_order.try(:ordergroup_id) + group_order.try!(:ordergroup_id) end # Updates the quantity/tolerance for this GroupOrderArticle by updating both GroupOrderArticle properties @@ -36,7 +36,7 @@ class GroupOrderArticle < ActiveRecord::Base logger.debug("Current quantity = #{self.quantity}, tolerance = #{self.tolerance}") # Get quantities ordered with the newest item first. - quantities = group_order_article_quantities.find(:all, :order => 'created_on desc') + quantities = group_order_article_quantities.order('created_on DESC').to_a logger.debug("GroupOrderArticleQuantity items found: #{quantities.size}") if (quantities.size == 0) @@ -120,8 +120,7 @@ class GroupOrderArticle < ActiveRecord::Base # In total there are enough units ordered. Now check the individual result for the ordergroup (group_order). # # Get all GroupOrderArticleQuantities for this OrderArticle... - order_quantities = GroupOrderArticleQuantity.all( - :conditions => ["group_order_article_id IN (?)", order_article.group_order_article_ids], :order => 'created_on') + order_quantities = GroupOrderArticleQuantity.where(group_order_article_id: order_article.group_order_article_ids).order('created_on') logger.debug "GroupOrderArticleQuantity records found: #{order_quantities.size}" # Determine quantities to be ordered... diff --git a/app/models/invite.rb b/app/models/invite.rb index 21cb1b9d..6db93138 100644 --- a/app/models/invite.rb +++ b/app/models/invite.rb @@ -5,7 +5,7 @@ class Invite < ActiveRecord::Base belongs_to :user belongs_to :group - validates_format_of :email, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i + validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i validates_presence_of :user validates_presence_of :group validates_presence_of :token diff --git a/app/models/invoice.rb b/app/models/invoice.rb index 0feb3ede..6f95cd43 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -7,7 +7,7 @@ class Invoice < ActiveRecord::Base validates_presence_of :supplier_id validates_numericality_of :amount, :deposit, :deposit_credit - scope :unpaid, :conditions => { :paid_on => nil } + scope :unpaid, -> { where(paid_on: nil) } # Replace numeric seperator with database format localize_input_of :amount, :deposit, :deposit_credit diff --git a/app/models/membership.rb b/app/models/membership.rb index 5af05c41..1c746135 100644 --- a/app/models/membership.rb +++ b/app/models/membership.rb @@ -5,14 +5,12 @@ class Membership < ActiveRecord::Base before_destroy :check_last_admin - # messages - ERR_NO_ADMIN_MEMBER_DELETE = I18n.t('model.membership.no_admin_delete') protected # check if this is the last admin-membership and deny def check_last_admin - raise ERR_NO_ADMIN_MEMBER_DELETE if self.group.role_admin? && self.group.memberships.size == 1 && Group.find_all_by_role_admin(true).size == 1 + raise I18n.t('model.membership.no_admin_delete') if self.group.role_admin? && self.group.memberships.size == 1 && Group.where(role_admin: true).count == 1 end end diff --git a/app/models/message.rb b/app/models/message.rb index 6504489c..7e3fc229 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -4,9 +4,9 @@ class Message < ActiveRecord::Base serialize :recipients_ids, Array attr_accessor :sent_to_all, :group_id, :recipient_tokens, :reply_to - scope :pending, where(:email_state => 0) - scope :sent, where(:email_state => 1) - scope :public, where(:private => false) + scope :pending, -> { where(:email_state => 0) } + scope :sent, -> { where(:email_state => 1) } + scope :public, -> { where(:private => false) } # Values for the email_state attribute: :none, :pending, :sent, :failed EMAIL_STATE = { diff --git a/app/models/order.rb b/app/models/order.rb index 99ccaaf9..738daac4 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -10,7 +10,7 @@ class Order < ActiveRecord::Base has_many :group_orders, :dependent => :destroy has_many :ordergroups, :through => :group_orders has_one :invoice - has_many :comments, :class_name => "OrderComment", :order => "created_at" + has_many :comments, -> { order('created_at') }, :class_name => "OrderComment" has_many :stock_changes belongs_to :supplier belongs_to :updated_by, :class_name => 'User', :foreign_key => 'updated_by_user_id' @@ -25,11 +25,11 @@ class Order < ActiveRecord::Base after_save :save_order_articles, :update_price_of_group_orders # Finders - scope :open, where(state: 'open').order('ends DESC') - scope :finished, where("orders.state = 'finished' OR orders.state = 'closed'").order('ends DESC') - scope :finished_not_closed, where(state: 'finished').order('ends DESC') - scope :closed, where(state: 'closed').order('ends DESC') - scope :stockit, where(supplier_id: 0).order('ends DESC') + scope :open, -> { where(state: 'open').order('ends DESC') } + scope :finished, -> { where("orders.state = 'finished' OR orders.state = 'closed'").order('ends DESC') } + scope :finished_not_closed, -> { where(state: 'finished').order('ends DESC') } + scope :closed, -> { where(state: 'closed').order('ends DESC') } + scope :stockit, -> { where(supplier_id: 0).order('ends DESC') } def stockit? supplier_id == 0 @@ -43,12 +43,12 @@ class Order < ActiveRecord::Base if stockit? # make sure to include those articles which are no longer available # but which have already been ordered in this stock order - StockArticle.available.all(:include => :article_category, - :order => 'article_categories.name, articles.name').reject{ |a| + StockArticle.available.includes(:article_category). + order('article_categories.name, articles.name').reject{ |a| a.quantity_available <= 0 and not a.ordered_in_order?(self) }.group_by { |a| a.article_category.name } else - supplier.articles.available.all.group_by { |a| a.article_category.name } + supplier.articles.available.group_by { |a| a.article_category.name } end end @@ -107,7 +107,7 @@ class Order < ActiveRecord::Base end def articles_sort_by_category - order_articles.all(:include => [:article], :order => 'articles.name').sort do |a,b| + order_articles.includes(:article).order('articles.name').sort do |a,b| a.article.article_category.name <=> b.article.article_category.name end end @@ -168,7 +168,7 @@ class Order < ActiveRecord::Base # Update order_articles. Save the current article_price to keep price consistency # Also save results for each group_order_result # Clean up - order_articles.all(:include => :article).each do |oa| + order_articles.includes(:article).each do |oa| oa.update_attribute(:article_price, oa.article.article_prices.first) oa.group_order_articles.each do |goa| goa.save_results! @@ -199,7 +199,7 @@ class Order < ActiveRecord::Base transaction_note = I18n.t('orders.model.notice_close', :name => name, :ends => ends.strftime(I18n.t('date.formats.default'))) - gos = group_orders.all(:include => :ordergroup) # Fetch group_orders + gos = group_orders.includes(:ordergroup) # Fetch group_orders gos.each { |group_order| group_order.update_price! } # Update prices of group_orders transaction do # Start updating account balances @@ -209,7 +209,7 @@ class Order < ActiveRecord::Base end if stockit? # Decreases the quantity of stock_articles - for oa in order_articles.all(:include => :article) + for oa in order_articles.includes(:article) oa.update_results! # Update units_to_order of order_article stock_changes.create! :stock_article => oa.article, :quantity => oa.units_to_order*-1 end @@ -236,7 +236,7 @@ class Order < ActiveRecord::Base end def keep_ordered_articles - chosen_order_articles = order_articles.find_all_by_article_id(article_ids) + chosen_order_articles = order_articles.where(article_id: article_ids) to_be_removed = order_articles - chosen_order_articles to_be_removed_but_ordered = to_be_removed.select { |a| a.quantity > 0 or a.tolerance > 0 } unless to_be_removed_but_ordered.empty? or ignore_warnings diff --git a/app/models/order_article.rb b/app/models/order_article.rb index ba53a278..a2e28fc5 100644 --- a/app/models/order_article.rb +++ b/app/models/order_article.rb @@ -19,17 +19,6 @@ class OrderArticle < ActiveRecord::Base before_create :init_from_balancing after_destroy :update_ordergroup_prices - def self.sort_by_name(order_articles) - order_articles.sort { |a,b| a.article.name <=> b.article.name } - end - - def self.sort_by_order_number(order_articles) - order_articles.sort do |a,b| - a.article.order_number.to_s.gsub(/[^[:digit:]]/, "").to_i <=> - b.article.order_number.to_s.gsub(/[^[:digit:]]/, "").to_i - end - end - # This method returns either the ArticlePrice or the Article # The first will be set, when the the order is finished def price diff --git a/app/models/ordergroup.rb b/app/models/ordergroup.rb index 745b6e3e..e556cb7d 100644 --- a/app/models/ordergroup.rb +++ b/app/models/ordergroup.rb @@ -62,9 +62,9 @@ class Ordergroup < Group def update_stats! # Get hours for every job of each user in period - jobs = users.sum { |u| u.tasks.done.sum(:duration, :conditions => ["updated_on > ?", APPLE_MONTH_AGO.month.ago]) } + jobs = users.to_a.sum { |u| u.tasks.done.where('updated_on > ?', APPLE_MONTH_AGO.month.ago).sum(:duration) } # Get group_order.price for every finished order in this period - orders_sum = group_orders.includes(:order).merge(Order.finished).where('orders.ends >= ?', APPLE_MONTH_AGO.month.ago).sum(:price) + orders_sum = group_orders.includes(:order).merge(Order.finished).where('orders.ends >= ?', APPLE_MONTH_AGO.month.ago).references(:orders).sum(:price) @readonly = false # Dirty hack, avoid getting RecordReadOnly exception when called in task after_save callback. A rails bug? update_attribute(:stats, {:jobs_size => jobs, :orders_sum => orders_sum}) @@ -113,8 +113,8 @@ class Ordergroup < Group # Make sure, the name is uniq, add usefull message if uniq group is already deleted def uniqueness_of_name - group = Ordergroup.where('groups.name = ?', name) - group = group.where('groups.id != ?', self.id) unless new_record? + group = Ordergroup.where(name: name) + group = group.where.not(id: self.id) unless new_record? if group.exists? message = group.first.deleted? ? :taken_with_deleted : :taken errors.add :name, message diff --git a/app/models/stock_article.rb b/app/models/stock_article.rb index 0948b257..27fc563c 100644 --- a/app/models/stock_article.rb +++ b/app/models/stock_article.rb @@ -3,7 +3,7 @@ class StockArticle < Article has_many :stock_changes - scope :available, -> { undeleted.where'quantity > 0' } + scope :available, -> { undeleted.where('quantity > 0') } before_destroy :check_quantity @@ -19,7 +19,7 @@ class StockArticle < Article def quantity_ordered OrderArticle.where(article_id: id). - joins(:order).where("orders.state = 'open' OR orders.state = 'finished'").sum(:units_to_order) + joins(:order).where(orders: {state: ['open', 'finished']}).sum(:units_to_order) end def quantity_history diff --git a/app/models/supplier.rb b/app/models/supplier.rb index 838c9607..4ea5c93a 100644 --- a/app/models/supplier.rb +++ b/app/models/supplier.rb @@ -1,14 +1,13 @@ # encoding: utf-8 class Supplier < ActiveRecord::Base - - has_many :articles, :conditions => {:type => nil}, - :include => [:article_category], :order => 'article_categories.name, articles.name' - has_many :stock_articles, :include => [:article_category], :order => 'article_categories.name, articles.name' + has_many :articles, -> { where(:type => nil).includes(:article_category).order('article_categories.name', 'articles.name') } + has_many :stock_articles, -> { includes(:article_category).order('article_categories.name', 'articles.name') } has_many :orders has_many :deliveries has_many :invoices belongs_to :shared_supplier # for the sharedLists-App + include ActiveModel::MassAssignmentSecurity attr_accessible :name, :address, :phone, :phone2, :fax, :email, :url, :contact_person, :customer_number, :delivery_days, :order_howto, :note, :shared_supplier_id, :min_order_quantity @@ -82,8 +81,8 @@ class Supplier < ActiveRecord::Base # Make sure, the name is uniq, add usefull message if uniq group is already deleted def uniqueness_of_name - supplier = Supplier.where('suppliers.name = ?', name) - supplier = supplier.where('suppliers.id != ?', self.id) unless new_record? + supplier = Supplier.where(name: name) + supplier = supplier.where.not(id: self.id) unless new_record? if supplier.exists? message = supplier.first.deleted? ? :taken_with_deleted : :taken errors.add :name, message diff --git a/app/models/task.rb b/app/models/task.rb index bd2f23d6..d15e0f2c 100644 --- a/app/models/task.rb +++ b/app/models/task.rb @@ -5,13 +5,14 @@ class Task < ActiveRecord::Base belongs_to :workgroup belongs_to :periodic_task_group - scope :non_group, where(workgroup_id: nil, done: false) - scope :done, where(done: true) - scope :undone, where(done: false) + scope :non_group, -> { where(workgroup_id: nil, done: false) } + scope :done, -> { where(done: true) } + scope :undone, -> { where(done: false) } attr_accessor :current_user_id # form will send user in string. responsibilities will added later + include ActiveModel::MassAssignmentSecurity attr_protected :users validates :name, :presence => true, :length => { :minimum => 3 } diff --git a/app/models/user.rb b/app/models/user.rb index f04d2714..bb98be2d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -26,7 +26,7 @@ class User < ActiveRecord::Base validates_presence_of :email validates_presence_of :password, :on => :create - validates_format_of :email, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i + validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i validates_uniqueness_of :email, :case_sensitive => false validates_presence_of :first_name # for simple_form validations validates_length_of :first_name, :in => 2..50 @@ -157,7 +157,7 @@ class User < ActiveRecord::Base #Returns an array with the users groups (but without the Ordergroups -> because tpye=>"") def member_of_groups() - self.groups.find(:all, :conditions => {:type => ""}) + self.groups.where(type: '') end def self.authenticate(login, password) diff --git a/app/models/workgroup.rb b/app/models/workgroup.rb index 3bcf124d..8b5e975a 100644 --- a/app/models/workgroup.rb +++ b/app/models/workgroup.rb @@ -3,7 +3,7 @@ class Workgroup < Group has_many :tasks # returns all non-finished tasks - has_many :open_tasks, :class_name => 'Task', :conditions => ['done = ?', false], order: 'due_date ASC, name ASC' + has_many :open_tasks, -> { where(:done => false).order('due_date ASC, name ASC') }, :class_name => 'Task' validates_uniqueness_of :name validate :last_admin_on_earth, :on => :update @@ -13,7 +13,7 @@ class Workgroup < Group # Check before destroy a group, if this is the last group with admin role def check_last_admin_group - if role_admin && Workgroup.where(:role_admin => true).size == 1 + if role_admin && Workgroup.where(role_admin: true).size == 1 raise I18n.t('workgroups.error_last_admin_group') end end @@ -21,7 +21,7 @@ class Workgroup < Group # add validation check on update # Return an error if this is the last group with admin role and role_admin should set to false def last_admin_on_earth - if !role_admin && !Workgroup.where('role_admin = ? AND id != ?', true, id).exists? + if !role_admin && !Workgroup.where(role_admin: true).where.not(id: id).exists? errors.add(:role_admin, I18n.t('workgroups.error_last_admin_role')) end end diff --git a/app/views/admin/ordergroups/_ordergroups.html.haml b/app/views/admin/ordergroups/_ordergroups.html.haml index 6670c05f..9de721b0 100644 --- a/app/views/admin/ordergroups/_ordergroups.html.haml +++ b/app/views/admin/ordergroups/_ordergroups.html.haml @@ -18,5 +18,5 @@ %td= ordergroup.users.size %td = link_to t('ui.edit'), edit_admin_ordergroup_path(ordergroup), class: 'btn btn-mini' - = link_to t('ui.delete'), [:admin, ordergroup], :confirm => t('admin.confirm', name: ordergroup.name), + = link_to t('ui.delete'), [:admin, ordergroup], :data => {:confirm => t('admin.confirm', name: ordergroup.name)}, :method => :delete, class: 'btn btn-mini btn-danger' diff --git a/app/views/admin/ordergroups/show.html.haml b/app/views/admin/ordergroups/show.html.haml index fa1641ca..bd339105 100644 --- a/app/views/admin/ordergroups/show.html.haml +++ b/app/views/admin/ordergroups/show.html.haml @@ -2,5 +2,5 @@ %section= render 'shared/group', group: @ordergroup = link_to t('ui.edit'), edit_admin_ordergroup_path(@ordergroup), class: 'btn' -= link_to t('ui.delete'), [:admin, @ordergroup], :confirm => t('.confirm'), :method => :delete, class: 'btn btn-danger' += link_to t('ui.delete'), [:admin, @ordergroup], :data => {:confirm => t('.confirm')}, :method => :delete, class: 'btn btn-danger' = link_to t('.send_message'), new_message_path(:message => {:group_id => @ordergroup.id}), class: 'btn' diff --git a/app/views/admin/users/_users.html.haml b/app/views/admin/users/_users.html.haml index 95d39464..b38c7c54 100644 --- a/app/views/admin/users/_users.html.haml +++ b/app/views/admin/users/_users.html.haml @@ -21,5 +21,5 @@ %td= format_roles(user) %td= format_time(user.last_login) %td= link_to t('ui.edit'), edit_admin_user_path(user), class: 'btn btn-mini' - %td= link_to t('ui.delete'), [:admin, user], :confirm => t('admin.confirm', name: user.name), + %td= link_to t('ui.delete'), [:admin, user], :data => {:confirm => t('admin.confirm', name: user.name)}, :method => :delete, class: 'btn btn-danger btn-mini' diff --git a/app/views/admin/users/show.html.haml b/app/views/admin/users/show.html.haml index 21d03e0a..50e368a2 100644 --- a/app/views/admin/users/show.html.haml +++ b/app/views/admin/users/show.html.haml @@ -29,12 +29,12 @@ .well %h4= t '.groupabos' %ul.unstyled - - for membership in Membership.find_all_by_user_id(@user.id) + - for membership in Membership.where(user: @user) %li= link_to(membership.group.name, [:admin, membership.group]) %hr/ %p = link_to t('ui.edit'), edit_admin_user_path(@user), class: 'btn' - = link_to t('ui.delete'), [:admin, @user], :confirm => t('.confirm', user: @user.first_name), + = link_to t('ui.delete'), [:admin, @user], :data => {:confirm => t('.confirm', user: @user.first_name)}, :method => :delete, class: 'btn btn-danger' = link_to t('.send_message'), new_message_path(:message => {:mail_to => @user.id}), class: 'btn' diff --git a/app/views/admin/workgroups/_workgroups.html.haml b/app/views/admin/workgroups/_workgroups.html.haml index fd61b463..8ab745ba 100644 --- a/app/views/admin/workgroups/_workgroups.html.haml +++ b/app/views/admin/workgroups/_workgroups.html.haml @@ -16,5 +16,5 @@ %td= format_roles(workgroup) %td = link_to t('ui.edit'), edit_admin_workgroup_path(workgroup), class: 'btn btn-mini' - = link_to t('ui.delete'), [:admin, workgroup], :confirm => t('admin.confirm', name: workgroup.name), + = link_to t('ui.delete'), [:admin, workgroup], :data => {:confirm => t('admin.confirm', name: workgroup.name)}, :method => :delete, class: 'btn btn-mini btn-danger' diff --git a/app/views/admin/workgroups/show.html.haml b/app/views/admin/workgroups/show.html.haml index 6f609001..cf6b8967 100644 --- a/app/views/admin/workgroups/show.html.haml +++ b/app/views/admin/workgroups/show.html.haml @@ -2,5 +2,5 @@ %section= render 'shared/group', group: @workgroup = link_to t('ui.edit'), edit_admin_workgroup_path(@workgroup), class: 'btn' -= link_to t('ui.delete'), [:admin, @workgroup], :confirm => t('.confirm'), :method => :delete, class: 'btn btn-danger' += link_to t('ui.delete'), [:admin, @workgroup], :data => {:confirm => t('.confirm')}, :method => :delete, class: 'btn btn-danger' = link_to_new_message(message_params: {group_id: @workgroup.id}) diff --git a/app/views/article_categories/index.html.haml b/app/views/article_categories/index.html.haml index 00bcc354..bada1f2e 100644 --- a/app/views/article_categories/index.html.haml +++ b/app/views/article_categories/index.html.haml @@ -15,5 +15,5 @@ %td= article_category.description %td = link_to t('ui.edit'), edit_article_category_path(article_category), class: 'btn btn-mini' - = link_to t('ui.delete'), article_category, :method => :delete, :confirm => t('.confirm_delete'), + = link_to t('ui.delete'), article_category, :method => :delete, :data => {:confirm => t('.confirm_delete')}, class: 'btn btn-mini btn-danger' diff --git a/app/views/articles/_article.html.haml b/app/views/articles/_article.html.haml index aaa6210c..8d4fae41 100644 --- a/app/views/articles/_article.html.haml +++ b/app/views/articles/_article.html.haml @@ -14,4 +14,4 @@ %td= link_to t('ui.edit'), edit_supplier_article_path(@supplier, article), :remote => true, class: 'btn btn-mini' %td= link_to t('ui.delete'), [@supplier, article], - :method => :delete, :confirm => t('.confirm_delete'), :remote => true, class: 'btn btn-mini btn-danger' + :method => :delete, :data => {:confirm => t('.confirm_delete')}, :remote => true, class: 'btn btn-mini btn-danger' diff --git a/app/views/articles/_articles.html.haml b/app/views/articles/_articles.html.haml index 283abc53..ae667863 100644 --- a/app/views/articles/_articles.html.haml +++ b/app/views/articles/_articles.html.haml @@ -28,7 +28,7 @@ = check_box_tag :checkall, 1, false, 'data-check-all' => '#articlesInListForm', 'data-ignore-onchange' => true %select{:name => "selected_action", 'data-submit-onchange' => true} %option{:value => '', :selected => 'selected'}= t '.option_select' - %option{:value => "destroy", 'data-confirm' => t('.confirm_delete')}= t '.option_delete' + %option{:value => "destroy", :data => {:confirm => t('.confirm_delete')}}= t '.option_delete' %option{:value => "setNotAvailable"}= t '.option_not_available' %option{:value => "setAvailable"}= t '.option_available' = hidden_field_tag 'supplier_id', @supplier.id diff --git a/app/views/articles/_import_search_results.haml b/app/views/articles/_import_search_results.haml index 254abca8..c456f38c 100644 --- a/app/views/articles/_import_search_results.haml +++ b/app/views/articles/_import_search_results.haml @@ -1,7 +1,7 @@ - if @articles.empty? %p= t '.not_found' - else - = pagination_links_remote @articles, :params => {:search => search_params} + = pagination_links_remote @articles, :params => {:q => search_params} %table.table.table-striped %thead %tr @@ -16,7 +16,7 @@ %tbody - for article in @articles %tr - %td= highlight article.name, params[:search][:name_contains_all] + %td= highlight article.name, params[:q][:name_cont_all] %td= article.origin %td= article.manufacturer %td= article.note diff --git a/app/views/articles/index.haml b/app/views/articles/index.haml index f6e11a60..fabe14f8 100644 --- a/app/views/articles/index.haml +++ b/app/views/articles/index.haml @@ -28,7 +28,7 @@ = t '.change_supplier' %span.caret %ul.dropdown-menu - - Supplier.undeleted.where('id != ?', @supplier.id).order('suppliers.name ASC').each do |supplier| + - Supplier.undeleted.where.not(id: @supplier.id).order('suppliers.name ASC').each do |supplier| %li= link_to supplier.name, supplier_articles_path(supplier), tabindex: -1 - unless @supplier.shared_supplier.nil? @@ -36,10 +36,10 @@ = form_tag shared_supplier_articles_path(@supplier), method: :get, remote: true, class: 'form-search', 'data-submit-onchange' => true do %h3= t '.import.title' - = text_field_tag "search[name_contains_all]", "", class: 'input-medium search-query', + = text_field_tag "q[name_cont_all]", "", class: 'input-medium search-query', placeholder: t('.import.placeholder') %label.checkbox - = check_box_tag "search[origin_equals]", "REG", false + = check_box_tag "q[origin_eq]", "REG", false = t '.import.restrict_region' #search_results.clearfix = link_to t('ui.close'), "#import", 'data-toggle-this' => '#import' diff --git a/app/views/deliveries/index.html.haml b/app/views/deliveries/index.html.haml index 423332b1..3c547adb 100644 --- a/app/views/deliveries/index.html.haml +++ b/app/views/deliveries/index.html.haml @@ -15,7 +15,7 @@ %td = link_to t('ui.show'), [@supplier, delivery], class: 'btn btn-mini' = link_to t('ui.edit'), edit_supplier_delivery_path(@supplier,delivery), class: 'btn btn-mini' - = link_to t('ui.delete'), [@supplier,delivery], :confirm => t('.confirm_delete'), :method => :delete, + = link_to t('ui.delete'), [@supplier,delivery], :data => {:confirm => t('.confirm_delete')}, :method => :delete, class: 'btn btn-mini btn-danger' = link_to t('.new_delivery', supplier: @supplier.name), new_supplier_delivery_path(@supplier), class: 'btn btn-primary' diff --git a/app/views/deliveries/show.html.haml b/app/views/deliveries/show.html.haml index 43f157bc..d96e233a 100644 --- a/app/views/deliveries/show.html.haml +++ b/app/views/deliveries/show.html.haml @@ -24,7 +24,7 @@ %th.numeric= t '.sum' %tbody - total_net, total_gross = 0,0 - - @delivery.stock_changes.all.each do |stock_change| + - @delivery.stock_changes.each do |stock_change| - quantity = stock_change.quantity - sum = quantity * stock_change.stock_article.price - total_net += sum diff --git a/app/views/finance/balancing/_order_article.html.haml b/app/views/finance/balancing/_order_article.html.haml index 24125544..d540081d 100644 --- a/app/views/finance/balancing/_order_article.html.haml +++ b/app/views/finance/balancing/_order_article.html.haml @@ -24,4 +24,4 @@ class: 'btn btn-mini' %td = link_to t('ui.delete'), order_order_article_path(order_article.order, order_article), method: :delete, - remote: true, confirm: t('.confirm'), class: 'btn btn-danger btn-mini' + remote: true, data: {confirm: t('.confirm')}, class: 'btn btn-danger btn-mini' diff --git a/app/views/finance/balancing/_orders.html.haml b/app/views/finance/balancing/_orders.html.haml index a71dd0c5..bc4f95a6 100644 --- a/app/views/finance/balancing/_orders.html.haml +++ b/app/views/finance/balancing/_orders.html.haml @@ -26,6 +26,6 @@ = link_to t('orders.index.action_receive'), '#', class: 'btn btn-mini disabled' = link_to t('.clear'), new_finance_order_path(order_id: order.id), class: 'btn btn-mini btn-primary' = link_to t('.close'), close_direct_finance_order_path(order), - :confirm => t('.confirm'), :method => :put, class: 'btn btn-mini' + :data => {:confirm => t('.confirm')}, :method => :patch, class: 'btn btn-mini' - else %i= t('.no_closed_orders') diff --git a/app/views/finance/balancing/confirm.html.haml b/app/views/finance/balancing/confirm.html.haml index 96f762fd..ac37a8e1 100644 --- a/app/views/finance/balancing/confirm.html.haml +++ b/app/views/finance/balancing/confirm.html.haml @@ -6,5 +6,5 @@ %td= group_order.ordergroup.name %td.numeric= number_to_currency(group_order.price) .form-actions - = link_to t('.clear'), close_finance_order_path(@order), method: :put, class: 'btn btn-primary' + = link_to t('.clear'), close_finance_order_path(@order), method: :patch, class: 'btn btn-primary' = link_to t('.or_cancel'), new_finance_order_path(order_id: @order.id) diff --git a/app/views/finance/financial_transactions/_ordergroup.haml b/app/views/finance/financial_transactions/_ordergroup.haml index c2595c61..48f4e2c9 100644 --- a/app/views/finance/financial_transactions/_ordergroup.haml +++ b/app/views/finance/financial_transactions/_ordergroup.haml @@ -1,7 +1,7 @@ %tr.transaction %td = select_tag 'financial_transactions[][ordergroup_id]', - options_for_select(Ordergroup.order(:name).all.map { |g| [ g.name, g.id ] }) + options_for_select(Ordergroup.order(:name).map { |g| [ g.name, g.id ] }) %td= text_field_tag 'financial_transactions[][amount]', nil, class: 'input-small' %td= link_to t('.remove'), "#", :title => t('.remove_group'), 'data-remove-transaction' => true, - class: 'btn btn-small' \ No newline at end of file + class: 'btn btn-small' diff --git a/app/views/finance/invoices/_invoices.html.haml b/app/views/finance/invoices/_invoices.html.haml index 0d3920ef..1aa6d4d4 100644 --- a/app/views/finance/invoices/_invoices.html.haml +++ b/app/views/finance/invoices/_invoices.html.haml @@ -27,5 +27,5 @@ %td= link_to format_date(invoice.order.ends), new_finance_order_path(order_id: invoice.order_id) if invoice.order %td= truncate(invoice.note) %td= link_to t('ui.edit'), edit_finance_invoice_path(invoice), class: 'btn btn-mini' - %td= link_to t('ui.delete'), finance_invoice_path(invoice), :confirm => t('.confirm_delete'), :method => :delete, + %td= link_to t('ui.delete'), finance_invoice_path(invoice), :data => {:confirm => t('.confirm_delete')}, :method => :delete, class: 'btn btn-danger btn-mini' diff --git a/app/views/group_orders/index.html.haml b/app/views/group_orders/index.html.haml index 41842342..9d685a9c 100644 --- a/app/views/group_orders/index.html.haml +++ b/app/views/group_orders/index.html.haml @@ -34,6 +34,6 @@ - unless Order.closed.empty? %section %h2= t '.closed_orders.title' - = render :partial => "orders", :locals => {:orders => Order.closed.all(:limit => 5), :pagination => false} + = render :partial => "orders", :locals => {:orders => Order.closed.limit(5), :pagination => false} %br/ = link_to t('.closed_orders.more'), archive_group_orders_path diff --git a/app/views/home/profile.html.haml b/app/views/home/profile.html.haml index 31fa9ee9..b0094e83 100644 --- a/app/views/home/profile.html.haml +++ b/app/views/home/profile.html.haml @@ -19,5 +19,5 @@ remote: true, class: 'btn btn-success btn-small' - if membership.group.type != 'Ordergroup' %td= link_to t('.groups.cancel'), cancel_membership_path(membership_id: membership), - confirm: t('.groups.cancel_confirm'), method: :post, + :data => {confirm: t('.groups.cancel_confirm')}, method: :post, class: 'btn btn-danger btn-small' diff --git a/app/views/messages/new.haml b/app/views/messages/new.haml index 9842e690..fdb9725c 100644 --- a/app/views/messages/new.haml +++ b/app/views/messages/new.haml @@ -36,8 +36,8 @@ = t('.list.mail', email: mail_to(FoodsoftConfig[:mailing_list_subscribe])).html_safe #recipients - = f.input :recipient_tokens, :input_html => { 'data-pre' => User.find_all_by_id(@message.recipients_ids).map(&:token_attributes).to_json } - = f.input :group_id, :as => :select, :collection => Group.undeleted.order('type DESC, name ASC').all.reject { |g| g.memberships.empty? } + = f.input :recipient_tokens, :input_html => { 'data-pre' => User.where(id: @message.recipients_ids).map(&:token_attributes).to_json } + = f.input :group_id, :as => :select, :collection => Group.undeleted.order('type DESC, name ASC').reject { |g| g.memberships.empty? } = f.input :private = f.input :subject, input_html: {class: 'input-xxlarge'} = f.input :body, input_html: {class: 'input-xxlarge'} diff --git a/app/views/orders/index.html.haml b/app/views/orders/index.html.haml index 16546373..f6845165 100644 --- a/app/views/orders/index.html.haml +++ b/app/views/orders/index.html.haml @@ -33,13 +33,13 @@ %td= format_time(order.ends) unless order.ends.nil? %td= truncate(order.note) %td= link_to t('.action_end'), finish_order_path(order), - confirm: t('.confirm_end', order: order.name), method: :post, + data: {confirm: t('.confirm_end', order: order.name)}, method: :post, class: 'btn btn-small btn-success' %td = link_to t('ui.edit'), edit_order_path(order), class: 'btn btn-small' = link_to t('ui.show'), order, class: 'btn btn-small' - = link_to t('ui.delete'), order, confirm: t('.confirm_delete'), method: :delete, + = link_to t('ui.delete'), order, data: {confirm: t('.confirm_delete')}, method: :delete, class: 'btn btn-small btn-danger' - unless @finished_orders.empty? @@ -60,7 +60,7 @@ %td = link_to t('ui.edit'), '#', class: 'btn btn-small disabled', tabindex: -1 = link_to t('ui.show'), order, class: 'btn btn-small' - = link_to t('ui.delete'), order, confirm: t('.confirm_delete'), method: :delete, + = link_to t('ui.delete'), order, data: {confirm: t('.confirm_delete')}, method: :delete, class: 'btn btn-small btn-danger' %h2= t '.orders_settled' diff --git a/app/views/orders/show.html.haml b/app/views/orders/show.html.haml index a3282fbf..ef1ebf7b 100644 --- a/app/views/orders/show.html.haml +++ b/app/views/orders/show.html.haml @@ -59,16 +59,15 @@ - if @order.open? = link_to t('.action_end'), finish_order_path(@order), method: :post, class: 'btn btn-success', - confirm: t('.confirm_end', order: @order.name) + data: {confirm: t('.confirm_end', order: @order.name)} = link_to t('ui.edit'), edit_order_path(@order), class: 'btn' - elsif not @order.closed? and not @order.stockit? -# TODO btn-success class only if not received before = link_to t('orders.index.action_receive'), receive_order_path(@order), class: 'btn btn-success' - unless @order.closed? - = link_to t('ui.delete'), @order, confirm: t('.confirm_delete'), method: :delete, + = link_to t('ui.delete'), @order, data_confirm: t('.confirm_delete'), method: :delete, class: 'btn btn-danger' - %section#articles_table = render @partial, order: @order diff --git a/app/views/shared/_article_fields_price.html.haml b/app/views/shared/_article_fields_price.html.haml index 73c5757b..ea6ee9a2 100644 --- a/app/views/shared/_article_fields_price.html.haml +++ b/app/views/shared/_article_fields_price.html.haml @@ -19,7 +19,7 @@ = number_to_currency(f.object.fc_price) rescue nil -# do this inline, since it's being used in ajax forms only -- field = f.object.class.model_name.underscore +- field = f.object.class.model_name.to_s.underscore :javascript var form = $('#article_fc_price').closest('form'); $('##{field}_price, ##{field}_tax, ##{field}_deposit', form).on('change keyup', function() { diff --git a/app/views/shared/articles_by/_articles.html.haml b/app/views/shared/articles_by/_articles.html.haml index be3ce1e9..d75832e4 100644 --- a/app/views/shared/articles_by/_articles.html.haml +++ b/app/views/shared/articles_by/_articles.html.haml @@ -8,7 +8,7 @@ %acronym{:title => t('shared.articles.received_desc')}= t 'shared.articles.received' %th= t 'shared.articles_by.price' - - for order_article in order.order_articles.ordered.all(:include => [:article, :article_price]) + - for order_article in order.order_articles.ordered.includes([:article, :article_price]) = render 'shared/articles_by/article_single', order_article: order_article, edit: (edit rescue nil) %tr %td{colspan: 4} diff --git a/app/views/shared/articles_by/_group_single.html.haml b/app/views/shared/articles_by/_group_single.html.haml index c1bf422e..9422288d 100644 --- a/app/views/shared/articles_by/_group_single.html.haml +++ b/app/views/shared/articles_by/_group_single.html.haml @@ -4,7 +4,7 @@ %th{colspan: 9} %h4.name= group_order.ordergroup.name - total = 0 - - for goa in group_order.group_order_articles.ordered.all(:include => :order_article) + - for goa in group_order.group_order_articles.ordered.includes(:order_article) - total += goa.total_price = render 'shared/articles_by/group_single_goa', goa: goa, edit: (edit rescue nil) %tr{class: cycle('even', 'odd', :name => 'articles')} diff --git a/app/views/stock_takings/_stock_takings.html.haml b/app/views/stock_takings/_stock_takings.html.haml index de06413c..d71b8ea4 100644 --- a/app/views/stock_takings/_stock_takings.html.haml +++ b/app/views/stock_takings/_stock_takings.html.haml @@ -15,5 +15,5 @@ %td= truncate stock_taking.note %td = link_to t('ui.edit'), edit_stock_taking_path(stock_taking), class: 'btn btn-mini' - = link_to t('ui.delete'), stock_taking, :confirm => t('.confirm_delete'), :method => :delete, + = link_to t('ui.delete'), stock_taking, :data => {:confirm => t('.confirm_delete')}, :method => :delete, class: 'btn btn-mini btn-danger' diff --git a/app/views/stock_takings/show.html.haml b/app/views/stock_takings/show.html.haml index 2756bc14..60d2502c 100644 --- a/app/views/stock_takings/show.html.haml +++ b/app/views/stock_takings/show.html.haml @@ -13,7 +13,7 @@ %th= t '.supplier' %th= t '.unit' %th= t '.amount' - - for stock_change in @stock_taking.stock_changes.all + - for stock_change in @stock_taking.stock_changes %tr %td= stock_change.stock_article.name %td= stock_change.stock_article.supplier.name @@ -23,5 +23,5 @@ .btn-group = link_to t('ui.edit'), edit_stock_taking_path(@stock_taking), class: 'btn' = link_to t('.overview'), stock_takings_path, class: 'btn' - = link_to t('ui.delete'), @stock_taking, :method => :delete, :confirm => t('.confirm_delete'), + = link_to t('ui.delete'), @stock_taking, :method => :delete, :data => {:confirm => t('.confirm_delete')}, class: 'btn btn-danger' diff --git a/app/views/stockit/_stock_article.html.haml b/app/views/stockit/_stock_article.html.haml index 72d4c510..0a9ba7b6 100644 --- a/app/views/stockit/_stock_article.html.haml +++ b/app/views/stockit/_stock_article.html.haml @@ -10,5 +10,5 @@ %td= stock_article.article_category.name %td = link_to t('ui.edit'), edit_stock_article_path(stock_article), remote: true, class: 'btn btn-mini' - = link_to t('ui.delete'), stock_article, :method => :delete, :confirm => t('.confirm_delete', :name => stock_article.name), + = link_to t('ui.delete'), stock_article, :method => :delete, :data => {:confirm => t('.confirm_delete', :name => stock_article.name)}, class: 'btn btn-mini btn-danger', :remote => true diff --git a/app/views/suppliers/index.haml b/app/views/suppliers/index.haml index e49c8f83..d2d3d346 100644 --- a/app/views/suppliers/index.haml +++ b/app/views/suppliers/index.haml @@ -24,4 +24,4 @@ %td = link_to t('ui.edit'), edit_supplier_path(supplier), class: 'btn btn-mini' = link_to t('ui.delete'), supplier_path(supplier), method: :delete, - confirm: t('.confirm_del', name: supplier.name), class: 'btn btn-mini btn-danger' + :data => {confirm: t('.confirm_del', name: supplier.name)}, class: 'btn btn-mini btn-danger' diff --git a/app/views/suppliers/show.haml b/app/views/suppliers/show.haml index fbc4e90a..360b06de 100644 --- a/app/views/suppliers/show.haml +++ b/app/views/suppliers/show.haml @@ -36,7 +36,7 @@ - if @current_user.role_suppliers? .form-actions = link_to t('ui.edit'), edit_supplier_path(@supplier), class: 'btn' - = link_to t('ui.delete'), @supplier, :confirm => t('.confirm_delete'), :method => :delete, class: 'btn btn-danger' + = link_to t('ui.delete'), @supplier, :data => {:confirm => t('.confirm_delete')}, :method => :delete, class: 'btn btn-danger' .span6 %h2= t '.last_deliveries' diff --git a/app/views/tasks/show.haml b/app/views/tasks/show.haml index fd3805ba..93f61269 100644 --- a/app/views/tasks/show.haml +++ b/app/views/tasks/show.haml @@ -30,8 +30,8 @@ - unless @task.done? = link_to t('.mark_done'), set_done_task_path(@task), method: :post, class: 'btn' = link_to t('ui.edit'), edit_task_path(@task), class: 'btn' - = link_to t('ui.delete'), task_path(@task), :method => :delete, :confirm => t('.confirm_delete_single'), + = link_to t('ui.delete'), task_path(@task), :method => :delete, :data => {:confirm => t('.confirm_delete_single')}, class: 'btn btn-danger' - if @task.periodic? = link_to t('.delete_group'), task_path(@task, periodic: true), method: :delete, - confirm: t('.confirm_delete_group'), class: 'btn btn-danger' + :data => {confirm: t('.confirm_delete_group')}, class: 'btn btn-danger' diff --git a/bin/autospec b/bin/autospec new file mode 100755 index 00000000..64dcb9cb --- /dev/null +++ b/bin/autospec @@ -0,0 +1,16 @@ +#!/usr/bin/env ruby +# +# This file was generated by Bundler. +# +# The application 'autospec' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require 'pathname' +ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile", + Pathname.new(__FILE__).realpath) + +require 'rubygems' +require 'bundler/setup' + +load Gem.bin_path('rspec-core', 'autospec') diff --git a/bin/bundle b/bin/bundle new file mode 100755 index 00000000..66e9889e --- /dev/null +++ b/bin/bundle @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) +load Gem.bin_path('bundler', 'bundle') diff --git a/bin/cap b/bin/cap new file mode 100755 index 00000000..30352d4d --- /dev/null +++ b/bin/cap @@ -0,0 +1,16 @@ +#!/usr/bin/env ruby +# +# This file was generated by Bundler. +# +# The application 'cap' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require 'pathname' +ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile", + Pathname.new(__FILE__).realpath) + +require 'rubygems' +require 'bundler/setup' + +load Gem.bin_path('capistrano', 'cap') diff --git a/bin/capify b/bin/capify new file mode 100755 index 00000000..0f486e81 --- /dev/null +++ b/bin/capify @@ -0,0 +1,16 @@ +#!/usr/bin/env ruby +# +# This file was generated by Bundler. +# +# The application 'capify' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require 'pathname' +ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile", + Pathname.new(__FILE__).realpath) + +require 'rubygems' +require 'bundler/setup' + +load Gem.bin_path('capistrano', 'capify') diff --git a/bin/mailcatcher b/bin/mailcatcher new file mode 100755 index 00000000..a4b2c248 --- /dev/null +++ b/bin/mailcatcher @@ -0,0 +1,16 @@ +#!/usr/bin/env ruby +# +# This file was generated by Bundler. +# +# The application 'mailcatcher' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require 'pathname' +ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile", + Pathname.new(__FILE__).realpath) + +require 'rubygems' +require 'bundler/setup' + +load Gem.bin_path('mailcatcher', 'mailcatcher') diff --git a/bin/rails b/bin/rails new file mode 100755 index 00000000..728cd85a --- /dev/null +++ b/bin/rails @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +APP_PATH = File.expand_path('../../config/application', __FILE__) +require_relative '../config/boot' +require 'rails/commands' diff --git a/bin/rake b/bin/rake new file mode 100755 index 00000000..17240489 --- /dev/null +++ b/bin/rake @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +require_relative '../config/boot' +require 'rake' +Rake.application.run diff --git a/bin/resque b/bin/resque new file mode 100755 index 00000000..2e40831b --- /dev/null +++ b/bin/resque @@ -0,0 +1,16 @@ +#!/usr/bin/env ruby +# +# This file was generated by Bundler. +# +# The application 'resque' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require 'pathname' +ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile", + Pathname.new(__FILE__).realpath) + +require 'rubygems' +require 'bundler/setup' + +load Gem.bin_path('resque', 'resque') diff --git a/bin/resque-web b/bin/resque-web new file mode 100755 index 00000000..b49543cd --- /dev/null +++ b/bin/resque-web @@ -0,0 +1,16 @@ +#!/usr/bin/env ruby +# +# This file was generated by Bundler. +# +# The application 'resque-web' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require 'pathname' +ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile", + Pathname.new(__FILE__).realpath) + +require 'rubygems' +require 'bundler/setup' + +load Gem.bin_path('resque', 'resque-web') diff --git a/bin/rspec b/bin/rspec new file mode 100755 index 00000000..0c86b5c6 --- /dev/null +++ b/bin/rspec @@ -0,0 +1,16 @@ +#!/usr/bin/env ruby +# +# This file was generated by Bundler. +# +# The application 'rspec' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require 'pathname' +ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile", + Pathname.new(__FILE__).realpath) + +require 'rubygems' +require 'bundler/setup' + +load Gem.bin_path('rspec-core', 'rspec') diff --git a/config/application.rb b/config/application.rb index c86d6b0b..9181a30c 100644 --- a/config/application.rb +++ b/config/application.rb @@ -6,12 +6,9 @@ require 'rails/all' # http://stackoverflow.com/questions/20361428 I18n.enforce_available_locales = true -if defined?(Bundler) - # If you precompile assets before deploying to production, use this line - Bundler.require(*Rails.groups(:assets => %w(development test))) - # If you want your assets lazily compiled in production, use this line - # Bundler.require(:default, :assets, Rails.env) -end +# Require the gems listed in Gemfile, including any gems +# you've limited to :test, :development, or :production. +Bundler.require(:default, Rails.env) module Foodsoft class Application < Rails::Application @@ -26,9 +23,6 @@ module Foodsoft # :all can be used as a placeholder for all plugins not explicitly named. # config.plugins = [ :exception_notification, :ssl_requirement, :all ] - # Activate observers that should always be running. - # config.active_record.observers = :cacher, :garbage_collector, :forum_observer - # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. # config.time_zone = 'Central Time (US & Canada)' @@ -41,9 +35,6 @@ module Foodsoft # Configure the default encoding used in templates for Ruby 1.9. config.encoding = "utf-8" - # Configure sensitive parameters which will be filtered from the log file. - config.filter_parameters += [:password] - # Enable escaping HTML in JSON. config.active_support.escape_html_entities_in_json = true @@ -56,7 +47,8 @@ module Foodsoft # This will create an empty whitelist of attributes available for mass-assignment for all models # in your app. As such, your models will need to explicitly whitelist or blacklist accessible # parameters by using an attr_accessible or attr_protected declaration. - config.active_record.whitelist_attributes = false # TODO: Bette re-activate this! + # TODO Re-activate this. Uncommenting this line will currently cause rspec to fail. + config.active_record.whitelist_attributes = false # Enable the asset pipeline config.assets.enabled = true @@ -67,5 +59,9 @@ module Foodsoft # It would be nice not to enable database connection when precompiling assets, # but i18n-js requires initialization, that's why it's on. config.assets.initialize_on_precompile = true + + # Load legacy scripts from vendor + config.assets.precompile += [ 'vendor/assets/javascripts/*.js' ] + end end diff --git a/config/environment.rb b/config/environment.rb index 39cacab4..ad09bf0c 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -1,5 +1,5 @@ -# Load the rails application +# Load the Rails application. require File.expand_path('../application', __FILE__) -# Initialize the rails application +# Initialize the Rails application. Foodsoft::Application.initialize! diff --git a/config/environments/development.rb.SAMPLE b/config/environments/development.rb.SAMPLE index ac1781e6..ddc936c2 100644 --- a/config/environments/development.rb.SAMPLE +++ b/config/environments/development.rb.SAMPLE @@ -1,38 +1,33 @@ Foodsoft::Application.configure do - # Settings specified here will take precedence over those in config/application.rb + # Settings specified here will take precedence over those in config/application.rb. # In the development environment your application's code is reloaded on - # every request. This slows down response time but is perfect for development + # every request. This slows down response time but is perfect for development # since you don't have to restart the web server when you make code changes. config.cache_classes = false - # Log error messages when you accidentally call methods on nil. - config.whiny_nils = true + # Do not eager load code on boot. + config.eager_load = false - # Show full error reports and disable caching + # Show full error reports and disable caching. config.consider_all_requests_local = true config.action_controller.perform_caching = false - # Don't care if the mailer can't send + # Don't care if the mailer can't send. config.action_mailer.raise_delivery_errors = false - # Print deprecation notices to the Rails logger + # Print deprecation notices to the Rails logger. config.active_support.deprecation = :log - # Only use best-standards-support built into browsers - config.action_dispatch.best_standards_support = :builtin - # Raise exception on mass assignment protection for Active Record models config.active_record.mass_assignment_sanitizer = :strict - # Log the query plan for queries taking more than this (works - # with SQLite, MySQL, and PostgreSQL) - config.active_record.auto_explain_threshold_in_seconds = 0.5 + # Raise an error on page load if there are pending migrations + config.active_record.migration_error = :page_load - # Do not compress assets - config.assets.compress = false - - # Expands the lines which load the assets + # Debug mode disables concatenation and preprocessing of assets. + # This option may cause significant delays in view rendering with a large + # number of complex assets. config.assets.debug = true # Required for i18n-js diff --git a/config/environments/production.rb b/config/environments/production.rb index 239640e0..6a1094ff 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -1,70 +1,80 @@ Foodsoft::Application.configure do - # Settings specified here will take precedence over those in config/application.rb + # Settings specified here will take precedence over those in config/application.rb. - # Code is not reloaded between requests + # Code is not reloaded between requests. config.cache_classes = true - # Full error reports are disabled and caching is turned on + # Eager load code on boot. This eager loads most of Rails and + # your application in memory, allowing both thread web servers + # and those relying on copy on write to perform better. + # Rake tasks automatically ignore this option for performance. + config.eager_load = true + + # Full error reports are disabled and caching is turned on. config.consider_all_requests_local = false config.action_controller.perform_caching = true - # Disable Rails's static asset server (Apache or nginx will already do this) + # Enable Rack::Cache to put a simple HTTP cache in front of your application + # Add `rack-cache` to your Gemfile before enabling this. + # For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid. + # config.action_dispatch.rack_cache = true + + # Disable Rails's static asset server (Apache or nginx will already do this). config.serve_static_assets = false - # Compress JavaScripts and CSS - config.assets.compress = true + # Compress JavaScripts and CSS. + config.assets.js_compressor = :uglifier + config.assets.css_compressor = :sass - # Don't fallback to assets pipeline if a precompiled asset is missed + # Do not fallback to assets pipeline if a precompiled asset is missed. config.assets.compile = false - # Generate digests for assets URLs + # Generate digests for assets URLs. config.assets.digest = true - # # Defaults to nil and saved in location specified by config.assets.prefix - # config.assets.manifest = YOUR_PATH + # Version of your assets, change this if you want to expire all your assets. + config.assets.version = '1.0' - # Specifies the header that your server uses for sending files + # Specifies the header that your server uses for sending files. # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. - config.force_ssl = true + # config.force_ssl = true - # See everything in the log (default is :info) - # config.log_level = :debug + # Set to :debug to see everything in the log. + config.log_level = :info - # Prepend all log lines with the following tags + # Prepend all log lines with the following tags. # config.log_tags = [ :subdomain, :uuid ] - # Use a different logger for distributed setups + # Use a different logger for distributed setups. # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) - # Use a different cache store in production + # Use a different cache store in production. # config.cache_store = :mem_cache_store - # Enable serving of images, stylesheets, and JavaScripts from an asset server + # Enable serving of images, stylesheets, and JavaScripts from an asset server. # config.action_controller.asset_host = "http://assets.example.com" - # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added) + # Precompile additional assets. + # application.js, application.css, and all non-JS/CSS in app/assets folder are already added. # config.assets.precompile += %w( search.js ) - # Disable delivery errors, bad email addresses will be ignored + # Ignore bad email addresses and do not raise email delivery errors. + # Set this to true and configure the email server for immediate delivery to raise delivery errors. # config.action_mailer.raise_delivery_errors = false - # Enable threaded mode - # config.threadsafe! - # Enable locale fallbacks for I18n (makes lookups for any locale fall back to - # the I18n.default_locale when a translation can not be found) + # the I18n.default_locale when a translation can not be found). config.i18n.fallbacks = true - # Send deprecation notices to registered listeners + # Send deprecation notices to registered listeners. config.active_support.deprecation = :notify - # Log the query plan for queries taking more than this (works - # with SQLite, MySQL, and PostgreSQL) - # config.active_record.auto_explain_threshold_in_seconds = 0.5 + # Disable automatic flushing of the log to improve performance. + # config.autoflush_log = false - # Use sendmail to avoid ssl cert problems - config.action_mailer.delivery_method = :sendmail + # Use default logging formatter so that PID and timestamp are not suppressed. + config.log_formatter = ::Logger::Formatter.new end diff --git a/config/environments/test.rb b/config/environments/test.rb index b67c0285..1a326914 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -1,40 +1,39 @@ Foodsoft::Application.configure do - # Settings specified here will take precedence over those in config/application.rb + # Settings specified here will take precedence over those in config/application.rb. # The test environment is used exclusively to run your application's - # test suite. You never need to work with it otherwise. Remember that + # test suite. You never need to work with it otherwise. Remember that # your test database is "scratch space" for the test suite and is wiped - # and recreated between test runs. Don't rely on the data there! + # and recreated between test runs. Don't rely on the data there! config.cache_classes = true - # Configure static asset server for tests with Cache-Control for performance - config.serve_static_assets = true - config.static_cache_control = "public, max-age=3600" + # Do not eager load code on boot. This avoids loading your whole application + # just for the purpose of running a single test. If you are using a tool that + # preloads Rails for running tests, you may have to set it to true. + config.eager_load = false # Required for i18n-js config.assets.initialize_on_precompile = true - # Log error messages when you accidentally call methods on nil - config.whiny_nils = true + # Configure static asset server for tests with Cache-Control for performance. + config.serve_static_assets = true + config.static_cache_control = "public, max-age=3600" - # Show full error reports and disable caching + # Show full error reports and disable caching. config.consider_all_requests_local = true config.action_controller.perform_caching = false - # Raise exceptions instead of rendering exception templates + # Raise exceptions instead of rendering exception templates. config.action_dispatch.show_exceptions = false - # Disable request forgery protection in test environment - config.action_controller.allow_forgery_protection = false + # Disable request forgery protection in test environment. + config.action_controller.allow_forgery_protection = false # Tell Action Mailer not to deliver emails to the real world. # The :test delivery method accumulates sent emails in the # ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test - # Raise exception on mass assignment protection for Active Record models - config.active_record.mass_assignment_sanitizer = :strict - - # Print deprecation notices to the stderr + # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr end diff --git a/config/initializers/client_side_validations.rb b/config/initializers/client_side_validations.rb index 95ff1644..8e7f76e2 100644 --- a/config/initializers/client_side_validations.rb +++ b/config/initializers/client_side_validations.rb @@ -1,9 +1,10 @@ # ClientSideValidations Initializer +# DISABLED FOR RAILS4 # Uncomment to disable uniqueness validator, possible security issue # Disabled because of possible security issue and because of bug # https://github.com/bcardarella/client_side_validations/pull/532 -ClientSideValidations::Config.disabled_validators = [:uniqueness] +#ClientSideValidations::Config.disabled_validators = [:uniqueness] # Uncomment to validate number format with current I18n locale # Foodsoft is currently using localize_input which is activated on certain diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb new file mode 100644 index 00000000..4a994e1e --- /dev/null +++ b/config/initializers/filter_parameter_logging.rb @@ -0,0 +1,4 @@ +# Be sure to restart your server when you modify this file. + +# Configure sensitive parameters which will be filtered from the log file. +Rails.application.config.filter_parameters += [:password] diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb index c113bdc8..ac033bf9 100644 --- a/config/initializers/inflections.rb +++ b/config/initializers/inflections.rb @@ -1,16 +1,16 @@ # Be sure to restart your server when you modify this file. -# Add new inflection rules using the following format -# (all these examples are active by default): -# ActiveSupport::Inflector.inflections do |inflect| +# Add new inflection rules using the following format. Inflections +# are locale specific, and you may define rules for as many different +# locales as you wish. All of these examples are active by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| # inflect.plural /^(ox)$/i, '\1en' # inflect.singular /^(ox)en/i, '\1' # inflect.irregular 'person', 'people' # inflect.uncountable %w( fish sheep ) # end -# + # These inflection rules are supported but not enabled by default: -# ActiveSupport::Inflector.inflections do |inflect| +# ActiveSupport::Inflector.inflections(:en) do |inflect| # inflect.acronym 'RESTful' # end - diff --git a/config/initializers/simple_form.rb b/config/initializers/simple_form.rb index b4cb19de..0c2c7999 100644 --- a/config/initializers/simple_form.rb +++ b/config/initializers/simple_form.rb @@ -1,4 +1,5 @@ # Use this setup block to configure all options available in SimpleForm. +require 'simple_form' SimpleForm.setup do |config| # Wrappers are used by the form builder to generate a # complete input. You can remove any component from the diff --git a/config/initializers/wrap_parameters.rb b/config/initializers/wrap_parameters.rb index 999df201..33725e95 100644 --- a/config/initializers/wrap_parameters.rb +++ b/config/initializers/wrap_parameters.rb @@ -1,14 +1,14 @@ # Be sure to restart your server when you modify this file. -# + # This file contains settings for ActionController::ParamsWrapper which # is enabled by default. # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. ActiveSupport.on_load(:action_controller) do - wrap_parameters format: [:json] + wrap_parameters format: [:json] if respond_to?(:wrap_parameters) end -# Disable root element in JSON by default. -ActiveSupport.on_load(:active_record) do - self.include_root_in_json = false -end +# To enable root element in JSON for ActiveRecord objects. +# ActiveSupport.on_load(:active_record) do +# self.include_root_in_json = true +# end diff --git a/config/navigation.rb b/config/navigation.rb index 49a3293d..9af119e0 100644 --- a/config/navigation.rb +++ b/config/navigation.rb @@ -4,7 +4,7 @@ SimpleNavigation::Configuration.run do |navigation| # allow engines to add to the menu - https://gist.github.com/mjtko/4873ee0c112b6bd646f8 - engines = Rails.application.railties.engines.select { |e| e.respond_to?(:navigation) } + engines = Rails::Engine.subclasses.map(&:instance).select { |e| e.respond_to?(:navigation) } # to include an engine but keep it from modifying the menu: #engines.reject! { |e| e.instance_of? FoodsoftMyplugin::Engine } diff --git a/config/routes.rb b/config/routes.rb index 86e49d23..a2c65428 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -6,8 +6,7 @@ Foodsoft::Application.routes.draw do get "sessions/new" - root :to => 'sessions#redirect_to_foodcoop' - + root :to => 'sessions#redirect_to_foodcoop', as: nil scope '/:foodcoop' do @@ -16,21 +15,21 @@ Foodsoft::Application.routes.draw do ########### Sessions - match '/login' => 'sessions#new', :as => 'login' - match '/logout' => 'sessions#destroy', :as => 'logout' + get '/login' => 'sessions#new', :as => 'login' + get '/logout' => 'sessions#destroy', :as => 'logout' get '/login/forgot_password' => 'login#forgot_password', as: :forgot_password post '/login/reset_password' => 'login#reset_password', as: :reset_password get '/login/new_password' => 'login#new_password', as: :new_password put '/login/update_password' => 'login#update_password', as: :update_password - match '/login/accept_invitation/:token' => 'login#accept_invitation', as: :accept_invitation + match '/login/accept_invitation/:token' => 'login#accept_invitation', as: :accept_invitation, via: [:get, :post] resources :sessions, :only => [:new, :create, :destroy] ########### User specific - match '/home/profile' => 'home#profile', :as => 'my_profile' - put '/home/update_profile' => 'home#update_profile', :as => 'update_profile' - match '/home/ordergroup' => 'home#ordergroup', :as => 'my_ordergroup' - match '/home/cancel_membership' => 'home#cancel_membership', :as => 'cancel_membership' + get '/home/profile', :as => 'my_profile' + patch '/home/update_profile', :as => 'update_profile' + get '/home/ordergroup' => 'home#ordergroup', :as => 'my_ordergroup' + post '/home/cancel_membership' => 'home#cancel_membership', :as => 'cancel_membership' ############ Orders, ordering @@ -149,8 +148,8 @@ Foodsoft::Application.routes.draw do put :update_note get :confirm - put :close - put :close_direct + patch :close + patch :close_direct get :new_on_order_article_create get :new_on_order_article_update diff --git a/db/schema.rb b/db/schema.rb index b7803b3b..4d78e630 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -9,151 +9,163 @@ # from scratch. The latter is a flawed and unsustainable approach (the more migrations # you'll amass, the slower it'll run and the greater likelihood for issues). # -# It's strongly recommended to check this file into your version control system. +# It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(:version => 20140102170431) do +ActiveRecord::Schema.define(version: 20140102170431) do - create_table "article_categories", :force => true do |t| - t.string "name", :default => "", :null => false + create_table "article_categories", force: true do |t| + t.string "name", default: "", null: false t.string "description" end - add_index "article_categories", ["name"], :name => "index_article_categories_on_name", :unique => true + add_index "article_categories", ["name"], name: "index_article_categories_on_name", unique: true, using: :btree - create_table "article_prices", :force => true do |t| + create_table "article_prices", force: true do |t| t.integer "article_id" - t.decimal "price", :precision => 8, :scale => 2, :default => 0.0, :null => false - t.decimal "tax", :precision => 8, :scale => 2, :default => 0.0, :null => false - t.decimal "deposit", :precision => 8, :scale => 2, :default => 0.0, :null => false + t.decimal "price", precision: 8, scale: 2, default: 0.0, null: false + t.decimal "tax", precision: 8, scale: 2, default: 0.0, null: false + t.decimal "deposit", precision: 8, scale: 2, default: 0.0, null: false t.integer "unit_quantity" t.datetime "created_at" end - add_index "article_prices", ["article_id"], :name => "index_article_prices_on_article_id" + add_index "article_prices", ["article_id"], name: "index_article_prices_on_article_id", using: :btree - create_table "articles", :force => true do |t| - t.string "name", :default => "", :null => false - t.integer "supplier_id", :default => 0, :null => false - t.integer "article_category_id", :default => 0, :null => false - t.string "unit", :default => "", :null => false + create_table "articles", force: true do |t| + t.string "name", default: "", null: false + t.integer "supplier_id", default: 0, null: false + t.integer "article_category_id", default: 0, null: false + t.string "unit", default: "", null: false t.string "note" - t.boolean "availability", :default => true, :null => false + t.boolean "availability", default: true, null: false t.string "manufacturer" t.string "origin" t.datetime "shared_updated_on" - t.decimal "price", :precision => 8, :scale => 2 + t.decimal "price", precision: 8, scale: 2 t.float "tax" - t.decimal "deposit", :precision => 8, :scale => 2, :default => 0.0 - t.integer "unit_quantity", :default => 1, :null => false + t.decimal "deposit", precision: 8, scale: 2, default: 0.0 + t.integer "unit_quantity", default: 1, null: false t.string "order_number" t.datetime "created_at" t.datetime "updated_at" t.datetime "deleted_at" t.string "type" - t.integer "quantity", :default => 0 + t.integer "quantity", default: 0 end - add_index "articles", ["article_category_id"], :name => "index_articles_on_article_category_id" - add_index "articles", ["name", "supplier_id"], :name => "index_articles_on_name_and_supplier_id" - add_index "articles", ["supplier_id"], :name => "index_articles_on_supplier_id" - add_index "articles", ["type"], :name => "index_articles_on_type" + add_index "articles", ["article_category_id"], name: "index_articles_on_article_category_id", using: :btree + add_index "articles", ["name", "supplier_id"], name: "index_articles_on_name_and_supplier_id", using: :btree + add_index "articles", ["supplier_id"], name: "index_articles_on_supplier_id", using: :btree + add_index "articles", ["type"], name: "index_articles_on_type", using: :btree - create_table "assignments", :force => true do |t| - t.integer "user_id", :default => 0, :null => false - t.integer "task_id", :default => 0, :null => false - t.boolean "accepted", :default => false + create_table "assignments", force: true do |t| + t.integer "user_id", default: 0, null: false + t.integer "task_id", default: 0, null: false + t.boolean "accepted", default: false end - add_index "assignments", ["user_id", "task_id"], :name => "index_assignments_on_user_id_and_task_id", :unique => true + add_index "assignments", ["user_id", "task_id"], name: "index_assignments_on_user_id_and_task_id", unique: true, using: :btree - create_table "deliveries", :force => true do |t| + create_table "configurable_settings", force: true do |t| + t.integer "configurable_id" + t.string "configurable_type" + t.integer "targetable_id" + t.string "targetable_type" + t.string "name", default: "", null: false + t.string "value_type" + t.text "value" + end + + add_index "configurable_settings", ["name"], name: "index_configurable_settings_on_name", using: :btree + + create_table "deliveries", force: true do |t| t.integer "supplier_id" t.date "delivered_on" t.datetime "created_at" t.text "note" end - add_index "deliveries", ["supplier_id"], :name => "index_deliveries_on_supplier_id" + add_index "deliveries", ["supplier_id"], name: "index_deliveries_on_supplier_id", using: :btree - create_table "financial_transactions", :force => true do |t| - t.integer "ordergroup_id", :default => 0, :null => false - t.decimal "amount", :precision => 8, :scale => 2, :default => 0.0, :null => false - t.text "note", :null => false - t.integer "user_id", :default => 0, :null => false - t.datetime "created_on", :null => false + create_table "financial_transactions", force: true do |t| + t.integer "ordergroup_id", default: 0, null: false + t.decimal "amount", precision: 8, scale: 2, default: 0.0, null: false + t.text "note", null: false + t.integer "user_id", default: 0, null: false + t.datetime "created_on", null: false end - add_index "financial_transactions", ["ordergroup_id"], :name => "index_financial_transactions_on_ordergroup_id" + add_index "financial_transactions", ["ordergroup_id"], name: "index_financial_transactions_on_ordergroup_id", using: :btree - create_table "group_order_article_quantities", :force => true do |t| - t.integer "group_order_article_id", :default => 0, :null => false - t.integer "quantity", :default => 0 - t.integer "tolerance", :default => 0 - t.datetime "created_on", :null => false + create_table "group_order_article_quantities", force: true do |t| + t.integer "group_order_article_id", default: 0, null: false + t.integer "quantity", default: 0 + t.integer "tolerance", default: 0 + t.datetime "created_on", null: false end - add_index "group_order_article_quantities", ["group_order_article_id"], :name => "index_group_order_article_quantities_on_group_order_article_id" + add_index "group_order_article_quantities", ["group_order_article_id"], name: "index_group_order_article_quantities_on_group_order_article_id", using: :btree - create_table "group_order_articles", :force => true do |t| - t.integer "group_order_id", :default => 0, :null => false - t.integer "order_article_id", :default => 0, :null => false - t.integer "quantity", :default => 0, :null => false - t.integer "tolerance", :default => 0, :null => false - t.datetime "updated_on", :null => false - t.decimal "result", :precision => 8, :scale => 3 - t.decimal "result_computed", :precision => 8, :scale => 3 + create_table "group_order_articles", force: true do |t| + t.integer "group_order_id", default: 0, null: false + t.integer "order_article_id", default: 0, null: false + t.integer "quantity", default: 0, null: false + t.integer "tolerance", default: 0, null: false + t.datetime "updated_on", null: false + t.decimal "result", precision: 8, scale: 3 + t.decimal "result_computed", precision: 8, scale: 3 end - add_index "group_order_articles", ["group_order_id", "order_article_id"], :name => "goa_index", :unique => true - add_index "group_order_articles", ["group_order_id"], :name => "index_group_order_articles_on_group_order_id" - add_index "group_order_articles", ["order_article_id"], :name => "index_group_order_articles_on_order_article_id" + add_index "group_order_articles", ["group_order_id", "order_article_id"], name: "goa_index", unique: true, using: :btree + add_index "group_order_articles", ["group_order_id"], name: "index_group_order_articles_on_group_order_id", using: :btree + add_index "group_order_articles", ["order_article_id"], name: "index_group_order_articles_on_order_article_id", using: :btree - create_table "group_orders", :force => true do |t| - t.integer "ordergroup_id", :default => 0, :null => false - t.integer "order_id", :default => 0, :null => false - t.decimal "price", :precision => 8, :scale => 2, :default => 0.0, :null => false - t.integer "lock_version", :default => 0, :null => false - t.datetime "updated_on", :null => false + create_table "group_orders", force: true do |t| + t.integer "ordergroup_id", default: 0, null: false + t.integer "order_id", default: 0, null: false + t.decimal "price", precision: 8, scale: 2, default: 0.0, null: false + t.integer "lock_version", default: 0, null: false + t.datetime "updated_on", null: false t.integer "updated_by_user_id" end - add_index "group_orders", ["order_id"], :name => "index_group_orders_on_order_id" - add_index "group_orders", ["ordergroup_id", "order_id"], :name => "index_group_orders_on_ordergroup_id_and_order_id", :unique => true - add_index "group_orders", ["ordergroup_id"], :name => "index_group_orders_on_ordergroup_id" + add_index "group_orders", ["order_id"], name: "index_group_orders_on_order_id", using: :btree + add_index "group_orders", ["ordergroup_id", "order_id"], name: "index_group_orders_on_ordergroup_id_and_order_id", unique: true, using: :btree + add_index "group_orders", ["ordergroup_id"], name: "index_group_orders_on_ordergroup_id", using: :btree - create_table "groups", :force => true do |t| - t.string "type", :default => "", :null => false - t.string "name", :default => "", :null => false + create_table "groups", force: true do |t| + t.string "type", default: "", null: false + t.string "name", default: "", null: false t.string "description" - t.decimal "account_balance", :precision => 8, :scale => 2, :default => 0.0, :null => false - t.datetime "created_on", :null => false - t.boolean "role_admin", :default => false, :null => false - t.boolean "role_suppliers", :default => false, :null => false - t.boolean "role_article_meta", :default => false, :null => false - t.boolean "role_finance", :default => false, :null => false - t.boolean "role_orders", :default => false, :null => false + t.decimal "account_balance", precision: 8, scale: 2, default: 0.0, null: false + t.datetime "created_on", null: false + t.boolean "role_admin", default: false, null: false + t.boolean "role_suppliers", default: false, null: false + t.boolean "role_article_meta", default: false, null: false + t.boolean "role_finance", default: false, null: false + t.boolean "role_orders", default: false, null: false t.datetime "deleted_at" t.string "contact_person" t.string "contact_phone" t.string "contact_address" t.text "stats" - t.integer "next_weekly_tasks_number", :default => 8 - t.boolean "ignore_apple_restriction", :default => false + t.integer "next_weekly_tasks_number", default: 8 + t.boolean "ignore_apple_restriction", default: false end - add_index "groups", ["name"], :name => "index_groups_on_name", :unique => true + add_index "groups", ["name"], name: "index_groups_on_name", unique: true, using: :btree - create_table "invites", :force => true do |t| - t.string "token", :default => "", :null => false - t.datetime "expires_at", :null => false - t.integer "group_id", :default => 0, :null => false - t.integer "user_id", :default => 0, :null => false - t.string "email", :default => "", :null => false + create_table "invites", force: true do |t| + t.string "token", default: "", null: false + t.datetime "expires_at", null: false + t.integer "group_id", default: 0, null: false + t.integer "user_id", default: 0, null: false + t.string "email", default: "", null: false end - add_index "invites", ["token"], :name => "index_invites_on_token" + add_index "invites", ["token"], name: "index_invites_on_token", using: :btree - create_table "invoices", :force => true do |t| + create_table "invoices", force: true do |t| t.integer "supplier_id" t.integer "delivery_id" t.integer "order_id" @@ -161,72 +173,72 @@ ActiveRecord::Schema.define(:version => 20140102170431) do t.date "date" t.date "paid_on" t.text "note" - t.decimal "amount", :precision => 8, :scale => 2, :default => 0.0, :null => false - t.decimal "deposit", :precision => 8, :scale => 2, :default => 0.0, :null => false - t.decimal "deposit_credit", :precision => 8, :scale => 2, :default => 0.0, :null => false + t.decimal "amount", precision: 8, scale: 2, default: 0.0, null: false + t.decimal "deposit", precision: 8, scale: 2, default: 0.0, null: false + t.decimal "deposit_credit", precision: 8, scale: 2, default: 0.0, null: false t.datetime "created_at" t.datetime "updated_at" end - add_index "invoices", ["delivery_id"], :name => "index_invoices_on_delivery_id" - add_index "invoices", ["supplier_id"], :name => "index_invoices_on_supplier_id" + add_index "invoices", ["delivery_id"], name: "index_invoices_on_delivery_id", using: :btree + add_index "invoices", ["supplier_id"], name: "index_invoices_on_supplier_id", using: :btree - create_table "memberships", :force => true do |t| - t.integer "group_id", :default => 0, :null => false - t.integer "user_id", :default => 0, :null => false + create_table "memberships", force: true do |t| + t.integer "group_id", default: 0, null: false + t.integer "user_id", default: 0, null: false end - add_index "memberships", ["user_id", "group_id"], :name => "index_memberships_on_user_id_and_group_id", :unique => true + add_index "memberships", ["user_id", "group_id"], name: "index_memberships_on_user_id_and_group_id", unique: true, using: :btree - create_table "messages", :force => true do |t| + create_table "messages", force: true do |t| t.integer "sender_id" t.text "recipients_ids" - t.string "subject", :null => false + t.string "subject", null: false t.text "body" - t.integer "email_state", :default => 0, :null => false - t.boolean "private", :default => false + t.integer "email_state", default: 0, null: false + t.boolean "private", default: false t.datetime "created_at" end - create_table "order_articles", :force => true do |t| - t.integer "order_id", :default => 0, :null => false - t.integer "article_id", :default => 0, :null => false - t.integer "quantity", :default => 0, :null => false - t.integer "tolerance", :default => 0, :null => false - t.integer "units_to_order", :default => 0, :null => false - t.integer "lock_version", :default => 0, :null => false + create_table "order_articles", force: true do |t| + t.integer "order_id", default: 0, null: false + t.integer "article_id", default: 0, null: false + t.integer "quantity", default: 0, null: false + t.integer "tolerance", default: 0, null: false + t.integer "units_to_order", default: 0, null: false + t.integer "lock_version", default: 0, null: false t.integer "article_price_id" t.integer "units_billed" t.integer "units_received" end - add_index "order_articles", ["order_id", "article_id"], :name => "index_order_articles_on_order_id_and_article_id", :unique => true - add_index "order_articles", ["order_id"], :name => "index_order_articles_on_order_id" + add_index "order_articles", ["order_id", "article_id"], name: "index_order_articles_on_order_id_and_article_id", unique: true, using: :btree + add_index "order_articles", ["order_id"], name: "index_order_articles_on_order_id", using: :btree - create_table "order_comments", :force => true do |t| + create_table "order_comments", force: true do |t| t.integer "order_id" t.integer "user_id" t.text "text" t.datetime "created_at" end - add_index "order_comments", ["order_id"], :name => "index_order_comments_on_order_id" + add_index "order_comments", ["order_id"], name: "index_order_comments_on_order_id", using: :btree - create_table "orders", :force => true do |t| + create_table "orders", force: true do |t| t.integer "supplier_id" t.text "note" t.datetime "starts" t.datetime "ends" - t.string "state", :default => "open" - t.integer "lock_version", :default => 0, :null => false + t.string "state", default: "open" + t.integer "lock_version", default: 0, null: false t.integer "updated_by_user_id" - t.decimal "foodcoop_result", :precision => 8, :scale => 2 + t.decimal "foodcoop_result", precision: 8, scale: 2 t.integer "created_by_user_id" end - add_index "orders", ["state"], :name => "index_orders_on_state" + add_index "orders", ["state"], name: "index_orders_on_state", using: :btree - create_table "page_versions", :force => true do |t| + create_table "page_versions", force: true do |t| t.integer "page_id" t.integer "lock_version" t.text "body" @@ -236,13 +248,13 @@ ActiveRecord::Schema.define(:version => 20140102170431) do t.datetime "updated_at" end - add_index "page_versions", ["page_id"], :name => "index_page_versions_on_page_id" + add_index "page_versions", ["page_id"], name: "index_page_versions_on_page_id", using: :btree - create_table "pages", :force => true do |t| + create_table "pages", force: true do |t| t.string "title" t.text "body" t.string "permalink" - t.integer "lock_version", :default => 0 + t.integer "lock_version", default: 0 t.integer "updated_by" t.integer "redirect" t.integer "parent_id" @@ -250,49 +262,49 @@ ActiveRecord::Schema.define(:version => 20140102170431) do t.datetime "updated_at" end - add_index "pages", ["permalink"], :name => "index_pages_on_permalink" - add_index "pages", ["title"], :name => "index_pages_on_title" + add_index "pages", ["permalink"], name: "index_pages_on_permalink", using: :btree + add_index "pages", ["title"], name: "index_pages_on_title", using: :btree - create_table "periodic_task_groups", :force => true do |t| + create_table "periodic_task_groups", force: true do |t| t.date "next_task_date" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end - create_table "settings", :force => true do |t| - t.string "var", :null => false + create_table "settings", force: true do |t| + t.string "var", null: false t.text "value" t.integer "thing_id" - t.string "thing_type", :limit => 30 - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.string "thing_type", limit: 30 + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end - add_index "settings", ["thing_type", "thing_id", "var"], :name => "index_settings_on_thing_type_and_thing_id_and_var", :unique => true + add_index "settings", ["thing_type", "thing_id", "var"], name: "index_settings_on_thing_type_and_thing_id_and_var", unique: true, using: :btree - create_table "stock_changes", :force => true do |t| + create_table "stock_changes", force: true do |t| t.integer "delivery_id" t.integer "order_id" t.integer "stock_article_id" - t.integer "quantity", :default => 0 + t.integer "quantity", default: 0 t.datetime "created_at" t.integer "stock_taking_id" end - add_index "stock_changes", ["delivery_id"], :name => "index_stock_changes_on_delivery_id" - add_index "stock_changes", ["stock_article_id"], :name => "index_stock_changes_on_stock_article_id" - add_index "stock_changes", ["stock_taking_id"], :name => "index_stock_changes_on_stock_taking_id" + add_index "stock_changes", ["delivery_id"], name: "index_stock_changes_on_delivery_id", using: :btree + add_index "stock_changes", ["stock_article_id"], name: "index_stock_changes_on_stock_article_id", using: :btree + add_index "stock_changes", ["stock_taking_id"], name: "index_stock_changes_on_stock_taking_id", using: :btree - create_table "stock_takings", :force => true do |t| + create_table "stock_takings", force: true do |t| t.date "date" t.text "note" t.datetime "created_at" end - create_table "suppliers", :force => true do |t| - t.string "name", :default => "", :null => false - t.string "address", :default => "", :null => false - t.string "phone", :default => "", :null => false + create_table "suppliers", force: true do |t| + t.string "name", default: "", null: false + t.string "address", default: "", null: false + t.string "phone", default: "", null: false t.string "phone2" t.string "fax" t.string "email" @@ -307,40 +319,40 @@ ActiveRecord::Schema.define(:version => 20140102170431) do t.datetime "deleted_at" end - add_index "suppliers", ["name"], :name => "index_suppliers_on_name", :unique => true + add_index "suppliers", ["name"], name: "index_suppliers_on_name", unique: true, using: :btree - create_table "tasks", :force => true do |t| - t.string "name", :default => "", :null => false + create_table "tasks", force: true do |t| + t.string "name", default: "", null: false t.string "description" t.date "due_date" - t.boolean "done", :default => false + t.boolean "done", default: false t.integer "workgroup_id" - t.datetime "created_on", :null => false - t.datetime "updated_on", :null => false - t.integer "required_users", :default => 1 - t.integer "duration", :default => 1 + t.datetime "created_on", null: false + t.datetime "updated_on", null: false + t.integer "required_users", default: 1 + t.integer "duration", default: 1 t.integer "periodic_task_group_id" end - add_index "tasks", ["due_date"], :name => "index_tasks_on_due_date" - add_index "tasks", ["name"], :name => "index_tasks_on_name" - add_index "tasks", ["workgroup_id"], :name => "index_tasks_on_workgroup_id" + add_index "tasks", ["due_date"], name: "index_tasks_on_due_date", using: :btree + add_index "tasks", ["name"], name: "index_tasks_on_name", using: :btree + add_index "tasks", ["workgroup_id"], name: "index_tasks_on_workgroup_id", using: :btree - create_table "users", :force => true do |t| + create_table "users", force: true do |t| t.string "nick" - t.string "password_hash", :default => "", :null => false - t.string "password_salt", :default => "", :null => false - t.string "first_name", :default => "", :null => false - t.string "last_name", :default => "", :null => false - t.string "email", :default => "", :null => false + t.string "password_hash", default: "", null: false + t.string "password_salt", default: "", null: false + t.string "first_name", default: "", null: false + t.string "last_name", default: "", null: false + t.string "email", default: "", null: false t.string "phone" - t.datetime "created_on", :null => false + t.datetime "created_on", null: false t.string "reset_password_token" t.datetime "reset_password_expires" t.datetime "last_login" end - add_index "users", ["email"], :name => "index_users_on_email", :unique => true - add_index "users", ["nick"], :name => "index_users_on_nick", :unique => true + add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree + add_index "users", ["nick"], name: "index_users_on_nick", unique: true, using: :btree end diff --git a/lib/foodsoft_wiki/app/models/page.rb b/lib/foodsoft_wiki/app/models/page.rb index 7759effe..ee279336 100644 --- a/lib/foodsoft_wiki/app/models/page.rb +++ b/lib/foodsoft_wiki/app/models/page.rb @@ -17,8 +17,8 @@ class Page < ActiveRecord::Base before_validation :update_permalink, :on => :update after_update :create_redirect - scope :non_redirected, :conditions => {:redirect => nil} - scope :no_parent, :conditions => {:parent_id => nil} + scope :non_redirected, -> { where(:redirect => nil) } + scope :no_parent, -> { where(:parent_id => nil) } def self.permalink(title) title.gsub(/[\/\.,;@\s]/, "_").gsub(/[\"\']/, "") diff --git a/lib/foodsoft_wiki/app/views/pages/_form.html.haml b/lib/foodsoft_wiki/app/views/pages/_form.html.haml index 5b84baa9..03589281 100644 --- a/lib/foodsoft_wiki/app/views/pages/_form.html.haml +++ b/lib/foodsoft_wiki/app/views/pages/_form.html.haml @@ -7,7 +7,7 @@ = simple_form_for @page do |f| = f.hidden_field :lock_version = f.input :title, input_html: {class: 'input-xxlarge'} - = f.input :body, input_html: {class: 'input-xxlarge'} + = f.input :body, input_html: {class: 'input-xxlarge', rows: 20} = f.input :parent_id, as: :select, collection: parent_pages_to_select(@page) .form-actions = button_tag :name => 'preview', class: 'btn' do diff --git a/lib/foodsoft_wiki/app/views/pages/show.html.haml b/lib/foodsoft_wiki/app/views/pages/show.html.haml index 91b7a9fc..440488a5 100644 --- a/lib/foodsoft_wiki/app/views/pages/show.html.haml +++ b/lib/foodsoft_wiki/app/views/pages/show.html.haml @@ -47,5 +47,5 @@ = link_to edit_page_path(@page), class: 'btn btn-primary' do %i.icon-edit= t '.edit' = link_to t('.delete'), @page, class: 'btn btn-danger', :method => :delete, - :confirm => t('.delete_confirm') + :data => {:confirm => t('.delete_confirm')} != '| ' + t('.last_updated', user: show_user(@page.user), when: format_datetime(@page.updated_at)) diff --git a/lib/foodsoft_wiki/config/routes.rb b/lib/foodsoft_wiki/config/routes.rb index 29a5ebef..5eb866e8 100644 --- a/lib/foodsoft_wiki/config/routes.rb +++ b/lib/foodsoft_wiki/config/routes.rb @@ -7,8 +7,8 @@ Rails.application.routes.draw do get :version, :on => :member get :revert, :on => :member end - match '/wiki/:permalink' => 'pages#show', :as => 'wiki_page' # , :constraints => {:permalink => /[^\s]+/} - match '/wiki' => 'pages#show', :defaults => {:permalink => 'Home'}, :as => 'wiki' + get '/wiki/:permalink' => 'pages#show', :as => 'wiki_page' # , :constraints => {:permalink => /[^\s]+/} + get '/wiki' => 'pages#show', :defaults => {:permalink => 'Home'}, :as => 'wiki' end diff --git a/lib/foodsoft_wiki/foodsoft_wiki.gemspec b/lib/foodsoft_wiki/foodsoft_wiki.gemspec index f3c50662..ceeca06c 100644 --- a/lib/foodsoft_wiki/foodsoft_wiki.gemspec +++ b/lib/foodsoft_wiki/foodsoft_wiki.gemspec @@ -16,7 +16,7 @@ Gem::Specification.new do |s| s.files = Dir["{app,config,db,lib}/**/*"] + ["Rakefile", "README.md"] s.test_files = Dir["test/**/*"] - s.add_dependency "rails", "~> 3.2.15" + s.add_dependency "rails" s.add_dependency 'wikicloth' s.add_dependency 'acts_as_versioned' # need git version, make sure that is included in foodsoft's Gemfile s.add_dependency 'diffy' diff --git a/lib/tasks/rails.rake b/lib/tasks/rails.rake deleted file mode 100644 index a4263ce0..00000000 --- a/lib/tasks/rails.rake +++ /dev/null @@ -1,31 +0,0 @@ -desc "Checks your app and gently warns you if you are using deprecated code." -task :deprecated => :environment do - deprecated = { - '@params' => 'Use params[] instead', - '@session' => 'Use session[] instead', - '@flash' => 'Use flash[] instead', - '@request' => 'Use request[] instead', - '@env' => 'Use env[] instead', - 'find_all\([^_]\|$\)' => 'Use find(:all) instead', - 'find_first' => 'Use find(:first) instead', - 'render_partial' => 'Use render :partial instead', - 'component' => 'Use of components are frowned upon', - 'paginate' => 'The default paginator is slow. Writing your own may be faster', - 'start_form_tag' => 'Use form_for instead', - 'end_form_tag' => 'Use form_for instead', - ':post => true' => 'Use :method => :post instead' - } - - deprecated.each do |key, warning| - puts '--> ' + key - output = `cd '#{File.expand_path('app', RAILS_ROOT)}' && grep -n --exclude=*.svn* --exclude=.#* -r '#{key}' *` - unless output =~ /^$/ - puts " !! " + warning + " !!" - puts ' ' + '.' * (warning.length + 6) - puts output - else - puts " Clean! Cheers for you!" - end - puts - end -end \ No newline at end of file diff --git a/spec/models/article_spec.rb b/spec/models/article_spec.rb index 0f63b88e..f484e988 100644 --- a/spec/models/article_spec.rb +++ b/spec/models/article_spec.rb @@ -36,12 +36,12 @@ describe Article do end it 'keeps a price history' do - expect(article.article_prices.all.map(&:price)).to eq([article.price]) + expect(article.article_prices.map(&:price)).to eq([article.price]) oldprice = article.price sleep 1 # so that the new price really has a later creation time article.price += 1 article.save! - expect(article.article_prices.all.map(&:price)).to eq([article.price, oldprice]) + expect(article.article_prices.reload.map(&:price)).to eq([article.price, oldprice]) end it 'is not in an open order by default' do diff --git a/spec/models/order_spec.rb b/spec/models/order_spec.rb index 81c58bd5..501f4200 100644 --- a/spec/models/order_spec.rb +++ b/spec/models/order_spec.rb @@ -23,7 +23,7 @@ describe Order do it 'is not closed by default' do expect(order).to_not be_closed end it 'has valid order articles' do - order.order_articles.all.each {|oa| expect(oa).to be_valid } + order.order_articles.each {|oa| expect(oa).to be_valid } end it 'can be finished' do diff --git a/spec/models/supplier_spec.rb b/spec/models/supplier_spec.rb index b3536105..5a989bd9 100644 --- a/spec/models/supplier_spec.rb +++ b/spec/models/supplier_spec.rb @@ -10,7 +10,7 @@ describe Supplier do it 'has valid articles' do supplier = create :supplier, article_count: true - supplier.articles.all.each {|a| expect(a).to be_valid } + supplier.articles.each {|a| expect(a).to be_valid } end end