Skip to content

Commit

Permalink
appease RubocopRails: Rails/ActiveRecordAliases
Browse files Browse the repository at this point in the history
> Use update instead of update_attributes.

OK.

Signed-off-by: Robb Kidd <rkidd@chef.io>
  • Loading branch information
robbkidd committed Jun 25, 2020
1 parent 961f89b commit 86fce0b
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/supermarket/app/controllers/cookbooks_controller.rb
Expand Up @@ -119,7 +119,7 @@ def download
def update
authorize! @cookbook, :manage_cookbook_urls?

@cookbook.update_attributes(cookbook_urls_params)
@cookbook.update(cookbook_urls_params)

if cookbook_urls_params.key?(:up_for_adoption)
if cookbook_urls_params[:up_for_adoption] == "true"
Expand Down Expand Up @@ -202,7 +202,7 @@ def deprecate
def undeprecate
authorize! @cookbook

@cookbook.update_attributes(deprecated: false, replacement: nil)
@cookbook.update(deprecated: false, replacement: nil)

redirect_to(
@cookbook,
Expand Down
2 changes: 1 addition & 1 deletion src/supermarket/app/controllers/profile_controller.rb
Expand Up @@ -7,7 +7,7 @@ class ProfileController < ApplicationController
# Update the current_user's profile
#
def update
if current_user.update_attributes(user_params)
if current_user.update(user_params)
redirect_to current_user, notice: t("profile.updated")
else
render "edit"
Expand Down
2 changes: 1 addition & 1 deletion src/supermarket/app/controllers/tools_controller.rb
Expand Up @@ -94,7 +94,7 @@ def update

authorize! @tool

if @tool.update_attributes(tool_params)
if @tool.update(tool_params)
key = if tool_params.key?(:up_for_adoption)
if tool_params[:up_for_adoption] == "true"
"adoption.up"
Expand Down
2 changes: 1 addition & 1 deletion src/supermarket/app/workers/oauth_token_refresh_worker.rb
Expand Up @@ -25,7 +25,7 @@ def perform(account_id)

refreshed_token = access_token.refresh!

account.update_attributes!(
account.update!(
oauth_token: refreshed_token.token,
oauth_expires: Time.zone.at(refreshed_token.expires_at),
oauth_refresh_token: refreshed_token.refresh_token
Expand Down
8 changes: 4 additions & 4 deletions src/supermarket/spec/controllers/cookbooks_controller_spec.rb
Expand Up @@ -172,8 +172,8 @@
end

it "works correctly with order" do
erlang.update_attributes(web_download_count: 10, api_download_count: 100)
ruby.update_attributes(web_download_count: 5, api_download_count: 101)
erlang.update(web_download_count: 10, api_download_count: 100)
ruby.update(web_download_count: 5, api_download_count: 101)

get :index, params: { order: "most_downloaded", platforms: %w{debian} }
expect(assigns[:cookbooks][0]).to eql(erlang)
Expand Down Expand Up @@ -209,8 +209,8 @@
end

it "works correctly with order" do
awesome_cookbook.update_attributes(web_download_count: 10, api_download_count: 100)
but_not_saucy.update_attributes(web_download_count: 5, api_download_count: 101)
awesome_cookbook.update(web_download_count: 10, api_download_count: 100)
but_not_saucy.update(web_download_count: 5, api_download_count: 101)

get :index, params: { order: "most_downloaded", badges: %w{partner} }
expect(assigns[:cookbooks][0]).to eql(awesome_cookbook)
Expand Down
Expand Up @@ -49,7 +49,7 @@
},
}

expect(fake_user).to receive(:update_attributes).with(attrs)
expect(fake_user).to receive(:update).with(attrs)
allow(controller).to receive(:current_user) { fake_user }

patch :update, params: { user: attributes_for(:user, attrs) }
Expand Down
2 changes: 1 addition & 1 deletion src/supermarket/spec/models/account_spec.rb
Expand Up @@ -44,7 +44,7 @@

[-0.1, 0, 12.5, 25, 26.1].each do |expiry|
create(:user).tap do |user|
user.chef_account.update_attributes!(
user.chef_account.update!(
oauth_expires: nowish + expiry.minutes
)
end
Expand Down
16 changes: 8 additions & 8 deletions src/supermarket/spec/models/cookbook_spec.rb
Expand Up @@ -744,32 +744,32 @@ def generate_params_versions(opts = {})
end

it 'orders by download_count descending when given "most_downloaded"' do
great.update_attributes(web_download_count: 1, api_download_count: 100)
cookbook.update_attributes(web_download_count: 5, api_download_count: 70)
great.update(web_download_count: 1, api_download_count: 100)
cookbook.update(web_download_count: 5, api_download_count: 70)

expect(Cookbook.ordered_by("most_downloaded").map(&:name))
.to eql(%w{great cookbook})
end

it 'orders by cookbook_followers_count when given "most_followed"' do
great.update_attributes(cookbook_followers_count: 100)
cookbook.update_attributes(cookbook_followers_count: 50)
great.update(cookbook_followers_count: 100)
cookbook.update(cookbook_followers_count: 50)

expect(Cookbook.ordered_by("most_followed").map(&:name))
.to eql(%w{great cookbook})
end

it "orders secondarily by id when cookbook follower counts are equal" do
great.update_attributes(cookbook_followers_count: 100)
cookbook.update_attributes(cookbook_followers_count: 100)
great.update(cookbook_followers_count: 100)
cookbook.update(cookbook_followers_count: 100)

expect(Cookbook.ordered_by("most_followed").map(&:name))
.to eql(%w{great cookbook})
end

it "orders secondarily by id when download counts are equal" do
great.update_attributes(web_download_count: 5, api_download_count: 100)
cookbook.update_attributes(web_download_count: 5, api_download_count: 100)
great.update(web_download_count: 5, api_download_count: 100)
cookbook.update(web_download_count: 5, api_download_count: 100)

expect(Cookbook.ordered_by("most_followed").map(&:name))
.to eql(%w{great cookbook})
Expand Down
2 changes: 1 addition & 1 deletion src/supermarket/spec/models/user_spec.rb
Expand Up @@ -113,7 +113,7 @@
it "returns the chef username for the user" do
user = create(:user)
account = user.accounts.for("chef_oauth2").first
account.update_attributes(username: "fanny")
account.update(username: "fanny")

expect(user.username).to eql("fanny")
end
Expand Down
Expand Up @@ -39,7 +39,7 @@

it "updates the account's OAuth tokens" do
account = create(:user).chef_account
account.update_attributes!(
account.update!(
oauth_token: ENV["VALID_OCID_OAUTH_TOKEN"],
oauth_refresh_token: ENV["VALID_OCID_REFRESH_TOKEN"]
)
Expand All @@ -63,7 +63,7 @@

it "fails quietly if the account's refresh token is bad" do
account = create(:user).chef_account
account.update_attributes!(oauth_refresh_token: "dorfle")
account.update!(oauth_refresh_token: "dorfle")

worker = OauthTokenRefreshWorker.new

Expand Down

0 comments on commit 86fce0b

Please sign in to comment.