locomotivecms_steam 1.4.1 → 1.5.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (173) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -1
  3. data/Gemfile.lock +31 -25
  4. data/Rakefile +2 -2
  5. data/config/locales/pt-BR.yml +43 -13
  6. data/lib/locomotive/steam.rb +9 -4
  7. data/lib/locomotive/steam/adapters/filesystem.rb +2 -7
  8. data/lib/locomotive/steam/adapters/filesystem/sanitizer.rb +0 -2
  9. data/lib/locomotive/steam/adapters/filesystem/sanitizers/page.rb +11 -0
  10. data/lib/locomotive/steam/adapters/filesystem/sanitizers/section.rb +37 -0
  11. data/lib/locomotive/steam/adapters/filesystem/sanitizers/site.rb +18 -0
  12. data/lib/locomotive/steam/adapters/filesystem/yaml_loaders/content_entry.rb +4 -3
  13. data/lib/locomotive/steam/adapters/filesystem/yaml_loaders/content_type.rb +4 -3
  14. data/lib/locomotive/steam/adapters/filesystem/yaml_loaders/section.rb +40 -0
  15. data/lib/locomotive/steam/adapters/filesystem/yaml_loaders/snippet.rb +0 -1
  16. data/lib/locomotive/steam/adapters/memory.rb +1 -1
  17. data/lib/locomotive/steam/entities/content_entry.rb +15 -3
  18. data/lib/locomotive/steam/entities/content_type.rb +2 -1
  19. data/lib/locomotive/steam/entities/page.rb +21 -19
  20. data/lib/locomotive/steam/entities/section.rb +24 -0
  21. data/lib/locomotive/steam/entities/site.rb +3 -1
  22. data/lib/locomotive/steam/liquid.rb +2 -0
  23. data/lib/locomotive/steam/liquid/drops/page.rb +4 -2
  24. data/lib/locomotive/steam/liquid/drops/params.rb +51 -0
  25. data/lib/locomotive/steam/liquid/drops/section.rb +56 -0
  26. data/lib/locomotive/steam/liquid/drops/section_block.rb +47 -0
  27. data/lib/locomotive/steam/liquid/drops/section_content_proxy.rb +97 -0
  28. data/lib/locomotive/steam/liquid/drops/section_editor_setting_data.rb +65 -0
  29. data/lib/locomotive/steam/liquid/drops/site.rb +2 -1
  30. data/lib/locomotive/steam/liquid/errors.rb +2 -0
  31. data/lib/locomotive/steam/liquid/filters/base.rb +3 -3
  32. data/lib/locomotive/steam/liquid/filters/date.rb +1 -1
  33. data/lib/locomotive/steam/liquid/filters/html.rb +7 -2
  34. data/lib/locomotive/steam/liquid/filters/json.rb +3 -1
  35. data/lib/locomotive/steam/liquid/tags/action.rb +2 -2
  36. data/lib/locomotive/steam/liquid/tags/alt_page_links.rb +63 -0
  37. data/lib/locomotive/steam/liquid/tags/concerns/i18n_page.rb +1 -1
  38. data/lib/locomotive/steam/liquid/tags/concerns/section.rb +117 -0
  39. data/lib/locomotive/steam/liquid/tags/global_section.rb +32 -0
  40. data/lib/locomotive/steam/liquid/tags/model_form.rb +1 -1
  41. data/lib/locomotive/steam/liquid/tags/section.rb +87 -0
  42. data/lib/locomotive/steam/liquid/tags/sections_dropzone.rb +56 -0
  43. data/lib/locomotive/steam/liquid/tags/snippet.rb +3 -2
  44. data/lib/locomotive/steam/liquid/template.rb +0 -5
  45. data/lib/locomotive/steam/middlewares.rb +1 -1
  46. data/lib/locomotive/steam/middlewares/auth.rb +29 -13
  47. data/lib/locomotive/steam/middlewares/concerns/helpers.rb +59 -0
  48. data/lib/locomotive/steam/middlewares/concerns/liquid_context.rb +94 -0
  49. data/lib/locomotive/steam/middlewares/encoded_link_redirection.rb +45 -0
  50. data/lib/locomotive/steam/middlewares/entry_submission.rb +1 -1
  51. data/lib/locomotive/steam/middlewares/favicon.rb +1 -1
  52. data/lib/locomotive/steam/middlewares/locale.rb +63 -15
  53. data/lib/locomotive/steam/middlewares/locale_redirection.rb +18 -6
  54. data/lib/locomotive/steam/middlewares/logging.rb +1 -1
  55. data/lib/locomotive/steam/middlewares/page.rb +35 -6
  56. data/lib/locomotive/steam/middlewares/path.rb +1 -1
  57. data/lib/locomotive/steam/middlewares/private_access.rb +1 -1
  58. data/lib/locomotive/steam/middlewares/redirection.rb +1 -1
  59. data/lib/locomotive/steam/middlewares/renderer.rb +2 -82
  60. data/lib/locomotive/steam/middlewares/robots.rb +1 -1
  61. data/lib/locomotive/steam/middlewares/section.rb +56 -0
  62. data/lib/locomotive/steam/middlewares/site.rb +1 -1
  63. data/lib/locomotive/steam/middlewares/sitemap.rb +58 -45
  64. data/lib/locomotive/steam/middlewares/templatized_page.rb +1 -1
  65. data/lib/locomotive/steam/middlewares/thread_safe.rb +85 -2
  66. data/lib/locomotive/steam/middlewares/timezone.rb +1 -1
  67. data/lib/locomotive/steam/middlewares/url_redirection.rb +1 -1
  68. data/lib/locomotive/steam/models/entity.rb +0 -2
  69. data/lib/locomotive/steam/models/mapper.rb +5 -3
  70. data/lib/locomotive/steam/models/scope.rb +8 -0
  71. data/lib/locomotive/steam/repositories.rb +4 -0
  72. data/lib/locomotive/steam/repositories/content_entry_repository.rb +6 -2
  73. data/lib/locomotive/steam/repositories/page_repository.rb +4 -1
  74. data/lib/locomotive/steam/repositories/section_repository.rb +14 -0
  75. data/lib/locomotive/steam/repositories/site_repository.rb +1 -1
  76. data/lib/locomotive/steam/repositories/snippet_repository.rb +0 -3
  77. data/lib/locomotive/steam/server.rb +3 -1
  78. data/lib/locomotive/steam/services.rb +17 -1
  79. data/lib/locomotive/steam/services/action_service.rb +10 -0
  80. data/lib/locomotive/steam/services/concerns/decorator.rb +0 -2
  81. data/lib/locomotive/steam/services/image_resizer_service.rb +1 -1
  82. data/lib/locomotive/steam/services/page_finder_service.rb +6 -0
  83. data/lib/locomotive/steam/services/section_finder_service.rb +17 -0
  84. data/lib/locomotive/steam/services/url_builder_service.rb +31 -17
  85. data/lib/locomotive/steam/services/url_finder_service.rb +87 -0
  86. data/lib/locomotive/steam/version.rb +2 -2
  87. data/locomotivecms_steam.gemspec +1 -1
  88. data/spec/fixtures/default/app/views/pages/tags/section.liquid.haml +11 -0
  89. data/spec/fixtures/default/app/views/sections/carousel.liquid +20 -0
  90. data/spec/fixtures/default/app/views/sections/footer.liquid +48 -0
  91. data/spec/fixtures/default/app/views/sections/header.liquid +54 -0
  92. data/spec/fixtures/default/config/deploy.yml +1 -1
  93. data/spec/fixtures/errors/section_bad_json_content.liquid +9 -0
  94. data/spec/fixtures/errors/section_bad_json_header.liquid +8 -0
  95. data/spec/fixtures/mongodb/locomotive_accounts.bson +0 -0
  96. data/spec/fixtures/mongodb/locomotive_accounts.metadata.json +1 -1
  97. data/spec/fixtures/mongodb/locomotive_activities.bson +0 -0
  98. data/spec/fixtures/mongodb/locomotive_activities.metadata.json +1 -1
  99. data/spec/fixtures/mongodb/locomotive_content_assets.bson +0 -0
  100. data/spec/fixtures/mongodb/locomotive_content_assets.metadata.json +1 -1
  101. data/spec/fixtures/mongodb/locomotive_content_entries.bson +0 -0
  102. data/spec/fixtures/mongodb/locomotive_content_entries.metadata.json +1 -1
  103. data/spec/fixtures/mongodb/locomotive_content_types.bson +0 -0
  104. data/spec/fixtures/mongodb/locomotive_content_types.metadata.json +1 -1
  105. data/spec/fixtures/mongodb/locomotive_pages.bson +0 -0
  106. data/spec/fixtures/mongodb/locomotive_pages.metadata.json +1 -1
  107. data/spec/fixtures/mongodb/locomotive_sections.bson +0 -0
  108. data/spec/fixtures/mongodb/{sessions.metadata.json → locomotive_sections.metadata.json} +1 -1
  109. data/spec/fixtures/mongodb/locomotive_sites.bson +0 -0
  110. data/spec/fixtures/mongodb/locomotive_sites.metadata.json +1 -1
  111. data/spec/fixtures/mongodb/locomotive_snippets.bson +0 -0
  112. data/spec/fixtures/mongodb/locomotive_snippets.metadata.json +1 -1
  113. data/spec/fixtures/mongodb/locomotive_theme_assets.bson +0 -0
  114. data/spec/fixtures/mongodb/locomotive_theme_assets.metadata.json +1 -1
  115. data/spec/fixtures/mongodb/locomotive_translations.bson +0 -0
  116. data/spec/fixtures/mongodb/locomotive_translations.metadata.json +1 -1
  117. data/spec/integration/repositories/content_entry_repository_spec.rb +1 -1
  118. data/spec/integration/repositories/page_repository_spec.rb +1 -1
  119. data/spec/integration/repositories/theme_asset_repository_spec.rb +1 -1
  120. data/spec/integration/server/auth_spec.rb +0 -4
  121. data/spec/integration/server/basic_spec.rb +8 -0
  122. data/spec/integration/server/contact_form_spec.rb +15 -2
  123. data/spec/integration/server/sitemap_spec.rb +5 -3
  124. data/spec/integration/services/content_entry_service_spec.rb +1 -1
  125. data/spec/support/helpers.rb +3 -3
  126. data/spec/unit/adapters/filesystem/sanitizers/section_spec.rb +65 -0
  127. data/spec/unit/adapters/filesystem/sanitizers/site_spec.rb +28 -2
  128. data/spec/unit/adapters/filesystem/yaml_loaders/content_entry_spec.rb +8 -4
  129. data/spec/unit/adapters/filesystem/yaml_loaders/content_type_spec.rb +2 -2
  130. data/spec/unit/adapters/filesystem/yaml_loaders/page_spec.rb +1 -1
  131. data/spec/unit/adapters/filesystem/yaml_loaders/section_spec.rb +27 -0
  132. data/spec/unit/entities/section_spec.rb +29 -0
  133. data/spec/unit/liquid/drops/params_spec.rb +38 -0
  134. data/spec/unit/liquid/drops/section_content_proxy_spec.rb +88 -0
  135. data/spec/unit/liquid/drops/section_spec.rb +26 -0
  136. data/spec/unit/liquid/filters/html_spec.rb +198 -170
  137. data/spec/unit/liquid/filters/json_spec.rb +7 -0
  138. data/spec/unit/liquid/tags/action_spec.rb +12 -2
  139. data/spec/unit/liquid/tags/alt_page_links_spec.rb +58 -0
  140. data/spec/unit/liquid/tags/global_section_spec.rb +130 -0
  141. data/spec/unit/liquid/tags/link_to_spec.rb +1 -1
  142. data/spec/unit/liquid/tags/locale_switcher_spec.rb +1 -1
  143. data/spec/unit/liquid/tags/model_form_spec.rb +8 -0
  144. data/spec/unit/liquid/tags/path_to_spec.rb +26 -3
  145. data/spec/unit/liquid/tags/section_spec.rb +231 -0
  146. data/spec/unit/liquid/tags/sections_dropzone_spec.rb +107 -0
  147. data/spec/unit/middlewares/auth_spec.rb +9 -2
  148. data/spec/unit/middlewares/encoded_link_redirection_spec.rb +73 -0
  149. data/spec/unit/middlewares/entry_submission_spec.rb +1 -1
  150. data/spec/unit/middlewares/helpers_spec.rb +3 -64
  151. data/spec/unit/middlewares/locale_redirection_spec.rb +13 -2
  152. data/spec/unit/middlewares/locale_spec.rb +52 -10
  153. data/spec/unit/middlewares/page_spec.rb +57 -16
  154. data/spec/unit/middlewares/private_access_spec.rb +1 -1
  155. data/spec/unit/middlewares/redirection_spec.rb +1 -1
  156. data/spec/unit/middlewares/renderer_spec.rb +2 -1
  157. data/spec/unit/middlewares/section_spec.rb +70 -0
  158. data/spec/unit/middlewares/site_spec.rb +1 -1
  159. data/spec/unit/middlewares/sitemap_spec.rb +4 -42
  160. data/spec/unit/middlewares/url_redirection_spec.rb +1 -1
  161. data/spec/unit/repositories/content_entry_repository_spec.rb +13 -13
  162. data/spec/unit/repositories/section_repository_spec.rb +38 -0
  163. data/spec/unit/repositories/snippet_repository_spec.rb +0 -3
  164. data/spec/unit/services/action_service_spec.rb +19 -1
  165. data/spec/unit/services/asset_host_service_spec.rb +8 -0
  166. data/spec/unit/services/parent_finder_service_spec.rb +1 -2
  167. data/spec/unit/services/section_finder_service_spec.rb +28 -0
  168. data/spec/unit/services/url_builder_service_spec.rb +14 -4
  169. data/spec/unit/services/url_finder_service_spec.rb +100 -0
  170. data/spec/unit/services_spec.rb +34 -20
  171. metadata +72 -11
  172. data/lib/locomotive/steam/middlewares/helpers.rb +0 -140
  173. data/spec/fixtures/mongodb/sessions.bson +0 -0
@@ -45,7 +45,7 @@ describe Locomotive::Steam::ContentEntryService do
45
45
 
46
46
  let(:site_id) { mongodb_site_id }
47
47
  let(:adapter) { Locomotive::Steam::MongoDBAdapter.new(database: mongodb_database, hosts: ['127.0.0.1:27017']) }
48
- let(:entry_id) { BSON::ObjectId.from_string('5ae73458e051bb4f5525c92f') }
48
+ let(:entry_id) { BSON::ObjectId.from_string('5baf7d38a953300567956448') }
49
49
 
50
50
  describe '#create' do
51
51
  subject { service.create('messages', { name: 'John', email: 'john@doe.net', message: 'Hello world!' }) }
@@ -4,11 +4,11 @@ module Spec
4
4
  module Helpers
5
5
 
6
6
  def mongodb_database
7
- 'steam_test_1_4_x'
7
+ 'steam_test_1_5_x'
8
8
  end
9
9
 
10
10
  def mongodb_site_id
11
- BSON::ObjectId.from_string('5ae73303e051bb4f2bcbeefa')
11
+ BSON::ObjectId.from_string('5baf76f4a9533004e4ae9840')
12
12
  end
13
13
 
14
14
  def reset!
@@ -49,7 +49,7 @@ module Spec
49
49
  File.expand_path('../../fixtures/default/', __FILE__)
50
50
  end
51
51
 
52
- def env_for(url, opts={})
52
+ def env_for(url, opts = {})
53
53
  Rack::MockRequest.env_for(url, opts)
54
54
  end
55
55
 
@@ -0,0 +1,65 @@
1
+ require 'spec_helper'
2
+
3
+ require_relative '../../../../../lib/locomotive/steam/adapters/filesystem/sanitizer.rb'
4
+ require_relative '../../../../../lib/locomotive/steam/adapters/filesystem/sanitizers/section.rb'
5
+ require_relative '../../../../../lib/locomotive/steam/errors.rb'
6
+
7
+ describe Locomotive::Steam::Adapters::Filesystem::Sanitizers::Section do
8
+
9
+ let(:template_path) { 'spec/fixtures/default/app/views/sections/header.liquid' }
10
+ let(:entity) { instance_double('SectionEntity', template_path: template_path) }
11
+ let(:site) { instance_double('Site', _id: 1) }
12
+ let(:scope) { instance_double('Scope', site: site) }
13
+ let(:sanitizer) { described_class.new }
14
+
15
+ before(:each) do
16
+ sanitizer.setup(scope);
17
+ end
18
+
19
+ describe '#apply_to_entity' do
20
+ subject { sanitizer.apply_to_entity(entity) }
21
+
22
+ describe 'with correct json' do
23
+
24
+ it 'sanitize entity' do
25
+ expect(entity).to receive(:definition=).with(hash_including({ 'name' => 'header' }))
26
+ expect(entity).to receive(:template=).with((<<-LIQUID
27
+ <h1> {{ section.settings.brand }} </h1>
28
+ <ul>
29
+ {% for block in section.blocks %}
30
+ <li>
31
+ <a href="{{ block.settings.url }}" target="{% if block.settings.new_tab %}_blank{% endif %}">
32
+ {{ block.settings.label }}
33
+ </a>
34
+ </li>
35
+ {% endfor %}
36
+ </ul>
37
+ LIQUID
38
+ ).gsub /^$\n/, '')
39
+ expect(entity).to receive(:[]=).with(:site_id, 1)
40
+ subject
41
+ end
42
+ end
43
+ describe 'errors' do
44
+ before(:each) do
45
+ allow(entity).to receive(:[]=)
46
+ end
47
+
48
+ describe 'in json header' do
49
+ let(:template_path) { 'spec/fixtures/errors/section_bad_json_header.liquid' }
50
+
51
+ it 'should throw an error' do
52
+ expect { subject }.to raise_error(Locomotive::Steam::ParsingRenderingError)
53
+ end
54
+ end
55
+
56
+ describe 'json content' do
57
+ let(:template_path) { 'spec/fixtures/errors/section_bad_json_content.liquid' }
58
+
59
+ it 'should throw an error' do
60
+ expect { subject }.to raise_error(JSON::ParserError)
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -6,14 +6,40 @@ require_relative '../../../../../lib/locomotive/steam/adapters/filesystem/saniti
6
6
  describe Locomotive::Steam::Adapters::Filesystem::Sanitizers::Site do
7
7
 
8
8
  let(:schema) { nil }
9
- let(:entity) { instance_double('SiteEntity', metafields_schema: schema) }
9
+ let(:routes) { nil }
10
+ let(:entity) { instance_double('SiteEntity', metafields_schema: schema, routes: routes) }
10
11
  let(:sanitizer) { described_class.new }
11
12
 
12
13
  describe '#apply_to_entity' do
13
14
 
14
15
  subject { sanitizer.apply_to_entity(entity) }
15
16
 
16
- it { expect(entity).to receive(:metafields_schema=).with(nil); subject }
17
+ it 'modifies the entity' do
18
+ expect(entity).to receive(:metafields_schema=).with(nil)
19
+ expect(entity).to receive(:routes=).with([])
20
+ subject
21
+ end
22
+
23
+ end
24
+
25
+ describe '#build_routes' do
26
+
27
+ let(:routes) { nil }
28
+
29
+ subject { sanitizer.send(:build_routes, routes) }
30
+
31
+ it { is_expected.to eq [] }
32
+
33
+ describe 'various formats of the routes' do
34
+
35
+ let(:routes) { [{ '/blog/:year/:month' => 'blog' }, { 'route' => '/products/:category/:slug', 'page_handle' => 'product' }] }
36
+
37
+ it { is_expected.to eq([
38
+ { 'route' => '/blog/:year/:month', 'page_handle' => 'blog' },
39
+ { 'route' => '/products/:category/:slug', 'page_handle' => 'product' }
40
+ ]) }
41
+
42
+ end
17
43
 
18
44
  end
19
45
 
@@ -35,11 +35,14 @@ describe Locomotive::Steam::Adapters::Filesystem::YAMLLoaders::ContentEntry do
35
35
 
36
36
  context 'a content type with a select field' do
37
37
 
38
- let(:field) { instance_double('Field', name: 'kind', type: :select) }
38
+ let(:options) { instance_double('Options') }
39
+ let(:field) { instance_double('Field', name: 'kind', type: :select, select_options: options) }
39
40
  let(:content_type) { instance_double('Bands', slug: 'bands', select_fields: [field], association_fields: [], file_fields: [], password_fields: []) }
40
41
 
41
42
  it 'adds a new attribute for the foreign key' do
42
- expect(subject.first[:kind_id]).to eq 'grunge'
43
+ expect(options).to receive(:by_name).twice.with('grunge').and_return(instance_double('GrungeOption', _id: 0))
44
+ expect(options).to receive(:by_name).with('rock').and_return(instance_double('RockOption', _id: 1))
45
+ expect(subject.first[:kind_id]).to eq 0
43
46
  expect(subject.first[:kind]).to eq nil
44
47
  end
45
48
 
@@ -65,10 +68,11 @@ describe Locomotive::Steam::Adapters::Filesystem::YAMLLoaders::ContentEntry do
65
68
  let(:content_type) { instance_double('Updates', slug: 'updates', select_fields: [field], association_fields: [], file_fields: [], password_fields: []) }
66
69
 
67
70
  it 'adds a new localized attribute for the foreign key' do
68
- option = instance_double('Option', _id: 'General')
71
+ option = instance_double('Option', _id: 0)
72
+ allow(options_scope).to receive(:with_locale) { |_, &block| block.call }
69
73
  allow(options).to receive(:by_name).with('General').and_return(option)
70
74
  allow(options).to receive(:by_name).with('Général').and_return(option)
71
- expect(subject.last[:category_id]).to eq({ en: 'General', fr: 'General' })
75
+ expect(subject.last[:category_id]).to eq({ en: 0, fr: 0 })
72
76
  expect(subject.last[:category]).to eq nil
73
77
  end
74
78
 
@@ -29,7 +29,7 @@ describe Locomotive::Steam::Adapters::Filesystem::YAMLLoaders::ContentType do
29
29
 
30
30
  subject { loader.send(:build_select_options_from_hash, options) }
31
31
 
32
- it { is_expected.to eq [{ _id: 'General', name: { en: 'General', fr: 'Général' }, position: 0 }, { _id: 'Gigs', name: { en: 'Gigs', fr: 'Concerts' }, position: 1 }, { _id: 'Bands', name: { en: 'Bands', fr: 'Groupes' }, position: 2 }] }
32
+ it { is_expected.to eq [{ _id: 0, name: { en: 'General', fr: 'Général' }, position: 0 }, { _id: 1, name: { en: 'Gigs', fr: 'Concerts' }, position: 1 }, { _id: 2, name: { en: 'Bands', fr: 'Groupes' }, position: 2 }] }
33
33
 
34
34
  end
35
35
 
@@ -40,7 +40,7 @@ describe Locomotive::Steam::Adapters::Filesystem::YAMLLoaders::ContentType do
40
40
 
41
41
  subject { loader.send(:build_select_options_from_array, options) }
42
42
 
43
- it { is_expected.to eq [{ _id: 'General', name: { en: 'General', fr: 'Général' }, position: 0 }, { _id: 'Gigs', name: { en: 'Gigs', fr: 'Concerts' }, position: 1 }, { _id: 'Bands', name: { en: 'Bands', fr: 'Groupes' }, position: 2 }] }
43
+ it { is_expected.to eq [{ _id: 0, name: { en: 'General', fr: 'Général' }, position: 0 }, { _id: 1, name: { en: 'Gigs', fr: 'Concerts' }, position: 1 }, { _id: 2, name: { en: 'Bands', fr: 'Groupes' }, position: 2 }] }
44
44
 
45
45
  end
46
46
 
@@ -15,7 +15,7 @@ describe Locomotive::Steam::Adapters::Filesystem::YAMLLoaders::Page do
15
15
  subject { loader.load(scope).sort { |a, b| a[:_fullpath] <=> b[:_fullpath] } }
16
16
 
17
17
  it 'tests various stuff' do
18
- expect(subject.size).to eq 34
18
+ expect(subject.size).to eq 35
19
19
  expect(subject.first[:title]).to eq(en: 'Page not found', fr: 'Page non trouvée')
20
20
  expect(subject[23][:is_layout]).to eq true
21
21
  expect(subject[23][:listed]).to eq false
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ require_relative '../../../../../lib/locomotive/steam/adapters/filesystem/yaml_loader.rb'
4
+ require_relative '../../../../../lib/locomotive/steam/adapters/filesystem/yaml_loaders/section.rb'
5
+
6
+ describe Locomotive::Steam::Adapters::Filesystem::YAMLLoaders::Section do
7
+
8
+ let(:site_path) { default_fixture_site_path }
9
+ let(:loader) { described_class.new(site_path) }
10
+
11
+ describe '#load' do
12
+
13
+ let(:scope) { instance_double('Scope', default_locale: :en) }
14
+
15
+ subject { loader.load(scope).sort { |a, b| a[:name] <=> b[:name] } }
16
+
17
+ it 'tests various stuff' do
18
+ expect(subject.size).to eq 3
19
+ expect(subject.first[:slug]).to eq('carousel')
20
+ expect(subject[1][:name]).to eq('Footer')
21
+ expect(subject[2][:name]).to eq('Header')
22
+ expect(subject[2][:slug]).to eq('header')
23
+ end
24
+
25
+ end
26
+
27
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe Locomotive::Steam::Section do
4
+
5
+ let(:attributes) { {} }
6
+ let(:section) { described_class.new(attributes) }
7
+
8
+ describe '#source' do
9
+
10
+ let(:attributes) { { template: "Hello world"} }
11
+
12
+ subject { section.source }
13
+ it { is_expected.to eq 'Hello world' }
14
+
15
+ end
16
+
17
+ describe '#definition' do
18
+ let(:attributes) { { definition: { name: 'aName' } } }
19
+ subject { section.definition }
20
+ it { is_expected.to eq({ 'name' => 'aName' }) }
21
+ end
22
+
23
+ describe '#type' do
24
+ let(:attributes) { { slug: 'hero' } }
25
+ subject { section.type }
26
+ it { is_expected.to eq 'hero' }
27
+ end
28
+
29
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe Locomotive::Steam::Liquid::Drops::Params do
4
+
5
+ let(:params) { { 'foo' => '42' } }
6
+ let(:drop) { described_class.new(params) }
7
+
8
+ it { expect(drop.before_method('bar').to_s).to eq '' }
9
+
10
+ it { expect(drop.before_method('foo').to_s).to eq '42' }
11
+
12
+ describe 'prevent XSS attack' do
13
+
14
+ context 'passing data from Liquid to HTML' do
15
+
16
+ let(:params) { { 'foo' => 'Hello<script>alert(document.cookie)</script>' } }
17
+
18
+ it { expect(drop.before_method('foo').to_s).to eq 'Hello&lt;script&gt;alert(document.cookie)&lt;/script&gt;' }
19
+
20
+ context 'security is disabled' do
21
+
22
+ it { expect(drop.before_method('foo').html_safe).to eq 'Hello<script>alert(document.cookie)</script>' }
23
+
24
+ end
25
+
26
+ end
27
+
28
+ context 'passing data from Liquid to Javascript' do
29
+
30
+ let(:params) { { 'foo' => "'+alert(document.cookie)+'" } }
31
+
32
+ it { expect(drop.before_method('foo').to_s).to eq '&#39;+alert(document.cookie)+&#39;' }
33
+
34
+ end
35
+
36
+ end
37
+
38
+ end
@@ -0,0 +1,88 @@
1
+ require 'spec_helper'
2
+
3
+ describe Locomotive::Steam::Liquid::Drops::SectionContentProxy do
4
+
5
+ let(:url_finder_service) { instance_double('UrlFinderService') }
6
+ let(:services) { instance_double('Services', url_finder: url_finder_service) }
7
+ let(:site) { instance_double('Site', default_locale: 'en') }
8
+ let(:context) { ::Liquid::Context.new({}, {}, { locale: 'en', services: services, site: site }) }
9
+ let(:drop) { described_class.new(content, settings).tap { |d| d.context = context } }
10
+
11
+ describe 'text type setting' do
12
+
13
+ let(:settings) { [{ 'id' => 'title', 'type' => 'text' }] }
14
+ let(:content) { { 'title' => %(Click <a href="//locomotive/_locomotive-link/aaaa">here</a>) } }
15
+
16
+ subject { drop.before_method(:title) }
17
+
18
+ it 'calls the url_finder_service to transform encoded links to existing urls' do
19
+ expect(url_finder_service).to receive(:decode_urls_for).with(%(Click <a href="//locomotive/_locomotive-link/aaaa">here</a>)).and_return('done')
20
+ is_expected.to eq 'done'
21
+ end
22
+
23
+ end
24
+
25
+ describe 'url type setting' do
26
+
27
+ let(:settings) { [{ 'id' => 'link', 'type' => 'url' }] }
28
+ let(:content) { { 'link' => { 'type' => 'page', 'value' => 42, 'new_window' => true } } }
29
+ let(:page) { instance_double('Page') }
30
+
31
+ before do
32
+ expect(url_finder_service).to receive(:url_for).with({ 'type' => 'page', 'value' => 42, 'new_window' => true }).and_return(['/foo/bar', true])
33
+ end
34
+
35
+ subject { drop.before_method(:link).to_s }
36
+
37
+ it 'returns the url to the page' do
38
+ is_expected.to eq '/foo/bar'
39
+ end
40
+
41
+ context 'it knows if the link has to be opened in a new window or not' do
42
+
43
+ subject { drop.before_method(:link).new_window }
44
+
45
+ it { is_expected.to eq true }
46
+
47
+ end
48
+
49
+ end
50
+
51
+ describe 'image picker type setting' do
52
+
53
+ let(:settings) { [{ 'id' => 'image', 'type' => 'image_picker' }] }
54
+ let(:value) { nil }
55
+ let(:content) { { 'image' => value } }
56
+ let(:page) { instance_double('Page') }
57
+ let(:image_drop) { drop.before_method(:image) }
58
+
59
+ subject { image_drop.to_s }
60
+
61
+ it { is_expected.to eq('') }
62
+
63
+ context 'the content is a string' do
64
+
65
+ let(:value) { 'banner.jpg' }
66
+
67
+ it { is_expected.to eq('banner.jpg') }
68
+
69
+ end
70
+
71
+ context 'the content is a hash' do
72
+
73
+ let(:value) { { source: 'awesome_banner.jpg', cropped: 'cropped_awesome_banner.jpg', width: 42, height: 30 } }
74
+
75
+ it { is_expected.to eq('cropped_awesome_banner.jpg') }
76
+
77
+ it 'has access to the width and height of the image' do
78
+ expect(image_drop.source).to eq('awesome_banner.jpg')
79
+ expect(image_drop.cropped).to eq('cropped_awesome_banner.jpg')
80
+ expect(image_drop.width).to eq(42)
81
+ expect(image_drop.height).to eq(30)
82
+ end
83
+
84
+ end
85
+
86
+ end
87
+
88
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe Locomotive::Steam::Liquid::Drops::Section do
4
+
5
+ let(:context) { ::Liquid::Context.new({}, {}, { locale: 'en' }) }
6
+ let(:settings) { [] }
7
+ let(:definition) { instance_double('SectionDefinition', definition: { 'settings' => settings }) }
8
+ let(:drop) { described_class.new(definition, content).tap { |d| d.context = context } }
9
+
10
+ describe 'text type setting' do
11
+
12
+ let(:url_finder) { instance_double('UrlFinder', decode_urls_for: 'Hello world') }
13
+ let(:settings) { [{ 'id' => 'title', 'type' => 'text' }] }
14
+ let(:content) { { 'settings' => { 'title' => 'Hello world' } } }
15
+
16
+ before { expect(drop.settings).to receive(:url_finder).and_return(url_finder) }
17
+
18
+ subject { drop.settings.before_method(:title) }
19
+
20
+ it 'returns the value of the text setting' do
21
+ is_expected.to eq 'Hello world'
22
+ end
23
+
24
+ end
25
+
26
+ end
@@ -10,7 +10,7 @@ describe Locomotive::Steam::Liquid::Filters::Html do
10
10
  let(:services) { Locomotive::Steam::Services.build_instance }
11
11
  let(:context) { instance_double('Context', registers: { services: services }) }
12
12
 
13
- let(:theme_asset_url) { services.theme_asset_url }
13
+ let(:_theme_asset_url) { services.theme_asset_url }
14
14
  let(:theme_asset_repository) { services.repositories.theme_asset }
15
15
 
16
16
  before { services.repositories.theme_asset = EngineThemeAsset.new(nil, site) }
@@ -19,239 +19,267 @@ describe Locomotive::Steam::Liquid::Filters::Html do
19
19
 
20
20
  before { @context = context }
21
21
 
22
- it 'writes the tag to display a rss/atom feed' do
23
- expect(auto_discovery_link_tag('/foo/bar')).to eq %(
24
- <link rel="alternate" type="application/rss+xml" title="RSS" href="/foo/bar" />
25
- ).strip
22
+ describe '#auto_discovery_link_tag' do
26
23
 
27
- expect(auto_discovery_link_tag('/foo/bar', 'rel:alternate2', 'type:atom', 'title:Hello world')).to eq %(
28
- <link rel="alternate2" type="atom" title="Hello world" href="/foo/bar" />
29
- ).strip
24
+ it 'writes the tag to display a rss/atom feed' do
25
+ expect(auto_discovery_link_tag('/foo/bar')).to eq %(
26
+ <link rel="alternate" type="application/rss+xml" title="RSS" href="/foo/bar" />
27
+ ).strip
28
+
29
+ expect(auto_discovery_link_tag('/foo/bar', 'rel:alternate2', 'type:atom', 'title:Hello world')).to eq %(
30
+ <link rel="alternate2" type="atom" title="Hello world" href="/foo/bar" />
31
+ ).strip
32
+ end
30
33
  end
31
34
 
32
- it 'returns an url for a stylesheet file' do
33
- result = "/sites/42/theme/stylesheets/main.css"
34
- expect(stylesheet_url('main.css')).to eq(result)
35
- expect(stylesheet_url('main')).to eq(result)
36
- expect(stylesheet_url(nil)).to eq('')
35
+ describe '#theme_asset_url' do
36
+
37
+ it 'returns the url to a JSON file' do
38
+ expect(theme_asset_url('others/manifest.json')).to eq('/sites/42/theme/others/manifest.json')
39
+ end
40
+
37
41
  end
38
42
 
39
- describe 'with checksum' do
43
+ describe '#stylesheet_url' do
40
44
 
41
- before do
42
- Locomotive::Steam.configure { |c| c.theme_assets_checksum = true }
43
- allow(theme_asset_repository).to receive(:checksums).and_return('stylesheets/main.css' => 42)
45
+ it 'returns an url for a stylesheet file' do
46
+ result = "/sites/42/theme/stylesheets/main.css"
47
+ expect(stylesheet_url('main.css')).to eq(result)
48
+ expect(stylesheet_url('main')).to eq(result)
49
+ expect(stylesheet_url(nil)).to eq('')
44
50
  end
45
51
 
46
- after do
47
- Locomotive::Steam.reset
52
+ it 'returns an url for a stylesheet file with folder' do
53
+ result = "/sites/42/theme/stylesheets/trash/main.css"
54
+ expect(stylesheet_url('trash/main.css')).to eq(result)
48
55
  end
49
56
 
50
- it 'returns an url with the checksum' do
51
- result = "/sites/42/theme/stylesheets/main.css?42"
52
- expect(stylesheet_url('main.css')).to eq(result)
57
+ it 'returns an url for a stylesheet file without touching the url that starts with "/"' do
58
+ result = "/trash/main.css"
59
+ expect(stylesheet_url('/trash/main.css')).to eq(result)
60
+ expect(stylesheet_url('/trash/main')).to eq(result)
53
61
  end
54
62
 
55
- end
63
+ it 'returns an url for a stylesheet file without touching the url that starts with "http:"' do
64
+ expect(stylesheet_url('http://cdn.example.com/trash/main.css')).to eq "http://cdn.example.com/trash/main.css"
65
+ end
56
66
 
57
- it 'returns an url for a stylesheet file with folder' do
58
- result = "/sites/42/theme/stylesheets/trash/main.css"
59
- expect(stylesheet_url('trash/main.css')).to eq(result)
60
- end
67
+ it 'returns an url for a stylesheet file without touching the url that starts with "https:"' do
68
+ expect(stylesheet_url('https://cdn.example.com/trash/main.css')).to eq "https://cdn.example.com/trash/main.css"
69
+ end
61
70
 
62
- it 'returns an url for a stylesheet file without touching the url that starts with "/"' do
63
- result = "/trash/main.css"
64
- expect(stylesheet_url('/trash/main.css')).to eq(result)
65
- expect(stylesheet_url('/trash/main')).to eq(result)
66
- end
71
+ it 'returns an url for a stylesheet file with respect to URL-parameters' do
72
+ result = "/sites/42/theme/stylesheets/main.css?v=42"
73
+ expect(stylesheet_url('main.css?v=42')).to eq(result)
74
+ expect(stylesheet_url('main?v=42')).to eq(result)
75
+ end
67
76
 
68
- it 'returns an url for a stylesheet file without touching the url that starts with "http:"' do
69
- expect(stylesheet_url('http://cdn.example.com/trash/main.css')).to eq "http://cdn.example.com/trash/main.css"
70
- end
77
+ it 'returns a link tag for a stylesheet file' do
78
+ result = "<link href=\"/sites/42/theme/stylesheets/main.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />"
79
+ expect(stylesheet_tag('main.css')).to eq(result)
80
+ expect(stylesheet_tag('main')).to eq(result)
81
+ expect(stylesheet_tag(nil)).to eq('')
82
+ end
71
83
 
72
- it 'returns an url for a stylesheet file without touching the url that starts with "https:"' do
73
- expect(stylesheet_url('https://cdn.example.com/trash/main.css')).to eq "https://cdn.example.com/trash/main.css"
74
- end
84
+ it 'returns a link tag for a stylesheet file with folder' do
85
+ result = "<link href=\"/sites/42/theme/stylesheets/trash/main.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />"
86
+ expect(stylesheet_tag('trash/main.css')).to eq(result)
87
+ end
75
88
 
76
- it 'returns an url for a stylesheet file with respect to URL-parameters' do
77
- result = "/sites/42/theme/stylesheets/main.css?v=42"
78
- expect(stylesheet_url('main.css?v=42')).to eq(result)
79
- expect(stylesheet_url('main?v=42')).to eq(result)
80
- end
89
+ it 'returns a link tag for a stylesheet file without touching the url that starts with "/"' do
90
+ expect(stylesheet_tag('/trash/main.css')).to eq "<link href=\"/trash/main.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />"
91
+ expect(stylesheet_tag('/trash/main')).to eq "<link href=\"/trash/main.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />"
92
+ end
81
93
 
82
- it 'returns a link tag for a stylesheet file' do
83
- result = "<link href=\"/sites/42/theme/stylesheets/main.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />"
84
- expect(stylesheet_tag('main.css')).to eq(result)
85
- expect(stylesheet_tag('main')).to eq(result)
86
- expect(stylesheet_tag(nil)).to eq('')
87
- end
94
+ it 'returns a link tag for a stylesheet file without touching the url that starts with "http:"' do
95
+ expect(stylesheet_tag('http://cdn.example.com/trash/main.css')).to eq "<link href=\"http://cdn.example.com/trash/main.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />"
96
+ end
88
97
 
89
- it 'returns a link tag for a stylesheet file with folder' do
90
- result = "<link href=\"/sites/42/theme/stylesheets/trash/main.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />"
91
- expect(stylesheet_tag('trash/main.css')).to eq(result)
92
- end
98
+ it 'returns a link tag for a stylesheet file without touching the url that starts with "https:"' do
99
+ expect(stylesheet_tag('https://cdn.example.com/trash/main.css')).to eq "<link href=\"https://cdn.example.com/trash/main.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />"
100
+ end
93
101
 
94
- it 'returns a link tag for a stylesheet file without touching the url that starts with "/"' do
95
- expect(stylesheet_tag('/trash/main.css')).to eq "<link href=\"/trash/main.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />"
96
- expect(stylesheet_tag('/trash/main')).to eq "<link href=\"/trash/main.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />"
97
- end
102
+ it 'returns a link tag for a stylesheet stored in Amazon S3' do
103
+ url = 'https://com.citrrus.locomotive.s3.amazonaws.com/sites/42/theme/stylesheets/bootstrap2.css'
104
+ allow(_theme_asset_url).to receive(:build).and_return(url)
105
+ result = "<link href=\"#{url}\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />"
106
+ expect(stylesheet_tag('bootstrap2.css')).to eq(result)
107
+ end
98
108
 
99
- it 'returns a link tag for a stylesheet file without touching the url that starts with "http:"' do
100
- expect(stylesheet_tag('http://cdn.example.com/trash/main.css')).to eq "<link href=\"http://cdn.example.com/trash/main.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />"
101
- end
109
+ it 'returns a link tag for a stylesheet file and media attribute set to print' do
110
+ result = "<link href=\"/sites/42/theme/stylesheets/main.css\" media=\"print\" rel=\"stylesheet\" type=\"text/css\" />"
111
+ expect(stylesheet_tag('main.css','print')).to eq(result)
112
+ expect(stylesheet_tag('main','print')).to eq(result)
113
+ expect(stylesheet_tag(nil)).to eq('')
114
+ end
102
115
 
103
- it 'returns a link tag for a stylesheet file without touching the url that starts with "https:"' do
104
- expect(stylesheet_tag('https://cdn.example.com/trash/main.css')).to eq "<link href=\"https://cdn.example.com/trash/main.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />"
105
- end
116
+ it 'returns a link tag for a stylesheet file with folder and media attribute set to print' do
117
+ result = "<link href=\"/sites/42/theme/stylesheets/trash/main.css\" media=\"print\" rel=\"stylesheet\" type=\"text/css\" />"
118
+ expect(stylesheet_tag('trash/main.css','print')).to eq(result)
119
+ end
106
120
 
107
- it 'returns a link tag for a stylesheet stored in Amazon S3' do
108
- url = 'https://com.citrrus.locomotive.s3.amazonaws.com/sites/42/theme/stylesheets/bootstrap2.css'
109
- allow(theme_asset_url).to receive(:build).and_return(url)
110
- result = "<link href=\"#{url}\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />"
111
- expect(stylesheet_tag('bootstrap2.css')).to eq(result)
112
- end
121
+ it 'returns a link tag for a stylesheet file without touching the url that starts with "/" and media attribute set to print' do
122
+ result = "<link href=\"/trash/main.css\" media=\"print\" rel=\"stylesheet\" type=\"text/css\" />"
123
+ expect(stylesheet_tag('/trash/main.css','print')).to eq(result)
124
+ expect(stylesheet_tag('/trash/main','print')).to eq(result)
125
+ end
113
126
 
114
- it 'returns a link tag for a stylesheet file and media attribute set to print' do
115
- result = "<link href=\"/sites/42/theme/stylesheets/main.css\" media=\"print\" rel=\"stylesheet\" type=\"text/css\" />"
116
- expect(stylesheet_tag('main.css','print')).to eq(result)
117
- expect(stylesheet_tag('main','print')).to eq(result)
118
- expect(stylesheet_tag(nil)).to eq('')
119
- end
127
+ it 'returns a link tag for a stylesheet file without touching the url that starts with "http:" and media attribute set to print' do
128
+ expect(stylesheet_tag('http://cdn.example.com/trash/main.css', 'print')).to eq "<link href=\"http://cdn.example.com/trash/main.css\" media=\"print\" rel=\"stylesheet\" type=\"text/css\" />"
129
+ expect(stylesheet_tag('http://cdn.example.com/trash/main', 'print')).to eq "<link href=\"http://cdn.example.com/trash/main\" media=\"print\" rel=\"stylesheet\" type=\"text/css\" />"
130
+ end
120
131
 
121
- it 'returns a link tag for a stylesheet file with folder and media attribute set to print' do
122
- result = "<link href=\"/sites/42/theme/stylesheets/trash/main.css\" media=\"print\" rel=\"stylesheet\" type=\"text/css\" />"
123
- expect(stylesheet_tag('trash/main.css','print')).to eq(result)
124
- end
132
+ it 'returns a link tag for a stylesheet file without touching the url that starts with "https:" and media attribute set to print' do
133
+ expect(stylesheet_tag('https://cdn.example.com/trash/main.css', 'print')).to eq "<link href=\"https://cdn.example.com/trash/main.css\" media=\"print\" rel=\"stylesheet\" type=\"text/css\" />"
134
+ expect(stylesheet_tag('https://cdn.example.com/trash/main', 'print')).to eq "<link href=\"https://cdn.example.com/trash/main\" media=\"print\" rel=\"stylesheet\" type=\"text/css\" />"
135
+ end
125
136
 
126
- it 'returns a link tag for a stylesheet file without touching the url that starts with "/" and media attribute set to print' do
127
- result = "<link href=\"/trash/main.css\" media=\"print\" rel=\"stylesheet\" type=\"text/css\" />"
128
- expect(stylesheet_tag('/trash/main.css','print')).to eq(result)
129
- expect(stylesheet_tag('/trash/main','print')).to eq(result)
130
- end
137
+ describe 'with checksum' do
131
138
 
132
- it 'returns a link tag for a stylesheet file without touching the url that starts with "http:" and media attribute set to print' do
133
- expect(stylesheet_tag('http://cdn.example.com/trash/main.css', 'print')).to eq "<link href=\"http://cdn.example.com/trash/main.css\" media=\"print\" rel=\"stylesheet\" type=\"text/css\" />"
134
- expect(stylesheet_tag('http://cdn.example.com/trash/main', 'print')).to eq "<link href=\"http://cdn.example.com/trash/main\" media=\"print\" rel=\"stylesheet\" type=\"text/css\" />"
135
- end
139
+ before do
140
+ Locomotive::Steam.configure { |c| c.theme_assets_checksum = true }
141
+ allow(theme_asset_repository).to receive(:checksums).and_return('stylesheets/main.css' => 42)
142
+ end
136
143
 
137
- it 'returns a link tag for a stylesheet file without touching the url that starts with "https:" and media attribute set to print' do
138
- expect(stylesheet_tag('https://cdn.example.com/trash/main.css', 'print')).to eq "<link href=\"https://cdn.example.com/trash/main.css\" media=\"print\" rel=\"stylesheet\" type=\"text/css\" />"
139
- expect(stylesheet_tag('https://cdn.example.com/trash/main', 'print')).to eq "<link href=\"https://cdn.example.com/trash/main\" media=\"print\" rel=\"stylesheet\" type=\"text/css\" />"
140
- end
144
+ after do
145
+ Locomotive::Steam.reset
146
+ end
141
147
 
142
- it 'returns an url for a javascript file' do
143
- result = "/sites/42/theme/javascripts/main.js"
144
- expect(javascript_url('main.js')).to eq(result)
145
- expect(javascript_url('main')).to eq(result)
146
- expect(javascript_url(nil)).to eq('')
147
- end
148
+ it 'returns an url with the checksum' do
149
+ result = "/sites/42/theme/stylesheets/main.css?42"
150
+ expect(stylesheet_url('main.css')).to eq(result)
151
+ end
148
152
 
149
- it 'returns an url for a javascript file with folder' do
150
- result = "/sites/42/theme/javascripts/trash/main.js"
151
- expect(javascript_url('trash/main.js')).to eq(result)
152
- expect(javascript_url('trash/main')).to eq(result)
153
- end
153
+ end
154
154
 
155
- it 'returns an url for a javascript file without touching the url that starts with "/"' do
156
- result = "/trash/main.js"
157
- expect(javascript_url('/trash/main.js')).to eq(result)
158
- expect(javascript_url('/trash/main')).to eq(result)
159
155
  end
160
156
 
161
- it 'returns an url for a javascript file without touching the url that starts with "http:"' do
162
- expect(javascript_url('http://cdn.example.com/trash/main.js')).to eq "http://cdn.example.com/trash/main.js"
163
- expect(javascript_url('http://cdn.example.com/trash/main')).to eq "http://cdn.example.com/trash/main"
164
- end
157
+ describe '#javascript_url' do
165
158
 
166
- it 'returns an url for a javascript file without touching the url that starts with "https:"' do
167
- expect(javascript_url('https://cdn.example.com/trash/main.js')).to eq "https://cdn.example.com/trash/main.js"
168
- expect(javascript_url('https://cdn.example.com/trash/main')).to eq "https://cdn.example.com/trash/main"
169
- end
159
+ it 'returns an url for a javascript file' do
160
+ result = "/sites/42/theme/javascripts/main.js"
161
+ expect(javascript_url('main.js')).to eq(result)
162
+ expect(javascript_url('main')).to eq(result)
163
+ expect(javascript_url(nil)).to eq('')
164
+ end
170
165
 
171
- it 'returns an url for a javascript file with respect to URL-parameters' do
172
- expect(javascript_url('main.js?v=42')).to eq "/sites/42/theme/javascripts/main.js?v=42"
173
- end
166
+ it 'returns an url for a javascript file with folder' do
167
+ result = "/sites/42/theme/javascripts/trash/main.js"
168
+ expect(javascript_url('trash/main.js')).to eq(result)
169
+ expect(javascript_url('trash/main')).to eq(result)
170
+ end
174
171
 
175
- it 'returns a script tag for a javascript file' do
176
- result = %{<script src="/sites/42/theme/javascripts/main.js" type="text/javascript" ></script>}
177
- expect(javascript_tag('main.js')).to eq(result)
178
- expect(javascript_tag('main')).to eq(result)
179
- expect(javascript_tag(nil)).to eq('')
180
- end
172
+ it 'returns an url for a javascript file without touching the url that starts with "/"' do
173
+ result = "/trash/main.js"
174
+ expect(javascript_url('/trash/main.js')).to eq(result)
175
+ expect(javascript_url('/trash/main')).to eq(result)
176
+ end
181
177
 
182
- it 'returns a script tag for a javascript file with folder' do
183
- result = %{<script src="/sites/42/theme/javascripts/trash/main.js" type="text/javascript" ></script>}
184
- expect(javascript_tag('trash/main.js')).to eq(result)
185
- expect(javascript_tag('trash/main')).to eq(result)
186
- end
178
+ it 'returns an url for a javascript file without touching the url that starts with "http:"' do
179
+ expect(javascript_url('http://cdn.example.com/trash/main.js')).to eq "http://cdn.example.com/trash/main.js"
180
+ expect(javascript_url('http://cdn.example.com/trash/main')).to eq "http://cdn.example.com/trash/main"
181
+ end
187
182
 
188
- it 'returns a script tag for a javascript file without touching the url that starts with "/"' do
189
- result = %{<script src="/trash/main.js" type="text/javascript" ></script>}
190
- expect(javascript_tag('/trash/main.js')).to eq(result)
191
- expect(javascript_tag('/trash/main')).to eq(result)
192
- end
183
+ it 'returns an url for a javascript file without touching the url that starts with "https:"' do
184
+ expect(javascript_url('https://cdn.example.com/trash/main.js')).to eq "https://cdn.example.com/trash/main.js"
185
+ expect(javascript_url('https://cdn.example.com/trash/main')).to eq "https://cdn.example.com/trash/main"
186
+ end
193
187
 
194
- it 'returns a script tag for a javascript file without touching the url that starts with "http:"' do
195
- expect(javascript_tag('http://cdn.example.com/trash/main.js')).to eq %{<script src="http://cdn.example.com/trash/main.js" type="text/javascript" ></script>}
196
- expect(javascript_tag('http://cdn.example.com/trash/main')).to eq %{<script src="http://cdn.example.com/trash/main" type="text/javascript" ></script>}
197
- end
188
+ it 'returns an url for a javascript file with respect to URL-parameters' do
189
+ expect(javascript_url('main.js?v=42')).to eq "/sites/42/theme/javascripts/main.js?v=42"
190
+ end
198
191
 
199
- it 'returns a script tag for a javascript file without touching the url that starts with "https:"' do
200
- expect(javascript_tag('https://cdn.example.com/trash/main.js')).to eq %{<script src="https://cdn.example.com/trash/main.js" type="text/javascript" ></script>}
201
- expect(javascript_tag('https://cdn.example.com/trash/main')).to eq %{<script src="https://cdn.example.com/trash/main" type="text/javascript" ></script>}
202
- end
192
+ it 'returns a script tag for a javascript file' do
193
+ result = %{<script src="/sites/42/theme/javascripts/main.js" type="text/javascript" ></script>}
194
+ expect(javascript_tag('main.js')).to eq(result)
195
+ expect(javascript_tag('main')).to eq(result)
196
+ expect(javascript_tag(nil)).to eq('')
197
+ end
203
198
 
204
- it 'returns a script tag for a javascript file with "defer" option' do
205
- result = %{<script src="https://cdn.example.com/trash/main.js" type="text/javascript" defer="defer" ></script>}
206
- expect(javascript_tag('https://cdn.example.com/trash/main.js', ['defer:defer'])).to eq(result)
207
- end
199
+ it 'returns a script tag for a javascript file with folder' do
200
+ result = %{<script src="/sites/42/theme/javascripts/trash/main.js" type="text/javascript" ></script>}
201
+ expect(javascript_tag('trash/main.js')).to eq(result)
202
+ expect(javascript_tag('trash/main')).to eq(result)
203
+ end
208
204
 
209
- it 'returns an image url for a given theme file without parameters' do
210
- expect(theme_image_url('foo.jpg')).to eq "/sites/42/theme/images/foo.jpg"
211
- end
205
+ it 'returns a script tag for a javascript file without touching the url that starts with "/"' do
206
+ result = %{<script src="/trash/main.js" type="text/javascript" ></script>}
207
+ expect(javascript_tag('/trash/main.js')).to eq(result)
208
+ expect(javascript_tag('/trash/main')).to eq(result)
209
+ end
212
210
 
213
- it 'returns an image tag for a given theme file without parameters' do
214
- expect(theme_image_tag('foo.jpg')).to eq "<img src=\"/sites/42/theme/images/foo.jpg\" >"
215
- end
211
+ it 'returns a script tag for a javascript file without touching the url that starts with "http:"' do
212
+ expect(javascript_tag('http://cdn.example.com/trash/main.js')).to eq %{<script src="http://cdn.example.com/trash/main.js" type="text/javascript" ></script>}
213
+ expect(javascript_tag('http://cdn.example.com/trash/main')).to eq %{<script src="http://cdn.example.com/trash/main" type="text/javascript" ></script>}
214
+ end
216
215
 
217
- it 'returns an image tag for a given theme file with size' do
218
- expect(theme_image_tag('foo.jpg', 'width:100', 'height:100')).to eq("<img src=\"/sites/42/theme/images/foo.jpg\" height=\"100\" width=\"100\" >")
219
- end
216
+ it 'returns a script tag for a javascript file without touching the url that starts with "https:"' do
217
+ expect(javascript_tag('https://cdn.example.com/trash/main.js')).to eq %{<script src="https://cdn.example.com/trash/main.js" type="text/javascript" ></script>}
218
+ expect(javascript_tag('https://cdn.example.com/trash/main')).to eq %{<script src="https://cdn.example.com/trash/main" type="text/javascript" ></script>}
219
+ end
220
220
 
221
- it 'returns an image tag without parameters' do
222
- expect(image_tag('foo.jpg')).to eq("<img src=\"foo.jpg\" >")
223
- end
221
+ it 'returns a script tag for a javascript file with "defer" option' do
222
+ result = %{<script src="https://cdn.example.com/trash/main.js" type="text/javascript" defer="defer" ></script>}
223
+ expect(javascript_tag('https://cdn.example.com/trash/main.js', ['defer:defer'])).to eq(result)
224
+ end
224
225
 
225
- it 'returns an image tag for a file with a leading slash' do
226
- expect(image_tag('/foo.jpg')).to eq "<img src=\"/foo.jpg\" >"
227
226
  end
228
227
 
229
- it 'returns an image tag with size' do
230
- expect(image_tag('foo.jpg', 'width:100', 'height:50')).to eq("<img src=\"foo.jpg\" height=\"50\" width=\"100\" >")
228
+ describe '#theme_image_url' do
229
+
230
+ it 'returns an image url for a given theme file without parameters' do
231
+ expect(theme_image_url('foo.jpg')).to eq "/sites/42/theme/images/foo.jpg"
232
+ end
233
+
234
+ it 'returns an image tag for a given theme file without parameters' do
235
+ expect(theme_image_tag('foo.jpg')).to eq "<img src=\"/sites/42/theme/images/foo.jpg\" >"
236
+ end
237
+
238
+ it 'returns an image tag for a given theme file with size' do
239
+ expect(theme_image_tag('foo.jpg', 'width:100', 'height:100')).to eq("<img src=\"/sites/42/theme/images/foo.jpg\" height=\"100\" width=\"100\" >")
240
+ end
241
+
242
+ it 'returns an image tag without parameters' do
243
+ expect(image_tag('foo.jpg')).to eq("<img src=\"foo.jpg\" >")
244
+ end
245
+
246
+ it 'returns an image tag for a file with a leading slash' do
247
+ expect(image_tag('/foo.jpg')).to eq "<img src=\"/foo.jpg\" >"
248
+ end
249
+
250
+ it 'returns an image tag with size' do
251
+ expect(image_tag('foo.jpg', 'width:100', 'height:50')).to eq("<img src=\"foo.jpg\" height=\"50\" width=\"100\" >")
252
+ end
253
+
231
254
  end
232
255
 
233
- it 'returns a flash tag without parameters' do
234
- expect(flash_tag('foo.flv')).to eq(%{
256
+ describe '#flash_tag' do
257
+
258
+ it 'returns a flash tag without parameters' do
259
+ expect(flash_tag('foo.flv')).to eq(%{
235
260
  <object>
236
261
  <param name="movie" value="foo.flv">
237
262
  <embed src="foo.flv">
238
263
  </embed>
239
264
  </object>
240
- }.strip)
241
- end
265
+ }.strip)
266
+ end
242
267
 
243
- it 'returns a flash tag with size' do
244
- expect(flash_tag('foo.flv', 'width:100', 'height:50')).to eq(%{
268
+ it 'returns a flash tag with size' do
269
+ expect(flash_tag('foo.flv', 'width:100', 'height:50')).to eq(%{
245
270
  <object height=\"50\" width=\"100\">
246
271
  <param name="movie" value="foo.flv">
247
272
  <embed src="foo.flv" height=\"50\" width=\"100\">
248
273
  </embed>
249
274
  </object>
250
- }.strip)
275
+ }.strip)
276
+ end
277
+
251
278
  end
252
279
 
253
280
  context 'asset_host' do
254
- let(:asset_host) { 'http://asset.dev' }
281
+
282
+ let(:asset_host) { 'http://asset.dev' }
255
283
 
256
284
  it 'returns an url for a stylesheet file with respect to URL-parameters' do
257
285
  result = "http://asset.dev/sites/42/theme/stylesheets/main.css?v=42"