From 86fce0be25c97ef25590ae720785780f5a1cd0cb Mon Sep 17 00:00:00 2001 From: Robb Kidd Date: Wed, 24 Jun 2020 18:09:09 -0400 Subject: [PATCH] appease RubocopRails: Rails/ActiveRecordAliases > Use update instead of update_attributes. OK. Signed-off-by: Robb Kidd --- .../app/controllers/cookbooks_controller.rb | 4 ++-- .../app/controllers/profile_controller.rb | 2 +- .../app/controllers/tools_controller.rb | 2 +- .../app/workers/oauth_token_refresh_worker.rb | 2 +- .../controllers/cookbooks_controller_spec.rb | 8 ++++---- .../spec/controllers/profile_controller_spec.rb | 2 +- src/supermarket/spec/models/account_spec.rb | 2 +- src/supermarket/spec/models/cookbook_spec.rb | 16 ++++++++-------- src/supermarket/spec/models/user_spec.rb | 2 +- .../workers/oauth_token_refresh_worker_spec.rb | 4 ++-- 10 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/supermarket/app/controllers/cookbooks_controller.rb b/src/supermarket/app/controllers/cookbooks_controller.rb index f64d02496a..ac6fe24151 100644 --- a/src/supermarket/app/controllers/cookbooks_controller.rb +++ b/src/supermarket/app/controllers/cookbooks_controller.rb @@ -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" @@ -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, diff --git a/src/supermarket/app/controllers/profile_controller.rb b/src/supermarket/app/controllers/profile_controller.rb index 28a048a13c..bb972867af 100644 --- a/src/supermarket/app/controllers/profile_controller.rb +++ b/src/supermarket/app/controllers/profile_controller.rb @@ -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" diff --git a/src/supermarket/app/controllers/tools_controller.rb b/src/supermarket/app/controllers/tools_controller.rb index 809a459933..45d1dcc2c2 100644 --- a/src/supermarket/app/controllers/tools_controller.rb +++ b/src/supermarket/app/controllers/tools_controller.rb @@ -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" diff --git a/src/supermarket/app/workers/oauth_token_refresh_worker.rb b/src/supermarket/app/workers/oauth_token_refresh_worker.rb index c18459f214..dd4aafbb33 100644 --- a/src/supermarket/app/workers/oauth_token_refresh_worker.rb +++ b/src/supermarket/app/workers/oauth_token_refresh_worker.rb @@ -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 diff --git a/src/supermarket/spec/controllers/cookbooks_controller_spec.rb b/src/supermarket/spec/controllers/cookbooks_controller_spec.rb index 8b8fd704a0..b982eb0546 100644 --- a/src/supermarket/spec/controllers/cookbooks_controller_spec.rb +++ b/src/supermarket/spec/controllers/cookbooks_controller_spec.rb @@ -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) @@ -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) diff --git a/src/supermarket/spec/controllers/profile_controller_spec.rb b/src/supermarket/spec/controllers/profile_controller_spec.rb index cc983537ce..f0a438800d 100644 --- a/src/supermarket/spec/controllers/profile_controller_spec.rb +++ b/src/supermarket/spec/controllers/profile_controller_spec.rb @@ -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) } diff --git a/src/supermarket/spec/models/account_spec.rb b/src/supermarket/spec/models/account_spec.rb index 091221d150..cf75c3f267 100644 --- a/src/supermarket/spec/models/account_spec.rb +++ b/src/supermarket/spec/models/account_spec.rb @@ -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 diff --git a/src/supermarket/spec/models/cookbook_spec.rb b/src/supermarket/spec/models/cookbook_spec.rb index 5560a1b96e..7786fb3c8d 100644 --- a/src/supermarket/spec/models/cookbook_spec.rb +++ b/src/supermarket/spec/models/cookbook_spec.rb @@ -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}) diff --git a/src/supermarket/spec/models/user_spec.rb b/src/supermarket/spec/models/user_spec.rb index 0c9d3e6a0d..a88493f33a 100644 --- a/src/supermarket/spec/models/user_spec.rb +++ b/src/supermarket/spec/models/user_spec.rb @@ -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 diff --git a/src/supermarket/spec/workers/oauth_token_refresh_worker_spec.rb b/src/supermarket/spec/workers/oauth_token_refresh_worker_spec.rb index de9a562606..25436fe672 100644 --- a/src/supermarket/spec/workers/oauth_token_refresh_worker_spec.rb +++ b/src/supermarket/spec/workers/oauth_token_refresh_worker_spec.rb @@ -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"] ) @@ -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