neat-pages 0.1.7 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +4 -0
- data/Gemfile +2 -0
- data/LICENSE +1 -1
- data/README.md +58 -22
- data/app/assets/javascripts/neat_pages/base.coffee +8 -1
- data/lib/.reek +12 -0
- data/lib/neat-pages.rb +2 -1
- data/lib/neat_pages/base.rb +5 -7
- data/lib/neat_pages/engine.rb +3 -1
- data/lib/neat_pages/errors.rb +9 -0
- data/lib/neat_pages/helpers.rb +8 -10
- data/lib/neat_pages/helpers/builder.rb +26 -16
- data/lib/neat_pages/helpers/navigation.rb +39 -27
- data/lib/neat_pages/helpers/status.rb +14 -0
- data/lib/neat_pages/implants/action_controller_implant.rb +3 -0
- data/lib/neat_pages/implants/mongoid_implant.rb +12 -10
- data/lib/neat_pages/{implants/railtie.rb → railtie.rb} +7 -4
- data/neat-pages.gemspec +23 -0
- data/spec/controllers/application_controller_spec.rb +24 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/controllers/examples_controller.rb +11 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +18 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +5 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +29 -0
- data/spec/dummy/config/environments/production.rb +80 -0
- data/spec/dummy/config/environments/test.rb +36 -0
- data/spec/dummy/config/initializers/standard_rails_initializers.rb +9 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +3 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/neat_pages/base_spec.rb +31 -5
- data/spec/neat_pages/helpers/builder_spec.rb +109 -0
- data/spec/neat_pages/helpers/navigation_spec.rb +105 -0
- data/spec/neat_pages/helpers/status_spec.rb +65 -0
- data/spec/neat_pages/helpers_spec.rb +67 -0
- data/spec/neat_pages/implants/mongoid_implant_spec.rb +43 -0
- data/spec/spec_helper.rb +21 -6
- data/spec/support/views_helper.rb +16 -0
- data/vendor/assets/javascripts/jquery.hashchange.min.js +1 -1
- metadata +134 -42
- data/lib/neat_pages/implants.rb +0 -12
@@ -0,0 +1,109 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe NeatPages::Helpers::Builder do
|
4
|
+
include ViewHelpers
|
5
|
+
|
6
|
+
describe "#b" do
|
7
|
+
context "with an empty builder" do
|
8
|
+
let(:builder) { NeatPages::Helpers::Builder.new(double, request_mock) }
|
9
|
+
|
10
|
+
context "when inserting the string <span>1</span>" do
|
11
|
+
subject { builder.b '<span>1</span>' }
|
12
|
+
|
13
|
+
it { should eql '<span>1</span>' }
|
14
|
+
it { should be_html_safe }
|
15
|
+
|
16
|
+
context "and inserting another <span>2</span>" do
|
17
|
+
before { builder.b '<span>1</span>' }
|
18
|
+
|
19
|
+
subject { builder.b '<span>2</span>' }
|
20
|
+
|
21
|
+
it { should eql '<span>1</span><span>2</span>' }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "#li" do
|
28
|
+
context "with an empty builder" do
|
29
|
+
let(:builder) { NeatPages::Helpers::Builder.new(double, request_mock) }
|
30
|
+
|
31
|
+
context "when inserting a li with the value 1" do
|
32
|
+
before { builder.li '1' }
|
33
|
+
|
34
|
+
specify { builder.b.should eql '<li>1</li>' }
|
35
|
+
end
|
36
|
+
|
37
|
+
context "when inserting an hidden li with the value 1, the css_class 'active'" do
|
38
|
+
before { builder.li '1', 'active', hidden: true }
|
39
|
+
|
40
|
+
specify { builder.b.should eql '<li class="active" style="display:none">1</li>' }
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "#path_to" do
|
47
|
+
context "with a builder having a base_url http://www.test.dev" do
|
48
|
+
|
49
|
+
context "and no params" do
|
50
|
+
let(:builder) { NeatPages::Helpers::Builder.new(double, request_mock(host: 'www.test.dev')) }
|
51
|
+
|
52
|
+
context "when asking for the path_to page 6" do
|
53
|
+
specify { builder.path_to(6).should eql 'http://www.test.dev?page=6' }
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "and the params sort=1, filter=type" do
|
58
|
+
let(:request) { request_mock(host: 'www.test.dev', env: { 'action_dispatch.request.query_parameters' => { 'sort' => 1, 'filter' => 'type' } })}
|
59
|
+
let(:builder) { NeatPages::Helpers::Builder.new(double, request) }
|
60
|
+
|
61
|
+
context "when asking for the path_to page 6" do
|
62
|
+
specify { builder.path_to(6).should eql 'http://www.test.dev?sort=1&filter=type&page=6' }
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context "and the params sort=1, filter=type, page=5" do
|
67
|
+
let(:request) { request_mock(host: 'www.test.dev', env: { 'action_dispatch.request.query_parameters' => { 'sort' => 1, 'filter' => 'type', 'page' => 5 } })}
|
68
|
+
let(:builder) { NeatPages::Helpers::Builder.new(double, request) }
|
69
|
+
|
70
|
+
context "when asking for the path_to page 6" do
|
71
|
+
specify { builder.path_to(6).should eql 'http://www.test.dev?sort=1&filter=type&page=6' }
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context "and the params page=5" do
|
76
|
+
let(:request) { request_mock(host: 'www.test.dev', env: { 'action_dispatch.request.query_parameters' => { 'page' => 5 } })}
|
77
|
+
let(:builder) { NeatPages::Helpers::Builder.new(double, request) }
|
78
|
+
|
79
|
+
context "when asking for the path_to page 6" do
|
80
|
+
specify { builder.path_to(6).should eql 'http://www.test.dev?page=6' }
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe "#reset_builder" do
|
87
|
+
context "with an empty builder" do
|
88
|
+
let(:builder) { NeatPages::Helpers::Builder.new(double, request_mock) }
|
89
|
+
|
90
|
+
context "when resetting the builder" do
|
91
|
+
before { builder.reset_builder }
|
92
|
+
|
93
|
+
specify { builder.b.should eql '' }
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
context "with a builder having the value '<span>1</span>'" do
|
98
|
+
let(:builder) { NeatPages::Helpers::Builder.new(double, request_mock) }
|
99
|
+
|
100
|
+
before { builder.b '<span>1</span>' }
|
101
|
+
|
102
|
+
context "when resetting the builder" do
|
103
|
+
before { builder.reset_builder }
|
104
|
+
|
105
|
+
specify { builder.b.should eql '' }
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe NeatPages::Helpers::Navigation do
|
4
|
+
include ViewHelpers
|
5
|
+
|
6
|
+
describe "#generate" do
|
7
|
+
|
8
|
+
let(:pagination) { double() }
|
9
|
+
|
10
|
+
context "with a pagination that doesn't need pages" do
|
11
|
+
before { pagination.stub(:paginated?).and_return(false) }
|
12
|
+
|
13
|
+
let(:builder) { NeatPages::Helpers::Navigation.new(pagination, request_mock) }
|
14
|
+
|
15
|
+
context "when generating the navigation" do
|
16
|
+
specify { builder.generate.should be_empty }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
context "with a 40 items pagination starting at 20 and having 10 items per page" do
|
20
|
+
before do
|
21
|
+
pagination.stub(:paginated?).and_return(true)
|
22
|
+
pagination.stub(:current_page).and_return(3)
|
23
|
+
pagination.stub(:next?).and_return(true)
|
24
|
+
pagination.stub(:next_page).and_return(4)
|
25
|
+
pagination.stub(:offset).and_return(20)
|
26
|
+
pagination.stub(:per_page).and_return(10)
|
27
|
+
pagination.stub(:previous?).and_return(true)
|
28
|
+
pagination.stub(:previous_page).and_return(2)
|
29
|
+
pagination.stub(:total_items).and_return(40)
|
30
|
+
pagination.stub(:total_pages).and_return(4)
|
31
|
+
end
|
32
|
+
|
33
|
+
let(:builder) { NeatPages::Helpers::Navigation.new(pagination, request_mock) }
|
34
|
+
|
35
|
+
context "when generating the navigation" do
|
36
|
+
specify { builder.generate.should eql '<ul class="standard" id="neat-pages-navigation" data-neat-pages-control=="navigation" data-per-page="10" data-total-items="40" data-total-pages="4"><li class="move previous "><a data-page="2" href="http://test.dev?page=2" class="previous">« Previous</a></li><li class="page"><a data-page="1" href="http://test.dev?page=1">1</a></li><li class="page"><a data-page="2" href="http://test.dev?page=2">2</a></li><li class="page selected"><a data-page="3" href="http://test.dev?page=3">3</a></li><li class="page"><a data-page="4" href="http://test.dev?page=4">4</a></li><li class="move next "><a data-page="4" href="http://test.dev?page=4" class="next">Next »</a></li></ul>' }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "with a 40 items pagination starting at 30 and having 10 items per page" do
|
41
|
+
before do
|
42
|
+
pagination.stub(:paginated?).and_return(true)
|
43
|
+
pagination.stub(:current_page).and_return(3)
|
44
|
+
pagination.stub(:next?).and_return(false)
|
45
|
+
pagination.stub(:next_page).and_return(nil)
|
46
|
+
pagination.stub(:offset).and_return(30)
|
47
|
+
pagination.stub(:per_page).and_return(10)
|
48
|
+
pagination.stub(:previous?).and_return(true)
|
49
|
+
pagination.stub(:previous_page).and_return(2)
|
50
|
+
pagination.stub(:total_items).and_return(40)
|
51
|
+
pagination.stub(:total_pages).and_return(4)
|
52
|
+
end
|
53
|
+
|
54
|
+
let(:builder) { NeatPages::Helpers::Navigation.new(pagination, request_mock) }
|
55
|
+
|
56
|
+
context "when generating the navigation" do
|
57
|
+
specify { builder.generate.should eql '<ul class="standard" id="neat-pages-navigation" data-neat-pages-control=="navigation" data-per-page="10" data-total-items="40" data-total-pages="4"><li class="move previous "><a data-page="2" href="http://test.dev?page=2" class="previous">« Previous</a></li><li class="page"><a data-page="1" href="http://test.dev?page=1">1</a></li><li class="page"><a data-page="2" href="http://test.dev?page=2">2</a></li><li class="page selected"><a data-page="3" href="http://test.dev?page=3">3</a></li><li class="page"><a data-page="4" href="http://test.dev?page=4">4</a></li><li class="move next disabled"><a data-page="#" href="#" class="next">Next »</a></li></ul>' }
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context "with a 200 items pagination starting at 110 and having 10 items per page" do
|
62
|
+
before do
|
63
|
+
pagination.stub(:paginated?).and_return(true)
|
64
|
+
pagination.stub(:current_page).and_return(12)
|
65
|
+
pagination.stub(:next?).and_return(true)
|
66
|
+
pagination.stub(:next_page).and_return(13)
|
67
|
+
pagination.stub(:offset).and_return(110)
|
68
|
+
pagination.stub(:per_page).and_return(10)
|
69
|
+
pagination.stub(:previous?).and_return(true)
|
70
|
+
pagination.stub(:previous_page).and_return(11)
|
71
|
+
pagination.stub(:total_items).and_return(200)
|
72
|
+
pagination.stub(:total_pages).and_return(20)
|
73
|
+
end
|
74
|
+
|
75
|
+
let(:builder) { NeatPages::Helpers::Navigation.new(pagination, request_mock) }
|
76
|
+
|
77
|
+
context "when generating the navigation" do
|
78
|
+
specify { builder.generate.should eql '<ul class="standard" id="neat-pages-navigation" data-neat-pages-control=="navigation" data-per-page="10" data-total-items="200" data-total-pages="20">'+
|
79
|
+
'<li class="move previous "><a data-page="11" href="http://test.dev?page=11" class="previous">« Previous</a></li>'+
|
80
|
+
'<li class="page" style="display:none"><a data-page="1" href="http://test.dev?page=1">1</a></li>'+
|
81
|
+
'<li class="page" style="display:none"><a data-page="2" href="http://test.dev?page=2">2</a></li>'+
|
82
|
+
'<li class="page" style="display:none"><a data-page="3" href="http://test.dev?page=3">3</a></li>'+
|
83
|
+
'<li class="page" style="display:none"><a data-page="4" href="http://test.dev?page=4">4</a></li>'+
|
84
|
+
'<li class="page" style="display:none"><a data-page="5" href="http://test.dev?page=5">5</a></li>'+
|
85
|
+
'<li class="page" style="display:none"><a data-page="6" href="http://test.dev?page=6">6</a></li>'+
|
86
|
+
'<li class="page" style="display:none"><a data-page="7" href="http://test.dev?page=7">7</a></li>'+
|
87
|
+
'<li class="page"><a data-page="8" href="http://test.dev?page=8">8</a></li>'+
|
88
|
+
'<li class="page"><a data-page="9" href="http://test.dev?page=9">9</a></li>'+
|
89
|
+
'<li class="page"><a data-page="10" href="http://test.dev?page=10">10</a></li>'+
|
90
|
+
'<li class="page"><a data-page="11" href="http://test.dev?page=11">11</a></li>'+
|
91
|
+
'<li class="page selected"><a data-page="12" href="http://test.dev?page=12">12</a></li>'+
|
92
|
+
'<li class="page"><a data-page="13" href="http://test.dev?page=13">13</a></li>'+
|
93
|
+
'<li class="page"><a data-page="14" href="http://test.dev?page=14">14</a></li>'+
|
94
|
+
'<li class="page"><a data-page="15" href="http://test.dev?page=15">15</a></li>'+
|
95
|
+
'<li class="page"><a data-page="16" href="http://test.dev?page=16">16</a></li>'+
|
96
|
+
'<li class="page"><a data-page="17" href="http://test.dev?page=17">17</a></li>'+
|
97
|
+
'<li class="page" style="display:none"><a data-page="18" href="http://test.dev?page=18">18</a></li>'+
|
98
|
+
'<li class="page" style="display:none"><a data-page="19" href="http://test.dev?page=19">19</a></li>'+
|
99
|
+
'<li class="page" style="display:none"><a data-page="20" href="http://test.dev?page=20">20</a></li>'+
|
100
|
+
'<li class="move next "><a data-page="13" href="http://test.dev?page=13" class="next">Next »</a></li></ul>' }
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe NeatPages::Helpers::Status do
|
4
|
+
include ViewHelpers
|
5
|
+
|
6
|
+
describe "#generate" do
|
7
|
+
|
8
|
+
let(:pagination) { double() }
|
9
|
+
|
10
|
+
context "with an empty pagination" do
|
11
|
+
before { pagination.stub(:empty?).and_return(true) }
|
12
|
+
|
13
|
+
let(:builder) { NeatPages::Helpers::Status.new(pagination, request_mock) }
|
14
|
+
|
15
|
+
context "when generating the status" do
|
16
|
+
specify { builder.generate.should be_empty }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context "with a pagination out of bound" do
|
21
|
+
before do
|
22
|
+
pagination.stub(:empty?).and_return(false)
|
23
|
+
pagination.stub(:out_of_bound?).and_return(true)
|
24
|
+
end
|
25
|
+
|
26
|
+
let(:builder) { NeatPages::Helpers::Status.new(pagination, request_mock) }
|
27
|
+
|
28
|
+
context "when generating the status" do
|
29
|
+
specify { builder.generate.should be_empty }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "with a 100 items pagination starting at 20 and having 10 items per page" do
|
34
|
+
before do
|
35
|
+
pagination.stub(:empty?).and_return(false)
|
36
|
+
pagination.stub(:out_of_bound?).and_return(false)
|
37
|
+
pagination.stub(:offset).and_return(20)
|
38
|
+
pagination.stub(:per_page).and_return(10)
|
39
|
+
pagination.stub(:total_items).and_return(100)
|
40
|
+
end
|
41
|
+
|
42
|
+
let(:builder) { NeatPages::Helpers::Status.new(pagination, request_mock) }
|
43
|
+
|
44
|
+
context "when generating the status" do
|
45
|
+
specify { builder.generate.should eql '<span data-neat-pages-control="status" id="neat-pages-status"><span class="from">21</span> to <span class="to">30</span>/<span class="total">100</span></span>' }
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context "with a 23 items pagination starting at 20 and having 10 items per page" do
|
50
|
+
before do
|
51
|
+
pagination.stub(:empty?).and_return(false)
|
52
|
+
pagination.stub(:out_of_bound?).and_return(false)
|
53
|
+
pagination.stub(:offset).and_return(20)
|
54
|
+
pagination.stub(:per_page).and_return(10)
|
55
|
+
pagination.stub(:total_items).and_return(23)
|
56
|
+
end
|
57
|
+
|
58
|
+
let(:builder) { NeatPages::Helpers::Status.new(pagination, request_mock) }
|
59
|
+
|
60
|
+
context "when generating the status" do
|
61
|
+
specify { builder.generate.should eql '<span data-neat-pages-control="status" id="neat-pages-status"><span class="from">21</span> to <span class="to">23</span>/<span class="total">23</span></span>' }
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe NeatPages::Helpers do
|
4
|
+
include ViewHelpers
|
5
|
+
|
6
|
+
let(:pagination) { double() }
|
7
|
+
let(:views) { Module.new { extend NeatPages::Helpers } }
|
8
|
+
|
9
|
+
describe "#neat_pages_ajax_items" do
|
10
|
+
before { views.stub(:render).and_return '[html_list_of_items]' }
|
11
|
+
|
12
|
+
context "when rendering the ajax items" do
|
13
|
+
specify { views.neat_pages_ajax_items('items').should eql '<div id="neat-pages-ajax-wrapper" class="first-load">[html_list_of_items]</div>' }
|
14
|
+
end
|
15
|
+
|
16
|
+
context "when rendering the ajax items for a table" do
|
17
|
+
specify { views.neat_pages_ajax_items('items', wrapper: 'tbody').should eql '<tbody id="neat-pages-ajax-wrapper" class="first-load">[html_list_of_items]</tbody>' }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#neat_pages_navigation" do
|
22
|
+
before do
|
23
|
+
views.stub(:request).and_return(request_mock(host: 'testview.dev'))
|
24
|
+
|
25
|
+
pagination.stub(:paginated?).and_return(true)
|
26
|
+
pagination.stub(:current_page).and_return(3)
|
27
|
+
pagination.stub(:next?).and_return(true)
|
28
|
+
pagination.stub(:next_page).and_return(4)
|
29
|
+
pagination.stub(:offset).and_return(20)
|
30
|
+
pagination.stub(:per_page).and_return(10)
|
31
|
+
pagination.stub(:previous?).and_return(true)
|
32
|
+
pagination.stub(:previous_page).and_return(2)
|
33
|
+
pagination.stub(:total_items).and_return(40)
|
34
|
+
pagination.stub(:total_pages).and_return(4)
|
35
|
+
|
36
|
+
views.stub(:pagination).and_return(pagination)
|
37
|
+
end
|
38
|
+
|
39
|
+
context "when rendering the navigation" do
|
40
|
+
specify { views.neat_pages_navigation.should eql '<ul class="standard" id="neat-pages-navigation" data-neat-pages-control=="navigation" data-per-page="10" data-total-items="40" data-total-pages="4">' +
|
41
|
+
'<li class="move previous "><a data-page="2" href="http://testview.dev?page=2" class="previous">« Previous</a></li>' +
|
42
|
+
'<li class="page"><a data-page="1" href="http://testview.dev?page=1">1</a></li>' +
|
43
|
+
'<li class="page"><a data-page="2" href="http://testview.dev?page=2">2</a></li>' +
|
44
|
+
'<li class="page selected"><a data-page="3" href="http://testview.dev?page=3">3</a></li>' +
|
45
|
+
'<li class="page"><a data-page="4" href="http://testview.dev?page=4">4</a></li>' +
|
46
|
+
'<li class="move next "><a data-page="4" href="http://testview.dev?page=4" class="next">Next »</a></li></ul>' }
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "#neat_pages_status" do
|
51
|
+
before do
|
52
|
+
views.stub(:request).and_return(request_mock)
|
53
|
+
|
54
|
+
pagination.stub(:empty?).and_return(false)
|
55
|
+
pagination.stub(:out_of_bound?).and_return(false)
|
56
|
+
pagination.stub(:offset).and_return(20)
|
57
|
+
pagination.stub(:per_page).and_return(10)
|
58
|
+
pagination.stub(:total_items).and_return(100)
|
59
|
+
|
60
|
+
views.stub(:pagination).and_return(pagination)
|
61
|
+
end
|
62
|
+
|
63
|
+
context "when rendering the status" do
|
64
|
+
specify { views.neat_pages_status.should eql '<span data-neat-pages-control="status" id="neat-pages-status"><span class="from">21</span> to <span class="to">30</span>/<span class="total">100</span></span>' }
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe NeatPages::Implants::MongoidCriteriaImplant do
|
4
|
+
let(:pagination) { double() }
|
5
|
+
let(:implant) { Module.new { extend NeatPages::Implants::MongoidCriteriaImplant } }
|
6
|
+
|
7
|
+
describe "#paginate" do
|
8
|
+
context "when the pagination isn't initialized" do
|
9
|
+
it "raises" do
|
10
|
+
expect { implant.paginate(nil) }.to raise_error NeatPages::Uninitalized
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
context "when the page is out of bound" do
|
15
|
+
before do
|
16
|
+
implant.stub(:count)
|
17
|
+
pagination.stub(:set_total_items)
|
18
|
+
pagination.stub(:out_of_bound?).and_return true
|
19
|
+
end
|
20
|
+
|
21
|
+
it "raises" do
|
22
|
+
expect { implant.paginate(pagination) }.to raise_error NeatPages::OutOfBound
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context "when asking for a page in bound" do
|
27
|
+
before do
|
28
|
+
implant.stub(:count)
|
29
|
+
implant.stub(:limit).and_return('')
|
30
|
+
implant.stub(:offset).and_return(implant)
|
31
|
+
|
32
|
+
pagination.stub(:set_total_items)
|
33
|
+
pagination.stub(:out_of_bound?).and_return false
|
34
|
+
pagination.stub(:offset)
|
35
|
+
pagination.stub(:limit)
|
36
|
+
end
|
37
|
+
|
38
|
+
specify { implant.paginate(pagination).should eql '' }
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
data/spec/spec_helper.rb
CHANGED
@@ -1,12 +1,27 @@
|
|
1
|
-
|
2
|
-
require "bundler/setup"
|
1
|
+
ENV["RAILS_ENV"] ||= 'test'
|
3
2
|
|
4
|
-
require '
|
5
|
-
require '
|
3
|
+
require 'simplecov'
|
4
|
+
require 'simplecov-rcov-text'
|
5
|
+
require 'coveralls'
|
6
6
|
|
7
|
-
|
7
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
8
|
+
SimpleCov::Formatter::HTMLFormatter,
|
9
|
+
SimpleCov::Formatter::RcovTextFormatter,
|
10
|
+
Coveralls::SimpleCov::Formatter
|
11
|
+
]
|
8
12
|
|
9
|
-
|
13
|
+
SimpleCov.start do
|
14
|
+
add_filter "spec/dummy"
|
15
|
+
add_filter "spec/support"
|
16
|
+
add_filter "spec/neat-pages_spec.rb"
|
17
|
+
end
|
18
|
+
|
19
|
+
require File.expand_path("../dummy/config/environment", __FILE__)
|
20
|
+
|
21
|
+
require 'rspec/rails'
|
22
|
+
require 'rspec/autorun'
|
23
|
+
|
24
|
+
Dir["./spec/support/**/*.rb"].sort.each {|f| require f }
|
10
25
|
|
11
26
|
RSpec.configure do |config|
|
12
27
|
config.mock_with :rspec
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module ViewHelpers
|
2
|
+
def request_mock(options={})
|
3
|
+
options.reverse_merge! env: {}, host: 'test.dev', path_info: '', port: 80, protocol: 'http://'
|
4
|
+
|
5
|
+
env = { 'action_dispatch.request.query_parameters' => {} }.merge options[:env]
|
6
|
+
|
7
|
+
request = double()
|
8
|
+
request.stub(:protocol).and_return options[:protocol]
|
9
|
+
request.stub(:host).and_return options[:host]
|
10
|
+
request.stub(:port).and_return options[:port]
|
11
|
+
request.stub(:path_info).and_return options[:path_info]
|
12
|
+
request.stub(:env).and_return env
|
13
|
+
|
14
|
+
return request
|
15
|
+
end
|
16
|
+
end
|
@@ -6,4 +6,4 @@
|
|
6
6
|
* Dual licensed under the MIT and GPL licenses.
|
7
7
|
* http://benalman.com/about/license/
|
8
8
|
*/
|
9
|
-
(function($,e,b){var c="hashchange",h=document,f,g=$.event.special,i=h.documentMode,d="on"+c in e&&(i===b||i>7);function a(j){j=j||location.href;return"#"+j.replace(/^[^#]*#?(.*)$/,"$1")}$.fn[c]=function(j){return j?this.bind(c,j):this.trigger(c)};$.fn[c].delay=50;g[c]=$.extend(g[c],{setup:function(){if(d){return false}$(f.start)},teardown:function(){if(d){return false}$(f.stop)}});f=(function(){var j={},p,m=a(),k=function(q){return q},l=k,o=k;j.start=function(){p||n()};j.stop=function(){p&&clearTimeout(p);p=b};function n(){var r=a(),q=o(m);if(r!==m){l(m=r,q);$(e).trigger(c)}else{if(q!==m){location.href=location.href.replace(/#.*/,"")+q}}p=setTimeout(n,$.fn[c].delay)}
|
9
|
+
(function($,e,b){var c="hashchange",h=document,f,g=$.event.special,i=h.documentMode,d="on"+c in e&&(i===b||i>7);function a(j){j=j||location.href;return"#"+j.replace(/^[^#]*#?(.*)$/,"$1")}$.fn[c]=function(j){return j?this.bind(c,j):this.trigger(c)};$.fn[c].delay=50;g[c]=$.extend(g[c],{setup:function(){if(d){return false}$(f.start)},teardown:function(){if(d){return false}$(f.stop)}});f=(function(){var j={},p,m=a(),k=function(q){return q},l=k,o=k;j.start=function(){p||n()};j.stop=function(){p&&clearTimeout(p);p=b};function n(){var r=a(),q=o(m);if(r!==m){l(m=r,q);$(e).trigger(c)}else{if(q!==m){location.href=location.href.replace(/#.*/,"")+q}}p=setTimeout(n,$.fn[c].delay)}!$.support.boxModel&&!d&&(function(){var q,r;j.start=function(){if(!q){r=$.fn[c].src;r=r&&r+a();q=$('<iframe tabindex="-1" title="empty"/>').hide().one("load",function(){r||l(a());n()}).attr("src",r||"javascript:0").insertAfter("body")[0].contentWindow;h.onpropertychange=function(){try{if(event.propertyName==="title"){q.document.title=h.title}}catch(s){}}}};j.stop=k;o=function(){return a(q.location.href)};l=function(v,s){var u=q.document,t=$.fn[c].domain;if(v!==s){u.title=h.title;u.open();t&&u.write('<script>document.domain="'+t+'"<\/script>');u.close();q.location.hash=v}}})();return j})()})(jQuery,this);
|