diff options
| author | Zog | 2018-02-05 09:50:46 +0100 | 
|---|---|---|
| committer | Zog | 2018-02-09 12:02:24 +0100 | 
| commit | 8f8ab427914c39fdfb0648978d4fdff25ccfdc63 (patch) | |
| tree | 0bf616f4c4a97943e7fa689ae736dbb15e506147 | |
| parent | 23882d8e525a63d15b4dca1731b2184984621f52 (diff) | |
| download | chouette-core-8f8ab427914c39fdfb0648978d4fdff25ccfdc63.tar.bz2 | |
Refs #5824; Add specs (and fix some)5824-autocomplete-stop-areas-scope
| -rw-r--r-- | spec/controllers/autocomplete_stop_areas_controller_spec.rb | 14 | ||||
| -rw-r--r-- | spec/factories/chouette_stop_areas.rb | 8 | ||||
| -rw-r--r-- | spec/models/calendar_spec.rb | 2 | 
3 files changed, 20 insertions, 4 deletions
| diff --git a/spec/controllers/autocomplete_stop_areas_controller_spec.rb b/spec/controllers/autocomplete_stop_areas_controller_spec.rb index e8733518c..e0d1cd714 100644 --- a/spec/controllers/autocomplete_stop_areas_controller_spec.rb +++ b/spec/controllers/autocomplete_stop_areas_controller_spec.rb @@ -4,9 +4,11 @@ RSpec.describe AutocompleteStopAreasController, type: :controller do    login_user    let(:referential) { Referential.first } -  let!(:stop_area) { create :stop_area, name: 'écolà militaire', stop_area_referential: referential.stop_area_referential } -  let!(:zdep_stop_area) { create :stop_area, area_type: "zdep", stop_area_referential: referential.stop_area_referential } -  let!(:not_zdep_stop_area) { create :stop_area, area_type: "lda", stop_area_referential: referential.stop_area_referential } +  let(:other_referential) { create :referential } +  let!(:stop_area) { create :stop_area, name: 'écolà militaire', referential: referential } +  let!(:other_referential_stop_area) { create :stop_area, name: 'écolà militaire', referential: other_referential } +  let!(:zdep_stop_area) { create :stop_area, area_type: "zdep", referential: referential } +  let!(:not_zdep_stop_area) { create :stop_area, area_type: "lda", referential: referential }    describe 'GET #index' do      it 'should be successful' do @@ -14,6 +16,12 @@ RSpec.describe AutocompleteStopAreasController, type: :controller do        expect(response).to be_success      end +    it "should filter stop areas based on referential" do +      get :index, referential_id: referential.id +      expect(assigns(:stop_areas)).to include(stop_area) +      expect(assigns(:stop_areas)).to_not include(other_referential_stop_area) +    end +      context 'search by name' do        it 'should be successful' do          get :index, referential_id: referential.id, q: 'écolà', :format => :json diff --git a/spec/factories/chouette_stop_areas.rb b/spec/factories/chouette_stop_areas.rb index 9b4764781..dab135ca6 100644 --- a/spec/factories/chouette_stop_areas.rb +++ b/spec/factories/chouette_stop_areas.rb @@ -10,6 +10,14 @@ FactoryGirl.define do      association :stop_area_referential +    transient do +      referential nil +    end + +    before(:create) do |stop_area, evaluator| +      stop_area.stop_area_referential = evaluator.referential.stop_area_referential if evaluator.referential +    end +      trait :deactivated do        deleted_at { 1.hour.ago }      end diff --git a/spec/models/calendar_spec.rb b/spec/models/calendar_spec.rb index 3cffd0f8a..a5c0a7471 100644 --- a/spec/models/calendar_spec.rb +++ b/spec/models/calendar_spec.rb @@ -36,7 +36,7 @@ RSpec.describe Calendar, :type => :model do      end      it 'validates that dates and date_ranges do not overlap but allow for days not in the list' do -      expect(build(:calendar, dates: [Date.today.beginning_of_week], date_ranges: [Date.today.beginning_of_week..Date.today], int_day_types: Calendar::THURSDAY)).to be_valid +      expect(build(:calendar, dates: [Date.today.beginning_of_week - 1.week], date_ranges: [(Date.today.beginning_of_week - 1.week)..Date.today], int_day_types: Calendar::THURSDAY)).to be_valid      end      it 'validates that there are no duplicates in dates' do | 
