locomotive_cms 2.1.4 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (143) hide show
  1. data/Gemfile +1 -5
  2. data/app/assets/images/locomotive/icons/flags/zh-CN.png +0 -0
  3. data/app/assets/javascripts/aloha/plugins/custom/inputcontrol/css/inputcontrol.css +3 -0
  4. data/app/assets/javascripts/aloha/plugins/custom/inputcontrol/lib/inputcontrol-plugin.js +94 -0
  5. data/app/assets/javascripts/aloha/plugins/custom/inputcontrol/package.json +1 -0
  6. data/app/assets/javascripts/locomotive.js +2 -1
  7. data/app/assets/javascripts/locomotive/models/content_type.js.coffee +6 -2
  8. data/app/assets/javascripts/locomotive/models/page.js.coffee +1 -1
  9. data/app/assets/javascripts/locomotive/models/site.js.coffee +1 -1
  10. data/app/assets/javascripts/locomotive/utils/aloha_settings.js.coffee +17 -7
  11. data/app/assets/javascripts/locomotive/utils/tinymce_settings.js.coffee +6 -0
  12. data/app/assets/javascripts/locomotive/views/application_view.js.coffee +13 -2
  13. data/app/assets/javascripts/locomotive/views/content_entries/_form_view.js.coffee +19 -2
  14. data/app/assets/javascripts/locomotive/views/content_entries/_popup_form_view.js.coffee +1 -1
  15. data/app/assets/javascripts/locomotive/views/content_entries/index_view.js.coffee +2 -2
  16. data/app/assets/javascripts/locomotive/views/content_types/_form_view.js.coffee +2 -1
  17. data/app/assets/javascripts/locomotive/views/content_types/custom_field_entry_view.js.coffee +3 -0
  18. data/app/assets/javascripts/locomotive/views/current_site/edit_view.js.coffee +2 -1
  19. data/app/assets/javascripts/locomotive/views/editable_elements/edit_all_view.js.coffee +3 -6
  20. data/app/assets/javascripts/locomotive/views/editable_elements/text_view.js.coffee +47 -0
  21. data/app/assets/javascripts/locomotive/views/inline_editor/toolbar_view.js.coffee +1 -1
  22. data/app/assets/javascripts/locomotive/views/pages/_form_view.js.coffee +2 -1
  23. data/app/assets/javascripts/locomotive/views/pages/list_view.js.coffee +2 -2
  24. data/app/assets/javascripts/locomotive/views/shared/fields/belongs_to_view.js.coffee +32 -0
  25. data/app/assets/javascripts/locomotive/views/shared/fields/has_many_view.js.coffee +2 -2
  26. data/app/assets/javascripts/locomotive/views/shared/fields/many_to_many_view.js.coffee +2 -2
  27. data/app/assets/javascripts/locomotive/views/shared/form_view.js.coffee +2 -0
  28. data/app/assets/javascripts/locomotive/views/snippets/_form_view.js.coffee +2 -1
  29. data/app/assets/javascripts/locomotive/views/theme_assets/_form_view.js.coffee +2 -1
  30. data/app/assets/javascripts/locomotive/views/theme_assets/index_view.js.coffee +0 -1
  31. data/app/assets/javascripts/tinymce/plugins/locomotive_media/langs/es.js +1 -0
  32. data/app/assets/javascripts/tinymce/plugins/locomotive_media/langs/et.js +1 -0
  33. data/app/assets/javascripts/tinymce/plugins/locomotive_media/langs/it.js +1 -0
  34. data/app/assets/javascripts/tinymce/plugins/locomotive_media/langs/ja.js +1 -0
  35. data/app/assets/javascripts/tinymce/plugins/locomotive_media/langs/nb.js +1 -0
  36. data/app/assets/javascripts/tinymce/plugins/locomotive_media/langs/nl.js +1 -0
  37. data/app/assets/javascripts/tinymce/plugins/locomotive_media/langs/no.js +1 -0
  38. data/app/assets/javascripts/tinymce/plugins/locomotive_media/langs/pl.js +1 -0
  39. data/app/assets/javascripts/tinymce/plugins/locomotive_media/langs/pt.js +1 -0
  40. data/app/assets/javascripts/tinymce/plugins/locomotive_media/langs/zh-cn.js +1 -0
  41. data/app/assets/stylesheets/locomotive.css +1 -0
  42. data/app/assets/stylesheets/locomotive/backoffice/codemirror_changes.css.scss +2 -0
  43. data/app/assets/stylesheets/locomotive/backoffice/formtastic_changes.css.scss +17 -3
  44. data/app/controllers/locomotive/content_entries_controller.rb +6 -2
  45. data/app/controllers/locomotive/public/content_entries_controller.rb +6 -0
  46. data/app/helpers/locomotive/base_helper.rb +8 -0
  47. data/app/helpers/locomotive/sites_helper.rb +6 -0
  48. data/app/models/locomotive/content_entry.rb +35 -5
  49. data/app/models/locomotive/content_type.rb +26 -8
  50. data/app/models/locomotive/editable_element.rb +15 -1
  51. data/app/models/locomotive/editable_file.rb +0 -2
  52. data/app/models/locomotive/editable_long_text.rb +3 -3
  53. data/app/models/locomotive/editable_short_text.rb +3 -64
  54. data/app/models/locomotive/editable_text.rb +84 -0
  55. data/app/models/locomotive/extensions/content_entry/csv.rb +7 -3
  56. data/app/models/locomotive/extensions/page/editable_elements.rb +3 -5
  57. data/app/models/locomotive/extensions/site/locales.rb +20 -0
  58. data/app/models/locomotive/extensions/site/timezone.rb +35 -0
  59. data/app/models/locomotive/site.rb +20 -16
  60. data/app/models/locomotive/theme_asset.rb +1 -1
  61. data/app/presenters/locomotive/content_entry_presenter.rb +1 -1
  62. data/app/presenters/locomotive/{editable_short_text_presenter.rb → editable_text_presenter.rb} +14 -2
  63. data/app/views/locomotive/current_site/_form.html.haml +1 -0
  64. data/app/views/locomotive/custom_fields/types/_belongs_to.html.haml +6 -5
  65. data/app/views/locomotive/pages/_editable_elements.html.haml +1 -1
  66. data/app/views/locomotive/shared/_head.html.haml +2 -0
  67. data/app/views/locomotive/shared/_main_app_head_before_backbone.html.haml +1 -0
  68. data/config/locales/admin_ui.de.yml +1 -0
  69. data/config/locales/admin_ui.en.yml +1 -0
  70. data/config/locales/admin_ui.et.yml +1 -0
  71. data/config/locales/admin_ui.fr.yml +1 -0
  72. data/config/locales/admin_ui.ja.yml +1 -0
  73. data/config/locales/admin_ui.nb.yml +2 -0
  74. data/config/locales/admin_ui.pl.yml +1 -0
  75. data/config/locales/admin_ui.pt-BR.yml +2 -1
  76. data/config/locales/admin_ui.ru.yml +24 -4
  77. data/config/locales/admin_ui.zh-CN.yml +347 -0
  78. data/config/locales/carrierwave.zh-CN.yml +4 -0
  79. data/config/locales/default.zh-CN.yml +116 -0
  80. data/config/locales/devise.nb.yml +1 -0
  81. data/config/locales/devise.zh-CN.yml +64 -0
  82. data/config/locales/flash.zh-CN.yml +115 -0
  83. data/config/locales/formtastic.en.yml +1 -0
  84. data/config/locales/formtastic.ru.yml +4 -1
  85. data/config/locales/formtastic.zh-CN.yml +112 -0
  86. data/features/backoffice/content_types/localized.feature +63 -0
  87. data/features/backoffice/pages.feature +3 -1
  88. data/features/backoffice/site.feature +7 -0
  89. data/features/public/contact_form.feature +11 -0
  90. data/features/public/content_entries.feature +13 -0
  91. data/features/public/pages.feature +24 -0
  92. data/features/step_definitions/page_steps.rb +6 -0
  93. data/features/step_definitions/web_steps.rb +24 -7
  94. data/lib/generators/locomotive/install/templates/locomotive.rb +2 -2
  95. data/lib/generators/locomotive/install/templates/mongoid.yml +23 -29
  96. data/lib/locomotive.rb +1 -4
  97. data/lib/locomotive/configuration.rb +3 -3
  98. data/lib/locomotive/dependencies.rb +1 -0
  99. data/lib/locomotive/engine.rb +2 -1
  100. data/lib/locomotive/liquid/drops/page.rb +1 -1
  101. data/lib/locomotive/liquid/filters/date.rb +3 -1
  102. data/lib/locomotive/liquid/filters/misc.rb +4 -0
  103. data/lib/locomotive/liquid/filters/text.rb +4 -0
  104. data/lib/locomotive/liquid/tags/editable.rb +1 -2
  105. data/lib/locomotive/liquid/tags/editable/text.rb +79 -0
  106. data/lib/locomotive/liquid/tags/inline_editor.rb +1 -1
  107. data/lib/locomotive/liquid/tags/link_to.rb +72 -13
  108. data/lib/locomotive/liquid/tags/with_scope.rb +3 -3
  109. data/lib/locomotive/middlewares.rb +0 -1
  110. data/lib/locomotive/mongoid/patches.rb +0 -16
  111. data/lib/locomotive/render.rb +1 -1
  112. data/lib/locomotive/version.rb +1 -1
  113. data/lib/tasks/locomotive.rake +15 -9
  114. data/mongodb/migrate/20130326201349_rename_entry_to_content_entry.rb +1 -1
  115. data/mongodb/migrate/20130621135025_create_editable_texts.rb +42 -0
  116. data/mongodb/migrate/20130627101548_localize_slugs_of_content_entries.rb +43 -0
  117. data/spec/dummy/config/initializers/locomotive.rb +1 -1
  118. data/spec/dummy/config/initializers/session_store.rb +1 -1
  119. data/spec/lib/locomotive/liquid/drops/page_spec.rb +1 -1
  120. data/spec/lib/locomotive/liquid/filters/misc_spec.rb +26 -0
  121. data/spec/lib/locomotive/liquid/tags/editable/text_spec.rb +85 -0
  122. data/spec/lib/locomotive/liquid/tags/link_to_spec.rb +111 -0
  123. data/spec/lib/locomotive/liquid/tags/with_scope_spec.rb +6 -0
  124. data/spec/models/locomotive/content_entry_spec.rb +27 -7
  125. data/spec/models/locomotive/{editable_short_text_spec.rb → editable_text_spec.rb} +53 -8
  126. data/spec/models/locomotive/extensions/page/editable_elements_spec.rb +6 -6
  127. data/spec/models/locomotive/site_spec.rb +52 -32
  128. data/vendor/assets/images/select2-spinner.gif +0 -0
  129. data/vendor/assets/images/select2.png +0 -0
  130. data/vendor/assets/images/select2x2.png +0 -0
  131. data/vendor/assets/javascripts/locomotive/liquid_mode.js +1 -1
  132. data/vendor/assets/javascripts/select2/select2.js +3054 -0
  133. data/vendor/assets/stylesheets/select2/select2.css.scss +652 -0
  134. metadata +77 -33
  135. data/app/assets/javascripts/locomotive/views/editable_elements/long_text_view.js.coffee +0 -36
  136. data/app/assets/javascripts/locomotive/views/editable_elements/short_text_view.js.coffee +0 -22
  137. data/app/presenters/locomotive/editable_long_text_presenter.rb +0 -5
  138. data/lib/locomotive/liquid/tags/editable/long_text.rb +0 -33
  139. data/lib/locomotive/liquid/tags/editable/short_text.rb +0 -41
  140. data/lib/locomotive/middlewares/fonts.rb +0 -42
  141. data/lib/locomotive/session_store.rb +0 -64
  142. data/spec/lib/locomotive/liquid/tags/editable/short_text_spec.rb +0 -46
  143. data/spec/models/locomotive/editable_long_text_spec.rb +0 -50
@@ -0,0 +1,85 @@
1
+ require 'spec_helper'
2
+
3
+ describe Locomotive::Liquid::Tags::Editable::Text do
4
+
5
+ let(:markup) { "'title', hint: 'Simple short text'" }
6
+ subject { build_tag }
7
+
8
+ context 'valid syntax' do
9
+
10
+ it 'does not raise an error' do
11
+ expect { subject }.to_not raise_error
12
+ end
13
+
14
+ end
15
+
16
+ context 'without a slug' do
17
+
18
+ let(:markup) { '' }
19
+
20
+ it 'requires a slug' do
21
+ expect { subject }.to raise_error(::Liquid::SyntaxError, "Syntax Error in 'editable_xxx' - Valid syntax: editable_xxx <slug>(, <options>)")
22
+ end
23
+
24
+ end
25
+
26
+ describe '.default_element_attributes' do
27
+
28
+ let(:content) { '' }
29
+ subject { build_tag('text', content).send(:default_element_attributes) }
30
+
31
+ it { should include(slug: 'title') }
32
+ it { should include(hint: 'Simple short text') }
33
+ it { should include(_type: 'Locomotive::EditableText') }
34
+ it { should include(format: 'html') }
35
+ it { should include(rows: 10) }
36
+ it { should include(line_break: true) }
37
+
38
+ describe 'default content' do
39
+
40
+ context 'only text' do
41
+
42
+ let(:content) { 'Lorem ipsum' }
43
+ it { should include(content_from_default: 'Lorem ipsum') }
44
+
45
+ end
46
+
47
+ context 'liquid tags' do
48
+
49
+ let(:content) { ['hello ', ::Liquid::Variable.new("{{ 'world' }}")] }
50
+ it { expect { subject }.to raise_error(::Liquid::SyntaxError, "Error in the default block for the title editable_element - No liquid tags are allowed inside.") }
51
+
52
+ end
53
+
54
+ end
55
+
56
+ context 'editable_short_text' do
57
+
58
+ subject { build_tag('short_text').send(:default_element_attributes) }
59
+
60
+ it { should include(format: 'raw') }
61
+ it { should include(rows: 2) }
62
+ it { should include(line_break: false) }
63
+
64
+ end
65
+
66
+ context 'editable_long_text' do
67
+
68
+ subject { build_tag('long_text').send(:default_element_attributes) }
69
+
70
+ it { should include(format: 'html') }
71
+ it { should include(rows: 15) }
72
+ it { should include(line_break: true) }
73
+
74
+ end
75
+
76
+ end
77
+
78
+ def build_tag(tag_name = 'text', content = nil)
79
+ klass = "Locomotive::Liquid::Tags::Editable::#{tag_name.camelize}".constantize
80
+ klass.new("editable_#{tag_name}", markup, ["{% endeditable_#{tag_name} %}"], {}).tap do |tag|
81
+ tag.instance_variable_set(:@nodelist, [*content]) if content
82
+ end
83
+ end
84
+
85
+ end
@@ -0,0 +1,111 @@
1
+ require 'spec_helper'
2
+
3
+ describe Locomotive::Liquid::Tags::LinkTo do
4
+
5
+ before(:each) { I18n.locale = :en }
6
+
7
+ let(:site) { FactoryGirl.create("test site") }
8
+ let(:assigns) { {} }
9
+
10
+ subject { render(template, assigns) }
11
+
12
+ context 'no page responding to the handle' do
13
+
14
+ let(:template) { "{% link_to unknown-page %}" }
15
+
16
+ it { should be_blank }
17
+
18
+ end
19
+
20
+ context 'no page responding to the handle' do
21
+
22
+ let(:assigns) { { 'project' => Locomotive::ContentEntry.new(_slug: 'hello-world', _label_field_name: :_slug ) } }
23
+ let(:template) { "{% link_to project %}" }
24
+
25
+ it { should be_blank }
26
+
27
+ end
28
+
29
+ describe 'page responding to the handle' do
30
+
31
+ let(:page) { create_page(site, 'Hello world', 'my-page') }
32
+ let(:template) { "{% link_to my-page %}" }
33
+ before(:each) { page }
34
+
35
+ it { should == %{<a href="/hello-world">Hello world</a>} }
36
+
37
+ context 'passing a page directly' do
38
+
39
+ let(:assigns) { { 'page' => page } }
40
+ let(:template) { "{% link_to page %}" }
41
+
42
+ it { should == %{<a href="/hello-world">Hello world</a>} }
43
+
44
+ end
45
+
46
+ end
47
+
48
+ describe 'templatized page' do
49
+
50
+ let(:parent_page) { create_page(site, 'List of projects') }
51
+ let(:page) { create_templatized_page(site, 'Template', 'project-template', parent_page, content_type) }
52
+ let(:content_type) { create_content_type(site, 'Projects') }
53
+ let(:content_entry) { create_content_entry(content_type, name: 'My fancy project') }
54
+ let(:assigns) { { 'project' => content_entry } }
55
+ before(:each) { page }
56
+
57
+ context 'without passing the handle' do
58
+
59
+ let(:template) { "{% link_to project %}" }
60
+
61
+ it { should == %{<a href="/list-of-projects/my-fancy-project">My fancy project</a>} }
62
+
63
+ end
64
+
65
+ context 'forcing the page' do
66
+
67
+ let(:another_parent_page) { create_page(site, 'Another list of projects') }
68
+ let(:another_page) { create_templatized_page(site, 'Template', 'another-project-template', another_parent_page, content_type) }
69
+ let(:template) { "{% link_to project, with: another-project-template %}" }
70
+ before(:each) { another_page }
71
+
72
+ it { should == %{<a href="/another-list-of-projects/my-fancy-project">My fancy project</a>} }
73
+
74
+ end
75
+
76
+ end
77
+
78
+ def render(template, assigns = {})
79
+ liquid_context = ::Liquid::Context.new({},
80
+ { 'contents' => Locomotive::Liquid::Drops::ContentTypes.new }.merge(assigns),
81
+ { site: site })
82
+ output = Liquid::Template.parse(template).render(liquid_context)
83
+ output.gsub(/\n\s{0,}/, '')
84
+ end
85
+
86
+ def create_page(site, title, handle = nil, parent = nil)
87
+ parent ||= site.pages.root.first
88
+ site.pages.create!(parent: parent, title: title, slug: title.permalink, handle: handle)
89
+ end
90
+
91
+ def create_templatized_page(site, title, handle, parent, content_type)
92
+ site.pages.create!(
93
+ parent: parent,
94
+ title: title,
95
+ handle: handle,
96
+ templatized: true,
97
+ target_klass_name: content_type.klass_with_custom_fields(:entries).to_s)
98
+ end
99
+
100
+ def create_content_type(site, name)
101
+ FactoryGirl.build(:content_type, site: site, name: name).tap do |content_type|
102
+ content_type.entries_custom_fields.build(name: 'name', type: 'string', label: 'name')
103
+ content_type.save!
104
+ end
105
+ end
106
+
107
+ def create_content_entry(content_type, attributes)
108
+ content_type.entries.create!(attributes)
109
+ end
110
+
111
+ end
@@ -10,6 +10,12 @@ describe Locomotive::Liquid::Tags::WithScope do
10
10
  attributes['title'].should == 'foo'
11
11
  attributes['hidden'].should == false
12
12
  end
13
+
14
+ it 'decodes regexps' do
15
+ scope = Locomotive::Liquid::Tags::WithScope.new('with_scope', 'title: /Like this one|or this one/', ["{% endwith_scope %}"], {})
16
+ attributes = scope.send(:decode, scope.instance_variable_get(:@attributes), ::Liquid::Context.new)
17
+ attributes['title'].should == /Like this one|or this one/
18
+ end
13
19
 
14
20
  it 'decodes context variable' do
15
21
  scope = Locomotive::Liquid::Tags::WithScope.new('with_scope', 'category: params.type', ["{% endwith_scope %}"], {})
@@ -37,7 +37,7 @@ describe Locomotive::ContentEntry do
37
37
 
38
38
  end
39
39
 
40
- describe '#slug' do
40
+ describe '.slug' do
41
41
 
42
42
  before :each do
43
43
  build_content_entry(_slug: 'dogs').tap(&:save!)._slug.should == 'dogs'
@@ -73,6 +73,12 @@ describe Locomotive::ContentEntry do
73
73
  build_content_entry(_slug: 'dogs').tap(&:save!)._slug.should == "dogs-#{i}"
74
74
  end
75
75
  end
76
+
77
+ it 'copies the slug in ALL the locales of the site' do
78
+ Locomotive::Site.any_instance.stubs(:locales).returns(%w(en fr ru))
79
+ entry = build_content_entry(_slug: 'monkeys').tap(&:save!)
80
+ entry._slug_translations.should == { 'en' => 'monkeys', 'fr' => 'monkeys', 'ru' => 'monkeys' }
81
+ end
76
82
  end
77
83
 
78
84
  describe '#I18n' do
@@ -81,6 +87,7 @@ describe Locomotive::ContentEntry do
81
87
  localize_content_type @content_type
82
88
  ::Mongoid::Fields::I18n.locale = 'en'
83
89
  @content_entry = build_content_entry(title: 'Hello world')
90
+ @content_entry.send(:set_slug)
84
91
  ::Mongoid::Fields::I18n.locale = 'fr'
85
92
  end
86
93
 
@@ -94,6 +101,19 @@ describe Locomotive::ContentEntry do
94
101
  @content_entry.translated?.should be_true
95
102
  end
96
103
 
104
+ describe '.slug' do
105
+
106
+ it 'is not nil in the default locale' do
107
+ ::Mongoid::Fields::I18n.locale = 'en'
108
+ @content_entry._slug.should == 'hello-world'
109
+ end
110
+
111
+ it 'is not translated by default in the other locale' do
112
+ @content_entry._slug.should be_nil # French
113
+ end
114
+
115
+ end
116
+
97
117
  end
98
118
 
99
119
  describe 'csv' do
@@ -108,17 +128,17 @@ describe Locomotive::ContentEntry do
108
128
 
109
129
  subject { build_content_entry.to_values(host: 'example.com') }
110
130
 
111
- its(:size) { should eq(4) }
131
+ its(:size) { should eq(5) }
112
132
 
113
133
  its(:first) { should eq('Locomotive') }
114
134
 
115
- its(:last) { should eq('') }
135
+ its(:last) { should eq('July 05, 2013 00:00') }
116
136
 
117
137
  context 'with a file' do
118
138
 
119
- subject { build_content_entry(file: FixturedAsset.open('5k.png')).tap(&:save).to_values(host: 'example.com') }
139
+ subject { build_content_entry(file: FixturedAsset.open('5k.png')).tap(&:save).to_values(host: 'example.com')[3] }
120
140
 
121
- its(:last) { should match(/^http:\/\/example.com\/sites\/[0-9a-f]+\/content_entry[0-9a-f]+\/[0-9a-f]+\/files\/5k.png$/) }
141
+ it { should match(/^http:\/\/example.com\/sites\/[0-9a-f]+\/content_entry[0-9a-f]+\/[0-9a-f]+\/files\/5k.png$/) }
122
142
 
123
143
  end
124
144
 
@@ -160,12 +180,12 @@ describe Locomotive::ContentEntry do
160
180
 
161
181
  it 'should find previous item when available' do
162
182
  @second.previous.title.should == 'first'
163
- @second.previous._position.should == 1
183
+ @second.previous._position.should == 0
164
184
  end
165
185
 
166
186
  it 'should find next item when available' do
167
187
  @second.next.title.should == 'third'
168
- @second.next._position.should == 3
188
+ @second.next._position.should == 2
169
189
  end
170
190
 
171
191
  it 'should return nil when fetching previous item on first in list' do
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Locomotive::EditableShortText do
3
+ describe Locomotive::EditableText do
4
4
 
5
5
  describe 'a simple case' do
6
6
 
@@ -8,7 +8,7 @@ describe Locomotive::EditableShortText do
8
8
  @site = FactoryGirl.create(:site)
9
9
  @home = @site.pages.root.first
10
10
 
11
- @home.update_attributes raw_template: "{% block body %}{% editable_short_text 'body' %}Lorem ipsum{% endeditable_short_text %}{% endblock %}"
11
+ @home.update_attributes raw_template: "{% block body %}{% editable_text 'body' %}Lorem ipsum{% endeditable_text %}{% endblock %}"
12
12
 
13
13
  @sub_page_1 = FactoryGirl.create(:page, slug: 'sub_page_1', parent: @home, raw_template: "{% extends 'parent' %}")
14
14
  @sub_page_2 = FactoryGirl.create(:page, slug: 'sub_page_2', parent: @home, raw_template: "{% extends 'parent' %}")
@@ -18,7 +18,34 @@ describe Locomotive::EditableShortText do
18
18
  @sub_page_1_1 = FactoryGirl.create(:page, slug: 'sub_page_1_1', parent: @sub_page_1, raw_template: "{% extends 'parent' %}")
19
19
  end
20
20
 
21
- context '#locales' do
21
+ describe 'properties' do
22
+
23
+ it 'exists' do
24
+ @sub_page_1.editable_elements.size.should == 1
25
+ end
26
+
27
+ it 'has a non-nil slug' do
28
+ @sub_page_1.editable_elements.first.slug.should == 'body'
29
+ end
30
+
31
+ it 'has a default content at first' do
32
+ @sub_page_1.editable_elements.first.default_content.should be_true
33
+ @sub_page_1.editable_elements.first.content.should == 'Lorem ipsum'
34
+ end
35
+
36
+ it 'is still default when it gets modified by the exact same value' do
37
+ @sub_page_1.editable_elements.first.content = 'Lorem ipsum'
38
+ @sub_page_1.editable_elements.first.default_content.should be_true
39
+ end
40
+
41
+ it 'strips the content' do
42
+ @sub_page_1.editable_elements.first.update_attribute :content, " Lorem ipsum\n\n "
43
+ @sub_page_1.editable_elements.first.content.should == 'Lorem ipsum'
44
+ end
45
+
46
+ end
47
+
48
+ describe 'locales' do
22
49
 
23
50
  it 'assigns the default locale' do
24
51
  @sub_page_1_el.locales.should == ['en']
@@ -35,7 +62,7 @@ describe Locomotive::EditableShortText do
35
62
 
36
63
  it 'adds new locale within sub page elements' do
37
64
  ::Mongoid::Fields::I18n.with_locale 'fr' do
38
- @home.update_attributes title: 'Accueil', raw_template: "{% block body %}{% editable_short_text 'body' %}Lorem ipsum{% endeditable_short_text %}{% endblock %}"
65
+ @home.update_attributes title: 'Accueil', raw_template: "{% block body %}{% editable_text 'body' %}Lorem ipsum{% endeditable_text %}{% endblock %}"
39
66
  page = Locomotive::Page.find(@sub_page_1._id)
40
67
  page.editable_elements.first.content = 'Lorem ipsum (FR)'
41
68
  page.save
@@ -45,7 +72,25 @@ describe Locomotive::EditableShortText do
45
72
 
46
73
  end
47
74
 
48
- context '#editable?' do
75
+ describe 'when modifying the raw template' do
76
+
77
+ it 'can update its content from the raw template if the user has not modified it' do
78
+ @home.update_attributes raw_template: "{% block body %}{% editable_text 'body' %}Lorem ipsum v2{% endeditable_text %}{% endblock %}"
79
+ @home.editable_elements.first.default_content.should be_true
80
+ @home.editable_elements.first.content.should == 'Lorem ipsum v2'
81
+ end
82
+
83
+ it 'does not touch the content if the user has modified it before' do
84
+ @home.editable_elements.first.content = 'Hello world'
85
+ @home.raw_template = "{% block body %}{% editable_text 'body' %}Lorem ipsum v2{% endeditable_text %}{% endblock %}"
86
+ @home.save
87
+ @home.editable_elements.first.default_content.should be_false
88
+ @home.editable_elements.first.content.should == 'Hello world'
89
+ end
90
+
91
+ end
92
+
93
+ describe '.editable?' do
49
94
 
50
95
  it 'is editable' do
51
96
  @sub_page_1_el.editable?.should be_true
@@ -78,7 +123,7 @@ describe Locomotive::EditableShortText do
78
123
 
79
124
  end
80
125
 
81
- context 'in sub pages level #1' do
126
+ describe 'in sub pages level #1' do
82
127
 
83
128
  before(:each) do
84
129
  @sub_page_1.reload
@@ -101,7 +146,7 @@ describe Locomotive::EditableShortText do
101
146
 
102
147
  end
103
148
 
104
- context 'in sub pages level #2' do
149
+ describe 'in sub pages level #2' do
105
150
 
106
151
  before(:each) do
107
152
  @sub_page_1_1.reload
@@ -131,7 +176,7 @@ describe Locomotive::EditableShortText do
131
176
  @site = FactoryGirl.create(:site)
132
177
  @home = @site.pages.root.first
133
178
 
134
- @home.update_attributes raw_template: "{% block body %}{% editable_short_text 'body', fixed: true %}Lorem ipsum{% endeditable_short_text %}{% endblock %}"
179
+ @home.update_attributes raw_template: "{% block body %}{% editable_text 'body', fixed: true %}Lorem ipsum{% endeditable_text %}{% endblock %}"
135
180
  @home_el = @home.editable_elements.first
136
181
 
137
182
  @sub_page_1 = FactoryGirl.create(:page, slug: 'sub_page_1', parent: @home, raw_template: "{% extends 'parent' %}")
@@ -6,7 +6,7 @@ describe Locomotive::Extensions::Page::EditableElements do
6
6
  @site = FactoryGirl.create(:site)
7
7
  @home = @site.pages.root.first
8
8
 
9
- @home.update_attributes raw_template: "{% editable_short_text 'body' %}Lorem ipsum{% endeditable_short_text %}"
9
+ @home.update_attributes raw_template: "{% editable_text 'body' %}Lorem ipsum{% endeditable_text %}"
10
10
 
11
11
  @sub_page_1 = FactoryGirl.create(:page, slug: 'sub_page_1', parent: @home, raw_template: "{% extends 'parent' %}")
12
12
  @sub_page_2 = FactoryGirl.create(:page, slug: 'sub_page_2', parent: @home, raw_template: "{% extends 'parent' %}")
@@ -23,15 +23,15 @@ describe Locomotive::Extensions::Page::EditableElements do
23
23
  end
24
24
 
25
25
  it 'changes the type of the element in all the children' do
26
- @home.update_attributes raw_template: "{% editable_long_text 'body' %}Lorem ipsum{% endeditable_long_text %}"
26
+ @home.update_attributes raw_template: "{% editable_file 'body' %}/nowhere.pdf{% endeditable_file %}"
27
27
  @sub_page_1.reload
28
- @sub_page_1.editable_elements.first._type.should == 'Locomotive::EditableLongText'
28
+ @sub_page_1.editable_elements.first._type.should == 'Locomotive::EditableFile'
29
29
  @sub_page_1_1.reload
30
- @sub_page_1_1.editable_elements.first._type.should == 'Locomotive::EditableLongText'
30
+ @sub_page_1_1.editable_elements.first._type.should == 'Locomotive::EditableFile'
31
31
  end
32
32
 
33
33
  it 'changes the hint of the element in all the children' do
34
- @home.update_attributes raw_template: "{% editable_long_text 'body', hint: 'My very useful hint' %}Lorem ipsum{% endeditable_long_text %}"
34
+ @home.update_attributes raw_template: "{% editable_text 'body', hint: 'My very useful hint' %}Lorem ipsum{% endeditable_text %}"
35
35
  @sub_page_1.reload
36
36
  @sub_page_1.editable_elements.first.hint.should == 'My very useful hint'
37
37
  @sub_page_1_1.reload
@@ -44,7 +44,7 @@ describe Locomotive::Extensions::Page::EditableElements do
44
44
 
45
45
  it 'does not remove the editable elements in other locales' do
46
46
  Mongoid::Fields::I18n.with_locale(:fr) do
47
- @home.update_attributes raw_template: "{% editable_short_text 'corps' %}Lorem ipsum{% endeditable_short_text %}"
47
+ @home.update_attributes raw_template: "{% editable_text 'corps' %}Lorem ipsum{% endeditable_text %}"
48
48
  end
49
49
  @home.reload
50
50
  @home.editable_elements.count.should == 2
@@ -107,54 +107,74 @@ describe Locomotive::Site do
107
107
 
108
108
  describe 'once created' do
109
109
 
110
- before(:each) do
111
- @site = FactoryGirl.create(:site)
112
- end
110
+ let(:site) { FactoryGirl.create(:site, locales: locales) }
113
111
 
114
- it 'should create index and 404 pages' do
115
- @site.pages.size.should == 2
116
- @site.pages.map(&:fullpath).sort.should == %w{404 index}
117
- end
112
+ context 'the default locale is fr' do
118
113
 
119
- it 'translates the index/404 pages if a new locale is added' do
120
- @site.update_attributes locales: %w(en fr)
114
+ let(:locales) { ['fr'] }
121
115
 
122
- @site.errors.should be_empty
116
+ it 'creates the index and 404 pages' do
117
+ site.pages.size.should == 2
123
118
 
124
- ::Mongoid::Fields::I18n.with_locale('fr') do
125
- @site.pages.root.first.tap do |page|
126
- page.title.should == "Page d'accueil"
127
- page.slug.should == 'index'
128
- end
119
+ site.pages.map(&:fullpath).sort.should == [nil, nil]
129
120
 
130
- @site.pages.not_found.first.tap do |page|
131
- page.title.should == 'Page non trouvée'
132
- page.slug.should == '404'
121
+ ::Mongoid::Fields::I18n.with_locale('fr') do
122
+ site.pages.map(&:fullpath).sort.should == %w{404 index}
133
123
  end
134
124
  end
125
+
135
126
  end
136
127
 
137
- it 'translates the index/404 pages if the default locale changes' do
138
- @site.update_attributes locales: %w(fr en)
128
+ context 'the default locale is en' do
129
+
130
+ let(:locales) { ['en'] }
131
+
132
+ it 'should create the index and 404 pages' do
133
+ site.pages.size.should == 2
134
+ site.pages.map(&:fullpath).sort.should == %w{404 index}
135
+ end
136
+
137
+ it 'translates the index/404 pages if a new locale is added' do
138
+ site.update_attributes locales: %w(en fr)
139
+
140
+ site.errors.should be_empty
139
141
 
140
- @site.errors.should be_empty
142
+ ::Mongoid::Fields::I18n.with_locale('fr') do
143
+ site.pages.root.first.tap do |page|
144
+ page.title.should == "Page d'accueil"
145
+ page.slug.should == 'index'
146
+ end
141
147
 
142
- ::Mongoid::Fields::I18n.with_locale('fr') do
143
- @site.pages.root.first.tap do |page|
144
- page.title.should == "Page d'accueil"
145
- page.slug.should == 'index'
148
+ site.pages.not_found.first.tap do |page|
149
+ page.title.should == 'Page non trouvée'
150
+ page.slug.should == '404'
151
+ end
146
152
  end
153
+ end
154
+
155
+ it 'translates the index/404 pages if the default locale changes' do
156
+ site.update_attributes locales: %w(fr en)
157
+
158
+ site.errors.should be_empty
147
159
 
148
- @site.pages.not_found.first.tap do |page|
149
- page.title.should == 'Page non trouvée'
150
- page.slug.should == '404'
160
+ ::Mongoid::Fields::I18n.with_locale('fr') do
161
+ site.pages.root.first.tap do |page|
162
+ page.title.should == "Page d'accueil"
163
+ page.slug.should == 'index'
164
+ end
165
+
166
+ site.pages.not_found.first.tap do |page|
167
+ page.title.should == 'Page non trouvée'
168
+ page.slug.should == '404'
169
+ end
151
170
  end
152
171
  end
153
- end
154
172
 
155
- it 'does not allow to remove the default locale' do
156
- @site.update_attributes locales: %w(fr)
157
- @site.errors[:locales].should == ['The previous default locale can not be removed right away.']
173
+ it 'does not allow to remove the default locale' do
174
+ site.update_attributes locales: %w(fr)
175
+ site.errors[:locales].should == ['The previous default locale can not be removed right away.']
176
+ end
177
+
158
178
  end
159
179
 
160
180
  end