Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

root/plugins/in_place_editing/test/in_place_editing_test.rb

Revision 7441, 3.2 kB (checked in by david, 1 year ago)

Moved in_place editing out of core and into its own plugin #9513

Line 
1 require File.expand_path(File.join(File.dirname(__FILE__), '../../../../test/test_helper'))
2 require 'test/unit'
3
4 class InPlaceEditingTest < Test::Unit::TestCase
5   include InPlaceEditing
6   include InPlaceMacrosHelper
7  
8   include ActionView::Helpers::UrlHelper
9   include ActionView::Helpers::TagHelper
10   include ActionView::Helpers::TextHelper
11   include ActionView::Helpers::FormHelper
12   include ActionView::Helpers::CaptureHelper
13  
14   def setup
15     @controller = Class.new do
16       def url_for(options)
17         url =  "http://www.example.com/"
18         url << options[:action].to_s if options and options[:action]
19         url
20       end
21     end
22     @controller = @controller.new
23   end
24  
25   def test_in_place_editor_external_control
26       assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nnew Ajax.InPlaceEditor('some_input', 'http://www.example.com/inplace_edit', {externalControl:'blah'})\n//]]>\n</script>),
27         in_place_editor('some_input', {:url => {:action => 'inplace_edit'}, :external_control => 'blah'})
28   end
29  
30   def test_in_place_editor_size
31       assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nnew Ajax.InPlaceEditor('some_input', 'http://www.example.com/inplace_edit', {size:4})\n//]]>\n</script>),
32         in_place_editor('some_input', {:url => {:action => 'inplace_edit'}, :size => 4})
33   end
34  
35   def test_in_place_editor_cols_no_rows
36       assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nnew Ajax.InPlaceEditor('some_input', 'http://www.example.com/inplace_edit', {cols:4})\n//]]>\n</script>),
37         in_place_editor('some_input', {:url => {:action => 'inplace_edit'}, :cols => 4})
38   end
39  
40   def test_in_place_editor_cols_with_rows
41       assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nnew Ajax.InPlaceEditor('some_input', 'http://www.example.com/inplace_edit', {cols:40, rows:5})\n//]]>\n</script>),
42         in_place_editor('some_input', {:url => {:action => 'inplace_edit'}, :rows => 5, :cols => 40})
43   end
44
45   def test_inplace_editor_loading_text
46       assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nnew Ajax.InPlaceEditor('some_input', 'http://www.example.com/inplace_edit', {loadingText:'Why are we waiting?'})\n//]]>\n</script>),
47         in_place_editor('some_input', {:url => {:action => 'inplace_edit'}, :loading_text => 'Why are we waiting?'})
48   end
49  
50   def test_in_place_editor_url
51     assert_match "Ajax.InPlaceEditor('id-goes-here', 'http://www.example.com/action_to_set_value')",
52     in_place_editor( 'id-goes-here', :url => { :action => "action_to_set_value" })   
53   end
54  
55   def test_in_place_editor_load_text_url
56     assert_match "Ajax.InPlaceEditor('id-goes-here', 'http://www.example.com/action_to_set_value', {loadTextURL:'http://www.example.com/action_to_get_value'})",
57     in_place_editor( 'id-goes-here',
58       :url => { :action => "action_to_set_value" },
59       :load_text_url => { :action => "action_to_get_value" })
60   end
61  
62   def test_in_place_editor_eval_scripts
63     assert_match "Ajax.InPlaceEditor('id-goes-here', 'http://www.example.com/action_to_set_value', {evalScripts:true})",
64     in_place_editor( 'id-goes-here',
65       :url => { :action => "action_to_set_value" },
66       :script => true )
67   end
68  
69 end
Note: See TracBrowser for help on using the browser.