spec/hyperdrive/middleware/pagination_spec.rb in hyperdrive-0.0.8 vs spec/hyperdrive/middleware/pagination_spec.rb in hyperdrive-0.0.9

- old
+ new

@@ -2,44 +2,44 @@ require 'spec_helper' describe Hyperdrive::Middleware::Pagination do def app - inner_app = ->(env) { [200, {}, [[env['hyperdrive.page'],env['hyperdrive.per_page'],env['hyperdrive.params'][:page],env['hyperdrive.params'][:per_page]].join(",")]] } + inner_app = ->(env) { [200, {}, [[env['hyperdrive.page'],env['hyperdrive.per_page']].join(',')]] } Hyperdrive::Middleware::Pagination.new(inner_app) end after do hyperdrive.send(:reset!) end - it "sets default values for page and per_page and removes them from hyperdrive.params" do - env = default_rack_env.merge('hyperdrive.params' => {}) - get '/', {}, env - last_response.body.must_equal '1,20,,' + it "sets default values for page and per_page" do + get '/', {} + last_response.body.must_equal '1,20' end it "sets page to 1 if value is less than 1" do - env = default_rack_env.merge('hyperdrive.params' => { page: '' }) - get '/', {}, env - last_response.body.must_equal '1,20,,' + get '/', { 'page' => '' } + last_response.body.must_equal '1,20' end + it "returns page value if supplied" do + get '/', { 'page' => '2' } + last_response.body.must_equal '2,20' + end + it "returns per_page value if supplied" do - env = default_rack_env.merge('hyperdrive.params' => { per_page: 42 }) - get '/', {}, env - last_response.body.must_equal '1,42,,' + get '/', { 'per_page' => 42 } + last_response.body.must_equal '1,42' end it "uses configured per_page value if per_page is not supplied" do hyperdrive.config[:per_page] = 13 - env = default_rack_env.merge('hyperdrive.params' => {}) - get '/', {}, env - last_response.body.must_equal '1,13,,' + get '/', {} + last_response.body.must_equal '1,13' end it "sets per_page to 20 if value is 0" do - env = default_rack_env.merge('hyperdrive.params' => { per_page: '' }) - get '/', {}, env - last_response.body.must_equal '1,20,,' + get '/', { 'per_page' => '' } + last_response.body.must_equal '1,20' end end