Skip to content

Commit 35431ba

Browse files
committed
Move ENV check back into spec_helper.rb
Signed-off-by: David Celis <[email protected]>
1 parent 2267ef2 commit 35431ba

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

lib/api-pagination/hooks.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ def self.init!
1818
require 'grape/pagination'
1919
Grape::API.send(:include, Grape::Pagination)
2020
end
21+
2122
# Kaminari and will_paginate conflict with each other, so we should check
2223
# to see if either is already active before attempting to load them.
2324
if defined?(Kaminari) && defined?(WillPaginate::CollectionMethods)
2425
STDERR.puts <<-EOC
25-
Warning: api-pagination relies on either Kaminari or WillPaginate, but these
26-
gems conflict. Please ensure only one of them is active at any given time.
26+
Warning: api-pagination relies on either Kaminari or WillPaginate, but these
27+
gems conflict. Please ensure only one of them is active at any given time.
28+
2729
EOC
2830
return
2931
elsif defined?(Kaminari)
@@ -57,6 +59,7 @@ def self.init!
5759
end
5860

5961
def self.initialize_kaminari!
62+
require 'kaminari/models/array_extension'
6063
ApiPagination.instance_variable_set(:@paginator, :kaminari)
6164
end
6265

@@ -71,8 +74,4 @@ def last_page?() !next_page end
7174
end
7275
end
7376

74-
if ENV['PAGINATOR']
75-
ApiPagination.instance_variable_set(:@paginator, ENV['PAGINATOR'].to_sym)
76-
end
77-
7877
ApiPagination::Hooks.init!

spec/spec_helper.rb

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
1-
require 'support/numbers_controller'
2-
require 'support/numbers_api'
3-
require 'api-pagination'
4-
51
if ENV['PAGINATOR']
62
ApiPagination.instance_variable_set(:@paginator, ENV['PAGINATOR'].to_sym)
73
else
84
warn 'No PAGINATOR set. Defaulting to kaminari. To test against will_paginate, run `PAGINATOR=will_paginate bundle exec rspec`'
95
ApiPagination.instance_variable_set(:@paginator, :kaminari)
106
end
117

12-
if ApiPagination.paginator == :kaminari
13-
Kaminari::Hooks.init
14-
elsif ApiPagination.paginator == :will_paginate
15-
require 'will_paginate/array'
16-
end
8+
require 'support/numbers_controller'
9+
require 'support/numbers_api'
10+
require 'api-pagination'
11+
12+
require 'will_paginate/array' if ApiPagination.paginator == :will_paginate
1713

1814
RSpec.configure do |config|
1915
config.include Rack::Test::Methods

0 commit comments

Comments
 (0)