Skip to content

Commit

Permalink
fixup! Add support for Rails 5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
urkle committed Dec 3, 2018
1 parent 743ae20 commit cff8749
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ def initialize(*args) #:nodoc:
unless orders.blank?
# fill out orders with :asc when undefined. make sure hash ordering
# follows column ordering.
self.orders = Hash[columns.map{|column| [column, orders[column] || :asc]}]
if self.orders.is_a?(Hash)
self.orders = Hash[columns.map{|column| [column, orders[column] || :asc]}]
else
self.orders = Hash[columns.map{|column| [column, orders || :asc]}]
end
end
end

Expand Down
5 changes: 5 additions & 0 deletions spec/index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ class Post < ::ActiveRecord::Base ; end
expect(index_for([:login, :deleted_at]).orders).to eq({"login" => :desc, "deleted_at" => :asc})
end

it "should assign order (all same direction)", :mysql => :skip do
add_index(:users, [:login, :deleted_at], :order => {:login => :desc, :deleted_at => :desc})
expect(index_for([:login, :deleted_at]).orders).to eq({"login" => :desc, "deleted_at" => :desc})
end

context "for duplicate index" do
it "should not complain if the index is the same" do
add_index(:users, :login)
Expand Down

0 comments on commit cff8749

Please sign in to comment.