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 | |
| 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')
| -rw-r--r-- | spec/controllers/routes_controller_spec.rb | 83 | ||||
| -rw-r--r-- | spec/controllers/stop_points_controller_spec.rb | 75 | ||||
| -rw-r--r-- | spec/support/devise.rb | 4 | ||||
| -rw-r--r-- | spec/views/routes/show.html.erb_spec.rb | 2 |
4 files changed, 161 insertions, 3 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 diff --git a/spec/support/devise.rb b/spec/support/devise.rb index 671c61122..444eb0fee 100644 --- a/spec/support/devise.rb +++ b/spec/support/devise.rb @@ -28,7 +28,7 @@ module DeviseRequestHelper end -module DeviseControllerhelper +module DeviseControllerHelper def login_user before(:each) do @request.env["devise.mapping"] = Devise.mappings[:user] @@ -39,7 +39,7 @@ end RSpec.configure do |config| config.include Devise::TestHelpers, :type => :controller - config.extend DeviseControllerhelper, :type => :controller + config.extend DeviseControllerHelper, :type => :controller config.include DeviseRequestHelper, :type => :request end diff --git a/spec/views/routes/show.html.erb_spec.rb b/spec/views/routes/show.html.erb_spec.rb index 05d783eb0..5fa7485b7 100644 --- a/spec/views/routes/show.html.erb_spec.rb +++ b/spec/views/routes/show.html.erb_spec.rb @@ -5,7 +5,7 @@ describe "/routes/show" do let!(:referential) { assign :referential, create(:referential) } let!(:line) { assign :line, create(:line) } let!(:route) { assign :route, create(:route, :line => line) } - let!(:stop_areas) { assign :stop_areas, Array.new(2) { create(:stop_area) }.paginate } + let!(:stop_points) { assign :stop_points, Array.new(2) { create(:stop_point) }.paginate } let!(:map) { assign(:map, mock(:to_html => '<div id="map"/>')) } it "should render h2 with the route name" do |
