merb_paginate 0.9.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.
Files changed (56) hide show
  1. data/CHANGELOG.rdoc +105 -0
  2. data/LICENSE +18 -0
  3. data/README.rdoc +125 -0
  4. data/Rakefile +59 -0
  5. data/lib/merbtasks.rb +17 -0
  6. data/lib/will_paginate.rb +40 -0
  7. data/lib/will_paginate/array.rb +35 -0
  8. data/lib/will_paginate/collection.rb +145 -0
  9. data/lib/will_paginate/core_ext.rb +58 -0
  10. data/lib/will_paginate/deprecation.rb +50 -0
  11. data/lib/will_paginate/finders.rb +9 -0
  12. data/lib/will_paginate/finders/active_record.rb +192 -0
  13. data/lib/will_paginate/finders/active_record/named_scope.rb +170 -0
  14. data/lib/will_paginate/finders/active_record/named_scope_patch.rb +39 -0
  15. data/lib/will_paginate/finders/active_resource.rb +51 -0
  16. data/lib/will_paginate/finders/base.rb +112 -0
  17. data/lib/will_paginate/finders/data_mapper.rb +30 -0
  18. data/lib/will_paginate/finders/sequel.rb +21 -0
  19. data/lib/will_paginate/version.rb +9 -0
  20. data/lib/will_paginate/view_helpers.rb +42 -0
  21. data/lib/will_paginate/view_helpers/base.rb +126 -0
  22. data/lib/will_paginate/view_helpers/link_renderer.rb +130 -0
  23. data/lib/will_paginate/view_helpers/link_renderer_base.rb +83 -0
  24. data/lib/will_paginate/view_helpers/merb.rb +13 -0
  25. data/spec/collection_spec.rb +147 -0
  26. data/spec/console +8 -0
  27. data/spec/console_fixtures.rb +8 -0
  28. data/spec/database.yml +22 -0
  29. data/spec/finders/active_record_spec.rb +461 -0
  30. data/spec/finders/active_resource_spec.rb +52 -0
  31. data/spec/finders/activerecord_test_connector.rb +108 -0
  32. data/spec/finders/data_mapper_spec.rb +62 -0
  33. data/spec/finders/data_mapper_test_connector.rb +20 -0
  34. data/spec/finders/sequel_spec.rb +53 -0
  35. data/spec/finders/sequel_test_connector.rb +9 -0
  36. data/spec/finders_spec.rb +76 -0
  37. data/spec/fixtures/admin.rb +3 -0
  38. data/spec/fixtures/developer.rb +13 -0
  39. data/spec/fixtures/developers_projects.yml +13 -0
  40. data/spec/fixtures/project.rb +15 -0
  41. data/spec/fixtures/projects.yml +6 -0
  42. data/spec/fixtures/replies.yml +29 -0
  43. data/spec/fixtures/reply.rb +7 -0
  44. data/spec/fixtures/schema.rb +38 -0
  45. data/spec/fixtures/topic.rb +6 -0
  46. data/spec/fixtures/topics.yml +30 -0
  47. data/spec/fixtures/user.rb +2 -0
  48. data/spec/fixtures/users.yml +35 -0
  49. data/spec/rcov.opts +2 -0
  50. data/spec/spec.opts +2 -0
  51. data/spec/spec_helper.rb +75 -0
  52. data/spec/tasks.rake +60 -0
  53. data/spec/view_helpers/base_spec.rb +64 -0
  54. data/spec/view_helpers/link_renderer_base_spec.rb +84 -0
  55. data/spec/view_helpers/view_example_group.rb +111 -0
  56. metadata +126 -0
@@ -0,0 +1,111 @@
1
+ unless $:.find { |p| p =~ %r{/html-scanner$} }
2
+ unless actionpack_path = $:.find { |p| p =~ %r{/actionpack(-[\d.]+)?/lib$} }
3
+ raise "cannot find ActionPack in load paths"
4
+ end
5
+ html_scanner_path = "#{actionpack_path}/action_controller/vendor/html-scanner"
6
+ $:.unshift(html_scanner_path)
7
+ end
8
+
9
+ require 'action_controller/assertions/selector_assertions'
10
+
11
+ class ViewExampleGroup < Spec::Example::ExampleGroup
12
+
13
+ include ActionController::Assertions::SelectorAssertions
14
+
15
+ def assert(value, message)
16
+ raise message unless value
17
+ end
18
+
19
+ def paginate(collection = {}, options = {}, &block)
20
+ if collection.instance_of? Hash
21
+ page_options = { :page => 1, :total_entries => 11, :per_page => 4 }.merge(collection)
22
+ collection = [1].paginate(page_options)
23
+ end
24
+
25
+ locals = { :collection => collection, :options => options }
26
+
27
+ @render_output = render(locals)
28
+ @html_document = nil
29
+
30
+ if block_given?
31
+ classname = options[:class] || WillPaginate::ViewHelpers.pagination_options[:class]
32
+ assert_select("div.#{classname}", 1, 'no main DIV', &block)
33
+ end
34
+
35
+ @render_output
36
+ end
37
+
38
+ def html_document
39
+ @html_document ||= HTML::Document.new(@render_output, true, false)
40
+ end
41
+
42
+ def response_from_page_or_rjs
43
+ html_document.root
44
+ end
45
+
46
+ def validate_page_numbers(expected, links, param_name = :page)
47
+ param_pattern = /\W#{CGI.escape(param_name.to_s)}=([^&]*)/
48
+
49
+ links.map { |e|
50
+ e['href'] =~ param_pattern
51
+ $1 ? $1.to_i : $1
52
+ }.should == expected
53
+ end
54
+
55
+ def assert_links_match(pattern, links = nil, numbers = nil)
56
+ links ||= assert_select 'div.pagination a[href]' do |elements|
57
+ elements
58
+ end
59
+
60
+ pages = [] if numbers
61
+
62
+ links.each do |el|
63
+ el['href'].should =~ pattern
64
+ if numbers
65
+ el['href'] =~ pattern
66
+ pages << ($1.nil?? nil : $1.to_i)
67
+ end
68
+ end
69
+
70
+ pages.should == numbers if numbers
71
+ end
72
+
73
+ def assert_no_links_match(pattern)
74
+ assert_select 'div.pagination a[href]' do |elements|
75
+ elements.each do |el|
76
+ el['href'] !~ pattern
77
+ end
78
+ end
79
+ end
80
+
81
+ def build_message(message, pattern, *args)
82
+ built_message = pattern.dup
83
+ for value in args
84
+ built_message.sub! '?', value.inspect
85
+ end
86
+ built_message
87
+ end
88
+
89
+ end
90
+
91
+ Spec::Example::ExampleGroupFactory.register(:view_helpers, ViewExampleGroup)
92
+
93
+ module HTML
94
+ Node.class_eval do
95
+ def inner_text
96
+ children.map(&:inner_text).join('')
97
+ end
98
+ end
99
+
100
+ Text.class_eval do
101
+ def inner_text
102
+ self.to_s
103
+ end
104
+ end
105
+
106
+ Tag.class_eval do
107
+ def inner_text
108
+ childless?? '' : super
109
+ end
110
+ end
111
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: merb_paginate
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.0
5
+ platform: ruby
6
+ authors:
7
+ - Jacques Crocker
8
+ - "Mislav Marohni\xC4\x87"
9
+ - PJ Hyett
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+
14
+ date: 2009-01-31 00:00:00 -08:00
15
+ default_executable:
16
+ dependencies:
17
+ - !ruby/object:Gem::Dependency
18
+ name: merb-core
19
+ type: :runtime
20
+ version_requirement:
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: "1.0"
26
+ version:
27
+ description: merb_paginate is a fork of will_paginate agnostic branch, refocused to work specifically with Merb
28
+ email: merbjedi@gmail.com
29
+ executables: []
30
+
31
+ extensions: []
32
+
33
+ extra_rdoc_files:
34
+ - README.rdoc
35
+ - LICENSE
36
+ files:
37
+ - LICENSE
38
+ - README.rdoc
39
+ - CHANGELOG.rdoc
40
+ - Rakefile
41
+ - lib/merbtasks.rb
42
+ - lib/will_paginate
43
+ - lib/will_paginate/array.rb
44
+ - lib/will_paginate/collection.rb
45
+ - lib/will_paginate/core_ext.rb
46
+ - lib/will_paginate/deprecation.rb
47
+ - lib/will_paginate/finders
48
+ - lib/will_paginate/finders/active_record
49
+ - lib/will_paginate/finders/active_record/named_scope.rb
50
+ - lib/will_paginate/finders/active_record/named_scope_patch.rb
51
+ - lib/will_paginate/finders/active_record.rb
52
+ - lib/will_paginate/finders/active_resource.rb
53
+ - lib/will_paginate/finders/base.rb
54
+ - lib/will_paginate/finders/data_mapper.rb
55
+ - lib/will_paginate/finders/sequel.rb
56
+ - lib/will_paginate/finders.rb
57
+ - lib/will_paginate/version.rb
58
+ - lib/will_paginate/view_helpers
59
+ - lib/will_paginate/view_helpers/base.rb
60
+ - lib/will_paginate/view_helpers/link_renderer.rb
61
+ - lib/will_paginate/view_helpers/link_renderer_base.rb
62
+ - lib/will_paginate/view_helpers/merb.rb
63
+ - lib/will_paginate/view_helpers.rb
64
+ - lib/will_paginate.rb
65
+ - spec/collection_spec.rb
66
+ - spec/console
67
+ - spec/console_fixtures.rb
68
+ - spec/database.yml
69
+ - spec/finders
70
+ - spec/finders/active_record_spec.rb
71
+ - spec/finders/active_resource_spec.rb
72
+ - spec/finders/activerecord_test_connector.rb
73
+ - spec/finders/data_mapper_spec.rb
74
+ - spec/finders/data_mapper_test_connector.rb
75
+ - spec/finders/sequel_spec.rb
76
+ - spec/finders/sequel_test_connector.rb
77
+ - spec/finders_spec.rb
78
+ - spec/fixtures
79
+ - spec/fixtures/admin.rb
80
+ - spec/fixtures/developer.rb
81
+ - spec/fixtures/developers_projects.yml
82
+ - spec/fixtures/project.rb
83
+ - spec/fixtures/projects.yml
84
+ - spec/fixtures/replies.yml
85
+ - spec/fixtures/reply.rb
86
+ - spec/fixtures/schema.rb
87
+ - spec/fixtures/topic.rb
88
+ - spec/fixtures/topics.yml
89
+ - spec/fixtures/user.rb
90
+ - spec/fixtures/users.yml
91
+ - spec/rcov.opts
92
+ - spec/spec.opts
93
+ - spec/spec_helper.rb
94
+ - spec/tasks.rake
95
+ - spec/view_helpers
96
+ - spec/view_helpers/base_spec.rb
97
+ - spec/view_helpers/link_renderer_base_spec.rb
98
+ - spec/view_helpers/view_example_group.rb
99
+ has_rdoc: true
100
+ homepage: http://github.com/merbjedi/merb_paginate
101
+ post_install_message:
102
+ rdoc_options: []
103
+
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: "0"
111
+ version:
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: "0"
117
+ version:
118
+ requirements: []
119
+
120
+ rubyforge_project: merb
121
+ rubygems_version: 1.3.1
122
+ signing_key:
123
+ specification_version: 2
124
+ summary: merb_paginate is a fork of will_paginate agnostic branch, refocused to work specifically with Merb
125
+ test_files: []
126
+