alchemy_cms 3.1.0.rc3 → 3.1.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e14489771d6905de909f3f5e46c0408ff9c739ab
4
- data.tar.gz: 9def26e3fdcf006427a909c983a2b0fefa043f04
3
+ metadata.gz: 1dd3580d83b92bb7990cc1a34e3567ebe037a409
4
+ data.tar.gz: 88b2975b2529f4a9ec05a780705a8d7d3c193286
5
5
  SHA512:
6
- metadata.gz: e0d265bd41d9bd04714b910a69027ceaa522ca725dd7fcd216e1ad451f56a76ed78caafc7d56876b4149b49044888bfef5d033b465ece9d16b3337582aad98c6
7
- data.tar.gz: 84c1e91cf582a2a0cbebe90436d2a9330d304f678518355fad2007583d08defd9ef29addda9379038fdd973b85da74365e9506186d71b6083cf71e0201f29d98
6
+ metadata.gz: a8e7aab4bbc54ca64d74829b148921fa122db90f1a7713e4aa554807a74ccd763ac23e97bdc8cad1643c49d4f31448b4d47fc0ff0bb63be9d867534f67935676
7
+ data.tar.gz: 43a18d1f7f2c31f76fccaa2f7b9afedf32ea6c5f192a65d9ff3aa71fdaeee94ff40e02b0d34e1e6015496c27ca976250ad4108edba0af319f0843e9a0eaedcf1
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source 'http://rubygems.org'
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
@@ -13,7 +13,11 @@ gem 'pg' if ENV['DB'] == 'postgresql'
13
13
  group :development, :test do
14
14
  gem 'jasmine-rails', github: 'searls/jasmine-rails'
15
15
  gem 'jasmine-jquery-rails', github: 'travisjeffery/jasmine-jquery-rails'
16
- gem 'coveralls', require: false
16
+ if ENV['TRAVIS']
17
+ gem 'coveralls', require: false
18
+ else
19
+ gem 'simplecov', require: false
20
+ end
17
21
  unless ENV['CI']
18
22
  gem 'launchy'
19
23
  gem 'annotate'
data/README.md CHANGED
@@ -1,7 +1,5 @@
1
1
  [![Gem Version](https://badge.fury.io/rb/alchemy_cms.svg)](http://badge.fury.io/rb/alchemy_cms)
2
- [![Build Status](https://travis-ci.org/AlchemyCMS/alchemy_cms.svg?branch=master)](https://travis-ci.org/AlchemyCMS/alchemy_cms) [![Code Climate](https://codeclimate.com/github/AlchemyCMS/alchemy_cms.svg)](https://codeclimate.com/github/AlchemyCMS/alchemy_cms) [![Coverage Status](https://img.shields.io/coveralls/AlchemyCMS/alchemy_cms.svg)](https://coveralls.io/r/AlchemyCMS/alchemy_cms?branch=master)
3
-
4
- **CAUTION: This master branch is a development branch that can contain bugs. For productive environments you should use the [current Ruby gem version](https://rubygems.org/gems/alchemy_cms/versions/3.0.0), or the [latest stable branch (3.0-stable)](https://github.com/AlchemyCMS/alchemy_cms/tree/3.0-stable).**
2
+ [![Build Status](https://travis-ci.org/AlchemyCMS/alchemy_cms.svg?branch=3.1-stable)](https://travis-ci.org/AlchemyCMS/alchemy_cms) [![Code Climate](https://codeclimate.com/github/AlchemyCMS/alchemy_cms.svg)](https://codeclimate.com/github/AlchemyCMS/alchemy_cms) [![Coverage Status](https://img.shields.io/coveralls/AlchemyCMS/alchemy_cms.svg)](https://coveralls.io/r/AlchemyCMS/alchemy_cms?branch=3.1-stable)
5
3
 
6
4
 
7
5
  ## About
@@ -33,8 +31,7 @@ Read more about Alchemy on the [website](http://alchemy-cms.com) and in the [gui
33
31
 
34
32
  **This version of Alchemy CMS runs with Rails 4 (including 4.1)**
35
33
 
36
- **Rails 4.2 support is coming soon. Watch [this pull request](https://github.com/AlchemyCMS/alchemy_cms/pull/655).**
37
-
34
+ * For Rails 4.2 support use the current [master branch](https://github.com/AlchemyCMS/alchemy_cms/tree/master).
38
35
  * For a Rails 3.2 compatible version use the [`2.8-stable` branch](https://github.com/AlchemyCMS/alchemy_cms/tree/2.8-stable).
39
36
  * For a Rails 3.1 compatible version use the [`2.1-stable` branch](https://github.com/AlchemyCMS/alchemy_cms/tree/2.1-stable).
40
37
  * For a Rails 3.0 compatible version use the [`2.0-stable` branch](https://github.com/AlchemyCMS/alchemy_cms/tree/2.0-stable).
@@ -55,7 +52,7 @@ For a Ruby 1.8.7 compatible version use the [`2.3-stable` branch](https://github
55
52
  Use the installer:
56
53
 
57
54
  ```shell
58
- $ gem install alchemy_cms --pre
55
+ $ gem install alchemy_cms
59
56
  $ alchemy new my_magicpage
60
57
  ```
61
58
 
@@ -74,11 +71,9 @@ $ alchemy --help
74
71
  Put this into your `Gemfile`:
75
72
 
76
73
  ```ruby
77
- gem 'alchemy_cms', github: 'AlchemyCMS/alchemy_cms', branch: 'master'
74
+ gem 'alchemy_cms', github: 'AlchemyCMS/alchemy_cms', branch: '3.1-stable'
78
75
  ```
79
76
 
80
- **NOTE:** You normally want to use a stable branch, like `3.0-stable`.
81
-
82
77
  If you want to use Russian translation and have better i18n support, you should put:
83
78
 
84
79
  ```ruby
@@ -103,16 +98,14 @@ the Devise based user model that Alchemy provides and was extracted [into its ow
103
98
  If you don't have your own user class, you can use the Alchemy user model. Just add the following gem into your `Gemfile`:
104
99
 
105
100
  ```ruby
106
- gem 'alchemy-devise', github: 'AlchemyCMS/alchemy-devise', branch: 'master'
101
+ gem 'alchemy-devise', github: 'AlchemyCMS/alchemy-devise', branch: '2.1-stable'
107
102
  ```
108
103
 
109
- **NOTE:** You normally want to use a stable branch, like `2.0-stable`.
110
-
111
104
  Then run:
112
105
 
113
106
  ```shell
114
107
  $ bundle install
115
- $ bin/rake alchemy_devise:install:migrations
108
+ $ bin/rails g alchemy:devise:install
116
109
  ```
117
110
 
118
111
  ##### Use your User model
@@ -123,10 +116,11 @@ The best practice is to use an initializer:
123
116
 
124
117
  ```ruby
125
118
  # config/initializers/alchemy.rb
126
- Alchemy.user_class_name = 'YourUserClass' # Defaults to 'User'
127
- Alchemy.signup_path = '/your/signup/path' # Defaults to '/signup'
128
- Alchemy.login_path = '/your/login/path' # Defaults to '/login'
129
- Alchemy.logout_path = '/your/logout/path' # Defaults to '/logout'
119
+ Alchemy.user_class_name = 'YourUserClass' # Defaults to 'User'
120
+ Alchemy.current_user_method = 'current_admin_user' # Defaults to 'current_user'
121
+ Alchemy.signup_path = '/your/signup/path' # Defaults to '/signup'
122
+ Alchemy.login_path = '/your/login/path' # Defaults to '/login'
123
+ Alchemy.logout_path = '/your/logout/path' # Defaults to '/logout'
130
124
  ```
131
125
 
132
126
  The only thing Alchemy needs to know from your user class is the `alchemy_roles` method.
@@ -12,9 +12,11 @@ module Alchemy
12
12
  before_action :set_root_page,
13
13
  only: [:index, :show, :sort, :order]
14
14
 
15
- authorize_resource class: Alchemy::Page
15
+ authorize_resource class: Alchemy::Page, except: :index
16
16
 
17
17
  def index
18
+ authorize! :index, :alchemy_admin_pages
19
+
18
20
  @locked_pages = Page.from_current_site.all_locked_by(current_alchemy_user)
19
21
  @languages = Language.all
20
22
  if !@page_root
@@ -310,6 +310,88 @@ class AlchemyTwoPointSix < ActiveRecord::Migration
310
310
  t.string "name"
311
311
  end
312
312
  end
313
+ end
314
+
315
+ def down
316
+ if table_exists?('alchemy_attachments')
317
+ drop_table "alchemy_attachments"
318
+ end
319
+
320
+ if table_exists?('alchemy_cells')
321
+ drop_table "alchemy_cells"
322
+ end
323
+
324
+ if table_exists?('alchemy_contents')
325
+ drop_table "alchemy_contents"
326
+ end
327
+
328
+ if table_exists?('alchemy_elements')
329
+ drop_table "alchemy_elements"
330
+ end
331
+
332
+ if table_exists?('alchemy_elements_alchemy_pages')
333
+ drop_table "alchemy_elements_alchemy_pages"
334
+ end
335
+
336
+ if table_exists?('alchemy_essence_booleans')
337
+ drop_table "alchemy_essence_booleans"
338
+ end
339
+
340
+ if table_exists?('alchemy_essence_dates')
341
+ drop_table "alchemy_essence_dates"
342
+ end
343
+
344
+ if table_exists?('alchemy_essence_files')
345
+ drop_table "alchemy_essence_files"
346
+ end
347
+
348
+ if table_exists?('alchemy_essence_htmls')
349
+ drop_table "alchemy_essence_htmls"
350
+ end
351
+
352
+ if table_exists?('alchemy_essence_links')
353
+ drop_table "alchemy_essence_links"
354
+ end
355
+
356
+ if table_exists?('alchemy_essence_pictures')
357
+ drop_table "alchemy_essence_pictures"
358
+ end
359
+
360
+ if table_exists?('alchemy_essence_richtexts')
361
+ drop_table "alchemy_essence_richtexts"
362
+ end
363
+
364
+ if table_exists?('alchemy_essence_selects')
365
+ drop_table "alchemy_essence_selects"
366
+ end
367
+
368
+ if table_exists?('alchemy_essence_texts')
369
+ drop_table "alchemy_essence_texts"
370
+ end
371
+
372
+ if table_exists?('alchemy_folded_pages')
373
+ drop_table "alchemy_folded_pages"
374
+ end
375
+
376
+ if table_exists?('alchemy_languages')
377
+ drop_table "alchemy_languages"
378
+ end
379
+
380
+ if table_exists?('alchemy_legacy_page_urls')
381
+ drop_table "alchemy_legacy_page_urls"
382
+ end
383
+
384
+ if table_exists?('alchemy_pages')
385
+ drop_table "alchemy_pages"
386
+ end
387
+
388
+ if table_exists?('alchemy_pictures')
389
+ drop_table "alchemy_pictures"
390
+ end
391
+
392
+ if table_exists?('alchemy_sites')
393
+ drop_table "alchemy_sites"
394
+ end
313
395
 
314
396
  end
315
397
  end
@@ -3,6 +3,7 @@
3
3
  # Alchemy has some defaults for user model name and login logout path names:
4
4
  #
5
5
  # +Alchemy.user_class_name+ defaults to +'User'+
6
+ # +Alchemy.current_user_method defaults to +'current_user'+
6
7
  # +Alchemy.signup_path defaults to +'/signup'+
7
8
  # +Alchemy.login_path defaults to +'/login'+
8
9
  # +Alchemy.logout_path defaults to +'/logout'+
@@ -10,14 +11,17 @@
10
11
  # Anyway, you can tell Alchemy about your authentication model configuration:
11
12
  #
12
13
  # 1. Your user class name - @see: Alchemy.user_class
13
- # 2. The path to the signup form - @see: Alchemy.signup_path
14
- # 3. The path to the login form - @see: Alchemy.login_path
15
- # 4. The path to the logout method - @see: Alchemy.logout_path
14
+ # 2. A method on your ApplicationController to get current user -
15
+ # @see: Alchemy.current_user_method
16
+ # 3. The path to the signup form - @see: Alchemy.signup_path
17
+ # 4. The path to the login form - @see: Alchemy.login_path
18
+ # 5. The path to the logout method - @see: Alchemy.logout_path
16
19
  #
17
20
  # == Example
18
21
  #
19
22
  # # config/initializers/alchemy.rb
20
23
  # Alchemy.user_class_name = 'Admin'
24
+ # Alchemy.current_user_method = 'current_admin'
21
25
  # Alchemy.signup_path = '/auth/signup'
22
26
  # Alchemy.login_path = '/auth/login'
23
27
  # Alchemy.logout_path = '/auth/logout'
@@ -1,5 +1,5 @@
1
1
  module Alchemy
2
- VERSION = "3.1.0.rc3"
2
+ VERSION = "3.1.0"
3
3
 
4
4
  def self.version
5
5
  VERSION
@@ -3,532 +3,551 @@ require 'spec_helper'
3
3
 
4
4
  module Alchemy
5
5
  describe Admin::PagesController do
6
- let(:user) { editor_user }
7
- before { sign_in(user) }
8
6
 
9
- describe '#index' do
10
- let(:language) { build_stubbed(:language) }
11
- let(:language_root) { build_stubbed(:language_root_page) }
12
-
13
- context 'with existing language root page' do
14
- before do
15
- expect(Language).to receive(:current_root_page).and_return(language_root)
16
- end
17
-
18
- it "assigns @page_root variable" do
19
- get :index
20
- expect(assigns(:page_root)).to be(language_root)
21
- end
7
+ context 'a guest' do
8
+ it 'can not access page tree' do
9
+ get :index
10
+ expect(request).to redirect_to(Alchemy.login_path)
22
11
  end
12
+ end
23
13
 
24
- context 'without language root page' do
25
- before do
26
- expect(Language).to receive(:current_root_page).and_return(nil)
27
- expect(Language).to receive(:find_by).and_return(language)
28
- expect(Language).to receive(:all).and_return([language])
29
- expect(Language).to receive(:with_root_page).and_return([language])
30
- end
14
+ context 'a member' do
15
+ before { sign_in(member_user) }
31
16
 
32
- it "it assigns current language" do
33
- get :index
34
- expect(assigns(:language)).to be(language)
35
- end
17
+ it 'can not access page tree' do
18
+ get :index
19
+ expect(request).to redirect_to(root_path)
36
20
  end
37
21
  end
38
22
 
39
- describe "#flush" do
40
- let(:language) { mock_model('Language', code: 'en', pages: double(flushables: [page_1, page_2])) }
41
- let(:page_1) { build_stubbed(:page) }
42
- let(:page_2) { build_stubbed(:page) }
23
+ context 'with logged in editor user' do
24
+ let(:user) { editor_user }
43
25
 
44
- before do
45
- expect(Language).to receive(:current).at_least(:once).and_return(language)
46
- end
26
+ before { sign_in(user) }
47
27
 
48
- it "should remove the cache of all pages" do
49
- expect(page_1).to receive(:publish!)
50
- expect(page_2).to receive(:publish!)
51
- xhr :post, :flush
52
- end
53
- end
28
+ describe '#index' do
29
+ let(:language) { build_stubbed(:language) }
30
+ let(:language_root) { build_stubbed(:language_root_page) }
54
31
 
55
- describe '#new' do
56
- context "pages in clipboard" do
57
- let(:clipboard) { session[:alchemy_clipboard] = {} }
58
- let(:page) { mock_model(Alchemy::Page, name: 'Foobar') }
32
+ context 'with existing language root page' do
33
+ before do
34
+ expect(Language).to receive(:current_root_page).and_return(language_root)
35
+ end
59
36
 
60
- before { clipboard['pages'] = [{'id' => page.id.to_s, 'action' => 'copy'}] }
37
+ it "assigns @page_root variable" do
38
+ get :index
39
+ expect(assigns(:page_root)).to be(language_root)
40
+ end
41
+ end
61
42
 
62
- it "should load all pages from clipboard" do
63
- xhr :get, :new, {page_id: page.id}
64
- expect(assigns(:clipboard_items)).to be_kind_of(Array)
43
+ context 'without language root page' do
44
+ before do
45
+ expect(Language).to receive(:current_root_page).and_return(nil)
46
+ expect(Language).to receive(:find_by).and_return(language)
47
+ expect(Language).to receive(:all).and_return([language])
48
+ expect(Language).to receive(:with_root_page).and_return([language])
49
+ end
50
+
51
+ it "it assigns current language" do
52
+ get :index
53
+ expect(assigns(:language)).to be(language)
54
+ end
65
55
  end
66
56
  end
67
- end
68
57
 
69
- describe '#show' do
70
- let(:page) { build_stubbed(:page, language_code: 'nl') }
58
+ describe "#flush" do
59
+ let(:language) { mock_model('Language', code: 'en', pages: double(flushables: [page_1, page_2])) }
60
+ let(:page_1) { build_stubbed(:page) }
61
+ let(:page_2) { build_stubbed(:page) }
71
62
 
72
- before do
73
- expect(Page).to receive(:find).with("#{page.id}").and_return(page)
74
- allow(Page).to receive(:language_root_for).and_return(mock_model(Alchemy::Page))
75
- end
63
+ before do
64
+ expect(Language).to receive(:current).at_least(:once).and_return(language)
65
+ end
76
66
 
77
- it "should assign @preview_mode with true" do
78
- get :show, id: page.id
79
- expect(assigns(:preview_mode)).to eq(true)
67
+ it "should remove the cache of all pages" do
68
+ expect(page_1).to receive(:publish!)
69
+ expect(page_2).to receive(:publish!)
70
+ xhr :post, :flush
71
+ end
80
72
  end
81
73
 
82
- it "should store page as current preview" do
83
- Page.current_preview = nil
84
- get :show, id: page.id
85
- expect(Page.current_preview).to eq(page)
86
- end
74
+ describe '#new' do
75
+ context "pages in clipboard" do
76
+ let(:clipboard) { session[:alchemy_clipboard] = {} }
77
+ let(:page) { mock_model(Alchemy::Page, name: 'Foobar') }
87
78
 
88
- it "should set the I18n locale to the pages language code" do
89
- get :show, id: page.id
90
- expect(::I18n.locale).to eq(:nl)
91
- end
79
+ before { clipboard['pages'] = [{'id' => page.id.to_s, 'action' => 'copy'}] }
92
80
 
93
- it "renders the application layout" do
94
- get :show, id: page.id
95
- expect(response).to render_template(layout: 'application')
81
+ it "should load all pages from clipboard" do
82
+ xhr :get, :new, {page_id: page.id}
83
+ expect(assigns(:clipboard_items)).to be_kind_of(Array)
84
+ end
85
+ end
96
86
  end
97
- end
98
87
 
99
- describe '#order' do
100
- let(:page_1) { FactoryGirl.create(:page, visible: true) }
101
- let(:page_2) { FactoryGirl.create(:page, visible: true) }
102
- let(:page_3) { FactoryGirl.create(:page, visible: true) }
103
- let(:page_item_1) { {id: page_1.id, slug: page_1.slug, restricted: false, external: page_1.redirects_to_external?, visible: page_1.visible?, children: [page_item_2]} }
104
- let(:page_item_2) { {id: page_2.id, slug: page_2.slug, restricted: false, external: page_2.redirects_to_external?, visible: page_2.visible?, children: [page_item_3]} }
105
- let(:page_item_3) { {id: page_3.id, slug: page_3.slug, restricted: false, external: page_3.redirects_to_external?, visible: page_3.visible? } }
106
- let(:set_of_pages) { [page_item_1] }
107
-
108
- it "stores the new order" do
109
- xhr :post, :order, set: set_of_pages.to_json
110
- page_1.reload
111
- expect(page_1.descendants).to eq([page_2, page_3])
112
- end
88
+ describe '#show' do
89
+ let(:page) { build_stubbed(:page, language_code: 'nl') }
113
90
 
114
- context 'with url nesting enabled' do
115
91
  before do
116
- expect(Alchemy::Config).to receive(:get).with(:url_nesting).at_least(:once).and_return(true)
92
+ expect(Page).to receive(:find).with("#{page.id}").and_return(page)
93
+ allow(Page).to receive(:language_root_for).and_return(mock_model(Alchemy::Page))
94
+ end
95
+
96
+ it "should assign @preview_mode with true" do
97
+ get :show, id: page.id
98
+ expect(assigns(:preview_mode)).to eq(true)
99
+ end
100
+
101
+ it "should store page as current preview" do
102
+ Page.current_preview = nil
103
+ get :show, id: page.id
104
+ expect(Page.current_preview).to eq(page)
117
105
  end
118
106
 
119
- it "updates the pages urlnames" do
107
+ it "should set the I18n locale to the pages language code" do
108
+ get :show, id: page.id
109
+ expect(::I18n.locale).to eq(:nl)
110
+ end
111
+
112
+ it "renders the application layout" do
113
+ get :show, id: page.id
114
+ expect(response).to render_template(layout: 'application')
115
+ end
116
+ end
117
+
118
+ describe '#order' do
119
+ let(:page_1) { FactoryGirl.create(:page, visible: true) }
120
+ let(:page_2) { FactoryGirl.create(:page, visible: true) }
121
+ let(:page_3) { FactoryGirl.create(:page, visible: true) }
122
+ let(:page_item_1) { {id: page_1.id, slug: page_1.slug, restricted: false, external: page_1.redirects_to_external?, visible: page_1.visible?, children: [page_item_2]} }
123
+ let(:page_item_2) { {id: page_2.id, slug: page_2.slug, restricted: false, external: page_2.redirects_to_external?, visible: page_2.visible?, children: [page_item_3]} }
124
+ let(:page_item_3) { {id: page_3.id, slug: page_3.slug, restricted: false, external: page_3.redirects_to_external?, visible: page_3.visible? } }
125
+ let(:set_of_pages) { [page_item_1] }
126
+
127
+ it "stores the new order" do
120
128
  xhr :post, :order, set: set_of_pages.to_json
121
- [page_1, page_2, page_3].map(&:reload)
122
- expect(page_1.urlname).to eq("#{page_1.slug}")
123
- expect(page_2.urlname).to eq("#{page_1.slug}/#{page_2.slug}")
124
- expect(page_3.urlname).to eq("#{page_1.slug}/#{page_2.slug}/#{page_3.slug}")
129
+ page_1.reload
130
+ expect(page_1.descendants).to eq([page_2, page_3])
125
131
  end
126
132
 
127
- context 'with invisible page in tree' do
128
- let(:page_item_2) do
129
- {
130
- id: page_2.id,
131
- slug: page_2.slug,
132
- children: [page_item_3],
133
- visible: false
134
- }
133
+ context 'with url nesting enabled' do
134
+ before do
135
+ expect(Alchemy::Config).to receive(:get).with(:url_nesting).at_least(:once).and_return(true)
135
136
  end
136
137
 
137
- it "does not use this pages slug in urlnames of descendants" do
138
+ it "updates the pages urlnames" do
138
139
  xhr :post, :order, set: set_of_pages.to_json
139
140
  [page_1, page_2, page_3].map(&:reload)
140
141
  expect(page_1.urlname).to eq("#{page_1.slug}")
141
142
  expect(page_2.urlname).to eq("#{page_1.slug}/#{page_2.slug}")
142
- expect(page_3.urlname).to eq("#{page_1.slug}/#{page_3.slug}")
143
+ expect(page_3.urlname).to eq("#{page_1.slug}/#{page_2.slug}/#{page_3.slug}")
143
144
  end
144
- end
145
145
 
146
- context 'with external page in tree' do
147
- let(:page_item_2) do
148
- {
149
- id: page_2.id,
150
- slug: page_2.slug,
151
- children: [page_item_3],
152
- external: true
153
- }
154
- end
146
+ context 'with invisible page in tree' do
147
+ let(:page_item_2) do
148
+ {
149
+ id: page_2.id,
150
+ slug: page_2.slug,
151
+ children: [page_item_3],
152
+ visible: false
153
+ }
154
+ end
155
155
 
156
- it "does not use this pages slug in urlnames of descendants" do
157
- xhr :post, :order, set: set_of_pages.to_json
158
- [page_1, page_2, page_3].map(&:reload)
159
- expect(page_3.urlname).to eq("#{page_1.slug}/#{page_3.slug}")
156
+ it "does not use this pages slug in urlnames of descendants" do
157
+ xhr :post, :order, set: set_of_pages.to_json
158
+ [page_1, page_2, page_3].map(&:reload)
159
+ expect(page_1.urlname).to eq("#{page_1.slug}")
160
+ expect(page_2.urlname).to eq("#{page_1.slug}/#{page_2.slug}")
161
+ expect(page_3.urlname).to eq("#{page_1.slug}/#{page_3.slug}")
162
+ end
160
163
  end
161
- end
162
164
 
163
- context 'with restricted page in tree' do
164
- let(:page_2) { FactoryGirl.create(:page, restricted: true) }
165
- let(:page_item_2) do
166
- {
167
- id: page_2.id,
168
- slug: page_2.slug,
169
- children: [page_item_3],
170
- restricted: true
171
- }
172
- end
165
+ context 'with external page in tree' do
166
+ let(:page_item_2) do
167
+ {
168
+ id: page_2.id,
169
+ slug: page_2.slug,
170
+ children: [page_item_3],
171
+ external: true
172
+ }
173
+ end
173
174
 
174
- it "updates restricted status of descendants" do
175
- xhr :post, :order, set: set_of_pages.to_json
176
- page_3.reload
177
- expect(page_3.restricted).to be_truthy
175
+ it "does not use this pages slug in urlnames of descendants" do
176
+ xhr :post, :order, set: set_of_pages.to_json
177
+ [page_1, page_2, page_3].map(&:reload)
178
+ expect(page_3.urlname).to eq("#{page_1.slug}/#{page_3.slug}")
179
+ end
178
180
  end
179
- end
180
181
 
181
- context 'with page having number as slug' do
182
- let(:page_item_2) do
183
- {
184
- id: page_2.id,
185
- slug: 42,
186
- children: [page_item_3]
187
- }
182
+ context 'with restricted page in tree' do
183
+ let(:page_2) { FactoryGirl.create(:page, restricted: true) }
184
+ let(:page_item_2) do
185
+ {
186
+ id: page_2.id,
187
+ slug: page_2.slug,
188
+ children: [page_item_3],
189
+ restricted: true
190
+ }
191
+ end
192
+
193
+ it "updates restricted status of descendants" do
194
+ xhr :post, :order, set: set_of_pages.to_json
195
+ page_3.reload
196
+ expect(page_3.restricted).to be_truthy
197
+ end
188
198
  end
189
199
 
190
- it "does not raise error" do
191
- expect {
200
+ context 'with page having number as slug' do
201
+ let(:page_item_2) do
202
+ {
203
+ id: page_2.id,
204
+ slug: 42,
205
+ children: [page_item_3]
206
+ }
207
+ end
208
+
209
+ it "does not raise error" do
210
+ expect {
211
+ xhr :post, :order, set: set_of_pages.to_json
212
+ }.not_to raise_error
213
+ end
214
+
215
+ it "still generates the correct urlname on page_3" do
192
216
  xhr :post, :order, set: set_of_pages.to_json
193
- }.not_to raise_error
217
+ [page_1, page_2, page_3].map(&:reload)
218
+ expect(page_3.urlname).to eq("#{page_1.slug}/#{page_2.slug}/#{page_3.slug}")
219
+ end
194
220
  end
195
221
 
196
- it "still generates the correct urlname on page_3" do
222
+ it "creates legacy urls" do
197
223
  xhr :post, :order, set: set_of_pages.to_json
198
- [page_1, page_2, page_3].map(&:reload)
199
- expect(page_3.urlname).to eq("#{page_1.slug}/#{page_2.slug}/#{page_3.slug}")
224
+ [page_2, page_3].map(&:reload)
225
+ expect(page_2.legacy_urls.size).to eq(1)
226
+ expect(page_3.legacy_urls.size).to eq(1)
200
227
  end
201
228
  end
202
-
203
- it "creates legacy urls" do
204
- xhr :post, :order, set: set_of_pages.to_json
205
- [page_2, page_3].map(&:reload)
206
- expect(page_2.legacy_urls.size).to eq(1)
207
- expect(page_3.legacy_urls.size).to eq(1)
208
- end
209
229
  end
210
- end
211
230
 
212
- describe "#configure" do
213
- render_views
231
+ describe "#configure" do
232
+ render_views
214
233
 
215
- context "with page having nested urlname" do
216
- let(:page) { create(:page, name: 'Foobar') }
234
+ context "with page having nested urlname" do
235
+ let(:page) { create(:page, name: 'Foobar') }
217
236
 
218
- it "should always show the slug" do
219
- xhr :get, :configure, {id: page.id}
220
- expect(response.body).to match /value="foobar"/
237
+ it "should always show the slug" do
238
+ xhr :get, :configure, {id: page.id}
239
+ expect(response.body).to match /value="foobar"/
240
+ end
221
241
  end
222
242
  end
223
- end
224
243
 
225
- describe '#create' do
226
- let(:language) { mock_model('Language', code: 'kl') }
227
- let(:parent) { mock_model('Page', language: language) }
228
- let(:page_params) { {parent_id: parent.id, name: 'new Page'} }
244
+ describe '#create' do
245
+ let(:language) { mock_model('Language', code: 'kl') }
246
+ let(:parent) { mock_model('Page', language: language) }
247
+ let(:page_params) { {parent_id: parent.id, name: 'new Page'} }
229
248
 
230
- context "a new page" do
231
- before do
232
- allow_any_instance_of(Page).to receive(:set_language_from_parent_or_default)
233
- allow_any_instance_of(Page).to receive(:save).and_return(true)
234
- end
235
-
236
- it "is nested under given parent" do
237
- allow(controller).to receive(:edit_admin_page_path).and_return('bla')
238
- xhr :post, :create, {page: page_params}
239
- expect(assigns(:page).parent_id).to eq(parent.id)
240
- end
241
-
242
- it "redirects to edit page template" do
243
- page = mock_model('Page')
244
- expect(controller).to receive(:edit_admin_page_path).and_return('bla')
245
- post :create, page: page_params
246
- expect(response).to redirect_to('bla')
247
- end
249
+ context "a new page" do
250
+ before do
251
+ allow_any_instance_of(Page).to receive(:set_language_from_parent_or_default)
252
+ allow_any_instance_of(Page).to receive(:save).and_return(true)
253
+ end
248
254
 
249
- context "if new page can not be saved" do
250
- it "renders the create form" do
251
- allow_any_instance_of(Page).to receive(:save).and_return(false)
252
- post :create, page: {name: 'page'}
253
- expect(response).to render_template('new')
255
+ it "is nested under given parent" do
256
+ allow(controller).to receive(:edit_admin_page_path).and_return('bla')
257
+ xhr :post, :create, {page: page_params}
258
+ expect(assigns(:page).parent_id).to eq(parent.id)
254
259
  end
255
- end
256
260
 
257
- context "with redirect_to in params" do
258
- let(:page_params) do
259
- {name: "Foobar", page_layout: 'standard', parent_id: parent.id}
261
+ it "redirects to edit page template" do
262
+ page = mock_model('Page')
263
+ expect(controller).to receive(:edit_admin_page_path).and_return('bla')
264
+ post :create, page: page_params
265
+ expect(response).to redirect_to('bla')
260
266
  end
261
267
 
262
- it "should redirect to given url" do
263
- post :create, page: page_params, redirect_to: admin_pictures_path
264
- expect(response).to redirect_to(admin_pictures_path)
268
+ context "if new page can not be saved" do
269
+ it "renders the create form" do
270
+ allow_any_instance_of(Page).to receive(:save).and_return(false)
271
+ post :create, page: {name: 'page'}
272
+ expect(response).to render_template('new')
273
+ end
265
274
  end
266
275
 
267
- context "but new page can not be saved" do
268
- render_views
276
+ context "with redirect_to in params" do
277
+ let(:page_params) do
278
+ {name: "Foobar", page_layout: 'standard', parent_id: parent.id}
279
+ end
269
280
 
270
- it "should render the `new` template" do
271
- allow_any_instance_of(Page).to receive(:save).and_return(false)
272
- xhr :post, :create, page: {name: 'page'}, redirect_to: admin_pictures_path
273
- expect(response.body).to match /form.+action=\"\/admin\/pages\"/
281
+ it "should redirect to given url" do
282
+ post :create, page: page_params, redirect_to: admin_pictures_path
283
+ expect(response).to redirect_to(admin_pictures_path)
284
+ end
285
+
286
+ context "but new page can not be saved" do
287
+ render_views
288
+
289
+ it "should render the `new` template" do
290
+ allow_any_instance_of(Page).to receive(:save).and_return(false)
291
+ xhr :post, :create, page: {name: 'page'}, redirect_to: admin_pictures_path
292
+ expect(response.body).to match /form.+action=\"\/admin\/pages\"/
293
+ end
294
+ end
295
+ end
296
+
297
+ context 'with page redirecting to external' do
298
+ it "redirects to sitemap" do
299
+ expect_any_instance_of(Page).to receive(:redirects_to_external?).and_return(true)
300
+ post :create, page: page_params
301
+ expect(response).to redirect_to(admin_pages_path)
274
302
  end
275
303
  end
276
304
  end
277
305
 
278
- context 'with page redirecting to external' do
279
- it "redirects to sitemap" do
280
- expect_any_instance_of(Page).to receive(:redirects_to_external?).and_return(true)
281
- post :create, page: page_params
282
- expect(response).to redirect_to(admin_pages_path)
306
+ context "with paste_from_clipboard in parameters" do
307
+ let(:page_in_clipboard) { mock_model(Alchemy::Page) }
308
+
309
+ before do
310
+ allow(Page).to receive(:find_by).with(id: "#{parent.id}").and_return(parent)
311
+ allow(Page).to receive(:find).with("#{page_in_clipboard.id}").and_return(page_in_clipboard)
312
+ end
313
+
314
+ it "should call Page#copy_and_paste" do
315
+ expect(Page).to receive(:copy_and_paste).with(
316
+ page_in_clipboard,
317
+ parent,
318
+ 'pasted Page'
319
+ ).and_return(
320
+ mock_model('Page', save: true, name: 'pasted Page', redirects_to_external?: false)
321
+ )
322
+ xhr :post, :create, {paste_from_clipboard: page_in_clipboard.id, page: {parent_id: parent.id, name: 'pasted Page'}}
283
323
  end
284
324
  end
285
325
  end
286
326
 
287
- context "with paste_from_clipboard in parameters" do
288
- let(:page_in_clipboard) { mock_model(Alchemy::Page) }
327
+ describe '#copy_language_tree' do
328
+ let(:params) { {languages: {new_lang_id: '2', old_lang_id: '1'}} }
329
+ let(:language_root_to_copy_from) { build_stubbed(:language_root_page) }
330
+ let(:copy_of_language_root) { build_stubbed(:language_root_page) }
331
+ let(:root_page) { mock_model('Page') }
289
332
 
290
333
  before do
291
- allow(Page).to receive(:find_by).with(id: "#{parent.id}").and_return(parent)
292
- allow(Page).to receive(:find).with("#{page_in_clipboard.id}").and_return(page_in_clipboard)
334
+ allow(Page).to receive(:copy).and_return(copy_of_language_root)
335
+ allow(Page).to receive(:root).and_return(root_page)
336
+ allow(Page).to receive(:language_root_for).and_return(language_root_to_copy_from)
337
+ allow_any_instance_of(Page).to receive(:move_to_child_of)
338
+ allow_any_instance_of(Page).to receive(:copy_children_to)
339
+ allow(controller).to receive(:store_current_language)
340
+ allow(Language).to receive(:current).and_return(mock_model('Language', language_code: 'it', code: 'it'))
293
341
  end
294
342
 
295
- it "should call Page#copy_and_paste" do
296
- expect(Page).to receive(:copy_and_paste).with(
297
- page_in_clipboard,
298
- parent,
299
- 'pasted Page'
300
- ).and_return(
301
- mock_model('Page', save: true, name: 'pasted Page', redirects_to_external?: false)
302
- )
303
- xhr :post, :create, {paste_from_clipboard: page_in_clipboard.id, page: {parent_id: parent.id, name: 'pasted Page'}}
343
+ it "should copy the language root page over to the other language" do
344
+ expect(Page).to receive(:copy).with(language_root_to_copy_from, {language_id: '2', language_code: 'it'})
345
+ post :copy_language_tree, params
304
346
  end
305
- end
306
- end
307
347
 
308
- describe '#copy_language_tree' do
309
- let(:params) { {languages: {new_lang_id: '2', old_lang_id: '1'}} }
310
- let(:language_root_to_copy_from) { build_stubbed(:language_root_page) }
311
- let(:copy_of_language_root) { build_stubbed(:language_root_page) }
312
- let(:root_page) { mock_model('Page') }
313
-
314
- before do
315
- allow(Page).to receive(:copy).and_return(copy_of_language_root)
316
- allow(Page).to receive(:root).and_return(root_page)
317
- allow(Page).to receive(:language_root_for).and_return(language_root_to_copy_from)
318
- allow_any_instance_of(Page).to receive(:move_to_child_of)
319
- allow_any_instance_of(Page).to receive(:copy_children_to)
320
- allow(controller).to receive(:store_current_language)
321
- allow(Language).to receive(:current).and_return(mock_model('Language', language_code: 'it', code: 'it'))
322
- end
348
+ it "should move the newly created language-root-page below the absolute root page" do
349
+ expect(copy_of_language_root).to receive(:move_to_child_of).with(root_page)
350
+ post :copy_language_tree, params
351
+ end
323
352
 
324
- it "should copy the language root page over to the other language" do
325
- expect(Page).to receive(:copy).with(language_root_to_copy_from, {language_id: '2', language_code: 'it'})
326
- post :copy_language_tree, params
327
- end
353
+ it "should copy all childs of the original page over to the new created one" do
354
+ expect(controller).to receive(:language_root_to_copy_from).and_return(language_root_to_copy_from)
355
+ expect(controller).to receive(:copy_of_language_root).and_return(copy_of_language_root)
356
+ expect(language_root_to_copy_from).to receive(:copy_children_to).with(copy_of_language_root)
357
+ post :copy_language_tree, params
358
+ end
328
359
 
329
- it "should move the newly created language-root-page below the absolute root page" do
330
- expect(copy_of_language_root).to receive(:move_to_child_of).with(root_page)
331
- post :copy_language_tree, params
360
+ it "should redirect to admin_pages_path" do
361
+ allow(controller).to receive(:copy_of_language_root)
362
+ allow(controller).to receive(:language_root_to_copy_from).and_return(double(copy_children_to: nil))
363
+ post :copy_language_tree, params
364
+ expect(response).to redirect_to(admin_pages_path)
365
+ end
332
366
  end
333
367
 
334
- it "should copy all childs of the original page over to the new created one" do
335
- expect(controller).to receive(:language_root_to_copy_from).and_return(language_root_to_copy_from)
336
- expect(controller).to receive(:copy_of_language_root).and_return(copy_of_language_root)
337
- expect(language_root_to_copy_from).to receive(:copy_children_to).with(copy_of_language_root)
338
- post :copy_language_tree, params
339
- end
368
+ describe '#edit' do
369
+ let!(:page) { create(:page) }
370
+ let!(:other_user) { create(:author_user) }
340
371
 
341
- it "should redirect to admin_pages_path" do
342
- allow(controller).to receive(:copy_of_language_root)
343
- allow(controller).to receive(:language_root_to_copy_from).and_return(double(copy_children_to: nil))
344
- post :copy_language_tree, params
345
- expect(response).to redirect_to(admin_pages_path)
346
- end
347
- end
372
+ context 'if page is locked by another user' do
373
+ before { page.lock_to!(other_user) }
374
+
375
+ context 'that is signed in' do
376
+ before do
377
+ expect_any_instance_of(DummyUser).to receive(:logged_in?).and_return(true)
378
+ end
348
379
 
349
- describe '#edit' do
350
- let!(:page) { create(:page) }
351
- let!(:other_user) { create(:author_user) }
380
+ it 'redirects to sitemap' do
381
+ get :edit, id: page.id
382
+ expect(response).to redirect_to(admin_pages_path)
383
+ end
384
+ end
352
385
 
353
- context 'if page is locked by another user' do
354
- before { page.lock_to!(other_user) }
386
+ context 'that is not signed in' do
387
+ before do
388
+ expect_any_instance_of(DummyUser).to receive(:logged_in?).and_return(false)
389
+ end
390
+
391
+ it 'renders the edit view' do
392
+ get :edit, id: page.id
393
+ expect(response).to render_template(:edit)
394
+ end
395
+ end
396
+ end
355
397
 
356
- context 'that is signed in' do
398
+ context 'if page is locked by myself' do
357
399
  before do
358
- expect_any_instance_of(DummyUser).to receive(:logged_in?).and_return(true)
400
+ expect_any_instance_of(Page).to receive(:locker).and_return(user)
401
+ expect(user).to receive(:logged_in?).and_return(true)
359
402
  end
360
403
 
361
- it 'redirects to sitemap' do
404
+ it 'renders the edit view' do
362
405
  get :edit, id: page.id
363
- expect(response).to redirect_to(admin_pages_path)
406
+ expect(response).to render_template(:edit)
364
407
  end
365
408
  end
366
409
 
367
- context 'that is not signed in' do
410
+ context 'if page is not locked' do
368
411
  before do
369
- expect_any_instance_of(DummyUser).to receive(:logged_in?).and_return(false)
412
+ expect_any_instance_of(Page).to receive(:locker).and_return(nil)
370
413
  end
371
414
 
372
415
  it 'renders the edit view' do
373
416
  get :edit, id: page.id
374
417
  expect(response).to render_template(:edit)
375
418
  end
376
- end
377
- end
378
419
 
379
- context 'if page is locked by myself' do
380
- before do
381
- expect_any_instance_of(Page).to receive(:locker).and_return(user)
382
- expect(user).to receive(:logged_in?).and_return(true)
383
- end
384
-
385
- it 'renders the edit view' do
386
- get :edit, id: page.id
387
- expect(response).to render_template(:edit)
420
+ it "lockes the page to myself" do
421
+ expect_any_instance_of(Page).to receive(:lock_to!)
422
+ get :edit, id: page.id
423
+ end
388
424
  end
389
425
  end
390
426
 
391
- context 'if page is not locked' do
392
- before do
393
- expect_any_instance_of(Page).to receive(:locker).and_return(nil)
394
- end
427
+ describe '#destroy' do
428
+ let(:clipboard) { session[:alchemy_clipboard] = {} }
429
+ let(:page) { FactoryGirl.create(:public_page) }
395
430
 
396
- it 'renders the edit view' do
397
- get :edit, id: page.id
398
- expect(response).to render_template(:edit)
399
- end
431
+ before { clipboard['pages'] = [{'id' => page.id.to_s}] }
400
432
 
401
- it "lockes the page to myself" do
402
- expect_any_instance_of(Page).to receive(:lock_to!)
403
- get :edit, id: page.id
433
+ it "should also remove the page from clipboard" do
434
+ xhr :post, :destroy, {id: page.id, _method: :delete}
435
+ expect(clipboard['pages']).to be_empty
404
436
  end
405
437
  end
406
- end
407
438
 
408
- describe '#destroy' do
409
- let(:clipboard) { session[:alchemy_clipboard] = {} }
410
- let(:page) { FactoryGirl.create(:public_page) }
439
+ describe '#publish' do
440
+ let(:page) { stub_model(Page, published_at: nil, public: false, name: "page", parent_id: 1, urlname: "page", language: stub_model(Language), page_layout: "bla") }
411
441
 
412
- before { clipboard['pages'] = [{'id' => page.id.to_s}] }
413
-
414
- it "should also remove the page from clipboard" do
415
- xhr :post, :destroy, {id: page.id, _method: :delete}
416
- expect(clipboard['pages']).to be_empty
417
- end
418
- end
419
-
420
- describe '#publish' do
421
- let(:page) { stub_model(Page, published_at: nil, public: false, name: "page", parent_id: 1, urlname: "page", language: stub_model(Language), page_layout: "bla") }
422
-
423
- before do
424
- allow(@controller).to receive(:load_page).and_return(page)
425
- @controller.instance_variable_set("@page", page)
426
- end
442
+ before do
443
+ allow(@controller).to receive(:load_page).and_return(page)
444
+ @controller.instance_variable_set("@page", page)
445
+ end
427
446
 
428
- it "should publish the page" do
429
- expect(page).to receive(:publish!)
430
- post :publish, { id: page.id }
447
+ it "should publish the page" do
448
+ expect(page).to receive(:publish!)
449
+ post :publish, { id: page.id }
450
+ end
431
451
  end
432
- end
433
452
 
434
- describe '#visit' do
435
- let(:page) { mock_model(Alchemy::Page, urlname: 'home') }
453
+ describe '#visit' do
454
+ let(:page) { mock_model(Alchemy::Page, urlname: 'home') }
436
455
 
437
- before do
438
- allow(Page).to receive(:find).with("#{page.id}").and_return(page)
439
- allow(page).to receive(:unlock!).and_return(true)
440
- allow(@controller).to receive(:multi_language?).and_return(false)
441
- end
456
+ before do
457
+ allow(Page).to receive(:find).with("#{page.id}").and_return(page)
458
+ allow(page).to receive(:unlock!).and_return(true)
459
+ allow(@controller).to receive(:multi_language?).and_return(false)
460
+ end
442
461
 
443
- it "should redirect to the page path" do
444
- expect(post :visit, id: page.id).to redirect_to(show_page_path(urlname: 'home'))
462
+ it "should redirect to the page path" do
463
+ expect(post :visit, id: page.id).to redirect_to(show_page_path(urlname: 'home'))
464
+ end
445
465
  end
446
- end
447
466
 
448
- describe '#fold' do
449
- let(:page) { mock_model(Alchemy::Page) }
450
- before { allow(Page).to receive(:find).and_return(page) }
467
+ describe '#fold' do
468
+ let(:page) { mock_model(Alchemy::Page) }
469
+ before { allow(Page).to receive(:find).and_return(page) }
451
470
 
452
- context "if page is currently not folded" do
453
- before { allow(page).to receive(:folded?).and_return(false) }
471
+ context "if page is currently not folded" do
472
+ before { allow(page).to receive(:folded?).and_return(false) }
454
473
 
455
- it "should fold the page" do
456
- expect(page).to receive(:fold!).with(user.id, true).and_return(true)
457
- xhr :post, :fold, id: page.id
474
+ it "should fold the page" do
475
+ expect(page).to receive(:fold!).with(user.id, true).and_return(true)
476
+ xhr :post, :fold, id: page.id
477
+ end
458
478
  end
459
- end
460
479
 
461
- context "if page is already folded" do
462
- before { allow(page).to receive(:folded?).and_return(true) }
480
+ context "if page is already folded" do
481
+ before { allow(page).to receive(:folded?).and_return(true) }
463
482
 
464
- it "should unfold the page" do
465
- expect(page).to receive(:fold!).with(user.id, false).and_return(true)
466
- xhr :post, :fold, id: page.id
483
+ it "should unfold the page" do
484
+ expect(page).to receive(:fold!).with(user.id, false).and_return(true)
485
+ xhr :post, :fold, id: page.id
486
+ end
467
487
  end
468
488
  end
469
- end
470
489
 
471
- describe '#sort' do
472
- before { allow(Page).to receive(:language_root_for).and_return(mock_model(Alchemy::Page)) }
490
+ describe '#sort' do
491
+ before { allow(Page).to receive(:language_root_for).and_return(mock_model(Alchemy::Page)) }
473
492
 
474
- it "should assign @sorting with true" do
475
- xhr :get, :sort
476
- expect(assigns(:sorting)).to eq(true)
493
+ it "should assign @sorting with true" do
494
+ xhr :get, :sort
495
+ expect(assigns(:sorting)).to eq(true)
496
+ end
477
497
  end
478
- end
479
-
480
- describe '#unlock' do
481
- let(:page) { mock_model(Alchemy::Page, name: 'Best practices') }
482
498
 
483
- before do
484
- allow(Page).to receive(:find).with("#{page.id}").and_return(page)
485
- allow(Page).to receive(:from_current_site).and_return(double(all_locked_by: nil))
486
- expect(page).to receive(:unlock!).and_return(true)
487
- end
499
+ describe '#unlock' do
500
+ let(:page) { mock_model(Alchemy::Page, name: 'Best practices') }
488
501
 
489
- it "should unlock the page" do
490
- xhr :post, :unlock, id: "#{page.id}"
491
- end
502
+ before do
503
+ allow(Page).to receive(:find).with("#{page.id}").and_return(page)
504
+ allow(Page).to receive(:from_current_site).and_return(double(all_locked_by: nil))
505
+ expect(page).to receive(:unlock!).and_return(true)
506
+ end
492
507
 
493
- context 'requesting for html format' do
494
- it "should redirect to admin_pages_path" do
495
- expect(post :unlock, id: page.id).to redirect_to(admin_pages_path)
508
+ it "should unlock the page" do
509
+ xhr :post, :unlock, id: "#{page.id}"
496
510
  end
497
511
 
498
- context 'if passing :redirect_to through params' do
499
- it "should redirect to the given path" do
500
- expect(post :unlock, id: page.id, redirect_to: 'this/path').to redirect_to('this/path')
512
+ context 'requesting for html format' do
513
+ it "should redirect to admin_pages_path" do
514
+ expect(post :unlock, id: page.id).to redirect_to(admin_pages_path)
515
+ end
516
+
517
+ context 'if passing :redirect_to through params' do
518
+ it "should redirect to the given path" do
519
+ expect(post :unlock, id: page.id, redirect_to: 'this/path').to redirect_to('this/path')
520
+ end
501
521
  end
502
522
  end
503
523
  end
504
- end
505
524
 
506
- describe "#switch_language" do
507
- let(:language) { build_stubbed(:klingonian)}
525
+ describe "#switch_language" do
526
+ let(:language) { build_stubbed(:klingonian)}
508
527
 
509
- before do
510
- allow(Language).to receive(:find_by).and_return(language)
511
- end
528
+ before do
529
+ allow(Language).to receive(:find_by).and_return(language)
530
+ end
512
531
 
513
- it "should store the current language in session" do
514
- get :switch_language, {language_id: language.id}
515
- expect(session[:alchemy_language_id]).to eq(language.id)
516
- end
532
+ it "should store the current language in session" do
533
+ get :switch_language, {language_id: language.id}
534
+ expect(session[:alchemy_language_id]).to eq(language.id)
535
+ end
517
536
 
518
- it "should redirect to sitemap" do
519
- expect(get :switch_language, {language_id: language.id}).to redirect_to(admin_pages_path)
520
- end
537
+ it "should redirect to sitemap" do
538
+ expect(get :switch_language, {language_id: language.id}).to redirect_to(admin_pages_path)
539
+ end
521
540
 
522
- context "coming from layoutpages" do
523
- before {
524
- allow(request).to receive(:referer).and_return('admin/layoutpages')
525
- }
541
+ context "coming from layoutpages" do
542
+ before {
543
+ allow(request).to receive(:referer).and_return('admin/layoutpages')
544
+ }
526
545
 
527
- it "should redirect to layoutpages" do
528
- expect(get :switch_language, {language_id: language.id}).to redirect_to(admin_layoutpages_path)
546
+ it "should redirect to layoutpages" do
547
+ expect(get :switch_language, {language_id: language.id}).to redirect_to(admin_layoutpages_path)
548
+ end
529
549
  end
530
550
  end
531
551
  end
532
-
533
552
  end
534
553
  end