ckeditor5 1.15.9 → 1.15.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ckeditor5/rails/engine.rb +3 -2
- data/lib/ckeditor5/rails/presets/plugins_builder.rb +9 -9
- data/lib/ckeditor5/rails/presets/preset_builder.rb +4 -6
- data/lib/ckeditor5/rails/version.rb +1 -1
- data/spec/lib/ckeditor5/rails/assets/asset_bundle_hml_serializer_spec.rb +7 -0
- data/spec/lib/ckeditor5/rails/cdn/helpers_spec.rb +19 -1
- data/spec/lib/ckeditor5/rails/engine_spec.rb +88 -0
- data/spec/lib/ckeditor5/rails/hooks/form_spec.rb +156 -0
- data/spec/lib/ckeditor5/rails/hooks/simple_form_spec.rb +100 -0
- data/spec/lib/ckeditor5/rails/presets/plugins_builder_spec.rb +10 -10
- data/spec/lib/ckeditor5/rails/presets/preset_builder_spec.rb +10 -0
- data/spec/spec_helper.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1cdcc72197788bc6dc57bb3b01158c932dbf27621084414bc832c5d772e01701
|
4
|
+
data.tar.gz: 7d6874e08d93346f9d478f46e2240bbc5df78a32700f50087de8fe8e4301cfc8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7dc9311974b2dd72a05fd61cea086585179e64700f800618d06f4bffd079f31ad99d31f1ea5917d7c28cdd4e03d675122b546d25518ed43a99928f2061afd448
|
7
|
+
data.tar.gz: 199da996b61646c658dbbe0c8119419220b669442a5eba6fc1c973dad7793e3db8e3a1e8808e075e8d0477236fd8741fa2927eae9c141fc7bb87364df6fee7ae
|
@@ -45,7 +45,7 @@ module CKEditor5::Rails
|
|
45
45
|
def find_preset(preset)
|
46
46
|
return preset if preset.is_a?(CKEditor5::Rails::Presets::PresetBuilder)
|
47
47
|
|
48
|
-
|
48
|
+
base.presets[preset]
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
@@ -54,7 +54,8 @@ module CKEditor5::Rails
|
|
54
54
|
|
55
55
|
delegate :version, :gpl, :premium, :cdn, :translations, :license_key,
|
56
56
|
:type, :menubar, :toolbar, :plugins, :plugin, :inline_plugin,
|
57
|
-
:language, :ckbox, :configure,
|
57
|
+
:language, :ckbox, :configure, :automatic_upgrades, :simple_upload_adapter,
|
58
|
+
:editable_height, to: :default_preset
|
58
59
|
|
59
60
|
def initialize(configuration)
|
60
61
|
@configuration = configuration
|
@@ -2,10 +2,10 @@
|
|
2
2
|
|
3
3
|
module CKEditor5::Rails
|
4
4
|
class Presets::PluginsBuilder
|
5
|
-
attr_reader :
|
5
|
+
attr_reader :items
|
6
6
|
|
7
7
|
def initialize(plugins)
|
8
|
-
@
|
8
|
+
@items = plugins
|
9
9
|
end
|
10
10
|
|
11
11
|
def self.create_plugin(name, **kwargs)
|
@@ -17,19 +17,19 @@ module CKEditor5::Rails
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def remove(*names)
|
20
|
-
names.each { |name|
|
20
|
+
names.each { |name| items.delete_if { |plugin| plugin.name == name } }
|
21
21
|
end
|
22
22
|
|
23
23
|
def prepend(*names, before: nil, **kwargs)
|
24
24
|
new_plugins = names.map { |name| self.class.create_plugin(name, **kwargs) }
|
25
25
|
|
26
26
|
if before
|
27
|
-
index =
|
27
|
+
index = items.index { |p| p.name == before }
|
28
28
|
raise ArgumentError, "Plugin '#{before}' not found" unless index
|
29
29
|
|
30
|
-
|
30
|
+
items.insert(index, *new_plugins)
|
31
31
|
else
|
32
|
-
|
32
|
+
items.insert(0, *new_plugins)
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
@@ -37,12 +37,12 @@ module CKEditor5::Rails
|
|
37
37
|
new_plugins = names.map { |name| self.class.create_plugin(name, **kwargs) }
|
38
38
|
|
39
39
|
if after
|
40
|
-
index =
|
40
|
+
index = items.index { |p| p.name == after }
|
41
41
|
raise ArgumentError, "Plugin '#{after}' not found" unless index
|
42
42
|
|
43
|
-
|
43
|
+
items.insert(index + 1, *new_plugins)
|
44
44
|
else
|
45
|
-
|
45
|
+
items.push(*new_plugins)
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
@@ -162,10 +162,9 @@ module CKEditor5::Rails
|
|
162
162
|
}
|
163
163
|
end
|
164
164
|
|
165
|
-
return unless block
|
166
|
-
|
167
165
|
builder = ToolbarBuilder.new(@config[:toolbar][:items])
|
168
|
-
builder.instance_eval(&block)
|
166
|
+
builder.instance_eval(&block) if block_given?
|
167
|
+
builder
|
169
168
|
end
|
170
169
|
|
171
170
|
def inline_plugin(name, code)
|
@@ -183,10 +182,9 @@ module CKEditor5::Rails
|
|
183
182
|
|
184
183
|
names.each { |name| plugin(name, **kwargs) } unless names.empty?
|
185
184
|
|
186
|
-
return unless block
|
187
|
-
|
188
185
|
builder = PluginsBuilder.new(@config[:plugins])
|
189
|
-
builder.instance_eval(&block)
|
186
|
+
builder.instance_eval(&block) if block_given?
|
187
|
+
builder
|
190
188
|
end
|
191
189
|
|
192
190
|
def language(ui = nil, content: ui) # rubocop:disable Naming/MethodParameterName
|
@@ -86,6 +86,13 @@ RSpec.describe CKEditor5::Rails::Assets::AssetsBundleHtmlSerializer do
|
|
86
86
|
it 'includes web component script' do
|
87
87
|
expect(html).to include('<script type="module" nonce="true">')
|
88
88
|
end
|
89
|
+
|
90
|
+
it 'memoizes scripts import map' do
|
91
|
+
first_call = serializer.send(:scripts_import_map_tag)
|
92
|
+
second_call = serializer.send(:scripts_import_map_tag)
|
93
|
+
|
94
|
+
expect(first_call.object_id).to eq(second_call.object_id)
|
95
|
+
end
|
89
96
|
end
|
90
97
|
|
91
98
|
describe '.url_resource_preload_type' do
|
@@ -160,7 +160,25 @@ RSpec.describe CKEditor5::Rails::Cdn::Helpers do
|
|
160
160
|
)
|
161
161
|
end
|
162
162
|
|
163
|
-
|
163
|
+
before do
|
164
|
+
allow(helper).to receive(:merge_with_editor_preset).and_return({})
|
165
|
+
end
|
166
|
+
|
167
|
+
it 'raises error about missing required parameters' do
|
168
|
+
expect { helper.ckeditor5_assets(preset: :default) }
|
169
|
+
.to raise_error(NoMatchingPatternKeyError)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
context 'with empty hash from preset' do
|
174
|
+
let(:preset) do
|
175
|
+
instance_double(
|
176
|
+
CKEditor5::Rails::Presets::PresetBuilder,
|
177
|
+
to_h_with_overrides: {}
|
178
|
+
)
|
179
|
+
end
|
180
|
+
|
181
|
+
it 'raises error about missing version and type' do
|
164
182
|
expect { helper.ckeditor5_assets(preset: :default) }
|
165
183
|
.to raise_error(ArgumentError, /forgot to define version/)
|
166
184
|
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe CKEditor5::Rails::Engine do
|
6
|
+
describe 'configuration' do
|
7
|
+
let(:preset) { instance_double(CKEditor5::Rails::Presets::PresetBuilder) }
|
8
|
+
let(:preset_manager) { instance_double(CKEditor5::Rails::Presets::Manager) }
|
9
|
+
|
10
|
+
before do
|
11
|
+
allow(described_class).to receive(:base).and_return(ActiveSupport::OrderedOptions.new)
|
12
|
+
allow(described_class.base).to receive(:presets).and_return(preset_manager)
|
13
|
+
allow(preset_manager).to receive(:default).and_return(preset)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'has default configuration' do
|
17
|
+
expect(described_class.base).to be_a(ActiveSupport::OrderedOptions)
|
18
|
+
|
19
|
+
default_preset = described_class.default_preset
|
20
|
+
|
21
|
+
expect(default_preset.type).to eq(:classic)
|
22
|
+
expect(default_preset.toolbar.items).to include(:undo, :redo, :'|', :heading)
|
23
|
+
expect(default_preset.plugins.items.map(&:name)).to include(:Essentials, :Paragraph, :Heading)
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '.configure' do
|
27
|
+
it 'yields configuration proxy' do
|
28
|
+
yielded_config = nil
|
29
|
+
described_class.configure do |config|
|
30
|
+
yielded_config = config
|
31
|
+
end
|
32
|
+
expect(yielded_config).to be_a(described_class::ConfigurationProxy)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'allows configuring default preset' do
|
36
|
+
described_class.configure do
|
37
|
+
automatic_upgrades enabled: false
|
38
|
+
version '35.0.0'
|
39
|
+
license_key '1234567'
|
40
|
+
end
|
41
|
+
|
42
|
+
expect(described_class.default_preset.version).to eq('35.0.0')
|
43
|
+
expect(described_class.default_preset.license_key).to eq('1234567')
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe '.find_preset' do
|
48
|
+
before do
|
49
|
+
allow(preset_manager).to receive(:[]).with(:custom).and_return(preset)
|
50
|
+
allow(preset_manager).to receive(:[]).with(
|
51
|
+
kind_of(CKEditor5::Rails::Presets::PresetBuilder)
|
52
|
+
).and_return(preset)
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'returns preset instance if provided' do
|
56
|
+
test_preset = CKEditor5::Rails::Presets::PresetBuilder.new
|
57
|
+
expect(described_class.find_preset(test_preset)).to eq(test_preset)
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'looks up preset by name' do
|
61
|
+
expect(described_class.find_preset(:custom)).to eq(preset)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe 'initializers' do
|
67
|
+
describe 'helper initializer' do
|
68
|
+
it 'includes helpers in ActionView and ActionController' do
|
69
|
+
expect(ActionView::Base.included_modules).to include(CKEditor5::Rails::Helpers)
|
70
|
+
expect(ActionController::Base.included_modules).to include(CKEditor5::Rails::Helpers)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe 'form_builder initializer' do
|
75
|
+
it 'includes FormBuilderExtension in ActionView::Helpers::FormBuilder' do
|
76
|
+
expect(ActionView::Helpers::FormBuilder.included_modules)
|
77
|
+
.to include(CKEditor5::Rails::Hooks::Form::FormBuilderExtension)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe 'simple_form initializer', if: defined?(SimpleForm) do
|
82
|
+
it 'registers ckeditor5 input type' do
|
83
|
+
expect(SimpleForm::FormBuilder.mappings[:ckeditor5])
|
84
|
+
.to eq(CKEditor5::Rails::Hooks::SimpleForm::CKEditor5Input)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -42,6 +42,162 @@ RSpec.describe CKEditor5::Rails::Hooks::Form do
|
|
42
42
|
})
|
43
43
|
end
|
44
44
|
end
|
45
|
+
|
46
|
+
context 'with as parameter' do
|
47
|
+
subject(:rendered_editor) do
|
48
|
+
builder.build_editor(:content, as: 'custom_field')
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'uses custom field name' do
|
52
|
+
expect(rendered_editor).to have_tag('ckeditor-component', with: {
|
53
|
+
name: 'post[custom_field]'
|
54
|
+
})
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'without object_name' do
|
59
|
+
let(:builder) { described_class.new('', post, template) }
|
60
|
+
|
61
|
+
it 'uses method name as field name' do
|
62
|
+
expect(rendered_editor).to have_tag('ckeditor-component', with: {
|
63
|
+
name: 'content'
|
64
|
+
})
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'with as parameter' do
|
68
|
+
subject(:rendered_editor) do
|
69
|
+
builder.build_editor(:content, as: 'custom_field')
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'uses as parameter as field name' do
|
73
|
+
expect(rendered_editor).to have_tag('ckeditor-component', with: {
|
74
|
+
name: 'custom_field'
|
75
|
+
})
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context 'with initial data handling' do
|
81
|
+
before do
|
82
|
+
allow(template).to receive(:ckeditor5_editor)
|
83
|
+
end
|
84
|
+
|
85
|
+
context 'when object responds to the method' do
|
86
|
+
it 'passes object method value as initial_data' do
|
87
|
+
builder.build_editor(:content)
|
88
|
+
|
89
|
+
expect(template).to have_received(:ckeditor5_editor)
|
90
|
+
.with(hash_including(initial_data: 'Initial content'))
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
context 'when object does not respond to the method' do
|
95
|
+
let(:post) { double('Post') }
|
96
|
+
|
97
|
+
it 'passes options initial_data value' do
|
98
|
+
builder.build_editor(:content, initial_data: 'Provided content')
|
99
|
+
|
100
|
+
expect(template).to have_received(:ckeditor5_editor)
|
101
|
+
.with(hash_including(initial_data: 'Provided content'))
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
context 'with validation classes handling' do
|
107
|
+
before do
|
108
|
+
allow(template).to receive(:ckeditor5_editor)
|
109
|
+
end
|
110
|
+
|
111
|
+
context 'when object has errors on the field' do
|
112
|
+
let(:post) do
|
113
|
+
instance_double('Post', errors: { content: ['is invalid'] })
|
114
|
+
end
|
115
|
+
|
116
|
+
it 'adds is-invalid class' do
|
117
|
+
builder.build_editor(:content, class: 'custom-class')
|
118
|
+
|
119
|
+
expect(template).to have_received(:ckeditor5_editor)
|
120
|
+
.with(hash_including(class: 'custom-class is-invalid'))
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'adds is-invalid class when no initial class exists' do
|
124
|
+
builder.build_editor(:content)
|
125
|
+
|
126
|
+
expect(template).to have_received(:ckeditor5_editor)
|
127
|
+
.with(hash_including(class: 'is-invalid'))
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
context 'when object has no errors' do
|
132
|
+
let(:post) do
|
133
|
+
instance_double('Post', errors: {})
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'keeps original class unchanged' do
|
137
|
+
builder.build_editor(:content, class: 'custom-class')
|
138
|
+
|
139
|
+
expect(template).to have_received(:ckeditor5_editor)
|
140
|
+
.with(hash_including(class: 'custom-class'))
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
context 'when object does not respond to errors' do
|
145
|
+
let(:post) { double('Post') }
|
146
|
+
|
147
|
+
it 'keeps original class unchanged' do
|
148
|
+
builder.build_editor(:content, class: 'custom-class')
|
149
|
+
|
150
|
+
expect(template).to have_received(:ckeditor5_editor)
|
151
|
+
.with(hash_including(class: 'custom-class'))
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
describe CKEditor5::Rails::Hooks::Form::FormBuilderExtension do
|
159
|
+
let(:template) { instance_double('ActionView::Base') }
|
160
|
+
let(:object) { double('Post') }
|
161
|
+
let(:builder) do
|
162
|
+
Class.new do
|
163
|
+
include CKEditor5::Rails::Hooks::Form::FormBuilderExtension
|
164
|
+
attr_reader :object_name, :object, :template
|
165
|
+
|
166
|
+
def initialize(object_name, object, template)
|
167
|
+
@object_name = object_name
|
168
|
+
@object = object
|
169
|
+
@template = template
|
170
|
+
end
|
171
|
+
end.new('post', object, template)
|
172
|
+
end
|
173
|
+
|
174
|
+
describe '#ckeditor5' do
|
175
|
+
let(:input_builder) { instance_double(CKEditor5::Rails::Hooks::Form::EditorInputBuilder) }
|
176
|
+
|
177
|
+
before do
|
178
|
+
allow(CKEditor5::Rails::Hooks::Form::EditorInputBuilder)
|
179
|
+
.to receive(:new)
|
180
|
+
.with('post', object, template)
|
181
|
+
.and_return(input_builder)
|
182
|
+
allow(input_builder).to receive(:build_editor)
|
183
|
+
end
|
184
|
+
|
185
|
+
it 'creates EditorInputBuilder with correct parameters' do
|
186
|
+
builder.ckeditor5(:content, class: 'custom-class')
|
187
|
+
|
188
|
+
expect(CKEditor5::Rails::Hooks::Form::EditorInputBuilder)
|
189
|
+
.to have_received(:new)
|
190
|
+
.with('post', object, template)
|
191
|
+
end
|
192
|
+
|
193
|
+
it 'calls build_editor with correct parameters' do
|
194
|
+
options = { class: 'custom-class' }
|
195
|
+
builder.ckeditor5(:content, options)
|
196
|
+
|
197
|
+
expect(input_builder)
|
198
|
+
.to have_received(:build_editor)
|
199
|
+
.with(:content, options)
|
200
|
+
end
|
45
201
|
end
|
46
202
|
end
|
47
203
|
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe CKEditor5::Rails::Hooks::SimpleForm::CKEditor5Input do
|
6
|
+
let(:template) { instance_double('ActionView::Base') }
|
7
|
+
let(:object) { double('Post', content: 'Initial content') }
|
8
|
+
let(:object_name) { 'post' }
|
9
|
+
let(:builder) do
|
10
|
+
double('FormBuilder',
|
11
|
+
object: object,
|
12
|
+
object_name: object_name,
|
13
|
+
template: template)
|
14
|
+
end
|
15
|
+
let(:attribute_name) { :content }
|
16
|
+
let(:input_html_options) { {} }
|
17
|
+
let(:input_options) { {} }
|
18
|
+
|
19
|
+
subject(:input) do
|
20
|
+
described_class.new(builder, attribute_name, nil, input_html_options, input_options)
|
21
|
+
end
|
22
|
+
|
23
|
+
before do
|
24
|
+
allow(template).to receive(:ckeditor5_editor)
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#input' do
|
28
|
+
it 'renders ckeditor with default options' do
|
29
|
+
input.input
|
30
|
+
|
31
|
+
expect(template).to have_received(:ckeditor5_editor).with(
|
32
|
+
hash_including(
|
33
|
+
preset: :default,
|
34
|
+
type: :classic,
|
35
|
+
config: nil,
|
36
|
+
initial_data: 'Initial content',
|
37
|
+
name: 'post[content]',
|
38
|
+
class: [{}, :required] # Simple Form adds these classes by default
|
39
|
+
)
|
40
|
+
)
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'with custom options' do
|
44
|
+
let(:input_options) do
|
45
|
+
{
|
46
|
+
preset: :custom_preset,
|
47
|
+
type: :inline,
|
48
|
+
config: { toolbar: [:bold] }
|
49
|
+
}
|
50
|
+
end
|
51
|
+
let(:input_html_options) do
|
52
|
+
{ class: 'custom-class', id: 'custom-id' }
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'renders ckeditor with merged options' do
|
56
|
+
input.input
|
57
|
+
|
58
|
+
expect(template).to have_received(:ckeditor5_editor).with(
|
59
|
+
hash_including(
|
60
|
+
preset: :custom_preset,
|
61
|
+
type: :inline,
|
62
|
+
config: { toolbar: [:bold] },
|
63
|
+
initial_data: 'Initial content',
|
64
|
+
name: 'post[content]',
|
65
|
+
class: [{ class: 'custom-class', id: 'custom-id' }, :required]
|
66
|
+
)
|
67
|
+
)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'when object does not respond to attribute' do
|
72
|
+
let(:object) { double('Post') }
|
73
|
+
let(:input_options) { { initial_data: 'Provided content' } }
|
74
|
+
|
75
|
+
it 'uses initial_data from options' do
|
76
|
+
input.input
|
77
|
+
|
78
|
+
expect(template).to have_received(:ckeditor5_editor).with(
|
79
|
+
hash_including(initial_data: 'Provided content')
|
80
|
+
)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
context 'with wrapper options' do
|
85
|
+
let(:wrapper_options) { { wrapper_class: 'wrapper' } }
|
86
|
+
let(:input_html_options) { { class: 'input' } }
|
87
|
+
|
88
|
+
it 'merges wrapper options with input options' do
|
89
|
+
input.input(wrapper_options)
|
90
|
+
|
91
|
+
expect(template).to have_received(:ckeditor5_editor).with(
|
92
|
+
hash_including(
|
93
|
+
class: [{ class: 'input' }, :required],
|
94
|
+
wrapper_class: 'wrapper'
|
95
|
+
)
|
96
|
+
)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -3,8 +3,8 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
RSpec.describe CKEditor5::Rails::Presets::PluginsBuilder do
|
6
|
-
let(:
|
7
|
-
let(:builder) { described_class.new(
|
6
|
+
let(:items) { [] }
|
7
|
+
let(:builder) { described_class.new(items) }
|
8
8
|
|
9
9
|
describe '.create_plugin' do
|
10
10
|
context 'when name is a string' do
|
@@ -27,7 +27,7 @@ RSpec.describe CKEditor5::Rails::Presets::PluginsBuilder do
|
|
27
27
|
|
28
28
|
describe '#remove' do
|
29
29
|
before do
|
30
|
-
|
30
|
+
items.push(
|
31
31
|
CKEditor5::Rails::Editor::PropsPlugin.new('Plugin1'),
|
32
32
|
CKEditor5::Rails::Editor::PropsPlugin.new('Plugin2'),
|
33
33
|
CKEditor5::Rails::Editor::PropsPlugin.new('Plugin3')
|
@@ -36,7 +36,7 @@ RSpec.describe CKEditor5::Rails::Presets::PluginsBuilder do
|
|
36
36
|
|
37
37
|
it 'removes specified plugins' do
|
38
38
|
builder.remove('Plugin1', 'Plugin3')
|
39
|
-
expect(
|
39
|
+
expect(items.map(&:name)).to eq(['Plugin2'])
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
@@ -44,20 +44,20 @@ RSpec.describe CKEditor5::Rails::Presets::PluginsBuilder do
|
|
44
44
|
let(:existing_plugin) { CKEditor5::Rails::Editor::PropsPlugin.new('ExistingPlugin') }
|
45
45
|
|
46
46
|
before do
|
47
|
-
|
47
|
+
items.push(existing_plugin)
|
48
48
|
end
|
49
49
|
|
50
50
|
context 'without before option' do
|
51
51
|
it 'adds plugins at the beginning' do
|
52
52
|
builder.prepend('NewPlugin1', 'NewPlugin2')
|
53
|
-
expect(
|
53
|
+
expect(items.map(&:name)).to eq(%w[NewPlugin1 NewPlugin2 ExistingPlugin])
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
57
|
context 'with before option' do
|
58
58
|
it 'adds plugins before specified plugin' do
|
59
59
|
builder.prepend('NewPlugin', before: 'ExistingPlugin')
|
60
|
-
expect(
|
60
|
+
expect(items.map(&:name)).to eq(%w[NewPlugin ExistingPlugin])
|
61
61
|
end
|
62
62
|
|
63
63
|
it 'raises error when target plugin not found' do
|
@@ -72,20 +72,20 @@ RSpec.describe CKEditor5::Rails::Presets::PluginsBuilder do
|
|
72
72
|
let(:existing_plugin) { CKEditor5::Rails::Editor::PropsPlugin.new('ExistingPlugin') }
|
73
73
|
|
74
74
|
before do
|
75
|
-
|
75
|
+
items.push(existing_plugin)
|
76
76
|
end
|
77
77
|
|
78
78
|
context 'without after option' do
|
79
79
|
it 'adds plugins at the end' do
|
80
80
|
builder.append('NewPlugin1', 'NewPlugin2')
|
81
|
-
expect(
|
81
|
+
expect(items.map(&:name)).to eq(%w[ExistingPlugin NewPlugin1 NewPlugin2])
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
85
85
|
context 'with after option' do
|
86
86
|
it 'adds plugins after specified plugin' do
|
87
87
|
builder.append('NewPlugin', after: 'ExistingPlugin')
|
88
|
-
expect(
|
88
|
+
expect(items.map(&:name)).to eq(%w[ExistingPlugin NewPlugin])
|
89
89
|
end
|
90
90
|
|
91
91
|
it 'raises error when target plugin not found' do
|
@@ -1,6 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
|
+
require_relative './plugins_builder_spec'
|
5
|
+
require_relative './toolbar_builder_spec'
|
4
6
|
|
5
7
|
RSpec.describe CKEditor5::Rails::Presets::PresetBuilder do
|
6
8
|
let(:builder) { described_class.new }
|
@@ -139,6 +141,10 @@ RSpec.describe CKEditor5::Rails::Presets::PresetBuilder do
|
|
139
141
|
end
|
140
142
|
expect(builder.config[:toolbar][:items]).to include(:bold, :italic, :undo)
|
141
143
|
end
|
144
|
+
|
145
|
+
it 'returns ToolbarBuilder instance if no block provided' do
|
146
|
+
expect(builder.toolbar).to be_a(CKEditor5::Rails::Presets::ToolbarBuilder)
|
147
|
+
end
|
142
148
|
end
|
143
149
|
|
144
150
|
describe '#plugins' do
|
@@ -157,6 +163,10 @@ RSpec.describe CKEditor5::Rails::Presets::PresetBuilder do
|
|
157
163
|
plugin_names = builder.config[:plugins].map { |p| p.name.to_s }
|
158
164
|
expect(plugin_names).to eq(%w[Paragraph Essentials])
|
159
165
|
end
|
166
|
+
|
167
|
+
it 'returns PluginsBuilder instance if no block provided' do
|
168
|
+
expect(builder.plugins).to be_a(CKEditor5::Rails::Presets::PluginsBuilder)
|
169
|
+
end
|
160
170
|
end
|
161
171
|
|
162
172
|
describe '#simple_upload_adapter' do
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ckeditor5
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.15.
|
4
|
+
version: 1.15.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mateusz Bagiński
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2024-11-
|
12
|
+
date: 2024-11-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -90,7 +90,9 @@ files:
|
|
90
90
|
- spec/lib/ckeditor5/rails/editor/props_inline_plugin_spec.rb
|
91
91
|
- spec/lib/ckeditor5/rails/editor/props_plugin_spec.rb
|
92
92
|
- spec/lib/ckeditor5/rails/editor/props_spec.rb
|
93
|
+
- spec/lib/ckeditor5/rails/engine_spec.rb
|
93
94
|
- spec/lib/ckeditor5/rails/hooks/form_spec.rb
|
95
|
+
- spec/lib/ckeditor5/rails/hooks/simple_form_spec.rb
|
94
96
|
- spec/lib/ckeditor5/rails/presets/manager_spec.rb
|
95
97
|
- spec/lib/ckeditor5/rails/presets/plugins_builder_spec.rb
|
96
98
|
- spec/lib/ckeditor5/rails/presets/preset_builder_spec.rb
|
@@ -138,7 +140,9 @@ test_files:
|
|
138
140
|
- spec/lib/ckeditor5/rails/editor/props_inline_plugin_spec.rb
|
139
141
|
- spec/lib/ckeditor5/rails/editor/props_plugin_spec.rb
|
140
142
|
- spec/lib/ckeditor5/rails/editor/props_spec.rb
|
143
|
+
- spec/lib/ckeditor5/rails/engine_spec.rb
|
141
144
|
- spec/lib/ckeditor5/rails/hooks/form_spec.rb
|
145
|
+
- spec/lib/ckeditor5/rails/hooks/simple_form_spec.rb
|
142
146
|
- spec/lib/ckeditor5/rails/presets/manager_spec.rb
|
143
147
|
- spec/lib/ckeditor5/rails/presets/plugins_builder_spec.rb
|
144
148
|
- spec/lib/ckeditor5/rails/presets/preset_builder_spec.rb
|