aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorMarc Florisson2012-05-16 18:04:48 +0200
committerMarc Florisson2012-05-16 18:04:48 +0200
commitf420c660705a524ac7e61afaf684330ebafcd4b9 (patch)
treec18e9e754631e89139bef468fc0d79bec35a8825 /spec
parent63f7a0b5183f52b8791adf2a61521e12f652a98e (diff)
parent12c3bf9d0e73947d34a809ce55d9a1a900f1df0f (diff)
downloadchouette-core-f420c660705a524ac7e61afaf684330ebafcd4b9.tar.bz2
refactor stop_points
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/routes_controller_spec.rb83
-rw-r--r--spec/controllers/stop_points_controller_spec.rb75
-rw-r--r--spec/support/devise.rb4
3 files changed, 160 insertions, 2 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