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
@@ -8,8 +8,8 @@ module Alchemy
|
|
8
8
|
|
9
9
|
describe '#index' do
|
10
10
|
before do
|
11
|
-
Page.
|
12
|
-
Page.
|
11
|
+
expect(Page).to receive(:from_current_site).and_return(double(all_last_edited_from: []))
|
12
|
+
expect(Page).to receive(:from_current_site).and_return(double(all_locked: []))
|
13
13
|
end
|
14
14
|
|
15
15
|
it "assigns @last_edited_pages" do
|
@@ -27,7 +27,7 @@ module Alchemy
|
|
27
27
|
let(:another_user) { mock_model('DummyUser') }
|
28
28
|
|
29
29
|
before do
|
30
|
-
Alchemy.user_class.
|
30
|
+
expect(Alchemy.user_class).to receive(:logged_in).and_return([another_user])
|
31
31
|
end
|
32
32
|
|
33
33
|
it "assigns @online_users" do
|
@@ -46,8 +46,8 @@ module Alchemy
|
|
46
46
|
|
47
47
|
context 'user having signed in before' do
|
48
48
|
before do
|
49
|
-
user.
|
50
|
-
user.
|
49
|
+
expect(user).to receive(:sign_in_count).and_return(5)
|
50
|
+
expect(user).to receive(:last_sign_in_at).and_return(Time.now)
|
51
51
|
end
|
52
52
|
|
53
53
|
it "assigns @first_time" do
|
@@ -72,8 +72,8 @@ module Alchemy
|
|
72
72
|
describe '#update_check' do
|
73
73
|
context "if current Alchemy version equals the latest released version or it is newer" do
|
74
74
|
before {
|
75
|
-
controller.
|
76
|
-
Alchemy.
|
75
|
+
allow(controller).to receive(:latest_alchemy_version).and_return('2.6')
|
76
|
+
allow(Alchemy).to receive(:version).and_return("2.6")
|
77
77
|
}
|
78
78
|
|
79
79
|
it "should render 'false'" do
|
@@ -84,8 +84,8 @@ module Alchemy
|
|
84
84
|
|
85
85
|
context "if current Alchemy version is older than latest released version" do
|
86
86
|
before {
|
87
|
-
controller.
|
88
|
-
Alchemy.
|
87
|
+
allow(controller).to receive(:latest_alchemy_version).and_return('2.6')
|
88
|
+
allow(Alchemy).to receive(:version).and_return("2.5")
|
89
89
|
}
|
90
90
|
|
91
91
|
it "should render 'true'" do
|
@@ -96,10 +96,10 @@ module Alchemy
|
|
96
96
|
|
97
97
|
context "requesting rubygems.org" do
|
98
98
|
before {
|
99
|
-
Net::HTTP.
|
99
|
+
allow_any_instance_of(Net::HTTP).to receive(:request).and_return(
|
100
100
|
OpenStruct.new({code: '200', body: '[{"number": "2.6"}, {"number": "2.5"}]'})
|
101
101
|
)
|
102
|
-
Alchemy.
|
102
|
+
allow(Alchemy).to receive(:version).and_return("2.6")
|
103
103
|
}
|
104
104
|
|
105
105
|
it "should have response code of 200" do
|
@@ -110,8 +110,8 @@ module Alchemy
|
|
110
110
|
|
111
111
|
context "requesting github.com" do
|
112
112
|
before {
|
113
|
-
controller.
|
114
|
-
Net::HTTP.
|
113
|
+
allow(controller).to receive(:query_rubygems).and_return(OpenStruct.new({code: '503'}))
|
114
|
+
allow_any_instance_of(Net::HTTP).to receive(:request).and_return(
|
115
115
|
OpenStruct.new({code: '200', body: '[{"name": "2.6"}, {"name": "2.5"}]'})
|
116
116
|
)
|
117
117
|
}
|
@@ -124,7 +124,7 @@ module Alchemy
|
|
124
124
|
|
125
125
|
context "rubygems.org and github.com are unavailable" do
|
126
126
|
before {
|
127
|
-
Net::HTTP.
|
127
|
+
allow_any_instance_of(Net::HTTP).to receive(:request).and_return(
|
128
128
|
OpenStruct.new({code: '503'})
|
129
129
|
)
|
130
130
|
}
|
@@ -13,26 +13,30 @@ module Alchemy
|
|
13
13
|
let(:alchemy_page) { build_stubbed(:page) }
|
14
14
|
|
15
15
|
before do
|
16
|
-
Page.
|
16
|
+
expect(Page).to receive(:find).and_return alchemy_page
|
17
17
|
end
|
18
18
|
|
19
19
|
context 'with cells' do
|
20
20
|
let(:cell) { build_stubbed(:cell, page: alchemy_page) }
|
21
21
|
|
22
|
-
before
|
22
|
+
before do
|
23
|
+
expect(alchemy_page).to receive(:cells).and_return [cell]
|
24
|
+
end
|
23
25
|
|
24
26
|
it "groups elements by cell" do
|
25
|
-
alchemy_page.
|
27
|
+
expect(alchemy_page).to receive(:elements_grouped_by_cells)
|
26
28
|
get :index, {page_id: alchemy_page.id}
|
27
|
-
assigns(:cells).
|
29
|
+
expect(assigns(:cells)).to eq([cell])
|
28
30
|
end
|
29
31
|
end
|
30
32
|
|
31
33
|
context 'without cells' do
|
32
|
-
before
|
34
|
+
before do
|
35
|
+
expect(alchemy_page).to receive(:cells).and_return []
|
36
|
+
end
|
33
37
|
|
34
38
|
it "assigns page elements" do
|
35
|
-
alchemy_page.
|
39
|
+
expect(alchemy_page).to receive(:elements).and_return(double(not_trashed: []))
|
36
40
|
get :index, {page_id: alchemy_page.id}
|
37
41
|
end
|
38
42
|
end
|
@@ -41,13 +45,9 @@ module Alchemy
|
|
41
45
|
describe '#list' do
|
42
46
|
let(:alchemy_page) { build_stubbed(:page) }
|
43
47
|
|
44
|
-
before do
|
45
|
-
Page.stub(find: alchemy_page)
|
46
|
-
end
|
47
|
-
|
48
48
|
context 'without page_id, but with page_urlname' do
|
49
49
|
it "loads page from urlname" do
|
50
|
-
Language.
|
50
|
+
expect(Language).to receive(:current).at_least(:once).and_return(double(code: 'en', pages: double(find_by: double(id: 1001))))
|
51
51
|
xhr :get, :list, {page_urlname: 'contact'}
|
52
52
|
end
|
53
53
|
|
@@ -56,7 +56,7 @@ module Alchemy
|
|
56
56
|
|
57
57
|
it "should return a select tag with elements" do
|
58
58
|
xhr :get, :list, {page_urlname: alchemy_page.urlname}
|
59
|
-
response.body.
|
59
|
+
expect(response.body).to match(/select(.*)elements_from_page_selector(.*)option/)
|
60
60
|
end
|
61
61
|
end
|
62
62
|
end
|
@@ -64,7 +64,7 @@ module Alchemy
|
|
64
64
|
context 'with page_id' do
|
65
65
|
it "loads page from urlname" do
|
66
66
|
xhr :get, :list, {page_id: alchemy_page.id}
|
67
|
-
assigns(:page_id).
|
67
|
+
expect(assigns(:page_id)).to eq(alchemy_page.id.to_s)
|
68
68
|
end
|
69
69
|
end
|
70
70
|
end
|
@@ -93,22 +93,22 @@ module Alchemy
|
|
93
93
|
expect(assigns(:trashed_elements).to_a).to eq [trashed_element.id]
|
94
94
|
end
|
95
95
|
|
96
|
-
it "
|
96
|
+
it "sets a new position to the element" do
|
97
97
|
xhr :post, :order, element_ids: [trashed_element.id]
|
98
98
|
trashed_element.reload
|
99
|
-
trashed_element.position.
|
99
|
+
expect(trashed_element.position).to_not be_nil
|
100
100
|
end
|
101
101
|
|
102
102
|
it "should assign the (new) page_id to the element" do
|
103
103
|
xhr :post, :order, element_ids: [trashed_element.id], page_id: 1, cell_id: nil
|
104
104
|
trashed_element.reload
|
105
|
-
trashed_element.page_id.
|
105
|
+
expect(trashed_element.page_id).to be 1
|
106
106
|
end
|
107
107
|
|
108
108
|
it "should assign the (new) cell_id to the element" do
|
109
109
|
xhr :post, :order, element_ids: [trashed_element.id], page_id: 1, cell_id: 5
|
110
110
|
trashed_element.reload
|
111
|
-
trashed_element.cell_id.
|
111
|
+
expect(trashed_element.cell_id).to be 5
|
112
112
|
end
|
113
113
|
end
|
114
114
|
end
|
@@ -116,10 +116,12 @@ module Alchemy
|
|
116
116
|
describe '#new' do
|
117
117
|
let(:alchemy_page) { build_stubbed(:page) }
|
118
118
|
|
119
|
-
before
|
119
|
+
before do
|
120
|
+
expect(Page).to receive(:find_by_id).and_return(alchemy_page)
|
121
|
+
end
|
120
122
|
|
121
123
|
it "assign variable for all available element definitions" do
|
122
|
-
alchemy_page.
|
124
|
+
expect(alchemy_page).to receive(:available_element_definitions)
|
123
125
|
get :new, {page_id: alchemy_page.id}
|
124
126
|
end
|
125
127
|
|
@@ -129,9 +131,9 @@ module Alchemy
|
|
129
131
|
before { clipboard['elements'] = clipboard_items }
|
130
132
|
|
131
133
|
it "should load all elements from clipboard" do
|
132
|
-
Element.
|
134
|
+
expect(Element).to receive(:all_from_clipboard_for_page).and_return(clipboard_items)
|
133
135
|
get :new, {page_id: alchemy_page.id}
|
134
|
-
assigns(:clipboard_items).
|
136
|
+
expect(assigns(:clipboard_items)).to eq(clipboard_items)
|
135
137
|
end
|
136
138
|
end
|
137
139
|
end
|
@@ -142,13 +144,13 @@ module Alchemy
|
|
142
144
|
|
143
145
|
it "should insert the element at bottom of list" do
|
144
146
|
xhr :post, :create, {element: {name: 'news', page_id: alchemy_page.id}}
|
145
|
-
alchemy_page.elements.count.
|
146
|
-
alchemy_page.elements.last.name.
|
147
|
+
expect(alchemy_page.elements.count).to eq(2)
|
148
|
+
expect(alchemy_page.elements.last.name).to eq('news')
|
147
149
|
end
|
148
150
|
|
149
151
|
context "on a page with a setting for insert_elements_at of top" do
|
150
152
|
before do
|
151
|
-
PageLayout.
|
153
|
+
expect(PageLayout).to receive(:get).at_least(:once).and_return({
|
152
154
|
'name' => 'news',
|
153
155
|
'elements' => ['news'],
|
154
156
|
'insert_elements_at' => 'top'
|
@@ -157,107 +159,120 @@ module Alchemy
|
|
157
159
|
|
158
160
|
it "should insert the element at top of list" do
|
159
161
|
xhr :post, :create, {element: {name: 'news', page_id: alchemy_page.id}}
|
160
|
-
alchemy_page.elements.count.
|
161
|
-
alchemy_page.elements.first.name.
|
162
|
+
expect(alchemy_page.elements.count).to eq(2)
|
163
|
+
expect(alchemy_page.elements.first.name).to eq('news')
|
162
164
|
end
|
163
165
|
end
|
164
166
|
end
|
165
167
|
|
166
168
|
context "if page has cells" do
|
167
|
-
|
168
|
-
|
169
|
-
@page = create(:public_page, :do_not_autogenerate => false)
|
170
|
-
@cell = create(:cell, :name => 'header', :page => @page)
|
171
|
-
PageLayout.stub(:get).and_return({
|
172
|
-
'name' => 'standard',
|
173
|
-
'elements' => ['article'],
|
174
|
-
'cells' => ['header']
|
175
|
-
})
|
176
|
-
Cell.stub(:definition_for).and_return({'name' => 'header', 'elements' => ['article']})
|
177
|
-
end
|
169
|
+
let(:page) { create(:public_page, do_not_autogenerate: false) }
|
170
|
+
let(:cell) { page.cells.first }
|
178
171
|
|
172
|
+
context "not pasting from clipboard" do
|
179
173
|
context "and cell name in element name" do
|
174
|
+
before do
|
175
|
+
expect(PageLayout).to receive(:get).at_least(:once).and_return({
|
176
|
+
'name' => 'standard',
|
177
|
+
'elements' => ['article'],
|
178
|
+
'cells' => ['header']
|
179
|
+
})
|
180
|
+
expect(Cell).to receive(:definition_for).and_return({
|
181
|
+
'name' => 'header',
|
182
|
+
'elements' => ['article']
|
183
|
+
})
|
184
|
+
end
|
185
|
+
|
180
186
|
it "should put the element in the correct cell" do
|
181
|
-
xhr :post, :create, {:
|
182
|
-
|
187
|
+
xhr :post, :create, {element: {name: "article#header", page_id: page.id}}
|
188
|
+
expect(cell.elements.first).to be_an_instance_of(Element)
|
183
189
|
end
|
184
190
|
end
|
185
191
|
|
186
192
|
context "and no cell name in element name" do
|
187
193
|
it "should put the element in the main cell" do
|
188
|
-
xhr :post, :create, {:
|
189
|
-
|
194
|
+
xhr :post, :create, {element: {name: "article", page_id: page.id}}
|
195
|
+
expect(page.elements.not_in_cell.first).to be_an_instance_of(Element)
|
190
196
|
end
|
191
197
|
end
|
192
198
|
end
|
193
199
|
|
194
|
-
context "
|
195
|
-
context "" do
|
200
|
+
context "pasting from clipboard" do
|
201
|
+
context "with default element insert position" do
|
196
202
|
before do
|
197
|
-
|
198
|
-
@cell = create(:cell, :name => 'header', :page => @page)
|
199
|
-
PageLayout.stub(:get).and_return({
|
203
|
+
expect(PageLayout).to receive(:get).at_least(:once).and_return({
|
200
204
|
'name' => 'standard',
|
201
205
|
'elements' => ['article'],
|
202
206
|
'cells' => ['header']
|
203
207
|
})
|
204
|
-
Cell.stub(:definition_for).and_return({'name' => 'header', 'elements' => ['article']})
|
205
208
|
clipboard['elements'] = [{'id' => element_in_clipboard.id.to_s}]
|
206
209
|
end
|
207
210
|
|
208
211
|
context "and cell name in element name" do
|
212
|
+
before do
|
213
|
+
expect(Cell).to receive(:definition_for).at_least(:once).and_return({
|
214
|
+
'name' => 'header',
|
215
|
+
'elements' => ['article']
|
216
|
+
})
|
217
|
+
end
|
218
|
+
|
209
219
|
it "should create the element in the correct cell" do
|
210
|
-
xhr :post, :create, {:
|
211
|
-
|
220
|
+
xhr :post, :create, {element: {page_id: page.id}, paste_from_clipboard: "#{element_in_clipboard.id}##{cell.name}"}
|
221
|
+
expect(cell.elements.first).to be_an_instance_of(Element)
|
212
222
|
end
|
213
|
-
end
|
214
223
|
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
224
|
+
context "with elements already in cell" do
|
225
|
+
before do
|
226
|
+
cell.elements.create(page_id: page.id, name: "article", create_contents_after_create: false)
|
227
|
+
end
|
228
|
+
|
229
|
+
it "should set the correct position for the element" do
|
230
|
+
xhr :post, :create, {element: {page_id: page.id}, paste_from_clipboard: "#{element_in_clipboard.id}##{cell.name}"}
|
231
|
+
expect(cell.elements.last.position).to eq(cell.elements.count)
|
232
|
+
end
|
219
233
|
end
|
220
234
|
end
|
221
235
|
|
222
|
-
context "" do
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
xhr :post, :create, {:element => {:page_id => @page.id}, :paste_from_clipboard => "#{element_in_clipboard.id}##{@cell.name}"}
|
227
|
-
@cell.elements.last.position.should == @cell.elements.count
|
236
|
+
context "and no cell name in element name" do
|
237
|
+
it "should create the element in the nil cell" do
|
238
|
+
xhr :post, :create, {element: {page_id: page.id}, paste_from_clipboard: "#{element_in_clipboard.id}"}
|
239
|
+
expect(page.elements.first.cell).to eq(nil)
|
228
240
|
end
|
229
241
|
end
|
230
242
|
end
|
231
243
|
|
232
244
|
context "on a page with a setting for insert_elements_at of top" do
|
233
|
-
let(:alchemy_page) { create(:public_page, :
|
234
|
-
let(:element_in_clipboard) { create(:element, :
|
235
|
-
let(:cell) { alchemy_page
|
236
|
-
let(:element) { create(:element, :
|
245
|
+
let!(:alchemy_page) { create(:public_page, name: 'News') }
|
246
|
+
let!(:element_in_clipboard) { create(:element, page: alchemy_page, name: 'news') }
|
247
|
+
let!(:cell) { create(:cell, name: 'news', page: alchemy_page) }
|
248
|
+
let!(:element) { create(:element, name: 'news', page: alchemy_page, cell: cell) }
|
237
249
|
|
238
250
|
before do
|
239
|
-
PageLayout.
|
251
|
+
expect(PageLayout).to receive(:get).at_least(:once).and_return({
|
240
252
|
'name' => 'news',
|
241
253
|
'elements' => ['news'],
|
242
254
|
'insert_elements_at' => 'top',
|
243
255
|
'cells' => ['news']
|
244
256
|
})
|
245
|
-
Cell.
|
257
|
+
expect(Cell).to receive(:definition_for).and_return({
|
258
|
+
'name' => 'news',
|
259
|
+
'elements' => ['news']
|
260
|
+
})
|
246
261
|
clipboard['elements'] = [{'id' => element_in_clipboard.id.to_s}]
|
247
262
|
cell.elements << element
|
248
263
|
end
|
249
264
|
|
250
265
|
it "should insert the element at top of list" do
|
251
|
-
xhr :post, :create, {:
|
252
|
-
cell.elements.count.
|
253
|
-
cell.elements.first.name.
|
254
|
-
cell.elements.first.
|
266
|
+
xhr :post, :create, {element: {name: 'news', page_id: alchemy_page.id}, paste_from_clipboard: "#{element_in_clipboard.id}##{cell.name}"}
|
267
|
+
expect(cell.elements.count).to eq(2)
|
268
|
+
expect(cell.elements.first.name).to eq('news')
|
269
|
+
expect(cell.elements.first).not_to eq(element)
|
255
270
|
end
|
256
271
|
end
|
257
272
|
end
|
258
273
|
end
|
259
274
|
|
260
|
-
context "
|
275
|
+
context "pasting from clipboard" do
|
261
276
|
render_views
|
262
277
|
|
263
278
|
before do
|
@@ -266,14 +281,14 @@ module Alchemy
|
|
266
281
|
|
267
282
|
it "should create an element from clipboard" do
|
268
283
|
xhr :post, :create, {paste_from_clipboard: element_in_clipboard.id, element: {page_id: alchemy_page.id}}
|
269
|
-
response.status.
|
270
|
-
response.body.
|
284
|
+
expect(response.status).to eq(200)
|
285
|
+
expect(response.body).to match(/Successfully added new element/)
|
271
286
|
end
|
272
287
|
|
273
288
|
context "and with cut as action parameter" do
|
274
289
|
it "should also remove the element id from clipboard" do
|
275
290
|
xhr :post, :create, {paste_from_clipboard: element_in_clipboard.id, element: {page_id: alchemy_page.id}}
|
276
|
-
session[:alchemy_clipboard]['elements'].detect { |item| item['id'] == element_in_clipboard.id.to_s }.
|
291
|
+
expect(session[:alchemy_clipboard]['elements'].detect { |item| item['id'] == element_in_clipboard.id.to_s }).to be_nil
|
277
292
|
end
|
278
293
|
end
|
279
294
|
end
|
@@ -281,7 +296,9 @@ module Alchemy
|
|
281
296
|
context 'if element could not be saved' do
|
282
297
|
subject { post :create, {element: {page_id: alchemy_page.id}} }
|
283
298
|
|
284
|
-
before
|
299
|
+
before do
|
300
|
+
expect_any_instance_of(Element).to receive(:save).and_return false
|
301
|
+
end
|
285
302
|
|
286
303
|
it "renders the new template" do
|
287
304
|
expect(subject).to render_template(:new)
|
@@ -291,13 +308,16 @@ module Alchemy
|
|
291
308
|
|
292
309
|
describe '#find_or_create_cell' do
|
293
310
|
before do
|
294
|
-
Cell.stub(:definition_for).and_return({'name' => 'header', 'elements' => ['header']})
|
295
311
|
controller.instance_variable_set(:@page, alchemy_page)
|
296
312
|
end
|
297
313
|
|
298
314
|
context "with element name and cell name in the params" do
|
299
315
|
before do
|
300
|
-
|
316
|
+
expect(Cell).to receive(:definition_for).and_return({
|
317
|
+
'name' => 'header',
|
318
|
+
'elements' => ['header']
|
319
|
+
})
|
320
|
+
expect(controller).to receive(:params).and_return({element: {name: 'header#header'}})
|
301
321
|
end
|
302
322
|
|
303
323
|
context "with cell not existing" do
|
@@ -323,18 +343,18 @@ module Alchemy
|
|
323
343
|
|
324
344
|
context "with only the element name in the params" do
|
325
345
|
before do
|
326
|
-
controller.
|
346
|
+
expect(controller).to receive(:params).and_return({element: {name: 'header'}})
|
327
347
|
end
|
328
348
|
|
329
349
|
it "should return nil" do
|
330
|
-
controller.send(:find_or_create_cell).
|
350
|
+
expect(controller.send(:find_or_create_cell)).to be_nil
|
331
351
|
end
|
332
352
|
end
|
333
353
|
|
334
354
|
context 'with cell definition not found' do
|
335
355
|
before do
|
336
|
-
controller.
|
337
|
-
Cell.
|
356
|
+
expect(controller).to receive(:params).and_return({element: {name: 'header#header'}})
|
357
|
+
expect(Cell).to receive(:definition_for).and_return nil
|
338
358
|
end
|
339
359
|
|
340
360
|
it "raises error" do
|
@@ -350,27 +370,27 @@ module Alchemy
|
|
350
370
|
let(:element_parameters) { ActionController::Parameters.new(tag_list: 'Tag 1', public: false) }
|
351
371
|
|
352
372
|
before do
|
353
|
-
Element.
|
354
|
-
controller.
|
373
|
+
expect(Element).to receive(:find).and_return element
|
374
|
+
expect(controller).to receive(:contents_params).and_return(contents_parameters)
|
355
375
|
end
|
356
376
|
|
357
377
|
it "updates all contents in element" do
|
358
|
-
element.
|
378
|
+
expect(element).to receive(:update_contents).with(contents_parameters)
|
359
379
|
xhr :put, :update, {id: element.id}
|
360
380
|
end
|
361
381
|
|
362
382
|
it "updates the element" do
|
363
|
-
controller.
|
364
|
-
element.
|
365
|
-
element.
|
383
|
+
expect(controller).to receive(:element_params).and_return(element_parameters)
|
384
|
+
expect(element).to receive(:update_contents).and_return(true)
|
385
|
+
expect(element).to receive(:update_attributes!).with(element_parameters).and_return(true)
|
366
386
|
xhr :put, :update, {id: element.id}
|
367
387
|
end
|
368
388
|
|
369
389
|
context "failed validations" do
|
370
390
|
it "displays validation failed notice" do
|
371
|
-
element.
|
391
|
+
expect(element).to receive(:update_contents).and_return(false)
|
372
392
|
xhr :put, :update, {id: element.id}
|
373
|
-
assigns(:element_validated).
|
393
|
+
expect(assigns(:element_validated)).to be_falsey
|
374
394
|
end
|
375
395
|
end
|
376
396
|
end
|
@@ -380,14 +400,14 @@ module Alchemy
|
|
380
400
|
let(:parameters) { ActionController::Parameters.new(contents: {1 => {ingredient: 'Title'}}) }
|
381
401
|
|
382
402
|
specify ":contents is required" do
|
383
|
-
controller.params.
|
403
|
+
expect(controller.params).to receive(:fetch).and_return(parameters)
|
384
404
|
controller.send :contents_params
|
385
405
|
end
|
386
406
|
|
387
407
|
specify "everything is permitted" do
|
388
|
-
controller.
|
389
|
-
parameters.
|
390
|
-
parameters.
|
408
|
+
expect(controller).to receive(:params).and_return(parameters)
|
409
|
+
expect(parameters).to receive(:fetch).and_return(parameters)
|
410
|
+
expect(parameters).to receive(:permit!)
|
391
411
|
controller.send :contents_params
|
392
412
|
end
|
393
413
|
end
|
@@ -396,14 +416,14 @@ module Alchemy
|
|
396
416
|
let(:parameters) { ActionController::Parameters.new(element: {public: true}) }
|
397
417
|
|
398
418
|
specify ":element is required" do
|
399
|
-
controller.params.
|
419
|
+
expect(controller.params).to receive(:require).with(:element).and_return(parameters)
|
400
420
|
controller.send :element_params
|
401
421
|
end
|
402
422
|
|
403
423
|
specify ":public and :tag_list is permitted" do
|
404
|
-
controller.
|
405
|
-
parameters.
|
406
|
-
parameters.
|
424
|
+
expect(controller).to receive(:params).and_return(parameters)
|
425
|
+
expect(parameters).to receive(:require).with(:element).and_return(parameters)
|
426
|
+
expect(parameters).to receive(:permit).with(:public, :tag_list)
|
407
427
|
controller.send :element_params
|
408
428
|
end
|
409
429
|
end
|
@@ -414,10 +434,10 @@ module Alchemy
|
|
414
434
|
|
415
435
|
let(:element) { build_stubbed(:element) }
|
416
436
|
|
417
|
-
before { Element.
|
437
|
+
before { expect(Element).to receive(:find).and_return element }
|
418
438
|
|
419
439
|
it "trashes the element instead of deleting it" do
|
420
|
-
element.
|
440
|
+
expect(element).to receive(:trash!).and_return(true)
|
421
441
|
subject
|
422
442
|
end
|
423
443
|
end
|
@@ -428,24 +448,24 @@ module Alchemy
|
|
428
448
|
let(:element) { build_stubbed(:element) }
|
429
449
|
|
430
450
|
before do
|
431
|
-
element.
|
432
|
-
Element.
|
451
|
+
expect(element).to receive(:save).and_return true
|
452
|
+
expect(Element).to receive(:find).and_return element
|
433
453
|
end
|
434
454
|
|
435
455
|
context 'if element is folded' do
|
436
|
-
before { element.
|
456
|
+
before { expect(element).to receive(:folded).and_return true }
|
437
457
|
|
438
458
|
it "sets folded to false." do
|
439
|
-
element.
|
459
|
+
expect(element).to receive(:folded=).with(false).and_return(true)
|
440
460
|
subject
|
441
461
|
end
|
442
462
|
end
|
443
463
|
|
444
464
|
context 'if element is not folded' do
|
445
|
-
before { element.
|
465
|
+
before { expect(element).to receive(:folded).and_return false }
|
446
466
|
|
447
467
|
it "sets folded to true." do
|
448
|
-
element.
|
468
|
+
expect(element).to receive(:folded=).with(true).and_return(true)
|
449
469
|
subject
|
450
470
|
end
|
451
471
|
end
|