comfortable_mexican_sofa 1.6.16 → 1.6.17

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.6.16
1
+ 1.6.17
@@ -14,7 +14,7 @@ class CmsContentController < ApplicationController
14
14
  def render_html(status = 200)
15
15
  if @cms_layout = @cms_page.layout
16
16
  app_layout = (@cms_layout.app_layout.blank? || request.xhr?) ? false : @cms_layout.app_layout
17
- render :inline => @cms_page.content, :layout => app_layout, :status => status
17
+ render :inline => @cms_page.content, :layout => app_layout, :status => status, :content_type => 'text/html'
18
18
  else
19
19
  render :text => I18n.t('cms.content.layout_not_found'), :status => 404
20
20
  end
@@ -37,7 +37,7 @@ class Cms::Site < ActiveRecord::Base
37
37
  def self.find_site(host, path = nil)
38
38
  return Cms::Site.first if Cms::Site.count == 1
39
39
  cms_site = nil
40
- Cms::Site.find_all_by_hostname(host).each do |site|
40
+ Cms::Site.find_all_by_hostname(real_host_from_aliases(host)).each do |site|
41
41
  if site.path.blank?
42
42
  cms_site = site
43
43
  elsif "#{path}/".match /^\/#{Regexp.escape(site.path.to_s)}\//
@@ -47,8 +47,17 @@ class Cms::Site < ActiveRecord::Base
47
47
  end
48
48
  return cms_site
49
49
  end
50
-
50
+
51
51
  protected
52
+
53
+ def self.real_host_from_aliases(host)
54
+ if aliases = ComfortableMexicanSofa.config.hostname_aliases
55
+ aliases.each do |alias_host, aliases|
56
+ return alias_host if aliases.include?(host)
57
+ end
58
+ end
59
+ host
60
+ end
52
61
 
53
62
  def assign_identifier
54
63
  self.identifier = self.identifier.blank?? self.hostname.try(:idify) : self.identifier
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "comfortable_mexican_sofa"
8
- s.version = "1.6.16"
8
+ s.version = "1.6.17"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Oleg Khabarov", "The Working Group Inc"]
12
- s.date = "2012-03-15"
12
+ s.date = "2012-03-24"
13
13
  s.description = ""
14
14
  s.email = "oleg@theworkinggroup.ca"
15
15
  s.extra_rdoc_files = [
@@ -26,6 +26,10 @@ ComfortableMexicanSofa.configure do |config|
26
26
  # If you want to include the routes manually set this to false
27
27
  # config.use_default_routes = true
28
28
 
29
+ # /sitemap.xml that is used by search engines for indexing. It's enabled by
30
+ # default, but you may turn it off.
31
+ # config.enable_sitemap = true
32
+
29
33
  # File uploads use Paperclip and can support filesystem or s3 uploads. Override
30
34
  # the upload method and appropriate settings based on Paperclip. For S3 see:
31
35
  # http://rdoc.info/gems/paperclip/2.3.8/Paperclip/Storage/S3, and for
@@ -87,6 +91,12 @@ ComfortableMexicanSofa.configure do |config|
87
91
  # are accessible by default. Empty array will prevent rendering of all partials.
88
92
  # config.allowed_partials = nil
89
93
 
94
+ # Site aliases, if you want to have aliases for your site. Good for harmonizing
95
+ # production env with dev/testing envs.
96
+ # e.g. config.site_aliases = {'host.com' => 'host.inv', 'host_a.com' => ['host.lvh.me', 'host.dev']}
97
+ # Default is nil (not used)
98
+ # config.hostname_aliases = nil
99
+
90
100
  end
91
101
 
92
102
  # Default credentials for ComfortableMexicanSofa::HttpAuth
data/config/routes.rb CHANGED
@@ -34,10 +34,14 @@ Rails.application.routes.draw do
34
34
  scope :controller => :cms_content do
35
35
  get 'cms-css/:site_id/:identifier' => :render_css, :as => 'cms_css'
36
36
  get 'cms-js/:site_id/:identifier' => :render_js, :as => 'cms_js'
37
- get '(:cms_path)/sitemap' => :render_sitemap,
38
- :as => 'cms_sitemap',
39
- :constraints => {:format => /xml/},
40
- :format => :xml
37
+
38
+ if ComfortableMexicanSofa.config.enable_sitemap
39
+ get '(:cms_path)/sitemap' => :render_sitemap,
40
+ :as => 'cms_sitemap',
41
+ :constraints => {:format => /xml/},
42
+ :format => :xml
43
+ end
44
+
41
45
  get '/' => :render_html, :as => 'cms_html', :path => "(*cms_path)"
42
46
  end
43
47
 
@@ -23,6 +23,10 @@ class ComfortableMexicanSofa::Configuration
23
23
  # If you want to include the routes manually set this to false
24
24
  attr_accessor :use_default_routes
25
25
 
26
+ # /sitemap.xml that is used by search engines for indexing. It's enabled by
27
+ # default, but you may turn it off.
28
+ attr_accessor :enable_sitemap
29
+
26
30
  # Upload settings
27
31
  attr_accessor :upload_file_options
28
32
 
@@ -64,6 +68,12 @@ class ComfortableMexicanSofa::Configuration
64
68
  # Whitelist of partials paths that can be used via {{cms:partial}} tag. All partials
65
69
  # are accessible by default. Empty array will prevent rendering of all partials.
66
70
  attr_accessor :allowed_partials
71
+
72
+ # Site aliases, if you want to have aliases for your site. Good for harmonizing
73
+ # production env with dev/testing envs.
74
+ # e.g. config.site_aliases = {'host.com' => 'host.inv', 'host_a.com' => ['host.lvh.me', 'host.dev']}
75
+ # Default is nil (not used)
76
+ attr_accessor :hostname_aliases
67
77
 
68
78
  # Configuration defaults
69
79
  def initialize
@@ -74,6 +84,7 @@ class ComfortableMexicanSofa::Configuration
74
84
  @admin_route_prefix = 'cms-admin'
75
85
  @admin_route_redirect = ''
76
86
  @use_default_routes = true
87
+ @enable_sitemap = true
77
88
  @upload_file_options = { :url => '/system/:class/:id/:attachment/:style/:filename' }
78
89
  @enable_fixtures = false
79
90
  @fixtures_path = File.expand_path('db/cms_fixtures', Rails.root)
@@ -91,6 +102,7 @@ class ComfortableMexicanSofa::Configuration
91
102
  @allow_irb = false
92
103
  @allowed_helpers = nil
93
104
  @allowed_partials = nil
105
+ @hostname_aliases = nil
94
106
  end
95
107
 
96
108
  end
@@ -2,7 +2,7 @@ class ComfortableMexicanSofa::FormBuilder < ActionView::Helpers::FormBuilder
2
2
 
3
3
  helpers = field_helpers -
4
4
  %w(hidden_field fields_for) +
5
- %w(select)
5
+ %w(select collection_select)
6
6
 
7
7
  helpers.each do |name|
8
8
  class_eval %Q^
@@ -19,10 +19,11 @@ class CmsContentControllerTest < ActionController::TestCase
19
19
  default_snippet_content
20
20
  layout_content_c'
21
21
  ), response.body
22
+ assert_equal 'text/html', response.content_type
22
23
  end
23
24
 
24
25
  def test_render_page_with_app_layout
25
- cms_layouts(:default).update_attribute(:app_layout, 'cms_admin.html.erb')
26
+ cms_layouts(:default).update_attribute(:app_layout, 'cms_admin')
26
27
  get :render_html, :cms_path => ''
27
28
  assert_response :success
28
29
  assert assigns(:cms_page)
@@ -30,7 +31,7 @@ class CmsContentControllerTest < ActionController::TestCase
30
31
  end
31
32
 
32
33
  def test_render_page_with_xhr
33
- cms_layouts(:default).update_attribute(:app_layout, 'cms_admin.html.erb')
34
+ cms_layouts(:default).update_attribute(:app_layout, 'cms_admin')
34
35
  xhr :get, :render_html, :cms_path => ''
35
36
  assert_response :success
36
37
  assert assigns(:cms_page)
@@ -137,7 +138,7 @@ class CmsContentControllerTest < ActionController::TestCase
137
138
  def test_render_css
138
139
  get :render_css, :site_id => cms_sites(:default).id, :identifier => cms_layouts(:default).identifier
139
140
  assert_response :success
140
- assert_match %r{text\/css}, response.headers["Content-Type"]
141
+ assert_match 'text/css', response.content_type
141
142
  assert_equal cms_layouts(:default).css, response.body
142
143
  end
143
144
 
@@ -149,7 +150,7 @@ class CmsContentControllerTest < ActionController::TestCase
149
150
  def test_render_js
150
151
  get :render_js, :site_id => cms_sites(:default).id, :identifier => cms_layouts(:default).identifier
151
152
  assert_response :success
152
- assert_match %r{text\/javascript}, response.headers["Content-Type"]
153
+ assert_equal 'text/javascript', response.content_type
153
154
  assert_equal cms_layouts(:default).js, response.body
154
155
  end
155
156
 
@@ -46,4 +46,16 @@ class RoutingExtensionsTest < ActionDispatch::IntegrationTest
46
46
  end
47
47
  end
48
48
 
49
+ def test_get_sitemap
50
+ get '/sitemap', :format => 'xml'
51
+ assert_response :success
52
+
53
+ ComfortableMexicanSofa.config.enable_sitemap = false
54
+ Rails.application.reload_routes!
55
+
56
+ assert_exception_raised ActionController::RoutingError, 'Page Not Found' do
57
+ get '/sitemap', :format => 'xml'
58
+ end
59
+ end
60
+
49
61
  end
data/test/test_helper.rb CHANGED
@@ -24,6 +24,7 @@ class ActiveSupport::TestCase
24
24
  config.admin_route_prefix = 'cms-admin'
25
25
  config.admin_route_redirect = ''
26
26
  config.use_default_routes = true
27
+ config.enable_sitemap = true
27
28
  config.enable_fixtures = false
28
29
  config.fixtures_path = File.expand_path('db/cms_fixtures', Rails.root)
29
30
  config.revisions_limit = 25
@@ -39,6 +40,7 @@ class ActiveSupport::TestCase
39
40
  config.allow_irb = false
40
41
  config.allowed_helpers = nil
41
42
  config.allowed_partials = nil
43
+ config.hostname_aliases = nil
42
44
  end
43
45
  ComfortableMexicanSofa::HttpAuth.username = 'username'
44
46
  ComfortableMexicanSofa::HttpAuth.password = 'password'
@@ -11,8 +11,8 @@ class ConfigurationTest < ActiveSupport::TestCase
11
11
  assert_equal 'ComfortableMexicanSofa::DummyAuth', config.public_auth
12
12
  assert_equal 'cms-admin', config.admin_route_prefix
13
13
  assert_equal true, config.use_default_routes
14
+ assert_equal true, config.enable_sitemap
14
15
  assert_equal '', config.admin_route_redirect
15
-
16
16
  assert_equal false, config.enable_fixtures
17
17
  assert_equal File.expand_path('db/cms_fixtures', Rails.root), config.fixtures_path
18
18
  assert_equal 25, config.revisions_limit
@@ -31,6 +31,7 @@ class ConfigurationTest < ActiveSupport::TestCase
31
31
  assert_equal false, config.allow_irb
32
32
  assert_equal nil, config.allowed_helpers
33
33
  assert_equal nil, config.allowed_partials
34
+ assert_equal nil, config.hostname_aliases
34
35
  end
35
36
 
36
37
  def test_initialization_overrides
@@ -121,4 +121,18 @@ class CmsSiteTest < ActiveSupport::TestCase
121
121
  assert_equal site_c, Cms::Site.find_site('test2.host', '/fr/some/path')
122
122
  end
123
123
 
124
+ def test_find_site_with_site_alias
125
+ site_a = cms_sites(:default)
126
+ site_b = Cms::Site.create!(:identifier => 'site_b', :hostname => 'test2.host')
127
+
128
+ ComfortableMexicanSofa.config.hostname_aliases = {
129
+ 'test.host' => 'alias_a.host',
130
+ 'test2.host' => %w(alias_b.host alias_c.host)
131
+ }
132
+
133
+ assert_equal site_a, Cms::Site.find_site('alias_a.host')
134
+ assert_equal site_b, Cms::Site.find_site('alias_b.host')
135
+ assert_equal site_b, Cms::Site.find_site('alias_c.host')
136
+ end
137
+
124
138
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: comfortable_mexican_sofa
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.16
4
+ version: 1.6.17
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-03-15 00:00:00.000000000Z
13
+ date: 2012-03-24 00:00:00.000000000Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
17
- requirement: &70113298842700 !ruby/object:Gem::Requirement
17
+ requirement: &70157649574360 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 3.0.0
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70113298842700
25
+ version_requirements: *70157649574360
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: active_link_to
28
- requirement: &70113298842040 !ruby/object:Gem::Requirement
28
+ requirement: &70157649573440 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: 1.0.0
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *70113298842040
36
+ version_requirements: *70157649573440
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: paperclip
39
- requirement: &70113298841120 !ruby/object:Gem::Requirement
39
+ requirement: &70157649572060 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,7 +44,7 @@ dependencies:
44
44
  version: 2.3.0
45
45
  type: :runtime
46
46
  prerelease: false
47
- version_requirements: *70113298841120
47
+ version_requirements: *70157649572060
48
48
  description: ''
49
49
  email: oleg@theworkinggroup.ca
50
50
  executables: []
@@ -369,7 +369,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
369
369
  version: '0'
370
370
  segments:
371
371
  - 0
372
- hash: 1361783085271841730
372
+ hash: -1640044306951500333
373
373
  required_rubygems_version: !ruby/object:Gem::Requirement
374
374
  none: false
375
375
  requirements: