diff options
| author | Alban Peignier | 2012-05-16 19:58:07 +0200 | 
|---|---|---|
| committer | Alban Peignier | 2012-05-16 19:58:07 +0200 | 
| commit | 085cb4a10750833679bbfa2a61930b3a9f8307c2 (patch) | |
| tree | 329ea7204fbc8d6cfb3d861512c7d7492108e9c1 /spec/controllers | |
| parent | 8c3eb6906fbd0d62a2fe63121b1851f523671f00 (diff) | |
| parent | 7bcb93aff46042a8fd229f6c78b3e8bbb4431f5c (diff) | |
| download | chouette-core-085cb4a10750833679bbfa2a61930b3a9f8307c2.tar.bz2 | |
Merge branch 'master' of chouette.dryade.priv:/srv/git/chouette2
Diffstat (limited to 'spec/controllers')
| -rw-r--r-- | spec/controllers/routes_controller_spec.rb | 83 | ||||
| -rw-r--r-- | spec/controllers/stop_points_controller_spec.rb | 75 | 
2 files changed, 158 insertions, 0 deletions
diff --git a/spec/controllers/routes_controller_spec.rb b/spec/controllers/routes_controller_spec.rb new file mode 100644 index 000000000..92bcbf4a8 --- /dev/null +++ b/spec/controllers/routes_controller_spec.rb @@ -0,0 +1,83 @@ +require 'spec_helper' + +describe RoutesController do +  login_user + +  let!(:referential) { create(:referential).switch } +  let!(:route) { referential; Factory(:route) } + +  it { should be_kind_of(ChouetteController) } + +  shared_examples_for "redirected to referential_line_path(referential,line)" do +    it "should redirect_to referential_line_path(referential,line)" do +      response.should redirect_to( referential_line_path(referential,route.line) ) +    end +  end +  shared_examples_for "line and referential linked" do +    it "assigns route.line as @line" do +      assigns[:line].should == route.line +    end + +    it "assigns referential as @referential" do +      assigns[:referential].should == referential +    end +  end +  shared_examples_for "route, line and referential linked" do +    it "assigns route as @route" do +      assigns[:route].should == route +    end +    it_behaves_like "line and referential linked" +  end + + +  describe "GET /index" do +    before(:each) do +      get :index, :line_id => route.line_id, +          :referential_id => referential.id +    end + +    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, +          :referential_id => referential.id, +          :route => { :name => "changed"} + +    end +    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, +          :referential_id => referential.id +    end + +    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,  +          :line_id => route.line_id, +          :referential_id => referential.id +    end + +    it_behaves_like "route, line and referential linked" + +    it "assigns RouteMap.new( referential, route) as @map" do +      assigns[:map].should be_an_instance_of(RouteMap) +      assigns[:map].referential.should == referential +      assigns[:map].route.should == route +    end + +    it "assigns route.stop_points.paginate(:page => nil, :per_page => 10) as @stop_points" do +      assigns[:stop_points].should == route.stop_points.paginate(:page => nil, :per_page => 10) +    end + +  end +end + diff --git a/spec/controllers/stop_points_controller_spec.rb b/spec/controllers/stop_points_controller_spec.rb new file mode 100644 index 000000000..20ed1170e --- /dev/null +++ b/spec/controllers/stop_points_controller_spec.rb @@ -0,0 +1,75 @@ +require 'spec_helper' + +describe StopPointsController do +  login_user + +  let!(:referential) { create(:referential).switch } +  let!(:route) { referential; Factory(:route) } +  let(:permutated_stop_point_ids) { +    old_stop_point_ids = route.stop_points.map(&:id) +    old_stop_point_ids.permutation.to_a.select { |permutated| permutated != old_stop_point_ids}.first +  } + +  it { should be_kind_of(ChouetteController) } + +  shared_examples_for "route, line and referential linked (stop_points)" do +    it "assigns route as @route" do +      assigns[:route].should == route +    end +    it "assigns route.line as @line" do +      assigns[:line].should == route.line +    end + +    it "assigns referential as @referential" do +      assigns[:referential].should == referential +    end +  end + +  describe "sort routing" do +    let(:path) { sort_referential_line_route_stop_points_path( referential, route.line, route)} +    it "routes /referential/:referentialid/line/:lineid/route/:routeid/stop_points/sort to stop_points#sort" do +      { :post => path }.should route_to(:controller => "stop_points",  +                                       :action => "sort", +                                       :referential_id => referential.id.to_s, +                                       :line_id => route.line_id.to_s, +                                       :route_id => route.id.to_s ) +    end +  end + +  describe "POST /sort" do +    before(:each) do +      post :sort, :line_id => route.line_id, +          :route_id => route.id, +          :referential_id => referential.id, +          :stop_point => permutated_stop_point_ids +    end +    it_behaves_like "route, line and referential linked (stop_points)" +  end + +  describe "#sort" do +    it "should delegate to route.sort! with permutated_stop_point_ids" do +      controller.stub!(:route => route, :params => { :stop_point => permutated_stop_point_ids}) +      controller.stub!(:respond_to => nil) +      route.should_receive(:reorder!).with(permutated_stop_point_ids) +      controller.sort +    end +  end +  describe "GET /index" do +    before(:each) do +      get :index, :line_id => route.line_id, +          :route_id => route.id, +          :referential_id => referential.id +    end +    it_behaves_like "route, line and referential linked (stop_points)" +  end +  describe "POST /create" do +    before(:each) do +      post :create, :line_id => route.line_id, +          :referential_id => referential.id, +          :route_id => route.id, +          :stop_point => Factory.attributes_for(:stop_point) + +    end +    it_behaves_like "route, line and referential linked (stop_points)" +  end +end  | 
