comfortable_mexican_sofa 1.0.13 → 1.0.14

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.13
1
+ 1.0.14
@@ -10,13 +10,13 @@ class CmsContentController < ApplicationController
10
10
  end
11
11
 
12
12
  def render_css
13
- render :text => @cms_layout.merged_css, :content_type => 'text/css'
13
+ render :text => @cms_layout.css, :content_type => 'text/css'
14
14
  end
15
15
 
16
16
  def render_js
17
- render :text => @cms_layout.merged_js, :content_type => 'text/javascript'
17
+ render :text => @cms_layout.js, :content_type => 'text/javascript'
18
18
  end
19
-
19
+
20
20
  protected
21
21
 
22
22
  def load_cms_site
@@ -26,15 +26,11 @@ protected
26
26
  end
27
27
 
28
28
  def load_cms_page
29
- # Attempting to load seed page
30
- if ComfortableMexicanSofa.configuration.seed_data_path
31
- @cms_page = CmsPage.load_from_file(@cms_site, "/#{params[:cms_path]}")
32
- end
33
-
34
- @cms_page ||= @cms_site.cms_pages.find_by_full_path!("/#{params[:cms_path]}")
29
+ @cms_page = CmsPage.load_for_full_path!(@cms_site, "/#{params[:cms_path]}")
35
30
  return redirect_to(@cms_page.target_page.full_path) if @cms_page.target_page
31
+
36
32
  rescue ActiveRecord::RecordNotFound
37
- if @cms_page = @cms_site.cms_pages.find_by_full_path('/404')
33
+ if @cms_page = CmsPage.load_for_full_path(@cms_site, '/404')
38
34
  render_html(404)
39
35
  else
40
36
  render :text => 'Page Not Found', :status => 404
@@ -42,7 +38,7 @@ protected
42
38
  end
43
39
 
44
40
  def load_cms_layout
45
- @cms_layout = @cms_site.cms_layouts.find(params[:id])
41
+ @cms_layout = CmsLayout.load_for_slug!(@cms_site, params[:id])
46
42
  rescue ActiveRecord::RecordNotFound
47
43
  render :nothing => true, :status => 404
48
44
  end
@@ -44,9 +44,9 @@ class CmsLayout < ActiveRecord::Base
44
44
  end
45
45
 
46
46
  # Attempting to initialize layout object from yaml file that is found in config.seed_data_path
47
- def self.load_from_file(site, name)
47
+ def self.load_from_file(site, slug)
48
48
  return nil if ComfortableMexicanSofa.config.seed_data_path.blank?
49
- file_path = "#{ComfortableMexicanSofa.config.seed_data_path}/#{site.hostname}/layouts/#{name}.yml"
49
+ file_path = "#{ComfortableMexicanSofa.config.seed_data_path}/#{site.hostname}/layouts/#{slug}.yml"
50
50
  return nil unless File.exists?(file_path)
51
51
  attributes = YAML.load_file(file_path).symbolize_keys!
52
52
  attributes[:parent] = CmsLayout.load_from_file(site, attributes[:parent])
@@ -54,6 +54,23 @@ class CmsLayout < ActiveRecord::Base
54
54
  new(attributes)
55
55
  end
56
56
 
57
+ # Wrapper around load_from_file and find_by_slug
58
+ # returns layout object if loaded / found
59
+ def self.load_for_slug!(site, slug)
60
+ if ComfortableMexicanSofa.configuration.seed_data_path
61
+ load_from_file(site, slug)
62
+ else
63
+ site.cms_layouts.find_by_slug(slug)
64
+ end || raise(ActiveRecord::RecordNotFound, "CmsLayout with slug: #{slug} cannot be found")
65
+ end
66
+
67
+ # Non-blowing-up version of the method above
68
+ def self.load_for_slug(site, slug)
69
+ load_for_slug!(site, slug)
70
+ rescue ActiveRecord::RecordNotFound
71
+ nil
72
+ end
73
+
57
74
  # -- Instance Methods -----------------------------------------------------
58
75
  # magical merging tag is {cms:page:content} If parent layout has this tag
59
76
  # defined its content will be merged. If no such tag found, parent content
@@ -48,10 +48,10 @@ class CmsPage < ActiveRecord::Base
48
48
 
49
49
  # Attempting to initialize page object from yaml file that is found in config.seed_data_path
50
50
  # This file defines all attributes of the page plus all the block information
51
- def self.load_from_file(site, url)
51
+ def self.load_from_file(site, path)
52
52
  return nil if ComfortableMexicanSofa.config.seed_data_path.blank?
53
- url = (url == '/')? '/index' : url.to_s.chomp('/')
54
- file_path = "#{ComfortableMexicanSofa.config.seed_data_path}/#{site.hostname}/pages#{url}.yml"
53
+ path = (path == '/')? '/index' : path.to_s.chomp('/')
54
+ file_path = "#{ComfortableMexicanSofa.config.seed_data_path}/#{site.hostname}/pages#{path}.yml"
55
55
  return nil unless File.exists?(file_path)
56
56
  attributes = YAML.load_file(file_path).symbolize_keys!
57
57
  attributes[:cms_layout] = CmsLayout.load_from_file(site, attributes[:cms_layout])
@@ -60,6 +60,23 @@ class CmsPage < ActiveRecord::Base
60
60
  new(attributes)
61
61
  end
62
62
 
63
+ # Wrapper around load_from_file and find_by_full_path
64
+ # returns page object if loaded / found
65
+ def self.load_for_full_path!(site, path)
66
+ if ComfortableMexicanSofa.configuration.seed_data_path
67
+ load_from_file(site, path)
68
+ else
69
+ site.cms_pages.find_by_full_path(path)
70
+ end || raise(ActiveRecord::RecordNotFound, "CmsPage with path: #{path} cannot be found")
71
+ end
72
+
73
+ # Non-blowing-up version of the method above
74
+ def self.load_for_full_path(site, path)
75
+ load_for_full_path!(site, path)
76
+ rescue ActiveRecord::RecordNotFound
77
+ nil
78
+ end
79
+
63
80
  # -- Instance Methods -----------------------------------------------------
64
81
  # Processing content will return rendered content and will populate
65
82
  # self.cms_tags with instances of CmsTag
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{comfortable_mexican_sofa}
8
- s.version = "1.0.13"
8
+ s.version = "1.0.14"
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 = %q{2010-11-03}
12
+ s.date = %q{2010-11-05}
13
13
  s.description = %q{}
14
14
  s.email = %q{oleg@theworkinggroup.ca}
15
15
  s.extra_rdoc_files = [
@@ -1,2 +1,3 @@
1
1
  label: Default Layout
2
+ slug: default
2
3
  content: <html>{{cms:page:content}}</html>
@@ -1,3 +1,4 @@
1
1
  label: Nested Layout
2
+ slug: nested
2
3
  parent: default
3
4
  content: <div>{{cms:page:content}}</div>
@@ -58,7 +58,7 @@ class CmsContentControllerTest < ActionController::TestCase
58
58
  end
59
59
 
60
60
  def test_render_css
61
- get :render_css, :id => cms_layouts(:default)
61
+ get :render_css, :id => cms_layouts(:default).slug
62
62
  assert_response :success
63
63
  assert_match %r{text\/css}, response.headers["Content-Type"]
64
64
  assert_equal cms_layouts(:default).css, response.body
@@ -70,7 +70,7 @@ class CmsContentControllerTest < ActionController::TestCase
70
70
  end
71
71
 
72
72
  def test_render_js
73
- get :render_js, :id => cms_layouts(:default)
73
+ get :render_js, :id => cms_layouts(:default).slug
74
74
  assert_response :success
75
75
  assert_match %r{text\/javascript}, response.headers["Content-Type"]
76
76
  assert_equal cms_layouts(:default).js, response.body
@@ -13,4 +13,22 @@ class RenderCmsSeedTest < ActionDispatch::IntegrationTest
13
13
  assert_equal '<html><div>Sub Child Page Content Content for Default Snippet</div></html>', response.body
14
14
  end
15
15
 
16
+ def test_get_seed_data_page
17
+ ComfortableMexicanSofa.configuration.seed_data_path = File.expand_path('../cms_seeds', File.dirname(__FILE__))
18
+
19
+ get '/'
20
+ assert_response :success
21
+ assert assigns(:cms_page)
22
+ assert assigns(:cms_page).new_record?
23
+ end
24
+
25
+ def test_get_seed_data_css
26
+ ComfortableMexicanSofa.configuration.seed_data_path = File.expand_path('../cms_seeds', File.dirname(__FILE__))
27
+
28
+ get '/cms-css/default'
29
+ assert_response :success
30
+ assert assigns(:cms_layout)
31
+ assert assigns(:cms_layout).new_record?
32
+ end
33
+
16
34
  end
@@ -58,13 +58,4 @@ class RenderCmsTest < ActionDispatch::IntegrationTest
58
58
  end
59
59
  end
60
60
 
61
- def test_get_seed_data_page
62
- ComfortableMexicanSofa.configuration.seed_data_path = File.expand_path('../cms_seeds', File.dirname(__FILE__))
63
-
64
- get '/seed_data_page'
65
- assert_response :success
66
- assert assigns(:cms_page)
67
- assert assigns(:cms_page).new_record?
68
- end
69
-
70
61
  end
data/test/test_helper.rb CHANGED
@@ -69,6 +69,7 @@ class ActionDispatch::IntegrationTest
69
69
 
70
70
  def setup
71
71
  host! 'test.host'
72
+ ComfortableMexicanSofa.config.seed_data_path = nil
72
73
  ComfortableMexicanSofa::HttpAuth.username = 'username'
73
74
  ComfortableMexicanSofa::HttpAuth.password = 'password'
74
75
  end
@@ -85,4 +85,29 @@ class CmsLayoutTest < ActiveSupport::TestCase
85
85
  assert_equal '<html><div>{{cms:page:content}}</div></html>', layout.merged_content
86
86
  end
87
87
 
88
+ def test_load_for_slug
89
+ assert layout = CmsLayout.load_for_slug!(cms_sites(:default), 'default')
90
+ assert !layout.new_record?
91
+ db_content = layout.content
92
+
93
+ ComfortableMexicanSofa.configuration.seed_data_path = File.expand_path('../cms_seeds', File.dirname(__FILE__))
94
+ assert layout = CmsLayout.load_for_slug!(cms_sites(:default), 'default')
95
+ assert layout.new_record?
96
+ file_content = layout.content
97
+ assert_not_equal db_content, file_content
98
+ end
99
+
100
+ def test_load_for_slug_exceptions
101
+ assert_exception_raised ActiveRecord::RecordNotFound, 'CmsLayout with slug: not_found cannot be found' do
102
+ CmsLayout.load_for_slug!(cms_sites(:default), 'not_found')
103
+ end
104
+ assert !CmsLayout.load_for_slug(cms_sites(:default), 'not_found')
105
+
106
+ ComfortableMexicanSofa.configuration.seed_data_path = File.expand_path('../cms_seeds', File.dirname(__FILE__))
107
+ assert_exception_raised ActiveRecord::RecordNotFound, 'CmsLayout with slug: not_found cannot be found' do
108
+ CmsLayout.load_for_slug!(cms_sites(:default), 'not_found')
109
+ end
110
+ assert !CmsLayout.load_for_slug(cms_sites(:default), 'not_found')
111
+ end
112
+
88
113
  end
@@ -149,6 +149,31 @@ class CmsPageTest < ActiveSupport::TestCase
149
149
  assert_equal '<html><div>Sub Child Page Content Content for Default Snippet</div></html>', page.content
150
150
  end
151
151
 
152
+ def test_load_for_full_path
153
+ assert page = CmsPage.load_for_full_path!(cms_sites(:default), '/')
154
+ assert !page.new_record?
155
+ db_content = page.content
156
+
157
+ ComfortableMexicanSofa.configuration.seed_data_path = File.expand_path('../cms_seeds', File.dirname(__FILE__))
158
+ assert page = CmsPage.load_for_full_path!(cms_sites(:default), '/')
159
+ assert page.new_record?
160
+ file_content = page.content
161
+ assert_not_equal db_content, file_content
162
+ end
163
+
164
+ def test_load_for_full_path_exceptions
165
+ assert_exception_raised ActiveRecord::RecordNotFound, 'CmsPage with path: /invalid_page cannot be found' do
166
+ CmsPage.load_for_full_path!(cms_sites(:default), '/invalid_page')
167
+ end
168
+ assert !CmsPage.load_for_full_path(cms_sites(:default), '/invalid_page')
169
+
170
+ ComfortableMexicanSofa.configuration.seed_data_path = File.expand_path('../cms_seeds', File.dirname(__FILE__))
171
+ assert_exception_raised ActiveRecord::RecordNotFound, 'CmsPage with path: /invalid_page cannot be found' do
172
+ CmsPage.load_for_full_path!(cms_sites(:default), '/invalid_page')
173
+ end
174
+ assert !CmsPage.load_for_full_path(cms_sites(:default), '/invalid_page')
175
+ end
176
+
152
177
  protected
153
178
 
154
179
  def new_params(options = {})
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: comfortable_mexican_sofa
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 11
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 13
10
- version: 1.0.13
9
+ - 14
10
+ version: 1.0.14
11
11
  platform: ruby
12
12
  authors:
13
13
  - Oleg Khabarov
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-11-03 00:00:00 -04:00
19
+ date: 2010-11-05 00:00:00 -04:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency