diff options
| author | Zog | 2017-12-27 13:42:39 +0100 | 
|---|---|---|
| committer | Zog | 2017-12-27 13:42:39 +0100 | 
| commit | 607fa5e03289a10b60a773bc40af38f1d721bbea (patch) | |
| tree | b27f8e9825e79675c606571ff7efb9953b8a4917 /spec | |
| parent | 78e2d256f895c1014a3def5f2ef6509086755215 (diff) | |
| download | chouette-core-607fa5e03289a10b60a773bc40af38f1d721bbea.tar.bz2 | |
Refs #5407 @2h; Model implementation
- Link PurchaseWindows to VehicleJourneys in the model
- Add an autocompletion endpoint
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/controllers/autocomplete_purchase_windows_controller_spec.rb | 33 | ||||
| -rw-r--r-- | spec/models/chouette/vehicle_journey_spec.rb | 1 | 
2 files changed, 34 insertions, 0 deletions
diff --git a/spec/controllers/autocomplete_purchase_windows_controller_spec.rb b/spec/controllers/autocomplete_purchase_windows_controller_spec.rb new file mode 100644 index 000000000..cea600ea8 --- /dev/null +++ b/spec/controllers/autocomplete_purchase_windows_controller_spec.rb @@ -0,0 +1,33 @@ +require 'rails_helper' + +RSpec.describe AutocompletePurchaseWindowsController, type: :controller do +  login_user + +  let(:referential) { Referential.first } +  let!(:window) { create :purchase_window, referential: referential, name: 'écolà militaire' } + +  describe 'GET #index' do +    it 'should be unauthorized' do +      expect { get(:index, referential_id: referential.id) }.to raise_error(FeatureChecker::NotAuthorizedError) +    end + +    with_feature "purchase_windows" do +      let(:request){ get(:index, referential_id: referential.id) } +      before do +        request +      end + +      it 'should be successful' do +        expect(response).to be_success +      end + +      context 'search by name' do +        let(:request){ get :index, referential_id: referential.id, q: {name_or_objectid_cont_any: 'écolà'}, :format => :json } +        it 'should be successful' do +          expect(response).to be_success +          expect(assigns(:purchase_windows)).to eq([window]) +        end +      end +    end +  end +end diff --git a/spec/models/chouette/vehicle_journey_spec.rb b/spec/models/chouette/vehicle_journey_spec.rb index ac9b21ceb..60ab2b818 100644 --- a/spec/models/chouette/vehicle_journey_spec.rb +++ b/spec/models/chouette/vehicle_journey_spec.rb @@ -2,6 +2,7 @@ require 'spec_helper'  describe Chouette::VehicleJourney, :type => :model do    it { is_expected.to be_versioned } +  it { should have_and_belong_to_many(:purchase_windows) }    it "must be valid with an at-stop day offset of 1" do      vehicle_journey = create(  | 
