qbrick 2.5.2 → 2.6.0

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: b059ac46e947e3b2a4defd38d5f4c5b2ceccdd0f
4
- data.tar.gz: a40b7e8ae32963620770c0aeb3a7f72a235c9812
3
+ metadata.gz: 3c9cc5b026051806ef35cb0e40a3e8d7d2075802
4
+ data.tar.gz: aed46d071929a30222d47dd1c8a2b62da1a8532e
5
5
  SHA512:
6
- metadata.gz: a2dacd142a4fb962b783997fe17fe52b07b581ae99cf3343c9a22ab2e686581b259ff93ffff04523cf62218bfa88be212e1d91d02d212ec3fecb34e5914a4a2f
7
- data.tar.gz: eece466ba49673881fa0b92620af9a6ffb5d56c9e4a8ce6594268670211673f1aba62ef972956d9bcf28b4d2b114a07d39364d259ee4f8d47398a93b618bd49f
6
+ metadata.gz: 84f5765abf6f575c7f134983463b72dd46f5b5bd8ae96b5985b585ca444f9c48dc44072f45535b0c3a4a3504beca0f8990612e8b96e565457fc7ff4448aeccd3
7
+ data.tar.gz: a9a58904375ed0e74816d4123a2ae63fa3732e40455324c58f169ad2c567d62a2184a257a83b145cd04c03927f3778bb756dea4134eccf196b5b1cfcd8f85b88
@@ -7,6 +7,7 @@ module Qbrick
7
7
  def index
8
8
  I18n.locale = params[:locale]
9
9
  @pages = Qbrick::Page.unscoped.published.content_page.translated.order(position: :asc)
10
+
10
11
  render json: @pages.as_json
11
12
  end
12
13
  end
@@ -4,6 +4,7 @@ module Qbrick
4
4
  respond_to :html
5
5
  layout 'qbrick/cms/application'
6
6
  before_action :set_content_locale, :authenticate_admin!
7
+ after_action :reset_remembered_locale
7
8
 
8
9
  def set_content_locale
9
10
  # this was taken from: https://github.com/screenconcept/hieronymus_shop/pull/218/files
@@ -14,9 +15,17 @@ module Qbrick
14
15
  new_locale = params[:content_locale] || session['backend_locale'] || I18n.locale
15
16
  session['backend_locale'] = new_locale.to_s
16
17
  return if I18n.locale == new_locale || !I18n.locale_available?(new_locale)
18
+
19
+ session['remembered_locale'] = I18n.locale
17
20
  I18n.locale = new_locale
18
21
  end
19
22
 
23
+ def reset_remembered_locale
24
+ return if session['remembered_locale'].blank?
25
+
26
+ I18n.locale = session.delete 'remembered_locale'
27
+ end
28
+
20
29
  def default_url_options
21
30
  { content_locale: I18n.locale }.merge(super)
22
31
  end
@@ -1,6 +1,7 @@
1
1
  module Qbrick
2
2
  class PagesController < ::ApplicationController
3
3
  respond_to :html
4
+ before_action :set_locale
4
5
  before_action :find_page_by_url, only: :show
5
6
 
6
7
  def index
@@ -30,14 +31,24 @@ module Qbrick
30
31
 
31
32
  private
32
33
 
34
+ def set_locale
35
+ new_locale = params[:locale] || session['frontend_locale'] || I18n.locale
36
+
37
+ return I18n.locale if I18n.locale == new_locale || !I18n.locale_available?(new_locale)
38
+
39
+ session['frontend_locale'] = new_locale.to_s
40
+ I18n.locale = new_locale
41
+ end
42
+ alias frontend_locale set_locale
43
+
33
44
  def redirect_page?
34
45
  @page.present? && @page.redirect? && @page.redirect_url.present?
35
46
  end
36
47
 
37
48
  def find_page_by_url
38
- url = locale.to_s
49
+ url = frontend_locale.to_s
39
50
  url += "/#{params[:url]}" if params[:url].present?
40
- @page = Qbrick::Page.find_by_url(url)
51
+ @page = Qbrick::Page.published.find_by_url(url)
41
52
  end
42
53
  end
43
54
  end
@@ -3,6 +3,7 @@ module Qbrick
3
3
  def index
4
4
  last_page = Qbrick::Page.published.last
5
5
  return unless stale?(etag: last_page, last_modified: last_page.updated_at.utc)
6
+
6
7
  respond_to do |format|
7
8
  format.html
8
9
  format.xml { @pages = Qbrick::Page.published }
@@ -10,12 +10,12 @@ module Qbrick
10
10
  acts_as_brick_list
11
11
 
12
12
  translate :title, :page_title, :slug, :keywords, :description,
13
- :body, :redirect_url, :url
13
+ :body, :redirect_url, :url, :published
14
14
 
15
15
  default_scope { order 'position ASC' }
16
16
 
17
- scope :published, -> { where published: Qbrick::PublishState::PUBLISHED }
18
- scope :translated, -> { where "url_#{I18n.locale.to_s.underscore} is not null" }
17
+ scope :published, -> { where locale_attr(:published) => Qbrick::PublishState::PUBLISHED }
18
+ scope :translated, -> { where.not locale_attr(:url) => nil }
19
19
 
20
20
  scope :content_page, -> { where page_type: Qbrick::PageType::CONTENT }
21
21
 
@@ -62,7 +62,7 @@ module Qbrick
62
62
  end
63
63
 
64
64
  def without_self
65
- self.class.where 'id != ?', id
65
+ self.class.where.not id: id
66
66
  end
67
67
 
68
68
  def published?
@@ -0,0 +1,25 @@
1
+ class LocalizePublishColumn < ActiveRecord::Migration
2
+ def up
3
+ rename_column :qbrick_pages, :published, :published_en
4
+ add_column :qbrick_pages, :published_de, :integer, default: 0
5
+
6
+ I18n.available_locales.each do |locale|
7
+ column_name = :"published_#{locale.to_s.underscore}"
8
+ add_column :qbrick_pages, column_name, :integer, default: 0 unless column_exists? :qbrick_pages, column_name
9
+ end
10
+
11
+ new_translations = Qbrick::Page.translated_columns_for(:published) - %w(published_en)
12
+ Qbrick::Page.all.each do |page|
13
+ page.update Hash[new_translations.zip([page.published_en] * new_translations.count)]
14
+ end
15
+ end
16
+
17
+ def down
18
+ translated_columns = Qbrick::Page.translated_columns_for(:published) - %w(published_en)
19
+ rename_column :qbrick_pages, :published_en
20
+
21
+ translated_columns.each do |column|
22
+ remove_column :qbrick_pages, column
23
+ end
24
+ end
25
+ end
@@ -45,7 +45,11 @@ module Qbrick
45
45
  end
46
46
 
47
47
  def locale_attr(attr_name)
48
- "#{attr_name}_#{I18n.locale.to_s.underscore}"
48
+ "#{attr_name}_#{locale_for_attr_name}"
49
+ end
50
+
51
+ def translated_columns_for(attr_name)
52
+ column_names & I18n.available_locales.map { |l| "#{attr_name}_#{l.to_s.underscore}" }
49
53
  end
50
54
  end
51
55
 
@@ -1,3 +1,3 @@
1
1
  module Qbrick
2
- VERSION = '2.5.2'
2
+ VERSION = '2.6.0'
3
3
  end
@@ -4,9 +4,9 @@ describe Qbrick::Api::PagesController, type: :controller do
4
4
  describe '#index' do
5
5
  before do
6
6
  @pages = []
7
- @pages << @page1 = create(:page, published: true, title_de: 'foobar de',
7
+ @pages << @page1 = create(:page, published_de: true, published_en: true, title_de: 'foobar de',
8
8
  url_de: 'de/foobar-de', title_en: 'foobar en', url_en: 'en/foobar-en')
9
- @pages << @page2 = create(:page, published: true, title_de: 'barfoo de',
9
+ @pages << @page2 = create(:page, published_de: true, published_en: true, title_de: 'barfoo de',
10
10
  url_de: 'de/barfoo-de', title_en: 'barfoo en', url_en: 'en/barfoo-en')
11
11
  @pages << @unpublished = create(:page, published: false, title_de: 'unpublished de',
12
12
  url_de: 'de/unpublished-de', title_en: 'unpublished en',
@@ -36,13 +36,13 @@ describe Qbrick::Api::PagesController, type: :controller do
36
36
 
37
37
  describe 'expected json format of a page' do
38
38
  before do
39
- @pages = []
40
- @pages << @page1 = create(:page, published: true, title_de: 'foobar de',
41
- url_de: 'de/foobar-de', title_en: 'foobar en', url_en: 'en/foobar-en')
42
- @pages << @page2 = create(:page, published: true, title_de: 'barfoo de',
43
- url_de: 'de/barfoo-de', title_en: 'barfoo en', url_en: 'en/barfoo-en')
44
-
45
39
  I18n.with_locale :de do
40
+ @pages = []
41
+ @pages << @page1 = create(:page, published: true, title_de: 'foobar de',
42
+ url_de: 'de/foobar-de', title_en: 'foobar en', url_en: 'en/foobar-en')
43
+ @pages << @page2 = create(:page, published: true, title_de: 'barfoo de',
44
+ url_de: 'de/barfoo-de', title_en: 'barfoo en', url_en: 'en/barfoo-en')
45
+
46
46
  get :index, use_route: :qbrick
47
47
  @json = JSON.parse(response.body)
48
48
  @page_hash = @json.first
@@ -6,8 +6,8 @@ describe Qbrick::PagesController, type: :controller do
6
6
  describe '#index' do
7
7
  before do
8
8
  @pages = [
9
- create(:page, published: true, fulltext_de: 'foobar'),
10
- create(:page, published: true, fulltext_de: 'barfoo')
9
+ create(:page, published_de: true, fulltext_de: 'foobar'),
10
+ create(:page, published_de: true, fulltext_de: 'barfoo')
11
11
  ]
12
12
  end
13
13
 
@@ -22,16 +22,23 @@ describe Qbrick::PagesController, type: :controller do
22
22
  end
23
23
 
24
24
  describe '#show' do
25
+ it "doesn't show unpublished pages" do
26
+ I18n.with_locale(:de) do
27
+ unpublished_page = FactoryGirl.create :page, url_de: 'de', published_de: false
28
+ expect { get :show, url: unpublished_page.slug, use_route: :qbrick }.to raise_error(ActionController::RoutingError)
29
+ end
30
+ end
31
+
25
32
  describe 'routing' do
26
33
  context 'without url' do
27
34
  before do
28
- @page = FactoryGirl.create(:page, url_de: 'de')
35
+ @page = FactoryGirl.create(:page, url_de: 'de', published_de: true)
29
36
  end
30
37
 
31
38
  context 'with matching locale' do
32
39
  it 'sets the corresponding page' do
33
40
  I18n.with_locale(:de) do
34
- get(:show, use_route: :qbrick)
41
+ get :show, use_route: :qbrick
35
42
  end
36
43
  expect(assigns(:page)).to eq(@page)
37
44
  end
@@ -56,7 +63,7 @@ describe Qbrick::PagesController, type: :controller do
56
63
  it 'responds with page' do
57
64
  page = FactoryGirl.create(:page, slug: 'dumdidum',
58
65
  url: 'de/dumdidum')
59
- get :show, url: page.slug, use_route: :qbrick
66
+ get :show, url: page.slug, use_route: :qbrick
60
67
  expect(assigns(:page)).to eq(page)
61
68
  end
62
69
  end
@@ -65,21 +72,21 @@ describe Qbrick::PagesController, type: :controller do
65
72
  it 'redirects to the redirected url' do
66
73
  page = FactoryGirl.create(:page, page_type: 'redirect', slug: 'dumdidum',
67
74
  url: 'de/dumdidum', redirect_url: 'de/redirect_page')
68
- get :show, url: page.slug, use_route: :qbrick
75
+ get :show, url: page.slug, use_route: :qbrick
69
76
  expect(response).to redirect_to('/de/redirect_page')
70
77
  end
71
78
 
72
79
  it 'redirects to invalid redirect urls with too many preceding slashes' do
73
80
  page = FactoryGirl.create(:page, page_type: 'redirect', slug: 'dumdidum',
74
81
  url: 'de/dumdidum', redirect_url: '///de/redirect_page')
75
- get :show, url: page.slug, use_route: :qbrick
82
+ get :show, url: page.slug, use_route: :qbrick
76
83
  expect(response).to redirect_to('/de/redirect_page')
77
84
  end
78
85
 
79
86
  it 'redirects to root' do
80
87
  page = FactoryGirl.create(:page, page_type: 'redirect', slug: 'dumdidum',
81
88
  url: 'de/dumdidum', redirect_url: '/')
82
- get :show, url: page.slug, use_route: :qbrick
89
+ get :show, url: page.slug, use_route: :qbrick
83
90
  expect(response).to redirect_to('/')
84
91
  end
85
92
  end
@@ -3,11 +3,11 @@ require 'spec_helper'
3
3
  describe Qbrick::SitemapsController, type: :controller do
4
4
  describe '#index' do
5
5
  before do
6
- @page = FactoryGirl.create(:page)
6
+ @page = FactoryGirl.create :page
7
7
  end
8
8
 
9
9
  it 'should be able to send a xml file' do
10
- get(:index, use_route: :qbrick, format: 'xml')
10
+ get :index, use_route: :qbrick, format: 'xml'
11
11
  end
12
12
  end
13
13
  end
@@ -36,10 +36,12 @@ describe Qbrick::Brick, type: :model do
36
36
 
37
37
  describe '#parents' do
38
38
  it 'returns the chain of parents' do
39
- item1, item2, item3 = double, double, Qbrick::Brick.new
40
- allow(item2).to receive(:brick_list).and_return(item1)
41
- allow(item3).to receive(:brick_list).and_return(item2)
42
- expect(item3.parents).to eq([item1, item2])
39
+ grandparent = double
40
+ parent = double
41
+ child = Qbrick::Brick.new
42
+ allow(parent).to receive(:brick_list).and_return grandparent
43
+ allow(child).to receive(:brick_list).and_return parent
44
+ expect(child.parents).to eq [grandparent, parent]
43
45
  end
44
46
  end
45
47
 
@@ -56,11 +58,13 @@ describe Qbrick::Brick, type: :model do
56
58
  end
57
59
 
58
60
  it 'returns true if the brick has siblings' do
59
- item1, item2, item3 = double, double, Qbrick::Brick.new
60
- allow(item1).to receive(:bricks).and_return([item2, item3])
61
- allow(item2).to receive(:brick_list).and_return(item1)
62
- allow(item3).to receive(:brick_list).and_return(item1)
63
- expect(item3.has_siblings?).to be_truthy
61
+ parent = double
62
+ sibling1 = double
63
+ sibling2 = Qbrick::Brick.new
64
+ allow(parent).to receive(:bricks).and_return([sibling1, sibling2])
65
+ allow(sibling1).to receive(:brick_list).and_return(parent)
66
+ allow(sibling2).to receive(:brick_list).and_return(parent)
67
+ expect(sibling2.has_siblings?).to be_truthy
64
68
  end
65
69
  end
66
70
 
@@ -68,9 +68,12 @@ describe Qbrick::Page, type: :model do
68
68
 
69
69
  describe '#published' do
70
70
  it 'returns only published pages' do
71
- _p1, p2, _p3 = 3.times.map { create(:page) }
72
- p2.update_attribute :published, Qbrick::PublishState::UNPUBLISHED
73
- expect(Qbrick::Page.published).to be_all { |p| expect(p.published?).to be_truthy }
71
+ unpublished_page = 3.times.map { create :page }.last
72
+ unpublished_page.update_attribute :published, Qbrick::PublishState::UNPUBLISHED
73
+
74
+ published_pages = Qbrick::Page.published
75
+ expect(published_pages).to be_all { |p| expect(p.published?).to be_truthy }
76
+ expect(published_pages).not_to include unpublished_page
74
77
  end
75
78
  end
76
79
 
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.5.2
4
+ version: 2.6.0
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-05-13 00:00:00.000000000 Z
15
+ date: 2015-05-20 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: rspec-rails
@@ -202,14 +202,14 @@ dependencies:
202
202
  requirements:
203
203
  - - '='
204
204
  - !ruby/object:Gem::Version
205
- version: 0.30.0
205
+ version: 0.31.0
206
206
  type: :development
207
207
  prerelease: false
208
208
  version_requirements: !ruby/object:Gem::Requirement
209
209
  requirements:
210
210
  - - '='
211
211
  - !ruby/object:Gem::Version
212
- version: 0.30.0
212
+ version: 0.31.0
213
213
  - !ruby/object:Gem::Dependency
214
214
  name: poltergeist
215
215
  requirement: !ruby/object:Gem::Requirement
@@ -744,6 +744,7 @@ files:
744
744
  - db/migrate/22_create_settings_collections.rb
745
745
  - db/migrate/23_add_metadata_to_asset.rb
746
746
  - db/migrate/23_devise_create_qbrick_admins.rb
747
+ - db/migrate/24_localize_publish_column.rb
747
748
  - db/seeds.rb
748
749
  - lib/generators/qbrick/assets/install_generator.rb
749
750
  - lib/generators/qbrick/custom_model_generator.rb
@@ -884,7 +885,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
884
885
  version: '0'
885
886
  requirements: []
886
887
  rubyforge_project: qbrick
887
- rubygems_version: 2.4.5
888
+ rubygems_version: 2.2.2
888
889
  signing_key:
889
890
  specification_version: 4
890
891
  summary: A tool that helps you to manage your content within your app.