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

Preparations for Rails 5.2 #2465

Merged
merged 5 commits into from
Jan 17, 2018
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
18 changes: 9 additions & 9 deletions api/spec/controllers/spree/api/resource_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ def permitted_widget_attributes

it "returns no widgets" do
get :index, params: { token: user.spree_api_key }, as: :json
expect(response).to be_success
expect(response).to be_successful
expect(json_response['widgets']).to be_blank
end

context "it has authorization to read widgets" do
it "returns widgets" do
get :index, params: { token: admin_user.spree_api_key }, as: :json
expect(response).to be_success
expect(response).to be_successful
expect(json_response['widgets']).to include(hash_including(
'name' => 'a widget',
'position' => 1
Expand All @@ -70,26 +70,26 @@ def permitted_widget_attributes

it "returns both widgets from comma separated string" do
get :index, params: { ids: [widget.id, widget2.id].join(','), token: admin_user.spree_api_key }, as: :json
expect(response).to be_success
expect(response).to be_successful
expect(json_response['widgets'].size).to eq 2
end

it "returns both widgets from multiple arguments" do
get :index, params: { ids: [widget.id, widget2.id], token: admin_user.spree_api_key }, as: :json
expect(response).to be_success
expect(response).to be_successful
expect(json_response['widgets'].size).to eq 2
end

it "returns one requested widgets" do
get :index, params: { ids: widget2.id.to_s, token: admin_user.spree_api_key }, as: :json
expect(response).to be_success
expect(response).to be_successful
expect(json_response['widgets'].size).to eq 1
expect(json_response['widgets'][0]['id']).to eq widget2.id
end

it "returns no widgets if empty" do
get :index, params: { ids: '', token: admin_user.spree_api_key }, as: :json
expect(response).to be_success
expect(response).to be_successful
expect(json_response['widgets']).to be_empty
end
end
Expand All @@ -107,7 +107,7 @@ def permitted_widget_attributes
context "it has authorization read widgets" do
it "returns widget details" do
get :show, params: { id: widget.to_param, token: admin_user.spree_api_key }, as: :json
expect(response).to be_success
expect(response).to be_successful
expect(json_response['name']).to eq 'a widget'
end
end
Expand All @@ -122,7 +122,7 @@ def permitted_widget_attributes
context "it is allowed to view a new widget" do
it "can learn how to create a new widget" do
get :new, params: { token: admin_user.spree_api_key }, as: :json
expect(response).to be_success
expect(response).to be_successful
expect(json_response["attributes"]).to eq(['name'])
end
end
Expand Down Expand Up @@ -159,7 +159,7 @@ def permitted_widget_attributes
context "it is authorized to update widgets" do
it "can update a widget" do
put :update, params: { id: widget.to_param, widget: { name: "another widget" }, token: admin_user.spree_api_key }, as: :json
expect(response).to be_success
expect(response).to be_successful
expect(json_response['name']).to eq 'another widget'
expect(widget.reload.name).to eq 'another widget'
end
Expand Down
4 changes: 2 additions & 2 deletions api/spec/requests/spree/api/config_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ module Spree

it "returns Spree::Money settings" do
get '/api/config/money'
expect(response).to be_success
expect(response).to be_successful
expect(json_response["symbol"]).to eq("$")
end

it "returns some configuration settings" do
get '/api/config'
expect(response).to be_success
expect(response).to be_successful
expect(json_response["default_country_iso"]).to eq("US")
expect(json_response["default_country_id"]).to eq(default_country.id)
end
Expand Down
12 changes: 6 additions & 6 deletions api/spec/requests/spree/api/orders_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,20 @@ module Spree

it "does not include unpermitted params, or allow overriding the user" do
subject
expect(response).to be_success
expect(response).to be_successful
order = Spree::Order.last
expect(order.user).to eq current_api_user
expect(order.email).to eq target_user.email
end

it { is_expected.to be_success }
it { is_expected.to be_successful }

context 'creating payment' do
let(:attributes) { super().merge(payments_attributes: [{ payment_method_id: payment_method.id }]) }

context "with allowed payment method" do
let!(:payment_method) { create(:check_payment_method, name: "allowed" ) }
it { is_expected.to be_success }
it { is_expected.to be_successful }
it "creates a payment" do
expect {
subject
Expand Down Expand Up @@ -91,7 +91,7 @@ module Spree
expect(order.created_at).to eq date_override
end

it { is_expected.to be_success }
it { is_expected.to be_successful }
end

context 'when the line items have custom attributes' do
Expand Down Expand Up @@ -126,7 +126,7 @@ module Spree
}.to change { order.reload.email }.to("foo@foobar.com")
end

it { is_expected.to be_success }
it { is_expected.to be_successful }

it "does not associate users" do
expect {
Expand All @@ -145,7 +145,7 @@ module Spree

context "with allowed payment method" do
let!(:payment_method) { create(:check_payment_method, name: "allowed" ) }
it { is_expected.to be_success }
it { is_expected.to be_successful }
it "creates a payment" do
expect {
subject
Expand Down
2 changes: 1 addition & 1 deletion api/spec/requests/spree/api/shipments_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@

it "returns the correct message" do
subject
expect(response).to be_success
expect(response).to be_successful
expect(parsed_response["success"]).to be true
expect(parsed_response["message"]).to eq("Variants successfully transferred")
end
Expand Down
2 changes: 1 addition & 1 deletion api/spec/requests/spree/api/stock_items_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module Spree
describe "#index" do
it "can list stock items for an active stock location" do
get spree.api_stock_location_stock_items_path(stock_location)
expect(response).to be_success
expect(response).to be_successful
expect(json_response['stock_items'].first).to have_attributes(attributes)
expect(json_response['stock_items'].first['variant']['sku']).to match /\ASKU-\d+\z/
end
Expand Down
14 changes: 7 additions & 7 deletions api/spec/requests/spree/api/stock_locations_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ module Spree
describe "#index" do
it "can see active stock locations" do
get spree.api_stock_locations_path
expect(response).to be_success
expect(response).to be_successful
stock_locations = json_response['stock_locations'].map { |sl| sl['name'] }
expect(stock_locations).to include stock_location.name
end

it "cannot see inactive stock locations" do
stock_location.update_attributes!(active: false)
get spree.api_stock_locations_path
expect(response).to be_success
expect(response).to be_successful
stock_locations = json_response['stock_locations'].map { |sl| sl['name'] }
expect(stock_locations).not_to include stock_location.name
end
Expand All @@ -31,7 +31,7 @@ module Spree
describe "#show" do
it "can see active stock locations" do
get spree.api_stock_location_path(stock_location)
expect(response).to be_success
expect(response).to be_successful
expect(json_response['name']).to eq stock_location.name
end

Expand Down Expand Up @@ -77,15 +77,15 @@ module Spree
describe "#index" do
it "can see active stock locations" do
get spree.api_stock_locations_path
expect(response).to be_success
expect(response).to be_successful
stock_locations = json_response['stock_locations'].map { |sl| sl['name'] }
expect(stock_locations).to include stock_location.name
end

it "can see inactive stock locations" do
stock_location.update_attributes!(active: false)
get spree.api_stock_locations_path
expect(response).to be_success
expect(response).to be_successful
stock_locations = json_response['stock_locations'].map { |sl| sl['name'] }
expect(stock_locations).to include stock_location.name
end
Expand Down Expand Up @@ -116,14 +116,14 @@ module Spree
describe "#show" do
it "can see active stock locations" do
get spree.api_stock_location_path(stock_location)
expect(response).to be_success
expect(response).to be_successful
expect(json_response['name']).to eq stock_location.name
end

it "can see inactive stock locations" do
stock_location.update_attributes!(active: false)
get spree.api_stock_location_path(stock_location)
expect(response).to be_success
expect(response).to be_successful
expect(json_response['name']).to eq stock_location.name
end
end
Expand Down
4 changes: 2 additions & 2 deletions api/spec/requests/spree/api/taxons_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,11 @@ module Spree

it "handles exclude_data correctly" do
get spree.api_taxon_products_path, params: { id: taxon.id, simple: true }
expect(response).to be_success
expect(response).to be_successful
simple_response = json_response

get spree.api_taxon_products_path, params: { id: taxon.id }
expect(response).to be_success
expect(response).to be_successful
full_response = json_response

expect(simple_response["products"][0]["description"]).to be_nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class GatewayWithPassword < PaymentMethod
second_method.move_to_top
end

it { is_expected.to be_success }
it { is_expected.to be_successful }
it { is_expected.to render_template "index" }

it "respects the order of payment methods by position" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

subject { get :index, params: { product_id: product.slug } }

it { is_expected.to be_success }
it { is_expected.to be_successful }

it 'assigns usable instance variables' do
subject
Expand All @@ -28,7 +28,7 @@

subject { get :index, params: { product_id: product.slug, variant_id: variant.id } }

it { is_expected.to be_success }
it { is_expected.to be_successful }

it 'assigns usable instance variables' do
subject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

it "can create a promotion rule of a valid type" do
get :index, params: { promotion_id: promotion.id, format: 'csv' }
expect(response).to be_success
expect(response).to be_successful
parsed = CSV.parse(response.body, headers: true)
expect(parsed.entries.map(&:to_h)).to eq([{ "Code" => code1.value }, { "Code" => code2.value }, { "Code" => code3.value }])
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

shared_examples 'sales total report' do
it 'should respond with success' do
expect(response).to be_success
expect(response).to be_successful
end

it 'should set search to be a ransack search' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def model_class

it 'succeeds' do
subject
expect(response).to be_success
expect(response).to be_successful
end
end

Expand All @@ -63,7 +63,7 @@ def model_class

it 'succeeds' do
subject
expect(response).to be_success
expect(response).to be_successful
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
shared_examples_for 'product search' do
it 'should respond with http success' do
subject
expect(response).to be_success
expect(response).to be_successful
end

it 'should set the Surrogate-Control header' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module Admin

it "can create a new stock location" do
get :new
expect(response).to be_success
expect(response).to be_successful
end
end

Expand All @@ -34,7 +34,7 @@ module Admin

it "can create a new stock location" do
get :new
expect(response).to be_success
expect(response).to be_successful
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

it 'can visit index' do
post :index
expect(response).to be_success
expect(response).to be_successful
end

it "allows admins to update a user's API key" do
Expand Down
2 changes: 1 addition & 1 deletion core/app/models/spree/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def self.find_by_param!(value)
scope :by_store, ->(store) { where(store_id: store.id) }

# shows completed orders first, by their completed_at date, then uncompleted orders by their created_at
scope :reverse_chronological, -> { order('spree_orders.completed_at IS NULL', completed_at: :desc, created_at: :desc) }
scope :reverse_chronological, -> { order(Arel.sql('spree_orders.completed_at IS NULL'), completed_at: :desc, created_at: :desc) }

def self.by_customer(customer)
joins(:user).where("#{Spree.user_class.table_name}.email" => customer)
Expand Down
2 changes: 1 addition & 1 deletion core/app/models/spree/price.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Price < Spree::Base
validates :currency, inclusion: { in: ::Money::Currency.all.map(&:iso_code), message: :invalid_code }
validates :country, presence: true, unless: -> { for_any_country? }

scope :currently_valid, -> { order("country_iso IS NULL, updated_at DESC, id DESC") }
scope :currently_valid, -> { order(Arel.sql("country_iso IS NULL, updated_at DESC, id DESC")) }
scope :for_master, -> { joins(:variant).where(spree_variants: { is_master: true }) }
scope :for_variant, -> { joins(:variant).where(spree_variants: { is_master: false }) }
scope :for_any_country, -> { where(country: nil) }
Expand Down
4 changes: 2 additions & 2 deletions core/app/models/spree/product/scopes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def self.property_conditions(property)
end

scope :with_master_price, -> do
joins(:master).where(Spree::Price.where(Spree::Variant.arel_table[:id].eq(Spree::Price.arel_table[:variant_id])).exists)
joins(:master).where(Spree::Price.where(Spree::Variant.arel_table[:id].eq(Spree::Price.arel_table[:variant_id])).arel.exists)
end

# Can't use add_search_scope for this as it needs a default argument
Expand All @@ -189,7 +189,7 @@ def self.with_variant_sku_cont(sku)
sku_match = "%#{sku}%"
variant_table = Spree::Variant.arel_table
subquery = Spree::Variant.where(variant_table[:sku].matches(sku_match).and(variant_table[:product_id].eq(arel_table[:id])))
where(subquery.exists)
where(subquery.arel.exists)
end

def self.distinct_by_product_ids(sort_order = nil)
Expand Down
2 changes: 1 addition & 1 deletion core/app/models/spree/stock_location.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class InvalidMovementError < StandardError; end
scope :active, -> { where(active: true) }
scope :order_default, -> { order(default: :desc, name: :asc) }

after_create :create_stock_items, if: "self.propagate_all_variants?"
after_create :create_stock_items, if: :propagate_all_variants?
after_save :ensure_one_default

def state_text
Expand Down
2 changes: 1 addition & 1 deletion core/app/models/spree/taxonomy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Taxonomy < Spree::Base

after_save :set_name

default_scope -> { order(:position) }
default_scope -> { order(position: :asc) }

private

Expand Down
2 changes: 1 addition & 1 deletion core/app/models/spree/variant/scopes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Spree
class Variant < Spree::Base
# FIXME: WARNING tested only under sqlite and postgresql
scope :descend_by_popularity, -> {
order("COALESCE((SELECT COUNT(*) FROM #{Spree::LineItem.quoted_table_name} GROUP BY #{Spree::LineItem.quoted_table_name}.variant_id HAVING #{Spree::LineItem.quoted_table_name}.variant_id = #{Spree::Variant.quoted_table_name}.id), 0) DESC")
order(Arel.sql("COALESCE((SELECT COUNT(*) FROM #{Spree::LineItem.quoted_table_name} GROUP BY #{Spree::LineItem.quoted_table_name}.variant_id HAVING #{Spree::LineItem.quoted_table_name}.variant_id = #{Spree::Variant.quoted_table_name}.id), 0) DESC"))
}

class << self
Expand Down
Loading