refinerycms-pages 2.0.5 → 2.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,6 +4,8 @@ module Refinery
4
4
  module Admin
5
5
  class PagesDialogsController < ::Refinery::Admin::DialogsController
6
6
 
7
+ helper :'refinery/admin/pages'
8
+
7
9
  def link_to
8
10
  # Get the switch_local variable to determine the locale we're currently editing
9
11
  # Set up Globalize with our current locale
@@ -51,6 +53,7 @@ module Refinery
51
53
  end
52
54
 
53
55
  def test_url
56
+ result = 'failure'
54
57
  begin
55
58
  timeout(5) do
56
59
  unless params[:url].blank?
@@ -59,19 +62,16 @@ module Refinery
59
62
  url.host = URI.parse(request.url).host
60
63
  end
61
64
 
62
- result = case Net::HTTP.get_response(url)
63
- when Net::HTTPSuccess, Net::HTTPRedirection
64
- 'success'
65
- else
66
- 'failure'
67
- end
68
-
69
- render :json => {:result => result}
65
+ result = 'success' if [Net::HTTPSuccess, Net::HTTPRedirection].
66
+ include? Net::HTTP.get_response(url)
70
67
  end
71
68
  end
69
+
72
70
  rescue
73
- render :json => {:result => 'failure'}
71
+ # the result is already set to failure.
74
72
  end
73
+
74
+ render :json => {:result => result}
75
75
  end
76
76
 
77
77
  def test_email
@@ -1,6 +1,7 @@
1
1
  module Refinery
2
2
  class PagesController < ::ApplicationController
3
3
  before_filter :find_page, :set_canonical, :except => [:preview]
4
+ before_filter :find_page_for_preview, :only => [:preview]
4
5
 
5
6
  # Save whole Page after delivery
6
7
  after_filter { |c| c.write_cache? }
@@ -39,14 +40,6 @@ module Refinery
39
40
  end
40
41
 
41
42
  def preview
42
- if page(fallback_to_404 = false)
43
- # Preview existing pages
44
- @page.attributes = params[:page]
45
- elsif params[:page]
46
- # Preview a non-persisted page
47
- @page = Page.new(params[:page])
48
- end
49
-
50
43
  render_with_templates?(:action => :show)
51
44
  end
52
45
 
@@ -72,6 +65,16 @@ module Refinery
72
65
  page.children.order('lft ASC').live.first
73
66
  end
74
67
 
68
+ def find_page_for_preview
69
+ if page(fallback_to_404 = false)
70
+ # Preview existing pages
71
+ @page.attributes = view_context.sanitize_hash params[:page]
72
+ elsif params[:page]
73
+ # Preview a non-persisted page
74
+ @page = Page.new params[:page]
75
+ end
76
+ end
77
+
75
78
  def find_page(fallback_to_404 = true)
76
79
  @page ||= case action_name
77
80
  when "home"
@@ -22,6 +22,31 @@ module Refinery
22
22
  { :selected => Refinery::Pages.send("#{template_type}_whitelist").first }
23
23
  end
24
24
  end
25
+
26
+ # In the admin area we use a slightly different title
27
+ # to inform the which pages are draft or hidden pages
28
+ def page_meta_information(page)
29
+ meta_information = ActiveSupport::SafeBuffer.new
30
+ meta_information << content_tag(:span, :class => 'label') do
31
+ ::I18n.t('hidden', :scope => 'refinery.admin.pages.page')
32
+ end unless page.show_in_menu?
33
+
34
+ meta_information << content_tag(:span, :class => 'label notice') do
35
+ ::I18n.t('draft', :scope => 'refinery.admin.pages.page')
36
+ end if page.draft?
37
+
38
+ meta_information.html_safe
39
+ end
40
+
41
+ # We show the title from the next available locale
42
+ # if there is no title for the current locale
43
+ def page_title_with_translations(page)
44
+ if page.title.present?
45
+ page.title
46
+ else
47
+ page.translations.detect {|t| t.title.present?}.title
48
+ end
49
+ end
25
50
  end
26
51
  end
27
52
  end
@@ -1,4 +1,20 @@
1
1
  module Refinery
2
2
  module PagesHelper
3
+
4
+ def sanitize_hash(input_hash)
5
+ sanitized_hash = HashWithIndifferentAccess.new
6
+ input_hash.each do |key, value|
7
+ # ActionPack's sanitize calls html_safe on sanitized input.
8
+ sanitized_hash[key] = if value.respond_to? :html_safe
9
+ sanitize value
10
+ elsif value.respond_to? :each
11
+ sanitize_hash value
12
+ else
13
+ value
14
+ end
15
+ end
16
+ sanitized_hash
17
+ end
18
+
3
19
  end
4
20
  end
@@ -1,9 +1,10 @@
1
1
  # Encoding: utf-8
2
+ require 'refinerycms-core'
2
3
  require 'acts_as_indexed'
3
4
  require 'friendly_id'
4
5
 
5
6
  module Refinery
6
- class Page < Refinery::Core::BaseModel
7
+ class Page < Core::BaseModel
7
8
  extend FriendlyId
8
9
 
9
10
  # when collecting the pages path how is each of the pages seperated?
@@ -25,9 +26,8 @@ module Refinery
25
26
  attr_accessible :id, :deletable, :link_url, :menu_match, :meta_keywords,
26
27
  :skip_to_first_child, :position, :show_in_menu, :draft,
27
28
  :parts_attributes, :browser_title, :meta_description,
28
- :parent_id, :menu_title, :created_at, :updated_at,
29
- :page_id, :layout_template, :view_template, :custom_slug,
30
- :slug
29
+ :parent_id, :menu_title, :page_id, :layout_template,
30
+ :view_template, :custom_slug, :slug
31
31
 
32
32
  attr_accessor :locale, :page_title, :page_menu_title # to hold temporarily
33
33
  validates :title, :presence => true
@@ -95,7 +95,7 @@ module Refinery
95
95
  end
96
96
  end
97
97
 
98
- # Finds a page using its title. This method is necessary because pages
98
+ # Finds pages by their title. This method is necessary because pages
99
99
  # are translated which means the title attribute does not exist on the
100
100
  # pages table thus requiring us to find the attribute on the translations table
101
101
  # and then join to the pages table again to return the associated record.
@@ -103,9 +103,9 @@ module Refinery
103
103
  with_globalize(:title => title)
104
104
  end
105
105
 
106
- # Finds a page using its slug. See by_title
106
+ # Finds pages by their slug. See by_title
107
107
  def by_slug(slug, conditions={})
108
- locales = Refinery.i18n_enabled? ? Refinery::I18n.frontend_locales : ::I18n.locale
108
+ locales = Refinery.i18n_enabled? ? Refinery::I18n.frontend_locales.map(&:to_s) : ::I18n.locale.to_s
109
109
  with_globalize({ :locale => locales, :slug => slug }.merge(conditions))
110
110
  end
111
111
 
@@ -148,7 +148,7 @@ module Refinery
148
148
 
149
149
  # Wrap up the logic of finding the pages based on the translations table.
150
150
  def with_globalize(conditions = {})
151
- conditions = {:locale => ::Globalize.locale}.merge(conditions)
151
+ conditions = {:locale => ::Globalize.locale.to_s}.merge(conditions)
152
152
  globalized_conditions = {}
153
153
  conditions.keys.each do |key|
154
154
  if (translated_attribute_names.map(&:to_s) | %w(locale)).include?(key.to_s)
@@ -199,7 +199,13 @@ module Refinery
199
199
  # Consists of:
200
200
  # * The default locale's translated slug
201
201
  def canonical
202
- Globalize.with_locale(::Refinery::I18n.default_frontend_locale){ url }
202
+ Globalize.with_locale(Refinery.i18n_enabled? && Refinery::I18n.default_frontend_locale || ::I18n.locale) { url }
203
+ end
204
+
205
+ # The canonical slug for this particular page.
206
+ # This is the slug for the default frontend locale.
207
+ def canonical_slug
208
+ Globalize.with_locale(Refinery.i18n_enabled? && Refinery::I18n.default_frontend_locale || ::I18n.locale) { slug }
203
209
  end
204
210
 
205
211
  # Returns in cascading order: custom_slug or menu_title or title depending on
@@ -219,7 +225,7 @@ module Refinery
219
225
  # This ensures that they are in the correct 0,1,2,3,4... etc order.
220
226
  def reposition_parts!
221
227
  reload.parts.each_with_index do |part, index|
222
- part.update_attribute(:position, index)
228
+ part.update_attributes :position => index
223
229
  end
224
230
  end
225
231
 
@@ -414,21 +420,6 @@ module Refinery
414
420
  end
415
421
  end
416
422
 
417
- # In the admin area we use a slightly different title to inform the which pages are draft or hidden pages
418
- # We show the title from the next available locale if there is no title for the current locale
419
- def title_with_meta
420
- if self.title.present?
421
- title = [self.title]
422
- else
423
- title = [self.translations.detect {|t| t.title.present?}.title]
424
- end
425
-
426
- title << "<em>(#{::I18n.t('hidden', :scope => 'refinery.admin.pages.page')})</em>" unless show_in_menu?
427
- title << "<em>(#{::I18n.t('draft', :scope => 'refinery.admin.pages.page')})</em>" if draft?
428
-
429
- title.join(' ')
430
- end
431
-
432
423
  # Used to index all the content on this page so it can be easily searched.
433
424
  def all_page_part_content
434
425
  parts.map(&:body).join(" ")
@@ -1,8 +1,7 @@
1
1
  module Refinery
2
2
  class PagePart < Refinery::Core::BaseModel
3
3
 
4
- attr_accessible :title, :content, :position, :body, :created_at,
5
- :updated_at, :refinery_page_id
4
+ attr_accessible :title, :content, :position, :body, :refinery_page_id
6
5
  belongs_to :page, :foreign_key => :refinery_page_id
7
6
 
8
7
  validates :title, :presence => true
@@ -7,7 +7,8 @@
7
7
  <% end %>
8
8
 
9
9
  <span class='title <%= 'toggle' if page.children.present? %>'>
10
- <%= page.title_with_meta.html_safe %>
10
+ <%= page_title_with_translations page %>
11
+ <%= page_meta_information page %>
11
12
  </span>
12
13
  <% if Refinery.i18n_enabled? and Refinery::I18n.frontend_locales.many? %>
13
14
  <span class='locales'>
@@ -36,7 +37,12 @@
36
37
  refinery.admin_page_path(page.uncached_nested_url),
37
38
  :class => "cancel confirm-delete",
38
39
  :title => t('delete', :scope => 'refinery.admin.pages'),
39
- :confirm => t('message', :scope => 'refinery.admin.delete', :title => page.title_with_meta.gsub(/\ ?<em>.*<\/em>/, "")),
40
+ :data => {
41
+ :confirm => t('message',
42
+ :scope => 'refinery.admin.delete',
43
+ :title => page_title_with_translations(page)
44
+ )
45
+ },
40
46
  :method => :delete if page.deletable? %>
41
47
  </span>
42
48
  </div>
@@ -6,11 +6,14 @@
6
6
  page_link_url = "#{[request.protocol, request.host_with_port].join}#{page_link_url}" if Refinery::Pages.absolute_page_links
7
7
  -%>
8
8
  <li class='clearfix<%= " child#{child}" if child %><%= " linked" if linked%>' id="<%= dom_id(page_link) -%>">
9
- <%= link_to page_link.title_with_meta.html_safe, page_link_url, {
9
+ <%= link_to page_link_url, {
10
10
  :title => t('.link_to_this_page'),
11
11
  :rel => page_link.title,
12
12
  :class => 'page_link'
13
- }.merge(link_args) %>
13
+ }.merge(link_args) do %>
14
+ <%= page_title_with_translations page_link %>
15
+ <%= page_meta_information page_link %>
16
+ <% end %>
14
17
  </li>
15
18
  <%= render :partial => 'page_link',
16
19
  :collection => page_link.children,
@@ -55,7 +55,7 @@ cs:
55
55
  save_as_draft: Uložit jako pracovní verzi
56
56
  skip_to_first_child: Přeskočit na první dceřinou stránku
57
57
  skip_to_first_child_label: Přesměruje návštěvníka na první dceřinou stránku.
58
- skip_to_first_child_help: Tato stránka se nezobrazí, místo toho bude odkaz na ní přesměrován na její první dceřinou stránku. To se může hodit pro seskupování stránkek.
58
+ skip_to_first_child_help: Tato stránka se nezobrazí, místo toho bude odkaz na ní přesměrován na její první dceřinou stránku. To se může hodit pro seskupování stránek.
59
59
  link_url: Přesměrovat tuto stránku na jiný web nebo stránku.
60
60
  link_url_help: Pokud chcete aby po kliknutí na odkaz na tutu stránku byl návštěvník přesměrován na jiný web, vložte adresu (např. http://google.com), jinak nechte prázdné
61
61
  parent_page_help: Můžete umístit tuto stránku v hierarchii pod jinou stránku. Pokud nevyberete nic, bude tato stránka umístěna na první úrovni.
@@ -49,6 +49,7 @@ en:
49
49
  create_content_section: Add content section
50
50
  delete_content_section: Delete content section
51
51
  reorder_content_section: Reorder content sections
52
+ reorder_content_section_done: I'm done reordering the content sections
52
53
  form_advanced_options:
53
54
  toggle_advanced_options: Access meta tag settings and menu options
54
55
  page_options: Page Options
@@ -34,10 +34,15 @@ fr:
34
34
  pages:
35
35
  delete: Supprimer définitivement cette page
36
36
  edit: Modifier cette page
37
+ new: Ajouter une nouvelle sous-page
38
+ expand_collapse: Développer ou réduire les sous-pages
37
39
  page:
38
40
  view_live_html: Voir cette page<br/><em>(Ouvre une nouvelle fenêtre)</em>
39
41
  hidden: caché
40
42
  draft: brouillon
43
+ form:
44
+ preview: Prévisualiser
45
+ preview_changes: Prévisualiser vos changements avant de les appliquer
41
46
  form_new_page_parts:
42
47
  title: Titre
43
48
  form_page_parts:
@@ -48,6 +53,7 @@ fr:
48
53
  page_options: Page Options
49
54
  parent_page: Page parente
50
55
  advanced_options: Options avancées
56
+ menu_title: Titre dans le menu
51
57
  custom_title: Titre personnalisé
52
58
  show_in_menu_title: Placer dans le menu
53
59
  show_in_menu_description: Placer cette page dans le menu du site
@@ -59,6 +65,7 @@ fr:
59
65
  link_url: Cette page redirige le visiteur vers un autre site ou une autre page
60
66
  link_url_help: "Si vous souhaitez que cette page mène à un autre site internet ou à une autre page lorsque l'on clique dessus dans le menu, entrez une URL '(par exemple http://google.com)'. Sinon laissez ce champ vide."
61
67
  parent_page_help: "Vous pouvez placer une page sous une autre page en la sélectionnant dans la liste. Si vous voulez que cette page soit une page parente, laissez ce champ vide."
68
+ menu_title_help: Si vous voulez que le menu affiche un titre différent que celui qui sera affiché sur la page, entrez-le ici.
62
69
  custom_title_help: "Si vous voulez que la page ait un titre différent de celui qui apparaît dans le menu, sélectionnez &apos;Text&apos; et entrez-le ici."
63
70
  actions:
64
71
  create_new_page: Créer une nouvelle page
@@ -18,14 +18,14 @@ pl:
18
18
  location: Lokacja
19
19
  new_window: Nowe okno
20
20
  new_window_label: Zaznacz tę kratkę aby link otwierał się w nowym oknie.
21
- not_sure: Nie wiesz, co wstawić w pole powyżej?
21
+ not_sure: 'Nie wiesz, co wstawić w pole powyżej?'
22
22
  step1: Znajdź stronę w sieci do której chcesz linkować.
23
23
  step2: Wklej adres z pola adresu Twojej przeglądarki i wklej go do pola powyżej.
24
24
  email_address:
25
25
  tab_name: Adres e-mail
26
26
  subject_line_optional: Opcjonalny temat
27
27
  body_optional: Opcjonalna treść
28
- not_sure: Nie wiesz, co wstawić w pola powyżej?
28
+ not_sure: 'Nie wiesz, co wstawić w pola powyżej?'
29
29
  step1_html: Wpisz lub wklej (np. z książki adresowej) adres e-mail do którego ma prowadzić link w pole '<stron>Adres e-mail</strong> powyżej.
30
30
  step2_html: Użyj pola '<strong>Temat</strong> aby wiadomość miała wstępnie określony temat.
31
31
  step3_html: Użyj pola '<strong>Treść</strong> aby wiadomość miała wstępnie określoną treść.
@@ -52,15 +52,17 @@ pl:
52
52
  custom_title: Inny tytuł
53
53
  show_in_menu_title: Pokaż w menu
54
54
  show_in_menu_description: Wyświetl tę stronę w menu witryny
55
- show_in_menu_help: Odznacz tę kratkę aby usunąć tę stronę z menu witryny. To może być przydatne jeżeli chcesz linkować do tej strony, ale nie chcesz aby była widoczna w menu.
55
+ show_in_menu_help: 'Odznacz tę kratkę aby usunąć tę stronę z menu witryny. To może być przydatne jeżeli chcesz linkować do tej strony, ale nie chcesz aby była widoczna w menu.'
56
56
  save_as_draft: Zapisz jako szkic
57
57
  skip_to_first_child: Pomiń stronę najwyższego poziomu
58
58
  skip_to_first_child_label: Przekieruj odwiedzających do pierwszej strony potomnej.
59
- skip_to_first_child_help: Ta opcja sprawia, że ta strona kieruje do pierwszej strony pod nią. To może być przydatne przy grupowaniu stron razem.
59
+ skip_to_first_child_help: 'Ta opcja sprawia, że ta strona kieruje do pierwszej strony pod nią. To może być przydatne przy grupowaniu stron razem.'
60
60
  link_url: Przekieruj tę stronę do innej strony lub witryny
61
- link_url_help: Jeżeli chcesz, aby ta strona prowadziła do innej strony lub witryny kiedy klikniesz ją w menu, wpisz tu adres URL, na przykład http://google.com.W innym wypadku pozostaw to pole pustym.
61
+ link_url_help: 'Jeżeli chcesz, aby ta strona prowadziła do innej strony lub witryny kiedy klikniesz ją w menu, wpisz tu adres URL, na przykład http://google.com.W innym wypadku pozostaw to pole pustym.'
62
62
  parent_page_help: Możesz umieścić tę stronę pod inną wybierając stronę nadrzędną z listy. Jeżeli ta strona ma być stroną najwyższego poziomu pozostaw to pole pustym.
63
- custom_title_help: Jeżeli chcesz aby ta strona miała inny tytuł niż ten widoczny w menu wybierz &apos;Tekst&apos; i wpisz go tutaj.
63
+ custom_title_help: 'Jeżeli chcesz aby ta strona miała inny tytuł niż ten widoczny w menu wybierz &apos;Tekst&apos; i wpisz go tutaj.'
64
+ menu_title: Tytuł w menu
65
+ menu_title_help: 'Jeżeli chcesz aby ta strona miała inny tytuł w menu wybierz &apos;Tekst&apos; i wpisz go tutaj.'
64
66
  actions:
65
67
  create_new_page: Dodaj nową stronę
66
68
  reorder_pages: Zmień kolejność stron
@@ -10,7 +10,11 @@ module Refinery
10
10
  def error_404(exception=nil)
11
11
  if (@page = ::Refinery::Page.where(:menu_match => "^/404$").includes(:parts).first).present?
12
12
  # render the application's custom 404 page with layout and meta.
13
- render :template => '/refinery/pages/show', :formats => [:html], :status => 404
13
+ if self.respond_to? :render_with_templates?
14
+ render_with_templates? :status => 404
15
+ else
16
+ render :template => '/refinery/pages/show', :formats => [:html], :status => 404
17
+ end
14
18
  return false
15
19
  else
16
20
  super
@@ -49,6 +49,55 @@ module Refinery
49
49
  end
50
50
  end
51
51
  end
52
+
53
+ describe "#page_meta_information" do
54
+ let(:page) { FactoryGirl.build(:page) }
55
+
56
+ context "when show_in_menu is false" do
57
+ it "adds 'hidden' label" do
58
+ page.show_in_menu = false
59
+
60
+ helper.page_meta_information(page).should eq("<span class=\"label\">hidden</span>")
61
+ end
62
+ end
63
+
64
+ context "when draft is true" do
65
+ it "adds 'draft' label" do
66
+ page.draft = true
67
+
68
+ helper.page_meta_information(page).should eq("<span class=\"label notice\">draft</span>")
69
+ end
70
+ end
71
+ end
72
+
73
+ describe "#page_title_with_translations" do
74
+ let(:page) { FactoryGirl.build(:page) }
75
+
76
+ before do
77
+ Globalize.with_locale(:en) do
78
+ page.title = "draft"
79
+ page.save!
80
+ end
81
+
82
+ Globalize.with_locale(:lv) do
83
+ page.title = "melnraksts"
84
+ page.save!
85
+ end
86
+ end
87
+
88
+ context "when title is present" do
89
+ it "returns it" do
90
+ helper.page_title_with_translations(page).should eq("draft")
91
+ end
92
+ end
93
+
94
+ context "when title for current locale isn't available" do
95
+ it "returns existing title from translations" do
96
+ Refinery::Page::Translation.where(:locale => :en).first.delete
97
+ helper.page_title_with_translations(page).should eq("melnraksts")
98
+ end
99
+ end
100
+ end
52
101
  end
53
102
  end
54
- end
103
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ module Refinery
4
+ describe PagesHelper do
5
+ describe "#sanitize_hash" do
6
+ context "when hash value responds to html_safe" do
7
+ it "returns hash with sanitized values" do
8
+ hash = { :key => "hack<script>" }
9
+ helper.sanitize_hash(hash).should eq("key" => "hack")
10
+ end
11
+ end
12
+
13
+ context "when hash value is an array" do
14
+ it "returns hash with sanitized values" do
15
+ hash = { :key => { :x => "hack<script>", :y => "malware<script>" } }
16
+ helper.sanitize_hash(hash).should eq("key"=>{"x"=>"hack", "y"=>"malware"})
17
+ end
18
+ end
19
+
20
+ context "when string value doesn't repsond to html_safe" do
21
+ it "returns hash with value untouched" do
22
+ String.any_instance.stub(:respond_to?).and_return(false)
23
+
24
+ hash = { :key => "hack<script>" }
25
+ helper.sanitize_hash(hash).should eq("key"=>"hack<script>")
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -7,7 +7,7 @@ module Refinery
7
7
  include GeneratorSpec::TestCase
8
8
  destination File.expand_path("../../../../tmp", __FILE__)
9
9
 
10
- before(:each) do
10
+ before do
11
11
  prepare_destination
12
12
  run_generator
13
13
  end
@@ -104,7 +104,7 @@ module Refinery
104
104
  end
105
105
  end
106
106
 
107
- describe '#canonical' do
107
+ context 'canonicals' do
108
108
  before do
109
109
  ::Refinery::I18n.stub(:default_frontend_locale).and_return(:en)
110
110
  ::Refinery::I18n.stub(:frontend_locales).and_return([Refinery::I18n.default_frontend_locale, :ru])
@@ -115,26 +115,53 @@ module Refinery
115
115
  let(:page_title) { 'team' }
116
116
  let(:child_title) { 'about' }
117
117
  let(:ru_page_title) { 'Новости' }
118
- let!(:default_canonical) {
119
- Globalize.with_locale(::Refinery::I18n.default_frontend_locale) {
120
- page.canonical
118
+
119
+ describe '#canonical' do
120
+ let!(:default_canonical) {
121
+ Globalize.with_locale(::Refinery::I18n.default_frontend_locale) {
122
+ page.canonical
123
+ }
121
124
  }
122
- }
123
125
 
124
- specify 'page returns itself' do
125
- page.canonical.should == page.url
126
- end
126
+ specify 'page returns itself' do
127
+ page.canonical.should == page.url
128
+ end
127
129
 
128
- specify 'default canonical matches page#canonical' do
129
- default_canonical.should == page.canonical
130
+ specify 'default canonical matches page#canonical' do
131
+ default_canonical.should == page.canonical
132
+ end
133
+
134
+ specify 'translated page returns master page' do
135
+ Globalize.with_locale(:ru) do
136
+ page.title = ru_page_title
137
+ page.save
138
+
139
+ page.canonical.should == default_canonical
140
+ end
141
+ end
130
142
  end
131
143
 
132
- specify 'translated page returns master page' do
133
- Globalize.with_locale(:ru) do
134
- page.title = ru_page_title
135
- page.save
144
+ describe '#canonical_slug' do
145
+ let!(:default_canonical_slug) {
146
+ Globalize.with_locale(::Refinery::I18n.default_frontend_locale) {
147
+ page.canonical_slug
148
+ }
149
+ }
150
+ specify 'page returns its own slug' do
151
+ page.canonical_slug.should == page.slug
152
+ end
153
+
154
+ specify 'default canonical_slug matches page#canonical' do
155
+ default_canonical_slug.should == page.canonical_slug
156
+ end
157
+
158
+ specify "translated page returns master page's slug'" do
159
+ Globalize.with_locale(:ru) do
160
+ page.title = ru_page_title
161
+ page.save
136
162
 
137
- page.canonical.should == default_canonical
163
+ page.canonical_slug.should == default_canonical_slug
164
+ end
138
165
  end
139
166
  end
140
167
  end
@@ -221,8 +248,8 @@ module Refinery
221
248
  it 'reposition correctly' do
222
249
  page.save
223
250
 
224
- page.parts.first.update_attribute(:position, 6)
225
- page.parts.last.update_attribute(:position, 4)
251
+ page.parts.first.update_attributes :position => 6
252
+ page.parts.last.update_attributes :position => 4
226
253
 
227
254
  page.parts.first.position.should == 6
228
255
  page.parts.last.position.should == 4
@@ -452,7 +479,7 @@ module Refinery
452
479
  let(:child_title) { 'about' }
453
480
  let(:created_root_about) { subject.class.create!(:title => child_title, :deletable => true) }
454
481
 
455
- before(:each) do
482
+ before do
456
483
  # Ensure pages are created.
457
484
  created_child
458
485
  created_root_about
@@ -42,7 +42,7 @@ module Refinery
42
42
  end
43
43
 
44
44
  context "when some pages exist" do
45
- before(:each) { 2.times { FactoryGirl.create(:page) } }
45
+ before { 2.times { |i| Page.create :title => "Page #{i}" } }
46
46
 
47
47
  it "shows reorder pages link" do
48
48
  visit refinery.admin_pages_path
@@ -55,18 +55,14 @@ module Refinery
55
55
  end
56
56
 
57
57
  context "when sub pages exist" do
58
- let(:company) { FactoryGirl.create(:page, :title => "Our Company") }
59
- let(:team) { FactoryGirl.create(:page, :parent => company, :title => 'Our Team') }
60
- let(:locations) { FactoryGirl.create(:page, :parent => company, :title => 'Our Locations')}
61
- let(:location) { FactoryGirl.create(:page, :parent => locations, :title => 'New York') }
58
+ let!(:company) { Page.create :title => 'Our Company' }
59
+ let!(:team) { company.children.create :title => 'Our Team' }
60
+ let!(:locations) { company.children.create :title => 'Our Locations' }
61
+ let!(:location) { locations.children.create :title => 'New York' }
62
62
 
63
63
  context "with auto expand option turned off" do
64
64
  before do
65
- Refinery::Pages.auto_expand_admin_tree = false
66
-
67
- # Pre load pages
68
- location
69
- team
65
+ Refinery::Pages.stub(:auto_expand_admin_tree).and_return(false)
70
66
 
71
67
  visit refinery.admin_pages_path
72
68
  end
@@ -81,14 +77,14 @@ module Refinery
81
77
  page.should_not have_content(locations.title)
82
78
  end
83
79
 
84
- it "expands children", :js => true do
85
- find(".toggle").click
80
+ it "expands children", :js do
81
+ find("#page_#{company.id} .toggle").click
86
82
 
87
83
  page.should have_content(team.title)
88
84
  page.should have_content(locations.title)
89
85
  end
90
86
 
91
- it "expands children when nested mutliple levels deep", :js => true do
87
+ it "expands children when nested mutliple levels deep", :js do
92
88
  find("#page_#{company.id} .toggle").click
93
89
  find("#page_#{locations.id} .toggle").click
94
90
 
@@ -98,11 +94,7 @@ module Refinery
98
94
 
99
95
  context "with auto expand option turned on" do
100
96
  before do
101
- Refinery::Pages.auto_expand_admin_tree = true
102
-
103
- # Pre load pages
104
- location
105
- team
97
+ Refinery::Pages.stub(:auto_expand_admin_tree).and_return(true)
106
98
 
107
99
  visit refinery.admin_pages_path
108
100
  end
@@ -151,7 +143,7 @@ module Refinery
151
143
  end
152
144
 
153
145
  describe "edit/update" do
154
- before(:each) { FactoryGirl.create(:page, :title => "Update me") }
146
+ before { Page.create :title => "Update me" }
155
147
 
156
148
  it "updates page" do
157
149
  visit refinery.admin_pages_path
@@ -169,9 +161,9 @@ module Refinery
169
161
 
170
162
  describe 'Previewing' do
171
163
  context "an existing page" do
172
- before(:each) { FactoryGirl.create(:page, :title => 'Preview me') }
164
+ before { Page.create :title => 'Preview me' }
173
165
 
174
- it 'will show the preview changes in a new window', :js => true do
166
+ it 'will show the preview changes in a new window', :js do
175
167
  visit refinery.admin_pages_path
176
168
 
177
169
  find('a[tooltip^=Edit]').click
@@ -181,7 +173,7 @@ module Refinery
181
173
  new_window_should_have_content("Some changes I'm unsure what they will look like")
182
174
  end
183
175
 
184
- it 'will not save the preview changes', :js => true do
176
+ it 'will not save the preview changes', :js do
185
177
  visit refinery.admin_pages_path
186
178
 
187
179
  find('a[tooltip^=Edit]').click
@@ -196,7 +188,7 @@ module Refinery
196
188
  end
197
189
 
198
190
  context 'a brand new page' do
199
- it "will not save when just previewing", :js => true do
191
+ it "will not save when just previewing", :js do
200
192
  visit refinery.admin_pages_path
201
193
 
202
194
  click_link "Add new page"
@@ -210,10 +202,10 @@ module Refinery
210
202
  end
211
203
 
212
204
  context 'a nested page' do
213
- let!(:parent_page) { FactoryGirl.create(:page, :title => "Our Parent Page") }
214
- let!(:nested_page) { FactoryGirl.create(:page, :parent => @parent, :title => 'Preview Me') }
205
+ let!(:parent_page) { Page.create :title => "Our Parent Page" }
206
+ let!(:nested_page) { parent_page.children.create :title => 'Preview Me' }
215
207
 
216
- it "works like an un-nested page", :js => true do
208
+ it "works like an un-nested page", :js do
217
209
  visit refinery.admin_pages_path
218
210
 
219
211
  within "#page_#{nested_page.id}" do
@@ -230,7 +222,7 @@ module Refinery
230
222
 
231
223
  describe "destroy" do
232
224
  context "when page can be deleted" do
233
- before(:each) { FactoryGirl.create(:page, :title => "Delete me") }
225
+ before { Page.create :title => "Delete me" }
234
226
 
235
227
  it "will show delete button" do
236
228
  visit refinery.admin_pages_path
@@ -244,7 +236,7 @@ module Refinery
244
236
  end
245
237
 
246
238
  context "when page can't be deleted" do
247
- before(:each) { FactoryGirl.create(:page, :title => "Indestructible", :deletable => false) }
239
+ before { Page.create :title => "Indestructible", :deletable => false }
248
240
 
249
241
  it "wont show delete button" do
250
242
  visit refinery.admin_pages_path
@@ -256,7 +248,7 @@ module Refinery
256
248
  end
257
249
 
258
250
  context "duplicate page titles" do
259
- before(:each) { FactoryGirl.create(:page, :title => "I was here first") }
251
+ before { Page.create :title => "I was here first" }
260
252
 
261
253
  it "will append nr to url path" do
262
254
  visit refinery.new_admin_page_path
@@ -269,7 +261,7 @@ module Refinery
269
261
  end
270
262
 
271
263
  context "with translations" do
272
- before(:each) do
264
+ before do
273
265
  Refinery::I18n.stub(:frontend_locales).and_return([:en, :ru])
274
266
 
275
267
  # Create a home page in both locales (needed to test menus)
@@ -339,7 +331,7 @@ module Refinery
339
331
  Refinery::I18n.stub(:frontend_locales).and_return([:en, :ru])
340
332
 
341
333
  _page = Globalize.with_locale(:en) {
342
- FactoryGirl.create(:page, :title => en_page_title)
334
+ Page.create :title => en_page_title
343
335
  }
344
336
  Globalize.with_locale(:ru) do
345
337
  _page.title = ru_page_title
@@ -418,14 +410,14 @@ module Refinery
418
410
  describe "add a page with title only for secondary locale" do
419
411
  let(:ru_page) {
420
412
  Globalize.with_locale(:ru) {
421
- FactoryGirl.create(:page, :title => ru_page_title)
413
+ Page.create :title => ru_page_title
422
414
  }
423
415
  }
424
416
  let(:ru_page_id) { ru_page.id }
425
417
  let(:ru_page_title) { 'Новости' }
426
418
  let(:ru_page_slug) { 'новости' }
427
419
 
428
- before(:each) do
420
+ before do
429
421
  ru_page
430
422
  visit refinery.admin_pages_path
431
423
  end
@@ -487,7 +479,7 @@ module Refinery
487
479
  end
488
480
  end
489
481
 
490
- describe "new page part", :js => true do
482
+ describe "new page part", :js do
491
483
  before do
492
484
  Refinery::Pages.stub(:new_page_parts).and_return(true)
493
485
  end
@@ -510,15 +502,16 @@ module Refinery
510
502
  describe 'advanced options' do
511
503
  describe 'view and layout templates' do
512
504
  context 'when parent page has templates set' do
513
- before(:each) do
505
+ before do
514
506
  Refinery::Pages.stub(:use_layout_templates).and_return(true)
515
507
  Refinery::Pages.stub(:use_view_templates).and_return(true)
516
508
  Refinery::Pages.stub(:layout_template_whitelist).and_return(['abc', 'refinery'])
517
509
  Refinery::Pages.stub(:view_template_whitelist).and_return(['abc', 'refinery'])
518
510
  Refinery::Pages.stub(:valid_templates).and_return(['abc', 'refinery'])
519
- parent_page = FactoryGirl.create(:page, :view_template => 'refinery',
520
- :layout_template => 'refinery')
521
- parent_page.children.create(FactoryGirl.attributes_for(:page))
511
+ parent_page = Page.create :title => 'Parent Page',
512
+ :view_template => 'refinery',
513
+ :layout_template => 'refinery'
514
+ parent_page.children.create :title => 'Child Page'
522
515
  end
523
516
 
524
517
  specify 'sub page should inherit them' do
@@ -558,9 +551,9 @@ module Refinery
558
551
  end
559
552
 
560
553
  describe "add page to second locale" do
561
- before(:each) do
554
+ before do
562
555
  Refinery::I18n.stub(:frontend_locales).and_return([:en, :lv])
563
- FactoryGirl.create(:page)
556
+ Page.create :title => 'First Page'
564
557
  end
565
558
 
566
559
  it "succeeds" do
@@ -580,7 +573,7 @@ module Refinery
580
573
  end
581
574
 
582
575
  describe "delete page from main locale" do
583
- before(:each) { FactoryGirl.create(:page) }
576
+ before { Page.create :title => 'Default Page' }
584
577
 
585
578
  it "doesn't succeed" do
586
579
  visit refinery.admin_pages_path
@@ -615,7 +608,7 @@ module Refinery
615
608
 
616
609
  describe "adding page link" do
617
610
  describe "with relative urls" do
618
- before(:each) { Refinery::Pages.absolute_page_links = false }
611
+ before { Refinery::Pages.absolute_page_links = false }
619
612
 
620
613
  it "shows Russian pages if we're editing the Russian locale" do
621
614
  visit 'refinery/pages_dialogs/link_to?wymeditor=true&switch_locale=ru'
@@ -633,7 +626,7 @@ module Refinery
633
626
  end
634
627
 
635
628
  describe "with absolute urls" do
636
- before(:each) { Refinery::Pages.absolute_page_links = true }
629
+ before { Refinery::Pages.absolute_page_links = true }
637
630
 
638
631
  it "shows Russian pages if we're editing the Russian locale" do
639
632
  visit 'refinery/pages_dialogs/link_to?wymeditor=true&switch_locale=ru'
@@ -652,7 +645,7 @@ module Refinery
652
645
 
653
646
  # see https://github.com/resolve/refinerycms/pull/1583
654
647
  context "when switching locales" do
655
- specify "dialog has correct links", :js => true do
648
+ specify "dialog has correct links", :js do
656
649
  visit refinery.edit_admin_page_path(about_page)
657
650
 
658
651
  click_link "Add Link"
@@ -3,10 +3,10 @@ require 'spec_helper'
3
3
 
4
4
  module Refinery
5
5
  describe 'page frontend' do
6
- let(:home_page) { FactoryGirl.create(:page, :title => 'Home', :link_url => '/') }
7
- let(:about_page) { FactoryGirl.create(:page, :title => 'About') }
8
- let(:draft_page) { FactoryGirl.create(:page, :title => 'Draft', :draft => true) }
9
- before(:each) do
6
+ let(:home_page) { Page.create :title => 'Home', :link_url => '/' }
7
+ let(:about_page) { Page.create :title => 'About' }
8
+ let(:draft_page) { Page.create :title => 'Draft', :draft => true }
9
+ before do
10
10
  # So that we can use Refinery.
11
11
  Refinery::PagesController.any_instance.stub(:refinery_user_required?).and_return(false)
12
12
 
@@ -65,7 +65,7 @@ module Refinery
65
65
  end
66
66
 
67
67
  describe 'title set (without menu title or browser title)' do
68
- before(:each) { visit '/about' }
68
+ before { visit '/about' }
69
69
 
70
70
  it "shows title at the top of the page" do
71
71
  find("#body_content_title").text.should == about_page.title
@@ -81,9 +81,9 @@ module Refinery
81
81
  end
82
82
 
83
83
  describe 'when menu_title is' do
84
- let(:page_mt) { FactoryGirl.create(:page, :title => 'Company News') }
84
+ let(:page_mt) { Page.create :title => 'Company News' }
85
85
 
86
- before(:each) do
86
+ before do
87
87
  Refinery::Page.stub(:fast_menu).and_return([page_mt])
88
88
  end
89
89
 
@@ -125,8 +125,10 @@ module Refinery
125
125
  end
126
126
 
127
127
  describe 'when browser_title is set' do
128
- let(:page_bt) { FactoryGirl.create(:page, :title => 'About Us', :browser_title => 'About Our Company') }
129
- before(:each) do
128
+ let(:page_bt) {
129
+ Page.create :title => 'About Us', :browser_title => 'About Our Company'
130
+ }
131
+ before do
130
132
  Refinery::Page.stub(:fast_menu).and_return([page_bt])
131
133
  end
132
134
  it 'should have the browser_title in the title tag' do
@@ -144,8 +146,8 @@ module Refinery
144
146
  end
145
147
 
146
148
  describe 'custom_slug' do
147
- let(:page_cs) { FactoryGirl.create(:page, :title => 'About Us') }
148
- before(:each) do
149
+ let(:page_cs) { Page.create :title => 'About Us' }
150
+ before do
149
151
  Refinery::Page.stub(:fast_menu).and_return([page_cs])
150
152
  end
151
153
 
@@ -206,11 +208,9 @@ module Refinery
206
208
  end
207
209
 
208
210
  describe "submenu page" do
209
- let(:submenu_page) {
210
- FactoryGirl.create(:page, :title => 'Sample Submenu', :parent_id => about_page.id)
211
- }
211
+ let(:submenu_page) { about_page.children.create :title => 'Sample Submenu' }
212
212
 
213
- before(:each) do
213
+ before do
214
214
  Refinery::Page.stub(:fast_menu).and_return([home_page, submenu_page, about_page.reload].sort_by(&:lft))
215
215
  end
216
216
 
@@ -225,8 +225,8 @@ module Refinery
225
225
  end
226
226
 
227
227
  describe "special characters title" do
228
- let(:special_page) { FactoryGirl.create(:page, :title => 'ä ö ü spéciål chåråctÉrs') }
229
- before(:each) do
228
+ let(:special_page) { Page.create :title => 'ä ö ü spéciål chåråctÉrs' }
229
+ before do
230
230
  Refinery::Page.stub(:fast_menu).and_return([home_page, about_page, special_page])
231
231
  end
232
232
 
@@ -242,11 +242,14 @@ module Refinery
242
242
  end
243
243
 
244
244
  describe "special characters title as submenu page" do
245
- let(:special_page) { FactoryGirl.create(:page, :title => 'ä ö ü spéciål chåråctÉrs',
246
- :parent_id => about_page.id) }
245
+ let(:special_page) {
246
+ about_page.children.create :title => ö ü spéciål chåråctÉrs'
247
+ }
247
248
 
248
- before(:each) do
249
- Refinery::Page.stub(:fast_menu).and_return([home_page, special_page, about_page.reload].sort_by(&:lft))
249
+ before do
250
+ Refinery::Page.stub(:fast_menu).and_return(
251
+ [home_page, special_page, about_page.reload].sort_by &:lft
252
+ )
250
253
  end
251
254
 
252
255
  it "succeeds" do
@@ -261,9 +264,9 @@ module Refinery
261
264
  end
262
265
 
263
266
  describe "hidden page" do
264
- let(:hidden_page) { FactoryGirl.create(:page, :title => "Hidden", :show_in_menu => false) }
267
+ let(:hidden_page) { Page.create :title => "Hidden", :show_in_menu => false }
265
268
 
266
- before(:each) do
269
+ before do
267
270
  Refinery::Page.stub(:fast_menu).and_return([home_page, about_page])
268
271
  end
269
272
 
@@ -280,8 +283,8 @@ module Refinery
280
283
  end
281
284
 
282
285
  describe "skip to first child" do
283
- let(:child_page) { FactoryGirl.create(:page, :title => "Child Page", :parent_id => about_page.id)}
284
- before(:each) do
286
+ let(:child_page) { about_page.children.create :title => "Child Page" }
287
+ before do
285
288
  child_page
286
289
  about = about_page.reload
287
290
  about.skip_to_first_child = true
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: refinerycms-pages
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.5
4
+ version: 2.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -54,7 +54,7 @@ dependencies:
54
54
  requirements:
55
55
  - - '='
56
56
  - !ruby/object:Gem::Version
57
- version: 2.0.5
57
+ version: 2.0.6
58
58
  type: :runtime
59
59
  prerelease: false
60
60
  version_requirements: !ruby/object:Gem::Requirement
@@ -62,7 +62,7 @@ dependencies:
62
62
  requirements:
63
63
  - - '='
64
64
  - !ruby/object:Gem::Version
65
- version: 2.0.5
65
+ version: 2.0.6
66
66
  - !ruby/object:Gem::Dependency
67
67
  name: babosa
68
68
  requirement: !ruby/object:Gem::Requirement
@@ -172,6 +172,7 @@ files:
172
172
  - spec/factories/pages.rb
173
173
  - spec/helpers/refinery/pages/admin/pages_helper_spec.rb
174
174
  - spec/helpers/refinery/pages/content_pages_helper_spec.rb
175
+ - spec/helpers/refinery/pages/pages_helper_spec.rb
175
176
  - spec/lib/generators/refinery/pages/pages_generator_spec.rb
176
177
  - spec/lib/pages/content_page_presenter_spec.rb
177
178
  - spec/lib/pages/content_presenter_spec.rb
@@ -197,7 +198,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
197
198
  version: '0'
198
199
  segments:
199
200
  - 0
200
- hash: -121281082121598221
201
+ hash: -2478798985618301281
201
202
  required_rubygems_version: !ruby/object:Gem::Requirement
202
203
  none: false
203
204
  requirements:
@@ -206,7 +207,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
206
207
  version: '0'
207
208
  segments:
208
209
  - 0
209
- hash: -121281082121598221
210
+ hash: -2478798985618301281
210
211
  requirements: []
211
212
  rubyforge_project: refinerycms
212
213
  rubygems_version: 1.8.22
@@ -218,6 +219,7 @@ test_files:
218
219
  - spec/factories/pages.rb
219
220
  - spec/helpers/refinery/pages/admin/pages_helper_spec.rb
220
221
  - spec/helpers/refinery/pages/content_pages_helper_spec.rb
222
+ - spec/helpers/refinery/pages/pages_helper_spec.rb
221
223
  - spec/lib/generators/refinery/pages/pages_generator_spec.rb
222
224
  - spec/lib/pages/content_page_presenter_spec.rb
223
225
  - spec/lib/pages/content_presenter_spec.rb