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.
@@ -1,163 +1,145 @@
1
- require File.dirname(__FILE__) + '/../test_helper'
1
+ require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
2
 
3
- # Don't go out to the Internet if we're not live
4
- class << PluginAWeek::TinyMCEHelper
5
- # Whether or not an IO failure should be caused
6
- attr_accessor :fail_io
7
-
8
- # Use pages we've already downloaded for Sourceforge and Wiki information
9
- def open(name, *rest, &block)
10
- name = case name
11
- when /showfiles/
12
- 'test/files/sourceforge.html'
13
- when /wiki/
14
- 'test/files/wiki.html'
15
- when /3_0_8/
16
- "#{EXPANDED_RAILS_ROOT}/../files/tinymce_3_0_8.zip"
17
- when /3_0_6_2/
18
- "#{EXPANDED_RAILS_ROOT}/../files/tinymce_3_0_6_2.zip"
19
- else
20
- name
3
+ uses_mocha 'mocking install/update' do
4
+ class TinyMceInstallerTest < Test::Unit::TestCase
5
+ def setup
6
+ TinyMCEHelper.expects(:open).with('http://sourceforge.net/project/showfiles.php?group_id=103281&package_id=111430').returns(open('test/files/sourceforge.html')) unless live?
7
+
8
+ # Set up public path
9
+ FileUtils.mkdir_p("#{Rails.root}/public/javascripts")
21
10
  end
22
11
 
23
- super
24
- end
25
- end unless ENV['LIVE']
26
-
27
- # Simulate user input
28
- class << STDIN
29
- attr_accessor :prompted
30
-
31
- def gets
32
- @prompted = true
33
- "#{@gets.is_a?(Array) ? @gets.shift : @gets}\n"
34
- end
35
-
36
- def gets=(value)
37
- @gets = value
38
- end
39
- end
40
-
41
- class TinyMceInstallerTest < Test::Unit::TestCase
42
- def setup
43
- # Set up public path
44
- FileUtils.mkdir_p("#{Rails.root}/public/javascripts")
45
-
46
- # Set default STDIN value
47
- STDIN.gets = 'n'
48
- STDIN.prompted = false
49
- end
50
-
51
- def test_should_save_latest_version_to_default_target
52
- PluginAWeek::TinyMCEHelper.install(:force => true)
53
-
54
- assert File.exists?("#{Rails.root}/public/javascripts/tiny_mce")
55
-
56
- source = File.read("#{Rails.root}/public/javascripts/tiny_mce/tiny_mce_src.js")
12
+ def test_should_save_latest_version_to_default_target
13
+ TinyMCEHelper.expects(:open).with('http://downloads.sourceforge.net/tinymce/tinymce_3_0_8.zip?modtime=1209567317&big_mirror=0').yields(open("#{EXPANDED_RAILS_ROOT}/../files/tinymce_3_0_8.zip")) unless live?
14
+ TinyMCEHelper.install(:force => true)
15
+
16
+ assert File.exists?("#{Rails.root}/public/javascripts/tiny_mce")
17
+
18
+ source = File.read("#{Rails.root}/public/javascripts/tiny_mce/tiny_mce_src.js")
19
+
20
+ if live?
21
+ assert source.include?('tinymce')
22
+ else
23
+ assert source.include?("majorVersion : '3'");
24
+ assert source.include?("minorVersion : '0.8'");
25
+ end
26
+ end
57
27
 
58
- if live?
59
- assert source.include?('tinymce')
60
- else
28
+ def test_should_allow_custom_version
29
+ TinyMCEHelper.expects(:open).with('http://downloads.sourceforge.net/tinymce/tinymce_3_0_6_2.zip?modtime=1207580953&big_mirror=0').yields(open("#{EXPANDED_RAILS_ROOT}/../files/tinymce_3_0_6_2.zip")) unless live?
30
+ TinyMCEHelper.install(:version => '3.0.6.2', :force => true)
31
+
32
+ assert File.exists?("#{Rails.root}/public/javascripts/tiny_mce")
33
+
34
+ source = File.read("#{Rails.root}/public/javascripts/tiny_mce/tiny_mce_src.js")
61
35
  assert source.include?("majorVersion : '3'");
62
- assert source.include?("minorVersion : '0.8'");
36
+ assert source.include?("minorVersion : '0.6.2'");
63
37
  end
64
- end
65
-
66
- def test_should_allow_custom_version
67
- PluginAWeek::TinyMCEHelper.install(:version => '3.0.6.2', :force => true)
68
38
 
69
- assert File.exists?("#{Rails.root}/public/javascripts/tiny_mce")
39
+ def test_should_allow_custom_target
40
+ TinyMCEHelper.expects(:open).with('http://downloads.sourceforge.net/tinymce/tinymce_3_0_8.zip?modtime=1209567317&big_mirror=0').yields(open("#{EXPANDED_RAILS_ROOT}/../files/tinymce_3_0_8.zip")) unless live?
41
+ TinyMCEHelper.install(:target => 'public/javascripts/tinymce', :force => true)
42
+
43
+ assert File.exists?("#{Rails.root}/public/javascripts/tinymce")
44
+ end
70
45
 
71
- source = File.read("#{Rails.root}/public/javascripts/tiny_mce/tiny_mce_src.js")
72
- assert source.include?("majorVersion : '3'");
73
- assert source.include?("minorVersion : '0.6.2'");
46
+ def teardown
47
+ FileUtils.rm_rf("#{Rails.root}/public")
48
+ end
74
49
  end
75
-
76
- def test_should_allow_custom_target
77
- PluginAWeek::TinyMCEHelper.install(:target => 'public/javascripts/tinymce', :force => true)
50
+
51
+ class TinyMceInstallerExistingTest < Test::Unit::TestCase
52
+ def setup
53
+ # Set up public path
54
+ FileUtils.mkdir_p("#{Rails.root}/public/javascripts/tiny_mce")
55
+ end
78
56
 
79
- assert File.exists?("#{Rails.root}/public/javascripts/tinymce")
80
- end
81
-
82
- def test_should_prompt_user_if_base_target_already_exists
83
- FileUtils.mkdir("#{Rails.root}/public/javascripts/tiny_mce")
84
- PluginAWeek::TinyMCEHelper.install
57
+ def test_should_prompt_user
58
+ expects_file_requests
59
+
60
+ STDIN.expects(:gets).returns("y\n")
61
+ TinyMCEHelper.install
62
+ end
85
63
 
86
- assert STDIN.prompted
87
- end
88
-
89
- def test_should_skip_if_target_exists_and_user_skips
90
- FileUtils.mkdir("#{Rails.root}/public/javascripts/tiny_mce")
91
- STDIN.gets = 'n'
92
- PluginAWeek::TinyMCEHelper.install
64
+ def test_should_skip_if_user_skips
65
+ TinyMCEHelper.expects(:open).never
66
+
67
+ STDIN.expects(:gets).returns("n\n")
68
+ TinyMCEHelper.install
69
+
70
+ assert !File.exists?("#{Rails.root}/public/javascripts/tiny_mce/tiny_mce_src.js")
71
+ end
93
72
 
94
- assert !File.exists?("#{Rails.root}/public/javascripts/tiny_mce/tiny_mce_src.js")
95
- end
96
-
97
- def test_should_not_skip_if_target_exists_and_user_doesnt_skip
98
- FileUtils.mkdir("#{Rails.root}/public/javascripts/tiny_mce")
99
- STDIN.gets = 'y'
100
- PluginAWeek::TinyMCEHelper.install
73
+ def test_should_not_skip_if_user_does_not_skip
74
+ expects_file_requests
75
+
76
+ STDIN.expects(:gets).returns("y\n")
77
+ TinyMCEHelper.install
78
+
79
+ assert File.exists?("#{Rails.root}/public/javascripts/tiny_mce/tiny_mce_src.js")
80
+ end
101
81
 
102
- assert File.exists?("#{Rails.root}/public/javascripts/tiny_mce/tiny_mce_src.js")
103
- end
104
-
105
- def test_should_continue_prompting_user_if_target_exists_and_invalid_option_is_typed
106
- FileUtils.mkdir("#{Rails.root}/public/javascripts/tiny_mce")
107
- STDIN.gets = %w(k y)
108
- PluginAWeek::TinyMCEHelper.install
82
+ def test_should_continue_prompting_user_if_invalid_response_is_typed
83
+ expects_file_requests
84
+
85
+ STDIN.expects(:gets).times(2).returns("k\n", "y\n")
86
+ TinyMCEHelper.install
87
+
88
+ assert File.exists?("#{Rails.root}/public/javascripts/tiny_mce/tiny_mce_src.js")
89
+ end
109
90
 
110
- assert STDIN.gets.chomp.empty?
111
- assert File.exists?("#{Rails.root}/public/javascripts/tiny_mce/tiny_mce_src.js")
112
- end
113
-
114
- def test_install_should_overwrite_existing_folder_if_forced
115
- FileUtils.mkdir("#{Rails.root}/public/javascripts/tiny_mce")
116
- PluginAWeek::TinyMCEHelper.install(:force => true)
91
+ def test_should_overwrite_if_forced
92
+ expects_file_requests
93
+
94
+ STDIN.expects(:gets).never
95
+ TinyMCEHelper.install(:force => true)
96
+
97
+ assert File.exists?("#{Rails.root}/public/javascripts/tiny_mce/tiny_mce_src.js")
98
+ end
117
99
 
118
- assert File.exists?("#{Rails.root}/public/javascripts/tiny_mce/tiny_mce_src.js")
119
- end
120
-
121
- def test_should_not_raise_exception_if_error_occurs_during_io_operation
122
- PluginAWeek::TinyMCEHelper.fail_io = true unless live?
100
+ def teardown
101
+ FileUtils.rm_rf("#{Rails.root}/public")
102
+ end
123
103
 
124
- assert_nothing_raised {PluginAWeek::TinyMCEHelper.install(:force => true)}
125
- ensure
126
- PluginAWeek::TinyMCEHelper.fail_io = false unless live?
127
- end
128
-
129
- def teardown
130
- FileUtils.rm_rf("#{Rails.root}/public")
104
+ private
105
+ def expects_file_requests
106
+ unless live?
107
+ TinyMCEHelper.expects(:open).with('http://sourceforge.net/project/showfiles.php?group_id=103281&package_id=111430').returns(open('test/files/sourceforge.html'))
108
+ TinyMCEHelper.expects(:open).with('http://downloads.sourceforge.net/tinymce/tinymce_3_0_8.zip?modtime=1209567317&big_mirror=0').yields(open("#{EXPANDED_RAILS_ROOT}/../files/tinymce_3_0_8.zip"))
109
+ end
110
+ end
131
111
  end
132
- end
133
112
 
134
- class TinyMceUpdaterTest < Test::Unit::TestCase
135
- def setup
136
- # Track valid options
137
- @original_valid_options = PluginAWeek::TinyMCEHelper.valid_options.dup
138
- end
139
-
140
- def test_should_update_options_if_options_configuration_doesnt_exist
141
- FileUtils.rm("#{Rails.root}/config/tiny_mce_options.yml")
142
- PluginAWeek::TinyMCEHelper.update_options
113
+ class TinyMceUpdaterTest < Test::Unit::TestCase
114
+ def setup
115
+ TinyMCEHelper.expects(:open).with('http://wiki.moxiecode.com/index.php/TinyMCE:Configuration').returns(open('test/files/sourceforge.html')) unless live?
116
+
117
+ # Track valid options
118
+ @original_valid_options = TinyMCEHelper.valid_options.dup
119
+ end
143
120
 
144
- assert File.exists?("#{Rails.root}/config/tiny_mce_options.yml")
145
- options = YAML.load(File.read(PluginAWeek::TinyMCEHelper::OPTIONS_FILE_PATH))
146
- assert_instance_of Array, options
147
- end
148
-
149
- def test_should_update_options_if_options_configuration_exists
150
- File.truncate("#{Rails.root}/config/tiny_mce_options.yml", 0)
151
- PluginAWeek::TinyMCEHelper.update_options
121
+ def test_should_update_options_if_options_configuration_doesnt_exist
122
+ FileUtils.rm("#{Rails.root}/config/tiny_mce_options.yml")
123
+ TinyMCEHelper.update_options
124
+
125
+ assert File.exists?("#{Rails.root}/config/tiny_mce_options.yml")
126
+ options = YAML.load(File.read(TinyMCEHelper::OPTIONS_FILE_PATH))
127
+ assert_instance_of Array, options
128
+ end
152
129
 
153
- assert File.exists?("#{Rails.root}/config/tiny_mce_options.yml")
154
- options = YAML.load(File.open(PluginAWeek::TinyMCEHelper::OPTIONS_FILE_PATH))
155
- assert_instance_of Array, options
156
- end
157
-
158
- def teardown
159
- PluginAWeek::TinyMCEHelper.valid_options = @original_valid_options
160
- FileUtils.cp("#{Rails.root}/config_bak/tiny_mce_options.yml", "#{Rails.root}/config")
130
+ def test_should_update_options_if_options_configuration_exists
131
+ File.truncate("#{Rails.root}/config/tiny_mce_options.yml", 0)
132
+ TinyMCEHelper.update_options
133
+
134
+ assert File.exists?("#{Rails.root}/config/tiny_mce_options.yml")
135
+ options = YAML.load(File.open(TinyMCEHelper::OPTIONS_FILE_PATH))
136
+ assert_instance_of Array, options
137
+ end
138
+
139
+ def teardown
140
+ TinyMCEHelper.valid_options = @original_valid_options
141
+ FileUtils.cp("#{Rails.root}/config_bak/tiny_mce_options.yml", "#{Rails.root}/config")
142
+ end
161
143
  end
162
144
  end
163
145
 
@@ -168,13 +150,13 @@ class TinyMceUninstallerTest < Test::Unit::TestCase
168
150
  end
169
151
 
170
152
  def test_uninstall_should_remove_options_configuration
171
- PluginAWeek::TinyMCEHelper.uninstall
153
+ TinyMCEHelper.uninstall
172
154
  assert !File.exists?("#{Rails.root}/config/tiny_mce_options.yml")
173
155
  end
174
156
 
175
157
  def test_uninstall_should_remove_tinymce_source
176
158
  FileUtils.mkdir("#{Rails.root}/public/javascripts/tiny_mce")
177
- PluginAWeek::TinyMCEHelper.uninstall
159
+ TinyMCEHelper.uninstall
178
160
 
179
161
  assert !File.exists?("#{Rails.root}/public/javascripts/tiny_mce")
180
162
  end
@@ -184,186 +166,3 @@ class TinyMceUninstallerTest < Test::Unit::TestCase
184
166
  FileUtils.cp("#{Rails.root}/config_bak/tiny_mce_options.yml", "#{Rails.root}/config")
185
167
  end
186
168
  end
187
-
188
- class TinyMceHelperTest < Test::Unit::TestCase
189
- include ActionView::Helpers::TagHelper
190
- include ActionView::Helpers::AssetTagHelper
191
- include ActionView::Helpers::JavaScriptHelper
192
- include PluginAWeek::TinyMCEHelper
193
-
194
- def setup
195
- # Set up test request
196
- @request = ActionController::TestRequest.new
197
- @controller = ActionController::Base.new
198
- @controller.request = @request
199
- @controller.instance_eval {@_params = request.path_parameters}
200
- @controller.send(:initialize_current_url)
201
-
202
- # Make sure we always start in a test environment
203
- silence_warnings {Object.const_set('RAILS_ENV', 'test')}
204
- end
205
-
206
- def test_valid_options_should_not_be_empty
207
- assert PluginAWeek::TinyMCEHelper.valid_options.any?
208
- end
209
-
210
- def test_should_be_using_tiny_mce_if_instance_variable_exists
211
- @uses_tiny_mce = true
212
- assert using_tiny_mce?
213
- end
214
-
215
- def test_should_not_be_using_tiny_mce_if_instance_variable_doesnt_exist
216
- @uses_tiny_mce = false
217
- assert !using_tiny_mce?
218
- end
219
-
220
- def test_should_use_source_file_name_if_in_development
221
- silence_warnings {Object.const_set('RAILS_ENV', 'development')}
222
- assert_equal 'tiny_mce/tiny_mce_src', tiny_mce_file_name
223
- end
224
-
225
- def test_should_use_compressed_file_name_if_in_test
226
- silence_warnings {Object.const_set('RAILS_ENV', 'test')}
227
- assert_equal 'tiny_mce/tiny_mce', tiny_mce_file_name
228
- end
229
-
230
- def test_should_use_compressed_file_name_if_in_production
231
- silence_warnings {Object.const_set('RAILS_ENV', 'production')}
232
- assert_equal 'tiny_mce/tiny_mce', tiny_mce_file_name
233
- end
234
-
235
- def test_should_use_environment_file_name_for_javascript_include_in_development
236
- silence_warnings {Object.const_set('RAILS_ENV', 'development')}
237
- assert_equal '<script src="/javascripts/tiny_mce/tiny_mce_src.js" type="text/javascript"></script>', javascript_include_tiny_mce
238
- end
239
-
240
- def test_should_use_environment_file_name_for_javascript_include_in_test
241
- silence_warnings {Object.const_set('RAILS_ENV', 'test')}
242
- assert_equal '<script src="/javascripts/tiny_mce/tiny_mce.js" type="text/javascript"></script>', javascript_include_tiny_mce
243
- end
244
-
245
- def test_should_include_conditional_javascript_if_using_tiny_mce
246
- @uses_tiny_mce = true
247
- assert_equal '<script src="/javascripts/tiny_mce/tiny_mce.js" type="text/javascript"></script>', javascript_include_tiny_mce_if_used
248
- end
249
-
250
- def test_should_not_include_conditional_javascript_if_not_using_tiny_mce
251
- @uses_tiny_mce = false
252
- assert_nil javascript_include_tiny_mce_if_used
253
- end
254
- end
255
-
256
- class TinyMceHelperScriptTest < Test::Unit::TestCase
257
- include ActionView::Helpers::TagHelper
258
- include ActionView::Helpers::JavaScriptHelper
259
- include PluginAWeek::TinyMCEHelper
260
-
261
- def setup
262
- # Track valid options
263
- @original_valid_options = PluginAWeek::TinyMCEHelper.valid_options.dup
264
- end
265
-
266
- def test_script_should_use_textareas_mode_and_simple_theme_by_default
267
- expected = <<-end_str
268
- tinyMCE.init({
269
- mode : 'textareas',
270
- theme : 'simple'
271
- });
272
- end_str
273
- assert_html_equal expected, tiny_mce_init_script
274
- end
275
-
276
- def test_script_should_raise_exception_if_invalid_option_provided
277
- assert_raise(ArgumentError) {tiny_mce_init_script(:invalid => true)}
278
- end
279
-
280
- def test_script_should_not_raise_exception_if_invalid_option_provided_but_valid_options_is_nil
281
- PluginAWeek::TinyMCEHelper.valid_options = nil
282
- assert_nothing_raised {tiny_mce_init_script(:invalid => true)}
283
- end
284
-
285
- def test_script_should_not_raise_exception_if_invalid_option_provided_but_valid_options_is_empty
286
- PluginAWeek::TinyMCEHelper.valid_options = []
287
- assert_nothing_raised {tiny_mce_init_script(:invalid => true)}
288
- end
289
-
290
- def test_script_should_not_raise_exception_for_dynamic_options
291
- assert_nothing_raised {tiny_mce_init_script(:theme_advanced_buttons_1 => '', :theme_advanced_container_test => '')}
292
- end
293
-
294
- def test_script_should_convert_symbols
295
- expected = <<-end_str
296
- tinyMCE.init({
297
- mode : 'textareas',
298
- theme : 'simple'
299
- });
300
- end_str
301
- assert_html_equal expected, tiny_mce_init_script(:mode => :textareas)
302
- end
303
-
304
- def test_script_should_convert_numbers
305
- expected = <<-end_str
306
- tinyMCE.init({
307
- mode : 'textareas',
308
- theme : 'simple',
309
- width : '640'
310
- });
311
- end_str
312
- assert_html_equal expected, tiny_mce_init_script(:width => 640)
313
- end
314
-
315
- def test_script_should_convert_arrays
316
- expected = <<-end_str
317
- tinyMCE.init({
318
- mode : 'textareas',
319
- theme : 'simple',
320
- valid_elements : 'b,p,br,i,u'
321
- });
322
- end_str
323
- assert_html_equal expected, tiny_mce_init_script(:valid_elements => %w(b p br i u))
324
- end
325
-
326
- def test_script_should_convert_boolean_true
327
- expected = <<-end_str
328
- tinyMCE.init({
329
- auto_reset_designmode : true,
330
- mode : 'textareas',
331
- theme : 'simple'
332
- });
333
- end_str
334
- assert_html_equal expected, tiny_mce_init_script(:auto_reset_designmode => true)
335
- end
336
-
337
- def test_script_should_convert_boolean_false
338
- expected = <<-end_str
339
- tinyMCE.init({
340
- auto_reset_designmode : false,
341
- mode : 'textareas',
342
- theme : 'simple'
343
- });
344
- end_str
345
- assert_html_equal expected, tiny_mce_init_script(:auto_reset_designmode => false)
346
- end
347
-
348
- def test_script_should_raise_exception_if_unknown_value_class_provided
349
- assert_raise(ArgumentError) {tiny_mce_init_script(:mode => Hash.new)}
350
- end
351
-
352
- def test_tiny_mce_should_wrap_script_in_javascript_tag
353
- expected = <<-end_str
354
- <script type="text/javascript">
355
- //<![CDATA[
356
- tinyMCE.init({
357
- mode : 'textareas',
358
- theme : 'simple'
359
- });
360
- //]]>
361
- </script>
362
- end_str
363
- assert_html_equal expected, tiny_mce
364
- end
365
-
366
- def teardown
367
- PluginAWeek::TinyMCEHelper.valid_options = @original_valid_options
368
- end
369
- end
data/uninstall.rb CHANGED
@@ -1,2 +1,2 @@
1
1
  # Uninstall TinyMCE
2
- PluginAWeek::TinyMCEHelper.uninstall
2
+ TinyMCEHelper.uninstall
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tiny_mce_helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Pfeifer
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-10-19 00:00:00 -04:00
12
+ date: 2008-12-14 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -24,19 +24,21 @@ extra_rdoc_files: []
24
24
  files:
25
25
  - lib/tiny_mce_helper.rb
26
26
  - tasks/tiny_mce_helper_tasks.rake
27
- - test/app_root
28
- - test/app_root/config_bak
29
- - test/app_root/config_bak/tiny_mce_options.yml
30
- - test/app_root/config
31
- - test/app_root/config/tiny_mce_options.yml
27
+ - test/test_helper.rb
32
28
  - test/files
33
- - test/files/wiki.html
34
29
  - test/files/tinymce_3_0_6_2.zip
35
30
  - test/files/sourceforge.html
36
31
  - test/files/tinymce_3_0_8.zip
37
- - test/test_helper.rb
32
+ - test/files/wiki.html
38
33
  - test/unit
39
34
  - test/unit/tiny_mce_helper_test.rb
35
+ - test/helpers
36
+ - test/helpers/tiny_mce_helper_test.rb
37
+ - test/app_root
38
+ - test/app_root/config_bak
39
+ - test/app_root/config_bak/tiny_mce_options.yml
40
+ - test/app_root/config
41
+ - test/app_root/config/tiny_mce_options.yml
40
42
  - CHANGELOG.rdoc
41
43
  - init.rb
42
44
  - install.rb
@@ -71,3 +73,4 @@ specification_version: 2
71
73
  summary: Adds helper methods for creating the TinyMCE initialization script.
72
74
  test_files:
73
75
  - test/unit/tiny_mce_helper_test.rb
76
+ - test/helpers/tiny_mce_helper_test.rb