Skip to content

Commit

Permalink
Ensure PageNumber is serialized as JSON number
Browse files Browse the repository at this point in the history
Fixes #603
  • Loading branch information
mislav committed Oct 15, 2019
1 parent cb60abe commit ab44416
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/will_paginate/page_number.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def to_i
@value
end

def_delegators :@value, :coerce, :==, :<=>, :to_s, :+, :-, :*, :/
def_delegators :@value, :coerce, :==, :<=>, :to_s, :+, :-, :*, :/, :to_json

def inspect
"#{@name} #{to_i}"
Expand Down
9 changes: 9 additions & 0 deletions spec/page_number_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'spec_helper'
require 'will_paginate/page_number'
require 'json'

describe WillPaginate::PageNumber do
describe "valid" do
Expand Down Expand Up @@ -38,6 +39,14 @@ def num
it "passes the Numeric=== type check" do |variable|
(Numeric === num).should be
end

it "fails the Numeric=== type check" do |variable|
(Integer === num).should_not be
end

it "serializes as JSON number" do
JSON.dump(page: num).should eq('{"page":12}')
end
end

describe "invalid" do
Expand Down

0 comments on commit ab44416

Please sign in to comment.