ramaze 2012.03.07 → 2012.04.14

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module Ramaze
2
- VERSION = "2012.03.07"
2
+ VERSION = "2012.04.14"
3
3
  end
@@ -7,7 +7,7 @@ path = File.expand_path('../', __FILE__)
7
7
  Gem::Specification.new do |s|
8
8
  s.name = 'ramaze'
9
9
  s.version = Ramaze::VERSION
10
- s.date = '2012-03-07'
10
+ s.date = '2012-04-14'
11
11
  s.authors = ['Michael \'manveru\' Fellinger']
12
12
  s.email = 'm.fellinger@gmail.com'
13
13
  s.summary = 'Ramaze is a simple and modular web framework'
@@ -1,6 +1,3 @@
1
- # Copyright (c) 2011 Michael Fellinger m.fellinger@gmail.com
2
- # All files in this distribution are subject to the terms of the MIT license.
3
-
4
1
  require File.expand_path('../../../../spec/helper', __FILE__)
5
2
  spec_require 'redis'
6
3
 
@@ -41,7 +38,7 @@ describe Ramaze::Cache::Redis do
41
38
  should 'store with ttl' do
42
39
  cache.store(:hello, @hello, :ttl => 0.2)
43
40
  cache.fetch(:hello).should == @hello
44
- sleep 0.3
41
+ sleep 0.2
45
42
  cache.fetch(:hello).should == nil
46
43
  end
47
44
 
@@ -59,4 +56,3 @@ describe Ramaze::Cache::Redis do
59
56
  klass.new.options[:answer].should == 42
60
57
  end
61
58
  end
62
-
@@ -16,6 +16,15 @@ class SpecHelperPaginateArray < Ramaze::Controller
16
16
  pager.navigation
17
17
  end
18
18
 
19
+ def custom_navigation
20
+ css = {:first => "TheFirst", :prev => "ThePrevious", :next => "TheNext",
21
+ :last => "TheLast", :number => "TheNumber",
22
+ :disabled =>"Severely Disabled", :current => "TheCurrent" }
23
+
24
+ pager = paginate(ALPHA, :css => css)
25
+ pager.navigation
26
+ end
27
+
19
28
  def iteration
20
29
  pager = paginate(ALPHA)
21
30
  out = []
@@ -67,5 +76,201 @@ describe Ramaze::Helper::Paginate do
67
76
  got = get('/array/iteration')
68
77
  got.body.scan(/\w+/).should == SpecHelperPaginateArray::ALPHA.first(10)
69
78
  end
79
+
80
+ it 'sets default css elements on page 1' do
81
+ doc = Hpricot(get('/array/navigation').body)
82
+ # Paginator outputs spans for disabled elements
83
+ # Since we're on the first page, the first two
84
+ # elements are spans, then a's
85
+ # Note that this is only valid for the first page since
86
+ # it doens't need lonks to first and prev
87
+ #
88
+ # Looking for spans first
89
+ spans = doc.search("//span")
90
+ first = spans.first[:class]
91
+ first.should == "first grey"
92
+
93
+ prev = spans[1][:class]
94
+ prev.should == "prev grey"
95
+
96
+ # Looking for a elements
97
+ as = doc.search("//a")
98
+ current = as.first[:class]
99
+ current.should == "current "
100
+
101
+ randomnumber = as[1][:class]
102
+ randomnumber.should == ""
103
+
104
+ nxt = as[3][:class]
105
+ nxt.should == "next"
106
+
107
+ last = as[4][:class]
108
+ last.should == "last"
109
+ end
110
+
111
+ it 'sets default css elements on page 2' do
112
+ doc = Hpricot(get('/array/navigation?pager=2').body)
113
+ # Paginator outputs spans for disabled elements
114
+ # Since we're on the second page, none are disabled
115
+ # Note that this is only valid for the second page since
116
+ # it will have all the links, while 1 and 3 have some disabled
117
+ #
118
+ # Looking for a elements
119
+ as = doc.search("//a")
120
+ first = as.first[:class]
121
+ first.should == "first"
122
+
123
+ prev = as[1][:class]
124
+ prev.should == "prev"
125
+
126
+ pg1 = as[2][:class]
127
+ pg1.should == ""
128
+
129
+ current = as[3][:class]
130
+ current.should == "current "
131
+
132
+ pg3 = as[4][:class]
133
+ pg3.should == ""
134
+
135
+ nxt = as[5][:class]
136
+ nxt.should == "next"
137
+
138
+ last = as[6][:class]
139
+ last.should == "last"
140
+ end
141
+
142
+ it 'sets default css elements on page 3' do
143
+ doc = Hpricot(get('/array/navigation?pager=3').body)
144
+ # Paginator outputs spans for disabled elements
145
+ # Since we're on the last page, last and next will be disabled
146
+ # Note that this is only valid for the third page
147
+ #
148
+ # Looking for a elements
149
+ as = doc.search("//a")
150
+ first = as.first[:class]
151
+ first.should == "first"
152
+
153
+ prev = as[1][:class]
154
+ prev.should == "prev"
155
+
156
+ pg1 = as[2][:class]
157
+ pg1.should == ""
158
+
159
+ pg2 = as[3][:class]
160
+ pg2.should == ""
161
+
162
+ current = as[4][:class]
163
+ current.should == "current "
164
+
165
+ # Looking for span elements
166
+ spans = doc.search("//span")
167
+ first = spans.first[:class]
168
+ first.should == "next grey"
169
+
170
+ last = spans[1][:class]
171
+ last.should == "last grey"
172
+
173
+ end
174
+
175
+ it 'sets our custom css elements for page 1' do
176
+ doc = Hpricot(get('/array/custom_navigation').body)
177
+ # Paginator outputs spans for disabled elements
178
+ # Since we're on the first page, the first two
179
+ # elements are spans, then a's
180
+ # Note that this is only valid for the first page since
181
+ # it doens't need lonks to first and prev
182
+ #
183
+ # Looking for spans first
184
+ spans = doc.search("//span")
185
+ first = spans.first[:class]
186
+ first.should.include? "TheFirst"
187
+ first.should.include? "Disabled"
188
+ first.should.include? "Severely"
189
+
190
+ prev = spans[1][:class]
191
+ prev.should.include? "Severely"
192
+ prev.should.include? "Disabled"
193
+ prev.should.include? "ThePrevious"
194
+
195
+ # Looking for a elements
196
+ as = doc.search("//a")
197
+ current = as.first[:class]
198
+ current.should.include? "TheCurrent"
199
+ current.should.include? "TheNumber"
200
+
201
+ randomnumber = as[1][:class]
202
+ randomnumber.should.include? "TheNumber"
203
+
204
+ nxt = as[3][:class]
205
+ nxt.should.include? "TheNext"
206
+
207
+ last = as[4][:class]
208
+ last.should.include? "TheLast"
209
+ end
210
+
211
+ it 'sets our custom css elements on page 2' do
212
+ doc = Hpricot(get('/array/custom_navigation?pager=2').body)
213
+ # Paginator outputs spans for disabled elements
214
+ # Since we're on the second page, none are disabled
215
+ # Note that this is only valid for the second page since
216
+ # it will have all the links, while 1 and 3 have some disabled
217
+ #
218
+ # Looking for a elements
219
+ as = doc.search("//a")
220
+ first = as.first[:class]
221
+ first.should == "TheFirst"
222
+
223
+ prev = as[1][:class]
224
+ prev.should == "ThePrevious"
225
+
226
+ pg1 = as[2][:class]
227
+ pg1.should == "TheNumber"
228
+
229
+ current = as[3][:class]
230
+ current.should == "TheCurrent TheNumber"
231
+
232
+ pg3 = as[4][:class]
233
+ pg3.should == "TheNumber"
234
+
235
+ nxt = as[5][:class]
236
+ nxt.should == "TheNext"
237
+
238
+ last = as[6][:class]
239
+ last.should == "TheLast"
240
+ end
241
+
242
+ it 'sets our custom css elements on page 3' do
243
+ doc = Hpricot(get('/array/custom_navigation?pager=3').body)
244
+ # Paginator outputs spans for disabled elements
245
+ # Since we're on the last page, last and next will be disabled
246
+ # Note that this is only valid for the third page
247
+ #
248
+ # Looking for a elements
249
+ as = doc.search("//a")
250
+ first = as.first[:class]
251
+ first.should == "TheFirst"
252
+
253
+ prev = as[1][:class]
254
+ prev.should == "ThePrevious"
255
+
256
+ pg1 = as[2][:class]
257
+ pg1.should == "TheNumber"
258
+
259
+ pg2 = as[3][:class]
260
+ pg2.should == "TheNumber"
261
+
262
+ current = as[4][:class]
263
+ current.should == "TheCurrent TheNumber"
264
+
265
+ # Looking for span elements
266
+ spans = doc.search("//span")
267
+ first = spans.first[:class]
268
+ first.should == "TheNext Severely Disabled"
269
+
270
+ last = spans[1][:class]
271
+ last.should == "TheLast Severely Disabled"
272
+
273
+ end
274
+
70
275
  end
71
276
  end
@@ -0,0 +1,58 @@
1
+ require File.expand_path('../../../../spec/helper', __FILE__)
2
+ spec_require 'sequel'
3
+
4
+ class SpecSession < Ramaze::Controller
5
+ map '/'
6
+ engine :None
7
+
8
+ def index
9
+ 'No session here'
10
+ end
11
+
12
+ def init
13
+ session[:counter] = 0
14
+ end
15
+
16
+ def view
17
+ session[:counter]
18
+ end
19
+
20
+ def increment
21
+ session[:counter] += 1
22
+ end
23
+
24
+ def decrement
25
+ session[:counter] -= 1
26
+ end
27
+
28
+ def reset
29
+ session.clear
30
+ end
31
+ end
32
+
33
+ Ramaze::Cache.options.session = Ramaze::Cache::LocalMemCache
34
+
35
+ describe 'Sessions with Ramaze::Cache::LocalMemCache' do
36
+ behaves_like :rack_test
37
+
38
+ should 'initiate session as needed' do
39
+ get '/'
40
+ last_response.body.should == 'No session here'
41
+ last_response['Set-Cookie'].should == nil
42
+
43
+ get('/init')
44
+ last_response.body.should == '0'
45
+
46
+ 1.upto(10) do |n|
47
+ get('/increment').body.should == n.to_s
48
+ end
49
+
50
+ get('/reset')
51
+ get('/view').body.should == ''
52
+ get('/init').body.should == '0'
53
+
54
+ -1.downto(-10) do |n|
55
+ get('/decrement').body.should == n.to_s
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,58 @@
1
+ require File.expand_path('../../../../spec/helper', __FILE__)
2
+ spec_require 'sequel'
3
+
4
+ class SpecSession < Ramaze::Controller
5
+ map '/'
6
+ engine :None
7
+
8
+ def index
9
+ 'No session here'
10
+ end
11
+
12
+ def init
13
+ session[:counter] = 0
14
+ end
15
+
16
+ def view
17
+ session[:counter]
18
+ end
19
+
20
+ def increment
21
+ session[:counter] += 1
22
+ end
23
+
24
+ def decrement
25
+ session[:counter] -= 1
26
+ end
27
+
28
+ def reset
29
+ session.clear
30
+ end
31
+ end
32
+
33
+ Ramaze::Cache.options.session = Ramaze::Cache::LRU
34
+
35
+ describe 'Sessions with Ramaze::Cache::LRU' do
36
+ behaves_like :rack_test
37
+
38
+ should 'initiate session as needed' do
39
+ get '/'
40
+ last_response.body.should == 'No session here'
41
+ last_response['Set-Cookie'].should == nil
42
+
43
+ get('/init')
44
+ last_response.body.should == '0'
45
+
46
+ 1.upto(10) do |n|
47
+ get('/increment').body.should == n.to_s
48
+ end
49
+
50
+ get('/reset')
51
+ get('/view').body.should == ''
52
+ get('/init').body.should == '0'
53
+
54
+ -1.downto(-10) do |n|
55
+ get('/decrement').body.should == n.to_s
56
+ end
57
+ end
58
+ end
@@ -40,7 +40,7 @@ end
40
40
 
41
41
  Ramaze::Cache.options.session = Ramaze::Cache::MemCache
42
42
 
43
- describe Innate::Session do
43
+ describe 'Sessions with Ramaze::Cache::MemCache' do
44
44
  behaves_like :rack_test
45
45
 
46
46
  should 'initiate session as needed' do
@@ -0,0 +1,63 @@
1
+ require File.expand_path('../../../../spec/helper', __FILE__)
2
+ spec_require 'redis'
3
+
4
+ spec_precondition 'Redis is running' do
5
+ cache = Redis.new
6
+ cache['active'] = true
7
+ end
8
+
9
+ class SpecSession < Ramaze::Controller
10
+ map '/'
11
+ engine :None
12
+
13
+ def index
14
+ 'No session here'
15
+ end
16
+
17
+ def init
18
+ session[:counter] = 0
19
+ end
20
+
21
+ def view
22
+ session[:counter]
23
+ end
24
+
25
+ def increment
26
+ session[:counter] += 1
27
+ end
28
+
29
+ def decrement
30
+ session[:counter] -= 1
31
+ end
32
+
33
+ def reset
34
+ session.clear
35
+ end
36
+ end
37
+
38
+ Ramaze::Cache.options.session = Ramaze::Cache::Redis
39
+
40
+ describe 'Sessions with Ramaze::Cache::Redis' do
41
+ behaves_like :rack_test
42
+
43
+ should 'initiate session as needed' do
44
+ get '/'
45
+ last_response.body.should == 'No session here'
46
+ last_response['Set-Cookie'].should == nil
47
+
48
+ get('/init')
49
+ last_response.body.should == '0'
50
+
51
+ 1.upto(10) do |n|
52
+ get('/increment').body.should == n.to_s
53
+ end
54
+
55
+ get('/reset')
56
+ get('/view').body.should == ''
57
+ get('/init').body.should == '0'
58
+
59
+ -1.downto(-10) do |n|
60
+ get('/decrement').body.should == n.to_s
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,60 @@
1
+ require File.expand_path('../../../../spec/helper', __FILE__)
2
+ spec_require 'sequel'
3
+
4
+ class SpecSession < Ramaze::Controller
5
+ map '/'
6
+ engine :None
7
+
8
+ def index
9
+ 'No session here'
10
+ end
11
+
12
+ def init
13
+ session[:counter] = 0
14
+ end
15
+
16
+ def view
17
+ session[:counter]
18
+ end
19
+
20
+ def increment
21
+ session[:counter] += 1
22
+ end
23
+
24
+ def decrement
25
+ session[:counter] -= 1
26
+ end
27
+
28
+ def reset
29
+ session.clear
30
+ end
31
+ end
32
+
33
+ Ramaze::Cache.options.session = Ramaze::Cache::Sequel.using(
34
+ :connection => Sequel.sqlite(':memory:')
35
+ )
36
+
37
+ describe 'Sessions with Ramaze::Cache::Sequel' do
38
+ behaves_like :rack_test
39
+
40
+ should 'initiate session as needed' do
41
+ get '/'
42
+ last_response.body.should == 'No session here'
43
+ last_response['Set-Cookie'].should == nil
44
+
45
+ get('/init')
46
+ last_response.body.should == '0'
47
+
48
+ 1.upto(10) do |n|
49
+ get('/increment').body.should == n.to_s
50
+ end
51
+
52
+ get('/reset')
53
+ get('/view').body.should == ''
54
+ get('/init').body.should == '0'
55
+
56
+ -1.downto(-10) do |n|
57
+ get('/decrement').body.should == n.to_s
58
+ end
59
+ end
60
+ end