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

Tackle Rails 6 deprecations #1636

Merged
merged 4 commits into from
Oct 13, 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
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ cache:
directories:
- /home/travis/.webdrivers/
rvm:
- 2.5.5
- 2.6.3
- 2.5.7
- 2.6.5
before_install:
- gem install bundler
before_script:
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/alchemy/admin/elements_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def create
def update
if @element.update_contents(contents_params)
@page = @element.page
@element_validated = @element.update_attributes!(element_params)
@element_validated = @element.update(element_params)
else
@element_validated = false
@notice = Alchemy.t('Validation failed')
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/alchemy/admin/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def configure
def update
# stores old page_layout value, because unfurtunally rails @page.changes does not work here.
@old_page_layout = @page.page_layout
if @page.update_attributes(page_params)
if @page.update(page_params)
@notice = Alchemy.t("Page saved", name: @page.name)
@while_page_edit = request.referer.include?('edit')

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/alchemy/admin/resources_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def create
end

def update
resource_instance_variable.update_attributes(resource_params)
resource_instance_variable.update(resource_params)
render_errors_or_redirect(
resource_instance_variable,
resources_path(resource_instance_variable.class, search_filter_params),
Expand Down
3 changes: 1 addition & 2 deletions app/controllers/alchemy/admin/tags_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ def update
operation_text = Alchemy.t('Replaced Tag') % {old_tag: @tag.name, new_tag: @new_tag.name}
@tag.destroy
else
@tag.update_attributes(tag_params)
@tag.save
@tag.update(tag_params)
operation_text = Alchemy.t(:successfully_updated_tag)
end
render_errors_or_redirect @tag, admin_tags_path, operation_text
Expand Down
10 changes: 8 additions & 2 deletions app/models/alchemy/language.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,16 @@ class Language < BaseRecord

scope :published, -> { where(public: true) }
scope :with_root_page, -> { joins(:pages).where(Page.table_name => {language_root: true}) }
scope :on_site, ->(s) { s ? where(site_id: s.id) : all }
scope :on_current_site, -> { on_site(Site.current) }

class << self
def on_site(site)
site ? where(site_id: site.id) : all
end

def on_current_site
on_site(Site.current)
end

# Store the current language in the current thread.
def current=(language)
RequestStore.store[:alchemy_current_language] = language
Expand Down
2 changes: 1 addition & 1 deletion app/models/alchemy/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ def fold!(user_id, status)

def set_restrictions_to_child_pages
descendants.each do |child|
child.update_attributes(restricted: restricted?)
child.update(restricted: restricted?)
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/alchemy/page/page_scopes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module Page::PageScopes

# All locked pages
#
scope :locked, -> { where.not(locked_at: nil, locked_by: nil) }
scope :locked, -> { where.not(locked_at: nil).where.not(locked_by: nil) }

# All pages locked by given user
#
Expand Down
2 changes: 1 addition & 1 deletion lib/alchemy/test_support/essence_shared_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
content = create(:alchemy_content, element: element, essence: essence, essence_type: essence.class.name)

content.update_column(:updated_at, 3.days.ago)
content.essence.update_attributes(essence.ingredient_column.to_sym => ingredient_value)
content.essence.update(essence.ingredient_column.to_sym => ingredient_value)

content.reload
expect(content.updated_at).to be_within(3.seconds).of(Time.current)
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/alchemy/admin/elements_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ module Alchemy
it "updates the element" do
expect(controller).to receive(:element_params).and_return(element_parameters)
expect(element).to receive(:update_contents).and_return(true)
expect(element).to receive(:update_attributes!).with(element_parameters).and_return(true)
expect(element).to receive(:update).with(element_parameters).and_return(true)
put :update, params: {id: element.id}, xhr: true
end

Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/alchemy/elements_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module Alchemy
end

it "should raise ActiveRecord::RecordNotFound error for unpublished elements" do
element.update_attributes(public: false)
element.update_columns(public: false)
expect {
get :show, params: {id: element.id}
}.to raise_error(ActiveRecord::RecordNotFound)
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/alchemy/pages_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ module Alchemy
end

it "should include content" do
page.elements.first.content_by_name('news_headline').essence.update_attributes({body: 'Peters Petshop'})
page.elements.first.content_by_name('news_headline').essence.update_columns(body: 'Peters Petshop')
get :show, params: {urlname: 'news', format: :rss}
expect(response.body).to match /Peters Petshop/
end
Expand Down
2 changes: 1 addition & 1 deletion spec/features/page_feature_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
let(:essence) { article.content_by_name('intro').essence }

before do
essence.update_attributes(body: 'Welcome to Peters Petshop', public: true)
essence.update_columns(body: 'Welcome to Peters Petshop', public: true)
end

it "should include all its elements and contents" do
Expand Down
6 changes: 3 additions & 3 deletions spec/features/page_redirects_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@

context "if requested page is unpublished" do
before do
public_page.update_attributes(
public_page.update(
public_on: nil,
visible: false,
name: 'Not Public',
Expand All @@ -103,7 +103,7 @@

context "with only unpublished pages in page tree" do
before do
public_child.update_attributes(public_on: nil)
public_child.update(public_on: nil)
end

it "should raise not found error" do
Expand Down Expand Up @@ -244,7 +244,7 @@

context "redirects to public child" do
before do
public_page.update_attributes(
public_page.update(
visible: false,
public_on: nil,
name: 'Not Public',
Expand Down
10 changes: 5 additions & 5 deletions spec/helpers/alchemy/pages_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -258,33 +258,33 @@ module Alchemy
let(:user) { build(:alchemy_dummy_user) }

it "should render a breadcrumb of restricted pages only" do
page.update_attributes!(restricted: true, urlname: 'a-restricted-public-page', name: 'A restricted Public Page', title: 'A restricted Public Page')
page.update_columns(restricted: true, urlname: 'a-restricted-public-page', name: 'A restricted Public Page', title: 'A restricted Public Page')
result = helper.render_breadcrumb(page: page, restricted_only: true).strip
expect(result).to have_selector("*[contains(\"#{page.name}\")]")
expect(result).to_not have_selector("*[contains(\"#{parent.name}\")]")
end
end

it "should render a breadcrumb of visible pages only" do
page.update_attributes!(visible: false, urlname: 'a-invisible-page', name: 'A Invisible Page', title: 'A Invisible Page')
page.update_columns(visible: false, urlname: 'a-invisible-page', name: 'A Invisible Page', title: 'A Invisible Page')
expect(helper.render_breadcrumb(page: page)).not_to match(/A Invisible Page/)
end

it "should render a breadcrumb of visible and unpublished pages" do
page.update_attributes!(public_on: nil, urlname: 'a-unpublic-page', name: 'A Unpublic Page', title: 'A Unpublic Page')
page.update_columns(public_on: nil, urlname: 'a-unpublic-page', name: 'A Unpublic Page', title: 'A Unpublic Page')
expect(helper.render_breadcrumb(page: page)).to match(/A Unpublic Page/)
end

context "with options[:without]" do
it "should render a breadcrumb without this page" do
page.update_attributes!(urlname: 'not-me', name: 'Not Me', title: 'Not Me')
page.update_columns(urlname: 'not-me', name: 'Not Me', title: 'Not Me')
expect(helper.render_breadcrumb(page: page, without: page)).not_to match(/Not Me/)
end
end

context "with options[:without] as array" do
it "should render a breadcrumb without these pages." do
page.update_attributes!(urlname: 'not-me', name: 'Not Me', title: 'Not Me')
page.update_columns(urlname: 'not-me', name: 'Not Me', title: 'Not Me')
expect(helper.render_breadcrumb(page: page, without: [page])).not_to match(/Not Me/)
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/models/alchemy/content_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Alchemy
let(:content) { element.contents.find_by(essence_type: 'Alchemy::EssenceText') }

it "should return the ingredient from its essence" do
content.essence.update_attributes(body: "Hello")
content.essence.update_columns(body: "Hello")
expect(content.ingredient).to eq("Hello")
end

Expand Down
6 changes: 3 additions & 3 deletions spec/models/alchemy/language_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ module Alchemy
describe "#remove_old_default if default attribute has changed to true" do
it "should unset the default status of the old default language" do
default_language
language.update_attributes(default: true)
language.update(default: true)
default_language.reload
expect(default_language.default).to be_falsey
end
Expand All @@ -81,7 +81,7 @@ module Alchemy
describe "#set_pages_language if language´s code has changed" do
it "should update all its pages with the new code" do
@other_page = create(:alchemy_page, language: language)
language.update_attributes(code: "fo")
language.update(code: "fo")
language.reload; page.reload; @other_page.reload
expect([page.language_code, @other_page.language_code]).to eq([language.code, language.code])
end
Expand All @@ -91,7 +91,7 @@ module Alchemy
it "should set all pages to unpublic if it gets set to unpublic" do
page = create(:alchemy_page, language: language)
@other_page = create(:alchemy_page, language: language)
language.update_attributes(public: false)
language.update(public: false)
language.reload; page.reload; @other_page.reload
expect([page.public?, @other_page.public?]).to eq([false, false])
end
Expand Down
4 changes: 2 additions & 2 deletions spec/models/alchemy/page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -327,14 +327,14 @@ module Alchemy

it "all elements not allowed on this page should be trashed" do
expect(news_page.trashed_elements).to be_empty
news_page.update_attributes(page_layout: 'standard')
news_page.update(page_layout: 'standard')
trashed = news_page.trashed_elements.pluck(:name)
expect(trashed).to eq(['news'])
expect(trashed).to_not include('article', 'header')
end

it "should autogenerate elements" do
news_page.update_attributes(page_layout: 'contact')
news_page.update(page_layout: 'contact')
expect(news_page.elements.pluck(:name)).to include('contactform')
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/models/alchemy/picture_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ module Alchemy
let(:picture) { create :alchemy_picture }

before do
essence_picture.update_attributes(picture_id: picture.id)
essence_picture.update_columns(picture_id: picture.id)
end

it "should raise error message" do
Expand Down