<commit_before># encoding: utf-8
require 'spec_helper'

describe "Variants", type: :feature do
  stub_authorization!

  let(:product) { create(:product_with_option_types, price: "1.99", cost_price: "1.00", weight: "2.5", height: "3.0", width: "1.0", depth: "1.5") }

  context "creating a new variant" do
    it "should allow an admin to create a new variant" do
      product.options.each do |option|
        create(:option_value, option_type: option.option_type)
      end

      visit spree.admin_path
      click_nav "Products"
      within_row(1) { click_icon :edit }
      click_link "Variants"
      click_on "New Variant"
      expect(page).to have_field('variant_price', with: "1.99")
      expect(page).to have_field('variant_cost_price', with: "1.00")
      expect(page).to have_field('variant_weight', with: "2.50")
      expect(page).to have_field('variant_height', with: "3.00")
      expect(page).to have_field('variant_width', with: "1.00")
      expect(page).to have_field('variant_depth', with: "1.50")
      expect(page).to have_select('variant[tax_category_id]')
    end
  end

  context "listing variants" do
    context "currency displaying" do
      context "using Russian Rubles" do
        before do
          Spree::Config[:currency] = "RUB"
        end

        let!(:variant) do
          create(:variant, product: product, price: 19.99)
        end

        # Regression test for https://github.com/spree/spree/issues/2737
        context "uses руб as the currency symbol" do
          it "on the products listing page" do
            visit spree.admin_product_variants_path(product)
            within_row(1) { expect(page).to have_content("19.99 ₽") }
          end
        end
      end
    end
  end
end<commit_msg>Add spec to test option value input appears when editing variants<commit_after># encoding: utf-8
require 'spec_helper'

describe "Variants", type: :feature do
  stub_authorization!

  let(:product) { create(:product_with_option_types, price: "1.99", cost_price: "1.00", weight: "2.5", height: "3.0", width: "1.0", depth: "1.5") }

  context "creating a new variant" do
    it "should allow an admin to create a new variant" do
      product.options.each do |option|
        create(:option_value, option_type: option.option_type)
      end

      visit spree.admin_path
      click_nav "Products"
      within_row(1) { click_icon :edit }
      click_link "Variants"
      click_on "New Variant"
      expect(page).to have_field('variant_price', with: "1.99")
      expect(page).to have_field('variant_cost_price', with: "1.00")
      expect(page).to have_field('variant_weight', with: "2.50")
      expect(page).to have_field('variant_height', with: "3.00")
      expect(page).to have_field('variant_width', with: "1.00")
      expect(page).to have_field('variant_depth', with: "1.50")
      expect(page).to have_select('variant[tax_category_id]')
    end
  end

  context "listing variants" do
    context "currency displaying" do
      context "using Russian Rubles" do
        before do
          Spree::Config[:currency] = "RUB"
        end

        let!(:variant) do
          create(:variant, product: product, price: 19.99)
        end

        # Regression test for https://github.com/spree/spree/issues/2737
        context "uses руб as the currency symbol" do
          it "on the products listing page" do
            visit spree.admin_product_variants_path(product)
            within_row(1) { expect(page).to have_content("19.99 ₽") }
          end
        end
      end
    end
  end

  context "editing existent variant" do
    let!(:variant) { create(:variant, product: product) }

    context "if product has an option type" do
      let!(:option_type) { create(:option_type) }
      let!(:option_value) { create(:option_value, option_type: option_type) }

      before do
        product.option_types << option_type
        variant.option_values << option_value
      end

      it "page has a field for editing the option value", js: true do
        visit spree.edit_admin_product_variant_path(product, variant)
        expect(page).to have_css("label", text: option_type.presentation)
        expect(page).to have_css(".select2-chosen", text: option_value.presentation)
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.11702626641651032, 'fraction_numerical': 0.02227954971857411, 'mean_word_length': 2.9674418604651165, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6810731', 'n_tokens_mistral': 1380, 'n_tokens_neox': 1320, 'n_words': 358}