jquids 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/.rspec +2 -0
- data/MIT-LICENSE +20 -0
- data/README.md +213 -0
- data/Rakefile +44 -0
- data/init.rb +1 -0
- data/jquids.gemspec +17 -0
- data/lib/jquids.rb +9 -0
- data/lib/jquids/constants/formats.rb +74 -0
- data/lib/jquids/constants/jq_versions.rb +3 -0
- data/lib/jquids/constants/styles.rb +29 -0
- data/lib/jquids/constants/timepicker_tags.rb +3 -0
- data/lib/jquids/constants/ui_versions.rb +3 -0
- data/lib/jquids/constants/version.rb +3 -0
- data/lib/jquids/errors/not_a_known_format.rb +8 -0
- data/lib/jquids/errors/not_a_known_style.rb +2 -0
- data/lib/jquids/form_helpers.rb +70 -0
- data/lib/jquids/includes_helper.rb +146 -0
- data/lib/jquids/jquids.rb +126 -0
- data/spec/jquids/form_helpers_spec.rb +343 -0
- data/spec/jquids/includes_helper_spec.rb +649 -0
- data/spec/jquids/jquids_spec.rb +441 -0
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +23 -0
- metadata +90 -0
@@ -0,0 +1,441 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe Jquids do
|
4
|
+
include ActionView::Helpers::AssetTagHelper
|
5
|
+
include Jquids
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
Jquids.instance_variable_set :@jquids_format, nil
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "The format function where:" do
|
12
|
+
|
13
|
+
describe "The default format" do
|
14
|
+
|
15
|
+
it "should return the natural format" do
|
16
|
+
Jquids.format.should == {:date => "%B %d, %Y", :time => " %I:%M %p", :js_date => "MM dd, yy", :tr_js_time => "hh:mm TT", :ampm => true}
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "Setting the format" do
|
22
|
+
|
23
|
+
describe "with an invalid key" do
|
24
|
+
|
25
|
+
it "should raise an Jquids::NotAKnownFormat error" do
|
26
|
+
expect{ Jquids.format=(:not_a_valid_key) }.to raise_error(Jquids::NotAKnownFormat, "Jquids: Unrecognized format specification: not_a_valid_key")
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
Jquids::FORMATS.each do |format|
|
32
|
+
|
33
|
+
describe "to '#{format[0]}'" do
|
34
|
+
|
35
|
+
it "should start with a default of 'natural' format" do
|
36
|
+
Jquids.format.should == {:date => "%B %d, %Y", :time => " %I:%M %p", :js_date => "MM dd, yy", :tr_js_time => "hh:mm TT", :ampm => true}
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should set the format to '#{format[0]}' when 'format=' is called" do
|
40
|
+
Jquids.format=(format[0])
|
41
|
+
Jquids.format.should == format[1]
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "The date_format_string function where:" do
|
53
|
+
|
54
|
+
describe "The format is the default state" do
|
55
|
+
|
56
|
+
describe "when the time input is blank" do
|
57
|
+
|
58
|
+
it "should return '%B %d, %Y'" do
|
59
|
+
Jquids.date_format_string.should == "%B %d, %Y"
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "when the time input is false" do
|
65
|
+
|
66
|
+
it "should return '%B %d, %Y'" do
|
67
|
+
Jquids.date_format_string(false).should == "%B %d, %Y"
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "when the time input is true" do
|
73
|
+
|
74
|
+
it "should return '%B %d, %Y %I:%M %p'" do
|
75
|
+
Jquids.date_format_string(true).should == "%B %d, %Y %I:%M %p"
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
describe "The format is set to ':american'" do
|
83
|
+
|
84
|
+
before(:each) do
|
85
|
+
Jquids.format= :american
|
86
|
+
end
|
87
|
+
|
88
|
+
describe "when the time input is blank" do
|
89
|
+
|
90
|
+
it "should return '%m/%d/%Y'" do
|
91
|
+
Jquids.date_format_string.should == "%m/%d/%Y"
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
describe "when the time input is false" do
|
97
|
+
|
98
|
+
it "should return '%m/%d/%Y'" do
|
99
|
+
Jquids.date_format_string(false).should == "%m/%d/%Y"
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
describe "when the time input is true" do
|
105
|
+
|
106
|
+
it "should return '%m/%d/%Y %I:%M %p'" do
|
107
|
+
Jquids.date_format_string(true).should == "%m/%d/%Y %I:%M %p"
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
|
116
|
+
describe "Formating a date where:" do
|
117
|
+
|
118
|
+
describe "using the default format" do
|
119
|
+
|
120
|
+
describe "for '01/01/2001'" do
|
121
|
+
|
122
|
+
it "should return 'January 01, 2001'" do
|
123
|
+
Jquids.format_date('01/01/2001'.to_date).should == "January 01, 2001"
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
127
|
+
|
128
|
+
describe "for '01/01/2001 11:00 PM'" do
|
129
|
+
|
130
|
+
it "should return 'January 01, 2001 11:00 PM'" do
|
131
|
+
Jquids.format_date('01/01/2001 11:00 PM'.to_time).should == "January 01, 2001 11:00 PM"
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
135
|
+
|
136
|
+
describe "for '01/01/2001 11:00 PM'" do
|
137
|
+
|
138
|
+
it "should return 'January 01, 2001 11:00 PM'" do
|
139
|
+
Jquids.format_date(DateTime.parse('01/01/2001 11:00 PM')).should == "January 01, 2001 11:00 PM"
|
140
|
+
end
|
141
|
+
|
142
|
+
end
|
143
|
+
|
144
|
+
end
|
145
|
+
|
146
|
+
describe "using the :american format" do
|
147
|
+
|
148
|
+
before(:each) do
|
149
|
+
Jquids.format= :american
|
150
|
+
end
|
151
|
+
|
152
|
+
describe "for '01/01/2001'" do
|
153
|
+
|
154
|
+
it "should return '01/01/2001'" do
|
155
|
+
Jquids.format_date('01/01/2001'.to_date).should == "01/01/2001"
|
156
|
+
end
|
157
|
+
|
158
|
+
end
|
159
|
+
|
160
|
+
describe "for '01/01/2001 11:00 PM'" do
|
161
|
+
|
162
|
+
it "should return '01/01/2001 11:00 PM'" do
|
163
|
+
Jquids.format_date('01/01/2001 11:00 PM'.to_time).should == "01/01/2001 11:00 PM"
|
164
|
+
end
|
165
|
+
|
166
|
+
end
|
167
|
+
|
168
|
+
describe "for a time of 01/01/2001 11:00 PM" do
|
169
|
+
|
170
|
+
it "should return '01/01/2001 11:00 PM'" do
|
171
|
+
Jquids.format_date(DateTime.parse('01/01/2001 11:00 PM')).should == "01/01/2001 11:00 PM"
|
172
|
+
end
|
173
|
+
|
174
|
+
end
|
175
|
+
|
176
|
+
end
|
177
|
+
|
178
|
+
end
|
179
|
+
|
180
|
+
describe "The format_time function where:" do
|
181
|
+
|
182
|
+
describe "when given 'garbage'" do
|
183
|
+
|
184
|
+
it "should return 'garbage'" do
|
185
|
+
Jquids.format_time('garbage').should == 'garbage'
|
186
|
+
end
|
187
|
+
|
188
|
+
end
|
189
|
+
|
190
|
+
describe "when given a date (01/01/2001) with no options" do
|
191
|
+
|
192
|
+
it "should return 'January 01, 2001'" do
|
193
|
+
Jquids.format_time('01/01/2001'.to_date).should == 'January 01, 2001'
|
194
|
+
end
|
195
|
+
|
196
|
+
end
|
197
|
+
|
198
|
+
describe "when given a date (01/01/2001) with options (:time => false)" do
|
199
|
+
|
200
|
+
it "should return 'January 01, 2001'" do
|
201
|
+
Jquids.format_time('01/01/2001'.to_date, :time => false).should == 'January 01, 2001'
|
202
|
+
end
|
203
|
+
|
204
|
+
end
|
205
|
+
|
206
|
+
describe "when given a date (01/01/2001) with options (:time => true)" do
|
207
|
+
|
208
|
+
it "should return 'January 01, 2001'" do
|
209
|
+
Jquids.format_time('01/01/2001'.to_date, :time => true).should == 'January 01, 2001'
|
210
|
+
end
|
211
|
+
|
212
|
+
end
|
213
|
+
|
214
|
+
describe "when given a time (01/01/2001 11:00) with options (:time => true)" do
|
215
|
+
|
216
|
+
it "should return 'January 01, 2001 11:00 AM'" do
|
217
|
+
Jquids.format_time('01/01/2001 11:00 AM'.to_time, {:time => true}).should == 'January 01, 2001 11:00 AM'
|
218
|
+
end
|
219
|
+
|
220
|
+
end
|
221
|
+
|
222
|
+
describe "when given a time (01/01/2001 11:00) with options (:time => false)" do
|
223
|
+
|
224
|
+
it "should return 'January 01, 2001'" do
|
225
|
+
Jquids.format_time('01/01/2001 11:00 AM'.to_time, {:time => false}).should == 'January 01, 2001'
|
226
|
+
end
|
227
|
+
|
228
|
+
end
|
229
|
+
|
230
|
+
end
|
231
|
+
|
232
|
+
describe "The 'jquids_process_options' function" do
|
233
|
+
|
234
|
+
describe "with :default_tim" do
|
235
|
+
|
236
|
+
describe "equaling Time.parse('January 1, 2001 5:00 PM')" do
|
237
|
+
|
238
|
+
it "returns {:datepicker_options => {:defaultDate => 'January 01, 2001'}, :timepicker_options => {:hour => 5, :minute => 0, :second => 0}}" do
|
239
|
+
Jquids.jquids_process_options({:default_time => Time.parse("January 1, 2001 5:00 PM")}).should ==
|
240
|
+
{:datepicker_options => {:defaultDate => 'January 01, 2001'}, :timepicker_options => {:hour => 17, :minute => 0, :second => 0}}
|
241
|
+
end
|
242
|
+
|
243
|
+
end
|
244
|
+
|
245
|
+
describe "equaling Date.parse('January 1, 2001 5:00 PM')" do
|
246
|
+
|
247
|
+
it "returns {:datepicker_options => {:defaultDate => 'January 01, 2001'}}" do
|
248
|
+
Jquids.jquids_process_options({:default_time => Date.parse("January 1, 2001 5:00 PM")}).should ==
|
249
|
+
{:datepicker_options => {:defaultDate => 'January 01, 2001'}}
|
250
|
+
end
|
251
|
+
|
252
|
+
end
|
253
|
+
|
254
|
+
describe "equaling 'pancakes'" do
|
255
|
+
|
256
|
+
it "returns {:datepicker_options => {:defaultDate => 'pancakes'}}" do
|
257
|
+
Jquids.jquids_process_options({:default_time => 'pancakes'}).should ==
|
258
|
+
{:datepicker_options => {:defaultDate => 'pancakes'}}
|
259
|
+
end
|
260
|
+
|
261
|
+
end
|
262
|
+
|
263
|
+
end
|
264
|
+
|
265
|
+
describe "with :popup" do
|
266
|
+
|
267
|
+
describe "equaling 'force'" do
|
268
|
+
|
269
|
+
it "should return :readonly => true" do
|
270
|
+
Jquids.jquids_process_options({:popup => "force"}).should == {:readonly => true}
|
271
|
+
end
|
272
|
+
|
273
|
+
end
|
274
|
+
|
275
|
+
describe "equaling :force" do
|
276
|
+
|
277
|
+
it "should return :readonly => true" do
|
278
|
+
Jquids.jquids_process_options({:popup => :force}).should == {:readonly => true}
|
279
|
+
end
|
280
|
+
|
281
|
+
end
|
282
|
+
|
283
|
+
describe "equaling 'pancakes'" do
|
284
|
+
|
285
|
+
it "should return :readonly => true" do
|
286
|
+
Jquids.jquids_process_options({:popup => 'pancakes'}).should == {}
|
287
|
+
end
|
288
|
+
|
289
|
+
end
|
290
|
+
|
291
|
+
describe "equaling :pancakes" do
|
292
|
+
|
293
|
+
it "should return :readonly => true" do
|
294
|
+
Jquids.jquids_process_options({:popup => :pancakes}).should == {}
|
295
|
+
end
|
296
|
+
|
297
|
+
end
|
298
|
+
|
299
|
+
end
|
300
|
+
|
301
|
+
describe "with :minute_interval" do
|
302
|
+
|
303
|
+
describe "equaling 15" do
|
304
|
+
|
305
|
+
it "returns :timepicker_options => {:stepMinute => 15}" do
|
306
|
+
Jquids.jquids_process_options({:minute_interval => 15}).should == {:timepicker_options => {:stepMinute => 15}}
|
307
|
+
end
|
308
|
+
|
309
|
+
end
|
310
|
+
|
311
|
+
describe "equaling 0.15" do
|
312
|
+
|
313
|
+
it "returns :timepicker_options => {:stepMinute => 15}" do
|
314
|
+
Jquids.jquids_process_options({:minute_interval => 0.15}).should == {:timepicker_options => {:stepMinute => 0.15}}
|
315
|
+
end
|
316
|
+
|
317
|
+
end
|
318
|
+
|
319
|
+
describe "equaling 'pancakes'" do
|
320
|
+
|
321
|
+
it "returns {}" do
|
322
|
+
Jquids.jquids_process_options({:minute_interval => "pancakes"}).should == {}
|
323
|
+
end
|
324
|
+
|
325
|
+
end
|
326
|
+
|
327
|
+
end
|
328
|
+
|
329
|
+
describe "with :year_range" do
|
330
|
+
|
331
|
+
describe "equals 2000..2020" do
|
332
|
+
|
333
|
+
it "returns :datepicker_options => {:yearRange => '2000:2020'}" do
|
334
|
+
Jquids.jquids_process_options({:year_range => 2000..2020}).should == {:datepicker_options => {:yearRange => '2000:2020'}}
|
335
|
+
end
|
336
|
+
|
337
|
+
end
|
338
|
+
|
339
|
+
describe "equals [2000..2020]" do
|
340
|
+
|
341
|
+
it "returns :datepicker_options => {:yearRange => '2000:2020'}" do
|
342
|
+
Jquids.jquids_process_options({:year_range => [2000, 2020]}).should == {:datepicker_options => {:yearRange => '2000:2020'}}
|
343
|
+
end
|
344
|
+
|
345
|
+
end
|
346
|
+
|
347
|
+
describe "equals 2.years.ago..2.years.from_now" do
|
348
|
+
|
349
|
+
it "returns :datepicker_options => {:yearRange => '#{2.years.ago.strftime("%Y")}:#{2.years.from_now.strftime("%Y")}'}" do
|
350
|
+
output = Jquids.jquids_process_options({:year_range => 2.years.ago..2.years.from_now})
|
351
|
+
output.should == {:datepicker_options => {:yearRange => "#{2.years.ago.strftime("%Y")}:#{2.years.from_now.strftime("%Y")}"}}
|
352
|
+
end
|
353
|
+
|
354
|
+
end
|
355
|
+
|
356
|
+
describe "equals [2.years.ago, 2.years.from_now]" do
|
357
|
+
|
358
|
+
it "returns :datepicker_options => {:yearRange => '#{2.years.ago.strftime("%Y")}:#{2.years.from_now.strftime("%Y")}'}" do
|
359
|
+
output = Jquids.jquids_process_options({:year_range => [2.years.ago, 2.years.from_now]})
|
360
|
+
output.should == {:datepicker_options => {:yearRange => "#{2.years.ago.strftime("%Y")}:#{2.years.from_now.strftime("%Y")}"}}
|
361
|
+
end
|
362
|
+
|
363
|
+
end
|
364
|
+
|
365
|
+
describe "equals 2.years.ago" do
|
366
|
+
|
367
|
+
it "returns :datepicker_options => {:yearRange => '#{2.years.ago.strftime("%Y")}:#{2.year.ago.strftime("%Y")}'}" do
|
368
|
+
output = Jquids.jquids_process_options({:year_range => 2.years.ago})
|
369
|
+
output.should == {:datepicker_options => {:yearRange => "#{2.years.ago.strftime("%Y")}:#{2.years.ago.strftime("%Y")}"}}
|
370
|
+
end
|
371
|
+
|
372
|
+
end
|
373
|
+
|
374
|
+
end
|
375
|
+
|
376
|
+
describe "with :month_year" do
|
377
|
+
|
378
|
+
describe "equals 'pancakes'" do
|
379
|
+
|
380
|
+
it "returns {}" do
|
381
|
+
output = Jquids.jquids_process_options(:month_year => "pancakes")
|
382
|
+
#puts output
|
383
|
+
output.should == {}
|
384
|
+
end
|
385
|
+
|
386
|
+
end
|
387
|
+
|
388
|
+
describe "equals 'dropdowns'" do
|
389
|
+
|
390
|
+
it "returns :datepicker_options => {:changeMonth => true, :changeYear => true}" do
|
391
|
+
output = Jquids.jquids_process_options({:month_year => "dropdowns"})
|
392
|
+
output.should == {:datepicker_options => {:changeMonth => true, :changeYear => true}}
|
393
|
+
end
|
394
|
+
|
395
|
+
end
|
396
|
+
|
397
|
+
describe "equals 'labels'" do
|
398
|
+
|
399
|
+
it "returns :datepicker_options => {:changeMonth => true, :changeYear => true}" do
|
400
|
+
output = Jquids.jquids_process_options({:month_year => "labels"})
|
401
|
+
output.should == {:datepicker_options => {:changeMonth => false, :changeYear => false}}
|
402
|
+
end
|
403
|
+
|
404
|
+
end
|
405
|
+
|
406
|
+
end
|
407
|
+
|
408
|
+
describe "with :image" do
|
409
|
+
|
410
|
+
describe "equals 'groovy.png'" do
|
411
|
+
|
412
|
+
it "returns :datepicker_options => {:buttonImage => '/images/groovy.png', :buttonImageOnly => true}" do
|
413
|
+
output = Jquids.jquids_process_options({:image => 'groovy.png'})
|
414
|
+
output.should == {:datepicker_options => {:buttonImage => '/images/groovy.png', :buttonImageOnly => true, :showOn => "button"}}
|
415
|
+
end
|
416
|
+
|
417
|
+
describe "with :datepicker_options => {:showOn} already set" do
|
418
|
+
|
419
|
+
it "returns :datepicker_options => {:buttonImage => '/images/groovy.png', :buttonImageOnly => true}" do
|
420
|
+
output = Jquids.jquids_process_options({:image => 'groovy.png', :datepicker_options => {:showOn => "both"}})
|
421
|
+
output.should == {:datepicker_options => {:buttonImage => '/images/groovy.png', :buttonImageOnly => true, :showOn => "both"}}
|
422
|
+
end
|
423
|
+
|
424
|
+
end
|
425
|
+
|
426
|
+
end
|
427
|
+
|
428
|
+
describe "equals 'http://www.google.com/images/MindControl.gif'" do
|
429
|
+
|
430
|
+
it "reuturns :datepicker_options => {:buttonImage => 'http://www.google.com/images/MindControl.gif', :buttonImageOnly => true}" do
|
431
|
+
output = Jquids.jquids_process_options({:image => 'http://www.google.com/images/MindControl.gif'})
|
432
|
+
output.should == {:datepicker_options => {:buttonImage => 'http://www.google.com/images/MindControl.gif', :buttonImageOnly => true, :showOn => 'button'}}
|
433
|
+
end
|
434
|
+
|
435
|
+
end
|
436
|
+
|
437
|
+
end
|
438
|
+
|
439
|
+
end
|
440
|
+
|
441
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
#require "rspec"
|
3
|
+
require "rspec" if Gem.source_index.find_name('rspec').map {|x| x.version}.first.version.to_i >= 2
|
4
|
+
require "spec" if Gem.source_index.find_name('rspec').map {|x| x.version}.first.version.to_i < 2
|
5
|
+
begin
|
6
|
+
require "json"
|
7
|
+
rescue LoadError
|
8
|
+
puts "'json' gem doesn't exist. Assuming Rails 3 is installed.'"
|
9
|
+
end
|
10
|
+
|
11
|
+
require "action_controller"
|
12
|
+
require "action_pack"
|
13
|
+
require "action_view"
|
14
|
+
require "active_support"
|
15
|
+
require "active_support/core_ext"
|
16
|
+
|
17
|
+
require "ostruct"
|
18
|
+
|
19
|
+
$: << (File.dirname(__FILE__) + "/../lib")
|
20
|
+
require "jquids"
|
21
|
+
|
22
|
+
#RSpec.configure do |config|
|
23
|
+
#end
|