Skip to content

Commit be23ff0

Browse files
committed
tests
2 parents 49f94ef + 72998e1 commit be23ff0

14 files changed

+229
-200
lines changed

Gemfile

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
source :rubygems
22

3-
gem 'rails', :git => 'git://github.com/rails/rails.git'
4-
gem "rack", :git => "git://github.com/rack/rack.git"
5-
gem "rack-test", :git => "git://github.com/brynary/rack-test.git"
3+
gem 'rails', '~> 3.1'
64
gem 'mocha'
7-

Gemfile.lock

+63-78
Original file line numberDiff line numberDiff line change
@@ -1,104 +1,89 @@
1-
GIT
2-
remote: git://github.com/brynary/rack-test.git
3-
revision: 4f2fc0f0afe702f7a6bc23fb57f1168bcc371703
4-
specs:
5-
rack-test (0.6.0)
6-
rack (>= 1.0)
7-
8-
GIT
9-
remote: git://github.com/rack/rack.git
10-
revision: 09433a26a9e6d3d8921432cf1fcafc871e543690
11-
specs:
12-
rack (1.3.0.beta)
13-
14-
GIT
15-
remote: git://github.com/rails/rails.git
16-
revision: bd4831d6995102f6003d401b2f257c8f8e553d7b
1+
GEM
2+
remote: http://rubygems.org/
173
specs:
18-
actionmailer (3.1.0.beta)
19-
actionpack (= 3.1.0.beta)
4+
actionmailer (3.1.0)
5+
actionpack (= 3.1.0)
206
mail (~> 2.3.0)
21-
actionpack (3.1.0.beta)
22-
activemodel (= 3.1.0.beta)
23-
activesupport (= 3.1.0.beta)
7+
actionpack (3.1.0)
8+
activemodel (= 3.1.0)
9+
activesupport (= 3.1.0)
2410
builder (~> 3.0.0)
2511
erubis (~> 2.7.0)
26-
i18n (~> 0.6.0beta1)
27-
rack (~> 1.3.0.beta)
28-
rack-cache (~> 1.0.1)
29-
rack-mount (~> 0.7.2)
30-
rack-test (~> 0.6.0)
31-
sprockets (~> 2.0.0.beta.2)
32-
tzinfo (~> 0.3.27)
33-
activemodel (3.1.0.beta)
34-
activesupport (= 3.1.0.beta)
35-
bcrypt-ruby (~> 2.1.4)
12+
i18n (~> 0.6)
13+
rack (~> 1.3.2)
14+
rack-cache (~> 1.0.3)
15+
rack-mount (~> 0.8.2)
16+
rack-test (~> 0.6.1)
17+
sprockets (~> 2.0.0)
18+
activemodel (3.1.0)
19+
activesupport (= 3.1.0)
20+
bcrypt-ruby (~> 3.0.0)
3621
builder (~> 3.0.0)
37-
i18n (~> 0.6.0beta1)
38-
activerecord (3.1.0.beta)
39-
activemodel (= 3.1.0.beta)
40-
activesupport (= 3.1.0.beta)
41-
arel (~> 2.1.0)
42-
tzinfo (~> 0.3.27)
43-
activeresource (3.1.0.beta)
44-
activemodel (= 3.1.0.beta)
45-
activesupport (= 3.1.0.beta)
46-
activesupport (3.1.0.beta)
22+
i18n (~> 0.6)
23+
activerecord (3.1.0)
24+
activemodel (= 3.1.0)
25+
activesupport (= 3.1.0)
26+
arel (~> 2.2.1)
27+
tzinfo (~> 0.3.29)
28+
activeresource (3.1.0)
29+
activemodel (= 3.1.0)
30+
activesupport (= 3.1.0)
31+
activesupport (3.1.0)
4732
multi_json (~> 1.0)
48-
rails (3.1.0.beta)
49-
actionmailer (= 3.1.0.beta)
50-
actionpack (= 3.1.0.beta)
51-
activerecord (= 3.1.0.beta)
52-
activeresource (= 3.1.0.beta)
53-
activesupport (= 3.1.0.beta)
54-
bundler (~> 1.0)
55-
railties (= 3.1.0.beta)
56-
railties (3.1.0.beta)
57-
actionpack (= 3.1.0.beta)
58-
activesupport (= 3.1.0.beta)
59-
rack-ssl (~> 1.3.2)
60-
rake (>= 0.8.7)
61-
thor (~> 0.14.6)
62-
63-
GEM
64-
remote: http://rubygems.org/
65-
specs:
66-
arel (2.1.0)
67-
bcrypt-ruby (2.1.4)
33+
arel (2.2.1)
34+
bcrypt-ruby (3.0.0-x86-mingw32)
6835
builder (3.0.0)
6936
erubis (2.7.0)
70-
hike (1.0.0)
71-
i18n (0.6.0beta1)
37+
hike (1.2.1)
38+
i18n (0.6.0)
7239
mail (2.3.0)
7340
i18n (>= 0.4.0)
7441
mime-types (~> 1.16)
7542
treetop (~> 1.4.8)
7643
mime-types (1.16)
7744
mocha (0.9.12)
78-
multi_json (1.0.1)
79-
polyglot (0.3.1)
80-
rack-cache (1.0.1)
45+
multi_json (1.0.3)
46+
polyglot (0.3.2)
47+
rack (1.3.2)
48+
rack-cache (1.0.3)
8149
rack (>= 0.4)
82-
rack-mount (0.7.2)
50+
rack-mount (0.8.3)
8351
rack (>= 1.0.0)
8452
rack-ssl (1.3.2)
8553
rack
86-
rake (0.8.7)
87-
sprockets (2.0.0.beta.2)
88-
hike (~> 1.0)
54+
rack-test (0.6.1)
55+
rack (>= 1.0)
56+
rails (3.1.0)
57+
actionmailer (= 3.1.0)
58+
actionpack (= 3.1.0)
59+
activerecord (= 3.1.0)
60+
activeresource (= 3.1.0)
61+
activesupport (= 3.1.0)
62+
bundler (~> 1.0)
63+
railties (= 3.1.0)
64+
railties (3.1.0)
65+
actionpack (= 3.1.0)
66+
activesupport (= 3.1.0)
67+
rack-ssl (~> 1.3.2)
68+
rake (>= 0.8.7)
69+
rdoc (~> 3.4)
70+
thor (~> 0.14.6)
71+
rake (0.9.2)
72+
rdoc (3.9.4)
73+
sprockets (2.0.0)
74+
hike (~> 1.2)
8975
rack (~> 1.0)
90-
tilt (~> 1.0)
76+
tilt (!= 1.3.0, ~> 1.1)
9177
thor (0.14.6)
92-
tilt (1.3)
93-
treetop (1.4.9)
78+
tilt (1.3.3)
79+
treetop (1.4.10)
80+
polyglot
9481
polyglot (>= 0.3.1)
95-
tzinfo (0.3.27)
82+
tzinfo (0.3.29)
9683

9784
PLATFORMS
98-
ruby
85+
x86-mingw32
9986

10087
DEPENDENCIES
10188
mocha
102-
rack!
103-
rack-test!
104-
rails!
89+
rails (~> 3.1)

jquery-rjs.gemspec

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ Gem::Specification.new do |spec|
88

99
spec.files = %w(README Rakefile Gemfile) + Dir['lib/**/*', 'vendor/**/*', 'test/**/*']
1010

11-
spec.add_dependency('rails', '>= 3.1.0.beta')
12-
spec.add_dependency('jquery-rails')
11+
spec.add_dependency('rails', '~> 3.1')
12+
spec.add_runtime_dependency('jquery-rails')
1313
end

lib/action_view/helpers/jquery_helper.rb

+11-8
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,10 @@ def select(pattern)
322322
# page.insert_html :bottom, 'list', '<li>Last item</li>'
323323
#
324324
def insert_html(position, id, *options_for_render)
325-
call "jQuery(\"#{jquery_id(id)}\").#{position == :top ? 'prepend' : 'append'}", render(*options_for_render)
325+
insertion = position.to_s.downcase
326+
insertion = 'append' if insertion == 'bottom'
327+
insertion = 'prepend' if insertion == 'top'
328+
call "$(\"#{jquery_id(id)}\").#{insertion}", render(*options_for_render)
326329
# content = javascript_object_for(render(*options_for_render))
327330
# record "Element.insert(\"#{id}\", { #{position.to_s.downcase}: #{content} });"
328331
end
@@ -338,7 +341,7 @@ def insert_html(position, id, *options_for_render)
338341
# page.replace_html 'person-45', :partial => 'person', :object => @person
339342
#
340343
def replace_html(id, *options_for_render)
341-
call "jQuery(\"#{jquery_id(id)}\").html", render(*options_for_render)
344+
call "$(\"#{jquery_id(id)}\").html", render(*options_for_render)
342345
# call 'Element.update', id, render(*options_for_render)
343346
end
344347

@@ -373,7 +376,7 @@ def replace_html(id, *options_for_render)
373376
# page.replace 'person_45', :partial => 'person', :object => @person
374377
#
375378
def replace(id, *options_for_render)
376-
call "jQuery(\"#{jquery_id(id)}\").replaceWith", render(*options_for_render)
379+
call "$(\"#{jquery_id(id)}\").replaceWith", render(*options_for_render)
377380
#call 'Element.replace', id, render(*options_for_render)
378381
end
379382

@@ -386,7 +389,7 @@ def replace(id, *options_for_render)
386389
# page.remove 'person_23', 'person_9', 'person_2'
387390
#
388391
def remove(*ids)
389-
call "jQuery(\"#{jquery_ids(ids)}\").remove"
392+
call "$(\"#{jquery_ids(ids)}\").remove"
390393
#loop_on_multiple_args 'Element.remove', ids
391394
end
392395

@@ -399,7 +402,7 @@ def remove(*ids)
399402
# page.show 'person_6', 'person_13', 'person_223'
400403
#
401404
def show(*ids)
402-
call "jQuery(\"#{jquery_ids(ids)}\").show"
405+
call "$(\"#{jquery_ids(ids)}\").show"
403406
#loop_on_multiple_args 'Element.show', ids
404407
end
405408

@@ -412,7 +415,7 @@ def show(*ids)
412415
# page.hide 'person_29', 'person_9', 'person_0'
413416
#
414417
def hide(*ids)
415-
call "jQuery(\"#{jquery_ids(ids)}\").hide"
418+
call "$(\"#{jquery_ids(ids)}\").hide"
416419
#loop_on_multiple_args 'Element.hide', ids
417420
end
418421

@@ -425,7 +428,7 @@ def hide(*ids)
425428
# page.toggle 'person_14', 'person_12', 'person_23' # Shows the previously hidden elements
426429
#
427430
def toggle(*ids)
428-
call "jQuery(\"#{jquery_ids(ids)}\").toggle"
431+
call "$(\"#{jquery_ids(ids)}\").toggle"
429432
#loop_on_multiple_args 'Element.toggle', ids
430433
end
431434

@@ -869,7 +872,7 @@ def append_enumerable_function!(call)
869872

870873
class JavaScriptElementCollectionProxy < JavaScriptCollectionProxy #:nodoc:\
871874
def initialize(generator, pattern)
872-
super(generator, "$$(#{::ActiveSupport::JSON.encode(pattern)})")
875+
super(generator, "$(#{::ActiveSupport::JSON.encode(pattern)})")
873876
end
874877
end
875878
end

lib/action_view/helpers/jquery_ui_helper.rb

+46-11
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,32 @@ module Helpers
1818
# See the documentation at http://script.aculo.us for more information on
1919
# using these helpers in your application.
2020
module JqueryUiHelper
21-
TOGGLE_EFFECTS = [:toggle_appear, :toggle_slide, :toggle_blind]
21+
SCRIPTACULOUS_EFFECTS = {
22+
:appear => {:method => 'fade', :mode => 'show'},
23+
:blind_down => {:method => 'blind', :mode => 'show', :options => {:direction => 'vertical'}},
24+
:blind_up => {:method => 'blind', :mode => 'hide', :options => {:direction => 'vertical'}},
25+
:blind_right => {:method => 'blind', :mode => 'show', :options => {:direction => 'horizontal'}},
26+
:blind_left => {:method => 'blind', :mode => 'hide', :options => {:direction => 'horizontal'}},
27+
:bounce_in => {:method => 'bounce', :mode => 'show', :options => {:direction => 'up'}},
28+
:bounce_out => {:method => 'bounce', :mode => 'hide', :options => {:direction => 'up'}},
29+
:drop_in => {:method => 'drop', :mode => 'show', :options => {:direction => 'up'}},
30+
:drop_out => {:method => 'drop', :mode => 'hide', :options => {:direction => 'down'}},
31+
:fade => {:method => 'fade', :mode => 'hide'},
32+
:fold_in => {:method => 'fold', :mode => 'hide'},
33+
:fold_out => {:method => 'fold', :mode => 'show'},
34+
:grow => {:method => 'scale', :mode => 'show'},
35+
:shrink => {:method => 'scale', :mode => 'hide'},
36+
:slide_down => {:method => 'slide', :mode => 'show', :options => {:direction => 'up'}},
37+
:slide_up => {:method => 'slide', :mode => 'hide', :options => {:direction => 'up'}},
38+
:slide_right => {:method => 'slide', :mode => 'show', :options => {:direction => 'left'}},
39+
:slide_left => {:method => 'slide', :mode => 'hide', :options => {:direction => 'left'}},
40+
:squish => {:method => 'scale', :mode => 'hide', :options => {:origin => "['top','left']"}},
41+
:switch_on => {:method => 'clip', :mode => 'show', :options => {:direction => 'vertical'}},
42+
:switch_off => {:method => 'clip', :mode => 'hide', :options => {:direction => 'vertical'}},
43+
:toggle_appear => {:method => 'fade', :mode => 'toggle'},
44+
:toggle_slide => {:method => 'slide', :mode => 'toggle', :options => {:direction => 'up'}},
45+
:toggle_blind => {:method => 'blind', :mode => 'toggle', :options => {:direction => 'vertical'}},
46+
}
2247

2348
# Returns a JavaScript snippet to be used on the Ajax callbacks for
2449
# starting visual effects.
@@ -39,23 +64,33 @@ module JqueryUiHelper
3964
# You can change the behaviour with various options, see
4065
# http://script.aculo.us for more documentation.
4166
def visual_effect(name, element_id = false, js_options = {})
42-
element = element_id ? ActiveSupport::JSON.encode(element_id) : "element"
67+
element = element_id ? ActiveSupport::JSON.encode(jquery_id(element_id)) : "this"
4368

69+
if SCRIPTACULOUS_EFFECTS.has_key? name.to_sym
70+
effect = SCRIPTACULOUS_EFFECTS[name.to_sym]
71+
name = effect[:method]
72+
mode = effect[:mode]
73+
js_options = js_options.merge(effect[:options]) if effect[:options]
74+
end
75+
4476
js_options[:queue] = if js_options[:queue].is_a?(Hash)
4577
'{' + js_options[:queue].map {|k, v| k == :limit ? "#{k}:#{v}" : "#{k}:'#{v}'" }.join(',') + '}'
4678
elsif js_options[:queue]
4779
"'#{js_options[:queue]}'"
4880
end if js_options[:queue]
49-
50-
[:endcolor, :direction, :startcolor, :scaleMode, :restorecolor].each do |option|
81+
82+
[:color, :direction, :startcolor, :endcolor].each do |option|
5183
js_options[option] = "'#{js_options[option]}'" if js_options[option]
5284
end
85+
86+
js_options[:duration] = (js_options[:duration] * 1000).to_i if js_options.has_key? :duration
87+
88+
#if ['fadeIn','fadeOut','fadeToggle'].include?(name)
89+
# "$(\"#{jquery_id(element_id)}\").#{name}();"
90+
#else
91+
"$(#{element}).#{mode || "effect"}(\"#{name}\",#{options_for_javascript(js_options)});"
92+
#end
5393

54-
if TOGGLE_EFFECTS.include? name.to_sym
55-
"Effect.toggle(#{element},'#{name.to_s.gsub(/^toggle_/,'')}',#{options_for_javascript(js_options)});"
56-
else
57-
"new Effect.#{name.to_s.camelize}(#{element},#{options_for_javascript(js_options)});"
58-
end
5994
end
6095

6196
# Makes the element with the DOM ID specified by +element_id+ sortable
@@ -136,7 +171,7 @@ def sortable_element(element_id, options = {})
136171
def sortable_element_js(element_id, options = {}) #:nodoc:
137172
options[:with] ||= "Sortable.serialize(#{ActiveSupport::JSON.encode(element_id)})"
138173
options[:onUpdate] ||= "function(){" + remote_function(options) + "}"
139-
options.delete_if { |key, value| PrototypeHelper::AJAX_OPTIONS.include?(key) }
174+
options.delete_if { |key, value| JqueryHelper::AJAX_OPTIONS.include?(key) }
140175

141176
[:tag, :overlap, :constraint, :handle].each do |option|
142177
options[option] = "'#{options[option]}'" if options[option]
@@ -207,7 +242,7 @@ def drop_receiving_element(element_id, options = {})
207242
def drop_receiving_element_js(element_id, options = {}) #:nodoc:
208243
options[:with] ||= "'id=' + encodeURIComponent(element.id)"
209244
options[:onDrop] ||= "function(element){" + remote_function(options) + "}"
210-
options.delete_if { |key, value| PrototypeHelper::AJAX_OPTIONS.include?(key) }
245+
options.delete_if { |key, value| JqueryHelper::AJAX_OPTIONS.include?(key) }
211246

212247
options[:accept] = array_or_string_for_javascript(options[:accept]) if options[:accept]
213248
options[:hoverclass] = "'#{options[:hoverclass]}'" if options[:hoverclass]

0 commit comments

Comments
 (0)