Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecations #1656

Merged
merged 13 commits into from
Oct 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions app/controllers/alchemy/admin/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,6 @@ def render_errors_or_redirect(object, redirect_url, flash_notice)
end
end

def per_page_value_for_screen_size
Alchemy::Deprecation.warn("#per_page_value_for_screen_size is deprecated, please use #items_per_page instead")
return items_per_page if session[:screen_size].blank?
screen_height = session[:screen_size].split('x').last.to_i
(screen_height / 50) - 12
end

# Does redirects for html and js requests
#
def do_redirect_to(url_or_path)
Expand Down
40 changes: 1 addition & 39 deletions app/helpers/alchemy/elements_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,6 @@ def render_elements(options = {})
render_format: 'html'
}.update(options)

if options[:sort_by]
Alchemy::Deprecation.warn "options[:sort_by] has been removed without replacement. " \
"Please implement your own element sorting by passing a custom finder instance to options[:finder]."
end

if options[:from_cell]
Alchemy::Deprecation.warn "options[:from_cell] has been removed without replacement. " \
"Please `render element.nested_elements` instead."
end

finder = options[:finder] || Alchemy::ElementsFinder.new(options)
elements = finder.elements(page: options[:from_page])

Expand Down Expand Up @@ -158,18 +148,7 @@ def render_elements(options = {})
# @note If the view partial is not found
# <tt>alchemy/elements/_view_not_found.html.erb</tt> gets rendered.
#
def render_element(*args)
if args.length == 4
element, _part, options, counter = *args
Alchemy::Deprecation.warn "passing a `part` parameter as second argument to `render_element` has been removed without replacement. " \
"You can safely remove it."
else
element, options, counter = *args
end

options ||= {}
counter ||= 1

def render_element(element, options = {}, counter = 1)
if element.nil?
warning('Element is nil')
render "alchemy/elements/view_not_found", {name: 'nil'}
Expand Down Expand Up @@ -249,22 +228,5 @@ def element_tags_attributes(element, options = {})
return {} if !element.taggable? || element.tag_list.blank?
{ 'data-element-tags' => options[:formatter].call(element.tag_list) }
end

# Sort given elements by content.
# @deprecated
# @param [Array] elements - The elements you want to sort
# @param [String] content_name - The name of the content you want to sort by
# @param [Boolean] reverse - Reverse the sorted elements order
#
# @return [Array]
def sort_elements_by_content(elements, content_name, reverse = false)
Alchemy::Deprecation.warn "options[:sort_by] is deprecated. Please implement your own element sorting."
sorted_elements = elements.sort_by do |element|
content = element.content_by_name(content_name)
content ? content.ingredient.to_s : ''
end

reverse ? sorted_elements.reverse : sorted_elements
end
end
end
7 changes: 0 additions & 7 deletions app/helpers/alchemy/pages_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -293,12 +293,5 @@ def meta_keywords
def meta_robots
"#{@page.robot_index? ? '' : 'no'}index, #{@page.robot_follow? ? '' : 'no'}follow"
end

# @deprecated
def render_cell(name, _options = {})
render_elements(only: name, fixed: true)
end
deprecate render_cell: 'Use render_elements(only: <cell-name>, fixed: true) instead',
deprecator: Alchemy::Deprecation
end
end
15 changes: 2 additions & 13 deletions app/models/alchemy/content/factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ def new(attributes = {})
element_id: element.id
).tap(&:build_essence)
end
alias_method :build, :new
deprecate build: :new, deprecator: Alchemy::Deprecation

# Creates a new content from elements definition in the +elements.yml+ file.
#
Expand All @@ -38,20 +36,11 @@ def new(attributes = {})
#
# @return [Alchemy::Content]
#
def create(*args)
attributes = args.last || {}
if args.length > 1
Alchemy::Deprecation.warn 'Passing an element as first argument to Alchemy::Content.create is deprecated! Pass an attribute hash with element inside instead.'
element = args.first
else
element = attributes[:element]
end
new(attributes.merge(element: element)).tap do |content|
def create(attributes = {})
new(attributes).tap do |content|
content.essence.save && content.save
end
end
alias_method :create_from_scratch, :create
deprecate create_from_scratch: :create, deprecator: Alchemy::Deprecation

# Creates a copy of source and also copies the associated essence.
#
Expand Down
17 changes: 1 addition & 16 deletions app/models/alchemy/element.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,6 @@ def new(attributes = {})

super(element_definition.merge(element_attributes).except(*FORBIDDEN_DEFINITION_ATTRIBUTES))
end
alias_method :new_from_scratch, :new
deprecate new_from_scratch: :new, deprecator: Alchemy::Deprecation

alias_method :create_from_scratch, :create
deprecate create_from_scratch: :create, deprecator: Alchemy::Deprecation

# This methods does a copy of source and all depending contents and all of their depending essences.
#
Expand Down Expand Up @@ -262,17 +257,7 @@ def compact?
# Element partials live in +app/views/alchemy/elements+
#
def to_partial_path
if Alchemy::LOOKUP_CONTEXT.exists?("#{name}_view", ["elements"], true)
Alchemy::Deprecation.warn <<~WARN
Having the `_view` suffix on your element view partials is deprecated
and will not be supported in Alchemy 5.0 anymore. You can safely remove the suffix now.

Please also rename the local `element` or `#{name}_view` variable into `#{name}`.
WARN
"alchemy/elements/#{name}_view"
else
"alchemy/elements/#{name}"
end
"alchemy/elements/#{name}"
end

# Returns the key that's taken for cache path.
Expand Down
8 changes: 1 addition & 7 deletions app/models/alchemy/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -310,13 +310,7 @@ def new_name_for_copy(custom_name, source_name)
# Use this for your custom element loading logic.
#
# @return [ActiveRecord::Relation]
def find_elements(options = {}, show_non_public = false)
if show_non_public
Alchemy::Deprecation.warn "Passing true as second argument to page#find_elements to include" \
" invisible elements has been removed. Please implement your own ElementsFinder" \
" and pass it with options[:finder]."
end

def find_elements(options = {})
finder = options[:finder] || Alchemy::ElementsFinder.new(options)
finder.elements(page: self)
end
Expand Down
2 changes: 0 additions & 2 deletions app/models/alchemy/page/page_elements.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,6 @@ def descendent_element_definitions
def element_definition_names
definition['elements'] || []
end
alias_method :element_names_from_definition, :element_definition_names
deprecate element_names_from_definition: :element_definition_names, deprecator: Alchemy::Deprecation

# Element definitions with given name(s)
#
Expand Down
6 changes: 0 additions & 6 deletions lib/alchemy/resources_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,6 @@ def resource_attribute_field_options(attribute)
end
end

# Renders the human model name with a count as h1 header
def resources_header
Alchemy::Deprecation.warn "resources_header is deprecated. Render 'alchemy/admin/resources/table_header' partial instead."
render 'alchemy/admin/resources/table_header'
end

# Returns true if the resource contains any relations
def contains_relations?
resource_handler.resource_relations.present?
Expand Down
93 changes: 0 additions & 93 deletions lib/alchemy/test_support/controller_requests.rb

This file was deleted.

43 changes: 0 additions & 43 deletions spec/helpers/alchemy/elements_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,27 +55,6 @@ module Alchemy
is_expected.to match(/2\./)
end
end

context 'with 4 arguments given' do
subject { render_element(element, :view, {locals: {some: 'thing'}}, 2) }

it 'passes options into the view' do
Alchemy::Deprecation.silence do
is_expected.to match(/thing/)
end
end

it 'passes counter into the view' do
Alchemy::Deprecation.silence do
is_expected.to match(/2\./)
end
end

it 'warns about removal of second parameter' do
expect(Alchemy::Deprecation).to receive(:warn)
subject
end
end
end

describe '#element_dom_id' do
Expand Down Expand Up @@ -128,28 +107,6 @@ module Alchemy
end
end

context 'with sort_by option given' do
let(:options) do
{ sort_by: :name }
end

it 'warns about removal of sort_by option' do
expect(Alchemy::Deprecation).to receive(:warn)
subject
end
end

context 'with from_cell option given' do
let(:options) do
{ from_cell: :header }
end

it 'warns about removal of from_cell option' do
expect(Alchemy::Deprecation).to receive(:warn)
subject
end
end

context 'with option separator given' do
let(:options) { {separator: '<hr>'} }

Expand Down
20 changes: 2 additions & 18 deletions spec/models/alchemy/element_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -808,24 +808,8 @@ module Alchemy
end

describe "#to_partial_path" do
context 'if element partial with _view suffix exists' do
before do
expect(Alchemy::LOOKUP_CONTEXT).to receive(:exists?) { true }
end

it do
expect(Element.new(name: 'article').to_partial_path).to eq('alchemy/elements/article_view')
end
end

context 'if element partial with _view suffix does not exist' do
before do
expect(Alchemy::LOOKUP_CONTEXT).to receive(:exists?) { false }
end

it do
expect(Element.new(name: 'article').to_partial_path).to eq('alchemy/elements/article')
end
it do
expect(Element.new(name: 'article').to_partial_path).to eq('alchemy/elements/article')
end
end

Expand Down
9 changes: 0 additions & 9 deletions spec/models/alchemy/page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1166,15 +1166,6 @@ module Alchemy
expect(subject.map(&:name)).to eq(['news'])
end
end

context 'with second argument set to true' do
subject { page.find_elements(options, true) }

it 'warns about removal of second argument' do
expect(Alchemy::Deprecation).to receive(:warn)
subject
end
end
end

describe '#first_public_child' do
Expand Down
1 change: 0 additions & 1 deletion spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
require 'shoulda-matchers'

require 'alchemy/seeder'
require 'alchemy/test_support/controller_requests'
require 'alchemy/test_support/config_stubbing'
require 'alchemy/test_support/essence_shared_examples'
require 'alchemy/test_support/integration_helpers'
Expand Down