diff options
| author | Marc Florisson | 2012-05-16 18:04:48 +0200 |
|---|---|---|
| committer | Marc Florisson | 2012-05-16 18:04:48 +0200 |
| commit | f420c660705a524ac7e61afaf684330ebafcd4b9 (patch) | |
| tree | c18e9e754631e89139bef468fc0d79bec35a8825 | |
| parent | 63f7a0b5183f52b8791adf2a61521e12f652a98e (diff) | |
| parent | 12c3bf9d0e73947d34a809ce55d9a1a900f1df0f (diff) | |
| download | chouette-core-f420c660705a524ac7e61afaf684330ebafcd4b9.tar.bz2 | |
refactor stop_points
23 files changed, 344 insertions, 137 deletions
@@ -31,7 +31,7 @@ gem 'RedCloth' gem "acts_as_tree", :git => "git://github.com/dryade/acts_as_tree.git" gem 'apartment', :git => 'git://github.com/dryade/apartment.git' -gem 'ninoxe', :path => '~/dev/chouette-ninoxe' #:git => 'git://chouette.dryade.priv/ninoxe' #, :path => '~/Projects/Ninoxe' +gem 'ninoxe', :git => 'git://chouette.dryade.priv/ninoxe' #, :path => '~/Projects/Ninoxe' gem 'acts_as_list', '0.1.6' gem 'composite_primary_keys', '4.1.2' diff --git a/Gemfile.lock b/Gemfile.lock index 64f671c64..28bd45242 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,4 +1,16 @@ GIT + remote: git://chouette.dryade.priv/ninoxe + revision: f5bceada23c96488b4d830947a7c6eb38bd22d4f + specs: + ninoxe (0.0.8) + GeoRuby + activerecord (~> 3.1.3) + acts_as_list (= 0.1.6) + composite_primary_keys (= 4.1.2) + geokit + rails (= 3.1.3) + +GIT remote: git://github.com/dryade/activerecord-jdbc-adapter.git revision: 0bf424bc3bcaf9f44646976cc4c1a8e9e57f11b4 specs: @@ -36,21 +48,11 @@ GIT user_interface (0.0.1) rails (~> 3.1.0) -PATH - remote: ~/dev/chouette-ninoxe - specs: - ninoxe (0.0.8) - GeoRuby - activerecord (~> 3.1.3) - acts_as_list (= 0.1.6) - composite_primary_keys (= 4.1.2) - geokit - rails (= 3.1.3) - GEM remote: http://rubygems.org/ specs: GeoRuby (1.3.4) + RedCloth (4.2.9) RedCloth (4.2.9-java) SyslogLogger (1.4.1) actionmailer (3.1.3) @@ -87,6 +89,7 @@ GEM acts_as_list (0.1.6) addressable (2.2.8) arel (2.2.3) + bcrypt-ruby (3.0.1) bcrypt-ruby (3.0.1-java) bouncy-castle-java (1.5.0146.1) builder (3.0.0) @@ -132,6 +135,7 @@ GEM factory_girl_rails (1.7.0) factory_girl (~> 2.6.0) railties (>= 3.0.0) + ffi (1.0.11) ffi (1.0.11-java) formtastic (2.0.2) rails (~> 3.0) @@ -157,7 +161,10 @@ GEM jruby-openssl (0.7.6.1) bouncy-castle-java (>= 1.5.0146.1) jruby-rack (1.1.5) + json (1.7.3) json (1.7.3-java) + launchy (2.1.0) + addressable (~> 2.2.6) launchy (2.1.0-java) addressable (~> 2.2.6) ffi (~> 1.0.9) @@ -178,6 +185,7 @@ GEM net-ssh (2.3.0) net-ssh-gateway (1.1.0) net-ssh (>= 1.99.1) + nokogiri (1.5.2) nokogiri (1.5.2-java) orm_adapter (0.0.7) polyamorous (0.5.0) @@ -232,8 +240,8 @@ GEM rspec-core (2.10.0) rspec-expectations (2.10.0) diff-lcs (~> 1.1.3) - rspec-mocks (2.10.0) - rspec-rails (2.10.0) + rspec-mocks (2.10.1) + rspec-rails (2.10.1) actionpack (>= 3.0) activesupport (>= 3.0) railties (>= 3.0) diff --git a/app/assets/stylesheets/stop_areas.css.scss b/app/assets/stylesheets/stop_areas.css.scss index b751723b4..e66f4dd28 100644 --- a/app/assets/stylesheets/stop_areas.css.scss +++ b/app/assets/stylesheets/stop_areas.css.scss @@ -65,6 +65,12 @@ span { margin-left: 7px; } img { margin: 0px 5px 0px 5px;} } + .no_parent{ + float: left; + padding: 3px 15px 3px 3px; + height: 25px; + width: 150px; + } .target{ border: 2px solid #86b41d; diff --git a/app/assets/stylesheets/stop_points.css.scss b/app/assets/stylesheets/stop_points.css.scss index d774fe0e7..73fc22aef 100644 --- a/app/assets/stylesheets/stop_points.css.scss +++ b/app/assets/stylesheets/stop_points.css.scss @@ -5,52 +5,47 @@ #workspace.stop_points.index { + .stop_point:after { + @include after_div_for_object; + } + + .stop_points { + } + + .stop_points:after { + @include content_to_clear; + } + + .formtastic .buttons { + a { + margin-top: 0px; + } + } + .stop_point { - margin-top: 8px; - margin-bottom: 8px; + @include div_for_object; + /* to create multi-column index */ + width: 350px; + padding-right: 10px; - .description:after { - clear: both; - float: left; + .handle { + cursor: move; + margin-right: 7px; + margin-bottom: 20px; } - .description { - .position { - width: 25px; - height: 20px; - float: left; - background-color: #61970B; - font-weight: bold; - color: white; - margin-right: 10px; - padding-left: 4px; - } - .info { - margin-bottom: 5px; - font-size: 10px; - color: #777; - font-weight: normal; - line-height: 14px; - .actions { - margin-top: 3px; - a { - padding-left: 15px; - } - a.link { - background: url(image-path('icons/link-small.png')) no-repeat 0% 50%; - } - a.remove { - background: url(image-path('user_interface/ui/remove-small.png')) no-repeat 0% 50%; - } - } - } + a.link { + background: url(image-path('icons/link-small.png')) no-repeat 0% 50%; } - .handle { - float: left; - cursor: move; - margin-right: 7px; - margin-bottom: 20px; + + .position { + background-color: #61970B; + font-weight: bold; + color: white; + margin-right: 10px; + padding-left: 4px; } + } } diff --git a/app/controllers/routes_controller.rb b/app/controllers/routes_controller.rb index fa429fbac..fed76f23b 100644 --- a/app/controllers/routes_controller.rb +++ b/app/controllers/routes_controller.rb @@ -15,8 +15,8 @@ class RoutesController < ChouetteController end def show - @map = RouteMap.new referential, resource - @stop_points = resource.stop_points.paginate(:page => params[:page], :per_page => 10) + @map = RouteMap.new referential, route + @stop_points = route.stop_points.paginate(:page => params[:page], :per_page => 10) show! end diff --git a/app/controllers/stop_points_controller.rb b/app/controllers/stop_points_controller.rb index a5e5f2a79..ae6bbd09a 100644 --- a/app/controllers/stop_points_controller.rb +++ b/app/controllers/stop_points_controller.rb @@ -9,20 +9,18 @@ class StopPointsController < ChouetteController end end - def index - index! - end - - def create - create! do |success, failure| - success.html { redirect_to referential_line_route_path(@referential,@line,@route) } - end - end - + alias_method :route, :parent def sort - parent.reorder!( params[:stop_point]) - render :nothing => true + begin + route.reorder!( params[:stop_point]) + flash[:notice] = t("stop_points.reorder_success") + rescue => e + flash[:alert] = t("stop_points.reorder_failure") + end + respond_to do |format| + format.html { redirect_to referential_line_route_stop_points_path(@referential,@line,@route) } + end end end diff --git a/app/views/companies/show.html.erb b/app/views/companies/show.html.erb index 8703bbc49..b5c64b691 100644 --- a/app/views/companies/show.html.erb +++ b/app/views/companies/show.html.erb @@ -57,7 +57,7 @@ <% content_for :sidebar do %> <ul class="actions"> <li><%= link_to t('companies.actions.edit'), edit_referential_company_path(@referential, @company), :class => "edit" %></li> - <li><%= link_to t('companys.actions.destroy'), referential_company_path(@referential, @company), :method => :delete, :confirm => t('companies.actions.destroy_confirm'), :class => "remove" %></li> + <li><%= link_to t('companies.actions.destroy'), referential_company_path(@referential, @company), :method => :delete, :confirm => t('companies.actions.destroy_confirm'), :class => "remove" %></li> <br> </ul> <% end %> diff --git a/app/views/lines/_form.erb b/app/views/lines/_form.erb index 1a7107e7e..043a323e7 100644 --- a/app/views/lines/_form.erb +++ b/app/views/lines/_form.erb @@ -20,7 +20,7 @@ <% end %> <%= form.buttons do %> - <%= form.commit_button true %> + <%= form.commit_button :label => 'somename' %> <li><%= t('or') %></li> <li><%= link_to t('cancel'), :back %></li> <% end %> diff --git a/app/views/lines/index.html.erb b/app/views/lines/index.html.erb index 26b97e0b3..f499f6940 100644 --- a/app/views/lines/index.html.erb +++ b/app/views/lines/index.html.erb @@ -23,7 +23,6 @@ </p> <% end %> - <div class="pagination"> <div class="page_info"> <%= page_entries_info @lines %> @@ -63,21 +62,21 @@ </ul> <div id="multiple_selection_menu"> - <h3>Sélection multiple</h3> + <h3><%= t(".multi_selection") %> </h3> <div class="disabled"> - <a class="enable" href="#">Activer la sélection multiple</a> + <a class="enable" href="#"><%= t(".multi_selection_enable") %></a> </div> <div class="enabled" style="display: none;"> - <a class="disable" href="#">Désactiver la sélection multiple</a> + <a class="disable" href="#"><%= t(".multi_selection_disable") %></a> <ul class="actions"> - <li><a href="#" class="remove">Supprimer les lignes</a></li> - <li><a href="#" class="export">Exporter les lignes</a></li> + <li><a href="#" class="remove"><%= t(".delete_selected") %></a></li> + <li><a href="#" class="export"><%= t(".export_selected") %></a></li> </ul> - <a class="select_all" href="#">Tout sélectionner</a> | <a class="deselect_all" href="#">désélectionner</a> - </div> + <a class="select_all" href="#"><%= t(".select_all") %></a> | <a class="deselect_all" href="#"><%= t(".deselect_all") %></a> + </div> </div> <% end %> diff --git a/app/views/stop_areas/_form.html.erb b/app/views/stop_areas/_form.html.erb index ffdd9faa1..208345523 100644 --- a/app/views/stop_areas/_form.html.erb +++ b/app/views/stop_areas/_form.html.erb @@ -12,11 +12,11 @@ <%= form.input :objectid %> <% else %> <li> - <label><%= @stop_area.human_attribute_name("stop_area_type") %>: </label> - <%= @stop_area.stop_area_type %> + <label><%= @stop_area.human_attribute_name("stop_area_type") %></label> + <%= t("area_types.label.#{@stop_area.stop_area_type}") %> </li> <li> - <label><%= @stop_area.human_attribute_name("objectid") %>: </label> + <label><%= @stop_area.human_attribute_name("objectid") %></label> <%= @stop_area.objectid %> </li> <% end %> diff --git a/app/views/stop_areas/show.html.erb b/app/views/stop_areas/show.html.erb index f4f7a9064..afaa5830a 100644 --- a/app/views/stop_areas/show.html.erb +++ b/app/views/stop_areas/show.html.erb @@ -96,6 +96,8 @@ <%= link_to image_tag("user_interface/ui/remove.png"), referential_stop_area_path(@referential, @stop_area.parent), :method => :delete, :confirm => t('stop_areas.actions.destroy_confirm'), :class => "remove" %> </div> <div class="link"><%= image_tag "icons/link.png"%></div> + <% else %> + <div class="no_parent"> </div> <% end %> <% if @stop_area.parent.present? || @stop_area.children.present? %> diff --git a/app/views/stop_points/_stop_point.html.erb b/app/views/stop_points/_stop_point.html.erb index 3d9297b32..641ddf683 100644 --- a/app/views/stop_points/_stop_point.html.erb +++ b/app/views/stop_points/_stop_point.html.erb @@ -10,7 +10,7 @@ <% end %> </p> <p> - <%= t('.lines') %> <% stop_point.stop_area.lines.each do |line| %> + <%= t('.lines') %> <% stop_point.stop_area.lines.reject { |l| l.id==@line.id}.each do |line| %> <span class="line"><%= line.number %></span> <% end %> - <%= stop_point.stop_area.human_attribute_name('country_code') %> <%= stop_point.stop_area.country_code %> diff --git a/app/views/stop_points/_stop_point_draggable.html.erb b/app/views/stop_points/_stop_point_draggable.html.erb new file mode 100644 index 000000000..7841b6116 --- /dev/null +++ b/app/views/stop_points/_stop_point_draggable.html.erb @@ -0,0 +1,18 @@ +<%= div_for(stop_point) do %> + <div class="handle" alt="<%= t('stop_points.index.move') %>" title="<%= t('stop_points.index.move') %>" ><%= image_tag "icons/move.png" %></div> + <span class="position"> + <%= stop_point.position + 1 %> + </span> + <%= stop_point.stop_area.name %> + <div class="info"> + <%= t('.lines') %> <% stop_point.stop_area.lines.reject { |l| l.id==@line.id}.each do |line| %> + <span class="line"><%= line.number %></span> + <% end %> - + <%= stop_point.stop_area.human_attribute_name('country_code') %> <%= stop_point.stop_area.country_code %> + <div class="actions"> + <%= link_to t("stop_points.actions.show"), referential_stop_area_path(@referential, stop_point.stop_area), :class => "link" %> | + <%= link_to t("actions.destroy"), referential_line_route_stop_point_path(@referential, @line, @route, stop_point), :method => :delete, :confirm => t('stop_points.actions.destroy_confirm'), :class => "remove" %> + </div> + </div> +<% end %> + diff --git a/app/views/stop_points/index.html.erb b/app/views/stop_points/index.html.erb index 54ba8cfe6..6f3b69ae0 100644 --- a/app/views/stop_points/index.html.erb +++ b/app/views/stop_points/index.html.erb @@ -13,29 +13,26 @@ </div> <h3><%= t('stop_points.index.subtitle')%></h3> -<% if @route.stop_points.empty? %> + <% if @route.stop_points.empty? %> <p><%= t('.no_stop_point') %></p> -<% end %> - <ul id="stop_areas"> - <% for stop_point in @route.stop_points %> - <%= content_tag_for :li, stop_point do %> - <div class="handle" alt="<%= t('stop_points.index.move') %>" title="<%= t('stop_points.index.move') %>" ><%= image_tag "icons/move.png" %></div> - <div class="description"> - <span class="position"> - <%= stop_point.position + 1 %> - </span> - <%= stop_point.stop_area.name %> - <div class="info"> - <%= stop_point.stop_area.human_attribute_name('country_code') %> <%= stop_point.stop_area.country_code %> - <div class="actions"> - <%= link_to t("stop_points.actions.show"), referential_stop_area_path(@referential, stop_point.stop_area), :class => "link" %> | - <%= link_to t("actions.destroy"), referential_line_route_stop_point_path(@referential, @line, @route, stop_point), :method => :delete, :confirm => t('stop_points.actions.destroy_confirm'), :class => "remove" %> - </div> - </div> - </div> - <% end %> + <% end %> + + <div id="sortable_stop_points"> + <%= render :partial => "stop_point_draggable", :collection => @route.stop_points, :as => :stop_point %> + </div> + <%= semantic_form_for( Chouette::StopPoint.new, + :url => sort_referential_line_route_stop_points_path( @referential, @line, @route), + :html => {:class => "formtastic stop_points_form"}) do |form| %> + <% @stop_points.each do |sp| %> + <input type="hidden" id="<%= "pos_#{sp.position}" %>" name="stop_point[]" value="<%= sp.id %>" /> <% end %> - </ul> + <%= form.buttons do %> + <%= form.commit_button t('.reorder_button') %> + <li><%= t('or') %></li> + <li><%= link_to t('cancel'), referential_line_route_stop_points_path(@referential, @line, @route) %></li> + <% end %> + <% end %> +</div> <% content_for :sidebar do %> <ul class="actions"> <li><%= link_to t('stop_points.actions.new'), new_referential_line_route_stop_point_path(@referential, @line, @route), :class => "add" %> @@ -46,25 +43,31 @@ // Sorting the list $(document).ready(function(){ - $('#stop_areas').sortable({ + $('#sortable_stop_points').sortable({ axis: 'y', dropOnEmpty: false, handle: '.handle', cursor: 'crosshair', - items: 'li', + items: '.stop_point', opacity: 0.4, scroll: true, update: function(){ - $.ajax({ - type: 'post', - data: $('#stop_areas').sortable('serialize'), - dataType: 'script', - complete: function(request){ - $('#stop_areas').effect('highlight'); - }, - url: "<%= sort_referential_line_route_stop_points_path( @referential, @line, @route)%>"}) + $('.stop_points_form input[name="stop_point[]"]').map(function(index,element){ + var stop_point_id =$('#sortable_stop_points .stop_point')[index].id.replace("stop_point_",""); + var before = $( element).attr("value"); + $( element).attr("value",stop_point_id); + var after = $( element).attr("value"); + console.log( "pos: "+index+", before: "+before+", after:"+after); + }); + // $.ajax({ + // type: 'post', + // data: $('#sortable_stop_points').sortable('serialize'), + // dataType: 'script', + // complete: function(request){ + // $('#sortable_stop_points').effect('highlight'); + // }, + // url: "<%= sort_referential_line_route_stop_points_path( @referential, @line, @route)%>"}) } }); }); </script> -</div> diff --git a/config/locales/companies.yml b/config/locales/companies.yml index b6b3db0d7..86af20ab2 100644 --- a/config/locales/companies.yml +++ b/config/locales/companies.yml @@ -17,7 +17,7 @@ en: activerecord: models: - company: "Companies" + company: Company attributes: company: registrationnumber: "Registration number" @@ -58,7 +58,7 @@ fr: activerecord: models: - company: "Transporteurs" + company: Transporteur attributes: company: registrationnumber: "Numéro d'enregistrement" diff --git a/config/locales/lines.yml b/config/locales/lines.yml index 7e565f24b..c585c5e13 100644 --- a/config/locales/lines.yml +++ b/config/locales/lines.yml @@ -15,8 +15,15 @@ en: index: title: Lines name_or_number: Name or number - selection: Selection + selection: Filter on selection_all: All + multi_selection: Multiple selection + multi_selection_enable: Enable multiple selection + multi_selection_disable: Disable multiple selection + delete_selected: Delete lines + export_selected: Export linges + select_all: Select all + deselect_all: Deselect all activerecord: models: line: Line @@ -53,12 +60,19 @@ fr: title: Modifier la ligne %{line} show: title: Ligne %{line} - itineraries: "Liste des itinéraires de la ligne" + itineraries: "Liste des séquences d'arrêts de la ligne" index: name_or_number: Nom ou indice title: Lignes - selection: Sélection + selection: Filtrer sur selection_all: Tous + multi_selection: Sélection multiple + multi_selection_enable: Activer la sélection multiple + multi_selection_disable: Désactiver la sélection multiple + delete_selected: Supprimer les lignes + export_selected: Exporter les lignes + select_all: Tout sélectionner + deselect_all: Tout désélectionner activerecord: models: line: Ligne diff --git a/config/locales/networks.yml b/config/locales/networks.yml index 6b0070933..06c7396cf 100644 --- a/config/locales/networks.yml +++ b/config/locales/networks.yml @@ -17,7 +17,7 @@ en: activerecord: models: - network: Networks + network: Network attributes: network: registrationnumber: "Registration number" diff --git a/config/locales/routes.yml b/config/locales/routes.yml index 149bdb508..e9422d2db 100644 --- a/config/locales/routes.yml +++ b/config/locales/routes.yml @@ -39,26 +39,26 @@ en: fr: routes: actions: - new: Ajouter un itinéraire - edit: Modifier cet itinéraire - destroy: Supprimer cet itinéraire - destroy_confirm: Etes vous sûr de détruire cet itinéraire ? + new: "Ajouter une séquence d'arrêts" + edit: "Modifier cette séquence d'arrêts" + destroy: "Supprimer cette séquence d'arrêts" + destroy_confirm: "Etes vous sûr de détruire cette séquence d'arrêts ?" new: - title: Ajouter un itinéraire + title: "Ajouter une séquence d'arrêts" edit: - title: "Modifier l'itinéraire %{route}" + title: "Modifier la séquence d'arrêts %{route}" show: - title: Itinéraire %{route} de la ligne %{line} - stop_points: "Liste des arrêts de l'itinéraire" - no_opposite_route: Aucun itinéraire associé en sens opposé + title: "Séquence d'arrêts %{route} de la ligne %{line}" + stop_areas: "Liste des arrêts de la séquence d'arrêts" + no_opposite_route: "Aucune séquence d'arrêts associée en sens opposé" undefined: Non défini index: - title: Itinéraires + title: "Séquences d'arrêts" selection: Sélection selection_all: Tous activerecord: models: - route: Itinéraire + route: "Séquence d'arrêts" attributes: route: line: Ligne @@ -68,7 +68,7 @@ fr: comment: Commentaire direction_code: Direction wayback_code: Sens - opposite_route: Itinéraire associé en sens opposé + opposite_route: "Séquence d'arrêts associée en sens opposé" objectid: Identifiant Neptune object_version: Version creation_time: Créé le diff --git a/config/locales/stop_areas.yml b/config/locales/stop_areas.yml index bb5d02869..c6d5f9274 100644 --- a/config/locales/stop_areas.yml +++ b/config/locales/stop_areas.yml @@ -22,7 +22,7 @@ en: index: title: Stop areas name_or_country_code: Name or Country code - selection: Selection + selection: Filter on selection_all: All area_type: Area Type select_parent: @@ -84,7 +84,7 @@ fr: index: name_or_country_code: Nom ou Code Postal title: Arrêts - selection: Sélection + selection: Filtrer sur selection_all: Tous area_type: Type d'arrêt select_parent: diff --git a/config/locales/stop_points.yml b/config/locales/stop_points.yml index 450b6924e..70f477d8e 100644 --- a/config/locales/stop_points.yml +++ b/config/locales/stop_points.yml @@ -1,5 +1,7 @@ en: stop_points: + reorder_success: "Reordering saved" + reorder_failure: "Fail in reordering" actions: show: Show index: Stops on route list @@ -11,6 +13,7 @@ en: title: Add a new stop route select_area: Select a stop area index: + reorder_button: Save reordering title: Stops on route %{route} subtitle: Stops on route ordered move: Move @@ -23,6 +26,8 @@ en: fr: stop_points: + reorder_success: "L'ordre a été mis à jour" + reorder_failure: "Echec de la mise à jour" actions: show: Consulter index: Liste des arrêts sur itinéraire @@ -34,8 +39,9 @@ fr: title: "Ajouter un arrêt à l'itinéraire %{route}" select_area: "Sélectionner un arrêt" index: + reorder_button: "Mettre à jour l'ordre de parcours" title: "Liste des arrêts de l'itinéraire %{route}" - subtitle: "Arrêts dans l'ordre du parcours " + subtitle: "Arrêts dans l'ordre " move: Déplacer no_stop_point: Aucun arrêt sur itinéraire activerecord: 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 |
