mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-04-08 07:46:59 +00:00
Fix Rails/Pluck Rubocops
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user