alchemy_cms 3.0.4 → 3.1.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -6
- data/Gemfile +4 -7
- data/README.md +207 -115
- data/alchemy_cms.gemspec +10 -9
- data/app/assets/javascripts/alchemy/alchemy.dragndrop.js.coffee +2 -2
- data/app/assets/javascripts/alchemy/alchemy.image_cropper.js.coffee +2 -2
- data/app/assets/javascripts/alchemy/alchemy.js +6 -7
- data/app/assets/javascripts/alchemy/alchemy.translations.js.coffee +1 -43
- data/app/assets/javascripts/alchemy/alchemy.uploader.js.coffee +1 -1
- data/app/assets/stylesheets/alchemy/_mixins.scss +2 -1
- data/app/assets/stylesheets/alchemy/buttons.scss +0 -5
- data/app/assets/stylesheets/alchemy/dialogs.scss +1 -0
- data/app/assets/stylesheets/alchemy/frame.scss +9 -12
- data/app/assets/stylesheets/tinymce/skins/alchemy/content.min.css.scss +11 -2
- data/app/assets/stylesheets/tinymce/skins/alchemy/skin.min.css.scss +9 -1
- data/app/controllers/alchemy/admin/attachments_controller.rb +2 -4
- data/app/controllers/alchemy/admin/essence_pictures_controller.rb +34 -38
- data/app/controllers/alchemy/api/base_controller.rb +19 -0
- data/app/controllers/alchemy/api/contents_controller.rb +35 -0
- data/app/controllers/alchemy/api/elements_controller.rb +29 -0
- data/app/controllers/alchemy/api/pages_controller.rb +32 -0
- data/app/controllers/alchemy/contents_controller.rb +1 -0
- data/app/controllers/alchemy/elements_controller.rb +5 -2
- data/app/controllers/alchemy/pages_controller.rb +4 -1
- data/app/controllers/alchemy/pictures_controller.rb +4 -36
- data/app/helpers/alchemy/admin/essences_helper.rb +5 -2
- data/app/helpers/alchemy/essences_helper.rb +14 -1
- data/app/models/alchemy/content.rb +32 -4
- data/app/models/alchemy/element.rb +2 -16
- data/app/models/alchemy/element/presenters.rb +2 -2
- data/app/models/alchemy/essence_file.rb +5 -0
- data/app/models/alchemy/essence_picture.rb +12 -8
- data/app/models/alchemy/picture.rb +1 -74
- data/app/models/alchemy/picture/transformations.rb +249 -0
- data/app/serializers/alchemy/content_serializer.rb +3 -10
- data/app/serializers/alchemy/element_serializer.rb +6 -3
- data/app/serializers/alchemy/legacy_element_serializer.rb +17 -0
- data/app/views/alchemy/admin/dashboard/_sites.html.erb +14 -4
- data/app/views/alchemy/admin/essence_pictures/crop.html.erb +8 -5
- data/app/views/alchemy/admin/pages/edit.html.erb +9 -9
- data/app/views/alchemy/admin/pictures/info.html.erb +2 -3
- data/app/views/alchemy/admin/tags/edit.html.erb +1 -1
- data/app/views/alchemy/essences/_essence_boolean_editor.html.erb +8 -7
- data/app/views/alchemy/essences/_essence_boolean_view.html.erb +3 -3
- data/app/views/alchemy/essences/_essence_date_editor.html.erb +8 -2
- data/app/views/alchemy/essences/_essence_date_view.html.erb +10 -8
- data/app/views/alchemy/essences/_essence_file_editor.html.erb +48 -53
- data/app/views/alchemy/essences/_essence_file_view.html.erb +5 -5
- data/app/views/alchemy/essences/_essence_html_editor.html.erb +5 -4
- data/app/views/alchemy/essences/_essence_link_editor.html.erb +17 -15
- data/app/views/alchemy/essences/_essence_link_view.html.erb +11 -7
- data/app/views/alchemy/essences/_essence_picture_editor.html.erb +4 -2
- data/app/views/alchemy/essences/_essence_picture_view.html.erb +4 -2
- data/app/views/alchemy/essences/_essence_richtext_view.html.erb +5 -4
- data/app/views/alchemy/essences/_essence_select_editor.html.erb +22 -32
- data/app/views/alchemy/essences/_essence_text_view.html.erb +7 -6
- data/app/views/alchemy/essences/shared/_essence_picture_tools.html.erb +1 -1
- data/app/views/layouts/alchemy/admin.html.erb +5 -3
- data/config/initializers/inflections.rb +3 -0
- data/config/initializers/simple_form.rb +1 -1
- data/config/locales/alchemy.en.yml +0 -1
- data/config/routes.rb +14 -0
- data/lib/alchemy/capistrano.rb +71 -0
- data/lib/alchemy/engine.rb +0 -3
- data/lib/alchemy/essence.rb +1 -1
- data/lib/alchemy/permissions.rb +19 -5
- data/lib/alchemy/picture_attributes.rb +1 -1
- data/lib/alchemy/test_support/auth_helpers.rb +1 -1
- data/lib/alchemy/test_support/essence_shared_examples.rb +37 -22
- data/lib/alchemy/test_support/integration_helpers.rb +1 -1
- data/lib/alchemy/tinymce.rb +21 -4
- data/lib/alchemy/upgrader/three_point_one.rb +43 -0
- data/lib/alchemy/upgrader/three_point_zero.rb +13 -0
- data/lib/alchemy/version.rb +2 -1
- data/lib/rails/generators/alchemy/module/module_generator.rb +30 -0
- data/lib/rails/generators/alchemy/module/templates/ability.rb.tt +11 -0
- data/lib/rails/generators/alchemy/module/templates/controller.rb.tt +2 -0
- data/lib/rails/generators/alchemy/module/templates/module_config.rb.tt +15 -0
- data/lib/rails/generators/alchemy/scaffold/scaffold_generator.rb +0 -1
- data/lib/rails/templates/alchemy.rb +2 -2
- data/lib/tasks/alchemy/db.rake +7 -1
- data/spec/controllers/admin/attachments_controller_spec.rb +38 -38
- data/spec/controllers/admin/base_controller_spec.rb +18 -18
- data/spec/controllers/admin/clipboard_controller_spec.rb +23 -18
- data/spec/controllers/admin/contents_controller_spec.rb +33 -27
- data/spec/controllers/admin/dashboard_controller_spec.rb +14 -14
- data/spec/controllers/admin/elements_controller_spec.rb +125 -105
- data/spec/controllers/admin/essence_files_controller_spec.rb +6 -7
- data/spec/controllers/admin/essence_pictures_controller_spec.rb +52 -42
- data/spec/controllers/admin/languages_controller_spec.rb +3 -3
- data/spec/controllers/admin/pages_controller_spec.rb +81 -71
- data/spec/controllers/admin/pictures_controller_spec.rb +69 -72
- data/spec/controllers/admin/resources_controller_spec.rb +5 -5
- data/spec/controllers/admin/trash_controller_spec.rb +15 -12
- data/spec/controllers/alchemy/admin/tags_controller_spec.rb +8 -8
- data/spec/controllers/alchemy/api/contents_controller_spec.rb +73 -0
- data/spec/controllers/alchemy/api/elements_controller_spec.rb +69 -0
- data/spec/controllers/alchemy/api/pages_controller_spec.rb +86 -0
- data/spec/controllers/attachments_controller_spec.rb +8 -8
- data/spec/controllers/contents_controller_spec.rb +22 -0
- data/spec/controllers/elements_controller_spec.rb +10 -4
- data/spec/controllers/messages_controller_spec.rb +35 -34
- data/spec/controllers/pages_controller_spec.rb +37 -28
- data/spec/controllers/pictures_controller_spec.rb +90 -23
- data/spec/dummy/app/models/dummy_user.rb +0 -4
- data/spec/dummy/app/views/alchemy/elements/_all_you_can_eat_editor.html.erb +11 -0
- data/spec/dummy/config/alchemy/elements.yml +22 -1
- data/spec/dummy/config/alchemy/page_layouts.yml +4 -0
- data/spec/dummy/config/application.rb +2 -1
- data/spec/dummy/config/environments/test.rb +3 -1
- data/spec/features/admin/dashboard_spec.rb +41 -6
- data/spec/features/admin/language_tree_feature_spec.rb +3 -3
- data/spec/features/admin/legacy_page_url_management_spec.rb +1 -1
- data/spec/features/admin/link_overlay_spec.rb +7 -7
- data/spec/features/admin/locale_select_feature_spec.rb +5 -2
- data/spec/features/admin/modules_integration_spec.rb +1 -1
- data/spec/features/admin/page_creation_feature_spec.rb +3 -2
- data/spec/features/admin/page_editing_feature_spec.rb +66 -79
- data/spec/features/admin/picture_library_integration_spec.rb +8 -8
- data/spec/features/admin/resources_integration_spec.rb +21 -21
- data/spec/features/admin/tinymce_feature_spec.rb +36 -0
- data/spec/features/navigation_spec.rb +1 -1
- data/spec/features/page_feature_spec.rb +34 -34
- data/spec/features/picture_security_spec.rb +4 -4
- data/spec/features/security_spec.rb +1 -1
- data/spec/features/translation_integration_spec.rb +7 -7
- data/spec/helpers/admin/base_helper_spec.rb +51 -49
- data/spec/helpers/admin/contents_helper_spec.rb +11 -11
- data/spec/helpers/admin/elements_helper_spec.rb +20 -17
- data/spec/helpers/admin/essences_helper_spec.rb +42 -11
- data/spec/helpers/admin/navigation_helper_spec.rb +64 -54
- data/spec/helpers/admin/pages_helper_spec.rb +10 -10
- data/spec/helpers/admin/tags_helper_spec.rb +16 -16
- data/spec/helpers/base_helper_spec.rb +11 -11
- data/spec/helpers/elements_block_helper_spec.rb +24 -24
- data/spec/helpers/elements_helper_spec.rb +46 -46
- data/spec/helpers/essences_helper_spec.rb +90 -17
- data/spec/helpers/pages_helper_spec.rb +53 -53
- data/spec/helpers/picture_url_helpers_spec.rb +6 -6
- data/spec/helpers/url_helper_spec.rb +32 -32
- data/spec/libraries/config_spec.rb +9 -9
- data/spec/libraries/controller_actions_spec.rb +14 -14
- data/spec/libraries/i18n_spec.rb +6 -6
- data/spec/libraries/kaminari/scoped_pagination_url_helper_spec.rb +4 -4
- data/spec/libraries/modules_spec.rb +4 -4
- data/spec/libraries/mount_point_spec.rb +13 -13
- data/spec/libraries/page_layout_spec.rb +24 -24
- data/spec/libraries/permissions_spec.rb +97 -80
- data/spec/libraries/resource_spec.rb +37 -37
- data/spec/libraries/resources_helper_spec.rb +19 -19
- data/spec/libraries/shell_spec.rb +17 -17
- data/spec/libraries/template_tracker_spec.rb +14 -14
- data/spec/libraries/tinymce_spec.rb +8 -8
- data/spec/libraries/userstamp_spec.rb +2 -2
- data/spec/mailers/messages_spec.rb +4 -4
- data/spec/models/attachment_spec.rb +86 -30
- data/spec/models/cell_spec.rb +10 -10
- data/spec/models/content_spec.rb +106 -46
- data/spec/models/element_spec.rb +94 -115
- data/spec/models/essence_date_spec.rb +1 -1
- data/spec/models/essence_file_spec.rb +4 -4
- data/spec/models/essence_picture_spec.rb +56 -25
- data/spec/models/essence_richtext_spec.rb +1 -1
- data/spec/models/essence_text_spec.rb +7 -7
- data/spec/models/language_spec.rb +12 -12
- data/spec/models/legacy_page_url_spec.rb +2 -2
- data/spec/models/message_spec.rb +12 -5
- data/spec/models/page_spec.rb +259 -235
- data/spec/models/picture_spec.rb +72 -166
- data/spec/models/site_spec.rb +41 -41
- data/spec/models/tag_spec.rb +7 -7
- data/spec/routing/api_routing_spec.rb +150 -0
- data/spec/routing/routing_spec.rb +28 -28
- data/spec/spec_helper.rb +6 -5
- data/spec/support/hint_examples.rb +5 -5
- data/spec/support/transformation_examples.rb +173 -0
- data/spec/tasks/helpers_spec.rb +29 -29
- data/spec/views/essences/essence_boolean_editor_spec.rb +32 -0
- data/spec/views/essences/essence_boolean_view_spec.rb +2 -2
- data/spec/views/essences/essence_date_view_spec.rb +1 -1
- data/spec/views/essences/essence_link_view_spec.rb +11 -0
- data/spec/views/essences/essence_picture_view_spec.rb +56 -11
- data/spec/views/essences/essence_richtext_view_spec.rb +12 -0
- data/spec/views/essences/essence_text_view_spec.rb +12 -0
- data/vendor/assets/javascripts/tinymce/langs/de.js +20 -2
- data/vendor/assets/javascripts/tinymce/langs/fr.js +14 -1
- data/vendor/assets/javascripts/tinymce/langs/nl.js +22 -4
- data/vendor/assets/javascripts/tinymce/plugins/anchor/plugin.min.js +1 -1
- data/vendor/assets/javascripts/tinymce/plugins/autoresize/plugin.min.js +1 -1
- data/vendor/assets/javascripts/tinymce/plugins/charmap/plugin.min.js +1 -1
- data/vendor/assets/javascripts/tinymce/plugins/code/plugin.min.js +1 -1
- data/vendor/assets/javascripts/tinymce/plugins/directionality/plugin.min.js +1 -1
- data/vendor/assets/javascripts/tinymce/plugins/fullscreen/plugin.min.js +1 -1
- data/vendor/assets/javascripts/tinymce/plugins/hr/plugin.min.js +1 -1
- data/vendor/assets/javascripts/tinymce/plugins/link/plugin.min.js +1 -1
- data/vendor/assets/javascripts/tinymce/plugins/paste/plugin.min.js +1 -1
- data/vendor/assets/javascripts/tinymce/plugins/tabfocus/plugin.min.js +1 -1
- data/vendor/assets/javascripts/tinymce/plugins/table/plugin.min.js +1 -1
- data/vendor/assets/javascripts/tinymce/themes/modern/theme.min.js +1 -1
- data/vendor/assets/javascripts/tinymce/tinymce.min.js +11 -10
- metadata +72 -42
- data/app/views/alchemy/messages/contact_form_mail.es.text.erb +0 -12
- data/config/locales/alchemy.es.yml +0 -958
- data/config/locales/alchemy.ru.yml +0 -837
- data/config/locales/simple_form.es.yml +0 -6
- data/config/locales/simple_form.ru.yml +0 -25
- data/lib/rails/generators/alchemy/scaffold/files/alchemy.es.yml +0 -31
- data/vendor/assets/javascripts/tinymce/langs/es.js +0 -197
- data/vendor/assets/javascripts/tinymce/langs/ru.js +0 -197
data/spec/models/content_spec.rb
CHANGED
@@ -2,24 +2,24 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
module Alchemy
|
4
4
|
describe Content do
|
5
|
-
let(:element) {
|
5
|
+
let(:element) { create(:element, name: 'headline', :create_contents_after_create => true) }
|
6
6
|
let(:content) { element.contents.find_by_essence_type('Alchemy::EssenceText') }
|
7
7
|
|
8
8
|
it "should return the ingredient from its essence" do
|
9
9
|
content.essence.update_attributes(:body => "Hello")
|
10
|
-
content.ingredient.
|
10
|
+
expect(content.ingredient).to eq("Hello")
|
11
11
|
end
|
12
12
|
|
13
13
|
describe '.normalize_essence_type' do
|
14
14
|
context "passing namespaced essence type" do
|
15
15
|
it "should not add alchemy namespace" do
|
16
|
-
Content.normalize_essence_type('Alchemy::EssenceText').
|
16
|
+
expect(Content.normalize_essence_type('Alchemy::EssenceText')).to eq("Alchemy::EssenceText")
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
context "passing not namespaced essence type" do
|
21
21
|
it "should add alchemy namespace" do
|
22
|
-
Content.normalize_essence_type('EssenceText').
|
22
|
+
expect(Content.normalize_essence_type('EssenceText')).to eq("Alchemy::EssenceText")
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
@@ -27,13 +27,13 @@ module Alchemy
|
|
27
27
|
describe '#normalized_essence_type' do
|
28
28
|
context "without namespace in essence_type column" do
|
29
29
|
it "should return the namespaced essence type" do
|
30
|
-
Content.new(:essence_type => 'EssenceText').normalized_essence_type.
|
30
|
+
expect(Content.new(:essence_type => 'EssenceText').normalized_essence_type).to eq('Alchemy::EssenceText')
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
34
|
context "with namespace in essence_type column" do
|
35
35
|
it "should return the namespaced essence type" do
|
36
|
-
Content.new(:essence_type => 'Alchemy::EssenceText').normalized_essence_type.
|
36
|
+
expect(Content.new(:essence_type => 'Alchemy::EssenceText').normalized_essence_type).to eq('Alchemy::EssenceText')
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
@@ -49,15 +49,17 @@ module Alchemy
|
|
49
49
|
let(:params) { {body: 'Mikes Petshop'} }
|
50
50
|
let(:essence) { content.essence }
|
51
51
|
|
52
|
-
before
|
52
|
+
before do
|
53
|
+
expect(essence).to receive(:content).at_least(:once).and_return content
|
54
|
+
end
|
53
55
|
|
54
56
|
it "updates the attributes of related essence and return true" do
|
55
|
-
|
56
|
-
content.ingredient.
|
57
|
+
is_expected.to be_truthy
|
58
|
+
expect(content.ingredient).to eq("Mikes Petshop")
|
57
59
|
end
|
58
60
|
|
59
61
|
it "updates timestamp after updating related essence" do
|
60
|
-
content.
|
62
|
+
expect(content).to receive(:touch)
|
61
63
|
subject
|
62
64
|
end
|
63
65
|
end
|
@@ -66,14 +68,14 @@ module Alchemy
|
|
66
68
|
let(:element) { create(:element, name: 'contactform', create_contents_after_create: true) }
|
67
69
|
|
68
70
|
it "should add error messages if save fails and return false" do
|
69
|
-
|
70
|
-
content.errors[:essence].
|
71
|
+
is_expected.to be_falsey
|
72
|
+
expect(content.errors[:essence].size).to eq(1)
|
71
73
|
end
|
72
74
|
end
|
73
75
|
|
74
76
|
context 'if essence is missing' do
|
75
77
|
before do
|
76
|
-
content.
|
78
|
+
expect(content).to receive(:essence).and_return nil
|
77
79
|
end
|
78
80
|
|
79
81
|
it "should raise error" do
|
@@ -90,12 +92,12 @@ module Alchemy
|
|
90
92
|
|
91
93
|
it "should create a new record with all attributes of source except given differences" do
|
92
94
|
copy = Content.copy(@content, {:name => 'foobar', :element_id => @element.id + 1})
|
93
|
-
copy.name.
|
95
|
+
expect(copy.name).to eq('foobar')
|
94
96
|
end
|
95
97
|
|
96
98
|
it "should make a new record for essence of source" do
|
97
99
|
copy = Content.copy(@content, {:element_id => @element.id + 1})
|
98
|
-
copy.essence_id.
|
100
|
+
expect(copy.essence_id).not_to eq(@content.essence_id)
|
99
101
|
end
|
100
102
|
|
101
103
|
it "should copy source essence attributes" do
|
@@ -108,7 +110,7 @@ module Alchemy
|
|
108
110
|
let(:element) { FactoryGirl.build_stubbed(:element) }
|
109
111
|
|
110
112
|
it "builds a new instance from elements.yml description" do
|
111
|
-
Content.build(element, {name: 'headline'}).
|
113
|
+
expect(Content.build(element, {name: 'headline'})).to be_instance_of(Content)
|
112
114
|
end
|
113
115
|
end
|
114
116
|
|
@@ -117,14 +119,14 @@ module Alchemy
|
|
117
119
|
|
118
120
|
context "with blank name key" do
|
119
121
|
it "returns a essence hash build from essence type" do
|
120
|
-
Content.
|
122
|
+
expect(Content).to receive(:content_description_from_essence_type).with(element, 'EssenceText')
|
121
123
|
Content.content_description(element, essence_type: 'EssenceText')
|
122
124
|
end
|
123
125
|
end
|
124
126
|
|
125
127
|
context "with name key present" do
|
126
128
|
it "returns a essence hash from element" do
|
127
|
-
Content.
|
129
|
+
expect(Content).to receive(:content_description_from_element).with(element, 'headline')
|
128
130
|
Content.content_description(element, name: 'headline')
|
129
131
|
end
|
130
132
|
end
|
@@ -135,18 +137,18 @@ module Alchemy
|
|
135
137
|
let(:essence) { {name: 'headline', type: 'EssenceText'} }
|
136
138
|
|
137
139
|
it "returns the description hash from element" do
|
138
|
-
element.
|
139
|
-
Content.content_description(element, name: 'headline').
|
140
|
+
expect(element).to receive(:content_description_for).and_return(essence)
|
141
|
+
expect(Content.content_description(element, name: 'headline')).to eq(essence)
|
140
142
|
end
|
141
143
|
|
142
144
|
context "with content description not found" do
|
143
145
|
before {
|
144
|
-
element.
|
145
|
-
element.
|
146
|
+
expect(element).to receive(:content_description_for).and_return(nil)
|
147
|
+
expect(element).to receive(:available_content_description_for).and_return(essence)
|
146
148
|
}
|
147
149
|
|
148
150
|
it "returns the description hash from available contents" do
|
149
|
-
Content.content_description(element, name: 'headline').
|
151
|
+
expect(Content.content_description(element, name: 'headline')).to eq(essence)
|
150
152
|
end
|
151
153
|
end
|
152
154
|
end
|
@@ -155,11 +157,11 @@ module Alchemy
|
|
155
157
|
let(:element) { FactoryGirl.build_stubbed(:element) }
|
156
158
|
|
157
159
|
it "returns the description hash from element" do
|
158
|
-
Content.
|
159
|
-
Content.content_description_from_essence_type(element, 'EssenceText').
|
160
|
+
expect(Content).to receive(:content_name_from_element_and_essence_type).with(element, 'EssenceText').and_return('Foo')
|
161
|
+
expect(Content.content_description_from_essence_type(element, 'EssenceText')).to eq({
|
160
162
|
'type' => 'EssenceText',
|
161
163
|
'name' => 'Foo'
|
162
|
-
}
|
164
|
+
})
|
163
165
|
end
|
164
166
|
end
|
165
167
|
|
@@ -167,7 +169,7 @@ module Alchemy
|
|
167
169
|
let(:element) { FactoryGirl.build_stubbed(:element) }
|
168
170
|
|
169
171
|
it "returns a name from essence type and count of essences in element" do
|
170
|
-
Content.content_name_from_element_and_essence_type(element, 'EssenceText').
|
172
|
+
expect(Content.content_name_from_element_and_essence_type(element, 'EssenceText')).to eq("essence_text_1")
|
171
173
|
end
|
172
174
|
end
|
173
175
|
|
@@ -188,24 +190,24 @@ module Alchemy
|
|
188
190
|
|
189
191
|
context "with default value present" do
|
190
192
|
it "should have the ingredient column filled with default value." do
|
191
|
-
Content.
|
193
|
+
allow(Content).to receive(:content_description_from_element).and_return({'name' => 'headline', 'type' => 'EssenceText', 'default' => 'Welcome'})
|
192
194
|
content = Content.create_from_scratch(element, name: 'headline')
|
193
|
-
content.ingredient.
|
195
|
+
expect(content.ingredient).to eq("Welcome")
|
194
196
|
end
|
195
197
|
end
|
196
198
|
end
|
197
199
|
|
198
200
|
describe '#ingredient=' do
|
199
|
-
let
|
201
|
+
let(:element) { FactoryGirl.create(:element, name: 'headline') }
|
200
202
|
|
201
203
|
it "should set the given value to the ingredient column of essence" do
|
202
204
|
c = Content.create_from_scratch(element, name: 'headline')
|
203
205
|
c.ingredient = "Welcome"
|
204
|
-
c.ingredient.
|
206
|
+
expect(c.ingredient).to eq("Welcome")
|
205
207
|
end
|
206
208
|
|
207
209
|
context "no essence associated" do
|
208
|
-
let
|
210
|
+
let(:element) { FactoryGirl.create(:element, name: 'headline') }
|
209
211
|
|
210
212
|
it "should raise error" do
|
211
213
|
c = Content.create(:element_id => element.id, name: 'headline')
|
@@ -216,10 +218,10 @@ module Alchemy
|
|
216
218
|
|
217
219
|
describe "#descriptions" do
|
218
220
|
context "without any descriptions in elements.yml file" do
|
219
|
-
before { Element.
|
221
|
+
before { allow(Element).to receive(:descriptions).and_return([]) }
|
220
222
|
|
221
223
|
it "should return an empty array" do
|
222
|
-
Content.descriptions.
|
224
|
+
expect(Content.descriptions).to eq([])
|
223
225
|
end
|
224
226
|
end
|
225
227
|
end
|
@@ -228,14 +230,14 @@ module Alchemy
|
|
228
230
|
let(:content) { build_stubbed(:content) }
|
229
231
|
|
230
232
|
it "returns a dom id string" do
|
231
|
-
content.dom_id.
|
233
|
+
expect(content.dom_id).to eq("essence_text_#{content.id}")
|
232
234
|
end
|
233
235
|
|
234
236
|
context "without an essence" do
|
235
|
-
before { content.
|
237
|
+
before { expect(content).to receive(:essence).and_return nil }
|
236
238
|
|
237
239
|
it "returns empty string" do
|
238
|
-
content.dom_id.
|
240
|
+
expect(content.dom_id).to eq('')
|
239
241
|
end
|
240
242
|
end
|
241
243
|
end
|
@@ -244,15 +246,56 @@ module Alchemy
|
|
244
246
|
let(:content) { build_stubbed(:content) }
|
245
247
|
|
246
248
|
it "returns the essence#partial_name" do
|
247
|
-
content.essence.
|
249
|
+
expect(content.essence).to receive(:partial_name)
|
248
250
|
content.essence_partial_name
|
249
251
|
end
|
250
252
|
|
251
253
|
context "without an essence" do
|
252
|
-
before { content.
|
254
|
+
before { expect(content).to receive(:essence).and_return nil }
|
253
255
|
|
254
256
|
it "returns empty string" do
|
255
|
-
content.essence_partial_name.
|
257
|
+
expect(content.essence_partial_name).to eq('')
|
258
|
+
end
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
describe '#preview_content?' do
|
263
|
+
let(:content) { build_stubbed(:content) }
|
264
|
+
|
265
|
+
context 'not defined as preview content' do
|
266
|
+
it "returns false" do
|
267
|
+
expect(content.preview_content?).to be false
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
context 'defined as preview content via take_me_for_preview' do
|
272
|
+
before do
|
273
|
+
expect(content).to receive(:description).at_least(:once).and_return({
|
274
|
+
'take_me_for_preview' => true
|
275
|
+
})
|
276
|
+
end
|
277
|
+
|
278
|
+
it "returns true" do
|
279
|
+
ActiveSupport::Deprecation.silence do
|
280
|
+
expect(content.preview_content?).to be true
|
281
|
+
end
|
282
|
+
end
|
283
|
+
|
284
|
+
it "display deprecation warning" do
|
285
|
+
expect(ActiveSupport::Deprecation).to receive(:warn)
|
286
|
+
content.preview_content?
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
290
|
+
context 'defined as preview content via as_element_title' do
|
291
|
+
before do
|
292
|
+
expect(content).to receive(:description).at_least(:once).and_return({
|
293
|
+
'as_element_title' => true
|
294
|
+
})
|
295
|
+
end
|
296
|
+
|
297
|
+
it "returns true" do
|
298
|
+
expect(content.preview_content?).to be true
|
256
299
|
end
|
257
300
|
end
|
258
301
|
end
|
@@ -262,7 +305,7 @@ module Alchemy
|
|
262
305
|
let(:content) { c = Content.new; c.essence = essence; c }
|
263
306
|
|
264
307
|
it "should return the essences preview_text" do
|
265
|
-
essence.
|
308
|
+
expect(essence).to receive(:preview_text).with(30)
|
266
309
|
content.preview_text
|
267
310
|
end
|
268
311
|
end
|
@@ -275,7 +318,7 @@ module Alchemy
|
|
275
318
|
it { eq('default_tinymce') }
|
276
319
|
|
277
320
|
context 'having custom tinymce config' do
|
278
|
-
before { content.
|
321
|
+
before { allow(content).to receive(:has_custom_tinymce_config?).and_return(true) }
|
279
322
|
it('returns name including element name') { eq('custom_tinymce article_text') }
|
280
323
|
end
|
281
324
|
end
|
@@ -284,12 +327,12 @@ module Alchemy
|
|
284
327
|
let(:content) { Content.new(id: 1) }
|
285
328
|
|
286
329
|
it "returns a name value for form fields with ingredient as default" do
|
287
|
-
content.form_field_name.
|
330
|
+
expect(content.form_field_name).to eq('contents[1][ingredient]')
|
288
331
|
end
|
289
332
|
|
290
333
|
context 'with a essence column given' do
|
291
334
|
it "returns a name value for form fields for that column" do
|
292
|
-
content.form_field_name(:link_title).
|
335
|
+
expect(content.form_field_name(:link_title)).to eq('contents[1][link_title]')
|
293
336
|
end
|
294
337
|
end
|
295
338
|
end
|
@@ -298,12 +341,12 @@ module Alchemy
|
|
298
341
|
let(:content) { Content.new(id: 1) }
|
299
342
|
|
300
343
|
it "returns a id value for form fields with ingredient as default" do
|
301
|
-
content.form_field_id.
|
344
|
+
expect(content.form_field_id).to eq('contents_1_ingredient')
|
302
345
|
end
|
303
346
|
|
304
347
|
context 'with a essence column given' do
|
305
348
|
it "returns a id value for form fields for that column" do
|
306
|
-
content.form_field_id(:link_title).
|
349
|
+
expect(content.form_field_id(:link_title)).to eq('contents_1_link_title')
|
307
350
|
end
|
308
351
|
end
|
309
352
|
end
|
@@ -312,5 +355,22 @@ module Alchemy
|
|
312
355
|
let(:subject) { Content.new }
|
313
356
|
end
|
314
357
|
|
358
|
+
describe '#settings' do
|
359
|
+
let(:element) { build_stubbed(:element, name: 'article') }
|
360
|
+
let(:content) { build_stubbed(:content, name: 'headline', element: element) }
|
361
|
+
|
362
|
+
it "returns the settings hash from description" do
|
363
|
+
expect(content.settings).to eq({deletable: true})
|
364
|
+
end
|
365
|
+
|
366
|
+
context 'if settings are not defined' do
|
367
|
+
let(:content) { build_stubbed(:content, name: 'intro', element: element) }
|
368
|
+
|
369
|
+
it "returns empty hash" do
|
370
|
+
expect(content.settings).to eq({})
|
371
|
+
end
|
372
|
+
end
|
373
|
+
end
|
374
|
+
|
315
375
|
end
|
316
376
|
end
|
data/spec/models/element_spec.rb
CHANGED
@@ -13,28 +13,28 @@ module Alchemy
|
|
13
13
|
|
14
14
|
it "should not create contents from scratch" do
|
15
15
|
copy = Element.copy(element)
|
16
|
-
copy.contents.count.
|
16
|
+
expect(copy.contents.count).to eq(element.contents.count)
|
17
17
|
end
|
18
18
|
|
19
19
|
it "should create a new record with all attributes of source except given differences" do
|
20
20
|
copy = Element.copy(element, {:name => 'foobar'})
|
21
|
-
copy.name.
|
21
|
+
expect(copy.name).to eq('foobar')
|
22
22
|
end
|
23
23
|
|
24
24
|
it "should make copies of all contents of source" do
|
25
25
|
copy = Element.copy(element)
|
26
|
-
copy.contents.pluck(:id).
|
26
|
+
expect(copy.contents.pluck(:id)).not_to eq(element.contents.pluck(:id))
|
27
27
|
end
|
28
28
|
|
29
29
|
it "the copy should include source element tags" do
|
30
30
|
copy = Element.copy(element)
|
31
|
-
copy.tag_list.
|
31
|
+
expect(copy.tag_list).to eq(element.tag_list)
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
35
|
describe '.definitions' do
|
36
36
|
context "without existing yml files" do
|
37
|
-
before { File.
|
37
|
+
before { allow(File).to receive(:exists?).and_return(false) }
|
38
38
|
|
39
39
|
it "should raise an error" do
|
40
40
|
expect { Element.definitions }.to raise_error(LoadError)
|
@@ -42,17 +42,17 @@ module Alchemy
|
|
42
42
|
end
|
43
43
|
|
44
44
|
context "without any definitions in elements.yml" do
|
45
|
-
before { YAML.
|
45
|
+
before { allow(YAML).to receive(:load_file).and_return(false) } # Yes, YAML.load_file returns false if an empty file exists.
|
46
46
|
|
47
47
|
it "should return an empty array" do
|
48
|
-
Element.definitions.
|
48
|
+
expect(Element.definitions).to eq([])
|
49
49
|
end
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
53
|
describe '.display_name_for' do
|
54
54
|
it "should return the translation for the given name" do
|
55
|
-
I18n.
|
55
|
+
expect(I18n).to receive(:t).with('subheadline', scope: "element_names", default: 'Subheadline').and_return('Überschrift')
|
56
56
|
expect(Element.display_name_for('subheadline')).to eq('Überschrift')
|
57
57
|
end
|
58
58
|
|
@@ -66,7 +66,7 @@ module Alchemy
|
|
66
66
|
FactoryGirl.create(:element, :name => 'article')
|
67
67
|
FactoryGirl.create(:element, :name => 'article')
|
68
68
|
excluded = FactoryGirl.create(:element, :name => 'claim')
|
69
|
-
Element.excluded(['claim']).
|
69
|
+
expect(Element.excluded(['claim'])).not_to include(excluded)
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
@@ -75,8 +75,8 @@ module Alchemy
|
|
75
75
|
element_1 = FactoryGirl.create(:element, :name => 'article')
|
76
76
|
element_2 = FactoryGirl.create(:element, :name => 'article')
|
77
77
|
elements = Element.named(['article'])
|
78
|
-
elements.
|
79
|
-
elements.
|
78
|
+
expect(elements).to include(element_1)
|
79
|
+
expect(elements).to include(element_2)
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
@@ -85,7 +85,7 @@ module Alchemy
|
|
85
85
|
Element.delete_all
|
86
86
|
FactoryGirl.create(:element, :cell_id => 6)
|
87
87
|
FactoryGirl.create(:element, :cell_id => nil)
|
88
|
-
Element.not_in_cell.
|
88
|
+
expect(Element.not_in_cell.size).to eq(1)
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
@@ -94,8 +94,8 @@ module Alchemy
|
|
94
94
|
element_1 = FactoryGirl.create(:element, :public => true)
|
95
95
|
element_2 = FactoryGirl.create(:element, :public => true)
|
96
96
|
elements = Element.published
|
97
|
-
elements.
|
98
|
-
elements.
|
97
|
+
expect(elements).to include(element_1)
|
98
|
+
expect(elements).to include(element_2)
|
99
99
|
end
|
100
100
|
end
|
101
101
|
|
@@ -126,24 +126,24 @@ module Alchemy
|
|
126
126
|
let(:clipboard) { [{'id' => element_1.id.to_s}, {'id' => element_2.id.to_s}] }
|
127
127
|
|
128
128
|
before do
|
129
|
-
Element.
|
129
|
+
allow(Element).to receive(:all_from_clipboard).and_return([element_1, element_2])
|
130
130
|
end
|
131
131
|
|
132
132
|
it "return all elements from clipboard that could be placed on page" do
|
133
133
|
elements = Element.all_from_clipboard_for_page(clipboard, page)
|
134
|
-
elements.
|
135
|
-
elements.
|
134
|
+
expect(elements).to eq([element_1])
|
135
|
+
expect(elements).not_to eq([element_2])
|
136
136
|
end
|
137
137
|
|
138
138
|
context "page nil" do
|
139
139
|
it "returns empty array" do
|
140
|
-
Element.all_from_clipboard_for_page(clipboard, nil).
|
140
|
+
expect(Element.all_from_clipboard_for_page(clipboard, nil)).to eq([])
|
141
141
|
end
|
142
142
|
end
|
143
143
|
|
144
144
|
context "clipboard nil" do
|
145
145
|
it "returns empty array" do
|
146
|
-
Element.all_from_clipboard_for_page(nil, page).
|
146
|
+
expect(Element.all_from_clipboard_for_page(nil, page)).to eq([])
|
147
147
|
end
|
148
148
|
end
|
149
149
|
end
|
@@ -156,14 +156,14 @@ module Alchemy
|
|
156
156
|
|
157
157
|
context "with namespaced essence type" do
|
158
158
|
subject { element.all_contents_by_type('Alchemy::EssenceText') }
|
159
|
-
it {
|
160
|
-
it('should return the correct list of essences') {
|
159
|
+
it { is_expected.not_to be_empty }
|
160
|
+
it('should return the correct list of essences') { is_expected.to eq(expected_contents) }
|
161
161
|
end
|
162
162
|
|
163
163
|
context "without namespaced essence type" do
|
164
164
|
subject { element.all_contents_by_type('EssenceText') }
|
165
|
-
it {
|
166
|
-
it('should return the correct list of essences') {
|
165
|
+
it { is_expected.not_to be_empty }
|
166
|
+
it('should return the correct list of essences') { is_expected.to eq(expected_contents) }
|
167
167
|
end
|
168
168
|
end
|
169
169
|
|
@@ -173,7 +173,7 @@ module Alchemy
|
|
173
173
|
|
174
174
|
context "with page having cells defining the correct elements" do
|
175
175
|
before do
|
176
|
-
Cell.
|
176
|
+
allow(Cell).to receive(:definitions).and_return([
|
177
177
|
{'name' => 'header', 'elements' => ['article', 'headline']},
|
178
178
|
{'name' => 'footer', 'elements' => ['article', 'text']},
|
179
179
|
{'name' => 'sidebar', 'elements' => ['teaser']}
|
@@ -184,13 +184,13 @@ module Alchemy
|
|
184
184
|
FactoryGirl.create(:cell, name: 'header', page: page)
|
185
185
|
FactoryGirl.create(:cell, name: 'footer', page: page)
|
186
186
|
FactoryGirl.create(:cell, name: 'sidebar', page: page)
|
187
|
-
element.available_page_cell_names(page).
|
188
|
-
element.available_page_cell_names(page).
|
187
|
+
expect(element.available_page_cell_names(page)).to include('header')
|
188
|
+
expect(element.available_page_cell_names(page)).to include('footer')
|
189
189
|
end
|
190
190
|
|
191
191
|
context "but without any cells" do
|
192
192
|
it "should return the 'nil cell'" do
|
193
|
-
element.available_page_cell_names(page).
|
193
|
+
expect(element.available_page_cell_names(page)).to eq(['for_other_elements'])
|
194
194
|
end
|
195
195
|
end
|
196
196
|
|
@@ -198,7 +198,7 @@ module Alchemy
|
|
198
198
|
|
199
199
|
context "with page having cells defining the wrong elements" do
|
200
200
|
before do
|
201
|
-
Cell.
|
201
|
+
allow(Cell).to receive(:definitions).and_return([
|
202
202
|
{'name' => 'header', 'elements' => ['download', 'headline']},
|
203
203
|
{'name' => 'footer', 'elements' => ['contactform', 'text']},
|
204
204
|
{'name' => 'sidebar', 'elements' => ['teaser']}
|
@@ -209,7 +209,7 @@ module Alchemy
|
|
209
209
|
FactoryGirl.create(:cell, name: 'header', page: page)
|
210
210
|
FactoryGirl.create(:cell, name: 'footer', page: page)
|
211
211
|
FactoryGirl.create(:cell, name: 'sidebar', page: page)
|
212
|
-
element.available_page_cell_names(page).
|
212
|
+
expect(element.available_page_cell_names(page)).to eq(['for_other_elements'])
|
213
213
|
end
|
214
214
|
end
|
215
215
|
end
|
@@ -222,13 +222,13 @@ module Alchemy
|
|
222
222
|
|
223
223
|
context "with namespaced essence type" do
|
224
224
|
it "should return content by passing a essence type" do
|
225
|
-
@element.content_by_type('Alchemy::EssenceText').
|
225
|
+
expect(@element.content_by_type('Alchemy::EssenceText')).to eq(@content)
|
226
226
|
end
|
227
227
|
end
|
228
228
|
|
229
229
|
context "without namespaced essence type" do
|
230
230
|
it "should return content by passing a essence type" do
|
231
|
-
@element.content_by_type('EssenceText').
|
231
|
+
expect(@element.content_by_type('EssenceText')).to eq(@content)
|
232
232
|
end
|
233
233
|
end
|
234
234
|
end
|
@@ -237,28 +237,17 @@ module Alchemy
|
|
237
237
|
let(:element) { Element.new(name: 'article') }
|
238
238
|
|
239
239
|
it "should call .display_name_for" do
|
240
|
-
Element.
|
240
|
+
expect(Element).to receive(:display_name_for).with(element.name)
|
241
241
|
element.display_name
|
242
242
|
end
|
243
243
|
end
|
244
244
|
|
245
|
-
describe '#essence_error_messages' do
|
246
|
-
let(:element) { Element.new(name: 'article') }
|
247
|
-
it "should return the translation with the translated content label" do
|
248
|
-
I18n.should_receive(:t).with('content_names.content', default: 'Content').and_return('Content')
|
249
|
-
I18n.should_receive(:t).with('content', scope: "content_names.article", default: 'Content').and_return('Contenido')
|
250
|
-
I18n.should_receive(:t).with('article.content.invalid', {:scope=>"content_validations", :default=>[:"fields.content.invalid", :"errors.invalid"], :field=>"Contenido"})
|
251
|
-
element.should_receive(:essence_errors).and_return({'content' => [:invalid]})
|
252
|
-
element.essence_error_messages
|
253
|
-
end
|
254
|
-
end
|
255
|
-
|
256
245
|
describe '#display_name_with_preview_text' do
|
257
246
|
let(:element) { FactoryGirl.build_stubbed(:element, name: 'Foo') }
|
258
247
|
|
259
248
|
it "returns a string with display name and preview text" do
|
260
|
-
element.
|
261
|
-
element.display_name_with_preview_text.
|
249
|
+
allow(element).to receive(:preview_text).and_return('Fula')
|
250
|
+
expect(element.display_name_with_preview_text).to eq("Foo: Fula")
|
262
251
|
end
|
263
252
|
end
|
264
253
|
|
@@ -266,14 +255,14 @@ module Alchemy
|
|
266
255
|
let(:element) { FactoryGirl.build_stubbed(:element) }
|
267
256
|
|
268
257
|
it "returns an string from element name and id" do
|
269
|
-
element.dom_id.
|
258
|
+
expect(element.dom_id).to eq("#{element.name}_#{element.id}")
|
270
259
|
end
|
271
260
|
end
|
272
261
|
|
273
262
|
describe '#new_from_scratch' do
|
274
263
|
it "should initialize an element by name from scratch" do
|
275
264
|
el = Element.new_from_scratch({:name => 'article'})
|
276
|
-
el.
|
265
|
+
expect(el).to be_valid
|
277
266
|
end
|
278
267
|
|
279
268
|
it "should raise an error if the given name is not defined in the elements.yml" do
|
@@ -282,17 +271,17 @@ module Alchemy
|
|
282
271
|
|
283
272
|
it "should take the first part of an given name containing a hash (#)" do
|
284
273
|
el = Element.new_from_scratch({:name => 'article#header'})
|
285
|
-
el.name.
|
274
|
+
expect(el.name).to eq("article")
|
286
275
|
end
|
287
276
|
|
288
277
|
it "should merge given attributes into defined ones" do
|
289
278
|
el = Element.new_from_scratch({:name => 'article', :page_id => 1})
|
290
|
-
el.page_id.
|
279
|
+
expect(el.page_id).to eq(1)
|
291
280
|
end
|
292
281
|
|
293
282
|
it "should not have forbidden attributes from definition" do
|
294
283
|
el = Element.new_from_scratch({:name => 'article'})
|
295
|
-
el.contents.
|
284
|
+
expect(el.contents).to eq([])
|
296
285
|
end
|
297
286
|
end
|
298
287
|
|
@@ -304,29 +293,29 @@ module Alchemy
|
|
304
293
|
|
305
294
|
context "without a content marked as preview" do
|
306
295
|
let(:contents) { [content, content_2] }
|
307
|
-
before { element.
|
296
|
+
before { allow(element).to receive(:contents).and_return(contents) }
|
308
297
|
|
309
298
|
it "returns the preview text of first content found" do
|
310
|
-
content.
|
299
|
+
expect(content).to receive(:preview_text).with(30)
|
311
300
|
element.preview_text
|
312
301
|
end
|
313
302
|
end
|
314
303
|
|
315
304
|
context "with a content marked as preview" do
|
316
305
|
let(:contents) { [content, preview_content] }
|
317
|
-
before { element.
|
306
|
+
before { allow(element).to receive(:contents).and_return(contents) }
|
318
307
|
|
319
308
|
it "should return the preview_text of this content" do
|
320
|
-
preview_content.
|
309
|
+
expect(preview_content).to receive(:preview_text).with(30)
|
321
310
|
element.preview_text
|
322
311
|
end
|
323
312
|
end
|
324
313
|
|
325
314
|
context "without any contents present" do
|
326
|
-
before { element.
|
315
|
+
before { allow(element).to receive(:contents).and_return([]) }
|
327
316
|
|
328
317
|
it "should return nil" do
|
329
|
-
element.preview_text.
|
318
|
+
expect(element.preview_text).to be_nil
|
330
319
|
end
|
331
320
|
end
|
332
321
|
end
|
@@ -342,24 +331,24 @@ module Alchemy
|
|
342
331
|
|
343
332
|
describe '#prev' do
|
344
333
|
it "should return previous element on same page" do
|
345
|
-
@element3.prev.
|
334
|
+
expect(@element3.prev).to eq(@element2)
|
346
335
|
end
|
347
336
|
|
348
337
|
context "with name as parameter" do
|
349
338
|
it "should return previous of this kind" do
|
350
|
-
@element3.prev('headline').
|
339
|
+
expect(@element3.prev('headline')).to eq(@element1)
|
351
340
|
end
|
352
341
|
end
|
353
342
|
end
|
354
343
|
|
355
344
|
describe '#next' do
|
356
345
|
it "should return next element on same page" do
|
357
|
-
@element2.next.
|
346
|
+
expect(@element2.next).to eq(@element3)
|
358
347
|
end
|
359
348
|
|
360
349
|
context "with name as parameter" do
|
361
350
|
it "should return next of this kind" do
|
362
|
-
@element1.next('text').
|
351
|
+
expect(@element1.next('text')).to eq(@element3)
|
363
352
|
end
|
364
353
|
end
|
365
354
|
end
|
@@ -369,30 +358,30 @@ module Alchemy
|
|
369
358
|
let(:element) { FactoryGirl.create(:element, :name => 'news', :create_contents_after_create => true) }
|
370
359
|
|
371
360
|
it "should return an ingredient by name" do
|
372
|
-
element.ingredient('news_headline').
|
361
|
+
expect(element.ingredient('news_headline')).to eq(EssenceText.first.ingredient)
|
373
362
|
end
|
374
363
|
|
375
364
|
it "should return the content for rss title" do
|
376
|
-
element.content_for_rss_title.
|
365
|
+
expect(element.content_for_rss_title).to eq(element.contents.find_by_name('news_headline'))
|
377
366
|
end
|
378
367
|
|
379
368
|
it "should return the content for rss descdefinitionription" do
|
380
|
-
element.content_for_rss_description.
|
369
|
+
expect(element.content_for_rss_description).to eq(element.contents.find_by_name('body'))
|
381
370
|
end
|
382
371
|
|
383
372
|
context 'if no content is defined as rss title' do
|
384
|
-
before { element.
|
373
|
+
before { expect(element).to receive(:content_descriptions).and_return([]) }
|
385
374
|
|
386
375
|
it "should return nil" do
|
387
|
-
element.content_for_rss_title.
|
376
|
+
expect(element.content_for_rss_title).to be_nil
|
388
377
|
end
|
389
378
|
end
|
390
379
|
|
391
380
|
context 'if no content is defined as rss description' do
|
392
|
-
before { element.
|
381
|
+
before { expect(element).to receive(:content_descriptions).and_return([]) }
|
393
382
|
|
394
383
|
it "should return nil" do
|
395
|
-
element.content_for_rss_description.
|
384
|
+
expect(element.content_for_rss_description).to be_nil
|
396
385
|
end
|
397
386
|
end
|
398
387
|
end
|
@@ -404,11 +393,11 @@ module Alchemy
|
|
404
393
|
let(:element) { build_stubbed(:element, page: page) }
|
405
394
|
let(:content) { double(:content, id: 1) }
|
406
395
|
|
407
|
-
before { element.
|
396
|
+
before { allow(element).to receive(:contents).and_return([content]) }
|
408
397
|
|
409
398
|
context "with attributes hash is nil" do
|
410
399
|
let(:params) { nil }
|
411
|
-
it {
|
400
|
+
it { is_expected.to be_truthy }
|
412
401
|
end
|
413
402
|
|
414
403
|
context "with valid attributes hash" do
|
@@ -416,17 +405,17 @@ module Alchemy
|
|
416
405
|
|
417
406
|
context 'with passing validations' do
|
418
407
|
before do
|
419
|
-
content.
|
408
|
+
expect(content).to receive(:update_essence).with({body: 'Title'}).and_return(true)
|
420
409
|
end
|
421
410
|
|
422
|
-
it {
|
411
|
+
it { is_expected.to be_truthy }
|
423
412
|
end
|
424
413
|
|
425
414
|
context 'with failing validations' do
|
426
415
|
it "adds error and returns false" do
|
427
|
-
content.
|
428
|
-
|
429
|
-
element.errors.
|
416
|
+
expect(content).to receive(:update_essence).with({body: 'Title'}).and_return(false)
|
417
|
+
is_expected.to be_falsey
|
418
|
+
expect(element.errors).not_to be_empty
|
430
419
|
end
|
431
420
|
end
|
432
421
|
end
|
@@ -438,7 +427,7 @@ module Alchemy
|
|
438
427
|
let(:now) { Time.now }
|
439
428
|
|
440
429
|
before do
|
441
|
-
Time.
|
430
|
+
allow(Time).to receive(:now).and_return(now)
|
442
431
|
end
|
443
432
|
|
444
433
|
context 'with touchable pages' do
|
@@ -446,19 +435,19 @@ module Alchemy
|
|
446
435
|
let(:pages) { [page] }
|
447
436
|
|
448
437
|
before do
|
449
|
-
Alchemy.user_class.
|
438
|
+
expect(Alchemy.user_class).to receive(:stamper).at_least(:once).and_return(locker.id)
|
450
439
|
end
|
451
440
|
|
452
441
|
it "updates page timestamps" do
|
453
|
-
element.
|
454
|
-
pages.
|
442
|
+
expect(element).to receive(:touchable_pages).and_return(pages)
|
443
|
+
expect(pages).to receive(:update_all).with({updated_at: now, updater_id: locker.id})
|
455
444
|
element.save
|
456
445
|
end
|
457
446
|
|
458
447
|
it "updates page userstamps" do
|
459
448
|
element.save
|
460
449
|
page.reload
|
461
|
-
page.updater_id.
|
450
|
+
expect(page.updater_id).to eq(locker.id)
|
462
451
|
end
|
463
452
|
end
|
464
453
|
|
@@ -466,11 +455,11 @@ module Alchemy
|
|
466
455
|
let(:cell) { mock_model('Cell') }
|
467
456
|
|
468
457
|
before do
|
469
|
-
element.
|
458
|
+
expect(element).to receive(:cell).at_least(:once).and_return(cell)
|
470
459
|
end
|
471
460
|
|
472
461
|
it "updates timestamp of cell" do
|
473
|
-
element.cell.
|
462
|
+
expect(element.cell).to receive(:touch)
|
474
463
|
element.save
|
475
464
|
end
|
476
465
|
end
|
@@ -487,22 +476,30 @@ module Alchemy
|
|
487
476
|
|
488
477
|
context "definition has 'taggable' key with true value" do
|
489
478
|
it "should return true" do
|
490
|
-
element.
|
491
|
-
|
479
|
+
expect(element).to receive(:definition).and_return({
|
480
|
+
'name' => 'article',
|
481
|
+
'taggable' => true
|
482
|
+
})
|
483
|
+
expect(element.taggable?).to be_truthy
|
492
484
|
end
|
493
485
|
end
|
494
486
|
|
495
487
|
context "definition has 'taggable' key with foo value" do
|
496
488
|
it "should return false" do
|
497
|
-
element.
|
498
|
-
|
489
|
+
expect(element).to receive(:definition).and_return({
|
490
|
+
'name' => 'article',
|
491
|
+
'taggable' => 'foo'
|
492
|
+
})
|
493
|
+
expect(element.taggable?).to be_falsey
|
499
494
|
end
|
500
495
|
end
|
501
496
|
|
502
497
|
context "definition has no 'taggable' key" do
|
503
498
|
it "should return false" do
|
504
|
-
element.
|
505
|
-
|
499
|
+
expect(element).to receive(:definition).and_return({
|
500
|
+
'name' => 'article'
|
501
|
+
})
|
502
|
+
expect(element.taggable?).to be_falsey
|
506
503
|
end
|
507
504
|
end
|
508
505
|
end
|
@@ -512,18 +509,23 @@ module Alchemy
|
|
512
509
|
let(:trashed_element) { element.trash! ; element }
|
513
510
|
subject { trashed_element }
|
514
511
|
|
515
|
-
it {
|
516
|
-
it {
|
517
|
-
|
512
|
+
it { is_expected.not_to be_public }
|
513
|
+
it { is_expected.to be_folded }
|
514
|
+
|
515
|
+
describe '#position' do
|
516
|
+
subject { super().position }
|
517
|
+
it { is_expected.to be_nil }
|
518
|
+
end
|
518
519
|
specify { expect { element.trash! }.to_not change(element, :page_id) }
|
519
520
|
specify { expect { element.trash! }.to_not change(element, :cell_id) }
|
520
521
|
|
521
522
|
context "with already one trashed element on the same page" do
|
522
523
|
let(:element_2) { FactoryGirl.create(:element, page_id: 1) }
|
523
|
-
|
524
|
+
|
525
|
+
before do
|
524
526
|
trashed_element
|
525
527
|
element_2
|
526
|
-
|
528
|
+
end
|
527
529
|
|
528
530
|
it "it should be possible to trash another" do
|
529
531
|
element_2.trash!
|
@@ -538,29 +540,6 @@ module Alchemy
|
|
538
540
|
end
|
539
541
|
end
|
540
542
|
|
541
|
-
describe '#cache_key' do
|
542
|
-
let(:page) { stub_model(Page, published_at: Time.now - 1.week) }
|
543
|
-
let(:element) { stub_model(Element, page: page, updated_at: Time.now) }
|
544
|
-
|
545
|
-
subject { element.cache_key }
|
546
|
-
|
547
|
-
before do
|
548
|
-
expect(Page).to receive(:current_preview).and_return(preview)
|
549
|
-
end
|
550
|
-
|
551
|
-
context "when current page rendered in preview mode" do
|
552
|
-
let(:preview) { page }
|
553
|
-
|
554
|
-
it { is_expected.to eq("alchemy/elements/#{element.id}-#{element.updated_at}") }
|
555
|
-
end
|
556
|
-
|
557
|
-
context "when current page not in preview mode" do
|
558
|
-
let(:preview) { nil }
|
559
|
-
|
560
|
-
it { is_expected.to eq("alchemy/elements/#{element.id}-#{page.published_at}") }
|
561
|
-
end
|
562
|
-
end
|
563
|
-
|
564
543
|
it_behaves_like "having a hint" do
|
565
544
|
let(:subject) { Element.new }
|
566
545
|
end
|