comfortable_mexican_sofa 1.12.2 → 1.12.3

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.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/comfortable_mexican_sofa/admin/application.js +1 -1
  3. data/app/assets/javascripts/comfortable_mexican_sofa/application.js.coffee +50 -57
  4. data/app/assets/javascripts/comfortable_mexican_sofa/cms/files.js.coffee +29 -0
  5. data/app/assets/javascripts/comfortable_mexican_sofa/cms/uploader.js.coffee +139 -0
  6. data/app/assets/stylesheets/comfortable_mexican_sofa/admin/application.css +1 -1
  7. data/app/assets/stylesheets/comfortable_mexican_sofa/application.css.sass +1 -0
  8. data/app/assets/stylesheets/comfortable_mexican_sofa/base.css.sass +67 -84
  9. data/app/controllers/comfy/admin/cms/base_controller.rb +11 -8
  10. data/app/controllers/comfy/admin/cms/categories_controller.rb +10 -9
  11. data/app/controllers/comfy/admin/cms/files_controller.rb +38 -69
  12. data/app/controllers/comfy/admin/cms/layouts_controller.rb +4 -3
  13. data/app/controllers/comfy/admin/cms/pages_controller.rb +17 -11
  14. data/app/controllers/comfy/admin/cms/revisions_controller.rb +10 -9
  15. data/app/controllers/comfy/admin/cms/sites_controller.rb +2 -1
  16. data/app/controllers/comfy/admin/cms/snippets_controller.rb +3 -2
  17. data/app/controllers/comfy/cms/assets_controller.rb +17 -9
  18. data/app/controllers/comfy/cms/content_controller.rb +20 -14
  19. data/app/models/comfy/cms/file.rb +16 -15
  20. data/app/models/comfy/cms/page.rb +2 -1
  21. data/app/models/comfy/cms/site.rb +5 -0
  22. data/app/views/comfy/admin/cms/files/_file.html.haml +26 -13
  23. data/app/views/comfy/admin/cms/files/_form.html.haml +8 -5
  24. data/app/views/comfy/admin/cms/files/_modal.html.haml +4 -0
  25. data/app/views/comfy/admin/cms/files/create.js.erb +1 -0
  26. data/app/views/comfy/admin/cms/files/destroy.js.coffee +2 -2
  27. data/app/views/comfy/admin/cms/files/index.html.haml +33 -31
  28. data/app/views/comfy/admin/cms/layouts/_form.html.haml +2 -5
  29. data/app/views/comfy/admin/cms/pages/_form.html.haml +7 -8
  30. data/app/views/comfy/admin/cms/pages/_form_blocks.html.haml +3 -3
  31. data/app/views/comfy/admin/cms/sites/_form.html.haml +2 -2
  32. data/app/views/comfy/admin/cms/sites/index.html.haml +1 -2
  33. data/app/views/comfy/admin/cms/snippets/_form.html.haml +5 -8
  34. data/app/views/kaminari/comfy/_paginator.html.haml +10 -11
  35. data/app/views/layouts/comfy/admin/cms.html.haml +3 -2
  36. data/app/views/layouts/comfy/admin/cms/_body.html.haml +8 -7
  37. data/app/views/layouts/comfy/admin/cms/{_center.html.haml → _flash.html.haml} +0 -3
  38. data/app/views/layouts/comfy/admin/cms/_footer_js.html.haml +0 -4
  39. data/app/views/layouts/comfy/admin/cms/_left.html.haml +10 -5
  40. data/comfortable_mexican_sofa.gemspec +9 -8
  41. data/config/cms_routes.rb +2 -2
  42. data/config/initializers/comfortable_mexican_sofa.rb +31 -13
  43. data/config/initializers/plupload.rb +9 -0
  44. data/config/locales/en.yml +18 -16
  45. data/db/upgrade_migrations/08_upgrade_to_1_12_0.rb +3 -0
  46. data/lib/comfortable_mexican_sofa.rb +6 -5
  47. data/lib/comfortable_mexican_sofa/access_control/admin_authentication.rb +20 -0
  48. data/lib/comfortable_mexican_sofa/access_control/admin_authorization.rb +8 -0
  49. data/lib/comfortable_mexican_sofa/access_control/public_authentication.rb +8 -0
  50. data/lib/comfortable_mexican_sofa/configuration.rb +11 -3
  51. data/lib/comfortable_mexican_sofa/engine.rb +1 -0
  52. data/lib/comfortable_mexican_sofa/fixture.rb +7 -5
  53. data/lib/comfortable_mexican_sofa/fixture/category.rb +10 -3
  54. data/lib/comfortable_mexican_sofa/form_builder.rb +1 -1
  55. data/lib/comfortable_mexican_sofa/routes/cms.rb +3 -0
  56. data/lib/comfortable_mexican_sofa/version.rb +1 -1
  57. data/lib/generators/comfy/cms/assets_generator.rb +15 -0
  58. data/lib/generators/comfy/cms/cms_generator.rb +19 -12
  59. data/lib/generators/comfy/cms/controllers_generator.rb +13 -0
  60. data/lib/generators/comfy/cms/models_generator.rb +13 -0
  61. data/lib/generators/comfy/cms/views_generator.rb +13 -0
  62. data/test/controllers/comfy/admin/cms/files_controller_test.rb +22 -95
  63. data/test/controllers/comfy/admin/cms/layouts_controller_test.rb +9 -10
  64. data/test/controllers/comfy/admin/cms/pages_controller_test.rb +26 -27
  65. data/test/controllers/comfy/admin/cms/snippets_controller_test.rb +7 -8
  66. data/test/controllers/comfy/cms/content_controller_test.rb +30 -4
  67. data/test/gemfiles/Gemfile.rails.4.0 +3 -2
  68. data/test/gemfiles/Gemfile.rails.4.1 +3 -2
  69. data/test/gemfiles/Gemfile.rails.master +3 -2
  70. data/test/generators/cms_assets_generator_test.rb +13 -0
  71. data/test/generators/cms_controllers_generator_test.rb +12 -0
  72. data/test/generators/cms_generator_test.rb +10 -8
  73. data/test/generators/cms_models_generator_test.rb +12 -0
  74. data/test/generators/cms_views_generator_test.rb +12 -0
  75. data/test/generators/scaffold_generator_test.rb +6 -7
  76. data/test/integration/access_control_test.rb +141 -0
  77. data/test/integration/routing_test.rb +19 -0
  78. data/test/lib/configuration_test.rb +8 -7
  79. data/test/lib/fixtures/categories_test.rb +1 -0
  80. data/test/lib/fixtures/files_test.rb +5 -0
  81. data/test/lib/fixtures/pages_test.rb +17 -1
  82. data/test/lib/fixtures/snippets_test.rb +5 -0
  83. data/test/models/page_test.rb +6 -0
  84. data/test/models/site_test.rb +9 -0
  85. data/test/test_helper.rb +28 -19
  86. metadata +82 -48
  87. data/app/views/comfy/admin/cms/files/_index.html.haml +0 -11
  88. data/lib/comfortable_mexican_sofa/authentication/dummy_auth.rb +0 -8
  89. data/lib/comfortable_mexican_sofa/authentication/http_auth.rb +0 -25
  90. data/test/integration/authentication_test.rb +0 -48
@@ -0,0 +1,12 @@
1
+ require_relative '../test_helper'
2
+ require_relative '../../lib/generators/comfy/cms/views_generator'
3
+
4
+ class CmsViewsGeneratorTest < Rails::Generators::TestCase
5
+ tests Comfy::Generators::Cms::ViewsGenerator
6
+
7
+ def test_generator
8
+ run_generator
9
+ assert_directory 'app/views/comfy'
10
+ assert_file 'app/views/comfy/admin/cms/pages/index.html.haml'
11
+ end
12
+ end
@@ -3,29 +3,28 @@ require_relative '../../lib/generators/comfy/scaffold/scaffold_generator'
3
3
 
4
4
  class ScaffoldGeneratorTest < Rails::Generators::TestCase
5
5
  tests Comfy::Generators::ScaffoldGenerator
6
-
6
+
7
7
  def test_generator
8
8
  run_generator %w(Foo bar:string)
9
-
9
+
10
10
  assert_migration 'db/migrate/create_foos.rb', read_file('scaffold/migration.rb')
11
11
  assert_file 'app/models/foo.rb', read_file('scaffold/model.rb')
12
12
  assert_file 'test/models/foo_test.rb', read_file('scaffold/tests/model.rb')
13
13
  assert_file 'test/fixtures/foos.yml', read_file('scaffold/tests/fixture')
14
-
14
+
15
15
  assert_file 'app/controllers/admin/foos_controller.rb', read_file('scaffold/controller.rb')
16
16
  assert_file 'test/controllers/admin/foos_controller_test.rb', read_file('scaffold/tests/controller.rb')
17
-
17
+
18
18
  assert_file 'app/views/admin/foos/index.html.haml', read_file('scaffold/views/index.haml')
19
19
  assert_file 'app/views/admin/foos/show.html.haml', read_file('scaffold/views/show.haml')
20
20
  assert_file 'app/views/admin/foos/new.html.haml', read_file('scaffold/views/new.haml')
21
21
  assert_file 'app/views/admin/foos/edit.html.haml', read_file('scaffold/views/edit.haml')
22
22
  assert_file 'app/views/admin/foos/_form.html.haml', read_file('scaffold/views/_form.haml')
23
-
23
+
24
24
  assert_file 'config/routes.rb', read_file('scaffold/routes.rb')
25
-
25
+
26
26
  assert_file 'app/views/comfy/admin/cms/partials/_navigation_inner.html.haml' do |file|
27
27
  assert_match "%li= active_link_to 'Foos', admin_foos_path", file
28
28
  end
29
29
  end
30
-
31
30
  end
@@ -0,0 +1,141 @@
1
+ require_relative '../test_helper'
2
+
3
+ class AccessControlTest < ActionDispatch::IntegrationTest
4
+
5
+ module TestAuthentication
6
+ module Authenticate
7
+ def authenticate
8
+ render :text => 'Test Login Denied', :status => :unauthorized
9
+ end
10
+ end
11
+
12
+ # faking ComfortableMexicanSofa.config.admin_auth = 'AccessControlTest::TestAuthentication'
13
+ # faking ComfortableMexicanSofa.config.public_auth = 'AccessControlTest::TestAuthentication'
14
+ class SitesController < Comfy::Admin::Cms::SitesController; include Authenticate; end
15
+ class ContentController < Comfy::Cms::ContentController; include Authenticate; end
16
+ end
17
+
18
+ module TestAuthorization
19
+ module Authorize
20
+ def authorize
21
+ @authorization_vars = self.instance_variables
22
+ render :text => 'Test Access Denied', :status => :forbidden
23
+ end
24
+ end
25
+
26
+ # faking ComfortableMexicanSofa.config.admin_authorization = 'AccessControlTest::TestAuthorization'
27
+ class SitesController < Comfy::Admin::Cms::SitesController; include Authorize; end
28
+ class LayoutsController < Comfy::Admin::Cms::LayoutsController; include Authorize; end
29
+ class PagesController < Comfy::Admin::Cms::PagesController; include Authorize; end
30
+ class SnippetsController < Comfy::Admin::Cms::SnippetsController; include Authorize; end
31
+ class FilesController < Comfy::Admin::Cms::FilesController; include Authorize; end
32
+ class CategoriesController < Comfy::Admin::Cms::CategoriesController; include Authorize; end
33
+ class RevisionsController < Comfy::Admin::Cms::RevisionsController; include Authorize; end
34
+ end
35
+
36
+
37
+ def test_admin_authentication_default
38
+ assert_equal 'ComfortableMexicanSofa::AccessControl::AdminAuthentication',
39
+ ComfortableMexicanSofa.config.admin_auth
40
+
41
+ get '/admin/sites'
42
+ assert_response :unauthorized
43
+
44
+ http_auth :get, '/admin/sites'
45
+ assert_response :success
46
+ end
47
+
48
+ def test_admin_authentication_custom
49
+ with_routing do |routes|
50
+ routes.draw do
51
+ get '/admin/sites' => 'access_control_test/test_authentication/sites#index'
52
+ end
53
+
54
+ get '/admin/sites'
55
+ assert_response :unauthorized
56
+ assert_equal 'Test Login Denied', response.body
57
+ end
58
+ end
59
+
60
+ def test_admin_authorization_default
61
+ assert_equal 'ComfortableMexicanSofa::AccessControl::AdminAuthorization',
62
+ ComfortableMexicanSofa.config.admin_authorization
63
+
64
+ Comfy::Admin::Cms::BaseController.send(:include, ComfortableMexicanSofa::AccessControl::AdminAuthorization)
65
+ http_auth :get, "/admin/sites/#{comfy_cms_sites(:default).to_param}/edit"
66
+ assert_response :success, response.body
67
+ end
68
+
69
+ def test_admin_authorization_custom
70
+ site = comfy_cms_sites(:default)
71
+ with_routing do |routes|
72
+ routes.draw do
73
+ s = '/admin/sites'
74
+ ns = 'access_control_test/test_authorization'
75
+ get "#{s}/:id/edit" => "#{ns}/sites#edit"
76
+ get "#{s}/:site_id/layouts/:id/edit" => "#{ns}/layouts#edit"
77
+ get "#{s}/:site_id/layouts/:layout_id/revisions/:id" => "#{ns}/revisions#show"
78
+ get "#{s}/:site_id/pages/:id/edit" => "#{ns}/pages#edit"
79
+ get "#{s}/:site_id/snippets/:id/edit" => "#{ns}/snippets#edit"
80
+ get "#{s}/:site_id/files/:id/edit" => "#{ns}/files#edit"
81
+ get "#{s}/:site_id/categories/:id/edit" => "#{ns}/categories#edit"
82
+ end
83
+
84
+ http_auth :get, "/admin/sites/#{site.id}/edit"
85
+ assert_response :forbidden
86
+ assert_equal 'Test Access Denied', response.body
87
+ assert assigns(:authorization_vars)
88
+ assert assigns(:authorization_vars).member?(:@site)
89
+
90
+ layout = comfy_cms_layouts(:default)
91
+ http_auth :get, "/admin/sites/#{site.id}/layouts/#{layout.id}/edit"
92
+ assert assigns(:authorization_vars).member?(:@site)
93
+ assert assigns(:authorization_vars).member?(:@layout)
94
+
95
+ revision = comfy_cms_revisions(:layout)
96
+ http_auth :get, "/admin/sites/#{site.id}/layouts/#{layout.id}/revisions/#{revision.id}"
97
+ assert assigns(:authorization_vars).member?(:@site)
98
+ assert assigns(:authorization_vars).member?(:@record)
99
+
100
+ page = comfy_cms_pages(:default)
101
+ http_auth :get, "/admin/sites/#{site.id}/pages/#{page.id}/edit"
102
+ assert assigns(:authorization_vars).member?(:@site)
103
+ assert assigns(:authorization_vars).member?(:@page)
104
+
105
+ snippet = comfy_cms_snippets(:default)
106
+ http_auth :get, "/admin/sites/#{site.id}/snippets/#{snippet.id}/edit"
107
+ assert assigns(:authorization_vars).member?(:@site)
108
+ assert assigns(:authorization_vars).member?(:@snippet)
109
+
110
+ file = comfy_cms_files(:default)
111
+ http_auth :get, "/admin/sites/#{site.id}/files/#{file.id}/edit"
112
+ assert assigns(:authorization_vars).member?(:@site)
113
+ assert assigns(:authorization_vars).member?(:@file)
114
+
115
+ category = comfy_cms_categories(:default)
116
+ http_auth :get, "/admin/sites/#{site.id}/categories/#{category.id}/edit"
117
+ assert assigns(:authorization_vars).member?(:@site)
118
+ assert assigns(:authorization_vars).member?(:@category)
119
+ end
120
+ end
121
+
122
+ def test_public_authentication_default
123
+ assert_equal 'ComfortableMexicanSofa::AccessControl::PublicAuthentication',
124
+ ComfortableMexicanSofa.config.public_auth
125
+
126
+ get '/'
127
+ assert_response :success, response.body
128
+ end
129
+
130
+ def test_public_authentication_custom
131
+ with_routing do |routes|
132
+ routes.draw do
133
+ get '/:format' => 'access_control_test/test_authentication/content#show', :path => "(*cms_path)"
134
+ end
135
+
136
+ get '/'
137
+ assert_response :unauthorized
138
+ assert_equal 'Test Login Denied', response.body
139
+ end
140
+ end
141
+ end
@@ -0,0 +1,19 @@
1
+ require_relative '../test_helper'
2
+
3
+ class RoutingIntergrationTest < ActionDispatch::IntegrationTest
4
+
5
+ def teardown
6
+ Rails.application.reload_routes!
7
+ end
8
+
9
+ def test_cms_public_prefix
10
+
11
+ assert_equal nil, ComfortableMexicanSofa.config.public_cms_path
12
+
13
+ Rails.application.routes.draw do
14
+ comfy_route :cms, :path => '/custom'
15
+ end
16
+
17
+ assert_equal '/custom', ComfortableMexicanSofa.config.public_cms_path
18
+ end
19
+ end
@@ -3,18 +3,19 @@
3
3
  require_relative '../test_helper'
4
4
 
5
5
  class ConfigurationTest < ActiveSupport::TestCase
6
-
6
+
7
7
  def test_configuration_presence
8
8
  assert config = ComfortableMexicanSofa.configuration
9
9
  assert_equal 'ComfortableMexicanSofa CMS Engine', config.cms_title
10
10
  assert_equal 'ApplicationController', config.base_controller
11
- assert_equal 'ComfortableMexicanSofa::HttpAuth', config.admin_auth
12
- assert_equal 'ComfortableMexicanSofa::DummyAuth', config.public_auth
11
+ assert_equal 'ComfortableMexicanSofa::AccessControl::AdminAuthentication', config.admin_auth
12
+ assert_equal 'ComfortableMexicanSofa::AccessControl::AdminAuthorization', config.admin_authorization
13
+ assert_equal 'ComfortableMexicanSofa::AccessControl::PublicAuthentication', config.public_auth
13
14
  assert_equal '', config.admin_route_redirect
14
15
  assert_equal false, config.enable_fixtures
15
16
  assert_equal File.expand_path('db/cms_fixtures', Rails.root), config.fixtures_path
16
17
  assert_equal 25, config.revisions_limit
17
- assert_equal ({
18
+ assert_equal ({
18
19
  'en' => 'English',
19
20
  'es' => 'Español'
20
21
  }), config.locales
@@ -26,14 +27,14 @@ class ConfigurationTest < ActiveSupport::TestCase
26
27
  assert_equal nil, config.allowed_partials
27
28
  assert_equal nil, config.hostname_aliases
28
29
  end
29
-
30
+
30
31
  def test_initialization_overrides
31
32
  ComfortableMexicanSofa.configuration.cms_title = 'New Title'
32
33
  assert_equal 'New Title', ComfortableMexicanSofa.configuration.cms_title
33
34
  end
34
-
35
+
35
36
  def test_version
36
37
  assert ComfortableMexicanSofa::VERSION
37
38
  end
38
-
39
+
39
40
  end
@@ -5,6 +5,7 @@ require_relative '../../test_helper'
5
5
  class FixtureCategoriesTest < ActiveSupport::TestCase
6
6
 
7
7
  def test_creation
8
+ Comfy::Cms::Category.destroy_all
8
9
  assert_difference 'Comfy::Cms::Category.count', 3 do
9
10
  ComfortableMexicanSofa::Fixture::Category::Importer.new('sample-site', 'default-site').import!
10
11
  assert Comfy::Cms::Category.where(:label => 'File Category', :categorized_type => 'Comfy::Cms::File').present?
@@ -7,6 +7,11 @@ class FixtureFilesTest < ActiveSupport::TestCase
7
7
  def test_creation
8
8
  Comfy::Cms::File.delete_all
9
9
 
10
+ # need to have categories present before linking
11
+ site = comfy_cms_sites(:default)
12
+ site.categories.create!(:categorized_type => 'Comfy::Cms::File', :label => 'category_a')
13
+ site.categories.create!(:categorized_type => 'Comfy::Cms::File', :label => 'category_b')
14
+
10
15
  assert_difference 'Comfy::Cms::File.count' do
11
16
  ComfortableMexicanSofa::Fixture::File::Importer.new('sample-site', 'default-site').import!
12
17
  assert file = Comfy::Cms::File.last
@@ -7,12 +7,17 @@ class FixturePagesTest < ActiveSupport::TestCase
7
7
  def test_creation
8
8
  Comfy::Cms::Page.delete_all
9
9
 
10
- layout = comfy_cms_layouts(:default)
10
+ site = comfy_cms_sites(:default)
11
+ layout = comfy_cms_layouts(:default)
11
12
  layout.update_column(:content, '<html>{{cms:page:content}}</html>')
12
13
 
13
14
  nested = comfy_cms_layouts(:nested)
14
15
  nested.update_column(:content, '<html>{{cms:page:left}}<br/>{{cms:page:right}}</html>')
15
16
 
17
+ # need to have categories present before linking
18
+ site.categories.create!(:categorized_type => 'Comfy::Cms::Page', :label => 'category_a')
19
+ site.categories.create!(:categorized_type => 'Comfy::Cms::Page', :label => 'category_b')
20
+
16
21
  assert_difference 'Comfy::Cms::Page.count', 2 do
17
22
  ComfortableMexicanSofa::Fixture::Page::Importer.new('sample-site', 'default-site').import!
18
23
 
@@ -22,6 +27,7 @@ class FixturePagesTest < ActiveSupport::TestCase
22
27
  assert_equal "<html>Home Page Fixture Contént\ndefault_snippet_content</html>", page.content_cache
23
28
  assert_equal 0, page.position
24
29
  assert page.is_published?
30
+
25
31
  assert_equal 2, page.categories.count
26
32
  assert_equal ['category_a', 'category_b'], page.categories.map{|c| c.label}
27
33
 
@@ -36,6 +42,16 @@ class FixturePagesTest < ActiveSupport::TestCase
36
42
  end
37
43
  end
38
44
 
45
+ def test_creation_with_missing_categories
46
+ Comfy::Cms::Page.delete_all
47
+
48
+ assert_difference 'Comfy::Cms::Page.count', 2 do
49
+ ComfortableMexicanSofa::Fixture::Page::Importer.new('sample-site', 'default-site').import!
50
+ assert page = Comfy::Cms::Page.where(:full_path => '/').first
51
+ assert_equal 0, page.categories.count
52
+ end
53
+ end
54
+
39
55
  def test_update
40
56
  page = comfy_cms_pages(:default)
41
57
  page.update_column(:updated_at, 10.years.ago)
@@ -7,6 +7,11 @@ class FixtureSnippetsTest < ActiveSupport::TestCase
7
7
  def test_creation
8
8
  Comfy::Cms::Snippet.delete_all
9
9
 
10
+ # need to have categories present before linking
11
+ site = comfy_cms_sites(:default)
12
+ site.categories.create!(:categorized_type => 'Comfy::Cms::Snippet', :label => 'category_a')
13
+ site.categories.create!(:categorized_type => 'Comfy::Cms::Snippet', :label => 'category_b')
14
+
10
15
  assert_difference 'Comfy::Cms::Snippet.count' do
11
16
  ComfortableMexicanSofa::Fixture::Snippet::Importer.new('sample-site', 'default-site').import!
12
17
  assert snippet = Comfy::Cms::Snippet.last
@@ -237,6 +237,12 @@ class CmsPageTest < ActiveSupport::TestCase
237
237
  assert_equal '//test.host/en/site/', comfy_cms_pages(:default).url
238
238
  assert_equal '//test.host/en/site/child-page', comfy_cms_pages(:child).url
239
239
  end
240
+
241
+ def test_url_with_public_cms_path
242
+ ComfortableMexicanSofa.config.public_cms_path = '/custom'
243
+ assert_equal '//test.host/custom/', comfy_cms_pages(:default).url
244
+ assert_equal '//test.host/custom/child-page', comfy_cms_pages(:child).url
245
+ end
240
246
 
241
247
  def test_unicode_slug_escaping
242
248
  page = comfy_cms_pages(:child)
@@ -149,4 +149,13 @@ class CmsSiteTest < ActiveSupport::TestCase
149
149
  assert_equal site_b, Comfy::Cms::Site.find_site('alias_c.host')
150
150
  end
151
151
 
152
+ def test_url
153
+ assert_equal '//test.host/', comfy_cms_sites(:default).url
154
+ end
155
+
156
+ def test_url_with_public_cms_path
157
+ ComfortableMexicanSofa.config.public_cms_path = '/custom'
158
+ assert_equal '//test.host/custom/', comfy_cms_sites(:default).url
159
+ end
160
+
152
161
  end
@@ -16,24 +16,25 @@ Paperclip::Attachment.default_options[:use_timestamp] = false
16
16
  class ActiveSupport::TestCase
17
17
  fixtures :all
18
18
  include ActionDispatch::TestProcess
19
-
19
+
20
20
  def setup
21
21
  reset_config
22
22
  reset_locale
23
23
  stub_paperclip
24
24
  end
25
-
25
+
26
26
  # resetting default configuration
27
27
  def reset_config
28
28
  ComfortableMexicanSofa.configure do |config|
29
29
  config.cms_title = 'ComfortableMexicanSofa CMS Engine'
30
- config.admin_auth = 'ComfortableMexicanSofa::HttpAuth'
31
- config.public_auth = 'ComfortableMexicanSofa::DummyAuth'
30
+ config.admin_auth = 'ComfortableMexicanSofa::AccessControl::AdminAuthentication'
31
+ config.admin_authorization = 'ComfortableMexicanSofa::AccessControl::AdminAuthorization'
32
+ config.public_auth = 'ComfortableMexicanSofa::AccessControl::PublicAuthentication'
32
33
  config.admin_route_redirect = ''
33
34
  config.enable_fixtures = false
34
35
  config.fixtures_path = File.expand_path('db/cms_fixtures', Rails.root)
35
36
  config.revisions_limit = 25
36
- config.locales = {
37
+ config.locales = {
37
38
  'en' => 'English',
38
39
  'es' => 'Español'
39
40
  }
@@ -44,16 +45,17 @@ class ActiveSupport::TestCase
44
45
  config.allowed_helpers = nil
45
46
  config.allowed_partials = nil
46
47
  config.hostname_aliases = nil
48
+ config.public_cms_path = nil
47
49
  end
48
- ComfortableMexicanSofa::HttpAuth.username = 'username'
49
- ComfortableMexicanSofa::HttpAuth.password = 'password'
50
+ ComfortableMexicanSofa::AccessControl::AdminAuthentication.username = 'username'
51
+ ComfortableMexicanSofa::AccessControl::AdminAuthentication.password = 'password'
50
52
  end
51
-
53
+
52
54
  def reset_locale
53
55
  I18n.default_locale = :en
54
56
  I18n.locale = :en
55
57
  end
56
-
58
+
57
59
  # Example usage:
58
60
  # assert_has_errors_on @record, :field_1, :field_2
59
61
  def assert_has_errors_on(record, *fields)
@@ -62,7 +64,7 @@ class ActiveSupport::TestCase
62
64
  unmatched = fields.flatten - record.errors.keys
63
65
  assert unmatched.blank?, "#{record.class} doesn't have errors on '#{unmatched.join(', ')}'"
64
66
  end
65
-
67
+
66
68
  # Example usage:
67
69
  # assert_exception_raised do ... end
68
70
  # assert_exception_raised ActiveRecord::RecordInvalid do ... end
@@ -92,13 +94,13 @@ class ActiveSupport::TestCase
92
94
  def rendered_content_formatter(string)
93
95
  string.gsub(/^[ ]+/, '')
94
96
  end
95
-
97
+
96
98
  def stub_paperclip
97
99
  Comfy::Cms::Block.any_instance.stubs(:save_attached_files).returns(true)
98
100
  Comfy::Cms::Block.any_instance.stubs(:delete_attached_files).returns(true)
99
101
  Paperclip::Attachment.any_instance.stubs(:post_process).returns(true)
100
102
  end
101
-
103
+
102
104
  end
103
105
 
104
106
  class ActionController::TestCase
@@ -108,28 +110,35 @@ class ActionController::TestCase
108
110
  end
109
111
 
110
112
  class ActionDispatch::IntegrationTest
111
-
113
+
112
114
  def setup
113
115
  host! 'test.host'
114
116
  reset_config
115
117
  reset_locale
116
118
  stub_paperclip
117
119
  end
118
-
120
+
119
121
  # Attaching http_auth stuff with request. Example use:
120
122
  # http_auth :get, '/cms-admin/pages'
121
123
  def http_auth(method, path, options = {}, username = 'username', password = 'password')
122
124
  send(method, path, options, {'HTTP_AUTHORIZATION' => "Basic #{Base64.encode64(username + ':' + password)}"})
123
125
  end
126
+
127
+ # Overriding helper method as it doesn't really work for integration tests by default
128
+ def with_routing(&block)
129
+ yield ComfortableMexicanSofa::Application.routes
130
+ ensure
131
+ load File.expand_path('../config/cms_routes.rb', File.dirname(__FILE__))
132
+ end
124
133
  end
125
134
 
126
135
  class Rails::Generators::TestCase
127
-
136
+
128
137
  destination File.expand_path('../tmp', File.dirname(__FILE__))
129
-
138
+
130
139
  setup :prepare_destination,
131
140
  :prepare_files
132
-
141
+
133
142
  def prepare_files
134
143
  config_path = File.join(self.destination_root, 'config')
135
144
  routes_path = File.join(config_path, 'routes.rb')
@@ -139,7 +148,7 @@ class Rails::Generators::TestCase
139
148
  f.write("Test::Application.routes.draw do\n\nend")
140
149
  end
141
150
  end
142
-
151
+
143
152
  def read_file(filename)
144
153
  File.read(
145
154
  File.join(
@@ -148,5 +157,5 @@ class Rails::Generators::TestCase
148
157
  )
149
158
  )
150
159
  end
151
-
160
+
152
161
  end