qbrick 2.6.1 → 2.6.2

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: fc399634917aca2db211deb27063aa7711c7b1bc
4
- data.tar.gz: 9d8d3256e5bd97d3775680d7766cc6c55219d7ad
3
+ metadata.gz: b4f3ceb72b5a03c06f602281f41bcc750f8d49ce
4
+ data.tar.gz: 4618b777f6e1a6151b95a1e17d6894aa158ac42c
5
5
  SHA512:
6
- metadata.gz: 672f482f10108c98212b8f997ce8b2971d128e6e4da394e09882d4984f0c5349b1f7a7f8dfb6b9c1fa0c736490ae2d8df41546b846f78ef285d88b08789f722d
7
- data.tar.gz: 0a7af236fd18bdb10ce18bbc1b4eaf57229f5cbddcbebaeeec3df3fe28e8fa81478fc27c58ed9838fb65bf64e1547c52e0336611485d5847c12ed4a054d6cda1
6
+ metadata.gz: c779195400c460314f4d37a8a6796637e043427dd6643c9d4aea53be22fa0c35914926e8177e10093cab10e9b28f3924e4746ce8147790196d04c3d51aad0383
7
+ data.tar.gz: bd0e378f688977977cb1dde7512f59ad11c6111a238fd56c1767343692be81f07d2fb6d7fb9332b9352b3321b77a948c38c4cafbbbf9aed4d8cd27a01dc0ad31
@@ -13,9 +13,8 @@ module Qbrick
13
13
 
14
14
  def show
15
15
  if redirect_page?
16
- redirect_url = @page.redirect_url.sub(%r{\A\/+}, '') # remove all preceding slashes
17
16
  session[:qbrick_referrer] = @page.id
18
- redirect_to "/#{redirect_url}"
17
+ redirect_to @page.redirect_url
19
18
  elsif @page.present?
20
19
  respond_with @page
21
20
  elsif @page.blank? && respond_to?(:handle_404)
@@ -8,8 +8,12 @@ module Qbrick
8
8
  #
9
9
  def method_missing(method, *args, &block)
10
10
  main_app.send(method, *args, &block)
11
- rescue NoMethodError
12
- super
11
+ rescue NoMethodError => exception
12
+ bc = ::ActiveSupport::BacktraceCleaner.new
13
+ bc.add_silencer { |l| l =~ /^#{__FILE__}.+#{__method__}'?$/ }
14
+ exception.set_backtrace bc.clean(exception.backtrace)
15
+
16
+ raise exception
13
17
  end
14
18
 
15
19
  def sublime_video_include_tag
@@ -27,6 +27,7 @@ module Qbrick
27
27
 
28
28
  before_validation :create_slug, :create_path
29
29
  after_save :update_child_paths
30
+ validate :remove_preceding_slashes, if: :redirect?
30
31
 
31
32
  validates :title, presence: true
32
33
  validates :slug, presence: true
@@ -81,6 +82,29 @@ module Qbrick
81
82
  page_type == Qbrick::PageType::REDIRECT || page_type == Qbrick::PageType::CUSTOM
82
83
  end
83
84
 
85
+ def internal_redirect?
86
+ return false unless redirect?
87
+
88
+ scheme = URI.parse(redirect_url).scheme
89
+ return true if scheme.nil?
90
+
91
+ internal_redirect = Qbrick::Engine.hosts.find do |h|
92
+ URI.parse("#{scheme}://#{h}").route_to(redirect_url).host.nil?
93
+ end
94
+
95
+ internal_redirect.present?
96
+ end
97
+
98
+ def external_redirect?
99
+ redirect? && !internal_redirect?
100
+ end
101
+
102
+ def remove_preceding_slashes
103
+ return if redirect_url.blank?
104
+
105
+ redirect_url.sub!(%r{^/+}, '/')
106
+ end
107
+
84
108
  def navigation?
85
109
  page_type == Qbrick::PageType::NAVIGATION
86
110
  end
@@ -10,7 +10,7 @@ class LocalizePublishColumn < ActiveRecord::Migration
10
10
 
11
11
  new_translations = Qbrick::Page.translated_columns_for(:published) - %w(published_en)
12
12
  Qbrick::Page.all.each do |page|
13
- page.update Hash[new_translations.zip([page.published_en] * new_translations.count)]
13
+ page.update_columns Hash[new_translations.zip([page.published_en] * new_translations.count)]
14
14
  end
15
15
  end
16
16
 
data/lib/qbrick/engine.rb CHANGED
@@ -11,7 +11,7 @@ module Qbrick
11
11
  isolate_namespace Qbrick
12
12
 
13
13
  config.i18n.fallbacks = [:de]
14
- config.i18n.load_path += Dir[Qbrick::Engine.root.join('config', 'locales', '**', '*.{yml}').to_s]
14
+ config.i18n.load_path += Dir[Qbrick::Engine.root.join('config/locales/**/*.{yml}').to_s]
15
15
 
16
16
  # defaults to nil
17
17
  config.sublime_video_token = nil
@@ -23,5 +23,11 @@ module Qbrick
23
23
  require 'action_view/dependency_tracker'
24
24
  ActionView::DependencyTracker.register_tracker :haml, ActionView::DependencyTracker::ERBTracker
25
25
  end
26
+
27
+ def hosts
28
+ [Socket.gethostname].tap do |result|
29
+ result.concat [Rails.application.config.hosts].flatten if Rails.application.config.respond_to? :hosts
30
+ end
31
+ end
26
32
  end
27
33
  end
@@ -1,3 +1,3 @@
1
1
  module Qbrick
2
- VERSION = '2.6.1'
2
+ VERSION = '2.6.2'
3
3
  end
@@ -60,7 +60,7 @@ describe Qbrick::PagesController, type: :controller do
60
60
 
61
61
  context 'when page is a redirect page' do
62
62
  it 'redirects to the redirected url' do
63
- page = FactoryGirl.create :page, page_type: 'redirect', slug: 'dumdidum', redirect_url: 'de/redirect_page'
63
+ page = FactoryGirl.create :page, page_type: 'redirect', slug: 'dumdidum', redirect_url: '/de/redirect_page'
64
64
  get :show, url: page.slug
65
65
  expect(response).to redirect_to('/de/redirect_page')
66
66
  end
@@ -537,4 +537,44 @@ describe Qbrick::Page, type: :model do
537
537
  expect(child_page.create_path).to eq '/le_parent/le_child'
538
538
  end
539
539
  end
540
+
541
+ context 'when it is a redirect page' do
542
+ let(:page) { build :page, page_type: Qbrick::PageType::REDIRECT }
543
+
544
+ describe '#internal_redirect?' do
545
+ it 'returns false for non redirect pages' do
546
+ expect(build(:page).internal_redirect?).to be_falsey
547
+ end
548
+
549
+ it 'returns false for external redirects' do
550
+ page.redirect_url = 'http://google.de'
551
+ expect(page.internal_redirect?).to be_falsey
552
+ end
553
+
554
+ it 'returns true for internal redirects' do
555
+ page.redirect_url = '/huhu'
556
+ expect(page.internal_redirect?).to be_truthy
557
+ page.redirect_url = "http://#{Socket.gethostname}/huhu"
558
+ expect(page.internal_redirect?).to be_truthy
559
+ end
560
+ end
561
+
562
+ describe '#external_redirect?' do
563
+ it 'returns false for non redirect pages' do
564
+ expect(build(:page).external_redirect?).to be_falsey
565
+ end
566
+
567
+ it 'returns true for external redirects' do
568
+ page.redirect_url = 'http://google.de'
569
+ expect(page.external_redirect?).to be_truthy
570
+ end
571
+
572
+ it 'returns false for internal redirects' do
573
+ page.redirect_url = '/huhu'
574
+ expect(page.external_redirect?).to be_falsey
575
+ page.redirect_url = "http://#{Socket.gethostname}/huhu"
576
+ expect(page.external_redirect?).to be_falsey
577
+ end
578
+ end
579
+ end
540
580
  end
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.1
4
+ version: 2.6.2
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-03 00:00:00.000000000 Z
15
+ date: 2015-06-10 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: rspec-rails