kuhsaft 1.5.0 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/app/assets/javascripts/kuhsaft/cms/application.js.coffee +1 -1
- data/app/controllers/kuhsaft/pages_controller.rb +8 -6
- data/app/models/kuhsaft/page.rb +4 -9
- data/app/views/kuhsaft/cms/pages/_form.html.haml +2 -1
- data/config/locales/models/kuhsaft/page/de.yml +1 -0
- data/db/migrate/10_add_redirect_url_to_kuhsaft_pages.rb +7 -0
- data/db/migrate/11_update_url_and_redirect_url_value.rb +45 -0
- data/lib/kuhsaft/version.rb +1 -1
- data/lib/templates/kuhsaft/translations/add_translation.html.erb +1 -0
- data/spec/controllers/kuhsaft/pages_controller_spec.rb +39 -13
- data/spec/features/cms_pages_spec.rb +28 -0
- data/spec/models/page_spec.rb +11 -2
- metadata +6 -4
@@ -17,7 +17,7 @@ loadTextEditor = ->
|
|
17
17
|
CKEDITOR.replaceAll('editor')
|
18
18
|
|
19
19
|
checkPageType = ->
|
20
|
-
redirect_url_input = $('#
|
20
|
+
redirect_url_input = $('#page_redirect_url')
|
21
21
|
if ($('#page_page_type option:selected').val() == 'redirect')
|
22
22
|
redirect_url_input.removeAttr('disabled')
|
23
23
|
else
|
@@ -7,12 +7,14 @@ module Kuhsaft
|
|
7
7
|
url += "/#{params[:url]}" if params[:url].present?
|
8
8
|
@page = Kuhsaft::Page.find_by_url(url)
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
10
|
+
if @page.present? && @page.redirect? && @page.redirect_url.present?
|
11
|
+
redirect_to "/#{@page.redirect_url}"
|
12
|
+
elsif @page.present?
|
13
|
+
respond_with @page
|
14
|
+
elsif @page.blank? && respond_to?(:handle_404)
|
15
|
+
handle_404
|
16
|
+
else
|
17
|
+
raise ActionController::RoutingError.new('Not Found')
|
16
18
|
end
|
17
19
|
end
|
18
20
|
end
|
data/app/models/kuhsaft/page.rb
CHANGED
@@ -6,8 +6,8 @@ class Kuhsaft::Page < ActiveRecord::Base
|
|
6
6
|
has_ancestry
|
7
7
|
acts_as_brick_list
|
8
8
|
|
9
|
-
translate :title, :slug, :keywords, :description, :body, :url, :fulltext
|
10
|
-
attr_accessible :title, :slug, :url, :page_type, :parent_id, :keywords, :description, :published
|
9
|
+
translate :title, :slug, :keywords, :description, :body, :redirect_url, :url, :fulltext
|
10
|
+
attr_accessible :title, :slug, :redirect_url, :url, :page_type, :parent_id, :keywords, :description, :published
|
11
11
|
|
12
12
|
default_scope order('position ASC')
|
13
13
|
|
@@ -19,6 +19,7 @@ class Kuhsaft::Page < ActiveRecord::Base
|
|
19
19
|
|
20
20
|
validates :title, :presence => true
|
21
21
|
validates :slug, :presence => true
|
22
|
+
validates :redirect_url, :presence => true, :if => :redirect?
|
22
23
|
#validates :url, :uniqueness => true, :unless => :navigation?
|
23
24
|
|
24
25
|
class << self
|
@@ -71,17 +72,11 @@ class Kuhsaft::Page < ActiveRecord::Base
|
|
71
72
|
if bricks.count == 0 && children.count > 0
|
72
73
|
children.first.link
|
73
74
|
else
|
74
|
-
|
75
|
-
url
|
76
|
-
else
|
77
|
-
"/#{url}"
|
78
|
-
end
|
75
|
+
"/#{url}"
|
79
76
|
end
|
80
77
|
end
|
81
78
|
|
82
79
|
def create_url
|
83
|
-
return if redirect?
|
84
|
-
|
85
80
|
complete_slug = ''
|
86
81
|
if parent.present?
|
87
82
|
complete_slug << parent.url.to_s
|
@@ -12,7 +12,8 @@
|
|
12
12
|
= form.input :slug, :required => false, :input_html => { :class => :span5 }
|
13
13
|
= form.input :parent_id, :collection => Kuhsaft::Page.flat_tree, :label_method => :nesting_name, :selected => params[:parent_id].presence || @page.parent_id.presence, :prompt => 'None', :input_html => { :class => :span3 }
|
14
14
|
= form.input :page_type, :collection => Kuhsaft::PageType.all, :prompt => false, :input_html => { :class => :span3 }
|
15
|
-
= form.input :
|
15
|
+
= form.input :redirect_url, :as => :string
|
16
|
+
= form.input :url, :as => :string, :input_html => { :disabled => 'disabled' }
|
16
17
|
= form.input :keywords, :input_html => { :class => :span5 }
|
17
18
|
= form.input :description, :as => :text, :input_html => { :class => :span5, :rows => 4 }
|
18
19
|
= form.input :published, :as => :boolean
|
@@ -0,0 +1,45 @@
|
|
1
|
+
class UpdateUrlAndRedirectUrlValue < ActiveRecord::Migration
|
2
|
+
def up
|
3
|
+
@redirect_pages = Kuhsaft::Page.where(:page_type => 'redirect')
|
4
|
+
I18n.available_locales.each do |locale|
|
5
|
+
move_url_to_redirect_url(locale)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def down
|
10
|
+
@redirect_pages = Kuhsaft::Page.where(:page_type => 'redirect')
|
11
|
+
I18n.available_locales.each do |locale|
|
12
|
+
move_redirect_url_to_url(locale)
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
def move_url_to_redirect_url(locale)
|
18
|
+
I18n.with_locale(locale) do
|
19
|
+
@redirect_pages.each do |redirect_page|
|
20
|
+
redirect_url = redirect_page.url
|
21
|
+
redirect_page.update_attributes(:url => update_url(redirect_page), :redirect_url => redirect_url) if redirect_page
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def move_redirect_url_to_url(locale)
|
27
|
+
I18n.with_locale(locale) do
|
28
|
+
@redirect_pages.each do |redirect_page|
|
29
|
+
url = redirect_page.redirect_url
|
30
|
+
redirect_page.update_attributes(:url => url, :redirect_url => nil, :page_type => nil) if redirect_page
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def update_url(page)
|
36
|
+
complete_slug = ''
|
37
|
+
if page.parent.present?
|
38
|
+
complete_slug << page.parent.url.to_s
|
39
|
+
else
|
40
|
+
complete_slug = "#{I18n.locale}"
|
41
|
+
end
|
42
|
+
complete_slug << "/#{page.slug}"
|
43
|
+
complete_slug
|
44
|
+
end
|
45
|
+
end
|
data/lib/kuhsaft/version.rb
CHANGED
@@ -7,6 +7,7 @@ class Add<%= get_locale.classify %>Translation < ActiveRecord::Migration
|
|
7
7
|
add_column :kuhsaft_pages, :description_<%= get_locale %>, :text
|
8
8
|
add_column :kuhsaft_pages, :body_<%= get_locale %>, :text
|
9
9
|
add_column :kuhsaft_pages, :url_<%= get_locale %>, :text
|
10
|
+
add_column :kuhsaft_pages, :redirect_url_<%= get_locale %>, :text
|
10
11
|
add_column :kuhsaft_pages, :fulltext_<%= get_locale %>, :text
|
11
12
|
end
|
12
13
|
|
@@ -4,24 +4,50 @@ describe Kuhsaft::PagesController do
|
|
4
4
|
subject { described_class }
|
5
5
|
|
6
6
|
describe '#show' do
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
describe 'redirect' do
|
8
|
+
around(:each) do |example|
|
9
|
+
I18n.with_locale :de do
|
10
|
+
example.run
|
11
|
+
end
|
10
12
|
end
|
11
13
|
|
12
|
-
context '
|
13
|
-
it '
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
context 'when page is not a redirect page' do
|
15
|
+
it 'responds with page' do
|
16
|
+
page = FactoryGirl.create(:page, :slug => 'dumdidum', :url => 'de/dumdidum')
|
17
|
+
get :show, { :url => page.slug, :use_route => :kuhsaft, :locale => :de }
|
18
|
+
assigns(:page).should eq(page)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'when page is a redirect page' do
|
23
|
+
it 'redirects to the redirected url' do
|
24
|
+
page = FactoryGirl.create(:page, :page_type => 'redirect', :slug => 'dumdidum', :url => 'de/dumdidum', :redirect_url => 'de/redirect_page')
|
25
|
+
get :show, { :url => page.slug, :use_route => :kuhsaft, :locale => :de }
|
26
|
+
expect(response).to redirect_to("/de/redirect_page")
|
18
27
|
end
|
19
28
|
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe 'routing' do
|
32
|
+
context 'without url' do
|
33
|
+
before do
|
34
|
+
@page = FactoryGirl.create(:page, :url_de => 'de')
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'with matching locale' do
|
38
|
+
it 'sets the corresponding page' do
|
39
|
+
I18n.with_locale(:de) do
|
40
|
+
get(:show, { :use_route => :kuhsaft })
|
41
|
+
end
|
42
|
+
assigns(:page).should eq(@page)
|
43
|
+
end
|
44
|
+
end
|
20
45
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
46
|
+
context 'without matching locale' do
|
47
|
+
it 'raises a routing error' do
|
48
|
+
I18n.with_locale(:en) do
|
49
|
+
expect { get(:show, { :use_route => :kuhsaft }) }.to raise_error(ActionController::RoutingError)
|
50
|
+
end
|
25
51
|
end
|
26
52
|
end
|
27
53
|
end
|
@@ -16,7 +16,35 @@ describe 'Cms/Pages' do
|
|
16
16
|
it 'creates a new page' do
|
17
17
|
expect { click_on 'Create Seite' }.to change(Kuhsaft::Page, :count).by(1)
|
18
18
|
end
|
19
|
+
|
20
|
+
it 'is not possible to change the value in url' do
|
21
|
+
page.find('#page_url')['disabled'].should be_true
|
22
|
+
end
|
19
23
|
end
|
20
24
|
|
25
|
+
describe '#update' do
|
26
|
+
context 'when creating a redirect page' do
|
27
|
+
before do
|
28
|
+
@page = FactoryGirl.create(:page, :url => 'de/dumdidum')
|
29
|
+
visit kuhsaft.edit_cms_page_path(@page)
|
30
|
+
select 'redirect', :from => 'Seitentyp'
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'has a value in redirect_page' do
|
34
|
+
fill_in 'Redirect URL', :with => 'target_page'
|
35
|
+
expect { click_on 'Update Seite' }.to change{ @page.reload.redirect_url }.to('target_page')
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'is invalid when no value is in redirect_page' do
|
39
|
+
click_on 'Update Seite'
|
40
|
+
page.should have_css('.error', :count => 1)
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'does not change the value in url' do
|
44
|
+
fill_in 'Redirect URL', :with => 'target_page'
|
45
|
+
expect { click_on 'Update Seite' }.to_not change{ @page.reload.url }
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
21
49
|
end
|
22
50
|
end
|
data/spec/models/page_spec.rb
CHANGED
@@ -254,8 +254,8 @@ describe Kuhsaft::Page do
|
|
254
254
|
end
|
255
255
|
|
256
256
|
context 'when it is a redirect? page' do
|
257
|
-
it 'returns the
|
258
|
-
page = create(:page, :page_type => Kuhsaft::PageType::REDIRECT, :
|
257
|
+
it 'returns the absolute url' do
|
258
|
+
page = create(:page, :page_type => Kuhsaft::PageType::REDIRECT, :redirect_url => 'en/references', :slug => 'news')
|
259
259
|
page.link.should eq('/en/news')
|
260
260
|
end
|
261
261
|
end
|
@@ -324,4 +324,13 @@ describe Kuhsaft::Page do
|
|
324
324
|
end
|
325
325
|
end
|
326
326
|
end
|
327
|
+
|
328
|
+
describe '#before_validation' do
|
329
|
+
it 'generates url automatically' do
|
330
|
+
page = Kuhsaft::Page.new :slug => 'slug'
|
331
|
+
page.url.should be_nil
|
332
|
+
page.valid?
|
333
|
+
page.url.should be_present
|
334
|
+
end
|
335
|
+
end
|
327
336
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kuhsaft
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ authors:
|
|
13
13
|
autorequire:
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
|
-
date: 2013-05-
|
16
|
+
date: 2013-05-27 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: rspec
|
@@ -450,6 +450,8 @@ files:
|
|
450
450
|
- db/migrate/07_add_default_value_to_brick_type_enabled.rb
|
451
451
|
- db/migrate/08_add_display_styles_to_bricks.rb
|
452
452
|
- db/migrate/09_add_additional_fields_to_kuhsaft_bricks.rb
|
453
|
+
- db/migrate/10_add_redirect_url_to_kuhsaft_pages.rb
|
454
|
+
- db/migrate/11_update_url_and_redirect_url_value.rb
|
453
455
|
- db/seeds.rb
|
454
456
|
- lib/generators/kuhsaft/assets/install_generator.rb
|
455
457
|
- lib/generators/kuhsaft/translations/add_generator.rb
|
@@ -542,7 +544,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
542
544
|
version: '0'
|
543
545
|
segments:
|
544
546
|
- 0
|
545
|
-
hash:
|
547
|
+
hash: 1502563843709159469
|
546
548
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
547
549
|
none: false
|
548
550
|
requirements:
|
@@ -551,7 +553,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
551
553
|
version: '0'
|
552
554
|
segments:
|
553
555
|
- 0
|
554
|
-
hash:
|
556
|
+
hash: 1502563843709159469
|
555
557
|
requirements: []
|
556
558
|
rubyforge_project: kuhsaft
|
557
559
|
rubygems_version: 1.8.24
|