<commit_before>require 'spec_helper'

describe Spree::Api::V1::ProductsController do
  let!(:product) { Factory(:product) }
  let(:attributes) { [:id, :name, :description, :price, :available_on, :permalink] }

  before do
    stub_authentication!
  end

  it "retrieves a list of products" do
    api_get :index
    json_response.first.should have_attributes(attributes)
  end

  it "gets a single product" do
    api_get :show, :id => product.to_param
    json_response.should have_attributes(attributes)
  end

  it "cannot create a new product if not an admin" do
    api_post :create, :name => "Brand new product!"
    json_response.should == { "error" => "You are not authorized to perform that action." }
  end
end
<commit_msg>Wrap ProductsController specs in a context for 'as a normal user'<commit_after>require 'spec_helper'

describe Spree::Api::V1::ProductsController do
  let!(:product) { Factory(:product) }
  let(:attributes) { [:id, :name, :description, :price, :available_on, :permalink] }

  before do
    stub_authentication!
  end

  context "as a normal user" do
    it "retrieves a list of products" do
      api_get :index
      json_response.first.should have_attributes(attributes)
    end

    it "gets a single product" do
      api_get :show, :id => product.to_param
      json_response.should have_attributes(attributes)
    end

    it "cannot create a new product if not an admin" do
      api_post :create, :name => "Brand new product!"
      json_response.should == { "error" => "You are not authorized to perform that action." }
    end
  end
end

{'fraction_non_alphanumeric': 0.10253164556962026, 'fraction_numerical': 0.0012658227848101266, 'mean_word_length': 3.8201219512195124, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '6718861', 'n_tokens_mistral': 498, 'n_tokens_neox': 482, 'n_words': 163}