kaminari-rspec 0.14.1.b0
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 +15 -0
- data/.gitignore +1 -0
- data/Gemfile +4 -0
- data/License.txt +22 -0
- data/README.md +70 -0
- data/Rakefile +35 -0
- data/kaminari-rspec.gemspec +30 -0
- data/lib/kaminari_rspec.rb +2 -0
- data/lib/kaminari_rspec/test_helpers.rb +90 -0
- data/lib/kaminari_rspec/version.rb +3 -0
- data/spec/lib/kaminari_rspec/flexmock/spec_helper_flexmock.rb +5 -0
- data/spec/lib/kaminari_rspec/flexmock/test_helpers_spec.rb +57 -0
- data/spec/lib/kaminari_rspec/mocha/spec_helper_mocha.rb +5 -0
- data/spec/lib/kaminari_rspec/mocha/test_helpers_spec.rb +57 -0
- data/spec/lib/kaminari_rspec/rr/spec_helper_rr.rb +5 -0
- data/spec/lib/kaminari_rspec/rr/test_helpers_spec.rb +55 -0
- data/spec/lib/kaminari_rspec/rspec/spec_helper_rspec.rb +3 -0
- data/spec/lib/kaminari_rspec/rspec/test_helpers_spec.rb +51 -0
- data/spec/lib/kaminari_rspec/test_helpers_spec.rb +115 -0
- data/spec/spec_helper.rb +11 -0
- metadata +171 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NzNhYjY4ZGY2MGMyMTEyYzc4OGU3MzY3NWY4OTU5OWQ4NjUxYTI1MQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZTFhYzg2NjdiM2EyYTEwZjU5MWJjMTVkMzUzMGZkMWYyZjQwYjczOA==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MjE4NjM2MDQ5YmEyY2JjMWYwOWIzZDAxYTEzNjljYzQ1ZWI1MmIwYmRjYWMx
|
10
|
+
OTZiMDA5NWU5MmI5NDdmNjNjNmJlZjM1ZWQ3MWRjOTBjNmRkMWRiNjk5Mjc0
|
11
|
+
NDhkNGM2MDYwNGE5NmMwZmUzNmE3YTczZmJiOWRhNWFhM2FjMTY=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NjI1MzZlNGZiYzZkYTgxMjVjYzgyYjgwY2M2ZDYwZTJkZmY1Yjc1OWFlYzM2
|
14
|
+
MTI3M2I5YzdiNDBiZmRiMzhmNmY1NTkzYjdkMjVhOTEyNTI4YzA3NDQ0NzMx
|
15
|
+
ZTI2ZjJjMWUzY2ZhNDA1MWZhODU4Mjg1YzJjNWVkZjk5ZDcxY2M=
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Gemfile.lock
|
data/Gemfile
ADDED
data/License.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
(The MIT License)
|
2
|
+
|
3
|
+
Copyright (c) 2013 Marco Sandrini
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
19
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
20
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
21
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
22
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
Kaminari Rspec Library
|
2
|
+
=========================
|
3
|
+
|
4
|
+
|
5
|
+
|
6
|
+
`kaminari-rspec` is a ruby gem that aims at simplifying writing the specs for views where Kaminari is used for pagination
|
7
|
+
|
8
|
+
Installing
|
9
|
+
----------
|
10
|
+
|
11
|
+
Simply install the gem to your system
|
12
|
+
|
13
|
+
`gem install kaminari-rspec`
|
14
|
+
|
15
|
+
or if you are using Bundler add it to your gemspec file and run `bundle install`.
|
16
|
+
|
17
|
+
Gem Versioning
|
18
|
+
--------------
|
19
|
+
|
20
|
+
The gem version reflects the kaminari version that is supports. Please notice that this gem is maintained in my spare time
|
21
|
+
so delays occur between the release of a new Kaminari version and the release of a new version of this gem. Feel free
|
22
|
+
to fork this repo and update the version and the code as needed.
|
23
|
+
|
24
|
+
Rendering views with RSpec's render_view
|
25
|
+
----------------------------------------
|
26
|
+
|
27
|
+
If you are rendering the views from your controller spec using render_views AND you are mocking
|
28
|
+
the data returned from the db with something along the lines of
|
29
|
+
|
30
|
+
`Model.stub_chain(:order, :page, :per).and_return([model_mock])`
|
31
|
+
|
32
|
+
you may want to also stub the methods needed by the pagination partials, in order to do that, just
|
33
|
+
add the following to your `spec_helper`
|
34
|
+
|
35
|
+
`config.include KaminariRspec::TestHelpers, :type => :controller`
|
36
|
+
|
37
|
+
and then modify your controller spec to look like
|
38
|
+
|
39
|
+
`Model.stub_chain(:order, :page, :per).and_return(stub_pagination([model_mock]))`
|
40
|
+
|
41
|
+
the stubs will return the values needed to set the pagination as being on the first and only page.
|
42
|
+
|
43
|
+
If specific pagination values are needed they can be defined using a hash
|
44
|
+
|
45
|
+
`stub_pagination(mocked_result, :total_count => 50, :current_page => 3, :per_page => 10)`
|
46
|
+
|
47
|
+
will create the same pagination links as a total count of 50 elements are available, with 10
|
48
|
+
elements per page and page 3 being the current_page. Notice that `current_page` is anyway always
|
49
|
+
set such that it respects the values passed in `total_count` and `per_page`, i.e. if you pass a
|
50
|
+
total count of 95 and a per page value of 10, current page will be capped to 10
|
51
|
+
|
52
|
+
Detecting mocking framework
|
53
|
+
---------------------------
|
54
|
+
|
55
|
+
If you are using RSpec >= 2.5.2 there is no need to explicitly pass the mocking framework you
|
56
|
+
are using to the stub_pagination method, as it is automatically detected by the TestHelpers.
|
57
|
+
For earlier versions you are required to explicitly use the same string you would pass to
|
58
|
+
`RSpec.configuration.mock_with` , so the actual method call is
|
59
|
+
|
60
|
+
`stub_pagination(mocked_result, :mock => :rspec, :total_count => 50, :current_page => 3, :per_page => 10)`
|
61
|
+
|
62
|
+
Default values
|
63
|
+
--------------
|
64
|
+
|
65
|
+
The TestHelpers will also try to guess values so that you don't need to explicitly pass them all.
|
66
|
+
* `:per_page` will default to 25
|
67
|
+
* `:current_page` will default to 1
|
68
|
+
* `:total_count` will default to 1 if the object passed as resource is not a collection, otherwise it will
|
69
|
+
invoke get the value from resource.length
|
70
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
require 'yard'
|
4
|
+
require 'yard/rake/yardoc_task'
|
5
|
+
|
6
|
+
task :spec => [:spec_common, :spec_with_rspec, :spec_with_mocha, :spec_with_flexmock]
|
7
|
+
|
8
|
+
YARD::Rake::YardocTask.new('yard')
|
9
|
+
|
10
|
+
desc 'Runs the specs that are common to all mocking mechanisms'
|
11
|
+
RSpec::Core::RakeTask.new(:spec_common) do |t|
|
12
|
+
t.pattern = 'spec/lib/kaminari_rspec/test_helpers_spec.rb'
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'Runs the specs that need the built-in RSpec mocking mechanism'
|
16
|
+
RSpec::Core::RakeTask.new(:spec_with_rspec) do |t|
|
17
|
+
t.pattern = 'spec/lib/kaminari_rspec/rspec/test_helpers_spec.rb'
|
18
|
+
end
|
19
|
+
|
20
|
+
desc 'Runs the specs that need the rr mocking mechanism'
|
21
|
+
RSpec::Core::RakeTask.new(:spec_with_rr) do |t|
|
22
|
+
t.pattern = 'spec/lib/kaminari_rspec/rr/test_helpers_spec.rb'
|
23
|
+
end
|
24
|
+
|
25
|
+
desc 'Runs the specs that need the mocha mocking mechanism'
|
26
|
+
RSpec::Core::RakeTask.new(:spec_with_mocha) do |t|
|
27
|
+
t.pattern = 'spec/lib/kaminari_rspec/mocha/test_helpers_spec.rb'
|
28
|
+
end
|
29
|
+
|
30
|
+
desc 'Runs the specs that need the flexmock mocking mechanism'
|
31
|
+
RSpec::Core::RakeTask.new(:spec_with_flexmock) do |t|
|
32
|
+
t.pattern = 'spec/lib/kaminari_rspec/flexmock/test_helpers_spec.rb'
|
33
|
+
end
|
34
|
+
|
35
|
+
task :default => :spec
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
3
|
+
require 'kaminari_rspec/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'kaminari-rspec'
|
7
|
+
s.version = KaminariRspec::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ['Marco Sandrini']
|
10
|
+
s.email = %w(nessche@gmail.com)
|
11
|
+
s.homepage = 'https://github.com/nessche/kaminari-rspec'
|
12
|
+
s.summary = 'A Rspec Helper library for the Kaminari gem'
|
13
|
+
s.description = 'A Rspec Helper library for the Kaminari gem'
|
14
|
+
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = %w(lib)
|
20
|
+
|
21
|
+
|
22
|
+
# specify any dependencies here; for example:
|
23
|
+
s.add_runtime_dependency 'kaminari', '0.14.1'
|
24
|
+
s.add_development_dependency 'rspec'
|
25
|
+
s.add_development_dependency 'rake'
|
26
|
+
s.add_development_dependency 'yard'
|
27
|
+
s.add_development_dependency 'rr'
|
28
|
+
s.add_development_dependency 'mocha'
|
29
|
+
s.add_development_dependency 'flexmock'
|
30
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
module KaminariRspec
|
2
|
+
module TestHelpers
|
3
|
+
|
4
|
+
def stub_pagination(resource, options={})
|
5
|
+
return nil unless resource
|
6
|
+
mock_framework = options[:mock] || discover_mock_framework
|
7
|
+
values = calculate_values(resource, options)
|
8
|
+
case mock_framework
|
9
|
+
when :rspec then stub_pagination_with_rspec(resource, values)
|
10
|
+
when :rr then stub_pagination_with_rr(resource, values)
|
11
|
+
when :mocha then stub_pagination_with_mocha(resource, values)
|
12
|
+
when :flexmock then stub_pagination_with_flexmock(resource, values)
|
13
|
+
when :nothing then resource
|
14
|
+
else
|
15
|
+
raise ArgumentError, "Invalid mock argument #{options[:mock]} / framework not supported"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def discover_mock_framework
|
20
|
+
|
21
|
+
mock_framework = RSpec.configuration.mock_framework
|
22
|
+
return mock_framework.framework_name if mock_framework.respond_to? :framework_name
|
23
|
+
puts('WARNING: Could not detect mocking framework, defaulting to :nothing, use :mock option to override')
|
24
|
+
return :nothing
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
def calculate_values(resource, options={})
|
30
|
+
|
31
|
+
values = {}
|
32
|
+
values[:total_count] = options[:total_count] || (resource.respond_to?(:length) ? resource.length : 1)
|
33
|
+
values[:limit_value] = options[:per_page] || 25
|
34
|
+
values[:total_pages] = (values[:total_count] / values[:limit_value]) + ((values[:total_count] % values[:limit_value]) == 0 ? 0 : 1)
|
35
|
+
values[:current_page] = [(options[:current_page] || 1), values[:total_pages]].min
|
36
|
+
return values
|
37
|
+
end
|
38
|
+
|
39
|
+
def stub_pagination_with_rspec(resource, values)
|
40
|
+
|
41
|
+
puts('Stubbing pagination methods with RSpec mocks')
|
42
|
+
|
43
|
+
values.each do |key, value |
|
44
|
+
allow(resource).to receive(key).and_return(value)
|
45
|
+
end
|
46
|
+
|
47
|
+
return resource
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
def stub_pagination_with_rr(resource, values)
|
52
|
+
|
53
|
+
puts('Stubbing pagination methods with RR')
|
54
|
+
|
55
|
+
values.each do |key, value|
|
56
|
+
eval "stub(resource).#{key} { #{value} }"
|
57
|
+
end
|
58
|
+
|
59
|
+
return resource
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
def stub_pagination_with_mocha(resource, values)
|
64
|
+
|
65
|
+
puts('Stubbing pagination methods with mocha')
|
66
|
+
|
67
|
+
values.each do |key, value|
|
68
|
+
resource.stubs(key).returns(value)
|
69
|
+
end
|
70
|
+
|
71
|
+
return resource
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
def stub_pagination_with_flexmock(resource, values)
|
76
|
+
|
77
|
+
puts('Stubbing pagination methods with flexmock')
|
78
|
+
|
79
|
+
mock = flexmock(resource)
|
80
|
+
|
81
|
+
values.each do |key, value|
|
82
|
+
mock.should_receive(key).zero_or_more_times.and_return(value)
|
83
|
+
end
|
84
|
+
|
85
|
+
return mock
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative 'spec_helper_flexmock'
|
3
|
+
require 'kaminari_rspec'
|
4
|
+
include KaminariRspec::TestHelpers
|
5
|
+
|
6
|
+
describe 'KaminariRspec::TestHelpers::' do
|
7
|
+
|
8
|
+
describe 'discover_mock_framework' do
|
9
|
+
|
10
|
+
context 'when the mock framework is flexmock' do
|
11
|
+
|
12
|
+
it 'should return flexmock' do
|
13
|
+
discover_mock_framework.should == :flexmock
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
describe 'stub_pagination' do
|
22
|
+
|
23
|
+
context 'when passed a nil resource' do
|
24
|
+
|
25
|
+
it 'returns nil' do
|
26
|
+
result = stub_pagination(nil)
|
27
|
+
result.should be_nil
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'when passed a non nil resource' do
|
33
|
+
|
34
|
+
# we check for total_count, to know if the stubbing was successful, no need to check for each
|
35
|
+
# method individually
|
36
|
+
it 'has the total_count method stubbed' do
|
37
|
+
resource = Object.new
|
38
|
+
result = stub_pagination(resource, :mock => :flexmock, :total_count => 23)
|
39
|
+
result.total_count.should == 23
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'and an unknown mocking framework' do
|
43
|
+
|
44
|
+
it 'raises an error' do
|
45
|
+
resource = Object.new
|
46
|
+
expect { stub_pagination(resource, :mock => :my_mock)}.to raise_error(ArgumentError)
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative 'spec_helper_mocha'
|
3
|
+
require 'kaminari_rspec'
|
4
|
+
include KaminariRspec::TestHelpers
|
5
|
+
|
6
|
+
describe 'KaminariRspec::TestHelpers::' do
|
7
|
+
|
8
|
+
describe 'discover_mock_framework' do
|
9
|
+
|
10
|
+
context 'when the mock framework is mocha' do
|
11
|
+
|
12
|
+
it 'should return mocha' do
|
13
|
+
discover_mock_framework.should == :mocha
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
describe 'stub_pagination' do
|
22
|
+
|
23
|
+
context 'when passed a nil resource' do
|
24
|
+
|
25
|
+
it 'returns nil' do
|
26
|
+
result = stub_pagination(nil)
|
27
|
+
result.should be_nil
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'when passed a non nil resource' do
|
33
|
+
|
34
|
+
# we check for total_count, to know if the stubbing was successful, no need to check for each
|
35
|
+
# method individually
|
36
|
+
it 'has the total_count method stubbed' do
|
37
|
+
resource = Object.new
|
38
|
+
result = stub_pagination(resource, :mock => :mocha, :total_count => 23)
|
39
|
+
result.total_count.should == 23
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'and an unknown mocking framework' do
|
43
|
+
|
44
|
+
it 'raises an error' do
|
45
|
+
resource = Object.new
|
46
|
+
expect { stub_pagination(resource, :mock => :my_mock)}.to raise_error(ArgumentError)
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative 'spec_helper_rr'
|
3
|
+
require 'kaminari_rspec'
|
4
|
+
include KaminariRspec::TestHelpers
|
5
|
+
|
6
|
+
describe 'KaminariRspec::TestHelpers::', :rr => true do
|
7
|
+
|
8
|
+
describe 'discover_mock_framework' do
|
9
|
+
|
10
|
+
context 'when the framework is rr' do
|
11
|
+
|
12
|
+
it 'should return rr' do
|
13
|
+
discover_mock_framework.should == :rr
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
describe 'stub_pagination' do
|
21
|
+
|
22
|
+
context 'when passed a nil resource' do
|
23
|
+
|
24
|
+
it 'returns nil' do
|
25
|
+
result = stub_pagination(nil)
|
26
|
+
result.should be_nil
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'when passed a non nil resource' do
|
32
|
+
|
33
|
+
# we check for total_count, to know if the stubbing was successful, no need to check for each
|
34
|
+
# method individually
|
35
|
+
it 'has the total_count method stubbed' do
|
36
|
+
resource = Object.new
|
37
|
+
result = stub_pagination(resource, :mock => :rr, :total_count => 23)
|
38
|
+
result.total_count.should == 23
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'and an unknown mocking framework' do
|
42
|
+
|
43
|
+
it 'raises an error' do
|
44
|
+
resource = Object.new
|
45
|
+
expect { stub_pagination(resource, :mock => :my_mock)}.to raise_error(ArgumentError)
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative 'spec_helper_rspec'
|
3
|
+
require 'kaminari_rspec'
|
4
|
+
include KaminariRspec::TestHelpers
|
5
|
+
|
6
|
+
describe 'KaminariRspec::TestHelpers::' do
|
7
|
+
|
8
|
+
describe 'discover_mock_framework' do
|
9
|
+
|
10
|
+
context 'when the mock framework does not support framework_name' do
|
11
|
+
|
12
|
+
before do
|
13
|
+
dumb_framework = Object.new
|
14
|
+
allow(RSpec.configuration).to receive(:mock_framework) { dumb_framework }
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should return :nothing' do
|
18
|
+
discover_mock_framework.should == :nothing
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'when the mock framework does support framework_name' do
|
25
|
+
|
26
|
+
before do
|
27
|
+
mock_framework = RSpec.configuration.mock_framework
|
28
|
+
allow(mock_framework).to receive(:framework_name) { :my_framework }
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should return the framework name' do
|
32
|
+
discover_mock_framework.should == :my_framework
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'when the mock framework is rspec' do
|
38
|
+
|
39
|
+
it 'should return rspec' do
|
40
|
+
discover_mock_framework.should == :rspec
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
end
|
51
|
+
|
@@ -0,0 +1,115 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'kaminari_rspec'
|
3
|
+
include KaminariRspec::TestHelpers
|
4
|
+
|
5
|
+
describe 'KaminariRspec::TestHelpers' do
|
6
|
+
|
7
|
+
|
8
|
+
describe 'calculate_values' do
|
9
|
+
|
10
|
+
context 'when no total_count is specified' do
|
11
|
+
|
12
|
+
context 'and when passed an object that does not implement length' do
|
13
|
+
|
14
|
+
it 'sets total_count to 1' do
|
15
|
+
|
16
|
+
values = calculate_values(Object.new)
|
17
|
+
values[:total_count].should == 1
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'and when passed an object that implements length' do
|
24
|
+
|
25
|
+
it 'sets total_count to the length of the object' do
|
26
|
+
|
27
|
+
values = calculate_values([ Object.new, Object.new])
|
28
|
+
values[:total_count].should == 2
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'when total_count is specified' do
|
38
|
+
|
39
|
+
it 'sets the total_count to the specified value' do
|
40
|
+
|
41
|
+
values = calculate_values(Object.new, :total_count => 13)
|
42
|
+
values[:total_count].should == 13
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
context 'when per_page is not specified' do
|
49
|
+
|
50
|
+
it 'set per_page to the default of 25' do
|
51
|
+
|
52
|
+
values = calculate_values(Object.new)
|
53
|
+
values[:limit_value].should == 25
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'when per_page is specified' do
|
60
|
+
|
61
|
+
it 'sets limit_value to the specified value' do
|
62
|
+
|
63
|
+
values = calculate_values(Object.new, :per_page => 17)
|
64
|
+
values[:limit_value].should == 17
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'sets total_pages based on total_count and per_page' do
|
71
|
+
values = calculate_values(Object.new, :total_count => 50, :per_page => 25)
|
72
|
+
values[:total_pages].should == 2
|
73
|
+
end
|
74
|
+
|
75
|
+
context 'when current_page is not specified' do
|
76
|
+
|
77
|
+
it 'set current_page to the default of 1' do
|
78
|
+
|
79
|
+
values = calculate_values(Object.new)
|
80
|
+
values[:current_page].should == 1
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
context 'when current_page is specified' do
|
87
|
+
|
88
|
+
context 'and the current_page value is <= num_pages'do
|
89
|
+
|
90
|
+
it 'sets current_page to the specified value' do
|
91
|
+
|
92
|
+
values = calculate_values(Object.new, :current_page => 19, :total_count => 500, :per_page => 20)
|
93
|
+
values[:current_page].should == 19
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
context 'and the current_page value is > total_pages' do
|
100
|
+
|
101
|
+
it 'sets current_page to the max value allowed by total_pages' do
|
102
|
+
|
103
|
+
values = calculate_values(Object.new, :current_page => 19, :total_count => 100, :per_page => 20)
|
104
|
+
values[:current_page].should == 5
|
105
|
+
end
|
106
|
+
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
|
3
|
+
|
4
|
+
# Requires supporting files with custom matchers and macros, etc,
|
5
|
+
# in ./support/ and its subdirectories.
|
6
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
7
|
+
|
8
|
+
RSpec.configure do |config|
|
9
|
+
config.color_enabled = true
|
10
|
+
config.formatter = 'documentation'
|
11
|
+
end
|
metadata
ADDED
@@ -0,0 +1,171 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kaminari-rspec
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.14.1.b0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Marco Sandrini
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-07-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: kaminari
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.14.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.14.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: yard
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rr
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: mocha
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: flexmock
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ! '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: A Rspec Helper library for the Kaminari gem
|
112
|
+
email:
|
113
|
+
- nessche@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- .gitignore
|
119
|
+
- Gemfile
|
120
|
+
- License.txt
|
121
|
+
- README.md
|
122
|
+
- Rakefile
|
123
|
+
- kaminari-rspec.gemspec
|
124
|
+
- lib/kaminari_rspec.rb
|
125
|
+
- lib/kaminari_rspec/test_helpers.rb
|
126
|
+
- lib/kaminari_rspec/version.rb
|
127
|
+
- spec/lib/kaminari_rspec/flexmock/spec_helper_flexmock.rb
|
128
|
+
- spec/lib/kaminari_rspec/flexmock/test_helpers_spec.rb
|
129
|
+
- spec/lib/kaminari_rspec/mocha/spec_helper_mocha.rb
|
130
|
+
- spec/lib/kaminari_rspec/mocha/test_helpers_spec.rb
|
131
|
+
- spec/lib/kaminari_rspec/rr/spec_helper_rr.rb
|
132
|
+
- spec/lib/kaminari_rspec/rr/test_helpers_spec.rb
|
133
|
+
- spec/lib/kaminari_rspec/rspec/spec_helper_rspec.rb
|
134
|
+
- spec/lib/kaminari_rspec/rspec/test_helpers_spec.rb
|
135
|
+
- spec/lib/kaminari_rspec/test_helpers_spec.rb
|
136
|
+
- spec/spec_helper.rb
|
137
|
+
homepage: https://github.com/nessche/kaminari-rspec
|
138
|
+
licenses: []
|
139
|
+
metadata: {}
|
140
|
+
post_install_message:
|
141
|
+
rdoc_options: []
|
142
|
+
require_paths:
|
143
|
+
- lib
|
144
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
145
|
+
requirements:
|
146
|
+
- - ! '>='
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '0'
|
149
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - ! '>'
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: 1.3.1
|
154
|
+
requirements: []
|
155
|
+
rubyforge_project:
|
156
|
+
rubygems_version: 2.0.5
|
157
|
+
signing_key:
|
158
|
+
specification_version: 4
|
159
|
+
summary: A Rspec Helper library for the Kaminari gem
|
160
|
+
test_files:
|
161
|
+
- spec/lib/kaminari_rspec/flexmock/spec_helper_flexmock.rb
|
162
|
+
- spec/lib/kaminari_rspec/flexmock/test_helpers_spec.rb
|
163
|
+
- spec/lib/kaminari_rspec/mocha/spec_helper_mocha.rb
|
164
|
+
- spec/lib/kaminari_rspec/mocha/test_helpers_spec.rb
|
165
|
+
- spec/lib/kaminari_rspec/rr/spec_helper_rr.rb
|
166
|
+
- spec/lib/kaminari_rspec/rr/test_helpers_spec.rb
|
167
|
+
- spec/lib/kaminari_rspec/rspec/spec_helper_rspec.rb
|
168
|
+
- spec/lib/kaminari_rspec/rspec/test_helpers_spec.rb
|
169
|
+
- spec/lib/kaminari_rspec/test_helpers_spec.rb
|
170
|
+
- spec/spec_helper.rb
|
171
|
+
has_rdoc:
|