Skip to content

Commit

Permalink
Merge branch 'fix-order' of https://github.com/nandalopes/searchlogic
Browse files Browse the repository at this point in the history
…into nandalopes-fix-order
  • Loading branch information
binarylogic committed Mar 1, 2011
2 parents c2152a3 + 3106214 commit a5ac7cd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
9 changes: 8 additions & 1 deletion lib/searchlogic/named_scopes/association_ordering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,14 @@ def association_ordering_condition_details(name)
end

def create_association_ordering_condition(association, order_as, condition, args)
named_scope("#{order_as}_by_#{association.name}_#{condition}", association_condition_options(association, "#{order_as}_by_#{condition}", args))
cond = condition
poly_class = nil
if condition =~ /^(\w+)_type_(\w+)$/
poly_type = $1
cond = $2
poly_class = poly_type.camelcase.constantize if poly_type
end
named_scope("#{order_as}_by_#{association.name}_#{condition}", association_condition_options(association, "#{order_as}_by_#{cond}", args, poly_class))
end
end
end
Expand Down
6 changes: 5 additions & 1 deletion spec/searchlogic/named_scopes/association_ordering_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@
it "should work through #order" do
Company.order('ascend_by_users_username').proxy_options.should == Company.ascend_by_users_username.proxy_options
end
end

it "should ascend with a polymorphic belongs to" do
Audit.descend_by_auditable_user_type_username.proxy_options.should == User.descend_by_username.proxy_options.merge(:joins => :users)
end
end
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class ::User < ActiveRecord::Base
has_many :carts, :dependent => :destroy
has_many :orders, :dependent => :destroy
has_many :orders_big, :class_name => 'Order', :conditions => 'total > 100'
has_many :audits, :as => :auditable
has_and_belongs_to_many :user_groups

self.skip_time_zone_conversion_for_attributes = [:whatever_at]
Expand Down

0 comments on commit a5ac7cd

Please sign in to comment.