comfortable_mexican_sofa 1.4.22 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +2 -2
- data/Gemfile +3 -7
- data/VERSION +1 -1
- data/app/assets/stylesheets/comfortable_mexican_sofa/form.css +44 -1
- data/app/controllers/cms_admin/files_controller.rb +10 -1
- data/app/controllers/cms_admin/layouts_controller.rb +9 -0
- data/app/controllers/cms_admin/pages_controller.rb +1 -1
- data/app/controllers/cms_admin/snippets_controller.rb +10 -1
- data/app/models/cms/block.rb +29 -0
- data/app/models/cms/file.rb +9 -19
- data/app/models/cms/layout.rb +9 -0
- data/app/models/cms/page.rb +3 -4
- data/app/models/cms/snippet.rb +9 -0
- data/app/views/cms_admin/files/_file.html.erb +1 -1
- data/app/views/cms_admin/files/_index.html.erb +1 -12
- data/app/views/cms_admin/files/_page_form.html.erb +12 -0
- data/app/views/cms_admin/files/destroy.js.erb +1 -1
- data/app/views/cms_admin/files/index.html.erb +6 -2
- data/app/views/cms_admin/layouts/_index_branch.html.erb +5 -1
- data/app/views/cms_admin/layouts/index.html.erb +1 -1
- data/app/views/cms_admin/pages/_form_blocks.html.erb +2 -2
- data/app/views/cms_admin/pages/edit.html.erb +1 -1
- data/app/views/cms_admin/pages/new.html.erb +1 -1
- data/app/views/cms_admin/snippets/index.html.erb +6 -2
- data/comfortable_mexican_sofa.gemspec +16 -10
- data/config/initializers/comfortable_mexican_sofa.rb +0 -4
- data/config/initializers/paperclip.rb +25 -0
- data/config/locales/en.yml +2 -0
- data/config/locales/es.yml +2 -0
- data/config/routes.rb +8 -8
- data/db/migrate/01_create_cms.rb +6 -0
- data/db/migrate/upgrades/06_upgrade_to_1_5_0.rb +21 -0
- data/lib/comfortable_mexican_sofa/configuration.rb +14 -19
- data/lib/comfortable_mexican_sofa/form_builder.rb +48 -36
- data/lib/comfortable_mexican_sofa/tag.rb +2 -12
- data/lib/comfortable_mexican_sofa/tags/collection.rb +0 -4
- data/lib/comfortable_mexican_sofa/tags/field_datetime.rb +0 -4
- data/lib/comfortable_mexican_sofa/tags/field_integer.rb +0 -4
- data/lib/comfortable_mexican_sofa/tags/field_string.rb +0 -4
- data/lib/comfortable_mexican_sofa/tags/field_text.rb +0 -4
- data/lib/comfortable_mexican_sofa/tags/file.rb +5 -0
- data/lib/comfortable_mexican_sofa/tags/page_datetime.rb +0 -4
- data/lib/comfortable_mexican_sofa/tags/page_file.rb +44 -0
- data/lib/comfortable_mexican_sofa/tags/page_files.rb +44 -0
- data/lib/comfortable_mexican_sofa/tags/page_integer.rb +0 -4
- data/lib/comfortable_mexican_sofa/tags/page_rich_text.rb +0 -4
- data/lib/comfortable_mexican_sofa/tags/page_string.rb +0 -4
- data/lib/comfortable_mexican_sofa/tags/page_text.rb +0 -4
- data/lib/comfortable_mexican_sofa/tags/snippet.rb +5 -0
- data/lib/comfortable_mexican_sofa/view_methods.rb +6 -1
- data/test/fixtures/cms/files.yml +2 -1
- data/test/fixtures/cms/layouts.yml +4 -1
- data/test/fixtures/cms/snippets.yml +1 -0
- data/test/functional/cms_admin/files_controller_test.rb +17 -19
- data/test/functional/cms_admin/layouts_controller_test.rb +18 -1
- data/test/functional/cms_admin/pages_controller_test.rb +63 -22
- data/test/functional/cms_admin/snippets_controller_test.rb +18 -1
- data/test/gemfiles/Gemfile.rails-3.0.x +10 -0
- data/test/gemfiles/Gemfile.rails-3.1.x +10 -0
- data/test/test_helper.rb +13 -12
- data/test/unit/configuration_test.rb +1 -1
- data/test/unit/models/block_test.rb +112 -1
- data/test/unit/models/file_test.rb +1 -51
- data/test/unit/models/layout_test.rb +1 -0
- data/test/unit/models/snippet_test.rb +14 -0
- data/test/unit/tags/collection_test.rb +5 -5
- data/test/unit/tags/field_datetime_test.rb +2 -2
- data/test/unit/tags/field_integer_test.rb +2 -2
- data/test/unit/tags/field_string_test.rb +2 -2
- data/test/unit/tags/field_text_test.rb +2 -2
- data/test/unit/tags/page_datetime_test.rb +2 -2
- data/test/unit/tags/page_file_test.rb +79 -0
- data/test/unit/tags/page_files_test.rb +72 -0
- data/test/unit/tags/page_integer_test.rb +2 -2
- data/test/unit/tags/page_rich_text_test.rb +2 -2
- data/test/unit/tags/page_string_test.rb +2 -2
- data/test/unit/tags/page_text_test.rb +2 -2
- data/test/unit/view_methods_test.rb +2 -1
- metadata +20 -14
- data/gemfiles/Gemfile.rails-3.0.x +0 -14
- data/gemfiles/Gemfile.rails-3.1.x +0 -14
@@ -51,7 +51,6 @@ class CmsAdmin::SnippetsControllerTest < ActionController::TestCase
|
|
51
51
|
assert assigns(:snippet)
|
52
52
|
assert_template :edit
|
53
53
|
assert_select "form[action=/cms-admin/sites/#{snippet.site.id}/snippets/#{snippet.id}]"
|
54
|
-
assert_select "form[action='/cms-admin/sites/#{snippet.site.id}/files?file[snippet_id]=#{snippet.id}']"
|
55
54
|
end
|
56
55
|
|
57
56
|
def test_get_edit_failure
|
@@ -119,5 +118,23 @@ class CmsAdmin::SnippetsControllerTest < ActionController::TestCase
|
|
119
118
|
assert_equal 'Snippet deleted', flash[:notice]
|
120
119
|
end
|
121
120
|
end
|
121
|
+
|
122
|
+
def test_reorder
|
123
|
+
snippet_one = cms_snippets(:default)
|
124
|
+
snippet_two = cms_sites(:default).snippets.create!(
|
125
|
+
:label => 'test',
|
126
|
+
:slug => 'test'
|
127
|
+
)
|
128
|
+
assert_equal 0, snippet_one.position
|
129
|
+
assert_equal 1, snippet_two.position
|
130
|
+
|
131
|
+
post :reorder, :site_id => cms_sites(:default), :cms_snippet => [snippet_two.id, snippet_one.id]
|
132
|
+
assert_response :success
|
133
|
+
snippet_one.reload
|
134
|
+
snippet_two.reload
|
135
|
+
|
136
|
+
assert_equal 1, snippet_one.position
|
137
|
+
assert_equal 0, snippet_two.position
|
138
|
+
end
|
122
139
|
|
123
140
|
end
|
data/test/test_helper.rb
CHANGED
@@ -6,6 +6,7 @@ require 'rails/test_help'
|
|
6
6
|
|
7
7
|
class ActiveSupport::TestCase
|
8
8
|
|
9
|
+
# Shut the fuck up
|
9
10
|
$stdout_orig = $stdout
|
10
11
|
$stderr_orig = $stderr
|
11
12
|
$stdout = StringIO.new
|
@@ -21,18 +22,18 @@ class ActiveSupport::TestCase
|
|
21
22
|
# resetting default configuration
|
22
23
|
def reset_config
|
23
24
|
ComfortableMexicanSofa.configure do |config|
|
24
|
-
config.cms_title
|
25
|
-
config.admin_auth
|
26
|
-
config.public_auth
|
27
|
-
config.admin_route_prefix
|
28
|
-
config.admin_route_redirect
|
29
|
-
config.allow_irb
|
30
|
-
config.enable_fixtures
|
31
|
-
config.fixtures_path
|
32
|
-
config.revisions_limit
|
33
|
-
config.locales
|
34
|
-
config.admin_locale
|
35
|
-
config.
|
25
|
+
config.cms_title = 'ComfortableMexicanSofa MicroCMS'
|
26
|
+
config.admin_auth = 'ComfortableMexicanSofa::HttpAuth'
|
27
|
+
config.public_auth = 'ComfortableMexicanSofa::DummyAuth'
|
28
|
+
config.admin_route_prefix = 'cms-admin'
|
29
|
+
config.admin_route_redirect = ''
|
30
|
+
config.allow_irb = false
|
31
|
+
config.enable_fixtures = false
|
32
|
+
config.fixtures_path = File.expand_path('db/cms_fixtures', Rails.root)
|
33
|
+
config.revisions_limit = 25
|
34
|
+
config.locales = { :en => 'English', :es => 'Español' }
|
35
|
+
config.admin_locale = nil
|
36
|
+
config.upload_file_options = { }
|
36
37
|
end
|
37
38
|
ComfortableMexicanSofa::HttpAuth.username = 'username'
|
38
39
|
ComfortableMexicanSofa::HttpAuth.password = 'password'
|
@@ -18,7 +18,7 @@ class ConfigurationTest < ActiveSupport::TestCase
|
|
18
18
|
assert_equal ({:en => 'English', :es => 'Español'}), config.locales
|
19
19
|
assert_equal nil, config.admin_locale
|
20
20
|
assert_equal nil, config.database_config
|
21
|
-
assert_equal
|
21
|
+
assert_equal ({}), config.upload_file_options
|
22
22
|
end
|
23
23
|
|
24
24
|
def test_initialization_overrides
|
@@ -8,7 +8,13 @@ class CmsBlockTest < ActiveSupport::TestCase
|
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
def
|
11
|
+
def test_tag
|
12
|
+
block = cms_blocks(:default_page_text)
|
13
|
+
assert block.page.tags(true).collect(&:identifier).member?('page_text_default_page_text')
|
14
|
+
assert_equal 'page_text_default_page_text', block.tag.identifier
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_creation_via_page_nested_attributes
|
12
18
|
assert_difference ['Cms::Page.count', 'Cms::Block.count'] do
|
13
19
|
page = Cms::Page.create!(
|
14
20
|
:site => cms_sites(:default),
|
@@ -30,4 +36,109 @@ class CmsBlockTest < ActiveSupport::TestCase
|
|
30
36
|
end
|
31
37
|
end
|
32
38
|
|
39
|
+
def test_creation_via_page_nested_attributes_as_hash
|
40
|
+
assert_difference ['Cms::Page.count', 'Cms::Block.count'] do
|
41
|
+
page = Cms::Page.create!(
|
42
|
+
:site => cms_sites(:default),
|
43
|
+
:layout => cms_layouts(:default),
|
44
|
+
:label => 'test page',
|
45
|
+
:slug => 'test_page',
|
46
|
+
:parent_id => cms_pages(:default).id,
|
47
|
+
:blocks_attributes => {
|
48
|
+
'0' => {
|
49
|
+
:label => 'default_page_text',
|
50
|
+
:content => 'test_content'
|
51
|
+
}
|
52
|
+
}
|
53
|
+
)
|
54
|
+
assert_equal 1, page.blocks.count
|
55
|
+
block = page.blocks.first
|
56
|
+
assert_equal 'default_page_text', block.label
|
57
|
+
assert_equal 'test_content', block.content
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_creation_and_update_via_nested_attributes_with_file
|
62
|
+
layout = cms_layouts(:default)
|
63
|
+
layout.update_attribute(:content, '{{cms:page_file:file}}')
|
64
|
+
|
65
|
+
page = nil
|
66
|
+
assert_difference ['Cms::Page.count', 'Cms::Block.count', 'Cms::File.count'] do
|
67
|
+
page = Cms::Page.create!(
|
68
|
+
:site => cms_sites(:default),
|
69
|
+
:layout => layout,
|
70
|
+
:label => 'test page',
|
71
|
+
:slug => 'test_page',
|
72
|
+
:parent_id => cms_pages(:default).id,
|
73
|
+
:blocks_attributes => [
|
74
|
+
{ :label => 'file',
|
75
|
+
:content => [fixture_file_upload('files/valid_image.jpg'), fixture_file_upload('files/invalid_file.gif')] }
|
76
|
+
]
|
77
|
+
)
|
78
|
+
assert_equal 1, page.blocks.count
|
79
|
+
block = page.blocks.first
|
80
|
+
assert_equal 'file', block.label
|
81
|
+
assert_equal nil, block.content
|
82
|
+
assert_equal 1, block.files.count
|
83
|
+
assert_equal 'valid_image.jpg', block.files.first.file_file_name
|
84
|
+
end
|
85
|
+
|
86
|
+
assert_no_difference ['Cms::Block.count', 'Cms::File.count'] do
|
87
|
+
page.update_attributes!(
|
88
|
+
:blocks_attributes => [
|
89
|
+
{ :label => 'file',
|
90
|
+
:content => fixture_file_upload('files/invalid_file.gif') }
|
91
|
+
]
|
92
|
+
)
|
93
|
+
page.reload
|
94
|
+
block = page.blocks.first
|
95
|
+
assert_equal 1, block.files.count
|
96
|
+
assert_equal 'invalid_file.gif', block.files.first.file_file_name
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_creation_and_update_via_nested_attributes_with_files
|
101
|
+
layout = cms_layouts(:default)
|
102
|
+
layout.update_attribute(:content, '{{cms:page_files:files}}')
|
103
|
+
|
104
|
+
page = nil
|
105
|
+
assert_difference ['Cms::Page.count', 'Cms::Block.count'] do
|
106
|
+
assert_difference 'Cms::File.count', 2 do
|
107
|
+
page = Cms::Page.create!(
|
108
|
+
:site => cms_sites(:default),
|
109
|
+
:layout => layout,
|
110
|
+
:label => 'test page',
|
111
|
+
:slug => 'test_page',
|
112
|
+
:parent_id => cms_pages(:default).id,
|
113
|
+
:blocks_attributes => [
|
114
|
+
{ :label => 'files',
|
115
|
+
:content => [fixture_file_upload('files/valid_image.jpg'), fixture_file_upload('files/invalid_file.gif')] }
|
116
|
+
]
|
117
|
+
)
|
118
|
+
assert_equal 1, page.blocks.count
|
119
|
+
block = page.blocks.first
|
120
|
+
assert_equal 'files', block.label
|
121
|
+
assert_equal nil, block.content
|
122
|
+
assert_equal 2, block.files.count
|
123
|
+
assert_equal ['valid_image.jpg', 'invalid_file.gif'], block.files.collect(&:file_file_name)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
assert_no_difference 'Cms::Block.count' do
|
128
|
+
assert_difference 'Cms::File.count', 2 do
|
129
|
+
page.update_attributes!(
|
130
|
+
:blocks_attributes => [
|
131
|
+
{ :label => 'files',
|
132
|
+
:content => [fixture_file_upload('files/valid_image.jpg'), fixture_file_upload('files/invalid_file.gif')] }
|
133
|
+
]
|
134
|
+
)
|
135
|
+
page.reload
|
136
|
+
block = page.blocks.first
|
137
|
+
assert_equal 4, block.files.count
|
138
|
+
assert_equal ['valid_image.jpg', 'invalid_file.gif', 'valid_image.jpg', 'invalid_file.gif'],
|
139
|
+
block.files.collect(&:file_file_name)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
33
144
|
end
|
@@ -22,57 +22,7 @@ class CmsFileTest < ActiveSupport::TestCase
|
|
22
22
|
:file => fixture_file_upload('files/valid_image.jpg')
|
23
23
|
)
|
24
24
|
assert_equal 'Valid Image', file.label
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_creation_with_layout_link_and_config_disabled
|
29
|
-
assert !ComfortableMexicanSofa.config.auto_file_categorization
|
30
|
-
assert_difference 'Cms::File.count' do
|
31
|
-
assert_no_difference ['Cms::Category.count', 'Cms::Categorization.count'] do
|
32
|
-
file = cms_sites(:default).files.create(
|
33
|
-
:file => fixture_file_upload('files/valid_image.jpg'),
|
34
|
-
:layout_id => cms_layouts(:default)
|
35
|
-
)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_creation_with_layout_link
|
41
|
-
ComfortableMexicanSofa.config.auto_file_categorization = true
|
42
|
-
assert_difference ['Cms::File.count', 'Cms::Category.count', 'Cms::Categorization.count'] do
|
43
|
-
file = cms_sites(:default).files.create(
|
44
|
-
:file => fixture_file_upload('files/valid_image.jpg'),
|
45
|
-
:layout_id => cms_layouts(:default)
|
46
|
-
)
|
47
|
-
assert_equal 1, file.categories.count
|
48
|
-
assert_equal '[layout] default', file.categories.first.label
|
49
|
-
assert_equal 'Cms::File', file.categories.first.categorized_type
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_creation_with_page_link
|
54
|
-
ComfortableMexicanSofa.config.auto_file_categorization = true
|
55
|
-
assert_difference ['Cms::File.count', 'Cms::Category.count', 'Cms::Categorization.count'] do
|
56
|
-
file = cms_sites(:default).files.create(
|
57
|
-
:file => fixture_file_upload('files/valid_image.jpg'),
|
58
|
-
:page_id => cms_pages(:default)
|
59
|
-
)
|
60
|
-
assert_equal 1, file.categories.count
|
61
|
-
assert_equal '[page] /', file.categories.first.label
|
62
|
-
assert_equal 'Cms::File', file.categories.first.categorized_type
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_creation_with_snippet_link
|
67
|
-
ComfortableMexicanSofa.config.auto_file_categorization = true
|
68
|
-
assert_difference ['Cms::File.count', 'Cms::Category.count', 'Cms::Categorization.count'] do
|
69
|
-
file = cms_sites(:default).files.create(
|
70
|
-
:file => fixture_file_upload('files/valid_image.jpg'),
|
71
|
-
:snippet_id => cms_snippets(:default)
|
72
|
-
)
|
73
|
-
assert_equal 1, file.categories.count
|
74
|
-
assert_equal '[snippet] default', file.categories.first.label
|
75
|
-
assert_equal 'Cms::File', file.categories.first.categorized_type
|
25
|
+
assert_equal 1, file.position
|
76
26
|
end
|
77
27
|
end
|
78
28
|
|
@@ -23,6 +23,20 @@ class CmsSnippetTest < ActiveSupport::TestCase
|
|
23
23
|
assert_equal 'Test', snippet.label
|
24
24
|
end
|
25
25
|
|
26
|
+
def test_create
|
27
|
+
assert_difference 'Cms::Snippet.count' do
|
28
|
+
snippet = cms_sites(:default).snippets.create(
|
29
|
+
:label => 'Test Snippet',
|
30
|
+
:slug => 'test',
|
31
|
+
:content => 'Test Content'
|
32
|
+
)
|
33
|
+
assert_equal 'Test Snippet', snippet.label
|
34
|
+
assert_equal 'test', snippet.slug
|
35
|
+
assert_equal 'Test Content', snippet.content
|
36
|
+
assert_equal 1, snippet.position
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
26
40
|
def test_update_forces_page_content_reload
|
27
41
|
snippet = cms_snippets(:default)
|
28
42
|
page = cms_pages(:default)
|
@@ -74,10 +74,10 @@ class CollectionTagTest < ActiveSupport::TestCase
|
|
74
74
|
assert tag = ComfortableMexicanSofa::Tag::Collection.initialize_tag(
|
75
75
|
cms_pages(:default), '{{ cms:collection:snippet:cms/snippet }}'
|
76
76
|
)
|
77
|
-
assert tag.content.blank?
|
77
|
+
assert tag.block.content.blank?
|
78
78
|
|
79
79
|
snippet = cms_snippets(:default)
|
80
|
-
tag.content = snippet.id
|
80
|
+
tag.block.content = snippet.id
|
81
81
|
assert_equal snippet.id, tag.block.content
|
82
82
|
assert_equal snippet.id, tag.content
|
83
83
|
assert_equal "<%= render :partial => 'partials/cms/snippets', :locals => {:model => 'Cms::Snippet', :identifier => '#{snippet.id}'} %>", tag.render
|
@@ -87,10 +87,10 @@ class CollectionTagTest < ActiveSupport::TestCase
|
|
87
87
|
assert tag = ComfortableMexicanSofa::Tag::Collection.initialize_tag(
|
88
88
|
cms_pages(:default), '{{ cms:collection:snippet:cms/snippet:path/to/partial:label:slug:param_a:param_b }}'
|
89
89
|
)
|
90
|
-
assert tag.content.blank?
|
90
|
+
assert tag.block.content.blank?
|
91
91
|
|
92
92
|
snippet = cms_snippets(:default)
|
93
|
-
tag.content = snippet.slug
|
93
|
+
tag.block.content = snippet.slug
|
94
94
|
assert_equal snippet.slug, tag.block.content
|
95
95
|
assert_equal snippet.slug, tag.content
|
96
96
|
assert_equal "<%= render :partial => 'path/to/partial', :locals => {:model => 'Cms::Snippet', :identifier => '#{snippet.slug}', :param_1 => 'param_a', :param_2 => 'param_b'} %>", tag.render
|
@@ -100,7 +100,7 @@ class CollectionTagTest < ActiveSupport::TestCase
|
|
100
100
|
assert tag = ComfortableMexicanSofa::Tag::Collection.initialize_tag(
|
101
101
|
cms_pages(:default), '{{ cms:collection:snippet:cms/snippet:path/to/partial }}'
|
102
102
|
)
|
103
|
-
assert tag.content.blank?
|
103
|
+
assert tag.block.content.blank?
|
104
104
|
assert_equal '', tag.render
|
105
105
|
end
|
106
106
|
|
@@ -34,9 +34,9 @@ class FieldDateTimeTagTest < ActiveSupport::TestCase
|
|
34
34
|
tag = ComfortableMexicanSofa::Tag::FieldDateTime.initialize_tag(
|
35
35
|
cms_pages(:default), '{{cms:field:content:datetime}}'
|
36
36
|
)
|
37
|
-
assert tag.content.blank?
|
37
|
+
assert tag.block.content.blank?
|
38
38
|
time = 2.days.ago
|
39
|
-
tag.content = time
|
39
|
+
tag.block.content = time
|
40
40
|
assert_equal time, tag.content
|
41
41
|
assert_equal '', tag.render
|
42
42
|
end
|
@@ -34,8 +34,8 @@ class FieldIntegerTagTest < ActiveSupport::TestCase
|
|
34
34
|
tag = ComfortableMexicanSofa::Tag::FieldInteger.initialize_tag(
|
35
35
|
cms_pages(:default), '{{cms:field:content:integer}}'
|
36
36
|
)
|
37
|
-
assert tag.content.blank?
|
38
|
-
tag.content = '5'
|
37
|
+
assert tag.block.content.blank?
|
38
|
+
tag.block.content = '5'
|
39
39
|
assert_equal '5', tag.content
|
40
40
|
assert_equal '', tag.render
|
41
41
|
end
|
@@ -37,8 +37,8 @@ class FieldStringTagTest < ActiveSupport::TestCase
|
|
37
37
|
tag = ComfortableMexicanSofa::Tag::FieldString.initialize_tag(
|
38
38
|
cms_pages(:default), '{{cms:field:content}}'
|
39
39
|
)
|
40
|
-
assert tag.content.blank?
|
41
|
-
tag.content = 'test_content'
|
40
|
+
assert tag.block.content.blank?
|
41
|
+
tag.block.content = 'test_content'
|
42
42
|
assert_equal 'test_content', tag.content
|
43
43
|
assert_equal '', tag.render
|
44
44
|
end
|
@@ -33,8 +33,8 @@ class FieldTextTagTest < ActiveSupport::TestCase
|
|
33
33
|
tag = ComfortableMexicanSofa::Tag::FieldText.initialize_tag(
|
34
34
|
cms_pages(:default), '{{cms:field:content:text}}'
|
35
35
|
)
|
36
|
-
assert tag.content.blank?
|
37
|
-
tag.content = 'test_content'
|
36
|
+
assert tag.block.content.blank?
|
37
|
+
tag.block.content = 'test_content'
|
38
38
|
assert_equal 'test_content', tag.content
|
39
39
|
assert_equal '', tag.render
|
40
40
|
end
|
@@ -34,9 +34,9 @@ class PageDateTimeTagTest < ActiveSupport::TestCase
|
|
34
34
|
tag = ComfortableMexicanSofa::Tag::PageDateTime.initialize_tag(
|
35
35
|
cms_pages(:default), '{{cms:page:content:datetime}}'
|
36
36
|
)
|
37
|
-
assert tag.content.blank?
|
37
|
+
assert tag.block.content.blank?
|
38
38
|
time = 2.days.ago
|
39
|
-
tag.content = time
|
39
|
+
tag.block.content = time
|
40
40
|
assert_equal time, tag.content
|
41
41
|
assert_equal time.to_s, tag.render
|
42
42
|
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require File.expand_path('../../test_helper', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
class PageFileTagTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
def test_initialize_tag
|
6
|
+
assert tag = ComfortableMexicanSofa::Tag::PageFile.initialize_tag(
|
7
|
+
cms_pages(:default), '{{ cms:page_file:label }}'
|
8
|
+
)
|
9
|
+
assert 'url', tag.type
|
10
|
+
|
11
|
+
assert tag = ComfortableMexicanSofa::Tag::PageFile.initialize_tag(
|
12
|
+
cms_pages(:default), '{{ cms:page_file:label:partial }}'
|
13
|
+
)
|
14
|
+
assert 'partial', tag.type
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_initialize_tag_failure
|
18
|
+
[
|
19
|
+
'{{cms:page_file}}',
|
20
|
+
'{{cms:not_page_file:label}}',
|
21
|
+
'{not_a_tag}'
|
22
|
+
].each do |tag_signature|
|
23
|
+
assert_nil ComfortableMexicanSofa::Tag::PageFile.initialize_tag(
|
24
|
+
cms_pages(:default), tag_signature
|
25
|
+
)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_content_and_render
|
30
|
+
page = cms_pages(:default)
|
31
|
+
|
32
|
+
assert tag = ComfortableMexicanSofa::Tag::PageFile.initialize_tag(page, '{{ cms:page_file:file:partial }}')
|
33
|
+
assert_equal "<%= render :partial => 'partials/page_file', :locals => {:identifier => nil} %>", tag.render
|
34
|
+
|
35
|
+
assert tag = ComfortableMexicanSofa::Tag::PageFile.initialize_tag(page, '{{ cms:page_file:file }}')
|
36
|
+
assert_equal nil, tag.content
|
37
|
+
assert_equal '', tag.render
|
38
|
+
|
39
|
+
page.update_attributes!(
|
40
|
+
:blocks_attributes => [
|
41
|
+
{ :label => 'file',
|
42
|
+
:content => fixture_file_upload('files/valid_image.jpg') }
|
43
|
+
]
|
44
|
+
)
|
45
|
+
file = tag.block.files.first
|
46
|
+
|
47
|
+
assert_equal file, tag.content
|
48
|
+
assert_equal "/system/files/#{file.id}/original/valid_image.jpg", tag.render
|
49
|
+
|
50
|
+
assert tag = ComfortableMexicanSofa::Tag::PageFile.initialize_tag(page, '{{ cms:page_file:file:link }}')
|
51
|
+
assert_equal "<a href='/system/files/#{file.id}/original/valid_image.jpg' target='_blank'>file</a>",
|
52
|
+
tag.render
|
53
|
+
|
54
|
+
assert tag = ComfortableMexicanSofa::Tag::PageFile.initialize_tag(page, '{{ cms:page_file:file:link:link label }}')
|
55
|
+
assert_equal "<a href='/system/files/#{file.id}/original/valid_image.jpg' target='_blank'>link label</a>",
|
56
|
+
tag.render
|
57
|
+
|
58
|
+
assert tag = ComfortableMexicanSofa::Tag::PageFile.initialize_tag(page, '{{ cms:page_file:file:image }}')
|
59
|
+
assert_equal "<img src='/system/files/#{file.id}/original/valid_image.jpg' alt='file' />",
|
60
|
+
tag.render
|
61
|
+
|
62
|
+
assert tag = ComfortableMexicanSofa::Tag::PageFile.initialize_tag(page, '{{ cms:page_file:file:image:image alt }}')
|
63
|
+
assert_equal "<img src='/system/files/#{file.id}/original/valid_image.jpg' alt='image alt' />",
|
64
|
+
tag.render
|
65
|
+
|
66
|
+
assert tag = ComfortableMexicanSofa::Tag::PageFile.initialize_tag(page, '{{ cms:page_file:file:partial }}')
|
67
|
+
assert_equal "<%= render :partial => 'partials/page_file', :locals => {:identifier => #{file.id}} %>",
|
68
|
+
tag.render
|
69
|
+
|
70
|
+
assert tag = ComfortableMexicanSofa::Tag::PageFile.initialize_tag(page, '{{ cms:page_file:file:partial:path/to/partial }}')
|
71
|
+
assert_equal "<%= render :partial => 'path/to/partial', :locals => {:identifier => #{file.id}} %>",
|
72
|
+
tag.render
|
73
|
+
|
74
|
+
assert tag = ComfortableMexicanSofa::Tag::PageFile.initialize_tag(page, '{{ cms:page_file:file:partial:path/to/partial:a:b }}')
|
75
|
+
assert_equal "<%= render :partial => 'path/to/partial', :locals => {:identifier => #{file.id}, :param_1 => 'a', :param_2 => 'b'} %>",
|
76
|
+
tag.render
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|