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

Deprecate Alchemy::Element.available #2309

Merged
merged 2 commits into from
Apr 26, 2022
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
2 changes: 1 addition & 1 deletion app/helpers/alchemy/elements_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def render_elements(options = {}, &blk)
#
# == Usage
#
# <%= render_element(Alchemy::Element.available.named(:headline).first) %>
# <%= render_element(Alchemy::Element.published.named(:headline).first) %>
#
mamhoff marked this conversation as resolved.
Show resolved Hide resolved
# @param [Alchemy::Element] element
# The element you want to render the view for
Expand Down
4 changes: 3 additions & 1 deletion app/models/alchemy/element.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class Element < BaseRecord
dependent: :destroy

has_many :nested_elements,
-> { order(:position).available },
-> { order(:position).published },
class_name: "Alchemy::Element",
foreign_key: :parent_element_id,
dependent: :destroy,
Expand Down Expand Up @@ -178,6 +178,8 @@ def all_from_clipboard_for_parent_element(clipboard, parent_element)

all_from_clipboard(clipboard).where(name: parent_element.definition["nestable_elements"])
end

deprecate available: :published, deprecator: Alchemy::Deprecation
end

# Returns next public element from same page.
Expand Down
2 changes: 1 addition & 1 deletion app/models/alchemy/ingredient_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def validate_format(format)

def duplicates
ingredient.class
.joins(:element).merge(Alchemy::Element.available)
.joins(:element).merge(Alchemy::Element.published)
.where(Alchemy::Element.table_name => { name: ingredient.element.name })
.where(value: ingredient.value)
.where.not(id: ingredient.id)
Expand Down
4 changes: 2 additions & 2 deletions app/models/alchemy/page/page_elements.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ module PageElements
source: :elements,
) do
has_many :all_elements
has_many :elements, -> { not_nested.unfixed.available }
has_many :fixed_elements, -> { fixed.available }
has_many :elements, -> { not_nested.unfixed.published }
has_many :fixed_elements, -> { fixed.published }
end

has_many :contents, through: :elements
Expand Down
2 changes: 1 addition & 1 deletion lib/alchemy/essence.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def acts_as_essence(options = {})
has_one :element, through: :content, class_name: "Alchemy::Element"
has_one :page, through: :element, class_name: "Alchemy::Page"
scope :available, -> { joins(:element).merge(Alchemy::Element.available) }
scope :available, -> { joins(:element).merge(Alchemy::Element.published) }
scope :from_element, ->(name) { joins(:element).where(Element.table_name => { name: name }) }
delegate :restricted?, to: :page, allow_nil: true
Expand Down
4 changes: 2 additions & 2 deletions lib/alchemy/permissions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def alchemy_guest_user_rules
c.public? && !c.restricted?
end

can :read, Alchemy::Element, Alchemy::Element.available.not_restricted do |e|
can :read, Alchemy::Element, Alchemy::Element.published.not_restricted do |e|
e.public? && !e.restricted?
end

Expand All @@ -68,7 +68,7 @@ def alchemy_member_rules
c.public?
end

can :read, Alchemy::Element, Alchemy::Element.available do |e|
can :read, Alchemy::Element, Alchemy::Element.published do |e|
e.public?
end

Expand Down
9 changes: 9 additions & 0 deletions spec/models/alchemy/element_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1138,4 +1138,13 @@ module Alchemy
element.reload.destroy!
end
end

describe ".available" do
subject { Alchemy::Element.available }

it "is deprecated" do
expect(Alchemy::Deprecation).to receive(:warn)
subject
end
end
end