rich_cms 2.1.7 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (179) hide show
  1. data/{CHANGELOG → CHANGELOG.rdoc} +24 -0
  2. data/README.textile +49 -33
  3. data/Rakefile +92 -10
  4. data/VERSION +1 -1
  5. data/app/controllers/rich/cms_controller.rb +10 -39
  6. data/app/controllers/rich/cms_sessions_controller.rb +31 -0
  7. data/app/views/rich/cms/dock/_menu.html.erb +10 -8
  8. data/app/views/rich/cms/dock/_panel.html.erb +1 -1
  9. data/app/views/rich/cms/dock/panel/edit/_rails2.html.erb +5 -3
  10. data/app/views/rich/cms/dock/panel/edit/_rails3.html.erb +4 -2
  11. data/app/views/rich/cms/dock/panel/login/_rails2.html.erb +18 -12
  12. data/app/views/rich/cms/dock/panel/login/_rails3.html.erb +18 -12
  13. data/app/views/rich_cms.html.erb +1 -1
  14. data/assets/jzip/jquery/cleditor.js +1132 -1132
  15. data/assets/jzip/jquery/extensions/browser_detect.js +1 -2
  16. data/assets/jzip/native/extensions.js +41 -0
  17. data/assets/jzip/rich/cms/editor.js +41 -7
  18. data/assets/jzip/rich_cms.jz +2 -1
  19. data/assets/sass/rich_cms/_panel.sass +11 -1
  20. data/config/routes.rb +12 -11
  21. data/lib/generators/rich/cms_admin/cms_admin_generator.rb +82 -0
  22. data/lib/generators/rich/{authlogic_user/templates → cms_admin/templates/authlogic}/migration.rb +0 -0
  23. data/lib/generators/rich/{authlogic_user/templates → cms_admin/templates/authlogic}/model.rb +0 -0
  24. data/lib/generators/rich/{authlogic_user/templates → cms_admin/templates/authlogic}/session.rb +0 -0
  25. data/lib/rich/cms/actionpack/action_controller/base.rb +3 -44
  26. data/lib/rich/cms/actionpack/action_view/base.rb +32 -10
  27. data/lib/rich/cms/actionpack.rb +1 -2
  28. data/lib/rich/cms/auth.rb +110 -0
  29. data/lib/rich/cms/content/group.rb +1 -2
  30. data/lib/rich/cms/content/item.rb +2 -3
  31. data/lib/rich/cms/core/string/html_safe.rb +1 -2
  32. data/lib/rich/cms/core/string.rb +1 -2
  33. data/lib/rich/cms/engine.rb +23 -51
  34. data/lib/rich/cms/rails/engine.rb +1 -2
  35. data/lib/rich/cms/version.rb +11 -0
  36. data/lib/rich_cms.rb +2 -2
  37. data/rails_generators/rich_cms_admin/lib/devise/route_devise.rb +32 -0
  38. data/rails_generators/rich_cms_admin/rich_cms_admin_generator.rb +113 -0
  39. data/rails_generators/{rich_authlogic_user/templates → rich_cms_admin/templates/authlogic}/migration.rb +0 -0
  40. data/rails_generators/{rich_authlogic_user/templates → rich_cms_admin/templates/authlogic}/model.rb +0 -0
  41. data/rails_generators/{rich_authlogic_user/templates → rich_cms_admin/templates/authlogic}/session.rb +0 -0
  42. data/rails_generators/{rich_authlogic_user → rich_cms_admin}/templates/config.rb +0 -0
  43. data/rails_generators/rich_cms_admin/templates/devise/README +23 -0
  44. data/rails_generators/rich_cms_admin/templates/devise/devise.rb +105 -0
  45. data/rails_generators/rich_cms_admin/templates/devise/en.yml +35 -0
  46. data/rails_generators/rich_cms_admin/templates/devise/migration.rb +23 -0
  47. data/rails_generators/rich_cms_admin/templates/devise/model.rb +9 -0
  48. data/rails_generators/rich_cms_content/rich_cms_content_generator.rb +18 -12
  49. data/rich_cms.gemspec +295 -105
  50. data/test/integrator.rb +89 -0
  51. data/test/rails-2/dummy/.bundle/config +2 -0
  52. data/test/rails-2/dummy/Gemfile +15 -0
  53. data/test/rails-2/dummy/Gemfile.lock +97 -0
  54. data/test/rails-2/dummy/Rakefile +10 -0
  55. data/test/rails-2/dummy/app/controllers/application_controller.rb +10 -0
  56. data/test/rails-2/dummy/app/helpers/application_helper.rb +3 -0
  57. data/test/rails-2/dummy/config/boot.rb +124 -0
  58. data/test/rails-2/dummy/config/database.yml +23 -0
  59. data/test/rails-2/dummy/config/environment.rb +41 -0
  60. data/test/rails-2/dummy/config/environments/development.rb +17 -0
  61. data/test/rails-2/dummy/config/environments/production.rb +28 -0
  62. data/test/rails-2/dummy/config/environments/test.rb +28 -0
  63. data/test/rails-2/dummy/config/initializers/backtrace_silencers.rb +7 -0
  64. data/test/rails-2/dummy/config/initializers/cookie_verification_secret.rb +7 -0
  65. data/test/rails-2/dummy/config/initializers/devise.rb +105 -0
  66. data/test/rails-2/dummy/config/initializers/enrichments.rb +5 -0
  67. data/test/rails-2/dummy/config/initializers/inflections.rb +10 -0
  68. data/test/rails-2/dummy/config/initializers/mime_types.rb +5 -0
  69. data/test/rails-2/dummy/config/initializers/new_rails_defaults.rb +21 -0
  70. data/test/rails-2/dummy/config/initializers/session_store.rb +15 -0
  71. data/test/rails-2/dummy/config/locales/en.yml +5 -0
  72. data/test/rails-2/dummy/config/preinitializer.rb +20 -0
  73. data/test/rails-2/dummy/config/routes.rb +44 -0
  74. data/test/rails-2/dummy/db/schema.rb +49 -0
  75. data/test/rails-2/dummy/db/seeds.rb +10 -0
  76. data/test/rails-2/dummy/public/404.html +30 -0
  77. data/test/rails-2/dummy/public/422.html +30 -0
  78. data/test/rails-2/dummy/public/500.html +30 -0
  79. data/test/rails-2/dummy/public/favicon.ico +0 -0
  80. data/test/rails-2/dummy/public/images/rails.png +0 -0
  81. data/test/rails-2/dummy/public/images/rich/cms/cleditor/buttons.gif +0 -0
  82. data/test/rails-2/dummy/public/images/rich/cms/cleditor/toolbar.gif +0 -0
  83. data/test/rails-2/dummy/public/javascripts/jquery/core.js +158 -0
  84. data/test/rails-2/dummy/public/javascripts/jquery/ui/rich_cms/core.js +1207 -0
  85. data/test/rails-2/dummy/public/javascripts/jquery/ui/rich_cms/draggable.js +798 -0
  86. data/test/rails-2/dummy/public/javascripts/jquery/ui/rich_cms/mouse.js +950 -0
  87. data/test/rails-2/dummy/public/javascripts/jquery/ui/rich_cms/widget.js +1188 -0
  88. data/test/rails-2/dummy/public/javascripts/rich_cms.js +1746 -0
  89. data/test/rails-2/dummy/public/robots.txt +5 -0
  90. data/test/rails-2/dummy/script/about +4 -0
  91. data/test/rails-2/dummy/script/console +3 -0
  92. data/test/rails-2/dummy/script/dbconsole +3 -0
  93. data/test/rails-2/dummy/script/destroy +3 -0
  94. data/test/rails-2/dummy/script/generate +3 -0
  95. data/test/rails-2/dummy/script/performance/benchmarker +3 -0
  96. data/test/rails-2/dummy/script/performance/profiler +3 -0
  97. data/test/rails-2/dummy/script/plugin +3 -0
  98. data/test/rails-2/dummy/script/runner +3 -0
  99. data/test/rails-2/dummy/script/server +3 -0
  100. data/test/rails-2/dummy/test/fixtures/authlogic_users.yml +6 -0
  101. data/test/rails-2/dummy/test/fixtures/devise_users.yml +5 -0
  102. data/test/rails-2/pending.rb +88 -0
  103. data/test/rails-2/test_helper.rb +13 -0
  104. data/test/rails-3/dummy/.bundle/config +2 -0
  105. data/test/rails-3/dummy/Gemfile +15 -0
  106. data/test/rails-3/dummy/Gemfile.lock +139 -0
  107. data/test/rails-3/dummy/Rakefile +7 -0
  108. data/test/rails-3/dummy/app/controllers/application_controller.rb +3 -0
  109. data/test/rails-3/dummy/app/helpers/application_helper.rb +2 -0
  110. data/test/rails-3/dummy/config/application.rb +42 -0
  111. data/test/rails-3/dummy/config/boot.rb +13 -0
  112. data/test/rails-3/dummy/config/database.yml +23 -0
  113. data/test/rails-3/dummy/config/environment.rb +5 -0
  114. data/test/rails-3/dummy/config/environments/development.rb +26 -0
  115. data/test/rails-3/dummy/config/environments/production.rb +49 -0
  116. data/test/rails-3/dummy/config/environments/test.rb +35 -0
  117. data/test/rails-3/dummy/config/initializers/backtrace_silencers.rb +7 -0
  118. data/test/rails-3/dummy/config/initializers/devise.rb +142 -0
  119. data/test/rails-3/dummy/config/initializers/enrichments.rb +5 -0
  120. data/test/rails-3/dummy/config/initializers/inflections.rb +10 -0
  121. data/test/rails-3/dummy/config/initializers/mime_types.rb +5 -0
  122. data/test/rails-3/dummy/config/initializers/secret_token.rb +7 -0
  123. data/test/rails-3/dummy/config/initializers/session_store.rb +8 -0
  124. data/test/rails-3/dummy/config/locales/en.yml +5 -0
  125. data/test/rails-3/dummy/config/routes.rb +59 -0
  126. data/test/rails-3/dummy/config.ru +4 -0
  127. data/test/rails-3/dummy/db/schema.rb +49 -0
  128. data/test/rails-3/dummy/db/seeds.rb +10 -0
  129. data/test/rails-3/dummy/public/404.html +26 -0
  130. data/test/rails-3/dummy/public/422.html +26 -0
  131. data/test/rails-3/dummy/public/500.html +26 -0
  132. data/test/rails-3/dummy/public/favicon.ico +0 -0
  133. data/test/rails-3/dummy/public/images/rich/cms/cleditor/buttons.gif +0 -0
  134. data/test/rails-3/dummy/public/images/rich/cms/cleditor/toolbar.gif +0 -0
  135. data/test/rails-3/dummy/public/javascripts/jquery/core.js +158 -0
  136. data/test/rails-3/dummy/public/javascripts/jquery/ui/rich_cms/core.js +1207 -0
  137. data/test/rails-3/dummy/public/javascripts/jquery/ui/rich_cms/draggable.js +798 -0
  138. data/test/rails-3/dummy/public/javascripts/jquery/ui/rich_cms/mouse.js +950 -0
  139. data/test/rails-3/dummy/public/javascripts/jquery/ui/rich_cms/widget.js +1188 -0
  140. data/test/rails-3/dummy/public/javascripts/rich_cms.js +1746 -0
  141. data/test/rails-3/dummy/script/rails +6 -0
  142. data/test/rails-3/dummy/test/fixtures/authlogic_users.yml +6 -0
  143. data/test/rails-3/dummy/test/fixtures/devise_users.yml +5 -0
  144. data/test/rails-3/test_helper.rb +17 -0
  145. data/test/shared/dummy/db/schema.rb +49 -0
  146. data/test/shared/dummy/db/seeds.rb +10 -0
  147. data/test/shared/dummy/fixtures/authlogic_users.yml +6 -0
  148. data/test/shared/dummy/models/authlogic_user.rb +8 -0
  149. data/test/shared/dummy/models/authlogic_user_session.rb +10 -0
  150. data/test/shared/dummy/models/cms_content.rb +2 -0
  151. data/test/shared/dummy/models/devise_user.rb +3 -0
  152. data/test/shared/dummy/stylesheets/app.css +100 -0
  153. data/test/shared/dummy/stylesheets/rich_cms.css +159 -0
  154. data/test/shared/dummy/views/application/index.html.erb +13 -0
  155. data/test/shared/dummy/views/layouts/application.html.erb +12 -0
  156. data/test/shared/support/action_controller/integration.rb +55 -0
  157. data/test/shared/support/action_controller/test_case.rb +28 -0
  158. data/test/shared/support/capybara/setup.rb +14 -0
  159. data/test/shared/support/test_helper.rb +1 -0
  160. data/test/shared/tests/actionpack/action_controller/base_test.rb +14 -0
  161. data/test/shared/tests/actionpack/action_view/base_test.rb +19 -0
  162. data/test/shared/tests/activesupport/active_support/dependencies_test.rb +15 -0
  163. data/test/shared/tests/app/integration/authenticated/authlogic.rb +88 -0
  164. data/test/shared/tests/app/integration/authenticated/devise_test.rb +89 -0
  165. data/test/shared/tests/app/integration/non_authenticated.rb +63 -0
  166. data/test/shared/tests/app/routing_test.rb +31 -0
  167. data/test/shared/tests/auth_test.rb +11 -0
  168. data/test/shared/tests/content/group.rb +10 -0
  169. data/test/shared/tests/content/item.rb +10 -0
  170. data/test/shared/tests/core/string/html_safe.rb +15 -0
  171. data/test/shared/tests/dummy_app.rb +228 -0
  172. data/test/shared/tests/engine_test.rb +19 -0
  173. data/test/shared/tests/rails/engine_test.rb +13 -0
  174. data/test/shared/tests/readme_test.rb +13 -0
  175. metadata +231 -63
  176. data/.gitignore +0 -2
  177. data/lib/generators/rich/authlogic_user/authlogic_user_generator.rb +0 -64
  178. data/rails_generators/rich_authlogic_user/rich_authlogic_user_generator.rb +0 -64
  179. data/test/test_helper.rb +0 -6
@@ -0,0 +1,89 @@
1
+ require File.expand_path("../../../../dummy_app.rb", __FILE__)
2
+
3
+ DummyApp.setup "Devise" do |app|
4
+ app.generate_cms_admin
5
+ app.restore_admin_fixtures
6
+ app.replace_devise_pepper
7
+ app.generate_cms_content
8
+ end
9
+
10
+ module App
11
+ module Integration
12
+ module Authenticated
13
+ class DeviseTest < ActionController::IntegrationTest
14
+ fixtures :devise_users
15
+
16
+ context "Rich-CMS implemented with Devise" do
17
+ setup do
18
+ Rich::Cms::Auth.setup do |config|
19
+ config.logic = :devise
20
+ config.klass = "DeviseUser"
21
+ end
22
+ visit "/cms/logout"
23
+ end
24
+
25
+ teardown do
26
+ DummyApp.restore_all true
27
+ end
28
+
29
+ should "behave as expected" do
30
+ visit "/"
31
+ assert page.has_no_css? "div#rich_cms_dock"
32
+ assert page.has_no_css? ".cms_content"
33
+ assert_equal "header" , find(".left h1" ).text
34
+ assert_equal "paragraph", find(".left div").text
35
+
36
+ visit "/cms"
37
+
38
+ assert page.has_css? "div#rich_cms_dock"
39
+ assert page.has_no_css? ".cms_content"
40
+
41
+ visit "/cms/hide"
42
+ assert page.has_no_css? "div#rich_cms_dock"
43
+ assert page.has_no_css? ".cms_content"
44
+ login
45
+
46
+ assert page.has_css? "div#rich_cms_dock"
47
+ assert page.has_content? "Mark content"
48
+ assert_equal "< header >" , find(".left h1.cms_content" ).text
49
+ assert_equal "< paragraph >", find(".left div.cms_content").text
50
+
51
+ mark_content
52
+ assert page.has_css? ".cms_content.marked"
53
+
54
+ edit_content "header"
55
+ assert_equal ".cms_content", find("#raccoon_tip input[name='content_item[__selector__]']").value
56
+ assert_equal "" , find("#raccoon_tip input[name='content_item[value]']" ).value
57
+
58
+ fill_in_and_submit "#raccoon_tip", {:"content_item[value]" => "Try out Rich-CMS!"}, "Save"
59
+ assert_equal "Try out Rich-CMS!", find(".left h1.cms_content" ).text
60
+ assert_equal "< paragraph >" , find(".left div.cms_content").text
61
+
62
+ edit_content "paragraph"
63
+ assert_equal ".cms_content", find("#raccoon_tip input[name='content_item[__selector__]']").value
64
+ assert_equal "" , find("#raccoon_tip textarea[name='content_item[value]']" ).value
65
+
66
+ fill_in_and_submit "#raccoon_tip", {:"content_item[value]" => "<p>Lorem ipsum dolor sit amet.</p>"}, "Save"
67
+ assert_equal "Try out Rich-CMS!" , find(".left h1.cms_content" ).text
68
+ assert_equal "Lorem ipsum dolor sit amet.", find(".left div.cms_content p").text
69
+
70
+ hide_dock
71
+ assert page.has_no_css? "div#rich_cms_dock"
72
+ assert page.has_css? ".cms_content"
73
+
74
+ visit "/cms"
75
+ assert page.has_css? "div#rich_cms_dock"
76
+ assert page.has_css? ".cms_content"
77
+
78
+ logout
79
+ assert page.has_no_css? "div#rich_cms_dock"
80
+ assert page.has_no_css? ".cms_content"
81
+ assert_equal "Try out Rich-CMS!" , find(".left h1" ).text
82
+ assert_equal "Lorem ipsum dolor sit amet.", find(".left div p").text
83
+ end
84
+ end
85
+
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,63 @@
1
+ require File.expand_path("../../../dummy_app.rb", __FILE__)
2
+
3
+ DummyApp.setup "Non authenticated" do |app|
4
+ app.generate_cms_content
5
+ end
6
+
7
+ module App
8
+ module Integration
9
+ class NonAuthenticatedTest < ActionController::IntegrationTest
10
+
11
+ context "Rich-CMS without authentication" do
12
+ setup do
13
+ Rich::Cms::Auth.setup do |config|
14
+ # no authentication
15
+ end
16
+ visit "/cms/logout"
17
+ end
18
+
19
+ teardown do
20
+ DummyApp.restore_all true
21
+ end
22
+
23
+ should "behave as expected" do
24
+ visit "/"
25
+ assert page.has_no_css? "div#rich_cms_dock"
26
+ assert_equal "< header >" , find(".left h1.cms_content" ).text
27
+ assert_equal "< paragraph >", find(".left div.cms_content").text
28
+
29
+ visit "/cms"
30
+ assert page.has_css? "div#rich_cms_dock"
31
+ assert page.has_content? "Mark content"
32
+
33
+ mark_content
34
+ assert page.has_css? ".cms_content.marked"
35
+
36
+ visit "/cms"
37
+ mark_content
38
+
39
+ edit_content "header"
40
+ assert_equal ".cms_content", find("#raccoon_tip input[name='content_item[__selector__]']").value
41
+ assert_equal "" , find("#raccoon_tip input[name='content_item[value]']" ).value
42
+
43
+ fill_in_and_submit "#raccoon_tip", {:"content_item[value]" => "Try out Rich-CMS!"}, "Save"
44
+ assert_equal "Try out Rich-CMS!", find(".left h1.cms_content" ).text
45
+ assert_equal "< paragraph >" , find(".left div.cms_content").text
46
+
47
+ edit_content "paragraph"
48
+ assert_equal ".cms_content", find("#raccoon_tip input[name='content_item[__selector__]']").value
49
+ assert_equal "" , find("#raccoon_tip textarea[name='content_item[value]']" ).value
50
+
51
+ fill_in_and_submit "#raccoon_tip", {:"content_item[value]" => "<p>Lorem ipsum dolor sit amet.</p>"}, "Save"
52
+ assert_equal "Try out Rich-CMS!" , find(".left h1.cms_content" ).text
53
+ assert_equal "Lorem ipsum dolor sit amet.", find(".left div.cms_content p").text
54
+
55
+ hide_dock
56
+ assert page.has_no_css? "div#rich_cms_dock"
57
+ assert page.has_css? ".cms_content"
58
+ end
59
+ end
60
+
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,31 @@
1
+ require File.expand_path("../../../test_helper.rb", __FILE__)
2
+
3
+ module App
4
+ class RoutingTest < ActionController::TestCase
5
+
6
+ test "rich_cms" do
7
+ assert_routing "/cms", :controller => "rich/cms", :action => "display", :display => true
8
+ assert_named_route "/cms", :rich_cms
9
+ end
10
+
11
+ test "rich_cms_hide" do
12
+ assert_routing "/cms/hide", :controller => "rich/cms", :action => "display", :display => false
13
+ assert_named_route "/cms/hide", :rich_cms_hide
14
+ end
15
+
16
+ %w(login logout).each do |action|
17
+ test "rich_cms_#{action}" do
18
+ assert_routing "/cms/#{action}", :controller => "rich/cms_sessions", :action => action
19
+ assert_named_route "/cms/#{action}", :"rich_cms_#{action}"
20
+ end
21
+ end
22
+
23
+ %w(position update).each do |action|
24
+ test "rich_cms_#{action}" do
25
+ assert_routing "/cms/#{action}", :controller => "rich/cms", :action => action
26
+ assert_named_route "/cms/#{action}", :"rich_cms_#{action}"
27
+ end
28
+ end
29
+
30
+ end
31
+ end
@@ -0,0 +1,11 @@
1
+ require File.expand_path("../../test_helper.rb", __FILE__)
2
+
3
+ class AuthTest < ActiveSupport::TestCase
4
+
5
+ context "Rich::Cms::Auth" do
6
+ should "be defined" do
7
+ assert defined?(::Rich::Cms::Auth)
8
+ end
9
+ end
10
+
11
+ end
@@ -0,0 +1,10 @@
1
+ require File.expand_path("../../../test_helper.rb", __FILE__)
2
+
3
+ module Content
4
+ class GroupTest < ActiveSupport::TestCase
5
+
6
+ test "do something" do
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ require File.expand_path("../../../test_helper.rb", __FILE__)
2
+
3
+ module Content
4
+ class ItemTest < ActiveSupport::TestCase
5
+
6
+ test "do something" do
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,15 @@
1
+ require File.expand_path("../../../../test_helper.rb", __FILE__)
2
+
3
+ module Core
4
+ module String
5
+ class HtmlSafeTest < ActiveSupport::TestCase
6
+
7
+ context "A String" do
8
+ should "respond to :html_safe" do
9
+ assert "".respond_to?(:html_safe)
10
+ end
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,228 @@
1
+ STDOUT.sync = true
2
+
3
+ module DummyApp
4
+ extend self
5
+
6
+ def setup(description, &block)
7
+ log "\n".ljust 145, "="
8
+ log "Setting up test environment for Rails #{major_rails_version} - #{description}\n"
9
+ log "\n".rjust 145, "="
10
+
11
+ restore_all
12
+ stash_all
13
+ yield self if block_given?
14
+ prepare_database
15
+ @prepared = true
16
+
17
+ log "=".ljust 145, "="
18
+ require File.expand_path("../../test_helper.rb", __FILE__)
19
+ end
20
+
21
+ def prepare_database
22
+ return if @db_prepared
23
+ if @ran_generator
24
+ stash "db/schema.rb", :schema
25
+ run "rake db:test:purge"
26
+ run "RAILS_ENV=test rake db:migrate"
27
+ else
28
+ run "rake db:test:load"
29
+ end
30
+ @db_prepared = true
31
+ end
32
+
33
+ def restore_all(force = nil)
34
+ if @prepared
35
+ unless force
36
+ log "Cannot (non-forced) restore files after having prepared the dummy app" unless force.nil?
37
+ return
38
+ end
39
+ end
40
+
41
+ delete "config/locales/devise.en.yml"
42
+ delete "db/migrate/*.rb"
43
+ delete "test/fixtures/cms_contents.yml"
44
+ delete "test/unit/*.rb"
45
+ restore "app/models/*.rb.#{STASHED_EXT}"
46
+ restore "**/*.#{STASHED_EXT}"
47
+ end
48
+
49
+ def stash_all
50
+ stash "Gemfile", :gemfile
51
+ stash "Gemfile.lock"
52
+ stash "app/models/*.rb"
53
+ stash "config/initializers/devise.rb"
54
+ stash "config/initializers/enrichments.rb"
55
+ stash "config/routes.rb", :routes
56
+ stash "test/fixtures/*_users.yml"
57
+ delete "db/migrate/*.rb"
58
+ end
59
+
60
+ def generate_cms_admin(logic = :devise)
61
+ logic_option = {:devise => "d", :authlogic => "a"}[@logic = logic]
62
+
63
+ if logic_option
64
+ klass = "#{logic.to_s.capitalize}User"
65
+
66
+ run case major_rails_version
67
+ when 2
68
+ "script/generate rich_cms_admin #{klass} -#{logic_option}"
69
+ when 3
70
+ "rails g rich:cms_admin #{klass} -#{logic_option}"
71
+ end
72
+ end
73
+
74
+ @ran_generator = true
75
+ end
76
+
77
+ def restore_admin_fixtures
78
+ restore "test/fixtures/#{@logic}_users.yml.#{STASHED_EXT}"
79
+ end
80
+
81
+ def replace_devise_pepper
82
+ devise_config = expand_path("config/initializers/devise.rb")
83
+ lines = File.open(devise_config).readlines
84
+ pepper = "b57fdc3ba6288df70ca46cf2f7a6c168408e2fd602a185deda0340db3f1b4427d7c02e94880ec3786a26c248ff40b12f4e39d3315bb7ddf5541b9efb27ecd8f7"
85
+
86
+ File.open(devise_config, "w") do |file|
87
+ lines.each do |line|
88
+ file << line.gsub(/(config\.pepper = ").*(")/, "config.pepper = \"#{pepper}\"")
89
+ end
90
+ end
91
+ end
92
+
93
+ def generate_cms_content
94
+ klass = "CmsContent"
95
+
96
+ run case major_rails_version
97
+ when 2
98
+ "script/generate rich_cms_content #{klass}"
99
+ when 3
100
+ "rails g rich:cms_content #{klass}"
101
+ end
102
+
103
+ @ran_generator = true
104
+ end
105
+
106
+ private
107
+
108
+ STASHED_EXT = "stashed"
109
+
110
+ def root_dir
111
+ @root_dir ||= File.expand_path("../../dummy/", __FILE__)
112
+ end
113
+
114
+ def major_rails_version
115
+ @major_rails_version ||= root_dir.match(/\/rails-(\d)\//)[1].to_i
116
+ end
117
+
118
+ def expand_path(path)
119
+ path.match(root_dir) ?
120
+ path :
121
+ File.expand_path(path, root_dir)
122
+ end
123
+
124
+ def target(file)
125
+ file.gsub /\.#{STASHED_EXT}$/, ""
126
+ end
127
+
128
+ def stashed(file)
129
+ file.match(/\.#{STASHED_EXT}$/) ?
130
+ file :
131
+ "#{file}.#{STASHED_EXT}"
132
+ end
133
+
134
+ def restore(string)
135
+ Dir[expand_path(string)].each do |file|
136
+ if File.exists?(stashed(file))
137
+ delete target(file)
138
+ log "Restoring #{stashed(file)}"
139
+ File.rename stashed(file), target(file)
140
+ end
141
+ end
142
+ end
143
+
144
+ def stash(string, replacement = nil)
145
+ Dir[expand_path(string)].each do |file|
146
+ unless File.exists?(stashed(file))
147
+ log "Stashing #{target(file)}"
148
+ File.rename target(file), stashed(file)
149
+ replace(file, replacement)
150
+ end
151
+ end
152
+ end
153
+
154
+ def delete(string)
155
+ Dir[expand_path(string)].each do |file|
156
+ log "Deleting #{file}"
157
+ File.delete file
158
+ end
159
+
160
+ dirname = expand_path File.dirname(string)
161
+
162
+ return unless File.exists?(dirname)
163
+ Dir.glob("#{dirname}/*", File::FNM_DOTMATCH) do |file|
164
+ return unless %w(. ..).include? File.basename(file)
165
+ end
166
+
167
+ log "Deleting #{dirname}"
168
+ Dir.delete dirname
169
+ end
170
+
171
+ def replace(file, replacement)
172
+ content = case replacement
173
+ when :gemfile
174
+ <<-CONTENT.gsub(/^ {18}/, "")
175
+ source "http://rubygems.org"
176
+
177
+ gem "rails", "#{{2 => "2.3.10", 3 => "3.0.3"}[major_rails_version]}"
178
+ gem "mysql2"
179
+
180
+ gem "authlogic"
181
+ gem "devise", "~> #{{2 => "1.0.9", 3 => "1.1.5"}[major_rails_version]}"
182
+ gem "rich_cms", :path => File.join(File.dirname(__FILE__), "..", "..", "..")
183
+
184
+ gem "shoulda"
185
+ gem "mocha"
186
+ gem "capybara"
187
+ gem "launchy"
188
+ CONTENT
189
+ when :schema
190
+ <<-CONTENT.gsub(/^ {18}/, "")
191
+ ActiveRecord::Schema.define(:version => 19820801180828) do
192
+ end
193
+ CONTENT
194
+ when :routes
195
+ case major_rails_version
196
+ when 2
197
+ <<-CONTENT.gsub(/^ {20}/, "")
198
+ ActionController::Routing::Routes.draw do |map|
199
+ map.root :controller => "application"
200
+ map.connect ':controller/:action/:id'
201
+ map.connect ':controller/:action/:id.:format'
202
+ end
203
+ CONTENT
204
+ when 3
205
+ <<-CONTENT.gsub(/^ {20}/, "")
206
+ Dummy::Application.routes.draw do
207
+ root :to => "application#index"
208
+ end
209
+ CONTENT
210
+ end
211
+ end
212
+
213
+ File.open target(file), "w" do |file|
214
+ file << content
215
+ end if content
216
+ end
217
+
218
+ def run(command)
219
+ return if command.to_s.gsub(/\s/, "").size == 0
220
+ log "Executing #{command}"
221
+ `cd #{root_dir} && #{command}`
222
+ end
223
+
224
+ def log(string)
225
+ puts string
226
+ end
227
+
228
+ end
@@ -0,0 +1,19 @@
1
+ require File.expand_path("../../test_helper.rb", __FILE__)
2
+
3
+ class EngineTest < ActiveSupport::TestCase
4
+
5
+ context "Rich::Cms::Engine" do
6
+ should "be defined" do
7
+ assert defined?(Rich::Cms::Engine)
8
+ end
9
+
10
+ should "respond to :init" do
11
+ assert Rich::Cms::Engine.respond_to?(:init)
12
+ end
13
+
14
+ context "on initialization" do
15
+ # test something
16
+ end
17
+ end
18
+
19
+ end
@@ -0,0 +1,13 @@
1
+ require File.expand_path("../../../test_helper.rb", __FILE__)
2
+
3
+ module Rails
4
+ class EngineTest < ActiveSupport::TestCase
5
+
6
+ context "Rails::Engine" do
7
+ should "be defined" do
8
+ assert defined?(Rails::Engine)
9
+ end
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ require File.expand_path("../../test_helper.rb", __FILE__)
2
+
3
+ class ReadmeTest < ActiveSupport::TestCase
4
+
5
+ context "something" do
6
+ setup do
7
+ end
8
+
9
+ should "do something" do
10
+ end
11
+ end
12
+
13
+ end