Commit d8aa7e09 by ivan Lan

Add spec_output to Product & Series

parent a00700d7
......@@ -46,7 +46,12 @@ RSpec.describe "#{namespace}/products", type: :request, capture_examples: true,
consumes 'application/json'
response(200, description: 'successful') do
it {
expect(JSON.parse(response.body)['series'].count).to eq(@product_1.series.count), "correct product's series"
body = JSON.parse(response.body)
expect(body['series'].count).to eq(@product_1.series.count), "correct product's series"
# check spec_output
expect(body['spec']).to eq(
[{"key"=>"大小", "val"=>["S", "M", "L"]}, {"key"=>"颜色", "val"=>["黑色", "红色", "白色"]}]
)
}
end
end
......
json.extract! product, :id, :title, :status, :status_zh,
:need_express, :need_time_attr,
:cover_image, :banners, :spec, :detail, :meta
:cover_image, :banners, :detail, :meta
json.spec product.spec_output
# TODO: NOTE: catalog_list is only vaild in the template example
json.catalog_list product.catalog_list if product.respond_to?(:catalog_list)
json.default_series product.default_series, partial: 'shotengai/share/series_simple', as: :series
......
json.extract! series, :id, :title, :original_price, :price,
:stock, :spec, :cover_image, :banners, :meta, :detail,
:shotengai_product_id
\ No newline at end of file
:stock, :cover_image, :banners, :meta, :detail,
:shotengai_product_id
json.spec series.spec_output
json.extract! series, :id, :title, :original_price, :price,
:stock, :spec, :cover_image, :meta, :shotengai_product_id
\ No newline at end of file
:stock, :cover_image, :meta, :shotengai_product_id
json.spec series.spec_output
\ No newline at end of file
......@@ -71,6 +71,15 @@ module Shotengai
super || {}
end
def spec_output
spec.map { |key, val|
{
key: key,
val: val,
}
}
end
class << self
def series_class
Shotengai::Series
......
......@@ -90,6 +90,15 @@ module Shotengai
def meta
super || {}
end
def spec_output
spec.map { |key, val|
{
key: key,
val: val,
}
}
end
private
# spec 字段
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment