<commit_before>require 'spec_helper'

module Spree
  describe Api::VariantsController do
    render_views

    let!(:product) { create(:product) }
    let!(:variant) do
      variant = product.master
      variant.option_values << create(:option_value)
      variant
    end

    let!(:base_attributes) { [:id, :name, :sku, :price, :weight, :height, :width, :depth, :is_master, :cost_price, :slug, :description] }
    let!(:show_attributes) { base_attributes.dup.push(:in_stock, :display_price) }
    let!(:new_attributes) { base_attributes }

    before do
      stub_authentication!
    end

    it "can see a paginated list of variants" do
      api_get :index
      first_variant = json_response["variants"].first
      first_variant.should have_attributes(show_attributes)
      first_variant["stock_items"].should be_present
      json_response["count"].should == 1
      json_response["current_page"].should == 1
      json_response["pages"].should == 1
    end

    it 'can control the page size through a parameter' do
      create(:variant)
      api_get :index, :per_page => 1
      json_response['count'].should == 1
      json_response['current_page'].should == 1
      json_response['pages'].should == 3<commit_msg>Use Api::ApiHelpers.variant_attributes in VariantsController spec<commit_after>require 'spec_helper'

module Spree
  describe Api::VariantsController do
    render_views

    let!(:product) { create(:product) }
    let!(:variant) do
      variant = product.master
      variant.option_values << create(:option_value)
      variant
    end

    let!(:base_attributes) { Api::ApiHelpers.variant_attributes }
    let!(:show_attributes) { base_attributes.dup.push(:in_stock, :display_price) }
    let!(:new_attributes) { base_attributes }

    before do
      stub_authentication!
    end

    it "can see a paginated list of variants" do
      api_get :index
      first_variant = json_response["variants"].first
      first_variant.should have_attributes(show_attributes)
      first_variant["stock_items"].should be_present
      json_response["count"].should == 1
      json_response["current_page"].should == 1
      json_response["pages"].should == 1
    end

    it 'can control the page size through a parameter' do
      create(:variant)
      api_get :index, :per_page => 1
      json_response['count'].should == 1
      json_response['current_page'].should == 1
      json_response['pages'].should == 3
{'fraction_non_alphanumeric': 0.11361771944216571, 'fraction_numerical': 0.005742411812961444, 'mean_word_length': 3.6018867924528304, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, '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': '7484816', 'n_tokens_mistral': 728, 'n_tokens_neox': 710, 'n_words': 162}