diff --git a/app/views/alchemy/essences/_essence_select_editor.html.erb b/app/views/alchemy/essences/_essence_select_editor.html.erb
index 0911c477bd..414c3d953c 100644
--- a/app/views/alchemy/essences/_essence_select_editor.html.erb
+++ b/app/views/alchemy/essences/_essence_select_editor.html.erb
@@ -1,21 +1,19 @@
-<% select_values = content.settings_value(:select_values, local_assigns.fetch(:options, {})) %>
-<% inline = content.settings_value(:display_inline, local_assigns.fetch(:options, {})) %>
-<% html_options = local_assigns.fetch(:html_options, {}) %>
+<% select_values = content.settings[:select_values] %>
<%= content_tag :div,
id: content.dom_id,
class: [
"content_editor",
"essence_select",
- inline ? 'display_inline' : nil
+ content.settings[:display_inline] ? 'display_inline' : nil
].compact, data: {content_id: content.id} do %>
<%= content_label(content) %>
<% if select_values.nil? %>
<%= warning(':select_values is nil',
"
.") %>
<% else %>
<%
@@ -25,8 +23,7 @@
options_tags = options_for_select(select_values, content.ingredient)
end %>
<%= select_tag content.form_field_name, options_tags, {
- class: ["alchemy_selectbox", "essence_editor_select", html_options[:class]].compact,
- style: html_options[:style]
+ class: ["alchemy_selectbox", "essence_editor_select"]
} %>
<% end %>
<% end %>
diff --git a/app/views/alchemy/essences/_essence_text_editor.html.erb b/app/views/alchemy/essences/_essence_text_editor.html.erb
index f7ec09a272..19d46e53bb 100644
--- a/app/views/alchemy/essences/_essence_text_editor.html.erb
+++ b/app/views/alchemy/essences/_essence_text_editor.html.erb
@@ -1,14 +1,10 @@
-<% options = local_assigns.fetch(:options, {}) %>
-<% html_options = local_assigns.fetch(:html_options, {}) %>
-
-
+
<%= content_label(content) %>
<%= text_field_tag(
content.form_field_name,
content.ingredient,
- class: ["thin_border #{content.settings[:linkable] ? ' text_with_icon' : ''}", html_options[:class]].join(' '),
- style: html_options[:style],
- type: content.settings_value(:input_type) || "text"
+ class: "thin_border #{content.settings[:linkable] ? ' text_with_icon' : ''}",
+ type: content.settings[:input_type] || "text"
) %>
<% if content.settings[:linkable] %>
<%= hidden_field_tag content.form_field_name(:link), content.essence.link %>
diff --git a/app/views/alchemy/essences/shared/_essence_picture_tools.html.erb b/app/views/alchemy/essences/shared/_essence_picture_tools.html.erb
index cb1c874bae..440cc2e968 100644
--- a/app/views/alchemy/essences/shared/_essence_picture_tools.html.erb
+++ b/app/views/alchemy/essences/shared/_essence_picture_tools.html.erb
@@ -1,11 +1,8 @@
-<% linkable = content.settings_value(:linkable, options) != false %>
+<% linkable = content.settings[:linkable] != false %>
-<% if content.essence && content.essence.allow_image_cropping?(options) %>
+<% if content.essence && content.essence.allow_image_cropping? %>
<%= link_to_dialog render_icon(:crop),
- alchemy.crop_admin_essence_picture_path(
- content.essence,
- options: content.settings.update(options)
- ), {
+ alchemy.crop_admin_essence_picture_path(content.essence), {
size: "1080x615",
title: Alchemy.t('Edit Picturemask'),
image_loader: false,
@@ -19,8 +16,7 @@
alchemy.admin_pictures_path(
element_id: content.element,
content_id: content.id,
- swap: true,
- options: options
+ swap: true
),
{
title: (content.ingredient ? Alchemy.t(:swap_image) : Alchemy.t(:insert_image)),
@@ -51,9 +47,8 @@
<%= link_to_dialog render_icon(:edit),
alchemy.edit_admin_essence_picture_path(
id: content.essence.id,
- content_id: content.id,
- options: options
+ content_id: content.id
), {
title: Alchemy.t(:edit_image_properties),
- size: edit_picture_dialog_size(content, options)
+ size: edit_picture_dialog_size(content)
}, title: Alchemy.t(:edit_image_properties) %>
diff --git a/lib/rails/generators/alchemy/essence/templates/editor.html.erb b/lib/rails/generators/alchemy/essence/templates/editor.html.erb
index ff4c7973d8..4fe06ba0b1 100644
--- a/lib/rails/generators/alchemy/essence/templates/editor.html.erb
+++ b/lib/rails/generators/alchemy/essence/templates/editor.html.erb
@@ -1,7 +1,6 @@
<%%#
Available locals:
* content (The object the essence is linked to the element)
- * html_options
Please consult Alchemy::Content.rb docs for further methods on the content object
%>
diff --git a/spec/helpers/alchemy/elements_block_helper_spec.rb b/spec/helpers/alchemy/elements_block_helper_spec.rb
index 0291d657fd..05474e2cde 100644
--- a/spec/helpers/alchemy/elements_block_helper_spec.rb
+++ b/spec/helpers/alchemy/elements_block_helper_spec.rb
@@ -137,8 +137,8 @@ module Alchemy
describe '#edit' do
it "should delegate to the render_essence_editor_by_name helper" do
- expect(scope).to receive(:render_essence_editor_by_name).with(element, "title", foo: 'bar')
- subject.edit :title, foo: 'bar'
+ expect(scope).to receive(:render_essence_editor_by_name).with(element, "title")
+ subject.edit(:title)
end
end
end
diff --git a/spec/views/essences/essence_boolean_editor_spec.rb b/spec/views/essences/essence_boolean_editor_spec.rb
index b48273742a..c557cb1c2c 100644
--- a/spec/views/essences/essence_boolean_editor_spec.rb
+++ b/spec/views/essences/essence_boolean_editor_spec.rb
@@ -3,28 +3,36 @@
require 'rails_helper'
describe 'alchemy/essences/_essence_boolean_editor' do
- let(:essence) { Alchemy::EssenceBoolean.new(ingredient: false) }
- let(:content) { Alchemy::Content.new(essence: essence, name: 'Boolean') }
+ let(:element) { create(:alchemy_element, name: 'all_you_can_eat') }
+ let(:content) { Alchemy::Content.create(name: 'essence_boolean', type: 'EssenceBoolean', element: element) }
+
+ let(:content_definition) do
+ {
+ name: 'essence_boolean',
+ type: 'EssenceBoolean'
+ }.with_indifferent_access
+ end
before do
+ expect(element).to receive(:content_definition_for) { content_definition }
+ allow_any_instance_of(Alchemy::Content).to receive(:definition) { content_definition }
allow(view).to receive(:render_content_name).and_return(content.name)
allow(view).to receive(:render_hint_for).and_return('')
end
- it "renders a checkbox" do
+ it "renders an unchecked checkbox" do
render partial: "alchemy/essences/essence_boolean_editor", locals: {content: content}
expect(rendered).to have_selector('input[type="checkbox"]')
end
- context 'with default value given in view local options' do
- it "checks the checkbox" do
- render partial: "alchemy/essences/essence_boolean_editor", locals: {content: content, options: {default_value: true}}
- expect(rendered).to have_selector('input[type="checkbox"][checked="checked"]')
- end
- end
-
context 'with default value given in content settings' do
- before { allow(content).to receive(:settings).and_return({default_value: true}) }
+ let(:content_definition) do
+ {
+ name: 'essence_boolean',
+ type: 'EssenceBoolean',
+ default: true
+ }.with_indifferent_access
+ end
it "checks the checkbox" do
render partial: "alchemy/essences/essence_boolean_editor", locals: {content: content}
diff --git a/spec/views/essences/essence_date_editor_spec.rb b/spec/views/essences/essence_date_editor_spec.rb
new file mode 100644
index 0000000000..71daea2705
--- /dev/null
+++ b/spec/views/essences/essence_date_editor_spec.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+RSpec.describe 'alchemy/essences/_essence_date_editor' do
+ let(:content) { Alchemy::Content.new(essence: essence) }
+ let(:essence) { Alchemy::EssenceDate.new }
+
+ before do
+ view.class.send(:include, Alchemy::Admin::BaseHelper)
+ allow(view).to receive(:content_label).and_return(content.name)
+ end
+
+ it "renders a datepicker" do
+ render 'alchemy/essences/essence_date_editor', content: content
+ expect(rendered).to have_css('input[type="text"][data-datepicker-type="date"].date')
+ end
+end
diff --git a/spec/views/essences/essence_picture_editor_spec.rb b/spec/views/essences/essence_picture_editor_spec.rb
index c452563ebf..2ac980fb1f 100644
--- a/spec/views/essences/essence_picture_editor_spec.rb
+++ b/spec/views/essences/essence_picture_editor_spec.rb
@@ -22,7 +22,7 @@
)
end
- let(:options) { Hash.new }
+ let(:settings) { Hash.new }
before do
view.class.send(:include, Alchemy::Admin::BaseHelper)
@@ -32,8 +32,9 @@
end
subject do
+ allow(content).to receive(:settings) { settings }
render partial: "alchemy/essences/essence_picture_editor",
- locals: {content: content, options: options}
+ locals: {content: content}
rendered
end
@@ -45,8 +46,10 @@
end
context "with settings[:deletable] being false" do
- let(:options) do
- {linkable: false}
+ let(:settings) do
+ {
+ linkable: false
+ }
end
it 'should not render a button to link and unlink the picture' do
diff --git a/spec/views/essences/essence_select_editor_spec.rb b/spec/views/essences/essence_select_editor_spec.rb
new file mode 100644
index 0000000000..8043ecc693
--- /dev/null
+++ b/spec/views/essences/essence_select_editor_spec.rb
@@ -0,0 +1,35 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+RSpec.describe 'alchemy/essences/_essence_select_editor' do
+ let(:content) { Alchemy::Content.new(essence: essence) }
+ let(:essence) { Alchemy::EssenceSelect.new }
+
+ before do
+ view.class.send(:include, Alchemy::Admin::BaseHelper)
+ allow(view).to receive(:content_label).and_return(content.name)
+ end
+
+ context 'if no select values are set' do
+ it 'renders a warning' do
+ render 'alchemy/essences/essence_select_editor', content: content
+ expect(rendered).to have_css('.warning')
+ end
+ end
+
+ context 'if select values are set' do
+ before do
+ allow(content).to receive(:settings) do
+ {
+ select_values: %w(red blue yellow)
+ }
+ end
+ end
+
+ it "renders a select box" do
+ render 'alchemy/essences/essence_select_editor', content: content
+ expect(rendered).to have_css('select.alchemy_selectbox')
+ end
+ end
+end
diff --git a/spec/views/essences/essence_text_editor_spec.rb b/spec/views/essences/essence_text_editor_spec.rb
index 9cb51987c9..bf10bab972 100644
--- a/spec/views/essences/essence_text_editor_spec.rb
+++ b/spec/views/essences/essence_text_editor_spec.rb
@@ -5,28 +5,49 @@
describe 'alchemy/essences/_essence_text_editor' do
let(:essence) { Alchemy::EssenceText.new(body: '1234') }
let(:content) { Alchemy::Content.new(essence: essence) }
+ let(:settings) { {} }
- context 'with no input type set' do
- before do
- allow(view).to receive(:content_label).and_return("1e Zahl")
- allow(content).to receive(:settings).and_return({})
- end
+ subject do
+ render partial: "alchemy/essences/essence_text_editor", locals: { content: content }
+ end
+ before do
+ view.class.send :include, Alchemy::Admin::BaseHelper
+ allow(view).to receive(:content_label).and_return("1e Zahl")
+ allow(content).to receive(:settings) { settings }
+ subject
+ end
+
+ context 'with no input type set' do
it "renders an input field of type number" do
- render partial: "alchemy/essences/essence_text_editor", locals: {content: content, options: {}, html_options: {}}
expect(rendered).to have_selector('input[type="text"]')
end
end
context 'with a different input type set' do
- before do
- allow(view).to receive(:content_label).and_return("1e Zahl")
- allow(content).to receive(:settings).and_return({input_type: "number"})
+ let(:settings) do
+ {
+ input_type: "number"
+ }
end
it "renders an input field of type number" do
- render partial: "alchemy/essences/essence_text_editor", locals: {content: content, options: {}, html_options: {}}
expect(rendered).to have_selector('input[type="number"]')
end
end
+
+ context 'with settings linkable set to true' do
+ let(:settings) do
+ {
+ linkable: true
+ }
+ end
+
+ it "renders link buttons" do
+ expect(rendered).to have_selector('input[type="hidden"][name="contents[][link]"]')
+ expect(rendered).to have_selector('input[type="hidden"][name="contents[][link_title]"]')
+ expect(rendered).to have_selector('input[type="hidden"][name="contents[][link_class_name]"]')
+ expect(rendered).to have_selector('input[type="hidden"][name="contents[][link_target]"]')
+ end
+ end
end