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, ...@@ -46,7 +46,12 @@ RSpec.describe "#{namespace}/products", type: :request, capture_examples: true,
consumes 'application/json' consumes 'application/json'
response(200, description: 'successful') do response(200, description: 'successful') do
it { 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
end end
......
json.extract! product, :id, :title, :status, :status_zh, json.extract! product, :id, :title, :status, :status_zh,
:need_express, :need_time_attr, :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 # TODO: NOTE: catalog_list is only vaild in the template example
json.catalog_list product.catalog_list if product.respond_to?(:catalog_list) 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.default_series product.default_series, partial: 'shotengai/share/series_simple', as: :series
......
json.extract! series, :id, :title, :original_price, :price, json.extract! series, :id, :title, :original_price, :price,
:stock, :spec, :cover_image, :banners, :meta, :detail, :stock, :cover_image, :banners, :meta, :detail,
:shotengai_product_id :shotengai_product_id
\ No newline at end of file json.spec series.spec_output
json.extract! series, :id, :title, :original_price, :price, json.extract! series, :id, :title, :original_price, :price,
:stock, :spec, :cover_image, :meta, :shotengai_product_id :stock, :cover_image, :meta, :shotengai_product_id
\ No newline at end of file json.spec series.spec_output
\ No newline at end of file
...@@ -71,6 +71,15 @@ module Shotengai ...@@ -71,6 +71,15 @@ module Shotengai
super || {} super || {}
end end
def spec_output
spec.map { |key, val|
{
key: key,
val: val,
}
}
end
class << self class << self
def series_class def series_class
Shotengai::Series Shotengai::Series
......
...@@ -90,6 +90,15 @@ module Shotengai ...@@ -90,6 +90,15 @@ module Shotengai
def meta def meta
super || {} super || {}
end end
def spec_output
spec.map { |key, val|
{
key: key,
val: val,
}
}
end
private private
# spec 字段 # 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