alchemy_cms 2.2.2 → 2.2.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -25,7 +25,7 @@ end
25
25
  group :development do
26
26
  unless ENV['CI']
27
27
  gem 'guard-spork'
28
- gem 'ruby-debug19', :require => 'ruby-debug', :platform => :ruby_19
28
+ gem 'debugger', :platform => :ruby_19
29
29
  gem 'ruby-debug', :platform => :ruby_18
30
30
  end
31
31
  end
@@ -37,7 +37,6 @@ Gem::Specification.new do |s|
37
37
 
38
38
  s.add_development_dependency(%q<bumpy>)
39
39
  s.add_development_dependency(%q<capybara>)
40
- s.add_development_dependency(%q<database_cleaner>)
41
40
  s.add_development_dependency(%q<factory_girl_rails>, ['~> 1.7.0'])
42
41
  s.add_development_dependency(%q<rspec-rails>)
43
42
  s.add_development_dependency(%q<sqlite3>)
@@ -334,7 +334,7 @@ module Alchemy
334
334
  # :overlay_options [Hash] # Overlay options. See link_to_overlay_window helper.
335
335
  # :if_permitted_to [Array] # Check permission for button. [:action, :controller]. Exactly how you defined the permission in your +authorization_rules.rb+. Defaults to controller and action from button url.
336
336
  # :skip_permission_check [Boolean] # Skip the permission check. Default false. NOT RECOMMENDED!
337
- # :loading_indicator [Boolean] # Shows the please wait overlay while loading. Default false.
337
+ # :loading_indicator [Boolean] # Shows the please wait overlay while loading. Only for buttons not opening an overlay window. Default true.
338
338
  #
339
339
  def toolbar_button(options = {})
340
340
  options.symbolize_keys!
@@ -344,7 +344,7 @@ module Alchemy
344
344
  :active => false,
345
345
  :link_options => {},
346
346
  :overlay_options => {},
347
- :loading_indicator => false
347
+ :loading_indicator => true
348
348
  }
349
349
  options = defaults.merge(options)
350
350
  button = content_tag('div', :class => 'button_with_label' + (options[:active] ? ' active' : '')) do
@@ -359,7 +359,7 @@ module Alchemy
359
359
  }
360
360
  )
361
361
  else
362
- link_to options[:url], {:class => "icon_button#{options[:loading_indicator] ? nil : ' please_wait'}", :title => options[:title]}.merge(options[:link_options]) do
362
+ link_to options[:url], {:class => "icon_button#{options[:loading_indicator] ? ' please_wait' : nil}", :title => options[:title]}.merge(options[:link_options]) do
363
363
  render_icon(options[:icon])
364
364
  end
365
365
  end
@@ -1,7 +1,14 @@
1
1
  module Alchemy
2
2
  class Content < ActiveRecord::Base
3
3
 
4
- attr_accessible :name, :element_id, :do_not_index, :essence_type, :essence_id
4
+ attr_accessible(
5
+ :do_not_index,
6
+ :element_id,
7
+ :essence_id,
8
+ :essence_type,
9
+ :name,
10
+ :position
11
+ )
5
12
 
6
13
  belongs_to :essence, :polymorphic => true, :dependent => :destroy
7
14
  belongs_to :element
@@ -2,13 +2,14 @@ module Alchemy
2
2
  class Element < ActiveRecord::Base
3
3
 
4
4
  attr_accessible(
5
+ :cell_id,
6
+ :create_contents_after_create,
7
+ :folded,
5
8
  :name,
6
- :unique,
7
9
  :page_id,
10
+ :position,
8
11
  :public,
9
- :cell_id,
10
- :folded,
11
- :create_contents_after_create
12
+ :unique
12
13
  )
13
14
 
14
15
  # All Elements inside a cell are a list. All Elements not in cell are in the cell_id.nil list.
@@ -20,16 +21,15 @@ module Alchemy
20
21
  belongs_to :page
21
22
  has_and_belongs_to_many :to_be_sweeped_pages, :class_name => 'Alchemy::Page', :uniq => true, :join_table => 'alchemy_elements_alchemy_pages'
22
23
 
23
- validates_uniqueness_of :position, :scope => [:page_id, :cell_id]
24
+ validates_uniqueness_of :position, :scope => [:page_id, :cell_id], :if => lambda { |e| e.position != nil }
24
25
  validates_presence_of :name, :on => :create
25
26
 
26
27
  attr_accessor :create_contents_after_create
27
28
 
28
29
  after_create :create_contents, :unless => Proc.new { |m| m.create_contents_after_create == false }
29
30
 
30
- # TODO: add a trashed column to elements table
31
- scope :trashed, where(:page_id => nil).order('updated_at DESC')
32
- scope :not_trashed, where(Element.arel_table[:page_id].not_eq(nil))
31
+ scope :trashed, where(:position => nil).order('updated_at DESC')
32
+ scope :not_trashed, where(Element.arel_table[:position].not_eq(nil))
33
33
  scope :published, where(:public => true)
34
34
  scope :available, published.not_trashed
35
35
  scope :named, lambda { |names| where(:name => names) }
@@ -61,19 +61,18 @@ module Alchemy
61
61
  end
62
62
  end
63
63
 
64
- # Nullifies the page_id and cell_id, fold the element, set it to unpublic and removes its position.
64
+ # Trashing an element means nullifying its position and unpublishing it.
65
65
  def trash
66
- self.attributes = {
67
- :page_id => nil,
68
- :cell_id => nil,
69
- :folded => true,
70
- :public => false
71
- }
66
+ self.update_column(:public, false)
72
67
  self.remove_from_list
73
68
  end
74
69
 
75
70
  def trashed?
76
- page_id.nil?
71
+ self.position.nil?
72
+ end
73
+
74
+ def folded?
75
+ self.trashed? || self.read_attribute(:folded)
77
76
  end
78
77
 
79
78
  def content_by_name(name)
@@ -17,6 +17,7 @@ module Alchemy
17
17
  :name,
18
18
  :page_layout,
19
19
  :parent_id,
20
+ :position,
20
21
  :public,
21
22
  :restricted,
22
23
  :robot_index,
@@ -44,10 +44,6 @@ module Alchemy #:nodoc:
44
44
  '#{ingredient_column}'
45
45
  end
46
46
 
47
- def ingredient
48
- send('#{ingredient_column}')
49
- end
50
-
51
47
  def preview_text_column
52
48
  '#{preview_text_column}'
53
49
  end
@@ -129,6 +125,13 @@ module Alchemy #:nodoc:
129
125
  end
130
126
  end
131
127
 
128
+ # Returns the value stored from the database column that is configured as ingredient column.
129
+ def ingredient
130
+ if self.respond_to?(ingredient_column)
131
+ self.send(ingredient_column)
132
+ end
133
+ end
134
+
132
135
  # Essence description from config/elements.yml
133
136
  def description
134
137
  return {} if element.nil? or element.content_descriptions.nil?
@@ -1,5 +1,5 @@
1
1
  module Alchemy
2
2
 
3
- VERSION = "2.2.2"
3
+ VERSION = "2.2.3.1"
4
4
 
5
5
  end
@@ -24,6 +24,34 @@ module Alchemy
24
24
 
25
25
  end
26
26
 
27
+ describe "untrashing" do
28
+
29
+ before(:each) do
30
+ @element = FactoryGirl.create(:element, :public => false, :position => nil, :page_id => 58, :cell_id => 32)
31
+ # Because of a before_create filter it can not be created with a nil position and needs to be trashed here
32
+ @element.trash
33
+ end
34
+
35
+ it "should set a new position to the element" do
36
+ post :order, {:element_ids => ["#{@element.id}"]}
37
+ @element.reload
38
+ @element.position.should_not == nil
39
+ end
40
+
41
+ it "should assign the (new) page_id to the element" do
42
+ post :order, {:element_ids => ["#{@element.id}"], :page_id => 1, :cell_id => nil}
43
+ @element.reload
44
+ @element.page_id.should == 1
45
+ end
46
+
47
+ it "should assign the (new) cell_id to the element" do
48
+ post :order, {:element_ids => ["#{@element.id}"], :page_id => 1, :cell_id => 5}
49
+ @element.reload
50
+ @element.cell_id.should == 5
51
+ end
52
+
53
+ end
54
+
27
55
  describe '#new' do
28
56
 
29
57
  context "elements in clipboard" do
@@ -1,19 +1,52 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Alchemy::Admin::TrashController do
4
3
 
5
- render_views
6
4
 
7
- before(:each) do
8
- activate_authlogic
9
- Alchemy::UserSession.create FactoryGirl.create(:admin_user)
10
- end
5
+ module Alchemy
6
+ module Admin
11
7
 
12
- it "should hold trashed elements" do
13
- @page = FactoryGirl.create(:page, :parent_id => Alchemy::Page.rootpage.id)
14
- @element = FactoryGirl.create(:element, :page => nil, :public => false, :position => 0, :folded => true)
15
- get :index, :page_id => @page.id
16
- response.body.should have_selector("#trash_items #element_#{@element.id}.element_editor")
17
- end
8
+ describe TrashController do
9
+
10
+ render_views
11
+
12
+ before(:each) do
13
+ activate_authlogic
14
+ UserSession.create FactoryGirl.create(:admin_user)
15
+ end
16
+
17
+ let(:page) do
18
+ FactoryGirl.create(:page, :parent_id => Page.rootpage.id)
19
+ end
20
+
21
+ let(:element) do
22
+ FactoryGirl.create(:element, :public => false)
23
+ end
24
+
25
+ it "should hold trashed elements" do
26
+ # Because of a before_create filter it can not be created with a nil position and needs to be trashed here
27
+ element.trash
28
+ get :index, :page_id => page.id
29
+ response.body.should have_selector("#trash_items #element_#{element.id}.element_editor")
30
+ end
18
31
 
32
+ it "should not hold elements that are not trashed" do
33
+ element = FactoryGirl.create(:element, :page_id => 5, :public => false)
34
+ get :index, :page_id => page.id
35
+ response.body.should_not have_selector("#trash_items #element_#{element.id}.element_editor")
36
+ end
37
+
38
+ context "#clear" do
39
+
40
+ it "should destroy all containing elements" do
41
+ # Because of a before_create filter it can not be created with a nil position and needs to be trashed here
42
+ element.trash
43
+ post :clear, {:page_id => 1}
44
+ Element.trashed.should be_empty
45
+ end
46
+
47
+ end
48
+
49
+ end
50
+
51
+ end
19
52
  end
@@ -0,0 +1,5 @@
1
+ fo:
2
+ activerecord:
3
+ errors:
4
+ messages:
5
+ record_invalid: "Validation failed: %{errors}"
@@ -3,12 +3,9 @@ require 'spec_helper'
3
3
  module Alchemy
4
4
  describe Admin::PagesController, :js => true do
5
5
 
6
- before(:all) do
6
+ before(:each) do
7
7
  create_admin_user
8
8
  @german_root = FactoryGirl.create(:language_root_page, :language => Language.get_default, :name => 'Deutsch')
9
- end
10
-
11
- before(:each) do
12
9
  login_into_alchemy
13
10
  end
14
11
 
@@ -62,9 +59,5 @@ module Alchemy
62
59
 
63
60
  end
64
61
 
65
- after(:all) {
66
- @german_root.delete
67
- }
68
-
69
62
  end
70
63
  end
@@ -5,8 +5,6 @@ unless ENV["CI"]
5
5
  describe "Resources" do
6
6
 
7
7
  before(:all) do
8
- create_admin_user
9
- load_authorization_rules
10
8
  Event.create!(:name => 'My Event',
11
9
  :hidden_name => 'not shown',
12
10
  :starts_at => DateTime.new(2012, 03, 02, 8, 15),
@@ -23,6 +21,8 @@ unless ENV["CI"]
23
21
  end
24
22
 
25
23
  before(:each) {
24
+ load_authorization_rules
25
+ create_admin_user
26
26
  login_into_alchemy
27
27
  }
28
28
 
@@ -1,190 +1,193 @@
1
1
  require 'ostruct'
2
2
  require 'spec_helper'
3
3
 
4
- describe Alchemy::PagesController do
4
+ module Alchemy
5
+ describe PagesController do
5
6
 
6
- before(:all) do
7
- @default_language = Alchemy::Language.get_default
8
- @default_language_root = FactoryGirl.create(:language_root_page, :language => @default_language, :name => 'Home')
9
- end
10
-
11
- describe "#show" do
12
-
13
- it "should include all its elements and contents" do
14
- p = FactoryGirl.create(:public_page, :language => @default_language)
15
- article = p.elements.find_by_name('article')
16
- article.content_by_name('intro').essence.update_attributes(:body => 'Welcome to Peters Petshop', :public => true)
17
- visit "/alchemy/#{p.urlname}"
18
- within('div#content div.article div.intro') { page.should have_content('Welcome to Peters Petshop') }
7
+ before(:all) do
8
+ @default_language = Language.get_default
9
+ @default_language_root = FactoryGirl.create(:language_root_page, :language => @default_language, :name => 'Home')
19
10
  end
20
11
 
21
- it "should show the navigation with all visible pages" do
22
- pages = [
23
- FactoryGirl.create(:public_page, :language => @default_language, :visible => true, :name => 'Page 1', :parent_id => @default_language_root.id),
24
- FactoryGirl.create(:public_page, :language => @default_language, :visible => true, :name => 'Page 2', :parent_id => @default_language_root.id)
25
- ]
26
- visit '/alchemy/'
27
- within('div#navigation ul') { page.should have_selector('li a[href="/alchemy/page-1"], li a[href="/alchemy/page-2"]') }
28
- end
12
+ describe "#show" do
29
13
 
30
- end
31
-
32
- describe "fulltext search" do
14
+ it "should include all its elements and contents" do
15
+ p = FactoryGirl.create(:public_page, :language => @default_language)
16
+ article = p.elements.find_by_name('article')
17
+ article.content_by_name('intro').essence.update_attributes(:body => 'Welcome to Peters Petshop', :public => true)
18
+ visit "/alchemy/#{p.urlname}"
19
+ within('div#content div.article div.intro') { page.should have_content('Welcome to Peters Petshop') }
20
+ end
33
21
 
34
- before(:all) do
35
- @page = FactoryGirl.create(:public_page, :language => @default_language, :visible => true, :name => 'Page 1', :parent_id => @default_language_root.id)
36
- @element = FactoryGirl.create(:element, :name => 'article', :page => @page)
37
- FactoryGirl.create(:public_page, :language => @default_language, :name => 'Suche', :page_layout => 'search', :parent_id => @default_language_root.id)
38
- end
22
+ it "should show the navigation with all visible pages" do
23
+ pages = [
24
+ FactoryGirl.create(:public_page, :language => @default_language, :visible => true, :name => 'Page 1', :parent_id => @default_language_root.id),
25
+ FactoryGirl.create(:public_page, :language => @default_language, :visible => true, :name => 'Page 2', :parent_id => @default_language_root.id)
26
+ ]
27
+ visit '/alchemy/'
28
+ within('div#navigation ul') { page.should have_selector('li a[href="/alchemy/page-1"], li a[href="/alchemy/page-2"]') }
29
+ end
39
30
 
40
- it "should have a correct path in the form tag" do
41
- visit('/alchemy/suche')
42
- page.should have_selector('div#content form[action="/alchemy/suche"]')
43
31
  end
44
32
 
45
- context "performing the search" do
46
-
47
- it "should display search results for richtext essences" do
48
- @element.content_by_name('text').essence.update_attributes(:body => '<p>Welcome to Peters Petshop</p>', :public => true)
49
- visit('/alchemy/suche?query=Petshop')
50
- within('div#content .search_result') { page.should have_content('Petshop') }
51
- end
33
+ describe "fulltext search" do
52
34
 
53
- it "should display search results for text essences" do
54
- @element.content_by_name('intro').essence.update_attributes(:body => 'Welcome to Peters Petshop', :public => true)
55
- visit('/alchemy/suche?query=Petshop')
56
- within('div#content .search_result') { page.should have_content('Petshop') }
35
+ before(:all) do
36
+ @page = FactoryGirl.create(:public_page, :language => @default_language, :visible => true, :name => 'Page 1', :parent_id => @default_language_root.id)
37
+ @element = FactoryGirl.create(:element, :name => 'article', :page => @page)
38
+ FactoryGirl.create(:public_page, :language => @default_language, :name => 'Suche', :page_layout => 'search', :parent_id => @default_language_root.id)
57
39
  end
58
40
 
59
- it "should not find contents placed on global-pages (layoutpage => true)" do
60
- @page.update_attributes(:layoutpage => true)
61
- @element.content_by_name('intro').essence.update_attributes(:body => 'Welcome to Peters Petshop', :public => true)
62
- visit('/alchemy/suche?query=Petshop')
63
- within('div#content') { page.should have_css('h2.no_search_results') }
41
+ it "should have a correct path in the form tag" do
42
+ visit('/alchemy/suche')
43
+ page.should have_selector('div#content form[action="/alchemy/suche"]')
64
44
  end
65
45
 
66
- it "should not find contents placed on unpublished pages (public => false)" do
67
- @page.update_attributes(:public => false)
68
- @element.content_by_name('intro').essence.update_attributes(:body => 'Welcome to Peters Petshop', :public => true)
69
- visit('/alchemy/suche?query=Petshop')
70
- within('div#content') { page.should have_css('h2.no_search_results') }
71
- end
46
+ context "performing the search" do
72
47
 
73
- it "should not find contents placed on restricted pages (restricted => true)" do
74
- @page.update_attributes(:restricted => true)
75
- @element.content_by_name('intro').essence.update_attributes(:body => 'Welcome to Peters Petshop', :public => true)
76
- visit('/alchemy/suche?query=Petshop')
77
- within('div#content') { page.should have_css('h2.no_search_results') }
78
- end
48
+ it "should display search results for richtext essences" do
49
+ @element.content_by_name('text').essence.update_attributes(:body => '<p>Welcome to Peters Petshop</p>', :public => true)
50
+ visit('/alchemy/suche?query=Petshop')
51
+ within('div#content .search_result') { page.should have_content('Petshop') }
52
+ end
79
53
 
80
- end
54
+ it "should display search results for text essences" do
55
+ @element.content_by_name('intro').essence.update_attributes(:body => 'Welcome to Peters Petshop', :public => true)
56
+ visit('/alchemy/suche?query=Petshop')
57
+ within('div#content .search_result') { page.should have_content('Petshop') }
58
+ end
81
59
 
82
- end
60
+ it "should not find contents placed on global-pages (layoutpage => true)" do
61
+ @page.update_attributes(:layoutpage => true)
62
+ @element.content_by_name('intro').essence.update_attributes(:body => 'Welcome to Peters Petshop', :public => true)
63
+ visit('/alchemy/suche?query=Petshop')
64
+ within('div#content') { page.should have_css('h2.no_search_results') }
65
+ end
83
66
 
84
- describe "redirecting" do
67
+ it "should not find contents placed on unpublished pages (public => false)" do
68
+ @page.update_attributes(:public => false)
69
+ @element.content_by_name('intro').essence.update_attributes(:body => 'Welcome to Peters Petshop', :public => true)
70
+ visit('/alchemy/suche?query=Petshop')
71
+ within('div#content') { page.should have_css('h2.no_search_results') }
72
+ end
85
73
 
86
- context "in multi language mode" do
74
+ it "should not find contents placed on restricted pages (restricted => true)" do
75
+ @page.update_attributes(:restricted => true)
76
+ @element.content_by_name('intro').essence.update_attributes(:body => 'Welcome to Peters Petshop', :public => true)
77
+ visit('/alchemy/suche?query=Petshop')
78
+ within('div#content') { page.should have_css('h2.no_search_results') }
79
+ end
87
80
 
88
- before(:each) do
89
- @page = FactoryGirl.create(:public_page)
90
- Alchemy::Config.stub!(:get) { |arg| arg == :url_nesting ? true : Alchemy::Config.parameter(arg) }
91
81
  end
92
82
 
93
- it "should redirect to url with nested language code if no language params are given" do
94
- visit "/alchemy/#{@page.urlname}"
95
- page.current_path.should == "/alchemy/#{@page.language_code}/#{@page.urlname}"
96
- end
83
+ end
84
+
85
+ describe "redirecting" do
97
86
 
98
- context "should redirect to public child" do
87
+ context "in multi language mode" do
99
88
 
100
89
  before(:each) do
101
- @page.update_attributes(:public => false, :name => 'Not Public', :urlname => '')
102
- @child = FactoryGirl.create(:public_page, :name => 'Public Child', :parent_id => @page.id)
103
- Alchemy::Config.stub!(:get) { |arg| arg == :url_nesting ? false : Alchemy::Config.parameter(arg) }
90
+ @page = FactoryGirl.create(:public_page)
91
+ Config.stub!(:get) { |arg| arg == :url_nesting ? true : Config.parameter(arg) }
104
92
  end
105
93
 
106
- it "if requested page is unpublished" do
107
- visit '/alchemy/kl/not-public'
108
- page.current_path.should == '/alchemy/kl/public-child'
94
+ it "should redirect to url with nested language code if no language params are given" do
95
+ visit "/alchemy/#{@page.urlname}"
96
+ page.current_path.should == "/alchemy/#{@page.language_code}/#{@page.urlname}"
109
97
  end
110
98
 
111
- it "with nested language code, if requested page is unpublished and url has no language code" do
112
- visit '/alchemy/not-public'
113
- page.current_path.should == '/alchemy/kl/public-child'
114
- end
99
+ context "should redirect to public child" do
115
100
 
116
- end
101
+ before(:each) do
102
+ @page.update_attributes(:public => false, :name => 'Not Public', :urlname => '')
103
+ @child = FactoryGirl.create(:public_page, :name => 'Public Child', :parent_id => @page.id)
104
+ Config.stub!(:get) { |arg| arg == :url_nesting ? false : Config.parameter(arg) }
105
+ end
117
106
 
118
- it "should redirect to pages url with default language, if requested url is index url" do
119
- visit '/alchemy/'
120
- page.current_path.should == '/alchemy/de/home'
121
- end
107
+ it "if requested page is unpublished" do
108
+ visit '/alchemy/kl/not-public'
109
+ page.current_path.should == '/alchemy/kl/public-child'
110
+ end
122
111
 
123
- it "should redirect to pages url with default language, if requested url is only the language code" do
124
- visit '/alchemy/de'
125
- page.current_path.should == '/alchemy/de/home'
126
- end
112
+ it "with nested language code, if requested page is unpublished and url has no language code" do
113
+ visit '/alchemy/not-public'
114
+ page.current_path.should == '/alchemy/kl/public-child'
115
+ end
127
116
 
128
- context "requested url is only the urlname" do
129
- it "then it should redirect to pages url with nested language." do
130
- visit '/alchemy/home'
117
+ end
118
+
119
+ it "should redirect to pages url with default language, if requested url is index url" do
120
+ visit '/alchemy/'
131
121
  page.current_path.should == '/alchemy/de/home'
132
122
  end
133
- end
134
123
 
135
- it "should keep additional params" do
136
- visit "/alchemy/#{@page.urlname}?query=Peter"
137
- page.current_url.should match(/\?query=Peter/)
138
- end
124
+ it "should redirect to pages url with default language, if requested url is only the language code" do
125
+ visit '/alchemy/de'
126
+ page.current_path.should == '/alchemy/de/home'
127
+ end
139
128
 
140
- it "should render 404 if urlname and lang parameter do not belong to same page" do
141
- Alchemy::User.stub!(:admins).and_return(OpenStruct.new(:count => 2))
142
- visit "/alchemy/en/#{@page.urlname}"
143
- page.status_code.should == 404
144
- end
129
+ context "requested url is only the urlname" do
130
+ it "then it should redirect to pages url with nested language." do
131
+ visit '/alchemy/home'
132
+ page.current_path.should == '/alchemy/de/home'
133
+ end
134
+ end
145
135
 
146
- context "with url nesting" do
136
+ it "should keep additional params" do
137
+ visit "/alchemy/#{@page.urlname}?query=Peter"
138
+ page.current_url.should match(/\?query=Peter/)
139
+ end
147
140
 
148
- before(:all) do
149
- @level1 = FactoryGirl.create(:public_page, :parent_id => @default_language_root.id, :name => 'catalog', :language => @default_language)
150
- @level2 = FactoryGirl.create(:public_page, :parent_id => @level1.id, :name => 'products', :language => @default_language)
151
- @level3 = FactoryGirl.create(:public_page, :parent_id => @level2.id, :name => 'screwdriver', :language => @default_language)
141
+ it "should render 404 if urlname and lang parameter do not belong to same page" do
142
+ User.stub!(:admins).and_return(OpenStruct.new(:count => 2))
143
+ visit "/alchemy/en/#{@page.urlname}"
144
+ page.status_code.should == 404
152
145
  end
153
146
 
154
- context "enabled" do
147
+ context "with url nesting" do
155
148
 
156
- before(:each) do
157
- Alchemy::Config.stub!(:get) { |arg| arg == :url_nesting ? true : Alchemy::Config.parameter(arg) }
149
+ before(:all) do
150
+ @level1 = FactoryGirl.create(:public_page, :parent_id => @default_language_root.id, :name => 'catalog', :language => @default_language)
151
+ @level2 = FactoryGirl.create(:public_page, :parent_id => @level1.id, :name => 'products', :language => @default_language)
152
+ @level3 = FactoryGirl.create(:public_page, :parent_id => @level2.id, :name => 'screwdriver', :language => @default_language)
158
153
  end
159
154
 
160
- context "requesting a non nested url" do
155
+ context "enabled" do
161
156
 
162
- it "should redirect to nested url" do
163
- visit "/alchemy/de/screwdriver"
164
- page.current_path.should == '/alchemy/de/catalog/products/screwdriver'
157
+ before(:each) do
158
+ Config.stub!(:get) { |arg| arg == :url_nesting ? true : Config.parameter(arg) }
165
159
  end
166
160
 
167
- it "should only redirect to nested url if page is nested" do
168
- visit "/alchemy/de/catalog"
169
- page.status_code.should == 200
170
- page.current_path.should == "/alchemy/de/catalog"
161
+ context "requesting a non nested url" do
162
+
163
+ it "should redirect to nested url" do
164
+ visit "/alchemy/de/screwdriver"
165
+ page.current_path.should == '/alchemy/de/catalog/products/screwdriver'
166
+ end
167
+
168
+ it "should only redirect to nested url if page is nested" do
169
+ visit "/alchemy/de/catalog"
170
+ page.status_code.should == 200
171
+ page.current_path.should == "/alchemy/de/catalog"
172
+ end
173
+
171
174
  end
172
175
 
173
176
  end
174
177
 
175
- end
178
+ context "disabled" do
176
179
 
177
- context "disabled" do
180
+ before(:each) do
181
+ Config.stub!(:get) { |arg| arg == :url_nesting ? false : Config.parameter(arg) }
182
+ end
178
183
 
179
- before(:each) do
180
- Alchemy::Config.stub!(:get) { |arg| arg == :url_nesting ? false : Alchemy::Config.parameter(arg) }
181
- end
184
+ context "requesting a nested url" do
182
185
 
183
- context "requesting a nested url" do
186
+ it "should redirect to not nested url" do
187
+ visit "/alchemy/de/catalog/products/screwdriver"
188
+ page.current_path.should == "/alchemy/de/screwdriver"
189
+ end
184
190
 
185
- it "should redirect to not nested url" do
186
- visit "/alchemy/de/catalog/products/screwdriver"
187
- page.current_path.should == "/alchemy/de/screwdriver"
188
191
  end
189
192
 
190
193
  end
@@ -193,97 +196,92 @@ describe Alchemy::PagesController do
193
196
 
194
197
  end
195
198
 
196
- end
199
+ context "not in multi language mode" do
197
200
 
198
- context "not in multi language mode" do
201
+ before(:each) do
202
+ @page = FactoryGirl.create(:public_page, :language => @default_language, :parent_id => @default_language_root.id)
203
+ Config.stub!(:get) { |arg| arg == :url_nesting ? false : Config.parameter(arg) }
204
+ end
199
205
 
200
- before(:each) do
201
- @page = FactoryGirl.create(:public_page, :language => @default_language, :parent_id => @default_language_root.id)
202
- Alchemy::Config.stub!(:get) { |arg| arg == :url_nesting ? false : Alchemy::Config.parameter(arg) }
203
- end
206
+ it "should redirect from nested language code url to normal url" do
207
+ visit "/alchemy/de/#{@page.urlname}"
208
+ page.current_path.should == "/alchemy/#{@page.urlname}"
209
+ end
204
210
 
205
- it "should redirect from nested language code url to normal url" do
206
- visit "/alchemy/de/#{@page.urlname}"
207
- page.current_path.should == "/alchemy/#{@page.urlname}"
208
- end
211
+ context "with no lang parameter" do
209
212
 
210
- context "with no lang parameter" do
213
+ it "should have defaults language language_id in the session" do
214
+ get show_page_path(:urlname => 'a-public-page')
215
+ controller.session[:language_id].should == Language.get_default.id
216
+ end
211
217
 
212
- it "should have defaults language language_id in the session" do
213
- get show_page_path(:urlname => 'a-public-page')
214
- controller.session[:language_id].should == Alchemy::Language.get_default.id
215
- end
218
+ it "should have defaults language language_code in the session" do
219
+ get show_page_path(:urlname => 'a-public-page')
220
+ controller.session[:language_code].should == Language.get_default.code
221
+ end
216
222
 
217
- it "should have defaults language language_code in the session" do
218
- get show_page_path(:urlname => 'a-public-page')
219
- controller.session[:language_code].should == Alchemy::Language.get_default.code
220
223
  end
221
224
 
222
- end
225
+ context "should redirect to public child" do
226
+
227
+ before(:each) do
228
+ @page.update_attributes(:public => false, :name => 'Not Public', :urlname => '')
229
+ @child = FactoryGirl.create(:public_page, :name => 'Public Child', :parent_id => @page.id, :language => @default_language)
230
+ end
223
231
 
224
- context "should redirect to public child" do
232
+ it "if requested page is unpublished" do
233
+ visit '/alchemy/not-public'
234
+ page.current_path.should == '/alchemy/public-child'
235
+ end
225
236
 
226
- before(:each) do
227
- @page.update_attributes(:public => false, :name => 'Not Public', :urlname => '')
228
- @child = FactoryGirl.create(:public_page, :name => 'Public Child', :parent_id => @page.id, :language => @default_language)
229
- end
237
+ it "with normal url, if requested url has nested language code and is not public" do
238
+ visit '/alchemy/de/not-public'
239
+ page.current_path.should == '/alchemy/public-child'
240
+ end
230
241
 
231
- it "if requested page is unpublished" do
232
- visit '/alchemy/not-public'
233
- page.current_path.should == '/alchemy/public-child'
234
242
  end
235
243
 
236
- it "with normal url, if requested url has nested language code and is not public" do
237
- visit '/alchemy/de/not-public'
238
- page.current_path.should == '/alchemy/public-child'
244
+ it "should redirect to pages url, if requested url is index url" do
245
+ visit '/alchemy/'
246
+ page.current_path.should == '/alchemy/home'
239
247
  end
240
248
 
241
- end
242
-
243
- it "should redirect to pages url, if requested url is index url" do
244
- visit '/alchemy/'
245
- page.current_path.should == '/alchemy/home'
246
- end
249
+ it "should keep additional params" do
250
+ visit "/alchemy/de/#{@page.urlname}?query=Peter"
251
+ page.current_url.should match(/\?query=Peter/)
252
+ end
247
253
 
248
- it "should keep additional params" do
249
- visit "/alchemy/de/#{@page.urlname}?query=Peter"
250
- page.current_url.should match(/\?query=Peter/)
251
254
  end
252
255
 
253
256
  end
254
257
 
255
- end
256
-
257
- describe "Handling of non-existing pages" do
258
+ describe "Handling of non-existing pages" do
258
259
 
259
- context "when a language root page exists" do
260
+ context "when a language root page exists" do
260
261
 
261
- before(:all) do
262
- # We need an admin user, because otherwise we will be redirected to UserSessions controller to create a new user
263
- FactoryGirl.create(:admin_user, :login => 'foo-boo', :email => 'foo@boo.org')
264
- end
262
+ before do
263
+ User.stub!(:admins).and_return([1, 2]) # We need a admin user or the signup page will show up
264
+ visit "/alchemy/non-existing-page"
265
+ end
265
266
 
266
- before(:each) do
267
- visit "/alchemy/non-existing-page"
268
- end
267
+ it "should render the status code in the title tag" do
268
+ within("title") { page.should have_content("404") }
269
+ end
269
270
 
270
- it "should render the status code in the title tag" do
271
- within("title") { page.should have_content("404") }
272
- end
271
+ it "should render the layout" do
272
+ page.should have_selector("#language_select")
273
+ end
273
274
 
274
- it "should render the layout" do
275
- page.should have_selector("#language_select")
276
275
  end
277
276
 
278
- end
277
+ context "404-Errors are handled by Rails now, so no need to test anymore.
278
+ However, it still serves as documentation how they can be handled, so we leave it here" do
279
279
 
280
- context "404-Errors are handled by Rails now, so no need to test anymore.
281
- However, it still serves as documentation how they can be handled, so we leave it here" do
280
+ it "should render public/404.html when it exists"
281
+ it "can be handled by matching /404 and routing it to a controller of choice when no public/404.html exists"
282
282
 
283
- it "should render public/404.html when it exists"
284
- it "can be handled by matching /404 and routing it to a controller of choice when no public/404.html exists"
283
+ end
285
284
 
286
285
  end
287
-
288
286
  end
289
287
  end