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 "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'

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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)

View file

@ -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)

View file

@ -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 = {

View file

@ -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

View file

@ -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

View file

@ -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(/[\"\']/, "")

View file

@ -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

View file

@ -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

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
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

View file

@ -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)

View file

@ -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

View file

@ -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

View file

@ -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:

View file

@ -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')

View file

@ -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 <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
# 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.
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

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
# 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:
# * <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:
#
@ -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 <tt>:conditions => {:color => :red}, :select => 'shirts.*', :include => :washing_instructions</tt>.
#
# 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 <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>.
#
# 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.
#
# 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 <tt>has_many</tt> 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

View file

@ -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)]