<commit_before>describe Comable::Admin::OrdersController do
  sign_in_admin

  let(:comable) { controller.comable }

  before { request.env['HTTP_REFERER'] = 'http://localhost:3000' }

  describe 'GET index' do
    it 'assigns all orders as @orders' do
      order = FactoryGirl.create(:order, :completed)
      get :index
      expect(assigns(:orders)).to eq([order])
    end
  end

  describe 'GET show' do
    it 'assigns the requested order as @order' do
      order = FactoryGirl.create(:order, :completed)
      get :show, id: order.to_param
      expect(assigns(:order)).to eq(order)
    end
  end

  describe 'GET export' do
    it 'exports the csv file' do
      order = FactoryGirl.create(:order, :completed)
      order_item = FactoryGirl.create(:order_item, order: order)<commit_msg>Add tests for `edit` and `update` actions<commit_after>describe Comable::Admin::OrdersController do
  sign_in_admin

  let(:comable) { controller.comable }

  let(:valid_attributes) { FactoryGirl.attributes_for(:order, :completed) }
  let(:invalid_attributes) { valid_attributes.merge(email: 'x' * 1024) }

  before { request.env['HTTP_REFERER'] = 'http://localhost:3000' }

  describe 'GET index' do
    it 'assigns all orders as @orders' do
      order = FactoryGirl.create(:order, :completed)
      get :index
      expect(assigns(:orders)).to eq([order])
    end
  end

  describe 'GET show' do
    it 'assigns the requested order as @order' do
      order = FactoryGirl.create(:order, :completed)
      get :show, id: order.to_param
      expect(assigns(:order)).to eq(order)
    end
  end

  describe 'GET edit' do
    it 'assigns the requested order as @order' do
      order = FactoryGirl.create(:order, :completed)
      get :edit, id: order.to_param
      expect(assigns(:order)).to eq(order)
    end
  end

  describe 'PUT update' do
    let!(:order) { FactoryGirl.create(:order, :completed) }

    describe 'with valid params' do
      let(:new_attributes) { { email: "NEW: #{order.email}" } }

      it 'updates the requested order' do
        put :update, id: order.to_param, order: new_attributes
        order.reload
        expect(order).to have_attributes(new_attributes)
      end

      it 'assigns the requested order as @order' do
        put :update, id: order.to_param, order: valid_attributes
        expect(assigns(:order)).to eq(order)
      end

      it 'redirects to the order' do
        put :update, id: order.to_param, order: valid_attributes
        expect(response).to redirect_to([comable, :admin, order])
      end
    end

    describe 'with invalid params' do
      it 'assigns the order as @order' do
        put :update, id: order.to_param, order: invalid_attributes
        expect(assigns(:order)).to eq(order)
      end

      it "re-renders the 'edit' template" do
        put :update, id: order.to_param, order: invalid_attributes
        expect(response).to render_template(:edit)
      end
    end
  end

  describe 'GET export' do
    it 'exports the csv file' do
      order = FactoryGirl.create(:order, :completed)
      order_item = FactoryGirl.create(:order_item, order: order)
{'fraction_non_alphanumeric': 0.11235595390524968, 'fraction_numerical': 0.0038412291933418692, 'mean_word_length': 3.177807486631016, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4669453', 'n_tokens_mistral': 991, 'n_tokens_neox': 936, 'n_words': 278}