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

Replace update_attributes with update #3334

Merged
merged 1 commit into from
Sep 19, 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
2 changes: 1 addition & 1 deletion api/app/controllers/spree/api/addresses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def update
authorize! :update, @order, order_token
find_address

if @order.update_attributes({ "#{@order_source}_attributes" => address_params })
if @order.update({ "#{@order_source}_attributes" => address_params })
@address = @order.send(@order_source)
respond_with(@address, default_template: :show)
else
Expand Down
2 changes: 1 addition & 1 deletion api/app/controllers/spree/api/credit_cards_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def index
end

def update
if @credit_card.update_attributes(credit_card_update_params)
if @credit_card.update(credit_card_update_params)
respond_with(@credit_card, default_template: :show)
else
invalid_resource!(@credit_card)
Expand Down
2 changes: 1 addition & 1 deletion api/app/controllers/spree/api/images_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def create

def update
@image = Spree::Image.accessible_by(current_ability, :update).find(params[:id])
@image.update_attributes(image_params)
@image.update(image_params)
respond_with(@image, default_template: :show)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def update
authorize! :update, inventory_unit.order

inventory_unit.transaction do
if inventory_unit.update_attributes(inventory_unit_params)
if inventory_unit.update(inventory_unit_params)
fire
render :show, status: 200
else
Expand Down
2 changes: 1 addition & 1 deletion api/app/controllers/spree/api/option_types_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def create

def update
@option_type = Spree::OptionType.accessible_by(current_ability, :update).find(params[:id])
if @option_type.update_attributes(option_type_params)
if @option_type.update(option_type_params)
render :show
else
invalid_resource!(@option_type)
Expand Down
2 changes: 1 addition & 1 deletion api/app/controllers/spree/api/option_values_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def create

def update
@option_value = scope.accessible_by(current_ability, :update).find(params[:id])
if @option_value.update_attributes(option_value_params)
if @option_value.update(option_value_params)
render :show
else
invalid_resource!(@option_value)
Expand Down
2 changes: 1 addition & 1 deletion api/app/controllers/spree/api/payments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def update
authorize! params[:action], @payment
if [email protected]?
render 'update_forbidden', status: 403
elsif @payment.update_attributes(payment_params)
elsif @payment.update(payment_params)
respond_with(@payment, default_template: :show)
else
invalid_resource!(@payment)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def create
def update
if @product_property
authorize! :update, @product_property
@product_property.update_attributes(product_property_params)
@product_property.update(product_property_params)
respond_with(@product_property, status: 200, default_template: :show)
else
invalid_resource!(@product_property)
Expand Down
2 changes: 1 addition & 1 deletion api/app/controllers/spree/api/properties_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def create
def update
if @property
authorize! :update, @property
@property.update_attributes(property_params)
@property.update(property_params)
respond_with(@property, status: 200, default_template: :show)
else
invalid_resource!(@property)
Expand Down
2 changes: 1 addition & 1 deletion api/app/controllers/spree/api/resource_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def create
def update
authorize! :update, @object

if @object.update_attributes(permitted_resource_params)
if @object.update(permitted_resource_params)
respond_with(@object, status: 200, default_template: :show)
else
invalid_resource!(@object)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def show

def update
@return_authorization = @order.return_authorizations.accessible_by(current_ability, :update).find(params[:id])
if @return_authorization.update_attributes(return_authorization_params)
if @return_authorization.update(return_authorization_params)
respond_with(@return_authorization, default_template: :show)
else
invalid_resource!(@return_authorization)
Expand Down
2 changes: 1 addition & 1 deletion api/app/controllers/spree/api/shipments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def find_shipment
end

def update_shipment
@shipment.update_attributes(shipment_params)
@shipment.update(shipment_params)
@shipment.reload
end

Expand Down
2 changes: 1 addition & 1 deletion api/app/controllers/spree/api/stock_items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def update
adjustment -= @stock_item.count_on_hand if params[:stock_item][:force]

Spree::StockItem.transaction do
if @stock_item.update_attributes(stock_item_params)
if @stock_item.update(stock_item_params)
adjust_stock_item_count_on_hand(adjustment)
respond_with(@stock_item, status: 200, default_template: :show)
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def create

def update
authorize! :update, stock_location
if stock_location.update_attributes(stock_location_params)
if stock_location.update(stock_location_params)
respond_with(stock_location, status: 200, default_template: :show)
else
invalid_resource!(stock_location)
Expand Down
2 changes: 1 addition & 1 deletion api/app/controllers/spree/api/stores_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def create

def update
authorize! :update, @store
if @store.update_attributes(store_params)
if @store.update(store_params)
respond_with(@store, status: 200, default_template: :show)
else
invalid_resource!(@store)
Expand Down
2 changes: 1 addition & 1 deletion api/app/controllers/spree/api/taxonomies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def create

def update
authorize! :update, taxonomy
if taxonomy.update_attributes(taxonomy_params)
if taxonomy.update(taxonomy_params)
respond_with(taxonomy, status: 200, default_template: :show)
else
invalid_resource!(taxonomy)
Expand Down
2 changes: 1 addition & 1 deletion api/app/controllers/spree/api/taxons_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def create

def update
authorize! :update, taxon
if taxon.update_attributes(taxon_params)
if taxon.update(taxon_params)
respond_with(taxon, status: 200, default_template: :show)
else
invalid_resource!(taxon)
Expand Down
2 changes: 1 addition & 1 deletion api/app/controllers/spree/api/variants_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def show

def update
@variant = scope.accessible_by(current_ability, :update).find(params[:id])
if @variant.update_attributes(variant_params)
if @variant.update(variant_params)
respond_with(@variant, status: 200, default_template: :show)
else
invalid_resource!(@product)
Expand Down
2 changes: 1 addition & 1 deletion api/app/controllers/spree/api/zones_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def show

def update
authorize! :update, zone
if zone.update_attributes(zone_params)
if zone.update(zone_params)
respond_with(zone, status: 200, default_template: :show)
else
invalid_resource!(zone)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module Spree
end

it "should touch the taxon" do
taxon.update_attributes(updated_at: Time.current - 10.seconds)
taxon.update(updated_at: Time.current - 10.seconds)
taxon_last_updated_at = taxon.updated_at
put spree.api_classifications_path, params: { taxon_id: taxon.id, product_id: last_product.id, position: 0 }
taxon.reload
Expand Down
6 changes: 3 additions & 3 deletions api/spec/requests/spree/api/orders_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ module Spree

context 'when an item does not track inventory' do
before do
order.line_items.first.variant.update_attributes!(track_inventory: false)
order.line_items.first.variant.update!(track_inventory: false)
end

it 'contains stock information on variant' do
Expand Down Expand Up @@ -547,15 +547,15 @@ module Spree
end

it "can add shipping address" do
order.update_attributes!(ship_address_id: nil)
order.update!(ship_address_id: nil)

expect {
put spree.api_order_path(order), params: { order: { ship_address_attributes: shipping_address } }
}.to change { order.reload.ship_address }.from(nil)
end

it "receives error message if trying to add shipping address with errors" do
order.update_attributes!(ship_address_id: nil)
order.update!(ship_address_id: nil)

shipping_address[:firstname] = ""

Expand Down
6 changes: 3 additions & 3 deletions api/spec/requests/spree/api/payments_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,22 +137,22 @@ module Spree
context "for a given payment" do
context "updating" do
it "can update" do
payment.update_attributes(state: 'pending')
payment.update(state: 'pending')
put spree.api_order_payment_path(order, payment), params: { payment: { amount: 2.01 } }
expect(response.status).to eq(200)
expect(payment.reload.amount).to eq(2.01)
end

context "update fails" do
it "returns a 422 status when the amount is invalid" do
payment.update_attributes(state: 'pending')
payment.update(state: 'pending')
put spree.api_order_payment_path(order, payment), params: { payment: { amount: 'invalid' } }
expect(response.status).to eq(422)
expect(json_response["error"]).to eq("Invalid resource. Please fix errors and try again.")
end

it "returns a 403 status when the payment is not pending" do
payment.update_attributes(state: 'completed')
payment.update(state: 'completed')
put spree.api_order_payment_path(order, payment), params: { payment: { amount: 2.01 } }
expect(response.status).to eq(403)
expect(json_response["error"]).to eq("This payment cannot be updated because it is completed.")
Expand Down
10 changes: 5 additions & 5 deletions api/spec/requests/spree/api/stock_items_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module Spree
end

it "cannot list stock items for an inactive stock location" do
stock_location.update_attributes!(active: false)
stock_location.update!(active: false)
get spree.api_stock_location_stock_items_path(stock_location)
expect(response).to be_not_found
end
Expand All @@ -39,7 +39,7 @@ module Spree
end

it "cannot see a stock item for an inactive stock location" do
stock_location.update_attributes!(active: false)
stock_location.update!(active: false)
get spree.api_stock_location_stock_item_path(stock_location, stock_item)
expect(response.status).to eq(404)
end
Expand Down Expand Up @@ -155,7 +155,7 @@ module Spree

context 'variant does not track inventory' do
before do
variant.update_attributes(track_inventory: false)
variant.update(track_inventory: false)
end

it "doesn't set the stock item's count_on_hand" do
Expand Down Expand Up @@ -221,7 +221,7 @@ module Spree

context 'not tracking inventory' do
before do
stock_item.variant.update_attributes(track_inventory: false)
stock_item.variant.update(track_inventory: false)
end

it "doesn't set the stock item's count_on_hand" do
Expand Down Expand Up @@ -279,7 +279,7 @@ module Spree

context 'not tracking inventory' do
before do
stock_item.variant.update_attributes(track_inventory: false)
stock_item.variant.update(track_inventory: false)
end

it "doesn't update the stock item's count_on_hand" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module Spree
end

it "cannot see inactive stock locations" do
stock_location.update_attributes!(active: false)
stock_location.update!(active: false)
get spree.api_stock_locations_path
expect(response).to be_successful
stock_locations = json_response['stock_locations'].map { |sl| sl['name'] }
Expand All @@ -37,7 +37,7 @@ module Spree
end

it "cannot see inactive stock locations" do
stock_location.update_attributes!(active: false)
stock_location.update!(active: false)
get spree.api_stock_location_path(stock_location)
expect(response).to be_not_found
end
Expand Down Expand Up @@ -84,7 +84,7 @@ module Spree
end

it "can see inactive stock locations" do
stock_location.update_attributes!(active: false)
stock_location.update!(active: false)
get spree.api_stock_locations_path
expect(response).to be_successful
stock_locations = json_response['stock_locations'].map { |sl| sl['name'] }
Expand Down Expand Up @@ -122,7 +122,7 @@ module Spree
end

it "can see inactive stock locations" do
stock_location.update_attributes!(active: false)
stock_location.update!(active: false)
get spree.api_stock_location_path(stock_location)
expect(response).to be_successful
expect(json_response['name']).to eq stock_location.name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def update
end
end

if @payment_method.update_attributes(attributes)
if @payment_method.update(attributes)
invoke_callbacks(:update, :after)
flash[:success] = t('spree.successfully_updated', resource: t('spree.payment_method'))
redirect_to edit_admin_payment_method_path(@payment_method)
Expand Down
2 changes: 1 addition & 1 deletion backend/app/controllers/spree/admin/products_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def update
end
end
invoke_callbacks(:update, :before)
if @object.update_attributes(permitted_resource_params)
if @object.update(permitted_resource_params)
invoke_callbacks(:update, :after)
flash[:success] = flash_message_for(@object, :successfully_updated)
respond_with(@object) do |format|
Expand Down
2 changes: 1 addition & 1 deletion backend/app/controllers/spree/admin/resource_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def edit

def update
invoke_callbacks(:update, :before)
if @object.update_attributes(permitted_resource_params)
if @object.update(permitted_resource_params)
invoke_callbacks(:update, :after)
respond_with(@object) do |format|
format.html do
Expand Down
4 changes: 2 additions & 2 deletions backend/app/controllers/spree/admin/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def create
end

def update
if @user.update_attributes(user_params)
if @user.update(user_params)
set_roles
set_stock_locations

Expand All @@ -55,7 +55,7 @@ def update

def addresses
if request.put?
if @user.update_attributes(user_params)
if @user.update(user_params)
flash.now[:success] = t('spree.account_updated')
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ module Admin

context "a return item has an inactive return authorization reason" do
before(:each) do
accepted_return_item.update_attributes(return_reason_id: inactive_rma_reason.id)
accepted_return_item.update(return_reason_id: inactive_rma_reason.id)
end

it "includes the inactive return authorization reason" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
before { allow(Spree::Order).to receive_message_chain(:includes, :find_by!) { order } }

it "updates + progresses the order" do
expect(order).to receive(:update_attributes) { true }
expect(order).to receive(:update) { true }
expect(order).to receive(:next) { false }
attributes = { order_id: order.number, order: { email: "" } }
put :update, params: attributes
Expand Down Expand Up @@ -109,7 +109,7 @@

context "not false guest checkout param" do
it "does not attempt to associate the user" do
allow(order).to receive_messages(update_attributes: true,
allow(order).to receive_messages(update: true,
next: false,
refresh_shipment_rates: true)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@
let(:updated_amount) { 300.0 }

context "the store credit has been partially used" do
before { store_credit.update_attributes(amount_used: 10.0) }
before { store_credit.update(amount_used: 10.0) }

context "the new amount is greater than the used amount" do
let(:updated_amount) { 11.0 }
Expand Down
Loading