Skip to content

Commit

Permalink
Merge pull request #7714 from spark-solutions/3-1-stable
Browse files Browse the repository at this point in the history
Localized fields for products/_form.html.erb to prevent incorrectly parsed decimal values (3-1-stable)
  • Loading branch information
damianlegawiec committed Dec 1, 2016
2 parents 92e02a1 + fc64997 commit e2cf4f0
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 4 deletions.
8 changes: 4 additions & 4 deletions backend/app/views/spree/admin/products/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -111,28 +111,28 @@
<div class="col-md-6">
<div id="shipping_specs_weight_field" data-hook="admin_product_form_weight" class="form-group">
<%= f.label :weight, Spree.t(:weight) %>
<%= f.text_field :weight, size: 4, class: 'form-control' %>
<%= f.text_field :weight, value: number_with_precision(@product.weight, precision: 2), size: 4, class: 'form-control' %>
</div>
</div>

<div class="col-md-6">
<div id="shipping_specs_height_field" data-hook="admin_product_form_height" class="form-group">
<%= f.label :height, Spree.t(:height) %>
<%= f.text_field :height, size: 4, class: 'form-control' %>
<%= f.text_field :height, value: number_with_precision(@product.height, precision: 2), size: 4, class: 'form-control' %>
</div>
</div>

<div class="col-md-6">
<div id="shipping_specs_width_field" data-hook="admin_product_form_width" class="form-group">
<%= f.label :width, Spree.t(:width) %>
<%= f.text_field :width, size: 4, class: 'form-control' %>
<%= f.text_field :width, value: number_with_precision(@product.width, precision: 2), size: 4, class: 'form-control' %>
</div>
</div>

<div class="col-md-6">
<div id="shipping_specs_depth_field" data-hook="admin_product_form_depth" class="form-group">
<%= f.label :depth, Spree.t(:depth) %>
<%= f.text_field :depth, size: 4, class: 'form-control' %>
<%= f.text_field :depth, value: number_with_precision(@product.depth, precision: 2), size: 4, class: 'form-control' %>
</div>
</div>
</div>
Expand Down
49 changes: 49 additions & 0 deletions backend/spec/features/admin/products/products_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,55 @@ def build_option_type_with_values(name, values)
expect(first('input[type=text]').value).to eq('baseball_cap_color')
end
end

context "using a locale with a different decimal format" do
before do
# change English locale’s separator and delimiter to match 19,99 format
I18n.backend.store_translations(
:en,
number: {
currency: {
format: {
separator: ",",
delimiter: "."
}
},
format: {
separator: ",",
delimiter: "."
}
}
)
end

after do
# revert changes to English locale
I18n.backend.store_translations(
:en,
number: {
currency: {
format: {
separator: ".",
delimiter: ","
}
},
format: {
separator: ".",
delimiter: ","
}
}
)
end

it 'should parse correctly decimal values like weight' do
visit spree.admin_product_path(product)
fill_in 'product_weight', with: '1'
click_button 'Update'
weight_prev = find('#product_weight').value
click_button 'Update'
expect(find('#product_weight').value).to eq(weight_prev)
end
end
end

context 'deleting a product', :js => true do
Expand Down

0 comments on commit e2cf4f0

Please sign in to comment.