refinerycms-pages 2.1.5 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/refinery/admin/page_parts_controller.rb +6 -1
  3. data/app/controllers/refinery/admin/pages_controller.rb +53 -45
  4. data/app/controllers/refinery/pages/admin/preview_controller.rb +12 -3
  5. data/app/controllers/refinery/pages_controller.rb +12 -12
  6. data/app/helpers/refinery/admin/pages_helper.rb +5 -4
  7. data/app/helpers/refinery/pages/content_pages_helper.rb +6 -1
  8. data/app/models/refinery/page.rb +115 -141
  9. data/app/models/refinery/page_part.rb +32 -7
  10. data/app/presenters/refinery/pages/content_presenter.rb +7 -5
  11. data/app/presenters/refinery/pages/menu_presenter.rb +41 -15
  12. data/app/presenters/refinery/pages/page_part_section_presenter.rb +1 -7
  13. data/app/presenters/refinery/pages/section_presenter.rb +2 -6
  14. data/app/views/refinery/admin/pages/_actions.html.erb +4 -13
  15. data/app/views/refinery/admin/pages/_form.html.erb +7 -10
  16. data/app/views/refinery/admin/pages/_form_advanced_options.html.erb +5 -3
  17. data/app/views/refinery/admin/pages/_form_extra_fields_for_more_options.html.erb +1 -0
  18. data/app/views/refinery/admin/pages/_form_new_page_parts.html.erb +8 -0
  19. data/app/views/refinery/admin/pages/_form_page_parts.html.erb +10 -21
  20. data/app/views/refinery/admin/pages/_page.html.erb +31 -31
  21. data/app/views/refinery/admin/pages/_page_part_field.html.erb +2 -1
  22. data/app/views/refinery/admin/pages/_records.html.erb +3 -3
  23. data/app/views/refinery/admin/pages/_save_and_continue_callback.html.erb +1 -0
  24. data/app/views/refinery/admin/pages/index.html.erb +2 -4
  25. data/app/views/refinery/admin/pages_dialogs/link_to.html.erb +1 -1
  26. data/config/locales/bg.yml +1 -2
  27. data/config/locales/ca.yml +85 -0
  28. data/config/locales/cs.yml +13 -3
  29. data/config/locales/da.yml +1 -2
  30. data/config/locales/de.yml +0 -1
  31. data/config/locales/el.yml +41 -29
  32. data/config/locales/en.yml +2 -2
  33. data/config/locales/es.yml +2 -4
  34. data/config/locales/fi.yml +1 -4
  35. data/config/locales/fr.yml +2 -2
  36. data/config/locales/hu.yml +1 -2
  37. data/config/locales/it.yml +15 -16
  38. data/config/locales/ja.yml +1 -3
  39. data/config/locales/ko.yml +1 -4
  40. data/config/locales/lt.yml +1 -3
  41. data/config/locales/lv.yml +0 -2
  42. data/config/locales/nb.yml +1 -4
  43. data/config/locales/nl.yml +1 -2
  44. data/config/locales/pl.yml +1 -13
  45. data/config/locales/pt-BR.yml +1 -3
  46. data/config/locales/pt.yml +1 -2
  47. data/config/locales/rs.yml +1 -3
  48. data/config/locales/ru.yml +8 -5
  49. data/config/locales/sk.yml +1 -2
  50. data/config/locales/sl.yml +1 -3
  51. data/config/locales/sv.yml +1 -3
  52. data/config/locales/tr.yml +1 -2
  53. data/config/locales/uk.yml +1 -5
  54. data/config/locales/vi.yml +1 -3
  55. data/config/locales/zh-CN.yml +1 -4
  56. data/config/locales/zh-TW.yml +1 -3
  57. data/config/routes.rb +16 -16
  58. data/db/migrate/20100913234708_create_refinerycms_pages_schema.rb +28 -11
  59. data/db/migrate/20140105190324_add_custom_slug_to_refinery_pages.rb +20 -0
  60. data/db/migrate/20150130044643_add_slug_to_refinery_page_parts.rb +6 -0
  61. data/db/migrate/20150720155305_update_slug_and_title_in_refinery_page_parts.rb +13 -0
  62. data/db/seeds.rb +42 -36
  63. data/lib/generators/refinery/pages/templates/config/initializers/refinery/pages.rb.erb +12 -0
  64. data/lib/refinery/pages.rb +4 -3
  65. data/lib/refinery/pages/admin/instance_methods.rb +3 -3
  66. data/lib/refinery/pages/configuration.rb +7 -1
  67. data/lib/refinery/pages/engine.rb +19 -18
  68. data/lib/refinery/pages/finder.rb +179 -0
  69. data/lib/refinery/pages/instance_methods.rb +3 -14
  70. data/lib/refinery/pages/tab.rb +2 -2
  71. data/lib/refinery/pages/types.rb +1 -1
  72. data/lib/refinery/pages/url.rb +15 -3
  73. data/license.md +1 -1
  74. data/refinerycms-pages.gemspec +8 -5
  75. data/spec/controllers/refinery/admin/pages_controller_spec.rb +53 -0
  76. data/spec/controllers/refinery/pages_controller_spec.rb +1 -1
  77. data/spec/factories/pages.rb +1 -1
  78. data/spec/features/refinery/admin/pages_spec.rb +274 -290
  79. data/spec/features/refinery/pages_spec.rb +123 -138
  80. data/spec/helpers/refinery/pages/admin/pages_helper_spec.rb +15 -11
  81. data/spec/helpers/refinery/pages/content_pages_helper_spec.rb +11 -11
  82. data/spec/lib/generators/refinery/pages/pages_generator_spec.rb +1 -1
  83. data/spec/lib/pages_spec.rb +2 -2
  84. data/spec/lib/refinery/pages/tab_spec.rb +9 -9
  85. data/spec/lib/refinery/pages/url_spec.rb +12 -12
  86. data/spec/models/refinery/page_finder_spec.rb +72 -0
  87. data/spec/models/refinery/page_menu_spec.rb +107 -0
  88. data/spec/models/refinery/page_meta_data_spec.rb +49 -0
  89. data/spec/models/refinery/page_part_spec.rb +67 -0
  90. data/spec/models/refinery/page_spec.rb +16 -534
  91. data/spec/models/refinery/page_url_spec.rb +320 -0
  92. data/spec/presenters/refinery/pages/content_page_presenter_spec.rb +9 -9
  93. data/spec/presenters/refinery/pages/content_presenter_spec.rb +20 -20
  94. data/spec/presenters/refinery/pages/menu_presenter_spec.rb +44 -6
  95. data/spec/presenters/refinery/pages/page_part_section_presenter_spec.rb +12 -12
  96. data/spec/presenters/refinery/pages/section_presenter_spec.rb +22 -22
  97. data/spec/presenters/refinery/pages/title_section_presenter_spec.rb +4 -4
  98. data/spec/support/refinery/pages/caching_helpers.rb +2 -2
  99. metadata +55 -25
  100. data/app/helpers/refinery/admin/page_parts_helper.rb +0 -6
  101. data/app/helpers/refinery/admin/pages_dialogs_helper.rb +0 -6
  102. data/app/sweepers/refinery/pages/page_sweeper.rb +0 -29
  103. data/lib/refinery/pages/caching.rb +0 -60
  104. data/spec/lib/refinery/pages/caching_spec.rb +0 -90
  105. data/spec/support/refinery/pages/caching.rb +0 -19
@@ -0,0 +1,179 @@
1
+ module Refinery
2
+ module Pages
3
+ class Finder
4
+ def self.by_path(path)
5
+ FinderByPath.new(path).find
6
+ end
7
+
8
+ def self.by_path_or_id(path, id)
9
+ FinderByPathOrId.new(path, id).find
10
+ end
11
+
12
+ def self.by_title(title)
13
+ FinderByTitle.new(title).find
14
+ end
15
+
16
+ def self.by_slug(slug, conditions = {})
17
+ FinderBySlug.new(slug, conditions).find
18
+ end
19
+
20
+ def self.with_globalize(conditions = {})
21
+ Finder.new(conditions).find
22
+ end
23
+
24
+ def initialize(conditions)
25
+ @conditions = conditions
26
+ end
27
+
28
+ def find
29
+ with_globalize
30
+ end
31
+
32
+ def with_globalize
33
+ globalized_conditions = {:locale => ::Globalize.locale.to_s}.merge(conditions)
34
+ translations_conditions = translations_conditions(globalized_conditions)
35
+
36
+ # A join implies readonly which we don't really want.
37
+ Page.where(globalized_conditions).
38
+ joins(:translations).
39
+ where(translations_conditions).
40
+ readonly(false)
41
+ end
42
+
43
+ private
44
+ attr_accessor :conditions
45
+
46
+ def translated_attributes
47
+ Page.translated_attribute_names.map(&:to_s) | %w(locale)
48
+ end
49
+
50
+ def translations_conditions(original_conditions)
51
+ translations_conditions = {}
52
+ original_conditions.keys.each do |key|
53
+ if translated_attributes.include? key.to_s
54
+ translations_conditions["#{Page.translation_class.table_name}.#{key}"] = original_conditions.delete(key)
55
+ end
56
+ end
57
+ translations_conditions
58
+ end
59
+
60
+ end
61
+
62
+ class FinderByTitle < Finder
63
+ def initialize(title)
64
+ @title = title
65
+ @conditions = default_conditions
66
+ end
67
+
68
+ def default_conditions
69
+ { :title => title }
70
+ end
71
+
72
+ private
73
+ attr_accessor :title
74
+ end
75
+
76
+ class FinderBySlug < Finder
77
+ def initialize(slug, conditions)
78
+ @slug = slug
79
+ @conditions = default_conditions.merge(conditions)
80
+ end
81
+
82
+ def default_conditions
83
+ {
84
+ :locale => Refinery::I18n.frontend_locales.map(&:to_s),
85
+ :slug => slug
86
+ }
87
+ end
88
+
89
+ private
90
+ attr_accessor :slug
91
+ end
92
+
93
+ class FinderByPath
94
+ def initialize(path)
95
+ @path = path
96
+ end
97
+
98
+ def find
99
+ if slugs_scoped_by_parent?
100
+ FinderByScopedPath.new(path).find
101
+ else
102
+ FinderByUnscopedPath.new(path).find
103
+ end
104
+ end
105
+
106
+ private
107
+ attr_accessor :path
108
+
109
+ def slugs_scoped_by_parent?
110
+ ::Refinery::Pages.scope_slug_by_parent
111
+ end
112
+
113
+ def by_slug(slug_path, conditions = {})
114
+ Finder.by_slug(slug_path, conditions)
115
+ end
116
+ end
117
+
118
+ class FinderByScopedPath < FinderByPath
119
+ def find
120
+ # With slugs scoped to the parent page we need to find a page by its full path.
121
+ # For example with about/example we would need to find 'about' and then its child
122
+ # called 'example' otherwise it may clash with another page called /example.
123
+ page = parent_page
124
+ while page && path_segments.any? do
125
+ page = next_page(page)
126
+ end
127
+ page
128
+ end
129
+
130
+ private
131
+
132
+ def path_segments
133
+ @path_segments ||= path.split('/').select(&:present?)
134
+ end
135
+
136
+ def parent_page
137
+ parent_page_segment = path_segments.shift
138
+ if parent_page_segment.friendly_id?
139
+ by_slug(parent_page_segment, :parent_id => nil).first
140
+ else
141
+ Page.find(parent_page_segment)
142
+ end
143
+ end
144
+
145
+ def next_page(page)
146
+ slug_or_id = path_segments.shift
147
+ page.children.by_slug(slug_or_id).first || page.children.find(slug_or_id)
148
+ end
149
+ end
150
+
151
+ class FinderByUnscopedPath < FinderByPath
152
+ def find
153
+ by_slug(path).first
154
+ end
155
+ end
156
+
157
+ class FinderByPathOrId
158
+ def initialize(path, id)
159
+ @path = path
160
+ @id = id
161
+ end
162
+
163
+ def find
164
+ if path.present?
165
+ if path.friendly_id?
166
+ FinderByPath.new(path).find
167
+ else
168
+ Page.friendly.find(path)
169
+ end
170
+ elsif id.present?
171
+ Page.friendly.find(id)
172
+ end
173
+ end
174
+
175
+ private
176
+ attr_accessor :id, :path
177
+ end
178
+ end
179
+ end
@@ -2,12 +2,7 @@ module Refinery
2
2
  module Pages
3
3
  module InstanceMethods
4
4
 
5
- def self.included(base)
6
- base.send :helper_method, :refinery_menu_pages
7
- base.send :alias_method_chain, :render, :presenters
8
- end
9
-
10
- def error_404(exception=nil)
5
+ def error_404(exception = nil)
11
6
  if (@page = ::Refinery::Page.where(:menu_match => "^/404$").includes(:parts).first).present?
12
7
  # render the application's custom 404 page with layout and meta.
13
8
  if self.respond_to? :render_with_templates?, true
@@ -21,15 +16,9 @@ module Refinery
21
16
  end
22
17
  end
23
18
 
24
- # Compiles the default menu.
25
- def refinery_menu_pages
26
- Menu.new Page.fast_menu
27
- end
28
-
29
- protected
30
- def render_with_presenters(*args)
19
+ def render(*args)
31
20
  present @page unless admin? || @meta
32
- render_without_presenters(*args)
21
+ super
33
22
  end
34
23
 
35
24
  end
@@ -21,8 +21,8 @@ module Refinery
21
21
 
22
22
  yield tab
23
23
 
24
- raise "A tab MUST have a name!: #{tab.inspect}" if tab.name.blank?
25
- raise "A tab MUST have a partial!: #{tab.inspect}" if tab.partial.blank?
24
+ raise ArgumentError, "A tab MUST have a name!: #{tab.inspect}" if tab.name.blank?
25
+ raise ArgumentError, "A tab MUST have a partial!: #{tab.inspect}" if tab.partial.blank?
26
26
 
27
27
  tab.templates = %w[all] if tab.templates.blank?
28
28
  tab.templates = Array(tab.templates)
@@ -7,7 +7,7 @@ module Refinery
7
7
  end
8
8
 
9
9
  def find_by_name(name)
10
- detect {|type| type.name.to_s.downcase == name.to_s.downcase}
10
+ detect { |type| type.name.to_s.downcase == name.to_s.downcase}
11
11
  end
12
12
 
13
13
  class << self
@@ -9,13 +9,25 @@ module Refinery
9
9
 
10
10
  def url
11
11
  current_url = page.link_url
12
-
13
- if current_url =~ %r{^/} &&
12
+ # Don't mess around with absolute URLs, just accept them. Examples:
13
+ #
14
+ # * https://github.com/parndt
15
+ # * http://github.com/parndt
16
+ # * //github.com/parndt
17
+ return current_url if current_url =~ %r{\A(https?:)?//}
18
+
19
+ if Refinery::I18n.url_filter_enabled? && current_url =~ %r{^/} &&
14
20
  Refinery::I18n.current_frontend_locale != Refinery::I18n.default_frontend_locale
15
21
  current_url = "/#{Refinery::I18n.current_frontend_locale}#{current_url}"
16
22
  end
17
23
 
18
- current_url
24
+ # See https://github.com/refinery/refinerycms/issues/2740
25
+ if current_url == '/'
26
+ Refinery::Core.mounted_path
27
+ else
28
+ [Refinery::Core.mounted_path, current_url.sub(%r{\A/}, '')].
29
+ join("/").sub("//", "/").sub(%r{/\z}, '')
30
+ end
19
31
  end
20
32
  end
21
33
 
data/license.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # MIT License
2
2
 
3
- Copyright (c) 2005-2013 [Resolve Digital](http://www.resolvedigital.com)
3
+ Copyright (c) 2005-2015 [Resolve Digital](http://resolve.digital)
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
9
9
  s.version = version
10
10
  s.summary = %q{Pages extension for Refinery CMS}
11
11
  s.description = %q{The default content extension of Refinery CMS. This extension handles the administration and display of user-editable pages.}
12
- s.email = %q{info@refinerycms.com}
12
+ s.email = %q{refinerycms@p.arndt.io}
13
13
  s.homepage = %q{http://refinerycms.com}
14
14
  s.rubyforge_project = %q{refinerycms}
15
15
  s.authors = ['Philip Arndt', 'Uģis Ozols', 'Rob Yurkowski']
@@ -19,10 +19,13 @@ Gem::Specification.new do |s|
19
19
  s.files = `git ls-files`.split("\n")
20
20
  s.test_files = `git ls-files -- spec/*`.split("\n")
21
21
 
22
- s.add_dependency 'friendly_id', '~> 4.0.9'
23
- s.add_dependency 'globalize', '~> 3.1.0'
24
- s.add_dependency 'awesome_nested_set', '~> 2.1.3'
25
- s.add_dependency 'seo_meta', '~> 1.4.0'
22
+ s.add_dependency 'friendly_id', '~> 5.1.0'
23
+ s.add_dependency 'globalize', ['>= 4.0.0', '< 5.2']
24
+ s.add_dependency 'awesome_nested_set', '~> 3.0.0'
25
+ s.add_dependency 'seo_meta', '~> 2.0.0.rc.1'
26
26
  s.add_dependency 'refinerycms-core', version
27
27
  s.add_dependency 'babosa', '!= 0.3.6'
28
+ s.add_dependency 'speakingurl-rails', '~> 1.1.2'
29
+
30
+ s.required_ruby_version = Refinery::Version.required_ruby_version
28
31
  end
@@ -0,0 +1,53 @@
1
+ require "spec_helper"
2
+
3
+ module Refinery
4
+ module Admin
5
+ describe PagesController, type: :controller do
6
+
7
+ describe "valid templates" do
8
+ before do
9
+ File.write(Rails.root.join('tmp', 'abc.html.erb'), '')
10
+ File.write(Rails.root.join('tmp', 'def.rb'), '')
11
+ File.write(Rails.root.join('tmp', 'xyz.html.erb'), '')
12
+ File.write(Rails.root.join('tmp', 'odd.file.name'), '')
13
+
14
+ allow(Refinery::Pages).to receive(:use_layout_templates).and_return(true)
15
+ allow(Refinery::Pages).to receive(:layout_template_whitelist).and_return(['abc', 'def'])
16
+ allow(Refinery::Pages).to receive(:layout_templates_pattern).and_return(['tmp', '*html*'])
17
+ allow(Refinery::Pages).to receive(:view_templates_pattern).and_return(['tmp', '*.{rb,erb}'])
18
+ end
19
+
20
+ after do
21
+ File.delete(Rails.root.join('tmp', 'abc.html.erb'))
22
+ File.delete(Rails.root.join('tmp', 'def.rb'))
23
+ File.delete(Rails.root.join('tmp', 'xyz.html.erb'))
24
+ File.delete(Rails.root.join('tmp', 'odd.file.name'))
25
+ end
26
+
27
+ describe 'layout templates' do
28
+ it 'returns the names of all files which fit the pattern and are in the whitelist' do
29
+ expect(subject.send(:valid_layout_templates)).to include('abc')
30
+ end
31
+
32
+ it 'does not return files whose names are not in the whitelist' do
33
+ expect(subject.send(:valid_layout_templates)).not_to include('xyz')
34
+ end
35
+
36
+ it 'does not return files that do not fit the pattern' do
37
+ expect(subject.send(:valid_layout_templates)).not_to include('def')
38
+ end
39
+ end
40
+
41
+ describe "valid view templates" do
42
+ it 'returns the names of all files which fit the pattern' do
43
+ expect(subject.send(:valid_view_templates)).to include('xyz','def', 'abc')
44
+ end
45
+
46
+ it "does not return names which don't fit the pattern" do
47
+ expect(subject.send(:valid_view_templates)).not_to include('odd')
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -1,7 +1,7 @@
1
1
  require "spec_helper"
2
2
 
3
3
  module Refinery
4
- describe PagesController do
4
+ describe PagesController, :type => :controller do
5
5
  before do
6
6
  FactoryGirl.create(:page, :link_url => "/")
7
7
  FactoryGirl.create(:page, :title => "test")
@@ -1,5 +1,5 @@
1
1
  FactoryGirl.define do
2
2
  factory :page, :class => Refinery::Page do
3
- sequence(:title, "a") {|n| "Test title #{n}" }
3
+ sequence(:title, "a") { |n| "Test title #{n}" }
4
4
  end
5
5
  end
@@ -1,29 +1,27 @@
1
1
  # encoding: utf-8
2
2
  require "spec_helper"
3
3
 
4
- def new_window_should_have_content(content)
5
- new_window = page.driver.browser.window_handles.last
6
- page.within_window new_window do
7
- page.should have_content(content)
4
+ def expect_window_with_content(content, window: windows.last)
5
+ page.within_window window do
6
+ expect(page).to have_content(content)
8
7
  end
9
8
  end
10
9
 
11
- def new_window_should_not_have_content(content)
12
- new_window = page.driver.browser.window_handles.last
13
- page.within_window new_window do
14
- page.should_not have_content(content)
10
+ def expect_window_without_content(content, window: windows.last)
11
+ page.within_window window do
12
+ expect(page).not_to have_content(content)
15
13
  end
16
14
  end
17
15
 
18
16
  module Refinery
19
17
  module Admin
20
- describe "Pages" do
21
- refinery_login_with :refinery_user
18
+ describe "Pages", :type => :feature do
19
+ refinery_login
22
20
 
23
21
  context "when no pages" do
24
22
  it "invites to create one" do
25
23
  visit refinery.admin_pages_path
26
- page.should have_content(%q{There are no pages yet. Click "Add new page" to add your first page.})
24
+ expect(page).to have_content(%q{There are no pages yet. Click "Add new page" to add your first page.})
27
25
  end
28
26
  end
29
27
 
@@ -32,8 +30,8 @@ module Refinery
32
30
  visit refinery.admin_pages_path
33
31
 
34
32
  within "#actions" do
35
- page.should have_content("Add new page")
36
- page.should have_selector("a[href='/refinery/pages/new']")
33
+ expect(page).to have_content("Add new page")
34
+ expect(page).to have_selector("a[href='/#{Refinery::Core.backend_route}/pages/new']")
37
35
  end
38
36
  end
39
37
 
@@ -42,21 +40,38 @@ module Refinery
42
40
  visit refinery.admin_pages_path
43
41
 
44
42
  within "#actions" do
45
- page.should have_no_content("Reorder pages")
46
- page.should have_no_selector("a[href='/refinery/pages']")
43
+ expect(page).to have_no_content("Reorder pages")
44
+ expect(page).to have_no_selector("a[href='/#{Refinery::Core.backend_route}/pages']")
47
45
  end
48
46
  end
49
47
  end
50
48
 
51
49
  context "when some pages exist" do
52
- before { 2.times { |i| Page.create :title => "Page #{i}" } }
50
+ let!(:page_0) { Page.create! title: 'Page 0' }
51
+ let!(:page_1) { Page.create! title: 'Page 1' }
53
52
 
54
53
  it "shows reorder pages link" do
55
54
  visit refinery.admin_pages_path
56
55
 
57
56
  within "#actions" do
58
- page.should have_content("Reorder pages")
59
- page.should have_selector("a[href='/refinery/pages']")
57
+ expect(page).to have_content("Reorder pages")
58
+ expect(page).to have_selector("a[href='/#{Refinery::Core.backend_route}/pages']")
59
+ end
60
+ end
61
+
62
+ context "when reordering pages" do
63
+ let(:reorder_url) { "/#{Refinery::Core.backend_route}/pages/update_positions" }
64
+ before do
65
+ visit refinery.admin_pages_path
66
+ page.driver.post(reorder_url, {
67
+ 'ul[0][0][id]' => "page_#{page_1.id}",
68
+ 'ul[0][1][id]' => "page_#{page_0.id}",
69
+ })
70
+ end
71
+
72
+ it "shows pages in the new order" do
73
+ visit refinery.admin_pages_path
74
+ expect(page.body).to match(/Page 1.*Page 0/m)
60
75
  end
61
76
  end
62
77
  end
@@ -69,71 +84,69 @@ module Refinery
69
84
 
70
85
  context "with auto expand option turned off" do
71
86
  before do
72
- Refinery::Pages.stub(:auto_expand_admin_tree).and_return(false)
87
+ allow(Refinery::Pages).to receive(:auto_expand_admin_tree).and_return(false)
73
88
 
74
89
  visit refinery.admin_pages_path
75
90
  end
76
91
 
77
92
  it "show parent page" do
78
93
 
79
- page.should have_content(company.title)
94
+ expect(page).to have_content(company.title)
80
95
  end
81
96
 
82
97
  it "doesn't show children" do
83
- page.should_not have_content(team.title)
84
- page.should_not have_content(locations.title)
98
+ expect(page).not_to have_content(team.title)
99
+ expect(page).not_to have_content(locations.title)
85
100
  end
86
101
 
87
102
  it "expands children", :js do
88
103
  find("#page_#{company.id} .title.toggle").click
89
104
 
90
- page.should have_content(team.title)
91
- page.should have_content(locations.title)
105
+ expect(page).to have_content(team.title)
106
+ expect(page).to have_content(locations.title)
92
107
  end
93
108
 
94
- it "expands children when nested mutliple levels deep", :js do
109
+ it "expands children when nested multiple levels deep", :js do
95
110
  find("#page_#{company.id} .title.toggle").click
96
111
  find("#page_#{locations.id} .title.toggle").click
97
112
 
98
- page.should have_content("New York")
113
+ expect(page).to have_content("New York")
99
114
  end
100
115
  end
101
116
 
102
117
  context "with auto expand option turned on" do
103
118
  before do
104
- Refinery::Pages.stub(:auto_expand_admin_tree).and_return(true)
119
+ allow(Refinery::Pages).to receive(:auto_expand_admin_tree).and_return(true)
105
120
 
106
121
  visit refinery.admin_pages_path
107
122
  end
108
123
 
109
124
  it "shows children" do
110
- page.should have_content(team.title)
111
- page.should have_content(locations.title)
125
+ expect(page).to have_content(team.title)
126
+ expect(page).to have_content(locations.title)
112
127
  end
113
128
  end
114
129
  end
115
130
  end
116
131
 
117
132
  describe "new/create" do
118
- it "allows to create page" do
133
+ it "Creates a page", js:true do
119
134
  visit refinery.admin_pages_path
120
135
 
121
- click_link "Add new page"
136
+ find('a', text: 'Add new page').trigger(:click)
122
137
 
123
138
  fill_in "Title", :with => "My first page"
124
- click_button "Save"
125
-
126
- page.should have_content("'My first page' was successfully added.")
139
+ expect { click_button "Save" }.to change(Refinery::Page, :count).from(0).to(1)
127
140
 
128
- page.body.should =~ /Remove this page forever/
129
- page.body.should =~ /Edit this page/
130
- page.body.should =~ %r{/refinery/pages/my-first-page/edit}
131
- page.body.should =~ /Add a new child page/
132
- page.body.should =~ %r{/refinery/pages/new\?parent_id=}
133
- page.body.should =~ /View this page live/
134
- page.body.should =~ %r{href="/my-first-page"}
141
+ expect(page).to have_content("'My first page' was successfully added.")
135
142
 
136
- Refinery::Page.count.should == 1
143
+ expect(page.body).to match(/Remove this page forever/)
144
+ expect(page.body).to match(/Edit this page/)
145
+ expect(page.body).to match(%r{/#{Refinery::Core.backend_route}/pages/my-first-page/edit})
146
+ expect(page.body).to match(/Add a new child page/)
147
+ expect(page.body).to match(%r{/#{Refinery::Core.backend_route}/pages/new\?parent_id=})
148
+ expect(page.body).to match(/View this page live/)
149
+ expect(page.body).to match(%r{href="/my-first-page"})
137
150
  end
138
151
 
139
152
  it "includes menu title field", :js => true do
@@ -141,24 +154,32 @@ module Refinery
141
154
 
142
155
  fill_in "Title", :with => "My first page"
143
156
 
144
- click_link "toggle_advanced_options"
157
+ find('#toggle_advanced_options').trigger(:click)
145
158
 
146
159
  fill_in "Menu title", :with => "The first page"
147
160
 
148
- click_button "Save"
161
+ # For some reason the first click doesn't always work?
162
+ begin
163
+ click_button "Save"
164
+ sleep 0.1
165
+ redo unless Refinery::Page.any?
166
+ end
149
167
 
150
- page.should have_content("'My first page' was successfully added.")
151
- page.body.should =~ %r{/pages/the-first-page}
168
+ expect(page).to have_content("'My first page' was successfully added.")
169
+ expect(page.body).to match(%r{/pages/the-first-page})
152
170
  end
153
171
 
154
- it "shows error if title is blank" do
172
+ it "allows to easily create nested page" do
173
+ parent_page = Page.create! :title => "Rails 4"
174
+
155
175
  visit refinery.admin_pages_path
156
176
 
157
- click_link "Add new page"
177
+ find("a[href='#{refinery.new_admin_page_path(:parent_id => parent_page.id)}']").click
158
178
 
179
+ fill_in "Title", :with => "Parent page"
159
180
  click_button "Save"
160
181
 
161
- page.should have_content("Title can't be blank")
182
+ expect(page).to have_content("'Parent page' was successfully added.")
162
183
  end
163
184
  end
164
185
 
@@ -167,17 +188,17 @@ module Refinery
167
188
  Page.create :title => "Update me"
168
189
 
169
190
  visit refinery.admin_pages_path
170
- page.should have_content("Update me")
191
+ expect(page).to have_content("Update me")
171
192
  end
172
193
 
173
194
  context 'when saving and returning to index' do
174
- it "updates page" do
175
- click_link "Edit this page"
195
+ it "updates page", js:true do
196
+ find('a[tooltip="Edit this page"]').trigger(:click)
176
197
 
177
198
  fill_in "Title", :with => "Updated"
178
199
  find("#submit_button").click
179
200
 
180
- page.should have_content("'Updated' was successfully updated.")
201
+ expect(page).to have_content("'Updated' was successfully updated.")
181
202
  end
182
203
  end
183
204
 
@@ -192,101 +213,129 @@ module Refinery
192
213
  end
193
214
 
194
215
  it "updates page", :js do
195
- page.should have_content("'Updated' was successfully updated.")
216
+ expect(page).to have_content("'Updated' was successfully updated.")
196
217
  end
197
218
 
198
219
  # Regression test for https://github.com/refinery/refinerycms/issues/1892
199
220
  context 'when saving to exit (a second time)' do
200
221
  it 'updates page', :js do
201
222
  find("#submit_button").click
202
- page.should have_content("'Updated' was successfully updated.")
223
+ expect(page).to have_content("'Updated' was successfully updated.")
203
224
  end
204
225
  end
205
226
  end
206
227
  end
207
228
 
208
- describe 'Previewing' do
229
+ describe 'Previewing', :js do
230
+ let(:preview_content) { "Some changes I'm unsure what they will look like".freeze }
209
231
  context "an existing page" do
210
232
  before { Page.create :title => 'Preview me' }
211
233
 
212
- it 'will show the preview changes in a new window', :js do
234
+ it 'will show the preview changes in a new window' do
213
235
  visit refinery.admin_pages_path
214
236
 
215
237
  find('a[tooltip^=Edit]').click
216
- fill_in "Title", :with => "Some changes I'm unsure what they will look like"
217
- click_button "Preview"
238
+ fill_in "Title", with: preview_content
239
+ window = window_opened_by do
240
+ click_button "Preview"
241
+ end
218
242
 
219
- new_window_should_have_content("Some changes I'm unsure what they will look like")
243
+ expect_window_with_content(preview_content, window: window)
244
+
245
+ window.close
220
246
  end
221
247
 
222
- it 'will not show the site bar', :js do
248
+ it 'will not show the site bar' do
223
249
  visit refinery.admin_pages_path
224
250
 
225
251
  find('a[tooltip^=Edit]').click
226
- fill_in "Title", :with => "Some changes I'm unsure what they will look like"
227
- click_button "Preview"
252
+ fill_in "Title", with: preview_content
253
+ window = window_opened_by do
254
+ click_button "Preview"
255
+ end
228
256
 
229
- new_window_should_not_have_content(
230
- ::I18n.t('switch_to_website', :scope => 'refinery.site_bar')
231
- )
232
- new_window_should_not_have_content(
233
- ::I18n.t('switch_to_website_editor', :scope => 'refinery.site_bar')
234
- )
257
+ expect_window_without_content(
258
+ ::I18n.t('switch_to_website', scope: 'refinery.site_bar'),
259
+ window: window
260
+ )
261
+ expect_window_without_content(
262
+ ::I18n.t('switch_to_website_editor', scope: 'refinery.site_bar'),
263
+ window: window
264
+ )
265
+
266
+ window.close
235
267
  end
236
268
 
237
- it 'will not save the preview changes', :js do
269
+ it 'will not save the preview changes' do
238
270
  visit refinery.admin_pages_path
239
271
 
240
272
  find('a[tooltip^=Edit]').click
241
- fill_in "Title", :with => "Some changes I'm unsure what they will look like"
242
- click_button "Preview"
273
+ fill_in "Title", with: preview_content
274
+ window = window_opened_by do
275
+ click_button "Preview"
276
+ end
277
+
278
+ expect_window_with_content(
279
+ preview_content,
280
+ window: window
281
+ )
243
282
 
244
- new_window_should_have_content("Some changes I'm unsure what they will look like")
283
+ window.close
245
284
 
246
- Page.by_title("Some changes I'm unsure what they will look like").should be_empty
285
+ expect(Page.by_title(preview_content)).to be_empty
247
286
  end
248
287
 
249
288
  # Regression test for previewing after save-and_continue
250
- it 'will show the preview in a new window after save-and-continue', :js do
289
+ it 'will show the preview in a new window after save-and-continue' do
251
290
  visit refinery.admin_pages_path
252
291
 
253
292
  find('a[tooltip^=Edit]').click
254
293
  fill_in "Title", :with => "Save this"
255
294
  click_button "Save & continue editing"
256
- page.should have_content("'Save this' was successfully updated")
295
+ expect(page).to have_content("'Save this' was successfully updated")
257
296
 
258
- click_button "Preview"
297
+ window = window_opened_by do
298
+ click_button "Preview"
299
+ end
259
300
 
260
- new_window_should_have_content("Save this")
261
- new_window_should_not_have_content(
262
- ::I18n.t('switch_to_website', :scope => 'refinery.site_bar')
263
- )
301
+ expect_window_with_content("Save this", window: window)
302
+ expect_window_without_content(
303
+ ::I18n.t('switch_to_website', :scope => 'refinery.site_bar'),
304
+ window: window
305
+ )
306
+
307
+ window.close
264
308
  end
265
309
 
266
- it 'will show pages with inherited templates', :js do
310
+ it 'will show pages with inherited templates', js:true do
267
311
  visit refinery.admin_pages_path
268
312
 
269
313
  find('a[tooltip^=Edit]').click
270
314
  fill_in 'Title', :with => 'Searchable'
271
- click_link 'Advanced options'
315
+ find('#toggle_advanced_options').trigger(:click)
272
316
  select 'Searchable', :from => 'View template'
273
- click_button 'Preview'
274
-
275
- new_window_should_have_content('Form application/search_form')
317
+ Timeout::timeout(5) do
318
+ click_button 'Preview'
319
+ sleep 0.1 and redo unless windows.many?
320
+ expect_window_with_content('Form application/search_form')
321
+ end
276
322
  end
277
323
  end
278
324
 
279
325
  context 'a brand new page' do
280
- it "will not save when just previewing", :js do
326
+ it "will not save when just previewing", js:true do
281
327
  visit refinery.admin_pages_path
282
328
 
283
- click_link "Add new page"
329
+ find('a', text: 'Add new page').trigger(:click)
284
330
  fill_in "Title", :with => "My first page"
285
- click_button "Preview"
331
+ window = window_opened_by do
332
+ click_button "Preview"
333
+ end
286
334
 
287
- new_window_should_have_content("My first page")
335
+ expect_window_with_content("My first page", window: window)
288
336
 
289
- Page.count.should == 0
337
+ expect(Page.count).to eq(0)
338
+ window.close
290
339
  end
291
340
  end
292
341
 
@@ -294,33 +343,35 @@ module Refinery
294
343
  let!(:parent_page) { Page.create :title => "Our Parent Page" }
295
344
  let!(:nested_page) { parent_page.children.create :title => 'Preview Me' }
296
345
 
297
- it "works like an un-nested page", :js do
346
+ it "works like an un-nested page" do
298
347
  visit refinery.admin_pages_path
299
348
 
300
349
  within "#page_#{nested_page.id}" do
301
350
  find('a[tooltip^=Edit]').click
302
351
  end
303
352
 
304
- fill_in "Title", :with => "Some changes I'm unsure what they will look like"
305
- click_button "Preview"
353
+ fill_in "Title", with: preview_content
354
+ window = window_opened_by do
355
+ click_button "Preview"
356
+ end
306
357
 
307
- new_window_should_have_content("Some changes I'm unsure what they will look like")
358
+ expect_window_with_content(preview_content)
308
359
  end
309
360
  end
310
361
  end
311
362
 
312
363
  describe "destroy" do
313
- context "when page can be deleted" do
364
+ context "when page can be deleted", js:true do
314
365
  before { Page.create :title => "Delete me" }
315
366
 
316
367
  it "will show delete button" do
317
368
  visit refinery.admin_pages_path
318
369
 
319
- click_link "Remove this page forever"
370
+ find('a[tooltip="Remove this page forever"]').trigger(:click)
320
371
 
321
- page.should have_content("'Delete me' was successfully removed.")
372
+ expect(page).to have_content("'Delete me' was successfully removed.")
322
373
 
323
- Refinery::Page.count.should == 0
374
+ expect(Refinery::Page.count).to eq(0)
324
375
  end
325
376
  end
326
377
 
@@ -330,8 +381,8 @@ module Refinery
330
381
  it "wont show delete button" do
331
382
  visit refinery.admin_pages_path
332
383
 
333
- page.should have_no_content("Remove this page forever")
334
- page.should have_no_selector("a[href='/refinery/pages/indestructible']")
384
+ expect(page).to have_no_content("Remove this page forever")
385
+ expect(page).to have_no_selector("a[href='/#{Refinery::Core.backend_route}/pages/indestructible']")
335
386
  end
336
387
  end
337
388
  end
@@ -345,19 +396,19 @@ module Refinery
345
396
  fill_in "Title", :with => "I was here first"
346
397
  click_button "Save"
347
398
 
348
- Refinery::Page.last.url[:path].should == ["i-was-here-first--2"]
399
+ expect(Refinery::Page.last.url[:path].first).to match(%r{\Ai-was-here-first-.+?})
349
400
  end
350
401
  end
351
402
 
352
403
  context "with translations" do
353
404
  before do
354
- Refinery::I18n.stub(:frontend_locales).and_return([:en, :ru])
405
+ allow(Refinery::I18n).to receive(:frontend_locales).and_return([:en, :ru])
355
406
 
356
407
  # Create a home page in both locales (needed to test menus)
357
408
  home_page = Globalize.with_locale(:en) do
358
409
  Page.create :title => 'Home',
359
- :link_url => '/',
360
- :menu_match => "^/$"
410
+ :link_url => '/',
411
+ :menu_match => "^/$"
361
412
  end
362
413
 
363
414
  Globalize.with_locale(:ru) do
@@ -366,40 +417,42 @@ module Refinery
366
417
  end
367
418
  end
368
419
 
369
- describe "add a page with title for default locale" do
420
+ describe "add a page with title for default locale", js:true do
370
421
  before do
371
422
  visit refinery.admin_pages_path
372
- click_link "Add new page"
423
+ find('a', text: "Add new page").trigger(:click)
373
424
  fill_in "Title", :with => "News"
374
425
  click_button "Save"
375
426
  end
376
427
 
377
- it "succeeds" do
378
- page.should have_content("'News' was successfully added.")
379
- Refinery::Page.count.should == 2
428
+ it "creates a page" do
429
+ expect(page).to have_content("'News' was successfully added.")
430
+ expect(Refinery::Page.count).to eq(2)
380
431
  end
381
432
 
382
433
  it "shows locale flag for page" do
383
434
  p = ::Refinery::Page.by_slug('news').first
384
- within "#page_#{p.id}" do
385
- page.should have_css("img[src='/assets/refinery/icons/flags/en.png']")
435
+ within "#page_#{p.id} .locales" do
436
+ expect(page).to have_css('.locale_marker')
437
+ expect(page).to have_content('EN')
386
438
  end
387
439
  end
388
440
 
389
441
  it "shows title in the admin menu" do
390
442
  p = ::Refinery::Page.by_slug('news').first
391
443
  within "#page_#{p.id}" do
392
- page.should have_content('News')
393
- page.find_link('Edit this page')[:href].should include('news')
444
+ expect(page).to have_content('News')
445
+ expect(page.find('a[tooltip="Edit this page"]')[:href]).to include('news')
394
446
  end
395
447
  end
396
448
 
397
449
  it "shows in frontend menu for 'en' locale" do
450
+ # page.driver.debug
398
451
  visit "/"
399
452
 
400
453
  within "#menu" do
401
- page.should have_content('News')
402
- page.should have_selector("a[href='/news']")
454
+ expect(page).to have_content('News')
455
+ expect(page).to have_selector("a[href='/news']")
403
456
  end
404
457
  end
405
458
 
@@ -408,18 +461,18 @@ module Refinery
408
461
 
409
462
  within "#menu" do
410
463
  # we should only have the home page in the menu
411
- page.should have_css('li', :count => 1)
464
+ expect(page).to have_css('li', :count => 1)
412
465
  end
413
466
  end
414
467
  end
415
468
 
416
- describe "add a page with title for both locales" do
469
+ describe "a page with two locales", js:true do
417
470
  let(:en_page_title) { 'News' }
418
471
  let(:en_page_slug) { 'news' }
419
472
  let(:ru_page_title) { 'Новости' }
420
473
  let(:ru_page_slug_encoded) { '%D0%BD%D0%BE%D0%B2%D0%BE%D1%81%D1%82%D0%B8' }
421
474
  let!(:news_page) do
422
- Refinery::I18n.stub(:frontend_locales).and_return([:en, :ru])
475
+ allow(Refinery::I18n).to receive(:frontend_locales).and_return([:en, :ru])
423
476
 
424
477
  _page = Globalize.with_locale(:en) {
425
478
  Page.create :title => en_page_title
@@ -432,44 +485,45 @@ module Refinery
432
485
  _page
433
486
  end
434
487
 
435
- it "succeeds" do
488
+ it "can have a title for each locale" do
436
489
  news_page.destroy!
437
490
  visit refinery.admin_pages_path
438
491
 
439
- click_link "Add new page"
492
+ find('a', text:"Add new page").trigger(:click)
440
493
  within "#switch_locale_picker" do
441
- click_link "Ru"
494
+ find('a', text: "RU").trigger(:click)
442
495
  end
443
496
  fill_in "Title", :with => ru_page_title
444
497
  click_button "Save"
445
498
 
446
- within "#page_#{Page.last.id}" do
447
- click_link "Application_edit"
499
+ within "#page_#{Page.last.id} .actions" do
500
+ find("a[href^='/#{Refinery::Core.backend_route}/pages/#{ru_page_slug_encoded}/edit']").click
448
501
  end
449
502
  within "#switch_locale_picker" do
450
- click_link "En"
503
+ find('a', text: "EN").trigger(:click)
451
504
  end
452
505
  fill_in "Title", :with => en_page_title
453
506
  find("#submit_button").click
454
507
 
455
- page.should have_content("'#{en_page_title}' was successfully updated.")
456
- Refinery::Page.count.should == 2
508
+ expect(page).to have_content("'#{en_page_title}' was successfully updated.")
509
+ expect(Refinery::Page.count).to eq(2)
457
510
  end
458
511
 
459
- it "shows both locale flags for page" do
512
+ it "is shown with both locales in the index" do
460
513
  visit refinery.admin_pages_path
461
514
 
462
- within "#page_#{news_page.id}" do
463
- page.should have_css("img[src='/assets/refinery/icons/flags/en.png']")
464
- page.should have_css("img[src='/assets/refinery/icons/flags/ru.png']")
515
+ within "#page_#{news_page.id} .locales" do
516
+ expect(page).to have_css('.locale_marker', count: 2)
517
+ expect(page).to have_content('EN')
518
+ expect(page).to have_content('RU')
465
519
  end
466
520
  end
467
521
 
468
- it "shows title in admin menu in current admin locale" do
522
+ it "shows title in current admin locale in the index" do
469
523
  visit refinery.admin_pages_path
470
524
 
471
525
  within "#page_#{news_page.id}" do
472
- page.should have_content(en_page_title)
526
+ expect(page).to have_content(en_page_title)
473
527
  end
474
528
  end
475
529
 
@@ -477,7 +531,7 @@ module Refinery
477
531
  visit refinery.admin_pages_path
478
532
 
479
533
  within "#page_#{news_page.id}" do
480
- page.find_link('Edit this page')[:href].should include(en_page_slug)
534
+ expect(page.find('a[tooltip="Edit this page"]')[:href]).to include(en_page_slug)
481
535
  end
482
536
  end
483
537
 
@@ -485,7 +539,7 @@ module Refinery
485
539
  visit "/"
486
540
 
487
541
  within "#menu" do
488
- page.find_link(news_page.title)[:href].should include(en_page_slug)
542
+ expect(page.find_link(news_page.title)[:href]).to include(en_page_slug)
489
543
  end
490
544
  end
491
545
 
@@ -493,12 +547,12 @@ module Refinery
493
547
  visit "/ru"
494
548
 
495
549
  within "#menu" do
496
- page.find_link(ru_page_title)[:href].should include(ru_page_slug_encoded)
550
+ expect(page.find_link(ru_page_title)[:href]).to include(ru_page_slug_encoded)
497
551
  end
498
552
  end
499
553
  end
500
554
 
501
- describe "add a page with title only for secondary locale" do
555
+ describe "add a page with title only for secondary locale", js:true do
502
556
  let(:ru_page) {
503
557
  Globalize.with_locale(:ru) {
504
558
  Page.create :title => ru_page_title
@@ -513,40 +567,40 @@ module Refinery
513
567
  visit refinery.admin_pages_path
514
568
  end
515
569
 
516
- it "succeeds" do
570
+ it "lets you add a Russian title without an English title" do
517
571
  ru_page.destroy!
518
- click_link "Add new page"
572
+ find('a', text: 'Add new page').trigger(:click)
519
573
  within "#switch_locale_picker" do
520
- click_link "Ru"
574
+ find('a', text: "RU").trigger(:click)
521
575
  end
522
576
  fill_in "Title", :with => ru_page_title
523
577
  click_button "Save"
524
578
 
525
- page.should have_content("'#{ru_page_title}' was successfully added.")
526
- Refinery::Page.count.should == 2
579
+ expect(page).to have_content("'#{ru_page_title}' was successfully added.")
580
+ expect(Refinery::Page.count).to eq(2)
527
581
  end
528
582
 
529
- it "shows locale flag for page" do
583
+ it "shows locale indicator for page" do
530
584
  within "#page_#{ru_page_id}" do
531
- page.should have_css("img[src='/assets/refinery/icons/flags/ru.png']")
585
+ expect(page).to have_selector('.locale_marker', text: 'RU')
532
586
  end
533
587
  end
534
588
 
535
- it "doesn't show locale flag for primary locale" do
589
+ it "doesn't show locale indicator for primary locale" do
536
590
  within "#page_#{ru_page_id}" do
537
- page.should_not have_css("img[src='/assets/refinery/icons/flags/en.png']")
591
+ expect(page).to_not have_selector('.locale_marker', text: 'EN')
538
592
  end
539
593
  end
540
594
 
541
595
  it "shows title in the admin menu" do
542
596
  within "#page_#{ru_page_id}" do
543
- page.should have_content(ru_page_title)
597
+ expect(page).to have_content(ru_page_title)
544
598
  end
545
599
  end
546
600
 
547
601
  it "uses slug in admin" do
548
602
  within "#page_#{ru_page_id}" do
549
- page.find_link('Edit this page')[:href].should include(ru_page_slug_encoded)
603
+ expect(page.find('a[tooltip="Edit this page"]')[:href]).to include(ru_page_slug_encoded)
550
604
  end
551
605
  end
552
606
 
@@ -554,8 +608,8 @@ module Refinery
554
608
  visit "/ru"
555
609
 
556
610
  within "#menu" do
557
- page.should have_content(ru_page_title)
558
- page.should have_selector("a[href*='/#{ru_page_slug_encoded}']")
611
+ expect(page).to have_content(ru_page_title)
612
+ expect(page).to have_selector("a[href*='/#{ru_page_slug_encoded}']")
559
613
  end
560
614
  end
561
615
 
@@ -564,26 +618,25 @@ module Refinery
564
618
 
565
619
  within "#menu" do
566
620
  # we should only have the home page in the menu
567
- page.should have_css('li', :count => 1)
621
+ expect(page).to have_css('li', :count => 1)
568
622
  end
569
623
  end
570
624
 
571
- context "when page is a child page" do
625
+ context "when page is a child page", js: true do
572
626
  it 'succeeds' do
573
627
  ru_page.destroy!
574
628
  parent_page = Page.create(:title => "Parent page")
575
629
  sub_page = Globalize.with_locale(:ru) {
576
- Page.create :title => ru_page_title
577
630
  Page.create :title => ru_page_title, :parent_id => parent_page.id
578
631
  }
579
- sub_page.parent.should == parent_page
632
+ expect(sub_page.parent).to eq(parent_page)
580
633
  visit refinery.admin_pages_path
581
634
  within "#page_#{sub_page.id}" do
582
- click_link "Application_edit"
635
+ find("a.edit_icon").trigger(:click)
583
636
  end
584
637
  fill_in "Title", :with => ru_page_title
585
638
  click_button "Save"
586
- page.should have_content("'#{ru_page_title}' was successfully updated")
639
+ expect(page).to have_content("'#{ru_page_title}' was successfully updated")
587
640
  end
588
641
  end
589
642
  end
@@ -591,12 +644,12 @@ module Refinery
591
644
 
592
645
  describe "new page part", :js do
593
646
  before do
594
- Refinery::Pages.stub(:new_page_parts).and_return(true)
647
+ allow(Refinery::Pages).to receive(:new_page_parts).and_return(true)
595
648
  end
596
649
 
597
650
  it "adds new page part" do
598
651
  visit refinery.new_admin_page_path
599
- click_link "add_page_part"
652
+ find("#add_page_part").trigger(:click)
600
653
 
601
654
  within "#new_page_part_dialog" do
602
655
  fill_in "new_page_part_title", :with => "testy"
@@ -604,7 +657,7 @@ module Refinery
604
657
  end
605
658
 
606
659
  within "#page_parts" do
607
- page.should have_content("testy")
660
+ expect(page).to have_content("testy")
608
661
  end
609
662
  end
610
663
  end
@@ -613,31 +666,34 @@ module Refinery
613
666
  let!(:some_page) { Page.create! :title => "Some Page" }
614
667
 
615
668
  before do
616
- some_page.parts.create! :title => "First Part", :position => 1
617
- some_page.parts.create! :title => "Second Part", :position => 2
618
- some_page.parts.create! :title => "Third Part", :position => 3
669
+ some_page.parts.create! :title => "First Part", :slug => "first_part", :position => 1
670
+ some_page.parts.create! :title => "Second Part", :slug => "second_part", :position => 2
671
+ some_page.parts.create! :title => "Third Part", :slug => "third_part", :position => 3
619
672
 
620
- Refinery::Pages.stub(:new_page_parts).and_return(true)
673
+ allow(Refinery::Pages).to receive(:new_page_parts).and_return(true)
621
674
  end
622
675
 
623
676
  it "deletes page parts" do
624
677
  visit refinery.edit_admin_page_path(some_page.id)
625
678
 
626
679
  within "#page_parts" do
627
- page.should have_content("First Part")
628
- page.should have_content("Second Part")
629
- page.should have_content("Third Part")
680
+ expect(page).to have_content("First Part")
681
+ expect(page).to have_content("Second Part")
682
+ expect(page).to have_content("Third Part")
630
683
  end
631
684
 
632
685
  2.times do
633
- click_link "delete_page_part"
634
- page.driver.browser.switch_to.alert.accept
686
+ find("#delete_page_part").trigger(:click)
687
+ # Poltergeist automatically accepts dialogues.
688
+ if Capybara.javascript_driver != :poltergeist
689
+ page.driver.browser.switch_to.alert.accept
690
+ end
635
691
  end
636
692
 
637
693
  within "#page_parts" do
638
- page.should have_no_content("First Part")
639
- page.should have_no_content("Second Part")
640
- page.should have_content("Third Part")
694
+ expect(page).to have_no_content("First Part")
695
+ expect(page).to have_no_content("Second Part")
696
+ expect(page).to have_content("Third Part")
641
697
  end
642
698
 
643
699
  click_button "submit_button"
@@ -645,9 +701,9 @@ module Refinery
645
701
  visit refinery.edit_admin_page_path(some_page.id)
646
702
 
647
703
  within "#page_parts" do
648
- page.should have_no_content("First Part")
649
- page.should have_no_content("Second Part")
650
- page.should have_content("Third Part")
704
+ expect(page).to have_no_content("First Part")
705
+ expect(page).to have_no_content("Second Part")
706
+ expect(page).to have_content("Third Part")
651
707
  end
652
708
  end
653
709
  end
@@ -656,26 +712,26 @@ module Refinery
656
712
  describe 'view and layout templates' do
657
713
  context 'when parent page has templates set' do
658
714
  before do
659
- Refinery::Pages.stub(:use_layout_templates).and_return(true)
660
- Refinery::Pages.stub(:layout_template_whitelist).and_return(['abc', 'refinery'])
661
- Refinery::Pages.stub(:valid_templates).and_return(['abc', 'refinery'])
715
+ allow(Refinery::Pages).to receive(:use_layout_templates).and_return(true)
716
+ allow(Refinery::Pages).to receive(:layout_template_whitelist).and_return(['abc', 'refinery'])
717
+ allow(Refinery::Pages).to receive(:valid_templates).and_return(['abc', 'refinery'])
662
718
  parent_page = Page.create :title => 'Parent Page',
663
- :view_template => 'refinery',
664
- :layout_template => 'refinery'
719
+ :view_template => 'refinery',
720
+ :layout_template => 'refinery'
665
721
  @page = parent_page.children.create :title => 'Child Page'
666
722
  end
667
723
 
668
724
  specify 'sub page should inherit them', :js => true do
669
725
  visit refinery.edit_admin_page_path(@page.id)
670
726
 
671
- click_link 'toggle_advanced_options'
727
+ find('#toggle_advanced_options').trigger(:click)
672
728
 
673
729
  within '#page_layout_template' do
674
- page.find('option[value=refinery]').should be_selected
730
+ expect(page.find('option[value=refinery]')).to be_selected
675
731
  end
676
732
 
677
733
  within '#page_view_template' do
678
- page.find('option[value=refinery]').should be_selected
734
+ expect(page.find('option[value=refinery]')).to be_selected
679
735
  end
680
736
  end
681
737
  end
@@ -683,98 +739,58 @@ module Refinery
683
739
  end
684
740
 
685
741
  # regression spec for https://github.com/refinery/refinerycms/issues/1891
686
- describe "page part body" do
742
+ describe "a page part with HTML", js:true do
687
743
  before do
688
744
  page = Refinery::Page.create! :title => "test"
689
745
  Refinery::Pages.default_parts.each_with_index do |default_page_part, index|
690
- page.parts.create(:title => default_page_part,
691
- :body => "<header class='regression'>test</header>",
692
- :position => index)
746
+ page.parts.create(
747
+ title: default_page_part,
748
+ slug: default_page_part,
749
+ body: "<header class='regression'>test</header>",
750
+ position: index
751
+ )
693
752
  end
694
753
  end
695
754
 
696
- specify "html shouldn't be stripped" do
755
+ specify "should retain the html" do
697
756
  visit refinery.admin_pages_path
698
- click_link "Edit this page"
699
- page.should have_content("header class='regression'")
700
- end
701
- end
702
-
703
- describe "with full page caching", :caching do
704
- include CachingHelpers
705
- let(:cached_page) { Page.create :title => 'Cached page' }
706
-
707
- before do
708
- cache_page(cached_page)
709
- end
710
-
711
- describe "creating updating or destroying a page" do
712
- it "should clear the page cache" do
713
- cached_page.should be_cached
714
-
715
- visit refinery.admin_pages_path
716
- click_link "Remove this page forever"
717
-
718
- cached_page.should_not be_cached
719
- end
757
+ find('a[tooltip="Edit this page"]').trigger(:click)
758
+ Capybara.ignore_hidden_elements = false
759
+ expect(page).to have_content("header class='regression'")
760
+ Capybara.ignore_hidden_elements = true
720
761
  end
721
762
  end
722
763
  end
723
764
 
724
- describe "TranslatePages" do
725
- refinery_login_with :refinery_translator
726
-
727
- describe "add page to main locale" do
728
- it "doesn't succeed" do
729
- visit refinery.admin_pages_path
730
-
731
- click_link "Add new page"
765
+ describe "TranslatePages", :type => :feature do
766
+ before { Globalize.locale = :en }
767
+ refinery_login
732
768
 
733
- fill_in "Title", :with => "Huh?"
734
- click_button "Save"
735
-
736
- page.should have_content("You do not have the required permission to modify pages in this language")
737
- end
738
- end
739
-
740
- describe "add page to second locale" do
769
+ describe "a page with a single locale", js: true do
741
770
  before do
742
- Refinery::I18n.stub(:frontend_locales).and_return([:en, :lv])
771
+ allow(Refinery::I18n).to receive(:frontend_locales).and_return([:en, :lv])
743
772
  Page.create :title => 'First Page'
744
773
  end
745
774
 
746
- it "succeeds" do
775
+ it "can have a second locale added to it" do
747
776
  visit refinery.admin_pages_path
748
777
 
749
- click_link "Add new page"
778
+ find('a', text: 'Add new page').trigger(:click)
750
779
 
751
780
  within "#switch_locale_picker" do
752
- click_link "Lv"
781
+ find('a', text: "LV").trigger(:click)
753
782
  end
754
783
  fill_in "Title", :with => "Brīva vieta reklāmai"
755
784
  click_button "Save"
756
785
 
757
- page.should have_content("'Brīva vieta reklāmai' was successfully added.")
758
- Refinery::Page.count.should == 2
759
- end
760
- end
761
-
762
- describe "delete page from main locale" do
763
- before { Page.create :title => 'Default Page' }
764
-
765
- it "doesn't succeed" do
766
- visit refinery.admin_pages_path
767
-
768
- click_link "Remove this page forever"
769
-
770
- page.should have_content("You do not have the required permission to modify pages in this language.")
771
- Refinery::Page.count.should == 1
786
+ expect(page).to have_content("'Brīva vieta reklāmai' was successfully added.")
787
+ expect(Refinery::Page.count).to eq(2)
772
788
  end
773
789
  end
774
790
 
775
791
  describe "Pages Link-to Dialog" do
776
792
  before do
777
- Refinery::I18n.frontend_locales = [:en, :ru]
793
+ allow(Refinery::I18n).to receive(:frontend_locales).and_return [:en, :ru]
778
794
 
779
795
  # Create a page in both locales
780
796
  about_page = Globalize.with_locale(:en) do
@@ -789,7 +805,7 @@ module Refinery
789
805
 
790
806
  let(:about_page) do
791
807
  page = Refinery::Page.last
792
- # we need page parts so that there's wymeditor
808
+ # we need page parts so that there's a visual editor
793
809
  Refinery::Pages.default_parts.each_with_index do |default_page_part, index|
794
810
  page.parts.create(:title => default_page_part, :body => nil, :position => index)
795
811
  end
@@ -801,17 +817,17 @@ module Refinery
801
817
  before { Refinery::Pages.absolute_page_links = false }
802
818
 
803
819
  it "shows Russian pages if we're editing the Russian locale" do
804
- visit refinery.link_to_admin_pages_dialogs_path(:wymeditor => true, :switch_locale => :ru)
820
+ visit refinery.link_to_admin_pages_dialogs_path(:visual_editor => true, :switch_locale => :ru)
805
821
 
806
- page.should have_content("About Ru")
807
- page.should have_selector("a[href='/ru/about-ru']")
822
+ expect(page).to have_content("About Ru")
823
+ expect(page).to have_selector("a[href='/ru/about-ru']")
808
824
  end
809
825
 
810
826
  it "shows default to the default locale if no query string is added" do
811
- visit refinery.link_to_admin_pages_dialogs_path(:wymeditor => true)
827
+ visit refinery.link_to_admin_pages_dialogs_path(:visual_editor => true)
812
828
 
813
- page.should have_content("About")
814
- page.should have_selector("a[href='/about']")
829
+ expect(page).to have_content("About")
830
+ expect(page).to have_selector("a[href='/about']")
815
831
  end
816
832
  end
817
833
 
@@ -819,49 +835,17 @@ module Refinery
819
835
  before { Refinery::Pages.absolute_page_links = true }
820
836
 
821
837
  it "shows Russian pages if we're editing the Russian locale" do
822
- visit refinery.link_to_admin_pages_dialogs_path(:wymeditor => true, :switch_locale => :ru)
838
+ visit refinery.link_to_admin_pages_dialogs_path(:visual_editor => true, :switch_locale => :ru)
823
839
 
824
- page.should have_content("About Ru")
825
- page.should have_selector("a[href='http://www.example.com/ru/about-ru']")
840
+ expect(page).to have_content("About Ru")
841
+ expect(page).to have_selector("a[href='http://www.example.com/ru/about-ru']")
826
842
  end
827
843
 
828
844
  it "shows default to the default locale if no query string is added" do
829
- visit refinery.link_to_admin_pages_dialogs_path(:wymeditor => true)
830
-
831
- page.should have_content("About")
832
- page.should have_selector("a[href='http://www.example.com/about']")
833
- end
834
- end
835
-
836
- # see https://github.com/refinery/refinerycms/pull/1583
837
- context "when switching locales" do
838
- specify "dialog has correct links", :js do
839
- visit refinery.edit_admin_page_path(about_page)
840
-
841
-
842
- find("#page_part_body .wym_tools_link a").click
845
+ visit refinery.link_to_admin_pages_dialogs_path(:visual_editor => true)
843
846
 
844
- page.should have_selector("iframe#dialog_frame")
845
-
846
- page.within_frame("dialog_frame") do
847
- page.should have_content("About")
848
- page.should have_css("a[href$='/about']")
849
-
850
- click_link "cancel_button"
851
- end
852
-
853
- within "#switch_locale_picker" do
854
- click_link "Ru"
855
- end
856
-
857
- find("#page_part_body .wym_tools_link a").click
858
-
859
- page.should have_selector("iframe#dialog_frame")
860
-
861
- page.within_frame("dialog_frame") do
862
- page.should have_content("About Ru")
863
- page.should have_css("a[href$='/ru/about-ru']")
864
- end
847
+ expect(page).to have_content("About")
848
+ expect(page).to have_selector("a[href='http://www.example.com/about']")
865
849
  end
866
850
  end
867
851
  end