Skip to content

Commit

Permalink
Use Alchemy::Current if supported
Browse files Browse the repository at this point in the history
Since Alchemy 7.1 `Alchemy::Language.current` is deprecated.
We should use `Alchemy::Current` if present in the Alchemy version.
  • Loading branch information
tvdeyen committed May 6, 2024
1 parent e330574 commit 99a3cf7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
6 changes: 5 additions & 1 deletion app/controllers/alchemy/json_api/admin/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ def caching_options
end

def set_current_preview
Alchemy::Page.current_preview = @page
if Alchemy.const_defined?(:Current)
Alchemy::Current.preview_page = @page
else
Alchemy::Page.current_preview = @page
end
end

def last_modified_for(page)
Expand Down
12 changes: 10 additions & 2 deletions app/controllers/alchemy/json_api/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,17 @@ def api_page(page)
def base_page_scope
# cancancan is not able to merge our complex AR scopes for logged in users
if can?(:edit_content, ::Alchemy::Page)
Alchemy::Language.current.pages.joins(page_version_type)
current_language.pages.joins(page_version_type)
else
Alchemy::Language.current.pages.published.joins(page_version_type)
current_language.pages.published.joins(page_version_type)
end
end

def current_language
if Alchemy.const_defined?(:Current)
Alchemy::Current.language
else
Alchemy::Language.current
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

it "stores page as preview" do
get :show, params: { path: page.urlname }
expect(Alchemy::Page.current_preview).to eq(page.id)
expect(Alchemy::Current.preview_page).to eq(page)
end
end
end

0 comments on commit 99a3cf7

Please sign in to comment.