diff options
| author | Marc Florisson | 2012-06-01 12:20:57 +0200 |
|---|---|---|
| committer | Marc Florisson | 2012-06-01 12:20:57 +0200 |
| commit | ee866a45955bac5cef7a8bdec58f86ffcb7cb702 (patch) | |
| tree | e66d3da0e628034afc362b524b52a1a71977f4ff | |
| parent | 7fd20ad1409398e06fb1167332c57b4ac4c9aadc (diff) | |
| parent | 7082d66ec221aee194d64a17ab5d21eb2955f419 (diff) | |
| download | chouette-core-ee866a45955bac5cef7a8bdec58f86ffcb7cb702.tar.bz2 | |
Merge branch 'master' of chouette.dryade.priv:/srv/git/chouette2
51 files changed, 380 insertions, 70 deletions
diff --git a/.gitignore b/.gitignore index 4dcf29e87..d96f025d0 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,5 @@ public/assets/ *.swp *.swo .DS_Store +chouette2.war +vendor/bundle @@ -5,7 +5,7 @@ gem 'jquery-rails' gem 'devise' gem "ffi-proj4", :git => 'git://github.com/dryade/ffi-proj4.git' - +gem "jruby-rack-worker" platforms :jruby do gem 'activerecord-jdbcpostgresql-adapter', :git => 'git://github.com/dryade/activerecord-jdbc-adapter.git' diff --git a/Gemfile.lock b/Gemfile.lock index 03062f915..b09c6fafc 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -71,6 +71,7 @@ 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) @@ -107,6 +108,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) @@ -157,6 +159,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) ffi-geos (0.0.4) ffi (~> 1.0.0) @@ -185,8 +188,13 @@ GEM jruby-openssl (0.7.6.1) bouncy-castle-java (>= 1.5.0146.1) jruby-rack (1.1.5) + jruby-rack-worker (0.3-java) + jruby-rack (>= 1.0.1) + json (1.7.3) json (1.7.3-java) json_pure (1.7.3) + launchy (2.1.0) + addressable (~> 2.2.6) launchy (2.1.0-java) addressable (~> 2.2.6) ffi (~> 1.0.9) @@ -207,6 +215,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) @@ -345,6 +354,7 @@ DEPENDENCIES inherited_resources jquery-rails jruby-openssl + jruby-rack-worker json launchy map_layers (~> 0.0.4) diff --git a/app/assets/images/severity-error.png b/app/assets/images/severity-error.png Binary files differnew file mode 100644 index 000000000..516a4d61a --- /dev/null +++ b/app/assets/images/severity-error.png diff --git a/app/assets/images/severity-info.png b/app/assets/images/severity-info.png Binary files differnew file mode 100644 index 000000000..740170cb7 --- /dev/null +++ b/app/assets/images/severity-info.png diff --git a/app/assets/images/severity-warning.png b/app/assets/images/severity-warning.png Binary files differnew file mode 100644 index 000000000..661327276 --- /dev/null +++ b/app/assets/images/severity-warning.png diff --git a/app/assets/javascripts/multiple_selection.js.coffee b/app/assets/javascripts/multiple_selection.js.coffee index 0353a2755..1ff473c4d 100644 --- a/app/assets/javascripts/multiple_selection.js.coffee +++ b/app/assets/javascripts/multiple_selection.js.coffee @@ -27,11 +27,27 @@ jQuery -> $('#multiple_selection_menu a.deselect_all').click(deselect_all) - disabled_action = (event) -> + handle_multiple_action = (event) -> event.preventDefault() - alert("Fonction activee au prochain milestone") + link = $(event.target) - $('#multiple_selection_menu .actions a').click(disabled_action) + href = link.attr("href") + method = link.data('multiple-method') + csrf_token = $('meta[name=csrf-token]').attr('content') + csrf_param = $('meta[name=csrf-param]').attr('content') + form = $('<form method="post" action="' + href + '"></form>') + target = link.attr('target') + metadata_input = '<input name="_method" value="' + method + '" type="hidden" />' + if csrf_param? and csrf_token? + metadata_input += '<input name="' + csrf_param + '" value="' + csrf_token + '" type="hidden" />' + form.append($(input).clone()) for input in $('input[type=checkbox].multiple_selection:checked') + + form.attr('target', target) if target? + + form.hide().append(metadata_input).appendTo('body') + form.submit() + + $('#multiple_selection_menu .actions a.remove').click(handle_multiple_action) diff --git a/app/assets/stylesheets/imports.css.scss b/app/assets/stylesheets/imports.css.scss index dda468465..bdc3a65cd 100644 --- a/app/assets/stylesheets/imports.css.scss +++ b/app/assets/stylesheets/imports.css.scss @@ -23,3 +23,15 @@ padding-right: 10px; } } + +#workspace.imports.show { + table { + th { + text-align: center; + font-style: italic; + } + td.message, td.created_at, td.position { + padding: 0 20px; + } + } +}
\ No newline at end of file diff --git a/app/assets/stylesheets/lines.css.scss b/app/assets/stylesheets/lines.css.scss index c5370611c..07ed34e5b 100644 --- a/app/assets/stylesheets/lines.css.scss +++ b/app/assets/stylesheets/lines.css.scss @@ -24,6 +24,7 @@ width: 350px; float: left; padding-right: 10px; + position: relative; .color { width: 64px; diff --git a/app/assets/stylesheets/multiple_selection.scss b/app/assets/stylesheets/multiple_selection.scss index e7f64857f..f3792d902 100644 --- a/app/assets/stylesheets/multiple_selection.scss +++ b/app/assets/stylesheets/multiple_selection.scss @@ -1,5 +1,7 @@ input[type=checkbox].multiple_selection { margin-left: 25px; + position: absolute; + top: 50px; } #multiple_selection_menu { diff --git a/app/controllers/lines_controller.rb b/app/controllers/lines_controller.rb index 42a126169..e14baf211 100644 --- a/app/controllers/lines_controller.rb +++ b/app/controllers/lines_controller.rb @@ -12,6 +12,13 @@ class LinesController < ChouetteController show! end + def destroy_all + objects = + get_collection_ivar || set_collection_ivar(end_of_association_chain.where(:id => params[:ids])) + objects.destroy_all + respond_with(objects, :location => smart_collection_url) + end + protected def collection diff --git a/app/maps/application_map.rb b/app/maps/application_map.rb index a4d8a84ab..dffb2501c 100644 --- a/app/maps/application_map.rb +++ b/app/maps/application_map.rb @@ -34,7 +34,9 @@ class ApplicationMap end def to_html(options = {}) - "<div id=\"#{id}\" class=\"#{default_class}\"></div> #{map.to_html(options)}" + if not respond_to?(:ready?) or ready? + "<div id=\"#{id}\" class=\"#{default_class}\"></div> #{map.to_html(options)}".html_safe + end end def kml diff --git a/app/maps/connection_link_map.rb b/app/maps/connection_link_map.rb index e915c3ae2..a6fb8517c 100644 --- a/app/maps/connection_link_map.rb +++ b/app/maps/connection_link_map.rb @@ -23,6 +23,10 @@ class ConnectionLinkMap < ApplicationMap end end + def ready? + Chouette::StopArea.bounds.present? + end + def bounds wgs84_bounds = Chouette::StopArea.bounds @bounds ||= OpenLayers::Bounds.new(wgs84_bounds.lower_corner.x, wgs84_bounds.lower_corner.y, wgs84_bounds.upper_corner.x, wgs84_bounds.upper_corner.y).transform(OpenLayers::Projection.new("EPSG:4326"), OpenLayers::Projection.new("EPSG:900913")) diff --git a/app/maps/line_map.rb b/app/maps/line_map.rb index 128b98dd2..a7a9f892d 100644 --- a/app/maps/line_map.rb +++ b/app/maps/line_map.rb @@ -29,4 +29,8 @@ class LineMap < ApplicationMap end + def ready? + Chouette::StopArea.bounds.present? + end + end diff --git a/app/maps/network_map.rb b/app/maps/network_map.rb index cedabdf6e..35283a48f 100644 --- a/app/maps/network_map.rb +++ b/app/maps/network_map.rb @@ -28,4 +28,8 @@ class NetworkMap < ApplicationMap end + def ready? + Chouette::StopArea.bounds.present? + end + end diff --git a/app/maps/route_map.rb b/app/maps/route_map.rb index 417b6037a..7cc525dde 100644 --- a/app/maps/route_map.rb +++ b/app/maps/route_map.rb @@ -22,12 +22,18 @@ class RouteMap < ApplicationMap end end + def ready? + route_bounds.present? + end + + def route_bounds + @route_bound ||= (route.geometry.empty? ? Chouette::StopArea.bounds : route.geometry.envelope) + end + def bounds - wgs84_bounds = ( route.geometry.empty?) ? Chouette::StopArea.bounds : route.geometry.envelope - @bounds ||= OpenLayers::Bounds.new( - wgs84_bounds.lower_corner.x, wgs84_bounds.lower_corner.y, - wgs84_bounds.upper_corner.x, wgs84_bounds.upper_corner.y). + route_bounds.lower_corner.x, route_bounds.lower_corner.y, + route_bounds.upper_corner.x, route_bounds.upper_corner.y). transform(OpenLayers::Projection.new("EPSG:4326"), OpenLayers::Projection.new("EPSG:900913")) end diff --git a/app/maps/stop_area_map.rb b/app/maps/stop_area_map.rb index 37ba77121..b7c060dce 100644 --- a/app/maps/stop_area_map.rb +++ b/app/maps/stop_area_map.rb @@ -40,6 +40,10 @@ EOF end end + def ready? + center.present? + end + def center stop_area.geometry or stop_area.default_position end diff --git a/app/models/import.rb b/app/models/import.rb index fd3fb139d..64b5b5624 100644 --- a/app/models/import.rb +++ b/app/models/import.rb @@ -9,6 +9,8 @@ class Import < ActiveRecord::Base attr_accessor :resources attr_accessor :loader + has_many :log_messages, :class_name => "ImportLogMessage", :order => :position, :dependent => :destroy + def loader @loader ||= ::Chouette::Loader.new(referential.slug) end @@ -26,7 +28,7 @@ class Import < ActiveRecord::Base self.status ||= "pending" end - after_create :import + after_create :delayed_import def delayed_import save_resources delay.import @@ -49,8 +51,13 @@ class Import < ActiveRecord::Base "#{root}/#{id}.zip" end + def name + "#{Import.model_name.humanize} #{id}" + end + def import begin + log_messages.create :key => :started if resources with_original_filename do |file| # chouette-command checks the file extension (and requires .zip) :( @@ -64,6 +71,7 @@ class Import < ActiveRecord::Base Rails.logger.error "Import #{id} failed : #{e}, #{e.backtrace}" update_attribute :status, "failed" end + log_messages.create :key => status end end diff --git a/app/models/import_log_message.rb b/app/models/import_log_message.rb new file mode 100644 index 000000000..699c9603d --- /dev/null +++ b/app/models/import_log_message.rb @@ -0,0 +1,36 @@ +class ImportLogMessage < ActiveRecord::Base + belongs_to :import + acts_as_list :scope => :import + + validates_presence_of :key + validates_inclusion_of :severity, :in => %w{info warning error} + + def arguments=(arguments) + write_attribute :arguments, (arguments.to_json if arguments.present?) + end + + def arguments + @decoded_arguments ||= + begin + if (stored_arguments = raw_attributes).present? + ActiveSupport::JSON.decode stored_arguments + else + {} + end + end + end + + def raw_attributes + read_attribute(:arguments) + end + + before_validation :define_default_attributes, :on => :create + def define_default_attributes + self.severity ||= "info" + end + + def full_message + I18n.translate key, arguments.symbolize_keys.merge(:scope => "import_log_messages.messages") + end + +end diff --git a/app/models/referential.rb b/app/models/referential.rb index 84640e43c..d7c5bba7e 100644 --- a/app/models/referential.rb +++ b/app/models/referential.rb @@ -34,44 +34,15 @@ class Referential < ActiveRecord::Base self end - before_create :prepare + before_create :create_schema before_destroy :destroy_schema - attr_accessor :resources - attr_accessor :loader - - def loader - @loader ||= ::Chouette::Loader.new(slug) - end + after_create :import_resources - def prepare - if resources - import_resources - else - create_schema - end - end - - def with_original_filename - Dir.mktmpdir do |tmp_dir| - tmp_link = File.join(tmp_dir, resources.original_filename) - FileUtils.ln_s resources.path, tmp_link - yield tmp_link - end - end + attr_accessor :resources def import_resources - # Apartment::Database.create create tables - loader.create - begin - with_original_filename do |file| - # chouette-command checks the file extension (and requires .zip) :( - loader.import file - end - rescue => e - loader.drop - raise e - end + imports.create(:resources => resources) if resources end def create_schema diff --git a/app/views/connection_links/show.html.erb b/app/views/connection_links/show.html.erb index 273d9102e..abc2db3de 100644 --- a/app/views/connection_links/show.html.erb +++ b/app/views/connection_links/show.html.erb @@ -1,7 +1,7 @@ <%= title_tag t('connection_links.show.title', :connection_link => @connection_link.name ) %> <div class="connection_link_show"> - <%= @map.to_html.html_safe %> + <%= @map.to_html %> <div class="summary"> <p> diff --git a/app/views/imports/_import.erb b/app/views/imports/_import.erb index 643b3f18b..6ccd5bb23 100644 --- a/app/views/imports/_import.erb +++ b/app/views/imports/_import.erb @@ -1,8 +1,8 @@ <%= div_for(import) do %> - <%= link_to("#", :class => "preview") do %> + <%= link_to(referential_import_path(@referential, import), :class => "preview") do %> <%= image_tag "import-#{import.status}.png" %> <% end %> - <%= Import.model_name.humanize %> <%= import.id %> + <%= link_to(import.name, referential_import_path(@referential, import)) %> <div class="info"> <%= l import.created_at %> diff --git a/app/views/imports/show.html.erb b/app/views/imports/show.html.erb new file mode 100644 index 000000000..fe2c89a39 --- /dev/null +++ b/app/views/imports/show.html.erb @@ -0,0 +1,38 @@ +<%= title_tag @import.name %> + +<div class="import_show"> + <div class="summary"> + <p> + <label><%= Import.human_attribute_name(:created_at) %>: </label> + <%= l @import.created_at %> + </p> + <p> + <label><%= Import.human_attribute_name(:status) %>: </label> + <%= t @import.status, :scope => "imports.statuses" %> + </p> + </div> + + <h3><%= t(".report") %></h3> + <table> + <tr> + <th></th> + <th><%= ImportLogMessage.human_attribute_name(:created_at) %></th> + <th><%= ImportLogMessage.human_attribute_name(:position) %></th> + <th><%= ImportLogMessage.human_attribute_name(:full_message) %></th> + </tr> + <% @import.log_messages.each do |message| %> + <tr> + <td class="severity"><%= image_tag "severity-#{message.severity}.png", :alt => t(message.severity, :scope => "import_log_messages.severities") %></td> + <td class="created_at"><%= l message.created_at, :format => :short %></td> + <td class="position"><%= message.position %></td> + <td class="message"><%= message.full_message %></td> + </tr> + <% end %> + </table> +</div> + +<% content_for :sidebar do %> +<ul class="actions"> + <li><%= link_to t('imports.actions.destroy'), referential_import_path(@referential, @import), :method => :delete, :confirm => t('imports.actions.destroy_confirm'), :class => "remove" %></li> +</ul> +<% end %> diff --git a/app/views/lines/_line.erb b/app/views/lines/_line.erb index 5405bcbb5..3565966fb 100644 --- a/app/views/lines/_line.erb +++ b/app/views/lines/_line.erb @@ -2,11 +2,11 @@ <%= link_to([@referential, line], :class => "preview", :title => "Ligne #{line.number}") do %> <div class="color"> <% if line.number and line.number.length <= 3 %> - <div class="number"><%= line.number %></div> + <div class="number"><%= line.number %></div> <% end %> - <%= check_box_tag "ids[]", line.id, false, :class => "multiple_selection", :style => "display: none;" %> </div> <% end %> + <%= check_box_tag "ids[]", line.id, false, :class => "multiple_selection", :style => "display: none;" %> <%= link_to truncate(line.name, :length => 30), [@referential, line], :title => "Ligne #{line.name}" %> <div class="info"> <%= line.human_attribute_name('network') %> <%= link_to_if line.network, line.network.name, referential_network_path(@referential, line.network), :title => "#{line.human_attribute_name('network')} #{line.network.name}" %> - diff --git a/app/views/lines/index.html.erb b/app/views/lines/index.html.erb index c39e94cbd..8c9766866 100644 --- a/app/views/lines/index.html.erb +++ b/app/views/lines/index.html.erb @@ -75,7 +75,7 @@ <a class="disable" href="#"><%= t(".multi_selection_disable") %></a> <ul class="actions"> - <li><a href="#" class="remove"><%= t(".delete_selected") %></a></li> + <%= link_to t(".delete_selected"), referential_lines_path(@referential), "data-multiple-method" => "delete", :class => "remove" %> <li><a href="#" class="export"><%= t(".export_selected") %></a></li> </ul> diff --git a/app/views/lines/show.html.erb b/app/views/lines/show.html.erb index 8d6157cc7..5e210ff5e 100644 --- a/app/views/lines/show.html.erb +++ b/app/views/lines/show.html.erb @@ -1,7 +1,7 @@ <%= title_tag t('lines.show.title', :line => @line.name ) %> <div class="line_show"> - <%= @map.to_html.html_safe %> + <%= @map.to_html %> <div class="summary"> <p> diff --git a/app/views/networks/show.html.erb b/app/views/networks/show.html.erb index b11cde17d..8c68f7a31 100644 --- a/app/views/networks/show.html.erb +++ b/app/views/networks/show.html.erb @@ -1,7 +1,7 @@ <%= title_tag t('networks.show.title', :network => @network.name )%> <div class="network_show"> - <%= @map.to_html.html_safe %> + <%= @map.to_html %> <div class="summary"> <p> <label><%= Chouette::Network.human_attribute_name("name") %>: </label> diff --git a/app/views/routes/show.html.erb b/app/views/routes/show.html.erb index 2ecbd0ada..72524846b 100644 --- a/app/views/routes/show.html.erb +++ b/app/views/routes/show.html.erb @@ -1,7 +1,7 @@ <%= title_tag t('routes.show.title', :route => @route.name, :line => @route.line.name ) %> <div class="route_show"> - <%= @map.to_html.html_safe %> + <%= @map.to_html %> <div class="summary"> <p> diff --git a/app/views/stop_areas/edit.html.erb b/app/views/stop_areas/edit.html.erb index be09d94e0..1ec77056d 100644 --- a/app/views/stop_areas/edit.html.erb +++ b/app/views/stop_areas/edit.html.erb @@ -1,5 +1,5 @@ <%= title_tag t('stop_areas.edit.title', :stop_area => @stop_area.name ) %> -<%= @map.to_html.html_safe %> +<%= @map.to_html %> <%= render "form" %> diff --git a/app/views/stop_areas/show.html.erb b/app/views/stop_areas/show.html.erb index 992a4050b..41d7576b5 100644 --- a/app/views/stop_areas/show.html.erb +++ b/app/views/stop_areas/show.html.erb @@ -1,7 +1,7 @@ <%= title_tag t('stop_areas.show.title', :stop_area => @stop_area.name ) %> <div class="stop_area_show"> - <%= @map.to_html.html_safe %> + <%= @map.to_html %> <div class="summary"> <p> <label><%= @stop_area.human_attribute_name("name") %>: </label> diff --git a/config/environments/production.rb b/config/environments/production.rb index a121daab6..d79d98df7 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -36,7 +36,7 @@ ChouetteIhm::Application.configure do # Use a different logger for distributed setups require 'syslog_logger' config.logger = SyslogLogger.new("rails/chouette2").tap do |logger| - logger.level = Logger::INFO + # logger.level = Logger::INFO end # Use a different cache store in production diff --git a/config/initializers/apartment.rb b/config/initializers/apartment.rb index be6b7e933..20263f5c6 100644 --- a/config/initializers/apartment.rb +++ b/config/initializers/apartment.rb @@ -1,6 +1,6 @@ Apartment.configure do |config| # set your options (described below) here - config.excluded_models = ["Referential", "User", "Import", "Delayed::Backend::ActiveRecord::Job"] # these models will not be multi-tenanted, but remain in the global (public) namespace + config.excluded_models = ["Referential", "User", "Import", "ImportLogMessage", "Delayed::Backend::ActiveRecord::Job"] # these models will not be multi-tenanted, but remain in the global (public) namespace # Dynamically get database names to migrate config.database_names = lambda{ Referential.select(:slug).map(&:slug) } diff --git a/config/initializers/db_migrate_in_war.rb b/config/initializers/db_migrate_in_war.rb new file mode 100644 index 000000000..ccba79773 --- /dev/null +++ b/config/initializers/db_migrate_in_war.rb @@ -0,0 +1,10 @@ +Rails.configuration.after_initialize do + Rails.logger.info "Migrating database" + ActiveRecord::Migrator.migrate("db/migrate/", nil) + + Apartment.database_names.each do |db| + Rails.logger.info "Migrating #{db} schema" + Apartment::Migrator.migrate db + end +end if ENV["CHOUETTE_RUN_MIGRATIONS"] == "true" + diff --git a/config/locales/imports.yml b/config/locales/imports.yml index d4c8b2d7c..40db6d65e 100644 --- a/config/locales/imports.yml +++ b/config/locales/imports.yml @@ -8,6 +8,21 @@ en: title: New import index: title: Imports + show: + report: Report + statuses: + pending: Pending + completed: Completed + failed: Failed + import_log_messages: + messages: + started: Started import + completed: Completed import + failed: Failed import + severities: + info: Information + warning: Warning + error: Error activerecord: models: import: @@ -17,16 +32,36 @@ en: attributes: import: resources: File to import + status: Status + import_log_message: + created_at: Date + position: N. + full_message: Message fr: imports: actions: new: Nouvel import - destroy: Supprimer + destroy: Supprimer cet import destroy_confirm: Etes vous sûr de détruire cet import ? new: title: Nouvel import index: title: Imports + show: + report: Rapport + statuses: + pending: En cours + completed: Achevé + failed: Echoué + import_log_messages: + messages: + started: Import démarré + completed: Import achevé avec succès + failed: Import interromptu + severities: + info: Information + warning: Alerte + error: Erreur activerecord: models: import: @@ -36,3 +71,8 @@ fr: attributes: import: resources: Fichier à importer + status: Status + import_log_message: + created_at: Date + position: "No" + full_message: Message diff --git a/config/routes.rb b/config/routes.rb index 4e8d75a9c..5e5f68b72 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -20,6 +20,7 @@ ChouetteIhm::Application.routes.draw do # resources :products resources :referentials do resources :stop_point_areas + match 'lines' => 'lines#destroy_all', :via => :delete resources :lines, :networks do resources :stop_areas do resources :stop_area_parents diff --git a/config/war_init.rb b/config/war_init.rb new file mode 100644 index 000000000..756bc5926 --- /dev/null +++ b/config/war_init.rb @@ -0,0 +1 @@ +ENV["CHOUETTE_RUN_MIGRATIONS"] = "true" diff --git a/config/warble.rb b/config/warble.rb index 70a4ca946..11c6bf090 100644 --- a/config/warble.rb +++ b/config/warble.rb @@ -42,7 +42,7 @@ Warbler::Config.new do |config| # An array of Bundler groups to avoid including in the war file. # Defaults to ["development", "test"]. - # config.bundle_without = [] + config.bundle_without = %w{development test assets} # Other gems to be included. If you don't use Bundler or a gemspec # file, you need to tell Warbler which gems your application needs @@ -78,7 +78,7 @@ Warbler::Config.new do |config| # Name of the archive (without the extension). Defaults to the basename # of the project directory. - # config.jar_name = "mywar" + config.jar_name = "chouette2" # Name of the MANIFEST.MF template for the war file. Defaults to a simple # MANIFEST.MF that contains the version of Warbler used to create the war file. @@ -134,9 +134,22 @@ Warbler::Config.new do |config| # Control the pool of Rails runtimes. Leaving unspecified means # the pool will grow as needed to service requests. It is recommended # that you fix these values when running a production server! - # config.webxml.jruby.min.runtimes = 2 - # config.webxml.jruby.max.runtimes = 4 + config.webxml.jruby.min.runtimes = 2 + config.webxml.jruby.max.runtimes = 4 + + config.webxml.jruby.worker.script = <<EOF +Rails.logger.info "start Delayed::JRubyWorker" +begin +require 'delayed/jruby_worker' +Delayed::JRubyWorker.new(:quiet => false).start +rescue => e + Rails.logger.fatal(e) + raise e +end +EOF # JNDI data source name # config.webxml.jndi = 'jdbc/rails' + + config.init_contents << "config/war_init.rb" end diff --git a/config/web.xml.erb b/config/web.xml.erb new file mode 100644 index 000000000..af962f3b7 --- /dev/null +++ b/config/web.xml.erb @@ -0,0 +1,36 @@ +<!DOCTYPE web-app PUBLIC + "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" + "http://java.sun.com/dtd/web-app_2_3.dtd"> +<web-app> +<% webxml.context_params.each do |k,v| %> + <context-param> + <param-name><%= k %></param-name> + <param-value><%= v %></param-value> + </context-param> +<% end %> + + <filter> + <filter-name>RackFilter</filter-name> + <filter-class>org.jruby.rack.RackFilter</filter-class> + </filter> + <filter-mapping> + <filter-name>RackFilter</filter-name> + <url-pattern>/*</url-pattern> + </filter-mapping> + + <listener> + <listener-class><%= webxml.servlet_context_listener %></listener-class> + </listener> + + <listener> + <listener-class>org.kares.jruby.rack.WorkerContextListener</listener-class> + </listener> + +<% if webxml.jndi then [webxml.jndi].flatten.each do |jndi| %> + <resource-ref> + <res-ref-name><%= jndi %></res-ref-name> + <res-type>javax.sql.DataSource</res-type> + <res-auth>Container</res-auth> + </resource-ref> +<% end; end %> +</web-app> diff --git a/db/migrate/20120529154848_create_import_log_messages.rb b/db/migrate/20120529154848_create_import_log_messages.rb new file mode 100644 index 000000000..b39a9eda7 --- /dev/null +++ b/db/migrate/20120529154848_create_import_log_messages.rb @@ -0,0 +1,14 @@ +class CreateImportLogMessages < ActiveRecord::Migration + def change + create_table :import_log_messages do |t| + t.belongs_to :import + t.string :key + t.string :arguments + t.integer :position + t.string :severity + + t.timestamps + end + add_index :import_log_messages, :import_id + end +end diff --git a/db/schema.rb b/db/schema.rb index 86aebcd98..ed4c93693 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20120516172252) do +ActiveRecord::Schema.define(:version => 20120529154848) do create_table "company", :force => true do |t| t.string "objectid" @@ -70,6 +70,18 @@ ActiveRecord::Schema.define(:version => 20120516172252) do add_index "delayed_jobs", ["priority", "run_at"], :name => "delayed_jobs_priority" + create_table "import_log_messages", :force => true do |t| + t.integer "import_id" + t.string "key" + t.string "arguments" + t.integer "position" + t.string "severity" + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "import_log_messages", ["import_id"], :name => "index_import_log_messages_on_import_id" + create_table "imports", :force => true do |t| t.integer "referential_id" t.string "status" diff --git a/lib/tasks/ci.rake b/lib/tasks/ci.rake index 9c541129b..cfd68a1cf 100644 --- a/lib/tasks/ci.rake +++ b/lib/tasks/ci.rake @@ -3,7 +3,7 @@ namespace :ci do cp "config/database.yml.ccontrol", "config/database.yml" end task :deploy do - cp "workspace.war", "/var/lib/tomcat6/webapps/chouette2.war" + cp "chouette2.war", "/var/lib/tomcat6/webapps/" end task :build => ["db:migrate", "spec", "war", "ci:deploy"] end diff --git a/spec/factories.rb b/spec/factories.rb index b77102321..c5c1c0ff0 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -11,4 +11,14 @@ FactoryGirl.define do f.password_confirmation "secret" end + factory :import do |f| + f.resources { Rack::Test::UploadedFile.new 'spec/fixtures/neptune.zip', 'application/zip', false } + f.association :referential + end + + factory :import_log_message do |f| + f.association :import + f.sequence(:key) { "key_#{n}" } + end + end diff --git a/spec/fixtures/neptune.zip b/spec/fixtures/neptune.zip Binary files differnew file mode 100644 index 000000000..86b688b51 --- /dev/null +++ b/spec/fixtures/neptune.zip diff --git a/spec/models/import_log_message_spec.rb b/spec/models/import_log_message_spec.rb new file mode 100644 index 000000000..dab951255 --- /dev/null +++ b/spec/models/import_log_message_spec.rb @@ -0,0 +1,16 @@ +require 'spec_helper' + +describe ImportLogMessage do + + describe "#attributes" do + + subject { create :import_log_message } + + it "should read json stored in database" do + subject.update_attribute :arguments, { "key" => "value"} + subject.raw_attributes.should == { "key" => "value"}.to_json + end + + end + +end diff --git a/spec/models/import_spec.rb b/spec/models/import_spec.rb index 734445b8b..f307b59db 100644 --- a/spec/models/import_spec.rb +++ b/spec/models/import_spec.rb @@ -1,7 +1,37 @@ require 'spec_helper' describe Import do + + subject { create :import } + + RSpec::Matchers.define :be_log_message do |expected| + match do |actual| + actual and expected.all? { |k,v| actual[k.to_s] == v } + end + end - + describe "#import" do + + before(:each) do + subject.stub :loader => mock(:import => true) + end + + it "should create a ImportLogmessage :started when started" do + subject.import + subject.log_messages.first.should be_log_message(:key => "started") + end + + it "should create a ImportLogmessage :completed when completed" do + subject.import + subject.log_messages.last.should be_log_message(:key => "completed") + end + + it "should create a ImportLogmessage :failed when failed" do + subject.loader.stub(:import).and_raise("import failed") + subject.import + subject.log_messages.last.should be_log_message(:key => "failed") + end + + end end diff --git a/spec/views/connection_links/show.html.erb_spec.rb b/spec/views/connection_links/show.html.erb_spec.rb index 8a03f5339..80d3adfb6 100644 --- a/spec/views/connection_links/show.html.erb_spec.rb +++ b/spec/views/connection_links/show.html.erb_spec.rb @@ -4,7 +4,7 @@ describe "/connection_links/show" do let!(:referential) { assign(:referential, create(:referential)) } let!(:connection_link) { assign(:connection_link, create(:connection_link)) } - let!(:map) { assign(:map, mock(:to_html => '<div id="map"/>')) } + let!(:map) { assign(:map, mock(:to_html => '<div id="map"/>'.html_safe)) } it "should render h2 with the connection_link name" do render diff --git a/spec/views/lines/show.html.erb_spec.rb b/spec/views/lines/show.html.erb_spec.rb index 42261005a..f77722672 100644 --- a/spec/views/lines/show.html.erb_spec.rb +++ b/spec/views/lines/show.html.erb_spec.rb @@ -5,7 +5,7 @@ describe "/lines/show" do let!(:referential) { assign :referential, create(:referential) } let!(:line) { assign :line, create(:line) } let!(:routes) { assign :routes, Array.new(2) { create(:route, :line => line) }.paginate } - let!(:map) { assign(:map, mock(:to_html => '<div id="map"/>')) } + let!(:map) { assign(:map, mock(:to_html => '<div id="map"/>'.html_safe)) } it "should render h2 with the line name" do render diff --git a/spec/views/networks/show.html.erb_spec.rb b/spec/views/networks/show.html.erb_spec.rb index 9c05fe4aa..08ecdd95d 100644 --- a/spec/views/networks/show.html.erb_spec.rb +++ b/spec/views/networks/show.html.erb_spec.rb @@ -4,7 +4,7 @@ describe "/networks/show" do let!(:referential) { assign(:referential, create(:referential)) } let!(:network) { assign(:network, create(:network)) } - let!(:map) { assign(:map, mock(:to_html => '<div id="map"/>')) } + let!(:map) { assign(:map, mock(:to_html => '<div id="map"/>'.html_safe)) } it "should render h2 with the network name" do render diff --git a/spec/views/routes/show.html.erb_spec.rb b/spec/views/routes/show.html.erb_spec.rb index 5fa7485b7..2f39adb9a 100644 --- a/spec/views/routes/show.html.erb_spec.rb +++ b/spec/views/routes/show.html.erb_spec.rb @@ -6,7 +6,7 @@ describe "/routes/show" do let!(:line) { assign :line, create(:line) } let!(:route) { assign :route, create(:route, :line => line) } let!(:stop_points) { assign :stop_points, Array.new(2) { create(:stop_point) }.paginate } - let!(:map) { assign(:map, mock(:to_html => '<div id="map"/>')) } + let!(:map) { assign(:map, mock(:to_html => '<div id="map"/>'.html_safe)) } it "should render h2 with the route name" do render diff --git a/spec/views/stop_areas/edit.html.erb_spec.rb b/spec/views/stop_areas/edit.html.erb_spec.rb index c3b89918d..17e9ca104 100644 --- a/spec/views/stop_areas/edit.html.erb_spec.rb +++ b/spec/views/stop_areas/edit.html.erb_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe "/stop_areas/edit" do let!(:referential) { assign(:referential, create(:referential)) } let!(:stop_area) { assign(:stop_area, create(:stop_area)) } - let!(:map) { assign(:map, mock(:to_html => '<div id="map"/>')) } + let!(:map) { assign(:map, mock(:to_html => '<div id="map"/>'.html_safe)) } describe "test" do it "should render h2 with the group name" do diff --git a/spec/views/stop_areas/show.html.erb_spec.rb b/spec/views/stop_areas/show.html.erb_spec.rb index 443a37232..b4be2c5e0 100644 --- a/spec/views/stop_areas/show.html.erb_spec.rb +++ b/spec/views/stop_areas/show.html.erb_spec.rb @@ -4,7 +4,7 @@ describe "/stop_areas/show" do let!(:referential) { assign :referential, create(:referential) } let!(:stop_area) { assign :stop_area, create(:stop_area) } - let!(:map) { assign(:map, mock(:to_html => '<div id="map"/>')) } + let!(:map) { assign(:map, mock(:to_html => '<div id="map"/>'.html_safe)) } it "should render h2 with the stop_area name" do render |
