# frozen_string_literal: true

require 'spec_helper'

describe BusStopsRoute do
  describe 'validations' do
    context 'same route and direction' do
      let!(:route) { create :route }
      let!(:direction) { 'West' }
      let!(:stop_1) { create :bus_stop }
      before :each do
        create :bus_stops_route, route: route,
                                 bus_stop: stop_1,
                                 sequence: sequence,
                                 direction: direction
      end
      context 'same sequence' do
        it 'is not valid' do
          stop_2 = create :bus_stop
          sequence = 1

          invalid_bsr = build :bus_stops_route, route: route,
                                                bus_stop: stop_2,
                                                sequence: sequence,
                                                direction: direction

          expect(invalid_bsr).not_to be_valid
        end
      end
      context 'same bus_stop' do
        it 'is not valid' do
          invalid_bsr = build :bus_stops_route, route: route,
                                                bus_stop: stop_1,
                                                direction: direction

          expect(invalid_bsr).not_to be_valid
        end
      end
    end
  end
end

# frozen_string_literal: true

require 'spec_helper'

describe BusStopsRoute do
  describe 'validations' do
    context 'same route and direction' do
      let!(:route) { create :route }
      let!(:direction) { 'West' }
      let!(:stop_1) { create :bus_stop }
      let!(:valid_bsr) { create :bus_stops_route, route: route,
                                                bus_stop: stop_1,
                                                direction: direction }
      context 'same sequence' do
        it 'is not valid' do
          stop_2 = create :bus_stop

          invalid_bsr = build :bus_stops_route, route: route,
                                                bus_stop: stop_2,
                                                sequence: valid_bsr.sequence,
                                                direction: direction

          expect(invalid_bsr).not_to be_valid
        end
      end
      context 'same bus_stop' do
        it 'is not valid' do
          invalid_bsr = build :bus_stops_route, route: route,
                                                bus_stop: valid_bsr.bus_stop,
                                                direction: direction

          expect(invalid_bsr).not_to be_valid
        end
      end
    end
  end
end

Make the scenario even clearer with accessing valid bsr
Make the scenario even clearer with accessing valid bsr
