releaf-content 1.0.4 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 026715c8a6ea2c87e202bf6790b4f67df7afb238
4
- data.tar.gz: 908892fee01d32e657a5dfbb186c138df5d6b437
3
+ metadata.gz: 50140d486352908f00053195a847e307f6905bf8
4
+ data.tar.gz: 60cbeff04c5d56eb50042904845de7bf87c9b7e2
5
5
  SHA512:
6
- metadata.gz: daaa7f982c8747ce37087b831f57f7fdaf37caefb5c45553881dcfd4fee3ec356c8b61d4538675512e7d540ab8a5080a2bdebdd4a284b65f95060bc6bd3a2bbe
7
- data.tar.gz: f860c3d0ccaaf1dc3a735674e1f40f75ff386f2e97bbf7a5ca5625c5ae959ef5ef51d79fd589a850aa3743d75cef6359cf90897cc21b53a3fa99b2c3fc992b03
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
- }, 'text');
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(function()
75
+ name_input.on('change', function()
76
76
  {
77
- slug_input.trigger('sluggenerate');
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
- respond_to do |format|
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
@@ -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
 
@@ -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
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-01 00:00:00.000000000 Z
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.4
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.4
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.5.1
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