Updated router. Temporarly replaced routing filter with rails internal.

This commit is contained in:
benni 2011-05-11 12:21:21 +02:00
parent b71fcdf371
commit eab16e337e
21 changed files with 190 additions and 128 deletions

View file

@ -7,8 +7,7 @@ gem 'mysql'
gem "fastercsv" gem "fastercsv"
gem "prawn", '<=0.6.3' gem "prawn", '<=0.6.3'
gem 'haml', '>=2.0.6' gem 'haml', '>=2.0.6'
#gem 'routing-filter', '0.0.1', :require => 'routing_filter' #gem 'routing-filter'
#gem 'sqlite3-ruby'
group :development do group :development do
gem 'annotate' gem 'annotate'

View file

@ -33,8 +33,8 @@ class Article < ActiveRecord::Base
belongs_to :article_category belongs_to :article_category
has_many :article_prices, :order => "created_at DESC" has_many :article_prices, :order => "created_at DESC"
named_scope :available, :conditions => {:availability => true} scope :available, :conditions => {:availability => true}
named_scope :not_in_stock, :conditions => {:type => nil} scope :not_in_stock, :conditions => {:type => nil}
# Validations # Validations
validates_presence_of :name, :unit, :price, :tax, :deposit, :unit_quantity, :supplier_id, :article_category_id validates_presence_of :name, :unit, :price, :tax, :deposit, :unit_quantity, :supplier_id, :article_category_id

View file

@ -4,7 +4,7 @@ class Delivery < ActiveRecord::Base
has_one :invoice has_one :invoice
has_many :stock_changes, :dependent => :destroy 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 validates_presence_of :supplier_id

View file

@ -12,8 +12,8 @@ class GroupOrder < ActiveRecord::Base
validates_numericality_of :price validates_numericality_of :price
validates_uniqueness_of :ordergroup_id, :scope => :order_id # order groups can only order once per order 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)]} } 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 :finished, lambda { {:conditions => ["order_id IN (?)", Order.finished_not_closed.collect(&:id)]} }
# Updates the "price" attribute. # Updates the "price" attribute.
# Until the order is finished this will be the maximum price or # Until the order is finished this will be the maximum price or

View file

@ -16,7 +16,7 @@ class GroupOrderArticle < ActiveRecord::Base
attr_accessor :ordergroup_id # To create an new GroupOrder if neccessary 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. # Custom attribute setter that accepts decimal numbers using localized decimal separator.
def result=(result) def result=(result)

View file

@ -6,7 +6,7 @@ class Invoice < ActiveRecord::Base
validates_presence_of :supplier_id 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. # Custom attribute setter that accepts decimal numbers using localized decimal separator.
def amount=(amount) def amount=(amount)

View file

@ -4,9 +4,9 @@ class Message < ActiveRecord::Base
serialize :recipients_ids, Array serialize :recipients_ids, Array
attr_accessor :sent_to_all, :group_id, :recipients_nicks attr_accessor :sent_to_all, :group_id, :recipients_nicks
named_scope :pending, :conditions => { :email_state => 0 } scope :pending, :conditions => { :email_state => 0 }
named_scope :sent, :conditions => { :email_state => 1 } scope :sent, :conditions => { :email_state => 1 }
named_scope :public, :conditions => {:private => false} scope :public, :conditions => {:private => false}
# Values for the email_state attribute: :none, :pending, :sent, :failed # Values for the email_state attribute: :none, :pending, :sent, :failed
EMAIL_STATE = { EMAIL_STATE = {

View file

@ -21,11 +21,11 @@ class Order < ActiveRecord::Base
after_update :update_price_of_group_orders after_update :update_price_of_group_orders
# Finders # Finders
named_scope :open, :conditions => {:state => 'open'}, :order => 'ends DESC' scope :open, :conditions => {:state => 'open'}, :order => 'ends DESC'
named_scope :finished, :conditions => "state = 'finished' OR state = 'closed'", :order => 'ends DESC' scope :finished, :conditions => "state = 'finished' OR state = 'closed'", :order => 'ends DESC'
named_scope :finished_not_closed, :conditions => {:state => 'finished'}, :order => 'ends DESC' scope :finished_not_closed, :conditions => {:state => 'finished'}, :order => 'ends DESC'
named_scope :closed, :conditions => {:state => 'closed'}, :order => 'ends DESC' scope :closed, :conditions => {:state => 'closed'}, :order => 'ends DESC'
named_scope :stockit, :conditions => {:supplier_id => 0}, :order => 'ends DESC' scope :stockit, :conditions => {:supplier_id => 0}, :order => 'ends DESC'
def stockit? def stockit?
supplier_id == 0 supplier_id == 0

View file

@ -9,7 +9,7 @@ class OrderArticle < ActiveRecord::Base
validates_presence_of :order_id, :article_id validates_presence_of :order_id, :article_id
validate :article_and_price_exist 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 # This method returns either the ArticlePrice or the Article

View file

@ -15,8 +15,8 @@ class Page < ActiveRecord::Base
before_validation :update_permalink, :on => :update before_validation :update_permalink, :on => :update
after_update :create_redirect after_update :create_redirect
named_scope :non_redirected, :conditions => {:redirect => nil} scope :non_redirected, :conditions => {:redirect => nil}
named_scope :no_parent, :conditions => {:parent_id => nil} scope :no_parent, :conditions => {:parent_id => nil}
def self.permalink(title) def self.permalink(title)
title.gsub(/[\/\.,;@\s]/, "_").gsub(/[\"\']/, "") title.gsub(/[\/\.,;@\s]/, "_").gsub(/[\"\']/, "")

View file

@ -1,7 +1,7 @@
class StockArticle < Article class StockArticle < Article
has_many :stock_changes has_many :stock_changes
named_scope :available, :conditions => "quantity > 0" scope :available, :conditions => "quantity > 0"
before_destroy :check_quantity before_destroy :check_quantity

View file

@ -3,9 +3,9 @@ class Task < ActiveRecord::Base
has_many :users, :through => :assignments has_many :users, :through => :assignments
belongs_to :workgroup belongs_to :workgroup
named_scope :non_group, :conditions => { :workgroup_id => nil, :done => false } scope :non_group, :conditions => { :workgroup_id => nil, :done => false }
named_scope :done, :conditions => {:done => true}, :order => "due_date DESC" 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 :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 # form will send user in string. responsibilities will added later
attr_protected :users attr_protected :users

View file

@ -1,80 +1,145 @@
ActionController::Routing::Routes.draw do |map| Foodsoft::Application.routes.draw do
# Use routing filter to select foodcoop config and datbase # Use routing filter to select foodcoop config and datbase
map.filter 'foodcoop', :file => File.join(RAILS_ROOT, "lib", "foodcoop_filter") # filter :foodcoop
scope '/:foodcoop', :defaults => { :foodcoop => Foodsoft.env } do
# Root path # Root path
map.root :controller => 'home', :action => 'index' root :to => 'home#index'
# User specific ########### 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'
# Wiki match '/login' => 'login#index', :as => 'login'
map.resources :pages, :collection => { :all => :get }, :member => {:version => :get, :revert => :get} match '/logout' => 'login#logout', :as => 'logout'
map.wiki_page "/wiki/:permalink", :controller => 'pages', :action => 'show', :permalink => /[^\s]+/ match '/home/profile' => 'home#profile', :as => 'my_profile'
map.wiki "/wiki", :controller => 'pages', :action => 'show', :permalink => 'Home' match '/home/ordergroup' => 'home#ordergroup', :as => 'my_ordergroup'
# Orders, ordering ############ Wiki
map.resources :orders, :member => { :finish => :post, :add_comment => :post }
map.with_options :controller => "ordering" do |ordering| resources :pages do
ordering.ordering "/ordering", :action => "index" get :all, :on => :collection
ordering.my_orders "/ordering/myOrders", :action => "myOrders" 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 end
match '/ordering/myOrders' => 'ordering#myOrders', :as => 'my_orders'
match '/ordering' => 'ordering#index', :as => 'ordering'
# Foodcoop orga ############ Foodcoop orga
map.resources :invites, :only => [:new, :create]
map.resources :tasks, resources :invites, :only => [:new, :create]
:collection => {:user => :get, :archive => :get, :workgroup => :get}
map.resources :messages, :only => [:index, :show, :new, :create], resources :tasks do
:member => { :reply => :get, :user => :get, :group => :get } collection do
map.namespace :foodcoop do |foodcoop| get :user
foodcoop.root :controller => "users", :action => "index" get :archive
foodcoop.resources :users, :only => [:index] get :workgroup
foodcoop.resources :ordergroups, :only => [:index] end
foodcoop.resources :workgroups, :only => [:index, :edit, :update],
:member => {:memberships => :get}
end end
# Article management resources :messages, :only => [:index, :show, :new, :create] do
map.resources :stock_takings, member do
:collection => {:fill_new_stock_article_form => :get, :add_stock_article => :post} get :reply
map.resources :stock_articles, get :user
:controller => 'stockit', :as => 'stockit', get :group
: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 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 end
# Administration namespace :foodcoop do
map.namespace :admin do |admin| root :to => 'users#index'
admin.root :controller => "base", :action => "index"
admin.resources :users resources :users, :only => [:index]
admin.resources :workgroups, :member => { :memberships => :get }
admin.resources :ordergroups, :member => { :memberships => :get } resources :ordergroups, :only => [:index]
resources :workgroups, :only => [:index, :edit, :update] do
get :memberships, :on => :member
end
end end
# Install the default route as the lowest priority. ########### Article management
map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format' 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
end end

View file

@ -1,7 +1,5 @@
require 'routing_filter/base'
module RoutingFilter module RoutingFilter
class Foodcoop < Base class Foodcoop < Filter
def around_recognize(path, env, &block) def around_recognize(path, env, &block)
token = extract_token!(path) # remove the token from the beginning of the path 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) yield.tap do |params| # invoke the given block (calls more filters and finally routing)

View file

@ -62,7 +62,7 @@ module Caboose #:nodoc:
# alias_method :calculate_with_deleted, :calculate # alias_method :calculate_with_deleted, :calculate
alias_method :delete_all!, :delete_all alias_method :delete_all!, :delete_all
end end
send :named_scope, :without_deleted, :conditions => {:deleted_at => nil} send :scope, :without_deleted, :conditions => {:deleted_at => nil}
end end
include InstanceMethods include InstanceMethods
end end

View file

@ -83,10 +83,10 @@ class ApplicationCheckerTest < ActiveSupport::TestCase
end end
def test_named_scope_left_over 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 @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 end
def test_check_routes def test_check_routes

View file

@ -51,7 +51,7 @@
== 2.2.1, released 2008-04-08 == 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 requires ActiveRecord::VERSION
* use strings in "respond_to?" calls to work around a bug in acts_as_ferret * use strings in "respond_to?" calls to work around a bug in acts_as_ferret
stable (ugh) stable (ugh)
@ -79,8 +79,8 @@
=== Other === Other
* Add ability to opt-in for Rails 2.1 feature "named_scope" by calling * Add ability to opt-in for Rails 2.1 feature "scope" by calling
WillPaginate.enable_named_scope (tested in Rails 1.2.6 and 2.0.2) WillPaginate.enable_scope (tested in Rails 1.2.6 and 2.0.2)
* Support complex page parameters like "developers[page]" * Support complex page parameters like "developers[page]"
* Move Array#paginate definition to will_paginate/array.rb. You can now easily * Move Array#paginate definition to will_paginate/array.rb. You can now easily
use pagination on arrays outside of Rails: use pagination on arrays outside of Rails:

View file

@ -16,7 +16,7 @@ desc 'Generate RDoc documentation for the will_paginate plugin.'
Rake::RDocTask.new(:rdoc) do |rdoc| Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_files.include('README.rdoc', 'LICENSE', 'CHANGELOG.rdoc'). rdoc.rdoc_files.include('README.rdoc', 'LICENSE', 'CHANGELOG.rdoc').
include('lib/**/*.rb'). include('lib/**/*.rb').
exclude('lib/will_paginate/named_scope*'). exclude('lib/will_paginate/scope*').
exclude('lib/will_paginate/array.rb'). exclude('lib/will_paginate/array.rb').
exclude('lib/will_paginate/version.rb') exclude('lib/will_paginate/version.rb')

View file

@ -46,18 +46,18 @@ module WillPaginate
end end
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). # (tested on Rails 2.0.2 and 1.2.6).
# #
# You can pass +false+ for +patch+ parameter to skip monkeypatching # You can pass +false+ for +patch+ parameter to skip monkeypatching
# *associations*. Use this if you feel that <tt>named_scope</tt> broke # *associations*. Use this if you feel that <tt>scope</tt> broke
# has_many, has_many :through or has_and_belongs_to_many associations in # has_many, has_many :through or has_and_belongs_to_many associations in
# your app. By passing +false+, you can still use <tt>named_scope</tt> in # your app. By passing +false+, you can still use <tt>scope</tt> in
# your models, but not through associations. # your models, but not through associations.
def enable_named_scope(patch = true) def enable_scope(patch = true)
return if defined? ActiveRecord::NamedScope return if defined? ActiveRecord::NamedScope
require 'will_paginate/named_scope' require 'will_paginate/scope'
require 'will_paginate/named_scope_patch' if patch require 'will_paginate/scope_patch' if patch
ActiveRecord::Base.send :include, WillPaginate::NamedScope ActiveRecord::Base.send :include, WillPaginate::NamedScope
end end

View file

@ -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 module WillPaginate
# This is a feature backported from Rails 2.1 because of its usefullness not only with will_paginate, # 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. # but in other aspects when managing complex conditions that you want to be reusable.
module NamedScope module NamedScope
# All subclasses of ActiveRecord::Base have two named_scopes: # All subclasses of ActiveRecord::Base have two scopes:
# * <tt>all</tt>, which is similar to a <tt>find(:all)</tt> query, and # * <tt>all</tt>, which is similar to a <tt>find(:all)</tt> query, and
# * <tt>scoped</tt>, which allows for the creation of anonymous scopes, on the fly: # * <tt>scoped</tt>, which allows for the creation of anonymous scopes, on the fly:
# #
@ -15,8 +15,8 @@ module WillPaginate
def self.included(base) def self.included(base)
base.class_eval do base.class_eval do
extend ClassMethods extend ClassMethods
named_scope :all scope :all
named_scope :scoped, lambda { |scope| scope } scope :scoped, lambda { |scope| scope }
end end
end end
@ -29,11 +29,11 @@ module WillPaginate
# such as <tt>:conditions => {:color => :red}, :select => 'shirts.*', :include => :washing_instructions</tt>. # such as <tt>:conditions => {:color => :red}, :select => 'shirts.*', :include => :washing_instructions</tt>.
# #
# class Shirt < ActiveRecord::Base # class Shirt < ActiveRecord::Base
# named_scope :red, :conditions => {:color => 'red'} # scope :red, :conditions => {:color => 'red'}
# named_scope :dry_clean_only, :joins => :washing_instructions, :conditions => ['washing_instructions.dry_clean_only = ?', true] # scope :dry_clean_only, :joins => :washing_instructions, :conditions => ['washing_instructions.dry_clean_only = ?', true]
# end # end
# #
# The above calls to <tt>named_scope</tt> define class methods <tt>Shirt.red</tt> and <tt>Shirt.dry_clean_only</tt>. <tt>Shirt.red</tt>, # The above calls to <tt>scope</tt> define class methods <tt>Shirt.red</tt> and <tt>Shirt.dry_clean_only</tt>. <tt>Shirt.red</tt>,
# in effect, represents the query <tt>Shirt.find(:all, :conditions => {:color => 'red'})</tt>. # in effect, represents the query <tt>Shirt.find(:all, :conditions => {:color => 'red'})</tt>.
# #
# Unlike Shirt.find(...), however, the object returned by <tt>Shirt.red</tt> is not an Array; it resembles the association object # Unlike Shirt.find(...), however, the object returned by <tt>Shirt.red</tt> is not an Array; it resembles the association object
@ -59,7 +59,7 @@ module WillPaginate
# Named scopes can also be procedural. # Named scopes can also be procedural.
# #
# class Shirt < ActiveRecord::Base # class Shirt < ActiveRecord::Base
# named_scope :colored, lambda { |color| # scope :colored, lambda { |color|
# { :conditions => { :color => color } } # { :conditions => { :color => color } }
# } # }
# end # end
@ -69,14 +69,14 @@ module WillPaginate
# Named scopes can also have extensions, just as with <tt>has_many</tt> declarations: # Named scopes can also have extensions, just as with <tt>has_many</tt> declarations:
# #
# class Shirt < ActiveRecord::Base # class Shirt < ActiveRecord::Base
# named_scope :red, :conditions => {:color => 'red'} do # scope :red, :conditions => {:color => 'red'} do
# def dom_id # def dom_id
# 'red_shirts' # 'red_shirts'
# end # end
# end # end
# end # end
# #
def named_scope(name, options = {}, &block) def scope(name, options = {}, &block)
scopes[name] = lambda do |parent_scope, *args| scopes[name] = lambda do |parent_scope, *args|
Scope.new(parent_scope, case options Scope.new(parent_scope, case options
when Hash when Hash

View file

@ -3,7 +3,7 @@ require 'lib/activerecord_test_case'
require 'will_paginate' require 'will_paginate'
WillPaginate.enable_activerecord WillPaginate.enable_activerecord
WillPaginate.enable_named_scope WillPaginate.enable_scope
class FinderTest < ActiveRecordTestCase class FinderTest < ActiveRecordTestCase
fixtures :topics, :replies, :users, :projects, :developers_projects fixtures :topics, :replies, :users, :projects, :developers_projects
@ -221,16 +221,16 @@ class FinderTest < ActiveRecordTestCase
assert_equal 2, entries.total_entries assert_equal 2, entries.total_entries
end end
## named_scope ## ## scope ##
def test_paginate_in_named_scope def test_paginate_in_scope
entries = Developer.poor.paginate :page => 1, :per_page => 1 entries = Developer.poor.paginate :page => 1, :per_page => 1
assert_equal 1, entries.size assert_equal 1, entries.size
assert_equal 2, entries.total_entries assert_equal 2, entries.total_entries
end end
def test_paginate_in_named_scope_on_habtm_association def test_paginate_in_scope_on_habtm_association
project = projects(:active_record) project = projects(:active_record)
assert_queries(2) do assert_queries(2) do
entries = project.developers.poor.paginate :page => 1, :per_page => 1 entries = project.developers.poor.paginate :page => 1, :per_page => 1
@ -240,7 +240,7 @@ class FinderTest < ActiveRecordTestCase
end end
end end
def test_paginate_in_named_scope_on_hmt_association def test_paginate_in_scope_on_hmt_association
project = projects(:active_record) project = projects(:active_record)
expected = [replies(:brave)] expected = [replies(:brave)]
@ -251,7 +251,7 @@ class FinderTest < ActiveRecordTestCase
end end
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) project = projects(:active_record)
expected = [topics(:ar)] expected = [topics(:ar)]