releaf-content 1.0.4 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 50140d486352908f00053195a847e307f6905bf8
|
4
|
+
data.tar.gz: 60cbeff04c5d56eb50042904845de7bf87c9b7e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff76c9fb70089fdd796c29447b5e37f67740d2cc0c691cd08c4314fac8c1425fc0ce50f3258d6a4978680b7cd86c00cf30aa9d2c53a9467ab15aa5499f394c45
|
7
|
+
data.tar.gz: 1a2a711aa4d467fc697ba3fcaaec0eed5a7ee4e0c500c39df401a99ed6f329ef2a19a35c0707d514ed570c9276d7f0425da2d7270f184cc1c805fb9bd3e9d449
|
@@ -61,7 +61,7 @@ jQuery(function()
|
|
61
61
|
slug_input.val( slug );
|
62
62
|
slug_link.find('span').text( encodeURIComponent( slug ) );
|
63
63
|
slug_button.trigger('loadingend');
|
64
|
-
}
|
64
|
+
});
|
65
65
|
});
|
66
66
|
|
67
67
|
slug_button.click(function()
|
@@ -72,9 +72,12 @@ jQuery(function()
|
|
72
72
|
if (name_input.val() === '')
|
73
73
|
{
|
74
74
|
// bind onchange slug generation only if starting out with an empty name
|
75
|
-
name_input.change
|
75
|
+
name_input.on('change', function()
|
76
76
|
{
|
77
|
-
slug_input.
|
77
|
+
if(slug_input.val().length === 0)
|
78
|
+
{
|
79
|
+
slug_input.trigger('sluggenerate');
|
80
|
+
}
|
78
81
|
});
|
79
82
|
}
|
80
83
|
}
|
@@ -10,9 +10,7 @@ class Releaf::Content::NodesController < Releaf::ActionController
|
|
10
10
|
tmp_resource.name = params[:name]
|
11
11
|
tmp_resource.reasign_slug
|
12
12
|
|
13
|
-
|
14
|
-
format.js { render text: tmp_resource.slug }
|
15
|
-
end
|
13
|
+
render text: tmp_resource.slug
|
16
14
|
end
|
17
15
|
|
18
16
|
def content_type_dialog
|
data/lib/releaf/content/node.rb
CHANGED
@@ -132,6 +132,10 @@ module Releaf::Content
|
|
132
132
|
locale_selection_enabled? && root?
|
133
133
|
end
|
134
134
|
|
135
|
+
def invalid_slug_format?
|
136
|
+
slug.present? && slug.to_url != slug
|
137
|
+
end
|
138
|
+
|
135
139
|
protected
|
136
140
|
|
137
141
|
def validate_parent_node_is_not_self
|
@@ -146,6 +150,10 @@ module Releaf::Content
|
|
146
150
|
self.errors.add(:parent_id, "descendant can't be parent")
|
147
151
|
end
|
148
152
|
|
153
|
+
def validate_slug
|
154
|
+
errors.add(:slug, :invalid) if invalid_slug_format?
|
155
|
+
end
|
156
|
+
|
149
157
|
private
|
150
158
|
|
151
159
|
def prevent_auto_update_settings_timestamp?
|
@@ -198,6 +206,7 @@ module Releaf::Content
|
|
198
206
|
validates_presence_of :parent, if: :parent_id?
|
199
207
|
validate :validate_parent_node_is_not_self
|
200
208
|
validate :validate_parent_is_not_descendant
|
209
|
+
validate :validate_slug
|
201
210
|
belongs_to :content, polymorphic: true, dependent: :destroy
|
202
211
|
accepts_nested_attributes_for :content
|
203
212
|
|
data/spec/features/nodes_spec.rb
CHANGED
@@ -271,6 +271,34 @@ describe "Nodes", js: true, with_tree: true, with_root: true do
|
|
271
271
|
|
272
272
|
end
|
273
273
|
|
274
|
+
scenario "Slugs", with_tree: false do
|
275
|
+
visit admin_nodes_path
|
276
|
+
|
277
|
+
open_toolbox_dialog 'Add child', @lv_root, ".view-index .collection li"
|
278
|
+
within_dialog do
|
279
|
+
click_link("Text page")
|
280
|
+
end
|
281
|
+
|
282
|
+
fill_in "Slug", with: "some-slug"
|
283
|
+
fill_in 'Name', with: "About us"
|
284
|
+
expect(page).to have_field("Slug", with: "some-slug")
|
285
|
+
|
286
|
+
fill_in "Slug", with: ""
|
287
|
+
fill_in 'Name', with: "About them"
|
288
|
+
expect(page).to have_field("Slug", with: "about-them")
|
289
|
+
|
290
|
+
# fill text to allow text page save
|
291
|
+
fill_in_richtext "Text", with: "asdasd"
|
292
|
+
|
293
|
+
fill_in "Slug", with: "invalid slug <>!"
|
294
|
+
click_button "Save"
|
295
|
+
expect(page).to have_error("is invalid", field: "Slug")
|
296
|
+
click_button "Suggest slug"
|
297
|
+
expect(page).to have_field("Slug", with: "about-them")
|
298
|
+
click_button "Save"
|
299
|
+
expect(page).to have_notification("Create succeeded")
|
300
|
+
end
|
301
|
+
|
274
302
|
describe "node order", with_tree: false do
|
275
303
|
def create_child parent, child_text, position=nil
|
276
304
|
visit admin_nodes_path
|
@@ -353,6 +353,50 @@ describe Node do
|
|
353
353
|
end
|
354
354
|
end
|
355
355
|
|
356
|
+
describe "#validate_slug" do
|
357
|
+
it "is called during validations" do
|
358
|
+
expect( subject ).to receive(:validate_slug)
|
359
|
+
subject.valid?
|
360
|
+
end
|
361
|
+
|
362
|
+
context "when invalid slug" do
|
363
|
+
it "adds format error on slug" do
|
364
|
+
allow(subject).to receive(:invalid_slug_format?).and_return(true)
|
365
|
+
expect{ subject.send(:validate_slug) }.to change{ subject.errors[:slug] }.to(["is invalid"])
|
366
|
+
end
|
367
|
+
end
|
368
|
+
|
369
|
+
context "when valid slug" do
|
370
|
+
it "does not add format error on slug" do
|
371
|
+
allow(subject).to receive(:invalid_slug_format?).and_return(false)
|
372
|
+
expect{ subject.send(:validate_slug) }.to_not change{ subject.errors[:slug] }.from([])
|
373
|
+
end
|
374
|
+
end
|
375
|
+
end
|
376
|
+
|
377
|
+
describe "#invalid_slug_format?" do
|
378
|
+
context "when slug value converted to url differs" do
|
379
|
+
it "returns true" do
|
380
|
+
subject.slug = "asd xx"
|
381
|
+
expect(subject.invalid_slug_format?).to be true
|
382
|
+
end
|
383
|
+
end
|
384
|
+
|
385
|
+
context "when slug value converted to url is same" do
|
386
|
+
it "returns false" do
|
387
|
+
subject.slug = "asd-xx"
|
388
|
+
expect(subject.invalid_slug_format?).to be false
|
389
|
+
end
|
390
|
+
end
|
391
|
+
|
392
|
+
context "when slug value is nil" do
|
393
|
+
it "returns false" do
|
394
|
+
subject.slug = nil
|
395
|
+
expect(subject.invalid_slug_format?).to be false
|
396
|
+
end
|
397
|
+
end
|
398
|
+
end
|
399
|
+
|
356
400
|
describe "#validate_parent_node_is_not_self" do
|
357
401
|
let(:node1) { create(:node, locale: "lv") }
|
358
402
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: releaf-content
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- CubeSystems
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-12-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: releaf-core
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.0.
|
19
|
+
version: 1.0.5
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1.0.
|
26
|
+
version: 1.0.5
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: stringex
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -134,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
134
134
|
version: '0'
|
135
135
|
requirements: []
|
136
136
|
rubyforge_project:
|
137
|
-
rubygems_version: 2.
|
137
|
+
rubygems_version: 2.6.7
|
138
138
|
signing_key:
|
139
139
|
specification_version: 4
|
140
140
|
summary: Node and content routes support for releaf
|