Removed acts_as_ordered. Fixed bug in group_orders archive.
This commit is contained in:
parent
eb532babd6
commit
92649d3053
23 changed files with 3 additions and 822 deletions
|
@ -58,8 +58,8 @@ class GroupOrdersController < ApplicationController
|
||||||
:conditions => { :state => 'closed' }, :order => "orders.ends DESC"
|
:conditions => { :state => 'closed' }, :order => "orders.ends DESC"
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html # myOrders.haml
|
format.html # archive.html.haml
|
||||||
format.js { render :partial => "orders", :locals => {:orders => @closed_orders, :pagination => true} }
|
format.js # archive.js.erb
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
#
|
#
|
||||||
class Order < ActiveRecord::Base
|
class Order < ActiveRecord::Base
|
||||||
extend ActiveSupport::Memoizable # Ability to cache method results. Use memoize :expensive_method
|
extend ActiveSupport::Memoizable # Ability to cache method results. Use memoize :expensive_method
|
||||||
acts_as_ordered :order => "ends" # easyier find of next or previous model
|
|
||||||
|
|
||||||
# Associations
|
# Associations
|
||||||
has_many :order_articles, :dependent => :destroy
|
has_many :order_articles, :dependent => :destroy
|
||||||
|
|
1
app/views/group_orders/archive.js.erb
Normal file
1
app/views/group_orders/archive.js.erb
Normal file
|
@ -0,0 +1 @@
|
||||||
|
$('#closed_orders').html('<%= escape_javascript(render("orders", orders: @closed_orders, pagination: true)) %>');
|
|
@ -1,10 +1,4 @@
|
||||||
- title "Bestellung: #{@order.name}"
|
- title "Bestellung: #{@order.name}"
|
||||||
#element_navigation
|
|
||||||
= link_to_unless @order.previous == @order, "<< #{@order.previous.name}", @order.previous
|
|
||||||
|
|
|
||||||
= link_to "Übersicht", orders_path
|
|
||||||
|
|
|
||||||
= link_to_unless @order.next == @order, "#{@order.next.name} >>", @order.next
|
|
||||||
|
|
||||||
// Order summary
|
// Order summary
|
||||||
.left_column{:style => "width:65em"}
|
.left_column{:style => "width:65em"}
|
||||||
|
|
27
vendor/plugins/acts_as_ordered/CHANGELOG
vendored
27
vendor/plugins/acts_as_ordered/CHANGELOG
vendored
|
@ -1,27 +0,0 @@
|
||||||
[28 September 2007]
|
|
||||||
|
|
||||||
* Refactoring.
|
|
||||||
|
|
||||||
[29 June 2007]
|
|
||||||
|
|
||||||
* Add :ignore_sti option to allow next and previous to iterate over all models.
|
|
||||||
|
|
||||||
[3 June 2007]
|
|
||||||
|
|
||||||
* Improve STI ordering
|
|
||||||
|
|
||||||
* BACKWARDS INCOMPATIBLE
|
|
||||||
|
|
||||||
To jump more than one record forward or back, pass :number => x to next or previous, not just the number.
|
|
||||||
Number defaults to 1.
|
|
||||||
|
|
||||||
Old: person.next(10)
|
|
||||||
New: person.next(:number => 10)
|
|
||||||
|
|
||||||
This allows options to be passed to the find method when the record is instantiated:
|
|
||||||
|
|
||||||
person.next(:include => :groups)
|
|
||||||
|
|
||||||
[31 Jul 2006]
|
|
||||||
|
|
||||||
* Make the plugin work with Rails 1.1, not just trunk
|
|
20
vendor/plugins/acts_as_ordered/MIT-LICENSE
vendored
20
vendor/plugins/acts_as_ordered/MIT-LICENSE
vendored
|
@ -1,20 +0,0 @@
|
||||||
Copyright (c) 2006 Jonathan Viney
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining
|
|
||||||
a copy of this software and associated documentation files (the
|
|
||||||
"Software"), to deal in the Software without restriction, including
|
|
||||||
without limitation the rights to use, copy, modify, merge, publish,
|
|
||||||
distribute, sublicense, and/or sell copies of the Software, and to
|
|
||||||
permit persons to whom the Software is furnished to do so, subject to
|
|
||||||
the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be
|
|
||||||
included in all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
||||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
||||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
||||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
||||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
||||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
||||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
88
vendor/plugins/acts_as_ordered/README
vendored
88
vendor/plugins/acts_as_ordered/README
vendored
|
@ -1,88 +0,0 @@
|
||||||
= acts_as_ordered
|
|
||||||
|
|
||||||
If you find this plugin useful, please consider a donation to show your support!
|
|
||||||
|
|
||||||
http://www.paypal.com/cgi-bin/webscr?cmd=_send-money
|
|
||||||
|
|
||||||
Email address: jonathan.viney@gmail.com
|
|
||||||
|
|
||||||
== Instructions
|
|
||||||
|
|
||||||
This plugin gives ActiveRecord models an easy way to find their neighbours in a given order.
|
|
||||||
|
|
||||||
== Resources
|
|
||||||
|
|
||||||
Install
|
|
||||||
* script/plugin install http://svn.viney.net.nz/things/rails/plugins/acts_as_ordered
|
|
||||||
|
|
||||||
== Usage
|
|
||||||
|
|
||||||
class Person < ActiveRecord::Base
|
|
||||||
acts_as_ordered :order => 'first_name'
|
|
||||||
end
|
|
||||||
|
|
||||||
Say you have people with first names of Adam, Jonathan and Robert:
|
|
||||||
|
|
||||||
p = Person.find_by_first_name('Jonathan')
|
|
||||||
|
|
||||||
p.next # Robert
|
|
||||||
p.previous # Adam
|
|
||||||
p.previous.previous # Adam (does not wrap around to end)
|
|
||||||
p.next.next # Robert (does not wrap around to start)
|
|
||||||
|
|
||||||
If you want the next and previous methods to wrap around the ends, use:
|
|
||||||
|
|
||||||
acts_as_ordered :order => 'first_name', :wrap => true
|
|
||||||
|
|
||||||
You can also jump by more than one at a time:
|
|
||||||
|
|
||||||
# Without wrapping (clamps to ends)
|
|
||||||
p = Person.find_by_first_name('Jonathan')
|
|
||||||
p.next(:number => 2) # Robert
|
|
||||||
p.next(:number => 100) # Robert
|
|
||||||
p.previous(:number => 100) # Jonathan
|
|
||||||
|
|
||||||
# With wrapping (wraps around ends as many times as you like)
|
|
||||||
p = Person.find_by_first_name('Jonathan')
|
|
||||||
p.next(:number => 8) # Adam
|
|
||||||
p.previous(:number => 17) # Robert
|
|
||||||
|
|
||||||
You can use this to get the next/previous model that matches some condition:
|
|
||||||
|
|
||||||
class Person < ActiveRecord::Base
|
|
||||||
acts_as_ordered :condition => proc { |p| p.age > 10 }
|
|
||||||
|
|
||||||
# Or check that a method on the model returns true
|
|
||||||
acts_as_ordered :conditions => :male?
|
|
||||||
end
|
|
||||||
|
|
||||||
In this case, the next and previous methods will return the closest adjacent object that matches the condition.
|
|
||||||
|
|
||||||
You can use this in a application to be able to quickly browse through people. Eg:
|
|
||||||
|
|
||||||
class PersonController < ApplicationController
|
|
||||||
def view_neighbour
|
|
||||||
# params[:direction] is passed off the page as 'next' or 'previous'
|
|
||||||
@person = Person.find(params[:id]).find_by_direction(params[:direction])
|
|
||||||
render :action => 'view'
|
|
||||||
end
|
|
||||||
|
|
||||||
# Or alternatively...
|
|
||||||
def view_next
|
|
||||||
@person = Person.find(params[:id]).next
|
|
||||||
render :action => 'view'
|
|
||||||
end
|
|
||||||
|
|
||||||
def view_previous
|
|
||||||
@person = Person.find(params[:id]).previous
|
|
||||||
render :action => 'view'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
Problems, comments, and suggestions all welcome. jonathan.viney@gmail.com
|
|
||||||
|
|
||||||
== Credits
|
|
||||||
|
|
||||||
Atelier Fabien - Support for :scope =>
|
|
||||||
Rick Olson - I borrowed some of the testing code from acts_as_versioned
|
|
22
vendor/plugins/acts_as_ordered/Rakefile
vendored
22
vendor/plugins/acts_as_ordered/Rakefile
vendored
|
@ -1,22 +0,0 @@
|
||||||
require 'rake'
|
|
||||||
require 'rake/testtask'
|
|
||||||
require 'rake/rdoctask'
|
|
||||||
|
|
||||||
desc 'Default: run unit tests.'
|
|
||||||
task :default => :test
|
|
||||||
|
|
||||||
desc 'Test the acts_as_ordered plugin.'
|
|
||||||
Rake::TestTask.new(:test) do |t|
|
|
||||||
t.libs << 'lib'
|
|
||||||
t.pattern = 'test/**/*_test.rb'
|
|
||||||
t.verbose = true
|
|
||||||
end
|
|
||||||
|
|
||||||
desc 'Generate documentation for the acts_as_ordered plugin.'
|
|
||||||
Rake::RDocTask.new(:rdoc) do |rdoc|
|
|
||||||
rdoc.rdoc_dir = 'rdoc'
|
|
||||||
rdoc.title = 'Acts As Ordered'
|
|
||||||
rdoc.options << '--line-numbers' << '--inline-source'
|
|
||||||
rdoc.rdoc_files.include('README')
|
|
||||||
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
||||||
end
|
|
1
vendor/plugins/acts_as_ordered/init.rb
vendored
1
vendor/plugins/acts_as_ordered/init.rb
vendored
|
@ -1 +0,0 @@
|
||||||
require 'acts_as_ordered'
|
|
|
@ -1,138 +0,0 @@
|
||||||
module ActiveRecord
|
|
||||||
module Acts
|
|
||||||
module Ordered
|
|
||||||
def self.included(base)
|
|
||||||
base.extend(ClassMethods)
|
|
||||||
end
|
|
||||||
|
|
||||||
class InvalidDirection < Exception
|
|
||||||
end
|
|
||||||
|
|
||||||
module ClassMethods
|
|
||||||
def acts_as_ordered(options = {})
|
|
||||||
options.assert_valid_keys :order, :wrap, :condition, :scope, :ignore_sti
|
|
||||||
|
|
||||||
options[:order] = options[:order] ? "#{options[:order]}, #{primary_key}" : primary_key
|
|
||||||
options[:condition] = options[:condition].to_proc if options[:condition].is_a?(Symbol)
|
|
||||||
options[:scope] = "#{options[:scope]}_id".to_sym if options[:scope].is_a?(Symbol) && options[:scope].to_s !~ /_id$/
|
|
||||||
|
|
||||||
cattr_accessor :_acts_as_ordered_options
|
|
||||||
self._acts_as_ordered_options = options
|
|
||||||
|
|
||||||
include InstanceMethods
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
module InstanceMethods
|
|
||||||
def ordered_scope_condition
|
|
||||||
scope = self.class._acts_as_ordered_options[:scope]
|
|
||||||
|
|
||||||
return if scope.nil?
|
|
||||||
|
|
||||||
if scope.is_a?(Symbol)
|
|
||||||
{ scope => send(scope) }
|
|
||||||
else
|
|
||||||
interpolate_sql(scope)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def adjacent_id(number)
|
|
||||||
ids = ordered_ids
|
|
||||||
ids.reverse! if number < 0
|
|
||||||
index = ids.index(self.id)
|
|
||||||
|
|
||||||
if self.class._acts_as_ordered_options[:wrap]
|
|
||||||
ids[(index + number.abs) % ids.size]
|
|
||||||
else
|
|
||||||
ids[index + number.abs] || ids.last
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def ordered_ids
|
|
||||||
conditions, options = [], self.class._acts_as_ordered_options
|
|
||||||
|
|
||||||
if !options[:ignore_sti] && !self.class.descends_from_active_record?
|
|
||||||
conditions << self.class.send(:type_condition)
|
|
||||||
end
|
|
||||||
|
|
||||||
unless ordered_scope_condition.blank?
|
|
||||||
conditions << self.class.send(:sanitize_sql, ordered_scope_condition)
|
|
||||||
end
|
|
||||||
|
|
||||||
sql_conditions = "WHERE #{conditions.join(') AND (')}" if conditions.any?
|
|
||||||
|
|
||||||
connection.select_values("SELECT #{self.class.primary_key} FROM #{self.class.table_name} #{sql_conditions} ORDER BY #{options[:order]}").map!(&:to_i)
|
|
||||||
end
|
|
||||||
|
|
||||||
def adjacent_record(options = {})
|
|
||||||
previous_record, number, ordered_options = self, options.delete(:number), self.class._acts_as_ordered_options
|
|
||||||
|
|
||||||
loop do
|
|
||||||
adjacent_record = self.class.base_class.find(previous_record.adjacent_id(number), options.dup)
|
|
||||||
matches = ordered_options[:condition] ? ordered_options[:condition].call(adjacent_record) : true
|
|
||||||
|
|
||||||
return adjacent_record if matches
|
|
||||||
return self if adjacent_record == self # If the search for a matching record failed
|
|
||||||
return self if previous_record == adjacent_record # If we've found the same adjacent_record twice
|
|
||||||
|
|
||||||
previous_record = adjacent_record
|
|
||||||
number = number < 0 ? -1 : 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def current_total
|
|
||||||
self.class.base_class.count :conditions => ordered_scope_condition
|
|
||||||
end
|
|
||||||
|
|
||||||
def current_index
|
|
||||||
ordered_ids.index(id)
|
|
||||||
end
|
|
||||||
|
|
||||||
def current_position
|
|
||||||
current_index + 1
|
|
||||||
end
|
|
||||||
|
|
||||||
def next(options = {})
|
|
||||||
adjacent_record(options.reverse_merge(:number => 1))
|
|
||||||
end
|
|
||||||
|
|
||||||
def previous(options = {})
|
|
||||||
options = options.reverse_merge(:number => 1)
|
|
||||||
options[:number] = -options[:number]
|
|
||||||
adjacent_record(options)
|
|
||||||
end
|
|
||||||
|
|
||||||
def find_by_direction(direction, options = {})
|
|
||||||
direction = direction.to_s
|
|
||||||
['next', 'previous'].include?(direction) ? send(direction, options) : raise(InvalidDirection.new(direction))
|
|
||||||
end
|
|
||||||
|
|
||||||
def first?
|
|
||||||
id == first_id
|
|
||||||
end
|
|
||||||
|
|
||||||
def last?
|
|
||||||
id == last_id
|
|
||||||
end
|
|
||||||
|
|
||||||
def first
|
|
||||||
self.class.base_class.find(first_id)
|
|
||||||
end
|
|
||||||
|
|
||||||
def last
|
|
||||||
self.class.base_class.find(last_id)
|
|
||||||
end
|
|
||||||
|
|
||||||
def first_id
|
|
||||||
ordered_ids.first
|
|
||||||
end
|
|
||||||
|
|
||||||
def last_id
|
|
||||||
ordered_ids.last
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
ActiveRecord::Base.send(:include, ActiveRecord::Acts::Ordered)
|
|
|
@ -1,30 +0,0 @@
|
||||||
require 'test/unit'
|
|
||||||
|
|
||||||
begin
|
|
||||||
require File.dirname(__FILE__) + '/../../../../config/environment'
|
|
||||||
rescue LoadError
|
|
||||||
require 'rubygems'
|
|
||||||
gem 'activerecord'
|
|
||||||
require 'active_record'
|
|
||||||
end
|
|
||||||
|
|
||||||
# Search for fixtures first
|
|
||||||
fixture_path = File.dirname(__FILE__) + '/fixtures/'
|
|
||||||
Dependencies.load_paths.insert(0, fixture_path)
|
|
||||||
|
|
||||||
ActiveRecord::Base.configurations = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
|
|
||||||
ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + '/debug.log')
|
|
||||||
ActiveRecord::Base.establish_connection(ENV['DB'] || 'mysql')
|
|
||||||
|
|
||||||
require 'active_record/fixtures'
|
|
||||||
|
|
||||||
require File.dirname(__FILE__) + '/../lib/acts_as_ordered'
|
|
||||||
|
|
||||||
load(File.dirname(__FILE__) + '/schema.rb')
|
|
||||||
|
|
||||||
Test::Unit::TestCase.fixture_path = File.dirname(__FILE__) + '/fixtures/'
|
|
||||||
|
|
||||||
class Test::Unit::TestCase #:nodoc:
|
|
||||||
self.use_transactional_fixtures = true
|
|
||||||
self.use_instantiated_fixtures = false
|
|
||||||
end
|
|
|
@ -1,281 +0,0 @@
|
||||||
require File.join(File.dirname(__FILE__), 'abstract_unit')
|
|
||||||
|
|
||||||
class ActsAsOrderedTest < Test::Unit::TestCase
|
|
||||||
fixtures :cartoons
|
|
||||||
|
|
||||||
def test_normal
|
|
||||||
bugs = cartoons(:bugs)
|
|
||||||
|
|
||||||
assert_equal bugs, bugs.previous
|
|
||||||
assert_equal cartoons(:daffy), bugs.next
|
|
||||||
|
|
||||||
# No wrapping
|
|
||||||
assert_equal cartoons(:roger), bugs.next.next.next.next.next
|
|
||||||
assert_equal bugs, bugs.next.next.next.next.next.next.previous.previous.previous.previous.previous.previous
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_find_by_direction
|
|
||||||
assert_equal cartoons(:bugs), cartoons(:bugs).find_by_direction(:previous)
|
|
||||||
|
|
||||||
assert_equal cartoons(:daffy), cartoons(:bugs).find_by_direction(:next)
|
|
||||||
assert_equal cartoons(:roger), cartoons(:bugs).find_by_direction(:next, :number => 5)
|
|
||||||
|
|
||||||
assert_raises(ActiveRecord::Acts::Ordered::InvalidDirection) { cartoons(:bugs).find_by_direction('destroy') }
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_insert_and_remove
|
|
||||||
bugs, daffy = cartoons(:bugs), cartoons(:daffy)
|
|
||||||
|
|
||||||
assert_equal daffy, bugs.next
|
|
||||||
cat = Cartoon.create(:first_name => 'Cat', :last_name => 'in the Hat')
|
|
||||||
assert_equal cat, bugs.next
|
|
||||||
assert_equal daffy, bugs.next.next
|
|
||||||
|
|
||||||
assert_equal cat, daffy.previous
|
|
||||||
assert cat.destroy
|
|
||||||
assert_equal bugs, daffy.previous
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_desc_order
|
|
||||||
bugs = reversed_cartoons(:bugs)
|
|
||||||
|
|
||||||
assert_equal bugs, bugs.next
|
|
||||||
assert_equal reversed_cartoons(:daffy), bugs.previous
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_with_wrapping
|
|
||||||
elmer = wrapped_cartoons(:elmer)
|
|
||||||
|
|
||||||
assert_equal wrapped_cartoons(:roger), elmer.next
|
|
||||||
assert_equal wrapped_cartoons(:roger), elmer.previous.previous.previous
|
|
||||||
|
|
||||||
assert_equal wrapped_cartoons(:bugs), elmer.next.next
|
|
||||||
assert_equal wrapped_cartoons(:bugs), elmer.previous.previous
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_jump_multiple_no_wrapping
|
|
||||||
daffy = cartoons(:daffy)
|
|
||||||
|
|
||||||
assert_equal cartoons(:roger), daffy.next(:number => 2)
|
|
||||||
assert_equal cartoons(:roger), daffy.next(:number => 100)
|
|
||||||
assert_equal cartoons(:bugs), daffy.previous(:number => 10)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_jump_multiple_with_wrapping
|
|
||||||
roger = wrapped_cartoons(:roger)
|
|
||||||
|
|
||||||
assert_equal roger, roger.previous(:number => 4)
|
|
||||||
assert_equal roger, roger.next(:number => 4)
|
|
||||||
|
|
||||||
assert_equal wrapped_cartoons(:elmer), roger.previous(:number => 9)
|
|
||||||
assert_equal wrapped_cartoons(:bugs), roger.next(:number => 13)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_with_condition
|
|
||||||
elmer = silly_cartoons(:elmer)
|
|
||||||
|
|
||||||
assert_equal silly_cartoons(:roger), elmer.next
|
|
||||||
assert_equal silly_cartoons(:roger), elmer.next(:number => 10)
|
|
||||||
assert_equal silly_cartoons(:elmer), elmer.previous
|
|
||||||
assert_equal silly_cartoons(:elmer), elmer.previous(:number => 3)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_with_condition_and_wrapping
|
|
||||||
bugs = funny_cartoons(:bugs)
|
|
||||||
|
|
||||||
assert_equal funny_cartoons(:daffy), bugs.next
|
|
||||||
assert_equal funny_cartoons(:elmer), bugs.next.next
|
|
||||||
assert_equal funny_cartoons(:bugs), bugs.next.next.next
|
|
||||||
assert_equal funny_cartoons(:bugs), bugs.next(:number => 3)
|
|
||||||
|
|
||||||
assert_equal funny_cartoons(:elmer), bugs.previous
|
|
||||||
assert_equal funny_cartoons(:daffy), bugs.previous(:number => 3)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_current_index_and_position
|
|
||||||
assert_equal 0, cartoons(:bugs).current_index
|
|
||||||
assert_equal 1, cartoons(:bugs).current_position
|
|
||||||
assert_equal 1, cartoons(:daffy).current_index
|
|
||||||
assert_equal 2, cartoons(:daffy).current_position
|
|
||||||
assert_equal 2, cartoons(:bugs).next.current_position
|
|
||||||
assert_equal 4, cartoons(:bugs).last.current_position
|
|
||||||
assert_equal 4, cartoons(:roger).current_position
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_current_total
|
|
||||||
assert_equal 4, cartoons(:bugs).current_total
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
|
||||||
def find_cartoon(name, klass)
|
|
||||||
klass.find(cartoons(name).id)
|
|
||||||
end
|
|
||||||
|
|
||||||
def wrapped_cartoons(name)
|
|
||||||
find_cartoon(name, WrappedCartoon)
|
|
||||||
end
|
|
||||||
|
|
||||||
def reversed_cartoons(name)
|
|
||||||
find_cartoon(name, ReversedCartoon)
|
|
||||||
end
|
|
||||||
|
|
||||||
def funny_cartoons(name)
|
|
||||||
find_cartoon(name, FunnyCartoon)
|
|
||||||
end
|
|
||||||
|
|
||||||
def silly_cartoons(name)
|
|
||||||
find_cartoon(name, SillyCartoon)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
class ActsAsOrderedWithScopeTest < Test::Unit::TestCase
|
|
||||||
fixtures :categories, :projects
|
|
||||||
|
|
||||||
def test_first_and_last_a
|
|
||||||
assert projects(:one).first?
|
|
||||||
assert projects(:three).last?
|
|
||||||
assert_equal 1, projects(:two).first_id
|
|
||||||
assert_equal 3, projects(:two).last_id
|
|
||||||
assert_equal projects(:one), projects(:one).first
|
|
||||||
assert_equal projects(:three), projects(:one).last
|
|
||||||
assert_equal projects(:one), projects(:two).first
|
|
||||||
assert_equal projects(:three), projects(:two).last
|
|
||||||
assert_equal projects(:one), projects(:three).first
|
|
||||||
assert_equal projects(:three), projects(:three).last
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_first_and_last_b
|
|
||||||
assert projects(:four).first?
|
|
||||||
assert projects(:seven).last?
|
|
||||||
assert_equal 4, projects(:five).first_id
|
|
||||||
assert_equal 7, projects(:five).last_id
|
|
||||||
assert_equal projects(:four), projects(:four).first
|
|
||||||
assert_equal projects(:seven), projects(:four).last
|
|
||||||
assert_equal projects(:four), projects(:five).first
|
|
||||||
assert_equal projects(:seven), projects(:five).last
|
|
||||||
assert_equal projects(:four), projects(:six).first
|
|
||||||
assert_equal projects(:seven), projects(:six).last
|
|
||||||
assert_equal projects(:four), projects(:seven).first
|
|
||||||
assert_equal projects(:seven), projects(:seven).last
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_symbol_scope_no_wrapping_a
|
|
||||||
one = projects(:one)
|
|
||||||
assert projects(:one).first?
|
|
||||||
assert projects(:three).last?
|
|
||||||
assert_equal one, one.previous
|
|
||||||
assert_equal one, one.next.previous
|
|
||||||
assert_equal projects(:two), one.next
|
|
||||||
assert_equal projects(:three), projects(:three).next
|
|
||||||
assert_equal projects(:three), one.next.next
|
|
||||||
assert_equal projects(:three), one.next.next.next
|
|
||||||
assert_equal projects(:three), one.next.next.next.next
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_symbol_scope_no_wrapping_b
|
|
||||||
assert projects(:four).first?
|
|
||||||
assert projects(:seven).last?
|
|
||||||
assert_equal projects(:four), projects(:four).previous
|
|
||||||
assert_equal projects(:five), projects(:four).next
|
|
||||||
assert_equal projects(:six), projects(:five).next
|
|
||||||
assert_equal projects(:seven), projects(:six).next
|
|
||||||
assert_equal projects(:seven), projects(:seven).next
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_symbol_scope_and_wrapping_a
|
|
||||||
one = wrapped_projects(:one)
|
|
||||||
assert wrapped_projects(:one).first?
|
|
||||||
assert wrapped_projects(:three).last?
|
|
||||||
assert_equal wrapped_projects(:three), one.previous
|
|
||||||
assert_equal wrapped_projects(:one), wrapped_projects(:one).next.previous
|
|
||||||
assert_equal wrapped_projects(:two), wrapped_projects(:one).next
|
|
||||||
assert_equal wrapped_projects(:three), wrapped_projects(:two).next
|
|
||||||
assert_equal wrapped_projects(:three), wrapped_projects(:one).next.next
|
|
||||||
assert_equal wrapped_projects(:one), wrapped_projects(:three).next
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_symbol_scope_and_wrapping_b
|
|
||||||
assert wrapped_projects(:four).first?
|
|
||||||
assert wrapped_projects(:seven).last?
|
|
||||||
assert_equal wrapped_projects(:seven), wrapped_projects(:four).previous
|
|
||||||
assert_equal wrapped_projects(:five), wrapped_projects(:four).next
|
|
||||||
assert_equal wrapped_projects(:six), wrapped_projects(:five).next
|
|
||||||
assert_equal wrapped_projects(:seven), wrapped_projects(:six).next
|
|
||||||
assert_equal wrapped_projects(:four), wrapped_projects(:seven).next
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_sql_scope_no_wrapping
|
|
||||||
one = sql_scoped_projects(:one)
|
|
||||||
assert sql_scoped_projects(:one).first?
|
|
||||||
assert sql_scoped_projects(:three).last?
|
|
||||||
assert_equal one, one.previous
|
|
||||||
assert_equal one, one.next.previous
|
|
||||||
assert_equal sql_scoped_projects(:two), one.next
|
|
||||||
assert_equal sql_scoped_projects(:three), sql_scoped_projects(:three).next
|
|
||||||
assert_equal sql_scoped_projects(:three), one.next.next
|
|
||||||
assert_equal sql_scoped_projects(:three), one.next.next.next
|
|
||||||
assert_equal sql_scoped_projects(:three), one.next.next.next.next
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_sql_scope_and_wrapping
|
|
||||||
one = wrapped_sql_scoped_projects(:one)
|
|
||||||
assert wrapped_sql_scoped_projects(:one).first?
|
|
||||||
assert wrapped_sql_scoped_projects(:three).last?
|
|
||||||
assert_equal wrapped_sql_scoped_projects(:three), one.previous
|
|
||||||
assert_equal wrapped_sql_scoped_projects(:one), wrapped_sql_scoped_projects(:one).next.previous
|
|
||||||
assert_equal wrapped_sql_scoped_projects(:two), wrapped_sql_scoped_projects(:one).next
|
|
||||||
assert_equal wrapped_sql_scoped_projects(:three), wrapped_sql_scoped_projects(:two).next
|
|
||||||
assert_equal wrapped_sql_scoped_projects(:three), wrapped_sql_scoped_projects(:one).next.next
|
|
||||||
assert_equal wrapped_sql_scoped_projects(:one), wrapped_sql_scoped_projects(:three).next
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_current_total
|
|
||||||
assert_equal 3, projects(:one).current_total
|
|
||||||
assert_equal 4, projects(:four).current_total
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_with_options
|
|
||||||
project = wrapped_projects(:one).next(:include => :category)
|
|
||||||
assert project.instance_variable_get('@category')
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
|
||||||
def find_project(name, klass)
|
|
||||||
klass.find(projects(name).id)
|
|
||||||
end
|
|
||||||
|
|
||||||
def wrapped_projects(name)
|
|
||||||
find_project(name, WrappedProject)
|
|
||||||
end
|
|
||||||
|
|
||||||
def sql_scoped_projects(name)
|
|
||||||
find_project(name, SQLScopedProject)
|
|
||||||
end
|
|
||||||
|
|
||||||
def wrapped_sql_scoped_projects(name)
|
|
||||||
find_project(name, WrappedSQLScopedProject)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
class ActsAsOrderedStiTest < Test::Unit::TestCase
|
|
||||||
fixtures :documents
|
|
||||||
|
|
||||||
def test_subclasses
|
|
||||||
assert_equal documents(:entry_2), documents(:entry_1).next
|
|
||||||
assert_equal documents(:entry_3), documents(:entry_2).next
|
|
||||||
assert_equal documents(:entry_2), documents(:entry_3).previous
|
|
||||||
assert_equal documents(:entry_1), documents(:entry_2).previous
|
|
||||||
|
|
||||||
assert_equal documents(:page_2), documents(:page_1).next
|
|
||||||
assert_equal documents(:page_1), documents(:page_2).previous
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_subclasses_without_sti_scoping
|
|
||||||
Document._acts_as_ordered_options[:ignore_sti] = true
|
|
||||||
|
|
||||||
assert_equal documents(:page_1), documents(:entry_2).next
|
|
||||||
assert_equal documents(:page_2), documents(:document_2).previous
|
|
||||||
ensure
|
|
||||||
Document._acts_as_ordered_options.delete(:ignore_sti)
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,6 +0,0 @@
|
||||||
mysql:
|
|
||||||
:adapter: mysql
|
|
||||||
:host: localhost
|
|
||||||
:username: rails
|
|
||||||
:password:
|
|
||||||
:database: rails_plugin_test
|
|
|
@ -1,27 +0,0 @@
|
||||||
class Cartoon < ActiveRecord::Base
|
|
||||||
acts_as_ordered :order => 'first_name'
|
|
||||||
end
|
|
||||||
|
|
||||||
class ReversedCartoon < ActiveRecord::Base
|
|
||||||
set_table_name :cartoons
|
|
||||||
acts_as_ordered :order => 'last_name desc'
|
|
||||||
end
|
|
||||||
|
|
||||||
class WrappedCartoon < ActiveRecord::Base
|
|
||||||
set_table_name :cartoons
|
|
||||||
acts_as_ordered :order => 'last_name', :wrap => true
|
|
||||||
end
|
|
||||||
|
|
||||||
class SillyCartoon < ActiveRecord::Base
|
|
||||||
set_table_name :cartoons
|
|
||||||
acts_as_ordered :condition => Proc.new { |c| c.first_name =~ /e/i }
|
|
||||||
end
|
|
||||||
|
|
||||||
class FunnyCartoon < ActiveRecord::Base
|
|
||||||
set_table_name :cartoons
|
|
||||||
acts_as_ordered :condition => Proc.new { |r| r.last_name_contains_u? }, :wrap => true
|
|
||||||
|
|
||||||
def last_name_contains_u?
|
|
||||||
last_name =~ /u/
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,19 +0,0 @@
|
||||||
bugs:
|
|
||||||
id: 1
|
|
||||||
first_name: Bugs
|
|
||||||
last_name: Bunny
|
|
||||||
|
|
||||||
daffy:
|
|
||||||
id: 2
|
|
||||||
first_name: Daffy
|
|
||||||
last_name: Duck
|
|
||||||
|
|
||||||
elmer:
|
|
||||||
id: 3
|
|
||||||
first_name: Elmer
|
|
||||||
last_name: Fudd
|
|
||||||
|
|
||||||
roger:
|
|
||||||
id: 4
|
|
||||||
first_name: Roger
|
|
||||||
last_name: Rabbit
|
|
|
@ -1,7 +0,0 @@
|
||||||
programming:
|
|
||||||
id: 1
|
|
||||||
name: Programming
|
|
||||||
|
|
||||||
design:
|
|
||||||
id: 2
|
|
||||||
name: Design
|
|
|
@ -1,3 +0,0 @@
|
||||||
class Category < ActiveRecord::Base
|
|
||||||
has_many :projects
|
|
||||||
end
|
|
|
@ -1,9 +0,0 @@
|
||||||
class Document < ActiveRecord::Base
|
|
||||||
acts_as_ordered
|
|
||||||
end
|
|
||||||
|
|
||||||
class Entry < Document
|
|
||||||
end
|
|
||||||
|
|
||||||
class Page < Document
|
|
||||||
end
|
|
|
@ -1,35 +0,0 @@
|
||||||
entry_1:
|
|
||||||
id: 1
|
|
||||||
title: Entry 1
|
|
||||||
type: Entry
|
|
||||||
|
|
||||||
entry_2:
|
|
||||||
id: 2
|
|
||||||
title: Entry 2
|
|
||||||
type: Entry
|
|
||||||
|
|
||||||
page_1:
|
|
||||||
id: 3
|
|
||||||
title: Page 1
|
|
||||||
type: Page
|
|
||||||
|
|
||||||
entry_3:
|
|
||||||
id: 4
|
|
||||||
title: Entry 3
|
|
||||||
type: Entry
|
|
||||||
|
|
||||||
document_1:
|
|
||||||
id: 5
|
|
||||||
title: Document 1
|
|
||||||
type:
|
|
||||||
|
|
||||||
page_2:
|
|
||||||
id: 6
|
|
||||||
title: Page 2
|
|
||||||
type: Page
|
|
||||||
|
|
||||||
document_2:
|
|
||||||
id: 7
|
|
||||||
title: Document 2
|
|
||||||
type:
|
|
||||||
|
|
|
@ -1,20 +0,0 @@
|
||||||
class Project < ActiveRecord::Base
|
|
||||||
belongs_to :category
|
|
||||||
acts_as_ordered :order => 'name', :scope => :category
|
|
||||||
end
|
|
||||||
|
|
||||||
class WrappedProject < ActiveRecord::Base
|
|
||||||
belongs_to :category
|
|
||||||
set_table_name :projects
|
|
||||||
acts_as_ordered :order => 'name', :scope => :category, :wrap => true
|
|
||||||
end
|
|
||||||
|
|
||||||
class SQLScopedProject < ActiveRecord::Base
|
|
||||||
set_table_name :projects
|
|
||||||
acts_as_ordered :order => 'name', :scope => 'category_id = #{category_id}'
|
|
||||||
end
|
|
||||||
|
|
||||||
class WrappedSQLScopedProject < ActiveRecord::Base
|
|
||||||
set_table_name :projects
|
|
||||||
acts_as_ordered :order => 'name', :scope => 'category_id = #{category_id}', :wrap => true
|
|
||||||
end
|
|
|
@ -1,41 +0,0 @@
|
||||||
one:
|
|
||||||
id: 1
|
|
||||||
category_id: 1
|
|
||||||
name: A - First Project
|
|
||||||
description: This is the first one
|
|
||||||
|
|
||||||
two:
|
|
||||||
id: 2
|
|
||||||
category_id: 1
|
|
||||||
name: B - Second Project
|
|
||||||
description: This is the second one
|
|
||||||
|
|
||||||
three:
|
|
||||||
id: 3
|
|
||||||
category_id: 1
|
|
||||||
name: C - Third Project
|
|
||||||
description: This is the third one
|
|
||||||
|
|
||||||
four:
|
|
||||||
id: 4
|
|
||||||
category_id: 2
|
|
||||||
name: D - Fourth
|
|
||||||
description: This is the fourth one
|
|
||||||
|
|
||||||
five:
|
|
||||||
id: 5
|
|
||||||
category_id: 2
|
|
||||||
name: E - Fifth
|
|
||||||
description: This is the fifth one
|
|
||||||
|
|
||||||
six:
|
|
||||||
id: 6
|
|
||||||
category_id: 2
|
|
||||||
name: F - Sixth
|
|
||||||
description: This is the sixth one
|
|
||||||
|
|
||||||
seven:
|
|
||||||
id: 7
|
|
||||||
category_id: 2
|
|
||||||
name: G - Seventh
|
|
||||||
description: This is the seventh one
|
|
21
vendor/plugins/acts_as_ordered/test/schema.rb
vendored
21
vendor/plugins/acts_as_ordered/test/schema.rb
vendored
|
@ -1,21 +0,0 @@
|
||||||
ActiveRecord::Schema.define :version => 0 do
|
|
||||||
create_table :cartoons, :force => true do |t|
|
|
||||||
t.column :first_name, :string
|
|
||||||
t.column :last_name, :string
|
|
||||||
end
|
|
||||||
|
|
||||||
create_table :categories, :force => true do |t|
|
|
||||||
t.column :name, :string
|
|
||||||
end
|
|
||||||
|
|
||||||
create_table :projects, :force => true do |t|
|
|
||||||
t.column :category_id, :integer
|
|
||||||
t.column :name, :string
|
|
||||||
t.column :description, :string
|
|
||||||
end
|
|
||||||
|
|
||||||
create_table :documents, :force => true do |t|
|
|
||||||
t.column :title, :string
|
|
||||||
t.column :type, :string
|
|
||||||
end
|
|
||||||
end
|
|
18
vendor/plugins/haml/init.rb
vendored
18
vendor/plugins/haml/init.rb
vendored
|
@ -1,18 +0,0 @@
|
||||||
begin
|
|
||||||
require File.join(File.dirname(__FILE__), 'lib', 'haml') # From here
|
|
||||||
rescue LoadError
|
|
||||||
begin
|
|
||||||
require 'haml' # From gem
|
|
||||||
rescue LoadError => e
|
|
||||||
# gems:install may be run to install Haml with the skeleton plugin
|
|
||||||
# but not the gem itself installed.
|
|
||||||
# Don't die if this is the case.
|
|
||||||
raise e unless defined?(Rake) &&
|
|
||||||
(Rake.application.top_level_tasks.include?('gems') ||
|
|
||||||
Rake.application.top_level_tasks.include?('gems:install'))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Load Haml.
|
|
||||||
# Haml may be undefined if we're running gems:install.
|
|
||||||
Haml.init_rails(binding) if defined?(Haml)
|
|
Loading…
Reference in a new issue