qbrick 2.6.0 → 2.6.1

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.
@@ -1,9 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
- # TODO: For some reason rspec does not recognize this as controller
4
- # spec even though it is in spec/controllers?
5
3
  describe Qbrick::Cms::PagesController, type: :controller do
6
- subject { described_class }
4
+ routes { Qbrick::Engine.routes }
7
5
 
8
6
  describe 'mirroring' do
9
7
  around(:each) do |example|
@@ -12,7 +10,7 @@ describe Qbrick::Cms::PagesController, type: :controller do
12
10
  end
13
11
  end
14
12
 
15
- let(:page) { FactoryGirl.create(:page, url_de: 'de', url_en: 'en') }
13
+ let(:page) { FactoryGirl.create(:page, path_de: 'de', path_en: 'en') }
16
14
  let!(:brick) do
17
15
  FactoryGirl.create(:text_brick,
18
16
  brick_list_id: page.id,
@@ -36,7 +34,7 @@ describe Qbrick::Cms::PagesController, type: :controller do
36
34
 
37
35
  context 'with no bricks on target locale' do
38
36
  it 'clones the existing bricks' do
39
- xhr :get, :mirror, use_route: :qbrick, target_locale: :en, page_id: page.id
37
+ xhr :get, :mirror, target_locale: :en, page_id: page.id
40
38
  I18n.with_locale :en do
41
39
  expect(page.bricks.count).to eq(1)
42
40
  end
@@ -45,13 +43,13 @@ describe Qbrick::Cms::PagesController, type: :controller do
45
43
 
46
44
  context 'with bricks on target locale' do
47
45
  it 'does not clone anything without the required parameter' do
48
- xhr :get, :mirror, use_route: :qbrick, target_locale: :en, page_id: page.id
46
+ xhr :get, :mirror, target_locale: :en, page_id: page.id
49
47
  expect(page.bricks.unscoped.where(locale: :en, brick_list_id: page.id).first.text).to eq('ENGLISH')
50
48
  end
51
49
 
52
50
  it 'clones the bricks when required parameter is set' do
53
51
  expect(page.bricks).to be_any
54
- xhr :get, :mirror, use_route: :qbrick, target_locale: :en, page_id: page.id, rutheless: 'true'
52
+ xhr :get, :mirror, target_locale: :en, page_id: page.id, rutheless: 'true'
55
53
  I18n.with_locale :en do
56
54
  expect(Qbrick::Page.find(page.id).bricks.first.text).to eq('DEUTSCH')
57
55
  end
@@ -1,92 +1,79 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Qbrick::PagesController, type: :controller do
4
- subject { described_class }
4
+ routes { Qbrick::Engine.routes }
5
5
 
6
6
  describe '#index' do
7
- before do
8
- @pages = [
9
- create(:page, published_de: true, fulltext_de: 'foobar'),
10
- create(:page, published_de: true, fulltext_de: 'barfoo')
11
- ]
12
- end
7
+ let(:search_term) { 'foobar' }
8
+ let!(:matching) { create(:page, published: 1).tap { |p| p.update_attribute :fulltext, search_term } }
9
+ let!(:nonmatching) { create(:page, published: 1).tap { |p| p.update_attribute :fulltext, 'barfoo' } }
10
+ let!(:unpublished) { create(:page, published: 0).tap { |p| p.update_attribute :fulltext, search_term } }
13
11
 
14
12
  context 'with search parameter' do
15
13
  it 'assigns the search results' do
16
- I18n.with_locale :de do
17
- get(:index, use_route: :qbrick, search: 'foobar')
18
- end
19
- expect(assigns(:pages)).to eq([@pages.first])
14
+ expect(matching.fulltext).to eq search_term
15
+ expect(unpublished.fulltext).to eq search_term
16
+
17
+ get :index, search: search_term
18
+
19
+ result = assigns :pages
20
+ expect(result).to include matching
21
+ expect(result).not_to include nonmatching
22
+ expect(result).not_to include unpublished
20
23
  end
21
24
  end
22
25
  end
23
26
 
24
27
  describe '#show' do
25
28
  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
29
+ unpublished_page = FactoryGirl.create :page, published: 0
30
+ expect { get :show, url: unpublished_page.slug }.to raise_error(ActionController::RoutingError)
30
31
  end
31
32
 
32
33
  describe 'routing' do
33
- context 'without url' do
34
- before do
35
- @page = FactoryGirl.create(:page, url_de: 'de', published_de: true)
36
- end
34
+ context 'on root page' do
35
+ let!(:root_page) { create :root_page }
37
36
 
38
37
  context 'with matching locale' do
39
- it 'sets the corresponding page' do
40
- I18n.with_locale(:de) do
41
- get :show, use_route: :qbrick
42
- end
43
- expect(assigns(:page)).to eq(@page)
38
+ it 'loads the page' do
39
+ get :show
40
+ expect(assigns(:page)).to eq(root_page)
44
41
  end
45
42
  end
46
43
 
47
44
  context 'without matching locale' do
48
45
  it 'raises a routing error' do
49
- expect { get(:show, use_route: :qbrick, locale: :en) }.to raise_error(ActionController::RoutingError)
46
+ expect { get(:show, locale: :de) }.to raise_error(ActionController::RoutingError)
50
47
  end
51
48
  end
52
49
  end
53
50
  end
54
51
 
55
52
  describe 'page type' do
56
- around(:each) do |example|
57
- I18n.with_locale :de do
58
- example.run
59
- end
60
- end
61
-
62
53
  context 'when page is not a redirect page' do
63
54
  it 'responds with page' do
64
- page = FactoryGirl.create(:page, slug: 'dumdidum',
65
- url: 'de/dumdidum')
66
- get :show, url: page.slug, use_route: :qbrick
55
+ page = FactoryGirl.create :page, slug: 'dumdidum'
56
+ get :show, url: page.slug
67
57
  expect(assigns(:page)).to eq(page)
68
58
  end
69
59
  end
70
60
 
71
61
  context 'when page is a redirect page' do
72
62
  it 'redirects to the redirected url' do
73
- page = FactoryGirl.create(:page, page_type: 'redirect', slug: 'dumdidum',
74
- url: 'de/dumdidum', redirect_url: 'de/redirect_page')
75
- get :show, url: page.slug, use_route: :qbrick
63
+ page = FactoryGirl.create :page, page_type: 'redirect', slug: 'dumdidum', redirect_url: 'de/redirect_page'
64
+ get :show, url: page.slug
76
65
  expect(response).to redirect_to('/de/redirect_page')
77
66
  end
78
67
 
79
68
  it 'redirects to invalid redirect urls with too many preceding slashes' do
80
- page = FactoryGirl.create(:page, page_type: 'redirect', slug: 'dumdidum',
81
- url: 'de/dumdidum', redirect_url: '///de/redirect_page')
82
- get :show, url: page.slug, use_route: :qbrick
69
+ page = FactoryGirl.create :page, page_type: 'redirect', slug: 'dumdidum', redirect_url: '///de/redirect_page', published: 1
70
+ get :show, url: page.slug
83
71
  expect(response).to redirect_to('/de/redirect_page')
84
72
  end
85
73
 
86
74
  it 'redirects to root' do
87
- page = FactoryGirl.create(:page, page_type: 'redirect', slug: 'dumdidum',
88
- url: 'de/dumdidum', redirect_url: '/')
89
- get :show, url: page.slug, use_route: :qbrick
75
+ page = FactoryGirl.create(:page, page_type: 'redirect', slug: 'dumdidum', redirect_url: '/')
76
+ get :show, url: page.slug
90
77
  expect(response).to redirect_to('/')
91
78
  end
92
79
  end
@@ -1,13 +1,12 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Qbrick::SitemapsController, type: :controller do
4
- describe '#index' do
5
- before do
6
- @page = FactoryGirl.create :page
7
- end
4
+ routes { Qbrick::Engine.routes }
8
5
 
6
+ describe '#index' do
9
7
  it 'should be able to send a xml file' do
10
- get :index, use_route: :qbrick, format: 'xml'
8
+ @page = FactoryGirl.create :page
9
+ get :index, format: 'xml'
11
10
  end
12
11
  end
13
12
  end
data/spec/factories.rb CHANGED
@@ -7,7 +7,13 @@ FactoryGirl.define do
7
7
  p.title { FactoryGirl.generate(:title) }
8
8
  p.published 1
9
9
  p.body 'lorem ipsum'
10
- p.url ''
10
+ p.page_type Qbrick::PageType::CONTENT
11
+ end
12
+
13
+ factory :root_page, parent: :page do |p|
14
+ sequence(:title) { |n| "Root Title #{n}" }
15
+ p.parent nil
16
+ p.page_type Qbrick::PageType::NAVIGATION
11
17
  end
12
18
 
13
19
  factory :text_brick, class: 'Qbrick::TextBrick' do |tb|
@@ -1,21 +1,18 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'Administrator Management', type: :feature do
4
- def create_admin
5
- @admin ||= FactoryGirl.create(:admin)
6
- end
4
+ let!(:root_page) { create :root_page }
5
+ let(:admin) { create :admin }
7
6
 
8
- def create_and_login_admin
9
- create_admin
10
- visit qbrick.cms_pages_path
11
- fill_in 'E-Mail', with: @admin.email
12
- fill_in 'Password', with: @admin.password
13
- click_on 'Login'
7
+ around(:each) do |example|
8
+ I18n.with_locale(:en) { example.run }
14
9
  end
15
10
 
16
11
  before :each do
17
- @page = FactoryGirl.create(:page, page_type: 'navigation', published: true, title: 'home')
18
- create_and_login_admin
12
+ visit qbrick.cms_pages_path
13
+ fill_in 'E-Mail', with: admin.email
14
+ fill_in 'Password', with: admin.password
15
+ click_on 'Login'
19
16
  end
20
17
 
21
18
  describe 'admin' do
@@ -34,10 +31,10 @@ describe 'Administrator Management', type: :feature do
34
31
 
35
32
  it 'can change his/her password' do
36
33
  click_on 'Change Password'
37
- fill_in 'Current Password', with: @admin.password
34
+ fill_in 'Current Password', with: admin.password
38
35
  fill_in 'Password', with: new_password
39
36
  fill_in 'Password Confirmation', with: new_password
40
- expect { click_on 'Update Admin' }.to change { Qbrick::Admin.find_by_email(@admin.email).encrypted_password }
37
+ expect { click_on 'Update Admin' }.to change { Qbrick::Admin.find_by_email(admin.email).encrypted_password }
41
38
  end
42
39
 
43
40
  it 'can create a new admin user' do
@@ -3,6 +3,10 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe 'Cms/Pages', type: :feature do
6
+ around(:each) do |example|
7
+ I18n.with_locale(:en) { example.run }
8
+ end
9
+
6
10
  before do
7
11
  admin = FactoryGirl.create(:admin)
8
12
  login_as(admin, scope: :admin)
@@ -10,7 +14,7 @@ describe 'Cms/Pages', type: :feature do
10
14
 
11
15
  context '#new' do
12
16
  before do
13
- visit qbrick.new_cms_page_path
17
+ visit qbrick.new_cms_page_path content_locale: 'en'
14
18
  fill_in 'Title', with: 'The Title of the page'
15
19
  fill_in 'Keywords', with: 'My keywords'
16
20
  fill_in 'Description', with: 'My Description'
@@ -23,35 +27,37 @@ describe 'Cms/Pages', type: :feature do
23
27
  end
24
28
 
25
29
  it 'is not possible to change the value in url' do
26
- expect(page.find('#page_url')['disabled']).to be_truthy
30
+ expect(page.find('#page_path_with_prefixed_locale')['disabled']).to be_truthy
27
31
  end
28
32
  end
29
33
 
30
34
  context 'when page is invalid' do
31
35
  it 'does not create a routing error by switching the locale' do
32
- @page = FactoryGirl.create(:page, title: 'DummyPage', title_en: 'DummyEN', slug: 'dummy_page')
33
- visit qbrick.edit_cms_page_path(@page)
36
+ sample_page = FactoryGirl.create :page, title: 'DummyPage', title_en: 'DummyEN', slug: 'dummy_page'
37
+ visit qbrick.edit_cms_page_path(sample_page)
34
38
  fill_in 'page_title', with: ''
35
39
  click_on 'Update Page'
36
40
  within '.language-navigation' do
37
41
  click_on 'EN'
38
42
  end
39
- expect(page).to have_content(@page.title_en)
43
+ expect(page).to have_content(sample_page.title_en)
40
44
  end
41
45
  end
42
46
  end
43
47
 
44
48
  describe '#update' do
45
49
  context 'when creating a redirect page' do
50
+ let(:a_page) do
51
+ FactoryGirl.create :page, path_de: '/dumdidum'
52
+ end
46
53
  before do
47
- @page = FactoryGirl.create(:page, url: 'de/dumdidum')
48
- visit qbrick.edit_cms_page_path(@page)
54
+ visit qbrick.edit_cms_page_path a_page, content_locale: 'en'
49
55
  select 'redirect', from: 'Pagetyp'
50
56
  end
51
57
 
52
58
  it 'has a value in redirect_page' do
53
59
  fill_in 'Redirect URL', with: 'target_page'
54
- expect { click_on 'Update Page' }.to change { @page.reload.redirect_url }.to('target_page')
60
+ expect { click_on 'Update Page' }.to change { Qbrick::Page.find(a_page.id).redirect_url }.to('target_page')
55
61
  end
56
62
 
57
63
  it 'is invalid when no value is in redirect_page' do
@@ -59,9 +65,9 @@ describe 'Cms/Pages', type: :feature do
59
65
  expect(page).to have_css('.error', count: 1)
60
66
  end
61
67
 
62
- it 'does not change the value in url' do
68
+ it 'does not change the value in path' do
63
69
  fill_in 'Redirect URL', with: 'target_page'
64
- expect { click_on 'Update Page' }.to_not change { @page.reload.url }
70
+ expect { click_on 'Update Page' }.to_not change { a_page.reload.path }
65
71
  end
66
72
  end
67
73
  end
@@ -69,11 +75,11 @@ describe 'Cms/Pages', type: :feature do
69
75
 
70
76
  describe '#edit' do
71
77
  it 'shows error messages on invalid bricks' do
72
- @page = FactoryGirl.create(:page)
73
- invalid_brick = FactoryGirl.build(:text_brick, text: nil, brick_list: @page)
78
+ sample_page = FactoryGirl.create(:page)
79
+ invalid_brick = FactoryGirl.build(:text_brick, text: nil, brick_list: sample_page)
74
80
  invalid_brick.save(validate: false)
75
81
 
76
- visit qbrick.edit_cms_page_path(@page)
82
+ visit qbrick.edit_cms_page_path(sample_page)
77
83
  expect(page).to have_css('.error', count: 1)
78
84
  end
79
85
  end
@@ -3,25 +3,26 @@ require 'spec_helper'
3
3
  describe 'pages#index', type: :feature do
4
4
  context 'with search parameter' do
5
5
  let! :page1 do
6
- p = create :page,
7
- published: true,
8
- title: 'Chromodorididae Ardeadoris'
9
- p.bricks << Qbrick::TextBrick.new(locale: I18n.locale,
10
- text: "#{'foo bar' * 300} Chromodorididae #{'foo bar' * 300}")
11
- p.save!
12
- p
6
+ main_page = nil
7
+ I18n.with_locale(:en) do
8
+ main_page = create :page, published: 1, title: 'Chromodorididae Ardeadoris'
9
+ main_page.bricks << Qbrick::TextBrick.new(locale: I18n.locale,
10
+ text: "#{'foo bar' * 300} Chromodorididae #{'foo bar' * 300}")
11
+ main_page.save!
12
+ end
13
+ main_page
13
14
  end
14
15
 
15
16
  let! :page2 do
16
- create :page,
17
- published: true,
18
- title: 'Chromodorididae Berlanguella'
17
+ I18n.with_locale(:en) do
18
+ create :page, published: 1, title: 'Chromodorididae Berlanguella'
19
+ end
19
20
  end
20
21
 
21
22
  let! :page3 do
22
- create :page,
23
- published: true,
24
- title: 'Gastropoda'
23
+ I18n.with_locale(:en) do
24
+ create :page, published: 1, title: 'Gastropoda'
25
+ end
25
26
  end
26
27
 
27
28
  context 'with fulltext' do
@@ -66,11 +67,8 @@ describe 'pages#index', type: :feature do
66
67
  end
67
68
 
68
69
  context 'without matches' do
69
- before do
70
- visit qbrick.pages_path(locale: :en, search: 'foobar')
71
- end
72
-
73
70
  it 'renders match count' do
71
+ visit qbrick.pages_path(locale: :en, search: 'foobar')
74
72
  expect(page).to have_content('No results')
75
73
  end
76
74
  end
@@ -1,14 +1,21 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Qbrick::Cms::PagesHelper, type: :helper do
4
+ let!(:page) do
5
+ I18n.with_locale(:en) do
6
+ create :page, title: 'Page 1', slug: 'page1', path_de: nil, title_de: nil, slug_de: nil
7
+ end
8
+ end
9
+ before(:each) { @page = page }
10
+
4
11
  describe '#content_tab_active' do
5
12
  it 'returns active when page has a title and no errors' do
6
- @page = create(:page, title: 'Page 1', slug: 'page1')
7
- expect(helper.content_tab_active(@page)).to be(:active)
13
+ I18n.with_locale :en do
14
+ expect(helper.content_tab_active(@page)).to be(:active)
15
+ end
8
16
  end
9
17
 
10
18
  it 'returns nil when page has no translation' do
11
- @page = create(:page, title: 'Page 1', slug: 'page1')
12
19
  I18n.with_locale :de do
13
20
  expect(helper.content_tab_active(@page)).to be_nil
14
21
  end
@@ -17,7 +24,6 @@ describe Qbrick::Cms::PagesHelper, type: :helper do
17
24
 
18
25
  describe '#metadata_tab_active' do
19
26
  it 'returns active when page is not translated' do
20
- @page = create(:page, title: 'Page 1', slug: 'page1')
21
27
  I18n.with_locale :de do
22
28
  expect(helper.metadata_tab_active(@page)).to be(:active)
23
29
  end
@@ -26,7 +32,6 @@ describe Qbrick::Cms::PagesHelper, type: :helper do
26
32
 
27
33
  describe '#hide_content_tab?' do
28
34
  it 'has a page without translations' do
29
- @page = create(:page, title: 'Page 1', slug: 'page1')
30
35
  I18n.with_locale :de do
31
36
  expect(helper.hide_content_tab?(@page)).to be_truthy
32
37
  end
@@ -11,8 +11,8 @@ describe Qbrick::Translatable do
11
11
  end
12
12
 
13
13
  describe 'normal locale' do
14
- before do
15
- I18n.locale = :en
14
+ around(:each) do |example|
15
+ I18n.with_locale(:en) { example.run }
16
16
  end
17
17
 
18
18
  describe '.translate' do
@@ -61,8 +61,8 @@ describe Qbrick::Translatable do
61
61
  end
62
62
 
63
63
  context 'when changing the locale' do
64
- before do
65
- I18n.locale = :de
64
+ around(:each) do |example|
65
+ I18n.with_locale(:de) { example.run }
66
66
  end
67
67
 
68
68
  it 'delegates the getter to current locale' do
@@ -79,15 +79,11 @@ describe Qbrick::Translatable do
79
79
  end
80
80
 
81
81
  describe 'country specific locale' do
82
- before do
83
- @locales = I18n.available_locales
84
- I18n.available_locales = [:de, 'de-CH']
85
- I18n.locale = 'de-CH'
86
- end
87
-
88
- after do
89
- I18n.available_locales = @locales
90
- I18n.locale = :en
82
+ around(:each) do |example|
83
+ available_locales_backup = I18n.available_locales.deep_dup
84
+ I18n.available_locales = [:de, 'de-CH', :en]
85
+ I18n.with_locale('de-CH') { example.run }
86
+ I18n.available_locales = available_locales_backup
91
87
  end
92
88
 
93
89
  describe '.translate' do
@@ -136,18 +132,23 @@ describe Qbrick::Translatable do
136
132
  end
137
133
 
138
134
  context 'when changing the locale' do
139
- before do
140
- I18n.locale = :de
141
- end
135
+ # outer describe block encapsulates with 'with_locale' and will set correct locale again!
136
+ before(:each) { I18n.locale = :de }
142
137
 
143
138
  it 'delegates the getter to current locale' do
139
+ locale_backup = I18n.locale
140
+ I18n.locale = :de
144
141
  expect(model).to receive(:name_de).and_return('Johannes')
145
142
  expect(model.name).to eq('Johannes')
143
+ I18n.locale = locale_backup
146
144
  end
147
145
 
148
146
  it 'delegates the getter to current locale' do
147
+ locale_backup = I18n.locale
148
+ I18n.locale = :de
149
149
  expect(model).to receive(:name_de=).with('Johannes')
150
150
  model.name = 'Johannes'
151
+ I18n.locale = locale_backup
151
152
  end
152
153
  end
153
154
  end