<commit_before>require 'spec_helper'

describe V1::Map::PortsController, type: :controller do

  let!(:port) { create(:port) }
  let(:yacht) { create(:yacht) }
  let(:user) { create(:user, yacht: yacht) }
  let(:user_without_yacht) { create(:user, email: '<EMAIL>') }
  let(:app) { create_client_app }
  let(:token) { access_token(app, user) }
  let(:token2) { access_token(app, user_without_yacht) }

  describe 'GET#calculate' do
    context 'is logged in' do
      before do
        controller.stub(:doorkeeper_token) { token }
        get :calculate, id: port
      end

      it_behaves_like 'a successful request'

      it 'includes cost' do
        expect(json.port.cost).not_to eq(nil)
      end

      context 'has no yacht' do
        before do
          controller.stub(:doorkeeper_token) { token2 }
          get :calculate, id: port
        end

        it_behaves_like 'a not successful request'

        it 'sets nil as cost' do
          expect(json.port.cost).to eq(nil)
        end

        it 'responds with (465) no yacht present' do
          expect(response.status).to eq(465)
        end
      end
    end

    context 'is logged out' do
      before { get :calculate, id: port }
      it_behaves_like 'an unauthorized request'
    end
  end
end
<commit_msg>ports index and show specs<commit_after>require 'spec_helper'

describe V1::Map::PortsController, type: :controller do

  let!(:port) { create(:port) }
  let(:yacht) { create(:yacht) }
  let(:user) { create(:user, yacht: yacht) }
  let(:user_without_yacht) { create(:user, email: '<EMAIL>') }
  let(:app) { create_client_app }
  let(:token) { access_token(app, user) }
  let(:token2) { access_token(app, user_without_yacht) }

  describe 'GET#calculate' do
    context 'is logged in' do
      before do
        controller.stub(:doorkeeper_token) { token }
        get :calculate, id: port
      end

      it_behaves_like 'a successful request'

      it 'includes cost' do
        expect(json.port.cost).not_to eq(nil)
      end

      context 'has no yacht' do
        before do
          controller.stub(:doorkeeper_token) { token2 }
          get :calculate, id: port
        end

        it_behaves_like 'a not successful request'

        it 'sets nil as cost' do
          expect(json.port.cost).to eq(nil)
        end

        it 'responds with (465) no yacht present' do
          expect(response.status).to eq(465)
        end
      end
    end

    context 'is logged out' do
      before { get :calculate, id: port }
      it_behaves_like 'an unauthorized request'
    end
  end

  describe 'GET#show' do
    before do
      controller.stub(:doorkeeper_token) { token }
      get :show, id: port
    end

    it_behaves_like 'a successful request'

    it 'includes port' do
      expect(json.port.id).to eq(port.id)
    end
  end

  describe 'GET#index' do
    before do
      controller.stub(:doorkeeper_token) { token }
      get :index
    end

    it_behaves_like 'a successful request'

    it 'includes ports' do
      expect(json.ports.count).to eq(1)
    end
  end
end

{'fraction_non_alphanumeric': 0.10579427083333333, 'fraction_numerical': 0.006184895833333333, 'mean_word_length': 2.5079908675799087, 'pattern_counts': {'":': 0, '<': 5, '<?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': '3625303', 'n_tokens_mistral': 1026, 'n_tokens_neox': 978, 'n_words': 276}