diff --git a/Gemfile b/Gemfile index 1aebc62f..50a0ced6 100644 --- a/Gemfile +++ b/Gemfile @@ -7,8 +7,7 @@ gem 'mysql' gem "fastercsv" gem "prawn", '<=0.6.3' gem 'haml', '>=2.0.6' -#gem 'routing-filter', '0.0.1', :require => 'routing_filter' -#gem 'sqlite3-ruby' +#gem 'routing-filter' group :development do gem 'annotate' diff --git a/app/models/article.rb b/app/models/article.rb index dcec5a09..43d2d1d9 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -33,8 +33,8 @@ class Article < ActiveRecord::Base belongs_to :article_category has_many :article_prices, :order => "created_at DESC" - named_scope :available, :conditions => {:availability => true} - named_scope :not_in_stock, :conditions => {:type => nil} + scope :available, :conditions => {:availability => true} + scope :not_in_stock, :conditions => {:type => nil} # Validations validates_presence_of :name, :unit, :price, :tax, :deposit, :unit_quantity, :supplier_id, :article_category_id diff --git a/app/models/delivery.rb b/app/models/delivery.rb index da0a0d8d..62510326 100644 --- a/app/models/delivery.rb +++ b/app/models/delivery.rb @@ -4,7 +4,7 @@ class Delivery < ActiveRecord::Base has_one :invoice has_many :stock_changes, :dependent => :destroy - named_scope :recent, :order => 'created_at DESC', :limit => 10 + scope :recent, :order => 'created_at DESC', :limit => 10 validates_presence_of :supplier_id diff --git a/app/models/group_order.rb b/app/models/group_order.rb index 9a0a7ad6..90b4ede8 100644 --- a/app/models/group_order.rb +++ b/app/models/group_order.rb @@ -12,8 +12,8 @@ class GroupOrder < ActiveRecord::Base validates_numericality_of :price validates_uniqueness_of :ordergroup_id, :scope => :order_id # order groups can only order once per order - named_scope :open, lambda { {:conditions => ["order_id IN (?)", Order.open.collect(&:id)]} } - named_scope :finished, lambda { {:conditions => ["order_id IN (?)", Order.finished_not_closed.collect(&:id)]} } + scope :open, lambda { {:conditions => ["order_id IN (?)", Order.open.collect(&:id)]} } + scope :finished, lambda { {:conditions => ["order_id IN (?)", Order.finished_not_closed.collect(&:id)]} } # Updates the "price" attribute. # Until the order is finished this will be the maximum price or diff --git a/app/models/group_order_article.rb b/app/models/group_order_article.rb index 9612917e..9f680551 100644 --- a/app/models/group_order_article.rb +++ b/app/models/group_order_article.rb @@ -16,7 +16,7 @@ class GroupOrderArticle < ActiveRecord::Base attr_accessor :ordergroup_id # To create an new GroupOrder if neccessary - named_scope :ordered, :conditions => 'result > 0' + scope :ordered, :conditions => 'result > 0' # Custom attribute setter that accepts decimal numbers using localized decimal separator. def result=(result) diff --git a/app/models/invoice.rb b/app/models/invoice.rb index b65305e5..7dd467f6 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -6,7 +6,7 @@ class Invoice < ActiveRecord::Base validates_presence_of :supplier_id - named_scope :unpaid, :conditions => { :paid_on => nil } + scope :unpaid, :conditions => { :paid_on => nil } # Custom attribute setter that accepts decimal numbers using localized decimal separator. def amount=(amount) diff --git a/app/models/message.rb b/app/models/message.rb index ccfd9768..165bc73b 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, :recipients_nicks - named_scope :pending, :conditions => { :email_state => 0 } - named_scope :sent, :conditions => { :email_state => 1 } - named_scope :public, :conditions => {:private => false} + scope :pending, :conditions => { :email_state => 0 } + scope :sent, :conditions => { :email_state => 1 } + scope :public, :conditions => {: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 f154501f..eaf20ea9 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -21,11 +21,11 @@ class Order < ActiveRecord::Base after_update :update_price_of_group_orders # Finders - named_scope :open, :conditions => {:state => 'open'}, :order => 'ends DESC' - named_scope :finished, :conditions => "state = 'finished' OR state = 'closed'", :order => 'ends DESC' - named_scope :finished_not_closed, :conditions => {:state => 'finished'}, :order => 'ends DESC' - named_scope :closed, :conditions => {:state => 'closed'}, :order => 'ends DESC' - named_scope :stockit, :conditions => {:supplier_id => 0}, :order => 'ends DESC' + scope :open, :conditions => {:state => 'open'}, :order => 'ends DESC' + scope :finished, :conditions => "state = 'finished' OR state = 'closed'", :order => 'ends DESC' + scope :finished_not_closed, :conditions => {:state => 'finished'}, :order => 'ends DESC' + scope :closed, :conditions => {:state => 'closed'}, :order => 'ends DESC' + scope :stockit, :conditions => {:supplier_id => 0}, :order => 'ends DESC' def stockit? supplier_id == 0 diff --git a/app/models/order_article.rb b/app/models/order_article.rb index 1c32b2c0..8fbe6b3a 100644 --- a/app/models/order_article.rb +++ b/app/models/order_article.rb @@ -9,7 +9,7 @@ class OrderArticle < ActiveRecord::Base validates_presence_of :order_id, :article_id validate :article_and_price_exist - named_scope :ordered, :conditions => "units_to_order >= 1" + scope :ordered, :conditions => "units_to_order >= 1" # This method returns either the ArticlePrice or the Article diff --git a/app/models/page.rb b/app/models/page.rb index 3ab33612..fba8cde9 100644 --- a/app/models/page.rb +++ b/app/models/page.rb @@ -15,8 +15,8 @@ class Page < ActiveRecord::Base before_validation :update_permalink, :on => :update after_update :create_redirect - named_scope :non_redirected, :conditions => {:redirect => nil} - named_scope :no_parent, :conditions => {:parent_id => nil} + scope :non_redirected, :conditions => {:redirect => nil} + scope :no_parent, :conditions => {:parent_id => nil} def self.permalink(title) title.gsub(/[\/\.,;@\s]/, "_").gsub(/[\"\']/, "") diff --git a/app/models/stock_article.rb b/app/models/stock_article.rb index 7e2924c0..ce091bed 100644 --- a/app/models/stock_article.rb +++ b/app/models/stock_article.rb @@ -1,7 +1,7 @@ class StockArticle < Article has_many :stock_changes - named_scope :available, :conditions => "quantity > 0" + scope :available, :conditions => "quantity > 0" before_destroy :check_quantity diff --git a/app/models/task.rb b/app/models/task.rb index 5b2c91c9..d1a70c6c 100644 --- a/app/models/task.rb +++ b/app/models/task.rb @@ -3,9 +3,9 @@ class Task < ActiveRecord::Base has_many :users, :through => :assignments belongs_to :workgroup - named_scope :non_group, :conditions => { :workgroup_id => nil, :done => false } - named_scope :done, :conditions => {:done => true}, :order => "due_date DESC" - named_scope :upcoming, lambda { |*args| {:conditions => ["done = 0 AND due_date = ?", (args.first || 7.days.from_now)]} } + scope :non_group, :conditions => { :workgroup_id => nil, :done => false } + scope :done, :conditions => {:done => true}, :order => "due_date DESC" + scope :upcoming, lambda { |*args| {:conditions => ["done = 0 AND due_date = ?", (args.first || 7.days.from_now)]} } # form will send user in string. responsibilities will added later attr_protected :users diff --git a/config/routes.rb b/config/routes.rb index 3c70774f..270f48e0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,80 +1,145 @@ -ActionController::Routing::Routes.draw do |map| +Foodsoft::Application.routes.draw do # Use routing filter to select foodcoop config and datbase - map.filter 'foodcoop', :file => File.join(RAILS_ROOT, "lib", "foodcoop_filter") +# filter :foodcoop - # Root path - map.root :controller => 'home', :action => 'index' + scope '/:foodcoop', :defaults => { :foodcoop => Foodsoft.env } do - # User specific - map.login "/login", :controller => 'login', :action => 'index' - map.logout '/logout', :controller => 'login', :action => 'logout' - map.my_profile '/home/profile', :controller => 'home', :action => 'profile' - map.my_ordergroup '/home/ordergroup', :controller => 'home', :action => 'ordergroup' + # Root path + root :to => 'home#index' - # Wiki - map.resources :pages, :collection => { :all => :get }, :member => {:version => :get, :revert => :get} - map.wiki_page "/wiki/:permalink", :controller => 'pages', :action => 'show', :permalink => /[^\s]+/ - map.wiki "/wiki", :controller => 'pages', :action => 'show', :permalink => 'Home' + ########### User specific - # Orders, ordering - map.resources :orders, :member => { :finish => :post, :add_comment => :post } - map.with_options :controller => "ordering" do |ordering| - ordering.ordering "/ordering", :action => "index" - ordering.my_orders "/ordering/myOrders", :action => "myOrders" + match '/login' => 'login#index', :as => 'login' + match '/logout' => 'login#logout', :as => 'logout' + match '/home/profile' => 'home#profile', :as => 'my_profile' + match '/home/ordergroup' => 'home#ordergroup', :as => 'my_ordergroup' + + ############ Wiki + + resources :pages do + get :all, :on => :collection + get :version, :on => :member + get :revert, :on => :member + end + match '/wiki/:permalink' => 'pages#show', :constraints => {:permalink => /[^\s]+/}, :as => 'wiki_page' + match '/wiki' => 'pages#show', :defaults => {:permalink => 'Home'}, :as => 'wiki' + + ############ Orders, ordering + + resources :orders do + member do + post :finish + post :add_comment + end + end + + match '/ordering/myOrders' => 'ordering#myOrders', :as => 'my_orders' + match '/ordering' => 'ordering#index', :as => 'ordering' + + ############ Foodcoop orga + + resources :invites, :only => [:new, :create] + + resources :tasks do + collection do + get :user + get :archive + get :workgroup + end + end + + resources :messages, :only => [:index, :show, :new, :create] do + member do + get :reply + get :user + get :group + end + end + + namespace :foodcoop do + root :to => 'users#index' + + resources :users, :only => [:index] + + resources :ordergroups, :only => [:index] + + resources :workgroups, :only => [:index, :edit, :update] do + get :memberships, :on => :member + end + end + + ########### Article management + + resources :stock_takings do + collection do + get :fill_new_stock_article_form + post :add_stock_article + end + end + + resources :stock_articles, :to => 'stockit', :as => 'stockit' do + collection do + get :auto_complete_for_article_name + get :fill_new_stock_article_form + end + end + + resources :suppliers do + get :shared_suppliers, :on => :collection + + resources :deliveries do + post :drop_stock_change, :on => :member + post :add_stock_article, :on => :collection + end + + resources :articles do + collection do + post :update_selected + get :edit_all + post :update_all + get :upload + post :parse_upload + post :create_from_upload + get :shared + get :import + post :sync + end + end + + resources :article_categories + + ########### Finance + + namespace :finance do + root :to => 'balancing#index' + match 'balancing/list' => 'balancing#list', :as => 'balancing' + + resources :invoices + + resources :transactions do + collection do + get :new_collection + post :create_collection + end + end + end + + ########### Administration + + namespace :admin do + root :to => 'base#index' + + resources :users + + resources :workgroups do + get :memberships, :on => :member + end + + resources :ordergroups do + get :memberships, :on => :member + end + end + end end - - - # Foodcoop orga - map.resources :invites, :only => [:new, :create] - map.resources :tasks, - :collection => {:user => :get, :archive => :get, :workgroup => :get} - map.resources :messages, :only => [:index, :show, :new, :create], - :member => { :reply => :get, :user => :get, :group => :get } - map.namespace :foodcoop do |foodcoop| - foodcoop.root :controller => "users", :action => "index" - foodcoop.resources :users, :only => [:index] - foodcoop.resources :ordergroups, :only => [:index] - foodcoop.resources :workgroups, :only => [:index, :edit, :update], - :member => {:memberships => :get} - end - - # Article management - map.resources :stock_takings, - :collection => {:fill_new_stock_article_form => :get, :add_stock_article => :post} - map.resources :stock_articles, - :controller => 'stockit', :as => 'stockit', - :collection => {:auto_complete_for_article_name => :get, :fill_new_stock_article_form => :get} - - map.resources :suppliers, - :collection => { :shared_suppliers => :get } do |suppliers| - suppliers.resources :deliveries, - :member => { :drop_stock_change => :post }, - :collection => {:add_stock_article => :post} - suppliers.resources :articles, - :collection => { :update_selected => :post, :edit_all => :get, :update_all => :post, - :upload => :get, :parse_upload => :post, :create_from_upload => :post, - :shared => :get, :import => :get, :sync => :post } - end - map.resources :article_categories - - # Finance - map.namespace :finance do |finance| - finance.root :controller => 'balancing' - finance.balancing "balancing/list", :controller => 'balancing', :action => 'list' - finance.resources :invoices - finance.resources :transactions, :collection => {:new_collection => :get, :create_collection => :post} - end - - # Administration - map.namespace :admin do |admin| - admin.root :controller => "base", :action => "index" - admin.resources :users - admin.resources :workgroups, :member => { :memberships => :get } - admin.resources :ordergroups, :member => { :memberships => :get } - end - - # Install the default route as the lowest priority. - map.connect ':controller/:action/:id' - map.connect ':controller/:action/:id.:format' end diff --git a/lib/foodcoop_filter.rb b/lib/foodcoop.rb similarity index 95% rename from lib/foodcoop_filter.rb rename to lib/foodcoop.rb index 10f81ec2..f4d61c32 100644 --- a/lib/foodcoop_filter.rb +++ b/lib/foodcoop.rb @@ -1,7 +1,5 @@ -require 'routing_filter/base' - module RoutingFilter - class Foodcoop < Base + class Foodcoop < Filter def around_recognize(path, env, &block) token = extract_token!(path) # remove the token from the beginning of the path yield.tap do |params| # invoke the given block (calls more filters and finally routing) diff --git a/vendor/plugins/acts_as_paranoid/lib/caboose/acts/paranoid.rb b/vendor/plugins/acts_as_paranoid/lib/caboose/acts/paranoid.rb index 3ad7ccc8..a417f6b9 100644 --- a/vendor/plugins/acts_as_paranoid/lib/caboose/acts/paranoid.rb +++ b/vendor/plugins/acts_as_paranoid/lib/caboose/acts/paranoid.rb @@ -62,7 +62,7 @@ module Caboose #:nodoc: # alias_method :calculate_with_deleted, :calculate alias_method :delete_all!, :delete_all end - send :named_scope, :without_deleted, :conditions => {:deleted_at => nil} + send :scope, :without_deleted, :conditions => {:deleted_at => nil} end include InstanceMethods end diff --git a/vendor/plugins/rails_upgrade/test/application_checker_test.rb b/vendor/plugins/rails_upgrade/test/application_checker_test.rb index 66b56b7a..f6c6e440 100644 --- a/vendor/plugins/rails_upgrade/test/application_checker_test.rb +++ b/vendor/plugins/rails_upgrade/test/application_checker_test.rb @@ -83,10 +83,10 @@ class ApplicationCheckerTest < ActiveSupport::TestCase end def test_named_scope_left_over - make_file("app/models", "post.rb", "named_scope :failure") + make_file("app/models", "post.rb", "scope :failure") @checker.check_ar_methods - assert @checker.alerts.has_key?("named_scope is now just scope") + assert @checker.alerts.has_key?("scope is now just scope") end def test_check_routes diff --git a/vendor/plugins/will_paginate/CHANGELOG.rdoc b/vendor/plugins/will_paginate/CHANGELOG.rdoc index 741abb1f..ac7bcaf5 100644 --- a/vendor/plugins/will_paginate/CHANGELOG.rdoc +++ b/vendor/plugins/will_paginate/CHANGELOG.rdoc @@ -51,7 +51,7 @@ == 2.2.1, released 2008-04-08 -* take less risky path when monkeypatching named_scope; fix that it no longer +* take less risky path when monkeypatching scope; fix that it no longer requires ActiveRecord::VERSION * use strings in "respond_to?" calls to work around a bug in acts_as_ferret stable (ugh) @@ -79,8 +79,8 @@ === Other -* Add ability to opt-in for Rails 2.1 feature "named_scope" by calling - WillPaginate.enable_named_scope (tested in Rails 1.2.6 and 2.0.2) +* Add ability to opt-in for Rails 2.1 feature "scope" by calling + WillPaginate.enable_scope (tested in Rails 1.2.6 and 2.0.2) * Support complex page parameters like "developers[page]" * Move Array#paginate definition to will_paginate/array.rb. You can now easily use pagination on arrays outside of Rails: diff --git a/vendor/plugins/will_paginate/Rakefile b/vendor/plugins/will_paginate/Rakefile index 253efd09..ffa18abc 100644 --- a/vendor/plugins/will_paginate/Rakefile +++ b/vendor/plugins/will_paginate/Rakefile @@ -16,7 +16,7 @@ desc 'Generate RDoc documentation for the will_paginate plugin.' Rake::RDocTask.new(:rdoc) do |rdoc| rdoc.rdoc_files.include('README.rdoc', 'LICENSE', 'CHANGELOG.rdoc'). include('lib/**/*.rb'). - exclude('lib/will_paginate/named_scope*'). + exclude('lib/will_paginate/scope*'). exclude('lib/will_paginate/array.rb'). exclude('lib/will_paginate/version.rb') diff --git a/vendor/plugins/will_paginate/lib/will_paginate.rb b/vendor/plugins/will_paginate/lib/will_paginate.rb index 1b633f16..07981b34 100644 --- a/vendor/plugins/will_paginate/lib/will_paginate.rb +++ b/vendor/plugins/will_paginate/lib/will_paginate.rb @@ -46,18 +46,18 @@ module WillPaginate end end - # Enable named_scope, a feature of Rails 2.1, even if you have older Rails + # Enable scope, a feature of Rails 2.1, even if you have older Rails # (tested on Rails 2.0.2 and 1.2.6). # # You can pass +false+ for +patch+ parameter to skip monkeypatching - # *associations*. Use this if you feel that named_scope broke + # *associations*. Use this if you feel that scope broke # has_many, has_many :through or has_and_belongs_to_many associations in - # your app. By passing +false+, you can still use named_scope in + # your app. By passing +false+, you can still use scope in # your models, but not through associations. - def enable_named_scope(patch = true) + def enable_scope(patch = true) return if defined? ActiveRecord::NamedScope - require 'will_paginate/named_scope' - require 'will_paginate/named_scope_patch' if patch + require 'will_paginate/scope' + require 'will_paginate/scope_patch' if patch ActiveRecord::Base.send :include, WillPaginate::NamedScope end diff --git a/vendor/plugins/will_paginate/lib/will_paginate/named_scope.rb b/vendor/plugins/will_paginate/lib/will_paginate/named_scope.rb index 6f00cf76..e9945f0f 100644 --- a/vendor/plugins/will_paginate/lib/will_paginate/named_scope.rb +++ b/vendor/plugins/will_paginate/lib/will_paginate/named_scope.rb @@ -1,10 +1,10 @@ -## stolen from: http://dev.rubyonrails.org/browser/trunk/activerecord/lib/active_record/named_scope.rb?rev=9084 +## stolen from: http://dev.rubyonrails.org/browser/trunk/activerecord/lib/active_record/scope.rb?rev=9084 module WillPaginate # This is a feature backported from Rails 2.1 because of its usefullness not only with will_paginate, # but in other aspects when managing complex conditions that you want to be reusable. module NamedScope - # All subclasses of ActiveRecord::Base have two named_scopes: + # All subclasses of ActiveRecord::Base have two scopes: # * all, which is similar to a find(:all) query, and # * scoped, which allows for the creation of anonymous scopes, on the fly: # @@ -15,8 +15,8 @@ module WillPaginate def self.included(base) base.class_eval do extend ClassMethods - named_scope :all - named_scope :scoped, lambda { |scope| scope } + scope :all + scope :scoped, lambda { |scope| scope } end end @@ -29,11 +29,11 @@ module WillPaginate # such as :conditions => {:color => :red}, :select => 'shirts.*', :include => :washing_instructions. # # class Shirt < ActiveRecord::Base - # named_scope :red, :conditions => {:color => 'red'} - # named_scope :dry_clean_only, :joins => :washing_instructions, :conditions => ['washing_instructions.dry_clean_only = ?', true] + # scope :red, :conditions => {:color => 'red'} + # scope :dry_clean_only, :joins => :washing_instructions, :conditions => ['washing_instructions.dry_clean_only = ?', true] # end # - # The above calls to named_scope define class methods Shirt.red and Shirt.dry_clean_only. Shirt.red, + # The above calls to scope define class methods Shirt.red and Shirt.dry_clean_only. Shirt.red, # in effect, represents the query Shirt.find(:all, :conditions => {:color => 'red'}). # # Unlike Shirt.find(...), however, the object returned by Shirt.red is not an Array; it resembles the association object @@ -59,7 +59,7 @@ module WillPaginate # Named scopes can also be procedural. # # class Shirt < ActiveRecord::Base - # named_scope :colored, lambda { |color| + # scope :colored, lambda { |color| # { :conditions => { :color => color } } # } # end @@ -69,14 +69,14 @@ module WillPaginate # Named scopes can also have extensions, just as with has_many declarations: # # class Shirt < ActiveRecord::Base - # named_scope :red, :conditions => {:color => 'red'} do + # scope :red, :conditions => {:color => 'red'} do # def dom_id # 'red_shirts' # end # end # end # - def named_scope(name, options = {}, &block) + def scope(name, options = {}, &block) scopes[name] = lambda do |parent_scope, *args| Scope.new(parent_scope, case options when Hash diff --git a/vendor/plugins/will_paginate/test/finder_test.rb b/vendor/plugins/will_paginate/test/finder_test.rb index 001cf3a7..2945f515 100644 --- a/vendor/plugins/will_paginate/test/finder_test.rb +++ b/vendor/plugins/will_paginate/test/finder_test.rb @@ -3,7 +3,7 @@ require 'lib/activerecord_test_case' require 'will_paginate' WillPaginate.enable_activerecord -WillPaginate.enable_named_scope +WillPaginate.enable_scope class FinderTest < ActiveRecordTestCase fixtures :topics, :replies, :users, :projects, :developers_projects @@ -221,16 +221,16 @@ class FinderTest < ActiveRecordTestCase assert_equal 2, entries.total_entries end - ## named_scope ## + ## scope ## - def test_paginate_in_named_scope + def test_paginate_in_scope entries = Developer.poor.paginate :page => 1, :per_page => 1 assert_equal 1, entries.size assert_equal 2, entries.total_entries end - def test_paginate_in_named_scope_on_habtm_association + def test_paginate_in_scope_on_habtm_association project = projects(:active_record) assert_queries(2) do entries = project.developers.poor.paginate :page => 1, :per_page => 1 @@ -240,7 +240,7 @@ class FinderTest < ActiveRecordTestCase end end - def test_paginate_in_named_scope_on_hmt_association + def test_paginate_in_scope_on_hmt_association project = projects(:active_record) expected = [replies(:brave)] @@ -251,7 +251,7 @@ class FinderTest < ActiveRecordTestCase end end - def test_paginate_in_named_scope_on_has_many_association + def test_paginate_in_scope_on_has_many_association project = projects(:active_record) expected = [topics(:ar)]