Upgrade to rails 4.1

This commit is contained in:
wvengen 2014-11-21 14:37:56 +01:00
parent 6188567931
commit 6e990fed4c
23 changed files with 179 additions and 197 deletions

View File

@ -1,6 +1,6 @@
language: ruby
rvm:
- 2.0.0
- 2.1
services:
- redis-server
env: COVERALLS=1

17
Gemfile
View File

@ -1,12 +1,11 @@
# A sample Gemfile
source "https://rubygems.org"
ruby "2.0.0"
gem "rails", '~> 4.0.0'
gem "rails", '~> 4.1'
gem 'sass-rails', '~> 4.0.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'sass-rails', '>= 4.0' # version to avoid bundle getting confused
gem 'coffee-rails'
gem 'less-rails'
gem 'uglifier', '>= 1.0.3'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
@ -27,12 +26,10 @@ gem 'prawn-table'
gem 'haml-rails'
gem 'kaminari'
gem '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 'twitter-bootstrap-rails', '~> 2.2.8'
gem 'simple-navigation'
gem 'simple-navigation-bootstrap'
gem 'ransack'
@ -56,6 +53,10 @@ end
group :development do
gem 'sqlite3'
gem 'mailcatcher'
# allow to use `debugger` https://github.com/conradirwin/pry-rescue
gem 'pry-rescue'
gem 'pry-stack_explorer'
# Better error output
gem 'better_errors'
@ -85,7 +86,7 @@ end
group :test do
gem 'rspec-rails'
gem 'factory_girl_rails', '~> 4.0'
gem 'factory_girl_rails'
gem 'faker'
gem 'capybara'
# webkit and poltergeist don't seem to work yet

View File

@ -1,24 +1,9 @@
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
specs:
localize_input (0.1.0)
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
@ -46,33 +31,35 @@ PATH
GEM
remote: https://rubygems.org/
specs:
actionmailer (4.0.10)
actionpack (= 4.0.10)
actionmailer (4.1.8)
actionpack (= 4.1.8)
actionview (= 4.1.8)
mail (~> 2.5, >= 2.5.4)
actionpack (4.0.10)
activesupport (= 4.0.10)
builder (~> 3.1.0)
erubis (~> 2.7.0)
actionpack (4.1.8)
actionview (= 4.1.8)
activesupport (= 4.1.8)
rack (~> 1.5.2)
rack-test (~> 0.6.2)
activemodel (4.0.10)
activesupport (= 4.0.10)
builder (~> 3.1.0)
activerecord (4.0.10)
activemodel (= 4.0.10)
activerecord-deprecated_finders (~> 1.0.2)
activesupport (= 4.0.10)
arel (~> 4.0.0)
activerecord-deprecated_finders (1.0.3)
activesupport (4.0.10)
actionview (4.1.8)
activesupport (= 4.1.8)
builder (~> 3.1)
erubis (~> 2.7.0)
activemodel (4.1.8)
activesupport (= 4.1.8)
builder (~> 3.1)
activerecord (4.1.8)
activemodel (= 4.1.8)
activesupport (= 4.1.8)
arel (~> 5.0.0)
activesupport (4.1.8)
i18n (~> 0.6, >= 0.6.9)
minitest (~> 4.2)
multi_json (~> 1.3)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1)
thread_safe (~> 0.1)
tzinfo (~> 0.3.37)
tzinfo (~> 1.1)
acts_as_tree (2.1.0)
activerecord (>= 3.0.0)
arel (4.0.2)
arel (5.0.1.20140414130214)
attribute_normalizer (1.2.0)
better_errors (2.0.0)
coderay (>= 1.0.0)
@ -82,7 +69,7 @@ GEM
debug_inspector (>= 0.0.1)
bootstrap-datepicker-rails (1.3.0.2)
railties (>= 3.0)
builder (3.1.4)
builder (3.2.2)
bullet (4.14.0)
activesupport (>= 3.0.0)
uniform_notifier (>= 1.6.0)
@ -110,7 +97,7 @@ GEM
ffi (~> 1.0, >= 1.0.11)
chronic (0.10.2)
coderay (1.1.0)
coffee-rails (4.0.1)
coffee-rails (4.1.0)
coffee-script (>= 2.2.0)
railties (>= 4.0.0, < 5.0)
coffee-script (2.3.0)
@ -119,7 +106,7 @@ GEM
coffee-script-source (1.8.0)
colorize (0.7.3)
commonjs (0.2.7)
connection_pool (2.0.0)
connection_pool (2.1.0)
content_for_in_controllers (0.0.2)
coveralls (0.7.1)
multi_json (~> 1.3)
@ -147,10 +134,10 @@ GEM
activesupport (>= 3.0.4)
execjs (2.2.2)
expression_parser (0.9.0)
factory_girl (4.4.0)
factory_girl (4.5.0)
activesupport (>= 3.0.0)
factory_girl_rails (4.4.1)
factory_girl (~> 4.4.0)
factory_girl_rails (4.5.0)
factory_girl (~> 4.5.0)
railties (>= 3.0.0)
faker (1.4.3)
i18n (~> 0.5)
@ -167,13 +154,16 @@ GEM
activesupport (>= 3.2, < 5)
hike (1.2.3)
i18n (0.6.11)
i18n-js (3.0.0.rc6)
i18n-js (3.0.0.rc7)
i18n (~> 0.6)
i18n-spec (0.5.2)
i18n-spec (0.6.0)
iso
inherited_resources (1.5.0)
inherited_resources (1.5.1)
actionpack (>= 3.2, < 4.2)
has_scope (~> 0.6.0.rc)
railties (>= 3.2, < 4.2)
responders (~> 1.0)
interception (0.5)
iso (0.2.1)
i18n
jquery-rails (3.1.2)
@ -183,13 +173,13 @@ GEM
kaminari (0.16.1)
actionpack (>= 3.0.0)
activesupport (>= 3.0.0)
less (2.5.1)
less (2.6.0)
commonjs (~> 0.2.7)
less-rails (2.5.0)
less-rails (2.6.0)
actionpack (>= 3.1)
less (~> 2.5.0)
less (~> 2.6.0)
libv8 (3.16.14.7)
mail (2.6.1)
mail (2.6.3)
mime-types (>= 1.16, < 3)
mailcatcher (0.2.4)
eventmachine
@ -205,18 +195,19 @@ GEM
callsite (~> 0.0, >= 0.0.11)
rack-contrib (~> 1.1)
railties (>= 3.0.0, < 5.0.0)
mime-types (2.4.2)
mini_portile (0.6.0)
minitest (4.7.5)
method_source (0.8.2)
mime-types (2.4.3)
mini_portile (0.6.1)
minitest (5.4.3)
mono_logger (1.1.0)
multi_json (1.10.1)
mysql2 (0.3.16)
mysql2 (0.3.17)
net-scp (1.2.1)
net-ssh (>= 2.6.5)
net-ssh (2.9.1)
netrc (0.8.0)
nokogiri (1.6.3.1)
mini_portile (= 0.6.0)
nokogiri (1.6.4.1)
mini_portile (~> 0.6.0)
pdf-core (0.4.0)
polyamorous (1.1.0)
activerecord (>= 3.0)
@ -224,25 +215,37 @@ GEM
prawn (1.3.0)
pdf-core (~> 0.4.0)
ttfunk (~> 1.4.0)
prawn-table (0.2.0)
prawn-table (0.2.1)
protected_attributes (1.0.8)
activemodel (>= 4.0.1, < 5.0)
pry (0.10.1)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
pry-rescue (1.4.1)
interception (>= 0.5)
pry
pry-stack_explorer (0.4.9.1)
binding_of_caller (>= 0.7)
pry (>= 0.9.11)
quiet_assets (1.0.3)
railties (>= 3.1, < 5.0)
rack (1.5.2)
rack-contrib (1.1.0)
rack-contrib (1.2.0)
rack (>= 0.9.1)
rack-protection (1.5.3)
rack
rack-test (0.6.2)
rack (>= 1.0)
rails (4.0.10)
actionmailer (= 4.0.10)
actionpack (= 4.0.10)
activerecord (= 4.0.10)
activesupport (= 4.0.10)
rails (4.1.8)
actionmailer (= 4.1.8)
actionpack (= 4.1.8)
actionview (= 4.1.8)
activemodel (= 4.1.8)
activerecord (= 4.1.8)
activesupport (= 4.1.8)
bundler (>= 1.3.0, < 2.0)
railties (= 4.0.10)
railties (= 4.1.8)
sprockets-rails (~> 2.0)
rails-assets-listjs (0.2.0.beta.4)
railties (>= 3.1)
@ -251,13 +254,13 @@ GEM
railties (~> 4.0)
rails-settings-cached (0.4.1)
rails (>= 4.0.0)
railties (4.0.10)
actionpack (= 4.0.10)
activesupport (= 4.0.10)
railties (4.1.8)
actionpack (= 4.1.8)
activesupport (= 4.1.8)
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (10.3.2)
ransack (1.4.1)
ransack (1.5.1)
actionpack (>= 3.0)
activerecord (>= 3.0)
activesupport (>= 3.0)
@ -267,7 +270,7 @@ GEM
redis-namespace (1.5.1)
redis (~> 3.0, >= 3.0.4)
ref (1.0.5)
responders (1.1.1)
responders (1.1.2)
railties (>= 3.2, < 4.2)
resque (1.25.2)
mono_logger (~> 1.0)
@ -283,7 +286,7 @@ GEM
rspec-core (~> 2.99.0)
rspec-expectations (~> 2.99.0)
rspec-mocks (~> 2.99.0)
rspec-collection_matchers (1.0.0)
rspec-collection_matchers (1.1.2)
rspec-expectations (>= 2.99.0.beta1)
rspec-core (2.99.2)
rspec-expectations (2.99.2)
@ -300,18 +303,18 @@ GEM
rspec-mocks (~> 2.99.0)
rspec-rerun (0.2.0)
rspec (>= 2.11.0, < 3)
ruby-prof (0.15.1)
ruby-prof (0.15.2)
ruby-units (1.4.5)
rubyzip (1.1.6)
sass (3.2.19)
sass-rails (4.0.3)
sass-rails (4.0.4)
railties (>= 4.0.0, < 5.0)
sass (~> 3.2.0)
sprockets (~> 2.8, <= 2.11.0)
sass (~> 3.2.2)
sprockets (~> 2.8, < 2.12)
sprockets-rails (~> 2.0)
select2-rails (3.5.9.1)
thor (~> 0.14)
selenium-webdriver (2.43.0)
selenium-webdriver (2.44.0)
childprocess (~> 0.5)
multi_json (~> 1.0)
rubyzip (~> 1.0)
@ -336,7 +339,8 @@ GEM
skinny (0.2.3)
eventmachine (~> 1.0.0)
thin (~> 1.5.0)
sprockets (2.11.0)
slop (3.6.0)
sprockets (2.11.3)
hike (~> 1.2)
multi_json (~> 1.0)
rack (~> 1.0)
@ -345,7 +349,7 @@ GEM
actionpack (>= 3.0)
activesupport (>= 3.0)
sprockets (>= 2.8, < 4.0)
sqlite3 (1.3.9)
sqlite3 (1.3.10)
sqlite3-ruby (1.3.3)
sqlite3 (>= 1.3.3)
sshkit (1.5.1)
@ -371,7 +375,8 @@ GEM
execjs
rails (>= 3.1)
railties (>= 3.1)
tzinfo (0.3.41)
tzinfo (1.2.2)
thread_safe (~> 0.1)
uglifier (2.5.3)
execjs (>= 0.3.0)
json (>= 1.8.0)
@ -379,7 +384,7 @@ GEM
vegas (0.1.11)
rack (>= 1.0.0)
websocket (1.2.1)
whenever (0.9.3)
whenever (0.9.4)
chronic (>= 0.6.3)
wikicloth (0.8.1)
builder
@ -404,16 +409,14 @@ DEPENDENCIES
capistrano-rails
capistrano-rvm
capybara
client_side_validations!
client_side_validations-simple_form!
coffee-rails (~> 4.0.0)
coffee-rails
connection_pool
coveralls
daemons
database_cleaner
date_time_attribute
exception_notification
factory_girl_rails (~> 4.0)
factory_girl_rails
faker
foodsoft_messages!
foodsoft_wiki!
@ -431,8 +434,10 @@ DEPENDENCIES
prawn
prawn-table
protected_attributes
pry-rescue
pry-stack_explorer
quiet_assets
rails (~> 4.0.0)
rails (~> 4.1)
rails-assets-listjs (= 0.2.0.beta.4)
rails-i18n
rails-settings-cached
@ -443,7 +448,7 @@ DEPENDENCIES
rspec-rerun
ruby-prof
ruby-units
sass-rails (~> 4.0.0)
sass-rails (>= 4.0)
select2-rails
selenium-webdriver
simple-navigation
@ -453,6 +458,6 @@ DEPENDENCIES
sqlite3
therubyracer
thin
twitter-bootstrap-rails
twitter-bootstrap-rails (~> 2.2.8)
uglifier (>= 1.0.3)
whenever

View File

@ -11,8 +11,6 @@
//= require list.unlist
//= require list.delay
//= require list.reset
//= require rails.validations
//= require rails.validations.simple_form
//= require i18n
//= require i18n/translations
//= require_self

View File

@ -174,8 +174,8 @@ module ApplicationHelper
def bootstrap_flash_patched
flash_messages = []
flash.each do |type, message|
type = :success if type == :notice
type = :error if type == :alert
type = :success if type == 'notice'
type = :error if type == 'alert'
text = content_tag(:div,
content_tag(:button, I18n.t('ui.marks.close').html_safe, :class => "close", "data-dismiss" => "alert") +
message, :class => "alert fade in alert-#{type}")

View File

@ -12,7 +12,7 @@ module DeliveriesHelper
def articles_for_select2(articles, except = [], &block)
articles = articles.reorder('articles.name ASC')
articles.reject! {|a| not except.index(a.id).nil? } if except
articles = articles.reject {|a| not except.index(a.id).nil? } if except
block_given? or block = Proc.new {|a| "#{a.name} (#{number_to_currency a.price}/#{a.unit})" }
articles.map do |a|
{:id => a.id, :text => block.call(a)}

View File

@ -47,7 +47,6 @@ class User < ActiveRecord::Base
end
after_save do
return if settings_attributes.nil?
settings_attributes.each do |key, value|
value.each do |k, v|
case v
@ -58,7 +57,7 @@ class User < ActiveRecord::Base
end
end
self.settings.merge!(key, value)
end
end if settings_attributes
end
# sorted by display name

View File

@ -2,10 +2,6 @@ require File.expand_path('../boot', __FILE__)
require 'rails/all'
# need to include this before requiring some other gems
# http://stackoverflow.com/questions/20361428
I18n.enforce_available_locales = true
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env)

View File

@ -1,23 +0,0 @@
# 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]
# Uncomment to validate number format with current I18n locale
# Foodsoft is currently using localize_input which is activated on certain
# fields only, meaning we can't globally turn this on. The non-i18n number
# format is still supported - so for now keep false.
# ClientSideValidations::Config.number_format_with_locale = true
# Uncomment the following block if you want each input field to have the validation messages attached.
# ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
# unless html_tag =~ /^<label/
# %{<div class="field_with_errors">#{html_tag}<label for="#{instance.send(:tag_id)}" class="message">#{instance.error_message.first}</label></div>}.html_safe
# else
# %{<div class="field_with_errors">#{html_tag}</div>}.html_safe
# end
# end

View File

@ -7,11 +7,16 @@ class Float
end
end
# allow +to_s+ on bigdecimal without argument too
if defined? BigDecimal
class BigDecimal
alias :foodsoft_to_s :to_s
def to_s(format = DEFAULT_STRING_FORMAT)
foodsoft_to_s(format).gsub /(\.0*|(\.[0-9]+?)0+)$/, '\2'
def to_s(*args)
if args.present?
foodsoft_to_s(*args)
else
foodsoft_to_s(*args).gsub /(\.0*|(\.[0-9]+?)0+)$/, '\2'
end
end
end
end

View File

@ -1,13 +1,12 @@
# 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
# wrapper, change the order or even add your own to the
# stack. The options given below are used to wrap the
# whole input.
config.wrappers :default, :class => :input,
:hint_class => :field_with_hint, :error_class => :field_with_errors do |b|
config.wrappers :default, class: :input,
hint_class: :field_with_hint, error_class: :field_with_errors do |b|
## Extensions enabled by default
# Any of these extensions can be disabled for a
# given input by passing: `f.input EXTENSION_NAME => false`.
@ -19,7 +18,7 @@ SimpleForm.setup do |config|
b.use :html5
# Calculates placeholders automatically from I18n
# You can also pass a string as f.input :placeholder => "Placeholder"
# You can also pass a string as f.input placeholder: "Placeholder"
b.use :placeholder
## Optional extensions
@ -42,8 +41,8 @@ SimpleForm.setup do |config|
## Inputs
b.use :label_input
b.use :hint, :wrap_with => { :tag => :span, :class => :hint }
b.use :error, :wrap_with => { :tag => :span, :class => :error }
b.use :hint, wrap_with: { tag: :span, class: :hint }
b.use :error, wrap_with: { tag: :span, class: :error }
end
# The default wrapper to be used by the FormBuilder.
@ -51,8 +50,8 @@ SimpleForm.setup do |config|
# Define the way to render check boxes / radio buttons with labels.
# Defaults to :nested for bootstrap config.
# :inline => input + label
# :nested => label > input
# inline: input + label
# nested: label > input
config.boolean_style = :nested
# Default class for buttons
@ -107,8 +106,11 @@ SimpleForm.setup do |config|
# Whether attributes are required by default (or not). Default is true.
# config.required_by_default = true
# Tell browsers whether to use default HTML5 validations (novalidate option).
# Default is enabled.
# Tell browsers whether to use the native HTML5 validations (novalidate form option).
# These validations are enabled in SimpleForm's internal config but disabled by default
# in this configuration, which is recommended due to some quirks from different browsers.
# To stop SimpleForm from generating the novalidate option, enabling the HTML5 validations,
# change this configuration to true.
config.browser_validations = true
# Collection of methods to detect if a file type was given.
@ -121,7 +123,7 @@ SimpleForm.setup do |config|
# Custom wrappers for input types. This should be a hash containing an input
# type as key and the wrapper that will be used for all inputs with specified type.
# config.wrapper_mappings = { :string => :prepend }
# config.wrapper_mappings = { string: :prepend }
# Default priority for time_zone inputs.
# config.time_zone_priority = nil
@ -129,9 +131,6 @@ SimpleForm.setup do |config|
# Default priority for country inputs.
# config.country_priority = nil
# Default size for text inputs.
# config.default_input_size = 50
# When false, do not use translations for labels.
# config.translate_labels = true
@ -140,4 +139,7 @@ SimpleForm.setup do |config|
# Cache SimpleForm inputs discovery
# config.cache_discovery = !Rails.env.development?
# Default class for inputs
# config.input_class = nil
end

View File

@ -1,53 +1,53 @@
# Use this setup block to configure all options available in SimpleForm.
SimpleForm.setup do |config|
config.wrappers :bootstrap, :tag => 'div', :class => 'control-group', :error_class => 'error' do |b|
config.wrappers :bootstrap, tag: 'div', class: 'control-group', error_class: 'error' do |b|
b.use :html5
b.use :placeholder
b.use :label
b.wrapper :tag => 'div', :class => 'controls' do |ba|
b.wrapper tag: 'div', class: 'controls' do |ba|
ba.use :input
ba.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' }
ba.use :hint, :wrap_with => { :tag => 'p', :class => 'help-block' }
ba.use :error, wrap_with: { tag: 'span', class: 'help-inline' }
ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
end
end
config.wrappers :prepend, :tag => 'div', :class => "control-group", :error_class => 'error' do |b|
config.wrappers :prepend, tag: 'div', class: "control-group", error_class: 'error' do |b|
b.use :html5
b.use :placeholder
b.use :label
b.wrapper :tag => 'div', :class => 'controls' do |input|
input.wrapper :tag => 'div', :class => 'input-prepend' do |prepend|
b.wrapper tag: 'div', class: 'controls' do |input|
input.wrapper tag: 'div', class: 'input-prepend' do |prepend|
prepend.use :input
end
input.use :hint, :wrap_with => { :tag => 'span', :class => 'help-block' }
input.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' }
input.use :hint, wrap_with: { tag: 'span', class: 'help-block' }
input.use :error, wrap_with: { tag: 'span', class: 'help-inline' }
end
end
config.wrappers :append, :tag => 'div', :class => "control-group", :error_class => 'error' do |b|
config.wrappers :append, tag: 'div', class: "control-group", error_class: 'error' do |b|
b.use :html5
b.use :placeholder
b.use :label
b.wrapper :tag => 'div', :class => 'controls' do |input|
input.wrapper :tag => 'div', :class => 'input-append' do |append|
b.wrapper tag: 'div', class: 'controls' do |input|
input.wrapper tag: 'div', class: 'input-append' do |append|
append.use :input
end
input.use :hint, :wrap_with => { :tag => 'span', :class => 'help-block' }
input.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' }
input.use :hint, wrap_with: { tag: 'span', class: 'help-block' }
input.use :error, wrap_with: { tag: 'span', class: 'help-inline' }
end
end
# Do not use the label in tables
config.wrappers :intable, :tag => 'div', :class => 'control-group control-group-intable', :error_class => 'error' do |b|
config.wrappers :intable, tag: 'div', class: 'control-group control-group-intable', error_class: 'error' do |b|
b.use :html5
b.use :placeholder
b.wrapper :tag => 'div', :class => 'controls controls-intable' do |ba|
b.wrapper tag: 'div', class: 'controls controls-intable' do |ba|
ba.use :input
ba.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' }
ba.use :hint, :wrap_with => { :tag => 'p', :class => 'help-block' }
ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
ba.use :error, wrap_with: { tag: 'span', class: 'help-inline' }
end
end
# Wrappers for forms and inputs using the Twitter Bootstrap toolkit.
# Check the Bootstrap docs (http://twitter.github.com/bootstrap)
# to learn about the different styles for forms and inputs,

View File

@ -237,7 +237,7 @@ class FoodsoftConfig
}
}
# allow engines to easily add to this
engines = Rails::Engine::Railties.engines.select { |e| e.respond_to?(:default_foodsoft_config) }
engines = Rails::Engine.subclasses.map(&:instance).select { |e| e.respond_to?(:default_foodsoft_config) }
engines.each { |e| e.default_foodsoft_config(cfg) }
cfg
end

View File

@ -4,7 +4,7 @@ class MessagesController < ApplicationController
# Renders the "inbox" action.
def index
@messages = Message.public.page(params[:page]).per(@per_page).order('created_at DESC').includes(:sender)
@messages = Message.pub.page(params[:page]).per(@per_page).order('created_at DESC').includes(:sender)
end
# Creates a new message object.

View File

@ -6,7 +6,7 @@ class Message < ActiveRecord::Base
scope :pending, -> { where(:email_state => 0) }
scope :sent, -> { where(:email_state => 1) }
scope :public, -> { where(:private => false) }
scope :pub, -> { where(:private => false) }
# Values for the email_state attribute: :none, :pending, :sent, :failed
EMAIL_STATE = {

View File

@ -1,7 +1,7 @@
/ insert_after 'erb[silent]:contains("<dashboard_middle_mark>")'
- if FoodsoftMessages.enabled?
- unless Message.public.empty?
- unless Message.pub.empty?
%section#messages
%h2= t '.messages.title'
= render 'messages/messages', messages: Message.public.order('created_at DESC').limit(5), pagination: false
= render 'messages/messages', messages: Message.pub.order('created_at DESC').limit(5), pagination: false
%p= link_to t('.messages.view_all'), messages_path

View File

@ -1,5 +1,5 @@
- if pagination
- if Message.public.count > 20
- if Message.pub.count > 20
= items_per_page
= pagination_links_remote messages

View File

@ -1,3 +1,5 @@
# Generic token verifier with foodcoop scope
# @todo use +Rails.application.message_verifier+ when possible
class TokenVerifier < ActiveSupport::MessageVerifier
def initialize(prefix)

View File

@ -2,15 +2,24 @@ require 'factory_girl'
FactoryGirl.define do
factory :article do
sequence(:name) { |n| Faker::Lorem.words(rand(2..4)).join(' ') + " ##{n}" }
factory :_article do
unit { Faker::Unit.unit }
price { rand(2600) / 100 }
tax { [6, 21].sample }
deposit { rand(10) < 8 ? 0 : [0.0, 0.80, 1.20, 12.00].sample }
unit_quantity { rand(5) < 3 ? 1 : rand(1..20) }
supplier { create :supplier }
article_category { create :article_category }
factory :article do
sequence(:name) { |n| Faker::Lorem.words(rand(2..4)).join(' ') + " ##{n}" }
supplier { create :supplier }
article_category { create :article_category }
end
factory :shared_article, class: SharedArticle do
sequence(:name) { |n| Faker::Lorem.words(rand(2..4)).join(' ') + " s##{n}" }
order_number { Faker::Lorem.characters(rand(1..12)) }
supplier { create :shared_supplier }
end
end
factory :article_category do

View File

@ -7,7 +7,7 @@ FactoryGirl.define do
supplier { create :supplier, article_count: (article_count.nil? ? true : article_count) }
article_ids { supplier.articles.map(&:id) unless supplier.nil? }
ignore do
transient do
article_count true
end

View File

@ -7,7 +7,7 @@ FactoryGirl.define do
phone { Faker::PhoneNumber.phone_number }
address { Faker::Address.street_address }
ignore do
transient do
article_count 0
end
@ -16,6 +16,8 @@ FactoryGirl.define do
article_count = rand(1..99) if article_count == true
create_list :article, article_count, supplier: supplier
end
factory :shared_supplier, class: SharedSupplier
end
end

View File

@ -59,9 +59,8 @@ describe Article do
end
describe 'connected to a shared database', :type => :feature do
let(:shared_supplier) { create(:supplier) }
let(:shared_article) { create :article, supplier: shared_supplier, order_number: Faker::Lorem.characters(rand(1..12)) }
let(:supplier) { create :supplier, shared_supplier_id: shared_supplier.id }
let(:shared_article) { create :shared_article }
let(:supplier) { create :supplier, shared_supplier_id: shared_article.supplier_id }
let(:article) { create :article, supplier: supplier, order_number: shared_article.order_number }
it 'can be found in the shared database' do
@ -85,7 +84,7 @@ describe Article do
end
it 'does not need to synchronise an imported article' do
article = SharedArticle.find(shared_article.id).build_new_article(supplier)
article = shared_article.build_new_article(supplier)
expect(article.shared_article_changed?).to be_falsey
end
@ -93,7 +92,7 @@ describe Article do
shared_article.unit = '1kg'
shared_article.unit_quantity = 1
shared_article.save!
article = SharedArticle.find(shared_article.id).build_new_article(supplier)
article = shared_article.build_new_article(supplier)
article.article_category = create :article_category
article.unit = '200g'
article.shared_updated_on -= 1 # to make update do something

View File

@ -1,29 +1,16 @@
# http://stackoverflow.com/questions/8774227
# http://blog.plataformatec.com.br/2011/12/three-tips-to-improve-the-performance-of-your-test-suite
class ActiveRecord::Base
mattr_accessor :shared_connection
@@shared_connection = nil
def self.connection
@@shared_connection || ConnectionPool::Wrapper.new(:size => 1) { retrieve_connection }
end
end
# Forces all threads to share the same connection. This works on
# Capybara because it starts the web server in a thread.
ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection
ActiveSupport.on_load(:after_initialize) do
# We simulate the shared database by pointing to our own database.
# This allows running tests without additional database setup.
# But take care when designing tests using the shared database.
SharedSupplier.establish_connection Rails.env
SharedArticle.establish_connection Rails.env
SharedSupplier.establish_connection Rails.env.to_sym
SharedArticle.establish_connection Rails.env.to_sym
# hack for different structure of shared database
SharedArticle.class_eval do
belongs_to :supplier, class_name: 'SharedSupplier'
alias_attribute :number, :order_number
alias_attribute :updated_on, :updated_at
def category
ArticleCategory.find(article_category_id).name
ArticleCategory.where(id: article_category_id).first
end
def self.find_by_number(n)
find_by_order_number(n)