tiny_mce_helper 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.rdoc +6 -0
- data/README.rdoc +5 -5
- data/Rakefile +1 -1
- data/install.rb +2 -2
- data/lib/tiny_mce_helper.rb +233 -234
- data/tasks/tiny_mce_helper_tasks.rake +4 -4
- data/test/helpers/tiny_mce_helper_test.rb +187 -0
- data/test/test_helper.rb +10 -1
- data/test/unit/tiny_mce_helper_test.rb +124 -325
- data/uninstall.rb +1 -1
- metadata +12 -9
@@ -0,0 +1,187 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
2
|
+
|
3
|
+
class TinyMceHelperTest < ActionView::TestCase
|
4
|
+
tests TinyMCEHelper
|
5
|
+
|
6
|
+
def test_valid_options_should_not_be_empty
|
7
|
+
assert TinyMCEHelper.valid_options.any?
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
uses_mocha 'stubbing Rails.env' do
|
12
|
+
class TinyMceHelperFilenameTest < ActionView::TestCase
|
13
|
+
tests TinyMCEHelper
|
14
|
+
|
15
|
+
def test_should_use_source_file_name_if_in_development
|
16
|
+
Rails.stubs(:env).returns(ActiveSupport::StringInquirer.new('development'))
|
17
|
+
assert_equal 'tiny_mce/tiny_mce_src', tiny_mce_file_name
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_should_use_compressed_file_name_if_in_test
|
21
|
+
Rails.stubs(:env).returns(ActiveSupport::StringInquirer.new('test'))
|
22
|
+
assert_equal 'tiny_mce/tiny_mce', tiny_mce_file_name
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_should_use_compressed_file_name_if_in_production
|
26
|
+
Rails.stubs(:env).returns(ActiveSupport::StringInquirer.new('production'))
|
27
|
+
assert_equal 'tiny_mce/tiny_mce', tiny_mce_file_name
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_should_use_environment_file_name_for_javascript_include_in_development
|
31
|
+
Rails.stubs(:env).returns(ActiveSupport::StringInquirer.new('development'))
|
32
|
+
assert_equal '<script src="/javascripts/tiny_mce/tiny_mce_src.js" type="text/javascript"></script>', javascript_include_tiny_mce
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_should_use_environment_file_name_for_javascript_include_in_test
|
36
|
+
Rails.stubs(:env).returns(ActiveSupport::StringInquirer.new('test'))
|
37
|
+
assert_equal '<script src="/javascripts/tiny_mce/tiny_mce.js" type="text/javascript"></script>', javascript_include_tiny_mce
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class TinyMceHelperDisabledTest < ActionView::TestCase
|
43
|
+
tests TinyMCEHelper
|
44
|
+
|
45
|
+
def setup
|
46
|
+
@uses_tiny_mce = false
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_should_not_be_using_tiny_mce
|
50
|
+
assert !using_tiny_mce?
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_should_not_include_conditional_javascript
|
54
|
+
assert_nil javascript_include_tiny_mce_if_used
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
class TinyMceHelperEnabledTest < ActionView::TestCase
|
59
|
+
tests TinyMCEHelper
|
60
|
+
|
61
|
+
def setup
|
62
|
+
@uses_tiny_mce = true
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_should_be_using_tiny_mce
|
66
|
+
assert using_tiny_mce?
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_should_include_conditional_javascript
|
70
|
+
assert_equal '<script src="/javascripts/tiny_mce/tiny_mce.js" type="text/javascript"></script>', javascript_include_tiny_mce_if_used
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
class TinyMceHelperScriptTest < ActionView::TestCase
|
75
|
+
tests TinyMCEHelper
|
76
|
+
|
77
|
+
def setup
|
78
|
+
# Track valid options
|
79
|
+
@original_valid_options = TinyMCEHelper.valid_options.dup
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_should_use_textareas_mode_and_simple_theme_by_default
|
83
|
+
expected = <<-end_str
|
84
|
+
tinyMCE.init({
|
85
|
+
mode : 'textareas',
|
86
|
+
theme : 'simple'
|
87
|
+
});
|
88
|
+
end_str
|
89
|
+
assert_html_equal expected, tiny_mce_init_script
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_should_raise_exception_if_invalid_option_provided
|
93
|
+
assert_raise(ArgumentError) {tiny_mce_init_script(:invalid => true)}
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_should_not_raise_exception_if_invalid_option_provided_but_valid_options_is_nil
|
97
|
+
TinyMCEHelper.valid_options = nil
|
98
|
+
assert_nothing_raised {tiny_mce_init_script(:invalid => true)}
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_should_not_raise_exception_if_invalid_option_provided_but_valid_options_is_empty
|
102
|
+
TinyMCEHelper.valid_options = []
|
103
|
+
assert_nothing_raised {tiny_mce_init_script(:invalid => true)}
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_should_not_raise_exception_for_dynamic_options
|
107
|
+
assert_nothing_raised {tiny_mce_init_script(:theme_advanced_buttons_1 => '', :theme_advanced_container_test => '')}
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_should_convert_symbols_to_strings
|
111
|
+
expected = <<-end_str
|
112
|
+
tinyMCE.init({
|
113
|
+
mode : 'textareas',
|
114
|
+
theme : 'simple'
|
115
|
+
});
|
116
|
+
end_str
|
117
|
+
assert_html_equal expected, tiny_mce_init_script(:mode => :textareas)
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_should_convert_numbers_to_strings
|
121
|
+
expected = <<-end_str
|
122
|
+
tinyMCE.init({
|
123
|
+
mode : 'textareas',
|
124
|
+
theme : 'simple',
|
125
|
+
width : '640'
|
126
|
+
});
|
127
|
+
end_str
|
128
|
+
assert_html_equal expected, tiny_mce_init_script(:width => 640)
|
129
|
+
end
|
130
|
+
|
131
|
+
def test_should_convert_arrays_to_comma_delimited_values
|
132
|
+
expected = <<-end_str
|
133
|
+
tinyMCE.init({
|
134
|
+
mode : 'textareas',
|
135
|
+
theme : 'simple',
|
136
|
+
valid_elements : 'b,p,br,i,u'
|
137
|
+
});
|
138
|
+
end_str
|
139
|
+
assert_html_equal expected, tiny_mce_init_script(:valid_elements => %w(b p br i u))
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_should_convert_true_to_boolean
|
143
|
+
expected = <<-end_str
|
144
|
+
tinyMCE.init({
|
145
|
+
auto_reset_designmode : true,
|
146
|
+
mode : 'textareas',
|
147
|
+
theme : 'simple'
|
148
|
+
});
|
149
|
+
end_str
|
150
|
+
assert_html_equal expected, tiny_mce_init_script(:auto_reset_designmode => true)
|
151
|
+
end
|
152
|
+
|
153
|
+
def test_should_convert_false_to_boolean
|
154
|
+
expected = <<-end_str
|
155
|
+
tinyMCE.init({
|
156
|
+
auto_reset_designmode : false,
|
157
|
+
mode : 'textareas',
|
158
|
+
theme : 'simple'
|
159
|
+
});
|
160
|
+
end_str
|
161
|
+
assert_html_equal expected, tiny_mce_init_script(:auto_reset_designmode => false)
|
162
|
+
end
|
163
|
+
|
164
|
+
def test_should_raise_exception_if_unknown_value_class_provided
|
165
|
+
assert_raise(ArgumentError) {tiny_mce_init_script(:mode => {})}
|
166
|
+
end
|
167
|
+
|
168
|
+
def teardown
|
169
|
+
TinyMCEHelper.valid_options = @original_valid_options
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
class TinyMceHelperScriptTagTest
|
174
|
+
def test_should_wrap_script_in_javascript_tag
|
175
|
+
expected = <<-end_str
|
176
|
+
<script type="text/javascript">
|
177
|
+
//<![CDATA[
|
178
|
+
tinyMCE.init({
|
179
|
+
mode : 'textareas',
|
180
|
+
theme : 'simple'
|
181
|
+
});
|
182
|
+
//]]>
|
183
|
+
</script>
|
184
|
+
end_str
|
185
|
+
assert_html_equal expected, tiny_mce
|
186
|
+
end
|
187
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -10,7 +10,7 @@ require 'plugin_test_helper'
|
|
10
10
|
|
11
11
|
EXPANDED_RAILS_ROOT = File.expand_path(Rails.root)
|
12
12
|
|
13
|
-
|
13
|
+
Test::Unit::TestCase.class_eval do
|
14
14
|
protected
|
15
15
|
def live?
|
16
16
|
ENV['LIVE']
|
@@ -20,3 +20,12 @@ class Test::Unit::TestCase #:nodoc:
|
|
20
20
|
assert_equal expected.strip.gsub(/\n\s*/, ''), actual.strip.gsub(/\n\s*/, '')
|
21
21
|
end
|
22
22
|
end
|
23
|
+
|
24
|
+
# Allow skipping of tests that require mocha
|
25
|
+
def uses_mocha(description)
|
26
|
+
require 'rubygems'
|
27
|
+
require 'mocha'
|
28
|
+
yield
|
29
|
+
rescue LoadError
|
30
|
+
$stderr.puts "Skipping #{description} tests. `gem install mocha` and try again."
|
31
|
+
end
|