alchemy_cms 3.1.0.rc3 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +6 -2
- data/README.md +11 -17
- data/app/controllers/alchemy/admin/pages_controller.rb +3 -1
- data/db/migrate/20130827094554_alchemy_two_point_six.rb +82 -0
- data/lib/alchemy/auth_accessors.rb +7 -3
- data/lib/alchemy/version.rb +1 -1
- data/spec/controllers/admin/pages_controller_spec.rb +398 -379
- data/spec/dummy/db/migrate/20130827094554_alchemy_two_point_six.rb +82 -0
- data/spec/spec_helper.rb +2 -3
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1dd3580d83b92bb7990cc1a34e3567ebe037a409
|
4
|
+
data.tar.gz: 88b2975b2529f4a9ec05a780705a8d7d3c193286
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8e7aab4bbc54ca64d74829b148921fa122db90f1a7713e4aa554807a74ccd763ac23e97bdc8cad1643c49d4f31448b4d47fc0ff0bb63be9d867534f67935676
|
7
|
+
data.tar.gz: 43a18d1f7f2c31f76fccaa2f7b9afedf32ea6c5f192a65d9ff3aa71fdaeee94ff40e02b0d34e1e6015496c27ca976250ad4108edba0af319f0843e9a0eaedcf1
|
data/Gemfile
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
source '
|
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
|
-
|
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=
|
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
|
-
|
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
|
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: '
|
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: '
|
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/
|
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
|
127
|
-
Alchemy.
|
128
|
-
Alchemy.
|
129
|
-
Alchemy.
|
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.
|
14
|
-
#
|
15
|
-
#
|
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'
|
data/lib/alchemy/version.rb
CHANGED
@@ -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
|
-
|
10
|
-
|
11
|
-
|
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
|
-
|
25
|
-
|
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
|
-
|
33
|
-
|
34
|
-
|
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
|
-
|
40
|
-
let(:
|
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
|
45
|
-
expect(Language).to receive(:current).at_least(:once).and_return(language)
|
46
|
-
end
|
26
|
+
before { sign_in(user) }
|
47
27
|
|
48
|
-
|
49
|
-
|
50
|
-
|
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
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
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
|
-
|
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
|
-
|
63
|
-
|
64
|
-
|
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
|
-
|
70
|
-
|
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
|
-
|
73
|
-
|
74
|
-
|
75
|
-
end
|
63
|
+
before do
|
64
|
+
expect(Language).to receive(:current).at_least(:once).and_return(language)
|
65
|
+
end
|
76
66
|
|
77
|
-
|
78
|
-
|
79
|
-
|
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
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
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
|
-
|
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
|
-
|
94
|
-
|
95
|
-
|
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
|
-
|
100
|
-
|
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(
|
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 "
|
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
|
-
|
122
|
-
expect(page_1.
|
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
|
128
|
-
|
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 "
|
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
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
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
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
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
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
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
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
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
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
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
|
-
|
191
|
-
|
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
|
-
|
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 "
|
222
|
+
it "creates legacy urls" do
|
197
223
|
xhr :post, :order, set: set_of_pages.to_json
|
198
|
-
[
|
199
|
-
expect(
|
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
|
-
|
213
|
-
|
231
|
+
describe "#configure" do
|
232
|
+
render_views
|
214
233
|
|
215
|
-
|
216
|
-
|
234
|
+
context "with page having nested urlname" do
|
235
|
+
let(:page) { create(:page, name: 'Foobar') }
|
217
236
|
|
218
|
-
|
219
|
-
|
220
|
-
|
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
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
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
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
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
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
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
|
-
|
258
|
-
|
259
|
-
|
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
|
-
|
263
|
-
|
264
|
-
|
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 "
|
268
|
-
|
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
|
271
|
-
|
272
|
-
|
273
|
-
|
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
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
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
|
-
|
288
|
-
let(:
|
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(:
|
292
|
-
allow(Page).to receive(:
|
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
|
296
|
-
expect(Page).to receive(:
|
297
|
-
|
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
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
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
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
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
|
-
|
330
|
-
|
331
|
-
|
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
|
-
|
335
|
-
|
336
|
-
|
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
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
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
|
-
|
350
|
-
|
351
|
-
|
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
|
-
|
354
|
-
|
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 '
|
398
|
+
context 'if page is locked by myself' do
|
357
399
|
before do
|
358
|
-
expect_any_instance_of(
|
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 '
|
404
|
+
it 'renders the edit view' do
|
362
405
|
get :edit, id: page.id
|
363
|
-
expect(response).to
|
406
|
+
expect(response).to render_template(:edit)
|
364
407
|
end
|
365
408
|
end
|
366
409
|
|
367
|
-
context '
|
410
|
+
context 'if page is not locked' do
|
368
411
|
before do
|
369
|
-
expect_any_instance_of(
|
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
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
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
|
-
|
392
|
-
|
393
|
-
|
394
|
-
end
|
427
|
+
describe '#destroy' do
|
428
|
+
let(:clipboard) { session[:alchemy_clipboard] = {} }
|
429
|
+
let(:page) { FactoryGirl.create(:public_page) }
|
395
430
|
|
396
|
-
|
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 "
|
402
|
-
|
403
|
-
|
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
|
-
|
409
|
-
|
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
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
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
|
-
|
429
|
-
|
430
|
-
|
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
|
-
|
435
|
-
|
453
|
+
describe '#visit' do
|
454
|
+
let(:page) { mock_model(Alchemy::Page, urlname: 'home') }
|
436
455
|
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
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
|
-
|
444
|
-
|
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
|
-
|
449
|
-
|
450
|
-
|
467
|
+
describe '#fold' do
|
468
|
+
let(:page) { mock_model(Alchemy::Page) }
|
469
|
+
before { allow(Page).to receive(:find).and_return(page) }
|
451
470
|
|
452
|
-
|
453
|
-
|
471
|
+
context "if page is currently not folded" do
|
472
|
+
before { allow(page).to receive(:folded?).and_return(false) }
|
454
473
|
|
455
|
-
|
456
|
-
|
457
|
-
|
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
|
-
|
462
|
-
|
480
|
+
context "if page is already folded" do
|
481
|
+
before { allow(page).to receive(:folded?).and_return(true) }
|
463
482
|
|
464
|
-
|
465
|
-
|
466
|
-
|
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
|
-
|
472
|
-
|
490
|
+
describe '#sort' do
|
491
|
+
before { allow(Page).to receive(:language_root_for).and_return(mock_model(Alchemy::Page)) }
|
473
492
|
|
474
|
-
|
475
|
-
|
476
|
-
|
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
|
-
|
484
|
-
|
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
|
-
|
490
|
-
|
491
|
-
|
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
|
-
|
494
|
-
|
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 '
|
499
|
-
it "should redirect to
|
500
|
-
expect(post :unlock, id: page.id
|
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
|
-
|
507
|
-
|
525
|
+
describe "#switch_language" do
|
526
|
+
let(:language) { build_stubbed(:klingonian)}
|
508
527
|
|
509
|
-
|
510
|
-
|
511
|
-
|
528
|
+
before do
|
529
|
+
allow(Language).to receive(:find_by).and_return(language)
|
530
|
+
end
|
512
531
|
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
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
|
-
|
519
|
-
|
520
|
-
|
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
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
541
|
+
context "coming from layoutpages" do
|
542
|
+
before {
|
543
|
+
allow(request).to receive(:referer).and_return('admin/layoutpages')
|
544
|
+
}
|
526
545
|
|
527
|
-
|
528
|
-
|
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
|