Fix Rails/Pluck Rubocops

This commit is contained in:
zanetagebka
2024-06-06 15:29:48 +02:00
parent f7500bba30
commit c456e649b2
16 changed files with 38 additions and 57 deletions

View File

@@ -222,7 +222,7 @@ module Api
it "loads taxons for distributed products in the order cycle" do
api_get :taxons, id: order_cycle.id, distributor: distributor.id
taxons = json_response.map{ |taxon| taxon['name'] }
taxons = json_response.pluck('name')
expect(json_response.length).to be 2
expect(taxons).to include taxon1.name, taxon2.name
@@ -233,7 +233,7 @@ module Api
it "loads properties for distributed products in the order cycle" do
api_get :properties, id: order_cycle.id, distributor: distributor.id
properties = json_response.map{ |property| property['name'] }
properties = json_response.pluck('name')
expect(json_response.length).to be 2
expect(properties).to include property1.presentation, property2.presentation
@@ -248,7 +248,7 @@ module Api
it "loads producer properties for distributed products in the order cycle" do
api_get :properties, id: order_cycle.id, distributor: distributor.id
properties = json_response.map{ |property| property['name'] }
properties = json_response.pluck('name')
expect(json_response.length).to be 3
expect(properties).to include property1.presentation, property2.presentation,
@@ -301,7 +301,7 @@ module Api
private
def product_ids
json_response.map{ |product| product['id'] }
json_response.pluck('id')
end
end
end

View File

@@ -146,8 +146,8 @@ module Api
as: :json
expect(json_response['orders']
.map{ |o| o[:id] }).to eq serialized_orders([order2, order3, order1, order4])
.map{ |o| o["id"] }
.pluck(:id)).to eq serialized_orders([order2, order3, order1, order4])
.pluck("id")
end
context "with an order without billing address" do
@@ -161,19 +161,16 @@ module Api
as: :json
expect(json_response['orders']
.map{ |o| o[:id] }).to match_array serialized_orders([order2, order3, order1, order4,
order7])
.map{ |o|
o["id"]
}
.pluck(:id)).to match_array serialized_orders([order2, order3, order1, order4,
order7]).pluck("id")
end
it 'can sort orders by bill_address.lastname' do
get :index, params: { q: { s: 'bill_address_lastname ASC' } },
as: :json
expect(json_response['orders']
.map{ |o| o[:id] }).to eq serialized_orders([order2, order3, order1, order4, order7])
.map{ |o| o["id"] }
.pluck(:id)).to eq serialized_orders([order2, order3, order1, order4, order7])
.pluck("id")
end
end
end

View File

@@ -295,6 +295,6 @@ RSpec.describe Api::V0::ProductsController, type: :controller do
end
def returned_product_ids
json_response['products'].map{ |obj| obj['id'] }
json_response['products'].pluck('id')
end
end

View File

@@ -37,7 +37,7 @@ RSpec.describe Api::V0::ShopsController, type: :controller do
expect(json_response).not_to match hub.name
response_ids = json_response.map { |shop| shop['id'] }
response_ids = json_response.pluck('id')
expect(response_ids).to contain_exactly(closed_hub1.id, closed_hub2.id)
end
end

View File

@@ -17,7 +17,7 @@ module Api
it "gets all states" do
api_get :index
expect(json_response.first.symbolize_keys.keys).to include(*attributes)
expect(json_response.map { |state| state[:name] }).to include(state.name)
expect(json_response.pluck(:name)).to include(state.name)
end
context "pagination" do

View File

@@ -32,7 +32,7 @@ RSpec.describe Api::V0::TaxonsController do
it "gets all taxons" do
api_get :index
json_names = json_response.map { |taxon_data| taxon_data["name"] }
json_names = json_response.pluck("name")
expect(json_names).to include(taxon.name, taxon2.name)
end