diff options
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/controllers/routes_controller_spec.rb | 10 | ||||
| -rw-r--r-- | spec/models/route_sections_selector_spec.rb | 43 | ||||
| -rw-r--r-- | spec/support/fake_iev_server.rb | 15 | ||||
| -rw-r--r-- | spec/support/referential.rb | 8 |
4 files changed, 55 insertions, 21 deletions
diff --git a/spec/controllers/routes_controller_spec.rb b/spec/controllers/routes_controller_spec.rb index a813056c3..de6d16c8b 100644 --- a/spec/controllers/routes_controller_spec.rb +++ b/spec/controllers/routes_controller_spec.rb @@ -37,7 +37,7 @@ describe RoutesController, :type => :controller do it_behaves_like "line and referential linked" it_behaves_like "redirected to referential_line_path(referential,line)" end - + describe "POST /create" do before(:each) do post :create, :line_id => route.line_id, @@ -48,7 +48,7 @@ describe RoutesController, :type => :controller do it_behaves_like "line and referential linked" it_behaves_like "redirected to referential_line_path(referential,line)" end - + describe "PUT /update" do before(:each) do put :update, :id => route.id, :line_id => route.line_id, @@ -59,10 +59,10 @@ describe RoutesController, :type => :controller do it_behaves_like "route, line and referential linked" it_behaves_like "redirected to referential_line_path(referential,line)" end - + describe "GET /show" do before(:each) do - get :show, :id => route.id, + get :show, :id => route.id, :line_id => route.line_id, :referential_id => referential.id end @@ -78,6 +78,6 @@ describe RoutesController, :type => :controller do # expect(assigns[:stop_points]).to eq(route.stop_points.paginate(:page => nil)) #end end - + end diff --git a/spec/models/route_sections_selector_spec.rb b/spec/models/route_sections_selector_spec.rb new file mode 100644 index 000000000..a00945d42 --- /dev/null +++ b/spec/models/route_sections_selector_spec.rb @@ -0,0 +1,43 @@ +require 'spec_helper' + +describe RouteSectionsSelector, :type => :model do + + let(:stop_points) { create_list :stop_point, 5 } + let(:itinerary) { double stop_points: stop_points, route_sections: [] } + + subject { RouteSectionsSelector.new itinerary } + + describe "#sections" do + + it "should create a Section between each StopPoint" do + expect(subject.sections.size).to eq(stop_points.size - 1) + end + + end + +end + +describe RouteSectionsSelector::Section, :type => :model do + + let(:departure) { create :stop_point } + let(:arrival) { create :stop_point } + + subject { RouteSectionsSelector::Section.new departure, arrival } + + let(:route_sections) do + create_list :route_section, 5, + departure: departure.stop_area, + arrival: arrival.stop_area + end + + describe "#candidates" do + it "should return an empty array when no RouteSection exists" do + expect(subject.candidates).to be_empty + end + + it "should return the RouteSections with the same departure/arrival StopAreas" do + expect(subject.candidates).to match_array(route_sections) + end + end + +end diff --git a/spec/support/fake_iev_server.rb b/spec/support/fake_iev_server.rb index c311fdc91..8cd002fae 100644 --- a/spec/support/fake_iev_server.rb +++ b/spec/support/fake_iev_server.rb @@ -10,17 +10,11 @@ end # Importer ############ # get list -fixture_request :get, - "http://#{Rails.application.secrets.api_endpoint}referentials/test/scheduled_jobs?action=importer", - 'scheduled_jobs.json' +fixture_request :get, "#{Rails.application.secrets.api_endpoint}referentials/test/scheduled_jobs?action=importer", 'scheduled_jobs.json' # get element -fixture_request :get, - "http://#{Rails.application.secrets.api_endpoint}referentials/test/scheduled_jobs/1?action=importer", - 'scheduled_job.json' +fixture_request :get, "#{Rails.application.secrets.api_endpoint}referentials/test/scheduled_jobs/1?action=importer", 'scheduled_job.json' # post element -fixture_request :post, - "http://#{Rails.application.secrets.api_endpoint}referentials/test/scheduled_jobs/", - 'scheduled_job.json' +fixture_request :post, "#{Rails.application.secrets.api_endpoint}referentials/test/scheduled_jobs/", 'scheduled_job.json' # Optionnels # delete element @@ -36,6 +30,3 @@ fixture_request :post, ############ # Validation ############ - - - diff --git a/spec/support/referential.rb b/spec/support/referential.rb index d77a05f41..8c468eb53 100644 --- a/spec/support/referential.rb +++ b/spec/support/referential.rb @@ -12,7 +12,7 @@ module ReferentialHelper end module ClassMethods - + def assign_referential before(:each) do assign :referential, referential @@ -34,7 +34,7 @@ RSpec.configure do |config| config.before(:suite) do # Clean all tables to start - DatabaseCleaner.clean_with :truncation + DatabaseCleaner.clean_with :truncation, except: %w[spatial_ref_sys] # Truncating doesn't drop schemas, ensure we're clean here, first *may not* exist Apartment::Tenant.drop('first') rescue nil # Create the default tenant for our tests @@ -49,7 +49,7 @@ RSpec.configure do |config| end config.before(:each, :js => true) do - DatabaseCleaner.strategy = :truncation + DatabaseCleaner.strategy = :truncation, { except: %w[spatial_ref_sys] } end config.before(:each) do @@ -61,6 +61,6 @@ RSpec.configure do |config| Apartment::Tenant.reset # Rollback transaction DatabaseCleaner.clean - end + end end |
