comfortable_mexican_sofa 1.11.0 → 1.11.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -0
  3. data/README.md +3 -3
  4. data/app/assets/stylesheets/comfortable_mexican_sofa/base.css.sass +6 -6
  5. data/app/controllers/admin/cms/categories_controller.rb +0 -2
  6. data/app/controllers/admin/cms/files_controller.rb +0 -2
  7. data/app/controllers/admin/cms/layouts_controller.rb +1 -3
  8. data/app/controllers/admin/cms/pages_controller.rb +0 -2
  9. data/app/controllers/admin/cms/sites_controller.rb +0 -2
  10. data/app/controllers/admin/cms/snippets_controller.rb +0 -2
  11. data/app/controllers/cms/assets_controller.rb +19 -0
  12. data/app/controllers/cms/content_controller.rb +33 -36
  13. data/app/models/cms/site.rb +2 -2
  14. data/app/views/admin/cms/categories/_index.html.haml +1 -1
  15. data/app/views/admin/cms/files/index.html.haml +0 -1
  16. data/app/views/admin/cms/pages/_form_blocks.html.haml +1 -1
  17. data/config/application.rb +2 -0
  18. data/config/initializers/comfortable_mexican_sofa.rb +11 -3
  19. data/config/locales/de.yml +1 -0
  20. data/config/locales/en.yml +1 -0
  21. data/config/locales/es.yml +1 -0
  22. data/config/locales/fr.yml +1 -0
  23. data/config/locales/ja.yml +1 -0
  24. data/config/locales/nl.yml +238 -0
  25. data/config/locales/pl.yml +1 -0
  26. data/config/locales/pt-BR.yml +1 -0
  27. data/config/locales/ru.yml +1 -0
  28. data/config/locales/sv.yml +1 -0
  29. data/config/locales/zh-CN.yml +1 -0
  30. data/lib/comfortable_mexican_sofa/authentication/http_auth.rb +10 -3
  31. data/lib/comfortable_mexican_sofa/configuration.rb +5 -4
  32. data/lib/comfortable_mexican_sofa/extensions/is_categorized.rb +1 -1
  33. data/lib/comfortable_mexican_sofa/extensions/is_mirrored.rb +5 -4
  34. data/lib/comfortable_mexican_sofa/extensions/rails.rb +0 -7
  35. data/lib/comfortable_mexican_sofa/fixture.rb +1 -1
  36. data/lib/comfortable_mexican_sofa/fixture/file.rb +1 -1
  37. data/lib/comfortable_mexican_sofa/routes/cms.rb +4 -4
  38. data/lib/comfortable_mexican_sofa/version.rb +1 -1
  39. data/test/controllers/admin/cms/layouts_controller_test.rb +1 -1
  40. data/test/controllers/admin/cms/pages_controller_test.rb +9 -2
  41. data/test/controllers/cms/assets_controller_test.rb +29 -0
  42. data/test/controllers/cms/content_controller_test.rb +72 -66
  43. data/test/gemfiles/Gemfile.rails.4.0 +1 -1
  44. data/test/gemfiles/Gemfile.rails.4.1 +20 -0
  45. data/test/lib/mirrors_test.rb +15 -3
  46. metadata +6 -2
@@ -223,6 +223,7 @@ pl:
223
223
  done: Zrobione
224
224
  all: Wszystko
225
225
  add: Dodaj
226
+ add_placeholder: Dodać Kategorię
226
227
  show:
227
228
  are_you_sure: Jesteś pewien?
228
229
  edit:
@@ -223,6 +223,7 @@ pt-BR:
223
223
  done: Pronto
224
224
  all: Todas
225
225
  add: Adicionar
226
+ add_placeholder: Adicione uma Categoria
226
227
  show:
227
228
  are_you_sure: Tem certeza?
228
229
  edit:
@@ -223,6 +223,7 @@ ru:
223
223
  done: Применить
224
224
  all: Все
225
225
  add: Добавить
226
+ add_placeholder: добавить категорию
226
227
  show:
227
228
  are_you_sure: Вы уверены?
228
229
  edit:
@@ -223,6 +223,7 @@ sv:
223
223
  done: Klar
224
224
  all: Alla
225
225
  add: Lägg till
226
+ add_placeholder: Lägga Kategori
226
227
  show:
227
228
  are_you_sure: Är du säker?
228
229
  edit:
@@ -223,6 +223,7 @@ zh-CN:
223
223
  done: 完成
224
224
  all: 全部
225
225
  add: 创建
226
+ add_placeholder: 添加类别
226
227
  show:
227
228
  are_you_sure: 确定删除该分类吗?
228
229
  edit:
@@ -3,16 +3,23 @@ module ComfortableMexicanSofa::HttpAuth
3
3
  # Like this:
4
4
  # ComfortableMexicanSofa::HttpAuth.username = 'myname'
5
5
  # ComfortableMexicanSofa::HttpAuth.password = 'mypassword'
6
+ #
7
+ # You can even use bcrypt (gem 'bcrypt-ruby'):
8
+ # require 'bcrypt'
9
+ # ComfortableMexicanSofa::HttpAuth.username = 'myname'
10
+ # ComfortableMexicanSofa::HttpAuth.password = BCrypt::Password.new '... bcrypt hash ...'
11
+ # Create the bcrypt hash with:
12
+ # BCrypt::Password.create('password').to_s
6
13
  mattr_accessor :username,
7
14
  :password
8
-
15
+
9
16
  # Simple http_auth. When implementing some other form of authentication
10
17
  # this method should return +true+ if everything is great, or redirect user
11
18
  # to some other page, thus denying access to cms admin section.
12
19
  def authenticate
13
20
  authenticate_or_request_with_http_basic do |username, password|
14
- username == self.username && password == self.password
21
+ self.username == username && self.password == password
15
22
  end
16
23
  end
17
-
24
+
18
25
  end
@@ -4,7 +4,7 @@ class ComfortableMexicanSofa::Configuration
4
4
 
5
5
  # Don't like ComfortableMexicanSofa? Set it to whatever you like. :(
6
6
  attr_accessor :cms_title
7
-
7
+
8
8
  # Controller that is inherited from CmsAdmin::BaseController
9
9
  # 'ApplicationController' is the default
10
10
  attr_accessor :base_controller
@@ -70,11 +70,11 @@ class ComfortableMexicanSofa::Configuration
70
70
  # e.g. config.site_aliases = {'host.com' => 'host.inv', 'host_a.com' => ['host.lvh.me', 'host.dev']}
71
71
  # Default is nil (not used)
72
72
  attr_accessor :hostname_aliases
73
-
73
+
74
74
  # Reveal partials that can be overwritten in the admin area.
75
75
  # Default is false.
76
76
  attr_accessor :reveal_cms_partials
77
-
77
+
78
78
  # Configuration defaults
79
79
  def initialize
80
80
  @cms_title = 'ComfortableMexicanSofa CMS Engine'
@@ -98,7 +98,8 @@ class ComfortableMexicanSofa::Configuration
98
98
  'sv' => 'Svenska',
99
99
  'ru' => 'Русский',
100
100
  'pl' => 'Polski',
101
- 'de' => 'Deutsch'
101
+ 'de' => 'Deutsch',
102
+ 'nl' => 'Nederlands'
102
103
  }
103
104
  @admin_locale = nil
104
105
  @database_config = nil
@@ -22,7 +22,7 @@ module ComfortableMexicanSofa::IsCategorized
22
22
 
23
23
  scope :for_category, lambda { |*categories|
24
24
  if (categories = [categories].flatten.compact).present?
25
- select("DISTINCT #{table_name}.*").
25
+ self.distinct.
26
26
  joins(:categorizations => :category).
27
27
  where('cms_categories.label' => categories)
28
28
  end
@@ -48,7 +48,7 @@ module ComfortableMexicanSofa::IsMirrored
48
48
  m = site.pages.find_by_full_path(self.full_path_was || self.full_path) || site.pages.new
49
49
  m.attributes = {
50
50
  :slug => self.slug,
51
- :label => self.slug.blank?? self.label : m.label,
51
+ :label => m.label.blank?? self.label : m.label,
52
52
  :parent_id => site.pages.find_by_full_path(self.parent.try(:full_path)).try(:id),
53
53
  :layout => site.layouts.find_by_identifier(self.layout.try(:identifier))
54
54
  }
@@ -64,8 +64,9 @@ module ComfortableMexicanSofa::IsMirrored
64
64
  mirror.is_mirrored = true
65
65
  begin
66
66
  mirror.save!
67
- rescue ActiveRecord::RecordInvalid
68
- logger.detailed_error($!)
67
+ rescue ActiveRecord::RecordInvalid => e
68
+ logger.error(e.message)
69
+ logger.error(e.backtrace.each{|line| error line })
69
70
  end
70
71
  end
71
72
  end
@@ -82,4 +83,4 @@ module ComfortableMexicanSofa::IsMirrored
82
83
 
83
84
  end
84
85
 
85
- ActiveRecord::Base.send :include, ComfortableMexicanSofa::IsMirrored
86
+ ActiveRecord::Base.send :include, ComfortableMexicanSofa::IsMirrored
@@ -14,11 +14,4 @@ module Enumerable
14
14
  end
15
15
  result
16
16
  end
17
- end
18
-
19
- class ActiveSupport::Logger
20
- def detailed_error(e)
21
- error(e.message)
22
- e.backtrace.each{|line| error line }
23
- end
24
17
  end
@@ -24,7 +24,7 @@ module ComfortableMexicanSofa::Fixture
24
24
  end
25
25
 
26
26
  def get_attributes(file_path)
27
- YAML.load_file(file_path)
27
+ YAML.load_file(file_path) || { }
28
28
  end
29
29
 
30
30
  def save_categorizations!(object, categories)
@@ -60,7 +60,7 @@ module ComfortableMexicanSofa::Fixture::File
60
60
  file.file.url
61
61
 
62
62
  open(::File.join(self.path, ::File.basename(file_path)), 'w') do |f|
63
- f.write(open(data_path))
63
+ open(data_path) { |src| f.write(src.read) }
64
64
  end
65
65
 
66
66
  ComfortableMexicanSofa.logger.warn("[FIXTURES] Exported File \t #{file.file_file_name}")
@@ -1,9 +1,9 @@
1
1
  class ActionDispatch::Routing::Mapper
2
-
2
+
3
3
  def comfy_route_cms(options = {})
4
4
  namespace :cms, :path => options[:path] do
5
- get 'cms-css/:site_id/:identifier' => 'content#render_css', :as => 'render_css'
6
- get 'cms-js/:site_id/:identifier' => 'content#render_js', :as => 'render_js'
5
+ get 'cms-css/:site_id/:identifier' => 'assets#render_css', :as => 'render_css'
6
+ get 'cms-js/:site_id/:identifier' => 'assets#render_js', :as => 'render_js'
7
7
 
8
8
  if options[:sitemap]
9
9
  get '(:cms_path)/sitemap' => 'content#render_sitemap',
@@ -12,7 +12,7 @@ class ActionDispatch::Routing::Mapper
12
12
  :format => :xml
13
13
  end
14
14
 
15
- get '/' => 'content#render_html', :as => 'render_html', :path => "(*cms_path)"
15
+ get '/:format' => 'content#show', :as => 'render_page', :path => "(*cms_path)"
16
16
  end
17
17
  end
18
18
  end
@@ -1,3 +1,3 @@
1
1
  module ComfortableMexicanSofa
2
- VERSION = "1.11.0"
2
+ VERSION = "1.11.1"
3
3
  end
@@ -21,7 +21,7 @@ class Admin::Cms::LayoutsControllerTest < ActionController::TestCase
21
21
  get :new, :site_id => site
22
22
  assert_response :success
23
23
  assert assigns(:layout)
24
- assert_equal '{{ cms:page:content:text }}', assigns(:layout).content
24
+ assert_equal '{{ cms:page:content:rich_text }}', assigns(:layout).content
25
25
  assert_template :new
26
26
  assert_select "form[action=/admin/sites/#{site.id}/layouts]"
27
27
  assert_select "form[action='/admin/sites/#{site.id}/files?ajax=true']"
@@ -243,6 +243,13 @@ class Admin::Cms::PagesControllerTest < ActionController::TestCase
243
243
  assert_response :success
244
244
  end
245
245
 
246
+ def test_get_edit_with_layout_and_no_tags
247
+ page = cms_pages(:default)
248
+ page.layout.update_column(:content, '')
249
+ get :edit, :site_id => page.site, :id => page
250
+ assert_response :success
251
+ end
252
+
246
253
  def test_creation
247
254
  assert_difference 'Cms::Page.count' do
248
255
  assert_difference 'Cms::Block.count', 2 do
@@ -433,11 +440,11 @@ class Admin::Cms::PagesControllerTest < ActionController::TestCase
433
440
 
434
441
  def test_get_toggle_branch
435
442
  page = cms_pages(:default)
436
- get :toggle_branch, :site_id => page.site, :id => page, :format => :js
443
+ xhr :get, :toggle_branch, :site_id => page.site, :id => page, :format => :js
437
444
  assert_response :success
438
445
  assert_equal [page.id.to_s], session[:cms_page_tree]
439
446
 
440
- get :toggle_branch, :site_id => page.site, :id => page, :format => :js
447
+ xhr :get, :toggle_branch, :site_id => page.site, :id => page, :format => :js
441
448
  assert_response :success
442
449
  assert_equal [], session[:cms_page_tree]
443
450
  end
@@ -0,0 +1,29 @@
1
+ require_relative '../../test_helper'
2
+
3
+ class Cms::AssetsControllerTest < ActionController::TestCase
4
+
5
+ def test_render_css
6
+ get :render_css, :site_id => cms_sites(:default).id, :identifier => cms_layouts(:default).identifier
7
+ assert_response :success
8
+ assert_match 'text/css', response.content_type
9
+ assert_equal cms_layouts(:default).css, response.body
10
+ end
11
+
12
+ def test_render_css_not_found
13
+ get :render_css, :site_id => cms_sites(:default).id, :identifier => 'bogus'
14
+ assert_response 404
15
+ end
16
+
17
+ def test_render_js
18
+ xhr :get, :render_js, :site_id => cms_sites(:default).id, :identifier => cms_layouts(:default).identifier
19
+ assert_response :success
20
+ assert_equal 'text/javascript', response.content_type
21
+ assert_equal cms_layouts(:default).js, response.body
22
+ end
23
+
24
+ def test_render_js_not_found
25
+ xhr :get, :render_js, :site_id => cms_sites(:default).id, :identifier => 'bogus'
26
+ assert_response 404
27
+ end
28
+
29
+ end
@@ -2,12 +2,12 @@ require_relative '../../test_helper'
2
2
 
3
3
  class Cms::ContentControllerTest < ActionController::TestCase
4
4
 
5
- def test_render_page
6
- get :render_html, :cms_path => ''
5
+ def test_show
6
+ get :show, :cms_path => ''
7
7
  assert_equal cms_sites(:default), assigns(:cms_site)
8
8
  assert_equal cms_layouts(:default), assigns(:cms_layout)
9
9
  assert_equal cms_pages(:default), assigns(:cms_page)
10
-
10
+
11
11
  assert_response :success
12
12
  assert_equal rendered_content_formatter(
13
13
  '
@@ -22,29 +22,59 @@ class Cms::ContentControllerTest < ActionController::TestCase
22
22
  assert_equal 'text/html', response.content_type
23
23
  end
24
24
 
25
- def test_render_page_with_app_layout
25
+ def test_show_as_json
26
+ get :show, :cms_path => '', :format => 'json'
27
+ assert_response :success
28
+
29
+ content = rendered_content_formatter(
30
+ '
31
+ layout_content_a
32
+ default_page_text_content_a
33
+ default_snippet_content
34
+ default_page_text_content_b
35
+ layout_content_b
36
+ default_snippet_content
37
+ layout_content_c'
38
+ )
39
+ page = cms_pages(:default)
40
+ json_response = JSON.parse(response.body)
41
+ assert_equal page.id, json_response['id']
42
+ assert_equal page.site.id, json_response['site_id']
43
+ assert_equal page.layout.id, json_response['layout_id']
44
+ assert_equal nil, json_response['parent_id']
45
+ assert_equal nil, json_response['target_page_id']
46
+ assert_equal 'Default Page', json_response['label']
47
+ assert_equal nil, json_response['slug']
48
+ assert_equal '/', json_response['full_path']
49
+ assert_equal content, json_response['content']
50
+ assert_equal 0, json_response['position']
51
+ assert_equal 1, json_response['children_count']
52
+ assert_equal true, json_response['is_published']
53
+ end
54
+
55
+ def test_show_with_app_layout
26
56
  cms_layouts(:default).update_columns(:app_layout => 'admin/cms')
27
- get :render_html, :cms_path => ''
57
+ get :show, :cms_path => ''
28
58
  assert_response :success
29
59
  assert assigns(:cms_page)
30
- assert_select "body[class='c-cms-content a-render-html']"
60
+ assert_select "body[class='c-cms-content a-show']"
31
61
  end
32
-
33
- def test_render_page_with_xhr
62
+
63
+ def test_show_with_xhr
34
64
  cms_layouts(:default).update_columns(:app_layout => 'cms_admin')
35
- xhr :get, :render_html, :cms_path => ''
65
+ xhr :get, :show, :cms_path => ''
36
66
  assert_response :success
37
67
  assert assigns(:cms_page)
38
- assert_no_select "body[class='c_cms_content a_render_html']"
68
+ assert_no_select "body[class='c_cms_content a_show']"
39
69
  end
40
-
41
- def test_render_page_not_found
70
+
71
+ def test_show_not_found
42
72
  assert_exception_raised ActionController::RoutingError, 'Page Not Found at: "doesnotexist"' do
43
- get :render_html, :cms_path => 'doesnotexist'
73
+ get :show, :cms_path => 'doesnotexist'
44
74
  end
45
75
  end
46
-
47
- def test_render_page_not_found_with_custom_404
76
+
77
+ def test_show_not_found_with_custom_404
48
78
  page = cms_sites(:default).pages.create!(
49
79
  :label => '404',
50
80
  :slug => '404',
@@ -58,48 +88,48 @@ class Cms::ContentControllerTest < ActionController::TestCase
58
88
  )
59
89
  assert_equal '/404', page.full_path
60
90
  assert page.is_published?
61
- get :render_html, :cms_path => 'doesnotexist'
91
+ get :show, :cms_path => 'doesnotexist'
62
92
  assert_response 404
63
93
  assert assigns(:cms_page)
64
94
  assert_match /custom 404 page content/, response.body
65
95
  end
66
-
67
- def test_render_page_with_no_site
96
+
97
+ def test_show_with_no_site
68
98
  Cms::Site.destroy_all
69
-
99
+
70
100
  assert_exception_raised ActionController::RoutingError, 'Site Not Found' do
71
- get :render_html, :cms_path => ''
101
+ get :show, :cms_path => ''
72
102
  end
73
103
  end
74
-
75
- def test_render_page_with_no_layout
104
+
105
+ def test_show_with_no_layout
76
106
  Cms::Layout.destroy_all
77
-
78
- get :render_html, :cms_path => ''
107
+
108
+ get :show, :cms_path => ''
79
109
  assert_response 404
80
110
  assert_equal 'Layout Not Found', response.body
81
111
  end
82
-
83
- def test_render_page_with_redirect
112
+
113
+ def test_show_with_redirect
84
114
  cms_pages(:child).update_columns(:target_page_id => cms_pages(:default).id)
85
115
  assert_equal cms_pages(:default), cms_pages(:child).target_page
86
- get :render_html, :cms_path => 'child-page'
116
+ get :show, :cms_path => 'child-page'
87
117
  assert_response :redirect
88
118
  assert_redirected_to cms_pages(:default).url
89
119
  end
90
-
91
- def test_render_page_unpublished
120
+
121
+ def test_show_unpublished
92
122
  page = cms_pages(:default)
93
123
  page.update_columns(:is_published => false)
94
-
124
+
95
125
  assert_exception_raised ActionController::RoutingError, 'Page Not Found at: ""' do
96
- get :render_html, :cms_path => ''
126
+ get :show, :cms_path => ''
97
127
  end
98
128
  end
99
-
100
- def test_render_page_with_irb_disabled
129
+
130
+ def test_show_with_irb_disabled
101
131
  assert_equal false, ComfortableMexicanSofa.config.allow_irb
102
-
132
+
103
133
  irb_page = cms_sites(:default).pages.create!(
104
134
  :label => 'irb',
105
135
  :slug => 'irb',
@@ -111,14 +141,14 @@ class Cms::ContentControllerTest < ActionController::TestCase
111
141
  :content => 'text <%= 2 + 2 %> text' }
112
142
  ]
113
143
  )
114
- get :render_html, :cms_path => 'irb'
144
+ get :show, :cms_path => 'irb'
115
145
  assert_response :success
116
146
  assert_match "text &lt;%= 2 + 2 %&gt; text", response.body
117
147
  end
118
-
119
- def test_render_page_with_irb_enabled
148
+
149
+ def test_show_with_irb_enabled
120
150
  ComfortableMexicanSofa.config.allow_irb = true
121
-
151
+
122
152
  irb_page = cms_sites(:default).pages.create!(
123
153
  :label => 'irb',
124
154
  :slug => 'irb',
@@ -130,34 +160,10 @@ class Cms::ContentControllerTest < ActionController::TestCase
130
160
  :content => 'text <%= 2 + 2 %> text' }
131
161
  ]
132
162
  )
133
- get :render_html, :cms_path => 'irb'
163
+ get :show, :cms_path => 'irb'
134
164
  assert_response :success
135
165
  assert_match "text 4 text", response.body
136
166
  end
137
-
138
- def test_render_css
139
- get :render_css, :site_id => cms_sites(:default).id, :identifier => cms_layouts(:default).identifier
140
- assert_response :success
141
- assert_match 'text/css', response.content_type
142
- assert_equal cms_layouts(:default).css, response.body
143
- end
144
-
145
- def test_render_css_not_found
146
- get :render_css, :site_id => cms_sites(:default).id, :identifier => 'bogus'
147
- assert_response 404
148
- end
149
-
150
- def test_render_js
151
- get :render_js, :site_id => cms_sites(:default).id, :identifier => cms_layouts(:default).identifier
152
- assert_response :success
153
- assert_equal 'text/javascript', response.content_type
154
- assert_equal cms_layouts(:default).js, response.body
155
- end
156
-
157
- def test_render_js_not_found
158
- get :render_js, :site_id => cms_sites(:default).id, :identifier => 'bogus'
159
- assert_response 404
160
- end
161
167
 
162
168
  def test_render_sitemap
163
169
  get :render_sitemap, :format => :xml
@@ -168,17 +174,17 @@ class Cms::ContentControllerTest < ActionController::TestCase
168
174
  def test_render_sitemap_with_path
169
175
  site = cms_sites(:default)
170
176
  site.update_columns(:path => 'en')
171
-
177
+
172
178
  get :render_sitemap, :cms_path => site.path, :format => :xml
173
179
  assert_response :success
174
180
  assert_equal cms_sites(:default), assigns(:cms_site)
175
181
  assert_match '<loc>//test.host/en/child-page</loc>', response.body
176
182
  end
177
-
183
+
178
184
  def test_render_sitemap_with_path_invalid_with_single_site
179
185
  site = cms_sites(:default)
180
186
  site.update_columns(:path => 'en')
181
-
187
+
182
188
  assert_exception_raised ActionController::RoutingError, 'Site Not Found' do
183
189
  get :render_sitemap, :cms_path => 'fr', :format => :xml
184
190
  end