Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
More portable than const_defined? somehow?
  • Loading branch information
rmg committed Mar 14, 2013
1 parent 62e5e37 commit ee3aed3
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
9 changes: 5 additions & 4 deletions lib/magic_grid/collection.rb
Expand Up @@ -28,6 +28,11 @@ def initialize(collection, opts = {})
@post_filter_callbacks = []
@paginations = []
@searchable_columns = []
if defined? Kaminari
@@kaminari_class = Kaminari
else
@@kaminari_class = nil
end
end

delegate :quoted_table_name, :map, :count, :to => :collection
Expand Down Expand Up @@ -269,8 +274,4 @@ def bound_current_page(page, per_page, total_entries)
end
end
end
if Module.const_defined?(:Kaminari)
Collection.kaminari_class = Kaminari
end

end
2 changes: 1 addition & 1 deletion spec/collection_spec.rb
Expand Up @@ -153,7 +153,7 @@
context "when no pagination is provided" do
# TODO replace this when rspec-mocks add 'hide_const'
# before :each do
# if Module.const_defined?(:Kaminari)
# if defined?(Kaminari)
# @kaminari = Module.const_get(:Kaminari)
# Object.send(:remove_const, :Kaminari)
# end
Expand Down
2 changes: 1 addition & 1 deletion spec/helpers_spec.rb
Expand Up @@ -92,7 +92,7 @@
context "renders top and bottom pagers as told" do
large_collection = (1..1000).to_a

if Module.const_defined? :Kaminari
if defined? Kaminari
def render(*args)
"<nav class='pagination'><!-- paginate! --></nav>".html_safe
end
Expand Down
2 changes: 1 addition & 1 deletion test/dummy/app/controllers/users_controller.rb
@@ -1,4 +1,4 @@
if Module.const_defined? :WillPaginate
if defined? WillPaginate
require 'will_paginate/array'
end

Expand Down

0 comments on commit ee3aed3

Please sign in to comment.