diff options
| -rw-r--r-- | Gemfile | 2 | ||||
| -rw-r--r-- | Gemfile.lock | 4 | ||||
| -rw-r--r-- | spec/models/route_spec.rb | 35 | 
3 files changed, 38 insertions, 3 deletions
| @@ -125,7 +125,7 @@ gem 'enumerize', '~> 2.1.2'  gem 'deep_cloneable', '~> 2.0.0'  gem 'acts-as-taggable-on', '~> 4.0.0' -gem 'acts_as_list', '~> 0.6.0' +gem 'acts_as_list', '~> 0.9.11'  gem 'acts_as_tree', '~> 2.1.0', require: 'acts_as_tree'  gem 'rabl' diff --git a/Gemfile.lock b/Gemfile.lock index 4fb77eeb9..2071eee78 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -86,7 +86,7 @@ GEM        tzinfo (~> 1.1)      acts-as-taggable-on (4.0.0)        activerecord (>= 4.0) -    acts_as_list (0.6.0) +    acts_as_list (0.9.11)        activerecord (>= 3.0)      acts_as_tree (2.1.0)        activerecord (>= 3.0.0) @@ -593,7 +593,7 @@ DEPENDENCIES    active_attr    activerecord-postgis-adapter (~> 3.0.0)    acts-as-taggable-on (~> 4.0.0) -  acts_as_list (~> 0.6.0) +  acts_as_list (~> 0.9.11)    acts_as_tree (~> 2.1.0)    apartment (~> 1.0.0)    awesome_print diff --git a/spec/models/route_spec.rb b/spec/models/route_spec.rb index b407cd866..58524038b 100644 --- a/spec/models/route_spec.rb +++ b/spec/models/route_spec.rb @@ -65,4 +65,39 @@ RSpec.describe Chouette::Route, :type => :model do        end      end    end + +  context "when creating stop_points" do +    # Here we tests that acts_as_list does not mess with the positions +    let(:stop_areas){ +      4.times.map{create :stop_area} +    } + +    it "should set a correct order to the stop_points" do + +      order = [0, 3, 2, 1] +      new = Referential.new +      new.name = "mkmkm" +      new.organisation = create(:organisation) +      new.line_referential = create(:line_referential) +      create(:line, line_referential: new.line_referential) +      new.stop_area_referential = create(:stop_area_referential) +      new.objectid_format = :netex +      new.save! +      new.switch +      route = new.routes.new + +      route.published_name = route.name = "Route" +      route.line = new.line_referential.lines.last +      order.each_with_index do |position, i| +        _attributes = { +          stop_area: stop_areas[i], +          position: position +        } +        route.stop_points.build _attributes +      end +      route.save +      expect(route).to be_valid +      expect{route.run_callbacks(:commit)}.to_not raise_error +    end +  end  end | 
