qbrick 2.6.4 → 2.6.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: d4039c7291357f0a19df1eeb7bd91a3bf1bfef68
4
- data.tar.gz: 03932d27ce93a7cb5fffb49aa436c85f4659ec5b
3
+ metadata.gz: 5670c7eb3b792219eaffc87f89487412df39450d
4
+ data.tar.gz: 61888a9f1c21b859e4d8b523cd5b048b2f0be56e
5
5
  SHA512:
6
- metadata.gz: cff2e82dc85540467c0c261d71d9775ab5f6845fc5d76095dc15e41ebadc2cb53f27be446efc65fb75acba4f21cd8ede77ee963df685c74bd7936bd8171822ca
7
- data.tar.gz: 450e54bb31980207d060185106ac46d01975797e4f6ca1024383bc70a308d6169ae47b879b91310baa2cf48a7a42c1ea46e0b774eb9c979a916d3f50f23eea5b
6
+ metadata.gz: 8007150311018f10e62926597f05c6e06eaa51fcf461a8547272a8487371c1468826b5c1db7ef9ad12e8f1e0fdedf97a920a3d117eb04ba6172b9c9dda0bb07e
7
+ data.tar.gz: d8cddcf1416dfeb3edb283fe8f7c49c66cd95adb43e69d40790e9b520d95516591418fb5a9099c14c6b77ad034817ea03abfc4ee810f80ee504cf2608d01f543
@@ -34,6 +34,7 @@ module Qbrick
34
34
  validates :redirect_url, presence: true, if: :redirect?
35
35
  validates :title, :slug, :keywords, :page_type, length: { maximum: 255 }
36
36
  validates :identifier, uniqueness: true, allow_blank: true
37
+ validate :slug_uniqueness
37
38
 
38
39
  class << self
39
40
  def flat_tree
@@ -66,6 +67,26 @@ module Qbrick
66
67
  end
67
68
  end # class methods
68
69
 
70
+ def slug_uniqueness
71
+ path_field = locale_attr :path
72
+ slug_field = locale_attr :slug
73
+ [slug_field, path_field].each do |field|
74
+ self.class.validators_on(field).map { |v| v.validate self }
75
+ return true if errors[field].present?
76
+ end
77
+
78
+ page_with_duplicated_paths = self.class.where path_field => path
79
+ page_with_duplicated_paths = page_with_duplicated_paths.where.not id: id if persisted?
80
+ return true unless page_with_duplicated_paths.exists?
81
+
82
+ message = 'page ids: '
83
+ page_with_duplicated_paths.pluck(:id).each do |id|
84
+ message << "<a href=\"#{edit_cms_page_path id}#page-metadata\" target=\"_blank\">#{id}</a> "
85
+ end
86
+ message = I18n.t 'activerecord.errors.models.qbrick/page.attributes.slug.duplicated_slug', append: " (#{message.strip})"
87
+ errors.add :slug, message.html_safe
88
+ end
89
+
69
90
  def without_self
70
91
  self.class.where.not id: id
71
92
  end
@@ -17,3 +17,10 @@ de:
17
17
  page_type: 'Seitentyp'
18
18
  parent_id: 'Übergeordnete Seite'
19
19
  parent: 'Übergeordnete Seite'
20
+ google_verification_key: 'Google Verification Key'
21
+ errors:
22
+ models:
23
+ qbrick/page:
24
+ attributes:
25
+ slug:
26
+ duplicated_slug: 'Der Slug ist leider schon vergeben%{append}'
@@ -18,3 +18,9 @@ en:
18
18
  parent_id: 'Parent page'
19
19
  parent: 'Parent page'
20
20
  google_verification_key: Google Verification Key
21
+ errors:
22
+ models:
23
+ qbrick/page:
24
+ attributes:
25
+ slug:
26
+ duplicated_slug: 'Unfortunately the slug is already available%{append}'
@@ -1,3 +1,3 @@
1
1
  module Qbrick
2
- VERSION = '2.6.4'
2
+ VERSION = '2.6.5'
3
3
  end
@@ -38,14 +38,13 @@ describe Qbrick::Cms::PagesHelper, type: :helper do
38
38
  end
39
39
 
40
40
  it 'has a redirect page' do
41
- @page = create(:page, title: 'Page 1', slug: 'page1',
42
- page_type: Qbrick::PageType::REDIRECT, redirect_url: 'en/references')
43
- expect(helper.hide_content_tab?(@page)).to be_truthy
41
+ page = create :page, title: 'Redirect', page_type: Qbrick::PageType::REDIRECT, redirect_url: 'en/foo'
42
+ expect(helper.hide_content_tab?(page)).to be_truthy
44
43
  end
45
44
 
46
45
  it 'has a not saved page' do
47
- @page = Qbrick::Page.new
48
- expect(helper.hide_content_tab?(@page)).to be_truthy
46
+ page = Qbrick::Page.new
47
+ expect(helper.hide_content_tab?(page)).to be_truthy
49
48
  end
50
49
  end
51
50
  end
@@ -376,6 +376,14 @@ describe Qbrick::Page, type: :model do
376
376
  describe '#path' do
377
377
  let(:page) { create :page, slug: 'page' }
378
378
 
379
+ it "doesn't allow duplicated paths" do
380
+ expect(page).to be_valid
381
+ duplicated_slug_page = build :page, slug: 'page'
382
+ expect(page.slug).to eq duplicated_slug_page.slug
383
+ expect(duplicated_slug_page).to be_invalid
384
+ expect(duplicated_slug_page.errors[:slug]).to be_present
385
+ end
386
+
379
387
  context 'without parent' do
380
388
  it 'returns path with leading /' do
381
389
  expect(page.path).to start_with '/'
@@ -421,14 +429,14 @@ describe Qbrick::Page, type: :model do
421
429
  expect(child.path).to eq('/parent/child')
422
430
  end
423
431
  end
424
- end
432
+ end # path
425
433
 
426
434
  describe '#translated' do
427
435
  before :each do
428
436
  I18n.with_locale(:en) do
429
- @page_1 = create(:page, title: 'Page 1', slug: 'page1')
430
- @page_2 = create(:page, title: 'Page 2', slug: 'page1')
431
- @page_3 = create(:page, title: 'Page 3', slug: 'page1')
437
+ @page_1 = create(:page, title: 'Page 1')
438
+ @page_2 = create(:page, title: 'Page 2')
439
+ @page_3 = create(:page, title: 'Page 3')
432
440
  end
433
441
  end
434
442
 
@@ -456,7 +464,7 @@ describe Qbrick::Page, type: :model do
456
464
  it 'should be findable via scope' do
457
465
  expect(Qbrick::Page.by_identifier(cat_page.identifier)).to eq(cat_page)
458
466
  end
459
- end
467
+ end # translated
460
468
 
461
469
  describe '#cloning' do
462
470
  around(:each) do |example|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qbrick
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.6.4
4
+ version: 2.6.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Immanuel Häussermann
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2015-06-19 00:00:00.000000000 Z
15
+ date: 2015-06-26 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: rspec-rails