peiji-san 1.1.1 → 1.2.0.pre

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 373aefbd57bea1d12fb01e0b27685991c7954a97
4
+ data.tar.gz: 69656282f80bc4eb90572f2e5dc181a7c5bf7155
5
+ SHA512:
6
+ metadata.gz: ddfaae2205eea8af0480a2916ab87bf32375241740a3285f6af7aace21ba9b9c3717d17c00e3ac4e2c4390805b0fa09ad8df4ce5bb8f2fd080f7d3450988323b
7
+ data.tar.gz: fc7ae2eb5f36cf8bee6a473afe2efd7b0c3481fa5ff0f4be9a2b78a0e9d4be751b66348a9fa4e06efd07431c6559060a8876642c5b59eaa3ebdaef80957a2c26
data/lib/peiji_san.rb CHANGED
@@ -110,12 +110,19 @@ module PeijiSan
110
110
  page = page.blank? ? 1 : page.to_i
111
111
  entries_per_page = entries_per_page || self.entries_per_page || ENTRIES_PER_PAGE
112
112
 
113
- entries = scoped
113
+ entries = limit(entries_per_page).offset((page - 1) * entries_per_page)
114
+
114
115
  entries.extend(PeijiSan::PaginationMethods)
115
116
  entries.current_page = page
116
117
  entries.entries_per_page = entries_per_page
117
- entries.scope_without_pagination = scoped
118
-
119
- entries.limit(entries_per_page).offset((page - 1) * entries_per_page)
118
+ entries.scope_without_pagination = _use_scoped? ? scoped : all
119
+
120
+ entries
121
+ end
122
+
123
+ private
124
+
125
+ def _use_scoped?
126
+ !const_defined?(:ActiveRecord) || ActiveRecord::VERSION::MAJOR < 4
120
127
  end
121
128
  end
@@ -60,7 +60,7 @@ module PeijiSan
60
60
  normalized_url_options = if respond_to?(:controller) # Rails
61
61
  url_for(url_options)
62
62
  else # Sinatra
63
- root_path = env['SCRIPT_NAME'].blank? ? "/" : env["SCRIPT_NAME"]
63
+ root_path = env['PATH_INFO'].blank? ? "/" : env["PATH_INFO"]
64
64
  url_for(root_path, url_options)
65
65
  end
66
66
 
@@ -76,8 +76,8 @@ module PeijiSan
76
76
  # What follows is a very simplistic implementation of link_to
77
77
  link_text, url, html_options = arguments[0..2]
78
78
  html_options[:href] = url
79
- attr_string = html_options.map do | attribute, value |
80
- '%s="%s"' % [Rack::Utils.escape_html(attribute), Rack::Utils.escape_html(value)]
79
+ attr_string = html_options.keys.sort.map do |attribute|
80
+ '%s="%s"' % [Rack::Utils.escape_html(attribute), Rack::Utils.escape_html(html_options[attribute])]
81
81
  end.join(' ')
82
82
 
83
83
  # Compose the tag
@@ -29,7 +29,11 @@ describe "The PeijiSan extended scope" do
29
29
  it "returns entries for the specified page" do
30
30
  page_1 = Member.page(1)
31
31
  page_1.length.must_equal 10
32
- page_1.must_equal Member.find(:all, :offset => 0, :limit => 10)
32
+ if ActiveRecord::VERSION::MAJOR < 4
33
+ page_1.must_equal Member.find(:all, :offset => 0, :limit => 10)
34
+ else
35
+ page_1.to_a.must_equal Member.offset(0).limit(10).to_a
36
+ end
33
37
  end
34
38
 
35
39
  it "returns the correct count of pages" do
@@ -90,8 +94,13 @@ describe "The PeijiSan extended scope" do
90
94
  Member.all_like_krs_1.page(1).page_count.must_equal 11
91
95
  Member.all_like_krs_1.but_ending_with_9.page(2).page_count.must_equal 1
92
96
 
93
- Member.all_like_krs_1.page(2).must_equal Member.find(:all, :conditions => "name LIKE 'KRS 1%'", :offset => 10, :limit => 10)
94
- Member.all_like_krs_1.but_ending_with_9.page(1).must_equal Member.find(:all, :conditions => "name LIKE 'KRS 1%' AND name LIKE '%9'", :offset => 0, :limit => 10)
97
+ if ActiveRecord::VERSION::MAJOR < 4
98
+ Member.all_like_krs_1.page(2).must_equal Member.find(:all, :conditions => "name LIKE 'KRS 1%'", :offset => 10, :limit => 10)
99
+ Member.all_like_krs_1.but_ending_with_9.page(1).must_equal Member.find(:all, :conditions => "name LIKE 'KRS 1%' AND name LIKE '%9'", :offset => 0, :limit => 10)
100
+ else
101
+ Member.all_like_krs_1.page(2).to_a.must_equal Member.where("name LIKE 'KRS 1%'").offset(10).limit(10).to_a
102
+ Member.all_like_krs_1.but_ending_with_9.page(1).to_a.must_equal Member.where("name LIKE 'KRS 1%' AND name LIKE '%9'").offset(0).limit(10).to_a
103
+ end
95
104
  end
96
105
 
97
106
  it "should still work when chained through an association proxy" do
data/test/sinatra_test.rb CHANGED
@@ -18,6 +18,14 @@ class SimplisticApp < Sinatra::Base
18
18
  collection.stubs(:page_count).returns(125)
19
19
  link_to_page(2, collection)
20
20
  end
21
+
22
+ get '/something' do
23
+ collection = stub('Articles in a subdirectory')
24
+ collection.stubs(:current_page?).with(1).returns(false)
25
+ collection.stubs(:current_page?).with(2).returns(false)
26
+ collection.stubs(:page_count).returns(125)
27
+ link_to_page(2, collection)
28
+ end
21
29
  end
22
30
 
23
31
  ENV['RACK_ENV'] = 'test'
@@ -34,6 +42,12 @@ describe "A Sinatra app that uses Peiji-San" do
34
42
  Rack::Utils.parse_query(query)
35
43
  end
36
44
 
45
+ it "has it's link_to_page method working in subdirectories" do
46
+ get '/something'
47
+ last_response.status.must_equal 200
48
+ assert_equal '<a href="&#x2F;something?page=2">2</a>', last_response.body
49
+ end
50
+
37
51
  it "has it's link_to_page method put in place and operational" do
38
52
  get '/'
39
53
  last_response.status.must_equal 200
data/test/test_helper.rb CHANGED
@@ -9,7 +9,7 @@ module PeijiSanTest
9
9
 
10
10
  require 'minitest/autorun'
11
11
  require 'minitest/spec'
12
- require 'mocha'
12
+ require 'mocha/setup'
13
13
 
14
14
  require 'active_support'
15
15
  require 'active_record'
@@ -58,8 +58,13 @@ class Member < ActiveRecord::Base
58
58
  extend PeijiSan
59
59
  self.entries_per_page = 10
60
60
 
61
- scope :all_like_krs_1, where("name LIKE 'KRS 1%'")
62
- scope :but_ending_with_9, where("name LIKE '%9'")
61
+ if ActiveRecord::VERSION::MAJOR < 4
62
+ scope :all_like_krs_1, where("name LIKE 'KRS 1%'")
63
+ scope :but_ending_with_9, where("name LIKE '%9'")
64
+ else
65
+ scope :all_like_krs_1, -> { where("name LIKE 'KRS 1%'") }
66
+ scope :but_ending_with_9, -> { where("name LIKE '%9'") }
67
+ end
63
68
 
64
69
  has_many :works
65
70
  end
@@ -68,5 +73,9 @@ class Work < ActiveRecord::Base
68
73
  extend PeijiSan
69
74
  self.entries_per_page = 5
70
75
 
71
- scope :uploaded, where(:status => 'uploaded')
76
+ if ActiveRecord::VERSION::MAJOR < 4
77
+ scope :uploaded, where(:status => 'uploaded')
78
+ else
79
+ scope :uploaded, -> { where(:status => 'uploaded') }
80
+ end
72
81
  end
@@ -68,12 +68,12 @@ describe "PeijiSan::ViewHelper::link_to_page" do
68
68
 
69
69
  it "should return a link with the class current if it's for the currently selected page" do
70
70
  collection.stubs(:current_page?).with(2).returns(true)
71
- link_to_page(2, collection).must_equal '<a href="/collections?page=2" class="current">2</a>'
71
+ link_to_page(2, collection).must_equal '<a class="current" href="/collections?page=2">2</a>'
72
72
  end
73
73
 
74
74
  it "should return a link with the class current if it's for the currently selected page" do
75
75
  collection.stubs(:current_page?).with(2).returns(true)
76
- link_to_page(2, collection, :current_class => 'looking_at').must_equal '<a href="/collections?page=2" class="looking_at">2</a>'
76
+ link_to_page(2, collection, :current_class => 'looking_at').must_equal '<a class="looking_at" href="/collections?page=2">2</a>'
77
77
  end
78
78
  end
79
79
 
@@ -158,7 +158,7 @@ describe "ApplicationHelper, when overriding defaults" do
158
158
 
159
159
  it "should return a link with the class current if it's for the currently selected page" do
160
160
  collection.stubs(:current_page?).with(2).returns(true)
161
- link_to_page(2, collection, :current_class => 'looking_at').must_equal '<a href="/collections?pagina=2#dude_so_many_pages" class="looking_at">2</a>'
161
+ link_to_page(2, collection, :current_class => 'looking_at').must_equal '<a class="looking_at" href="/collections?pagina=2#dude_so_many_pages">2</a>'
162
162
  end
163
163
 
164
164
  it "should return a list of page numbers that should be included in the pagination list with the specified number of :max_visible" do
metadata CHANGED
@@ -1,184 +1,182 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: peiji-san
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 1
7
- - 1
8
- - 1
9
- segments_generated: true
10
- version: 1.1.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.2.0.pre
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Eloy Duran
14
8
  - Manfred Stienstra
15
9
  - Julik Tarkhanov
16
10
  autorequire:
17
11
  bindir: bin
18
12
  cert_chain: []
19
-
20
- date: 2012-01-23 00:00:00 +01:00
21
- default_executable:
22
- dependencies:
23
- - !ruby/object:Gem::Dependency
24
- version_requirements: &id001 !ruby/object:Gem::Requirement
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- segments:
29
- - 0
30
- segments_generated: true
31
- version: "0"
32
- requirement: *id001
13
+ date: 2013-07-31 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
33
16
  name: minitest
34
- prerelease: false
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
35
22
  type: :development
36
- - !ruby/object:Gem::Dependency
37
- version_requirements: &id002 !ruby/object:Gem::Requirement
38
- requirements:
39
- - - ">="
40
- - !ruby/object:Gem::Version
41
- segments:
42
- - 0
43
- segments_generated: true
44
- version: "0"
45
- requirement: *id002
46
- name: mocha
47
23
  prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - '>='
27
+ - !ruby/object:Gem::Version
28
+ version: '0'
29
+ - !ruby/object:Gem::Dependency
30
+ name: mocha
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - '>='
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
48
36
  type: :development
49
- - !ruby/object:Gem::Dependency
50
- version_requirements: &id003 !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- segments:
55
- - 0
56
- segments_generated: true
57
- version: "0"
58
- requirement: *id003
59
- name: rake
60
37
  prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ - !ruby/object:Gem::Dependency
44
+ name: rake
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
61
50
  type: :development
62
- - !ruby/object:Gem::Dependency
63
- version_requirements: &id004 !ruby/object:Gem::Requirement
64
- requirements:
65
- - - ">="
66
- - !ruby/object:Gem::Version
67
- segments:
68
- - 0
69
- segments_generated: true
70
- version: "0"
71
- requirement: *id004
72
- name: rack-test
73
51
  prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ - !ruby/object:Gem::Dependency
58
+ name: rack-test
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
74
64
  type: :development
75
- - !ruby/object:Gem::Dependency
76
- version_requirements: &id005 !ruby/object:Gem::Requirement
77
- requirements:
78
- - - ">="
79
- - !ruby/object:Gem::Version
80
- segments:
81
- - 0
82
- segments_generated: true
83
- version: "0"
84
- requirement: *id005
85
- name: rdoc
86
65
  prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ - !ruby/object:Gem::Dependency
72
+ name: rdoc
73
+ requirement: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
87
78
  type: :development
88
- - !ruby/object:Gem::Dependency
89
- version_requirements: &id006 !ruby/object:Gem::Requirement
90
- requirements:
91
- - - ">="
92
- - !ruby/object:Gem::Version
93
- segments:
94
- - 3
95
- - 1
96
- segments_generated: true
97
- version: "3.1"
98
- requirement: *id006
99
- name: activesupport
100
79
  prerelease: false
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ - !ruby/object:Gem::Dependency
86
+ name: activesupport
87
+ requirement: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '3.1'
101
92
  type: :development
102
- - !ruby/object:Gem::Dependency
103
- version_requirements: &id007 !ruby/object:Gem::Requirement
104
- requirements:
105
- - - ">="
106
- - !ruby/object:Gem::Version
107
- segments:
108
- - 3
109
- - 1
110
- segments_generated: true
111
- version: "3.1"
112
- requirement: *id007
113
- name: activerecord
114
93
  prerelease: false
94
+ version_requirements: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '3.1'
99
+ - !ruby/object:Gem::Dependency
100
+ name: activerecord
101
+ requirement: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '3.1'
115
106
  type: :development
116
- - !ruby/object:Gem::Dependency
117
- version_requirements: &id008 !ruby/object:Gem::Requirement
118
- requirements:
119
- - - ">="
120
- - !ruby/object:Gem::Version
121
- segments:
122
- - 3
123
- - 1
124
- segments_generated: true
125
- version: "3.1"
126
- requirement: *id008
127
- name: actionpack
128
107
  prerelease: false
108
+ version_requirements: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '3.1'
113
+ - !ruby/object:Gem::Dependency
114
+ name: actionpack
115
+ requirement: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - '>='
118
+ - !ruby/object:Gem::Version
119
+ version: '3.1'
129
120
  type: :development
130
- - !ruby/object:Gem::Dependency
131
- version_requirements: &id009 !ruby/object:Gem::Requirement
132
- requirements:
133
- - - ">="
134
- - !ruby/object:Gem::Version
135
- segments:
136
- - 0
137
- segments_generated: true
138
- version: "0"
139
- requirement: *id009
140
- name: sqlite3
141
121
  prerelease: false
122
+ version_requirements: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '3.1'
127
+ - !ruby/object:Gem::Dependency
128
+ name: sqlite3
129
+ requirement: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
142
134
  type: :development
143
- - !ruby/object:Gem::Dependency
144
- version_requirements: &id010 !ruby/object:Gem::Requirement
145
- requirements:
146
- - - ">="
147
- - !ruby/object:Gem::Version
148
- segments:
149
- - 0
150
- segments_generated: true
151
- version: "0"
152
- requirement: *id010
153
- name: sinatra
154
135
  prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - '>='
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ - !ruby/object:Gem::Dependency
142
+ name: sinatra
143
+ requirement: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - '>='
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
155
148
  type: :development
156
- - !ruby/object:Gem::Dependency
157
- version_requirements: &id011 !ruby/object:Gem::Requirement
158
- requirements:
159
- - - ">="
160
- - !ruby/object:Gem::Version
161
- segments:
162
- - 0
163
- segments_generated: true
164
- version: "0"
165
- requirement: *id011
166
- name: tobias-sinatra-url-for
167
149
  prerelease: false
150
+ version_requirements: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - '>='
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ - !ruby/object:Gem::Dependency
156
+ name: tobias-sinatra-url-for
157
+ requirement: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - '>='
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
168
162
  type: :development
163
+ prerelease: false
164
+ version_requirements: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - '>='
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
169
169
  description:
170
- email:
170
+ email:
171
171
  - eloy.de.enige@gmail.com
172
172
  - manfred@fngtps.com
173
173
  - me@julik.nl
174
174
  executables: []
175
-
176
175
  extensions: []
177
-
178
- extra_rdoc_files:
176
+ extra_rdoc_files:
179
177
  - LICENSE
180
178
  - README.rdoc
181
- files:
179
+ files:
182
180
  - LICENSE
183
181
  - README.rdoc
184
182
  - Rakefile
@@ -189,37 +187,28 @@ files:
189
187
  - test/sinatra_test.rb
190
188
  - test/test_helper.rb
191
189
  - test/view_helper_test.rb
192
- has_rdoc: true
193
190
  homepage: http://github.com/Fingertips/peiji-san
194
191
  licenses: []
195
-
192
+ metadata: {}
196
193
  post_install_message:
197
194
  rdoc_options: []
198
-
199
- require_paths:
195
+ require_paths:
200
196
  - lib
201
- required_ruby_version: !ruby/object:Gem::Requirement
202
- requirements:
203
- - - ">="
204
- - !ruby/object:Gem::Version
205
- segments:
206
- - 0
207
- segments_generated: true
208
- version: "0"
209
- required_rubygems_version: !ruby/object:Gem::Requirement
210
- requirements:
211
- - - ">="
212
- - !ruby/object:Gem::Version
213
- segments:
214
- - 0
215
- segments_generated: true
216
- version: "0"
197
+ required_ruby_version: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - '>='
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ required_rubygems_version: !ruby/object:Gem::Requirement
203
+ requirements:
204
+ - - '>'
205
+ - !ruby/object:Gem::Version
206
+ version: 1.3.1
217
207
  requirements: []
218
-
219
208
  rubyforge_project:
220
- rubygems_version: 1.3.6
209
+ rubygems_version: 2.0.2
221
210
  signing_key:
222
- specification_version: 3
223
- summary: PeijiSan is a Rails plugin which uses named scopes to create a thin pagination layer.
211
+ specification_version: 4
212
+ summary: PeijiSan is a Rails plugin which uses named scopes to create a thin pagination
213
+ layer.
224
214
  test_files: []
225
-