Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 4 commits
  • 5 files changed
  • 0 commit comments
  • 2 contributors
View
4 .travis.yml
@@ -7,9 +7,9 @@ branches:
only:
- master
before_script:
- - "sh -c 'phantomjs -v'"
+ - "phantomjs -v"
- "sh -c 'cd spec/dummy && RAILS_ENV=test bundle exec rake db:create db:schema:load --trace'"
-script: "bundle exec rspec spec --format=doc"
+script: "bundle exec rspec spec"
env:
- DB=mysql
- DB=postgresql
View
26 app/controllers/alchemy/base_controller.rb
@@ -123,9 +123,29 @@ def hashified_options
end
end
+ # Handles the layout rendering
+ #
+ # Can be used inside the controller´s +layout+ class method
+ #
+ # === Example:
+ # layout :layout_for_page
+ #
+ # === Usage:
+ # 1. You can pass none or false as url parameter to avoid any layout rendering.
+ # 2. You can pass a layout name of any existing layout file in +app/views/layouts+ folder.
+ #
+ # If no layout name is given, Alchemy tries to render +app/views/layouts/application/+ layout.
+ # If that is not present, Alchemy tries to render +app/views/layouts/alchemy/pages+ layout.
+ #
def layout_for_page
- if !params[:layout].blank? && params[:layout] != 'none'
- params[:layout]
+ if params[:layout] == 'none' || params[:layout] == 'false'
+ false
+ elsif !params[:layout].blank?
+ if File.exist?(Rails.root.join('app/views/layouts', "#{params[:layout]}.html.erb"))
+ params[:layout]
+ else
+ raise_not_found_error
+ end
elsif File.exist?(Rails.root.join('app/views/layouts', 'application.html.erb'))
'application'
else
@@ -138,7 +158,7 @@ def render_404(exception = nil)
logger.info "Rendering 404: #{exception.message}"
end
@page = Page.language_root_for(session[:language_id])
- render :file => "#{Rails.root}/public/404", :status => 404, :layout => !@page.nil?
+ render :file => Rails.root.join("public/404.html"), :status => 404, :layout => !@page.nil?
end
protected
View
21 spec/controllers/pages_controller_spec.rb
@@ -42,8 +42,25 @@
context "with param layout set to none" do
it "should not render a layout" do
- get :show, :urlname => :home, :layout => false
- response.body.should_not have_content('<head>')
+ get :show, :urlname => :home, :layout => 'none'
+ response.body.should_not match /<head>/
+ end
+
+ end
+
+ context "with param layout set to false" do
+
+ it "should not render a layout" do
+ get :show, :urlname => :home, :layout => 'false'
+ response.body.should_not match /<head>/
+ end
+
+ end
+
+ context "with params layout set to not existing layout" do
+
+ it "should raise ActionController::RoutingError" do
+ expect { get :show, :urlname => :home, :layout => 'lkuiuk' }.to raise_error(ActionController::RoutingError)
end
end
View
8 spec/spec_helper.rb
@@ -30,15 +30,7 @@ def configure
require 'capybara/poltergeist'
Capybara.default_driver = :rack_test
Capybara.default_selector = :css
- Capybara.register_driver :poltergeist do |app|
- Capybara::Poltergeist::Driver.new(app, {
- :debug => ENV['CI'] && RUBY_VERSION == "1.8.7",
- :js_errors => !(ENV['CI'] && RUBY_VERSION == "1.8.7")
- })
- end
Capybara.javascript_driver = :poltergeist
- # Raising the default wait time for capybara requests on ci under ruby 1.8.7
- Capybara.default_wait_time = 5 if ENV['CI'] && RUBY_VERSION == "1.8.7"
Capybara.register_driver(:rack_test_translated_header) do |app|
Capybara::RackTest::Driver.new(app, :headers => { 'HTTP_ACCEPT_LANGUAGE' => 'de' })
end
View
4 spec/support/alchemy/specs_helpers.rb
@@ -28,6 +28,8 @@ def authorize_as_admin
#
def login_into_alchemy
visit '/alchemy/admin/login'
+ # Giving phantomjs some time to start under ruby 1.8.7 on travis-ci
+ sleep(5) if ENV['CI'] && RUBY_VERSION == "1.8.7"
fill_in('alchemy_user_session_login', :with => 'jdoe')
fill_in('alchemy_user_session_password', :with => 's3cr3t')
click_on('Login')
@@ -53,7 +55,7 @@ def load_authorization_rules
# end
#
def create_admin_user
- @user = FactoryGirl.build(:admin_user).save_without_session_maintenance
+ @user ||= FactoryGirl.build(:admin_user).save_without_session_maintenance
end
end

No commit comments for this range

Something went wrong with that request. Please try again.