Skip to content

Commit

Permalink
Merge pull request #1310 from tvdeyen/rails-5.1-support
Browse files Browse the repository at this point in the history
Rails 5.1 support
  • Loading branch information
tvdeyen authored Oct 1, 2017
2 parents 0000aa8 + 5a0f167 commit ddde1e7
Show file tree
Hide file tree
Showing 11 changed files with 232 additions and 188 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ group :development, :test do
gem 'spring'
gem 'spring-commands-rspec'
gem 'rubocop', require: false
gem 'listen'
end
gem 'capybara', '~> 2.4'
gem 'database_cleaner', '~> 1.3'
Expand Down
4 changes: 2 additions & 2 deletions alchemy_cms.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ Gem::Specification.new do |gem|
gem.add_runtime_dependency 'jquery-rails', ['~> 4.0']
gem.add_runtime_dependency 'jquery-ui-rails', ['~> 5.0.0']
gem.add_runtime_dependency 'kaminari', ['~> 0.15']
gem.add_runtime_dependency 'originator', ['~> 3.0']
gem.add_runtime_dependency 'originator', ['~> 3.1']
gem.add_runtime_dependency 'non-stupid-digest-assets', ['~> 1.0.8']
gem.add_runtime_dependency 'rails', ['~> 5.0.0']
gem.add_runtime_dependency 'rails', ['~> 5.0', '< 6.0']
gem.add_runtime_dependency 'ransack', ['~> 1.4']
gem.add_runtime_dependency 'request_store', ['~> 1.2']
gem.add_runtime_dependency 'responders', ['~> 2.0']
Expand Down
14 changes: 12 additions & 2 deletions app/helpers/alchemy/elements_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,12 @@ def element_dom_id(element)

# Renders the HTML tag attributes required for preview mode.
def element_preview_code(element)
tag_options(element_preview_code_attributes(element))
if respond_to?(:tag_options)
tag_options(element_preview_code_attributes(element))
else
# Rails 5.1 uses TagBuilder
tag_builder.tag_options(element_preview_code_attributes(element))
end
end

# Returns a hash containing the HTML tag attributes required for preview mode.
Expand All @@ -205,7 +210,12 @@ def element_preview_code_attributes(element)
# HTML tag attributes containing the element's tag information.
#
def element_tags(element, options = {})
tag_options(element_tags_attributes(element, options))
if respond_to?(:tag_options)
tag_options(element_tags_attributes(element, options))
else
# Rails 5.1 uses TagBuilder
tag_builder.tag_options(element_tags_attributes(element, options))
end
end

# Returns the element's tags information as an attribute hash.
Expand Down
13 changes: 7 additions & 6 deletions spec/controllers/alchemy/admin/resources_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ class Admin::EventsController < Alchemy::Admin::ResourcesController

describe '#index' do
let(:params) { Hash.new }
let!(:peter) { Event.create(name: 'Peter') }
let!(:lustig) { Event.create(name: 'Lustig') }
let!(:peter) { create(:event, name: 'Peter') }
let!(:lustig) { create(:event, name: 'Lustig') }

before do
authorize_user(:as_admin)
Expand All @@ -33,7 +33,7 @@ class Admin::EventsController < Alchemy::Admin::ResourcesController
end

context "but searching for record with certain association" do
let(:bauwagen) { Location.create(name: 'Bauwagen') }
let(:bauwagen) { create(:location, name: 'Bauwagen') }
let(:params) { {q: {name_or_hidden_name_or_location_name_cont: "Bauwagen"}} }

before do
Expand All @@ -52,7 +52,7 @@ class Admin::EventsController < Alchemy::Admin::ResourcesController

describe '#update' do
let(:params) { {q: 'some_query', page: 6} }
let!(:peter) { Event.create(name: 'Peter') }
let!(:peter) { create(:event, name: 'Peter') }

it 'redirects to index, keeping the current location parameters' do
post :update, params: {id: peter.id, event: {name: "Hans"}}.merge(params)
Expand All @@ -62,16 +62,17 @@ class Admin::EventsController < Alchemy::Admin::ResourcesController

describe '#create' do
let(:params) { {q: 'some_query', page: 6} }
let!(:location) { create(:location) }

it 'redirects to index, keeping the current location parameters' do
post :create, params: {event: {name: "Hans"}}.merge(params)
post :create, params: {event: {name: "Hans", location_id: location.id}}.merge(params)
expect(response.redirect_url).to eq("http://test.host/admin/events?page=6&q=some_query")
end
end

describe '#destroy' do
let(:params) { {q: 'some_query', page: 6} }
let!(:peter) { Event.create(name: 'Peter') }
let!(:peter) { create(:event, name: 'Peter') }

it 'redirects to index, keeping the current location parameters' do
delete :destroy, params: {id: peter.id}.merge(params)
Expand Down
5 changes: 5 additions & 0 deletions spec/dummy/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@
# require "action_cable/engine"
# require "rails/test_unit/railtie"

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
require "alchemy_cms"

module Dummy
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 5.1

# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
Expand Down
4 changes: 2 additions & 2 deletions spec/dummy/config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

config.cache_store = :memory_store
config.public_file_server.headers = {
'Cache-Control' => 'public, max-age=172800'
'Cache-Control' => "public, max-age=#{2.days.seconds.to_i}"
}
else
config.action_controller.perform_caching = false
Expand Down Expand Up @@ -50,5 +50,5 @@

# Use an evented file watcher to asynchronously detect changes in source code,
# routes, locales, etc. This feature depends on the listen gem.
# config.file_watcher = ActiveSupport::EventedFileUpdateChecker
config.file_watcher = ActiveSupport::EventedFileUpdateChecker
end
7 changes: 6 additions & 1 deletion spec/dummy/config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
config.consider_all_requests_local = false
config.action_controller.perform_caching = true

# Attempt to read encrypted secrets from `config/secrets.yml.enc`.
# Requires an encryption key in `ENV["RAILS_MASTER_KEY"]` or
# `config/secrets.yml.key`.
config.read_encrypted_secrets = true

# Disable serving static files from the `/public` folder by default since
# Apache or NGINX already handles this.
config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
Expand Down Expand Up @@ -78,7 +83,7 @@
if ENV["RAILS_LOG_TO_STDOUT"].present?
logger = ActiveSupport::Logger.new(STDOUT)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
config.logger = ActiveSupport::TaggedLogging.new(logger)
end

# Do not dump schema after migrations.
Expand Down
14 changes: 14 additions & 0 deletions spec/dummy/config/initializers/new_framework_defaults_5_1.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Be sure to restart your server when you modify this file.
#
# This file contains migration options to ease your Rails 5.1 upgrade.
#
# Once upgraded flip defaults one by one to migrate to the new default.
#
# Read the Guide for Upgrading Ruby on Rails for more info on each option.

# Make `form_with` generate non-remote forms.
Rails.application.config.action_view.form_with_generates_remote_forms = false

# Unknown asset fallback will return the path passed in when the given
# asset is not present in the asset pipeline.
# Rails.application.config.assets.unknown_asset_fallback = false
Loading

0 comments on commit ddde1e7

Please sign in to comment.