aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXinhui2017-02-22 16:04:53 +0100
committerXinhui2017-02-22 16:04:53 +0100
commit77d4aca6f3328e7918077e7f6c32462cf95caa84 (patch)
tree1ea07d2e34fc3f07a177c12c243765294f7b1926
parentb88cd552930099714000393584355c314f045cb6 (diff)
parent15e221c2fe06ebd6ca18d7a392ab05f95b59be74 (diff)
downloadchouette-core-77d4aca6f3328e7918077e7f6c32462cf95caa84.tar.bz2
Merge branch 'refactoring_import'
-rw-r--r--.gitignore3
-rw-r--r--Gemfile1
-rw-r--r--Gemfile.lock5
-rw-r--r--app/controllers/imports_controller.rb109
-rw-r--r--app/helpers/breadcrumb_helper.rb10
-rw-r--r--app/models/import.rb90
-rw-r--r--app/models/import_message.rb7
-rw-r--r--app/models/import_resource.rb23
-rw-r--r--app/models/referential.rb1
-rw-r--r--app/models/workbench.rb2
-rw-r--r--app/uploaders/import_uploader.rb49
-rw-r--r--app/views/imports/_form.html.slim5
-rw-r--r--app/views/imports/_import.html.slim24
-rw-r--r--app/views/imports/_imports.html.slim9
-rw-r--r--app/views/imports/index.html.slim15
-rw-r--r--app/views/imports/index.js.slim1
-rw-r--r--app/views/imports/new.html.slim4
-rw-r--r--app/views/imports/show.html.slim21
-rw-r--r--app/views/shared/_header.html.slim3
-rw-r--r--config/locales/breadcrumbs.en.yml1
-rw-r--r--config/locales/breadcrumbs.fr.yml1
-rw-r--r--config/routes.rb13
-rw-r--r--db/migrate/20120515134710_create_imports.rb11
-rw-r--r--db/migrate/20161227104202_create_imports.rb14
-rw-r--r--db/migrate/20161227104741_add_file_to_imports.rb5
-rw-r--r--db/migrate/20161228102458_create_import_messages.rb13
-rw-r--r--db/migrate/20161228103628_create_import_resources.rb10
-rw-r--r--db/schema.rb39
-rw-r--r--spec/controllers/imports_controller_spec.rb14
-rw-r--r--spec/controllers/vehicle_journey_imports_controller_spec.rb2
-rw-r--r--spec/factories/import_messages.rb10
-rw-r--r--spec/factories/import_resources.rb6
-rw-r--r--spec/factories/imports.rb11
-rw-r--r--spec/models/import_message_spec.rb7
-rw-r--r--spec/models/import_resource_spec.rb13
-rw-r--r--spec/models/import_spec.rb8
36 files changed, 286 insertions, 274 deletions
diff --git a/.gitignore b/.gitignore
index 4bd57ce25..1bca870cb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -31,5 +31,8 @@ coverage
bin/
+# Ignore uploaded files
+/public/uploads
+
# Ignore node modules
/node_modules
diff --git a/Gemfile b/Gemfile
index 306689e6c..38dd85736 100644
--- a/Gemfile
+++ b/Gemfile
@@ -120,6 +120,7 @@ gem 'acts_as_list', '~> 0.6.0'
gem 'acts_as_tree', '~> 2.1.0', require: 'acts_as_tree'
gem 'rabl'
+gem 'carrierwave', '~> 1.0'
gem 'sidekiq'
gem 'sinatra'
diff --git a/Gemfile.lock b/Gemfile.lock
index f152ffd08..1c9f275e5 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -115,6 +115,10 @@ GEM
rack (>= 1.0.0)
rack-test (>= 0.5.4)
xpath (~> 2.0)
+ carrierwave (1.0.0)
+ activemodel (>= 4.0.0)
+ activesupport (>= 4.0.0)
+ mime-types (>= 1.16)
celluloid (0.16.0)
timers (~> 4.0.0)
choice (0.1.7)
@@ -600,6 +604,7 @@ DEPENDENCIES
capistrano-ext
capistrano-npm
capybara (~> 2.4.0)
+ carrierwave (~> 1.0)
cocoon
codifligne!
coffee-rails (~> 4.0.0)
diff --git a/app/controllers/imports_controller.rb b/app/controllers/imports_controller.rb
index 757e7f09e..3eab7e66b 100644
--- a/app/controllers/imports_controller.rb
+++ b/app/controllers/imports_controller.rb
@@ -1,110 +1,29 @@
-# coding: utf-8
-require 'will_paginate/array'
-require 'open-uri'
-
-class ImportsController < ChouetteController
+class ImportsController < BreadcrumbController
defaults :resource_class => Import
-
- respond_to :html, :only => [:show, :index, :destroy, :imported_file, :rule_parameter_set, :compliance_check]
- respond_to :js, :only => [:index, :compliance_check]
- belongs_to :referential
-
- def index
- begin
- index! do
- build_breadcrumb :index
- end
- rescue Ievkit::Error, Faraday::Error => error
- logger.error("Iev failure : #{error.message}")
- flash[:error] = t(error.locale_for_error)
- redirect_to referential_path(@referential)
- end
- end
+ respond_to :html
+ belongs_to :workbench
def show
- begin
- show! do
- build_breadcrumb :show
- end
- rescue Ievkit::Error, Faraday::Error => error
- logger.error("Iev failure : #{error.message}")
- flash[:error] = t(error.locale_for_error)
- redirect_to referential_path(@referential)
- end
- end
-
- def destroy
- begin
- destroy!
- rescue Ievkit::Error, Faraday::Error => error
- logger.error("Iev failure : #{error.message}")
- flash[:error] = t(error.locale_for_error)
- redirect_to referential_path(@referential)
- end
- end
-
- def imported_file
- # WARNING : files under 10kb in size get treated as StringIO by OpenUri
- # http://stackoverflow.com/questions/10496874/why-does-openuri-treat-files-under-10kb-in-size-as-stringio
- OpenURI::Buffer.send :remove_const, 'StringMax' if OpenURI::Buffer.const_defined?('StringMax')
- OpenURI::Buffer.const_set 'StringMax', 0
- begin
- send_file open(resource.file_path), { :type => "application/#{resource.filename_extension}", :disposition => "attachment", :filename => resource.filename }
- rescue Ievkit::Error, Faraday::Error => error
- logger.error("Iev failure : #{error.message}")
- flash[:error] = t(error.locale_for_error)
- redirect_to referential_path(@referential)
- end
- end
-
- def rule_parameter_set
- begin
- @rule_parameter_set = resource.rule_parameter_set
- build_breadcrumb :rule_parameter_set
- render "rule_parameter_sets/show"
- rescue Ievkit::Error, Faraday::Error => error
- logger.error("Iev failure : #{error.message}")
- flash[:error] = t(error.locale_for_error)
- redirect_to referential_path(@referential)
+ show! do
+ build_breadcrumb :show
end
end
- def export
- respond_to do |format|
- format.zip { send_file ComplianceCheckExport.new(resource, @referential.id, request).export, :type => :zip }
+ def index
+ index! do
+ build_breadcrumb :index
end
end
- def compliance_check
- begin
- @compliance_check = resource
- build_breadcrumb :compliance_check
- render "compliance_checks/report"
- rescue Ievkit::Error, Faraday::Error => error
- logger.error("Iev failure : #{error.message}")
- flash[:error] = t(error.locale_for_error)
- redirect_to referential_path(@referential)
+ def new
+ new! do
+ build_breadcrumb :new
end
end
- protected
- alias_method :import, :resource
+ private
- def import_service
- ImportService.new(@referential)
+ def import_params
+ params.require(:import).permit(:name, :file, :referential_id)
end
-
- def resource
- @import ||= import_service.find( params[:id] )
- @line_items = @import.report.line_items
- if @line_items.size > 500
- @line_items = @line_items.paginate(page: params[:page], per_page: 20)
- end
- @import
- end
-
- def collection
- @imports ||= import_service.all.sort_by{ |import| import.created_at }.reverse.paginate(:page => params[:page])
- end
-
end
diff --git a/app/helpers/breadcrumb_helper.rb b/app/helpers/breadcrumb_helper.rb
index a382f1926..3a742d0dc 100644
--- a/app/helpers/breadcrumb_helper.rb
+++ b/app/helpers/breadcrumb_helper.rb
@@ -216,14 +216,10 @@ module BreadcrumbHelper
end
def import_breadcrumb (action)
- referential_breadcrumb
- add_breadcrumb Referential.human_attribute_name("imports"), referential_imports_path(@referential) unless action == :index
-
- add_breadcrumb @import.name, referential_import_path(@referential, @import.id) if @import
-
- #add_breadcrumb @rule_parameter_set.import.name, compliance_check_referential_import_path(@referential, @rule_parameter_set.import.id) if action == :rule_parameter_set
+ add_breadcrumb I18n.t("breadcrumbs.referentials"), referentials_path
+ add_breadcrumb breadcrumb_label(@workbench), workbench_path(@workbench), :title => breadcrumb_tooltip(@workbench)
+ add_breadcrumb I18n.t("breadcrumbs.imports"), workbench_imports_path(@workbench)
- #add_breadcrumb "Tests de conformité", compliance_check_referential_import_path(@referential, @compliance_check.id) if @compliance_check
end
def export_breadcrumb (action)
diff --git a/app/models/import.rb b/app/models/import.rb
index 078f1698e..8ffac5c5e 100644
--- a/app/models/import.rb
+++ b/app/models/import.rb
@@ -1,87 +1,7 @@
-require 'open-uri'
+class Import < ActiveRecord::Base
+ mount_uploader :file, ImportUploader
+ belongs_to :workbench
+ belongs_to :referential
-class Import
- include JobConcern
-
- def initialize( response )
- @datas = response
- end
-
- def report?
- links["action_report"].present?
- end
-
- def report
- Rails.cache.fetch("#{cache_key}/action_report", expires_in: cache_expiration) do
- report_path = links["action_report"]
- if report_path
- response = Ievkit.get(report_path)
- ImportReport.new(response)
- else
- nil
- end
- end
- end
-
- def rule_parameter_set?
- links["validation_params"].present?
- end
-
- def rule_parameter_set
- Rails.cache.fetch("#{cache_key}/validation_params", expires_in: cache_expiration) do
- rule_parameter_set_path = links["validation_params"]
- if rule_parameter_set_path
- response = Ievkit.get(rule_parameter_set_path)
- rule_parameter_set = RuleParameterSet.new(:name => "", :import => self).tap { |rps| rps.parameters = response.validation }
- else
- nil
- end
- end
- end
-
- def compliance_check?
- links["validation_report"].present?
- end
-
- def compliance_check_validation_report
- puts "compliance_check_validation_report"
- Rails.cache.fetch("#{cache_key}/validation_report", expires_in: cache_expiration) do
- compliance_check_path = links["validation_report"]
- if compliance_check_path
- response = Ievkit.get(compliance_check_path)
- ComplianceCheckResult.new(response)
- else
- nil
- end
- end
- end
-
- def destroy
- delete_path = links["delete"]
- cancel_path = links["cancel"]
-
- if delete_path
- Ievkit.delete(delete_path)
- elsif cancel_path
- Ievkit.delete(cancel_path)
- else
- nil
- end
- end
-
- def file_path?
- links["data"].present?
- end
-
- def file_path
- links["data"]
- end
-
- def filename
- File.basename(file_path) if file_path
- end
-
- def filename_extension
- File.extname(filename).gsub(".", "") if filename
- end
+ validates :file, presence: true
end
diff --git a/app/models/import_message.rb b/app/models/import_message.rb
new file mode 100644
index 000000000..5d0f5c862
--- /dev/null
+++ b/app/models/import_message.rb
@@ -0,0 +1,7 @@
+class ImportMessage < ActiveRecord::Base
+ belongs_to :import
+ belongs_to :resource, class_name: ImportResource
+ enum criticity: [:info, :warning, :error]
+
+ validates :criticity, presence: true
+end
diff --git a/app/models/import_resource.rb b/app/models/import_resource.rb
new file mode 100644
index 000000000..f140e1b36
--- /dev/null
+++ b/app/models/import_resource.rb
@@ -0,0 +1,23 @@
+class ImportResource < ActiveRecord::Base
+ include AASM
+ belongs_to :import
+
+ aasm column: :status do
+ state :new, :initial => true
+ state :pending
+ state :successful
+ state :failed
+
+ event :run do
+ transitions :from => [:new, :failed], :to => :pending
+ end
+
+ event :successful do
+ transitions :from => [:pending, :failed], :to => :successful
+ end
+
+ event :failed do
+ transitions :from => :pending, :to => :failed
+ end
+ end
+end
diff --git a/app/models/referential.rb b/app/models/referential.rb
index 34da65755..dbc7b76e7 100644
--- a/app/models/referential.rb
+++ b/app/models/referential.rb
@@ -34,7 +34,6 @@ class Referential < ActiveRecord::Base
has_many :companies, through: :line_referential
has_many :group_of_lines, through: :line_referential
has_many :networks, through: :line_referential
-
has_many :metadatas, class_name: "ReferentialMetadata", inverse_of: :referential, dependent: :destroy
accepts_nested_attributes_for :metadatas
diff --git a/app/models/workbench.rb b/app/models/workbench.rb
index 21c586873..008f73d46 100644
--- a/app/models/workbench.rb
+++ b/app/models/workbench.rb
@@ -8,7 +8,7 @@ class Workbench < ActiveRecord::Base
has_many :companies, through: :line_referential
has_many :group_of_lines, through: :line_referential
has_many :stop_areas, through: :stop_area_referential
-
+ has_many :imports
validates :name, presence: true
validates :organisation, presence: true
diff --git a/app/uploaders/import_uploader.rb b/app/uploaders/import_uploader.rb
new file mode 100644
index 000000000..2740393ca
--- /dev/null
+++ b/app/uploaders/import_uploader.rb
@@ -0,0 +1,49 @@
+class ImportUploader < CarrierWave::Uploader::Base
+
+ # Include RMagick or MiniMagick support:
+ # include CarrierWave::RMagick
+ # include CarrierWave::MiniMagick
+
+ # Choose what kind of storage to use for this uploader:
+ storage :file
+ # storage :fog
+
+ # Override the directory where uploaded files will be stored.
+ # This is a sensible default for uploaders that are meant to be mounted:
+ def store_dir
+ "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
+ end
+
+ # Provide a default URL as a default if there hasn't been a file uploaded:
+ # def default_url
+ # # For Rails 3.1+ asset pipeline compatibility:
+ # # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
+ #
+ # "/images/fallback/" + [version_name, "default.png"].compact.join('_')
+ # end
+
+ # Process files as they are uploaded:
+ # process scale: [200, 300]
+ #
+ # def scale(width, height)
+ # # do something
+ # end
+
+ # Create different versions of your uploaded files:
+ # version :thumb do
+ # process resize_to_fit: [50, 50]
+ # end
+
+ # Add a white list of extensions which are allowed to be uploaded.
+ # For images you might use something like this:
+ # def extension_whitelist
+ # %w(jpg jpeg gif png)
+ # end
+
+ # Override the filename of the uploaded files:
+ # Avoid using model.id or version_name here, see uploader/store.rb for details.
+ # def filename
+ # "something.jpg" if original_filename
+ # end
+
+end
diff --git a/app/views/imports/_form.html.slim b/app/views/imports/_form.html.slim
new file mode 100644
index 000000000..693ce6fc4
--- /dev/null
+++ b/app/views/imports/_form.html.slim
@@ -0,0 +1,5 @@
+= simple_form_for [workbench, import] do |f|
+ = f.input :name
+ = f.input :file
+ = f.association :referential
+ = f.button :submit
diff --git a/app/views/imports/_import.html.slim b/app/views/imports/_import.html.slim
deleted file mode 100644
index 7d4753358..000000000
--- a/app/views/imports/_import.html.slim
+++ /dev/null
@@ -1,24 +0,0 @@
-#index_item.panel.panel-default.import
- .panel-heading
- .panel-title.clearfix
- span.pull-right
- = link_to referential_import_path(@referential, import.id), method: :delete, :data => {:confirm => t('imports.actions.destroy_confirm')}, class: 'btn btn-danger btn-sm' do
- span.fa.fa-trash-o
-
- h5
- = link_to( referential_import_path(@referential, import.id), class: 'preview', :title => "#{ImportTask.model_name.human.capitalize} #{import.name}") do
- = job_status_title(import)
-
- .panel-body
- p
- = link_to font_awesome_classic_tag("fa-file-#{import.filename_extension}-o") + t("imports.show.imported_file"), imported_file_referential_import_path(@referential, import.id) if import.file_path?
-
- p
- = link_to font_awesome_classic_tag("fa-external-link") + t("imports.show.compliance_check"), compliance_check_referential_import_path(@referential, import.id) if import.compliance_check?
-
- .panel-footer
- = import_attributes_tag(import)
-
- .history
- = l(import.created_at, :format => "%d/%m/%Y %H:%M") if import.created_at
- = " | #{import.user_name}" \ No newline at end of file
diff --git a/app/views/imports/_imports.html.slim b/app/views/imports/_imports.html.slim
deleted file mode 100644
index 3605fd10b..000000000
--- a/app/views/imports/_imports.html.slim
+++ /dev/null
@@ -1,9 +0,0 @@
-.page_info
- span.search = t("will_paginate.page_entries_info.search")
- = page_entries_info @imports
-
-.imports.paginated_content
- = paginated_content @imports, "imports/import"
-
-.pagination
- = will_paginate @imports, :container => false, renderer: RemoteBootstrapPaginationLinkRenderer \ No newline at end of file
diff --git a/app/views/imports/index.html.slim b/app/views/imports/index.html.slim
index b1922d005..fd87de90f 100644
--- a/app/views/imports/index.html.slim
+++ b/app/views/imports/index.html.slim
@@ -1,13 +1,12 @@
= title_tag t('.title')
+- @imports.each do |import|
+ .import
+ li = link_to import.name, workbench_import_path(@workbench, import)
+ li = import.referential.name
+ li = link_to import.file.file.filename, import.file.url, target: :_blank
+ hr
.warning = t('.warning')
-
-#imports
- = render 'imports'
-
- content_for :sidebar do
ul.actions
- li
- = link_to t('imports.actions.new'), new_referential_import_task_path(@referential), class: 'add'
- li
- = link_to t('rule_parameter_sets.actions.index'), organisation_rule_parameter_sets_path, class: 'link' \ No newline at end of file
+ li = link_to t('imports.actions.new'), new_workbench_import_path(workbench_id: @workbench), class: 'add'
diff --git a/app/views/imports/index.js.slim b/app/views/imports/index.js.slim
deleted file mode 100644
index 2fac7d26c..000000000
--- a/app/views/imports/index.js.slim
+++ /dev/null
@@ -1 +0,0 @@
-| $('#imports').html("#{escape_javascript(render("imports"))}"); \ No newline at end of file
diff --git a/app/views/imports/new.html.slim b/app/views/imports/new.html.slim
new file mode 100644
index 000000000..55b655a85
--- /dev/null
+++ b/app/views/imports/new.html.slim
@@ -0,0 +1,4 @@
+= title_tag t('.title')
+.row
+ .col-lg-8.col-lg-offset-2.col-md-8.col-md-offset-2.col-sm-8.col-sm-offset-2
+ = render 'form', import: @import, workbench: @workbench
diff --git a/app/views/imports/show.html.slim b/app/views/imports/show.html.slim
index 5992af311..b40e11ea4 100644
--- a/app/views/imports/show.html.slim
+++ b/app/views/imports/show.html.slim
@@ -2,26 +2,13 @@
.col-md-8
= title_tag job_status_title(@import)
- .col-md-4
- = import_attributes_tag(@import)
-
-- if @import.report.failure_code?
- .alert.alert-danger
- = t("iev.failure.#{@import.report.failure_code}")
-
-.progress_bars
- = progress_bar_tag(@import)
-
.import_show
.links
- = link_to font_awesome_classic_tag("fa-file-#{@import.filename_extension}-o") + t("imports.show.imported_file"), imported_file_referential_import_path(@referential, @import.id) if @import.file_path?
- = link_to font_awesome_classic_tag("fa-external-link") + t("imports.show.compliance_check"), compliance_check_referential_import_path(@referential, @import.id) if @import.compliance_check?
-
- = render(partial: 'shared/ie_report', locals: {job: @import, line_items: @line_items})
+ = link_to font_awesome_classic_tag("fa-file-#{@import.file.file.extension}-o") + t("imports.show.imported_file"), @import.file.url
- content_for :sidebar do
ul.actions
li
- = link_to t('imports.actions.destroy'), referential_import_path(@referential, @import.id), method: :delete, data: {confirm: t('imports.actions.destroy_confirm')}, class: 'remove'
-
- = history_tag(@import) \ No newline at end of file
+ = link_to t('imports.actions.destroy'), workbench_import_path(@workbench, @import.id), method: :delete, data: {confirm: t('imports.actions.destroy_confirm')}, class: 'remove'
+
+ = history_tag(@import)
diff --git a/app/views/shared/_header.html.slim b/app/views/shared/_header.html.slim
index 73e705e35..33aee09a4 100644
--- a/app/views/shared/_header.html.slim
+++ b/app/views/shared/_header.html.slim
@@ -90,9 +90,6 @@ nav.navbar.navbar-default.navbar-fixed-top role="navigation"
= link_to referential_timebands_path(@referential) do
span.badge.pull-right = @referential.timebands.size
= Referential.human_attribute_name("timebands")
-
- li
- = link_to Referential.human_attribute_name("imports"), referential_imports_path(@referential)
li
= link_to Referential.human_attribute_name("exports"), referential_exports_path(@referential)
li
diff --git a/config/locales/breadcrumbs.en.yml b/config/locales/breadcrumbs.en.yml
index 911c992c3..6fec15b85 100644
--- a/config/locales/breadcrumbs.en.yml
+++ b/config/locales/breadcrumbs.en.yml
@@ -4,3 +4,4 @@ en:
vehicle_journey_frequencies: "Times bands"
referentials: "Home"
users: "Users"
+ imports: Imports
diff --git a/config/locales/breadcrumbs.fr.yml b/config/locales/breadcrumbs.fr.yml
index ffcba3015..b941138c7 100644
--- a/config/locales/breadcrumbs.fr.yml
+++ b/config/locales/breadcrumbs.fr.yml
@@ -4,3 +4,4 @@ fr:
vehicle_journey_frequencies: "Créneaux horaires"
referentials: "Accueil"
users: "Utilisateurs"
+ imports: Imports
diff --git a/config/routes.rb b/config/routes.rb
index 9ceb65db0..2a912124d 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -1,7 +1,9 @@
require 'sidekiq/web'
ChouetteIhm::Application.routes.draw do
- resources :workbenches, :only => [:show]
+ resources :workbenches, :only => [:show] do
+ resources :imports
+ end
devise_for :users, :controllers => {
:registrations => 'users/registrations', :invitations => 'users/invitations'
@@ -122,15 +124,6 @@ ChouetteIhm::Application.routes.draw do
end
resources :import_tasks, :only => [:new, :create]
- resources :imports, :only => [:index, :show, :destroy] do
- member do
- get "imported_file"
- get "rule_parameter_set"
- get "compliance_check"
- get 'export', defaults: { format: 'zip' }
- end
- end
-
resources :export_tasks, :only => [:new, :create] do
collection do
get 'references'
diff --git a/db/migrate/20120515134710_create_imports.rb b/db/migrate/20120515134710_create_imports.rb
deleted file mode 100644
index 5da398fc9..000000000
--- a/db/migrate/20120515134710_create_imports.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-class CreateImports < ActiveRecord::Migration
- def change
- create_table :imports do |t|
- t.belongs_to :referential
- t.string :status
-
- t.timestamps
- end
- add_index :imports, :referential_id
- end
-end
diff --git a/db/migrate/20161227104202_create_imports.rb b/db/migrate/20161227104202_create_imports.rb
new file mode 100644
index 000000000..97a2d6029
--- /dev/null
+++ b/db/migrate/20161227104202_create_imports.rb
@@ -0,0 +1,14 @@
+class CreateImports < ActiveRecord::Migration
+ def change
+ create_table :imports do |t|
+ t.string :status
+ t.string :current_step_id
+ t.float :current_step_progress
+ t.references :workbench, index: true
+ t.references :referential, index: true
+ t.string :name
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/migrate/20161227104741_add_file_to_imports.rb b/db/migrate/20161227104741_add_file_to_imports.rb
new file mode 100644
index 000000000..36498039b
--- /dev/null
+++ b/db/migrate/20161227104741_add_file_to_imports.rb
@@ -0,0 +1,5 @@
+class AddFileToImports < ActiveRecord::Migration
+ def change
+ add_column :imports, :file, :string
+ end
+end
diff --git a/db/migrate/20161228102458_create_import_messages.rb b/db/migrate/20161228102458_create_import_messages.rb
new file mode 100644
index 000000000..53a26cbd2
--- /dev/null
+++ b/db/migrate/20161228102458_create_import_messages.rb
@@ -0,0 +1,13 @@
+class CreateImportMessages < ActiveRecord::Migration
+ def change
+ create_table :import_messages do |t|
+ t.integer :criticity
+ t.string :message_key
+ t.hstore :message_attributs
+ t.references :import, index: true
+ t.references :resource, index: true
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/migrate/20161228103628_create_import_resources.rb b/db/migrate/20161228103628_create_import_resources.rb
new file mode 100644
index 000000000..ef9c3563f
--- /dev/null
+++ b/db/migrate/20161228103628_create_import_resources.rb
@@ -0,0 +1,10 @@
+class CreateImportResources < ActiveRecord::Migration
+ def change
+ create_table :import_resources do |t|
+ t.references :import, index: true
+ t.string :status
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index d91db0968..0dcd5457c 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,8 +11,8 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20170215163027) do
+ActiveRecord::Schema.define(version: 20170215163027) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
enable_extension "postgis"
@@ -243,6 +243,43 @@ ActiveRecord::Schema.define(version: 20170215163027) do
t.integer "line_id", limit: 8
end
+ create_table "import_messages", force: true do |t|
+ t.integer "criticity"
+ t.string "message_key"
+ t.hstore "message_attributs"
+ t.integer "import_id"
+ t.integer "resource_id"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+ add_index "import_messages", ["import_id"], :name => "index_import_messages_on_import_id"
+ add_index "import_messages", ["resource_id"], :name => "index_import_messages_on_resource_id"
+
+ create_table "import_resources", force: true do |t|
+ t.integer "import_id"
+ t.string "status"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+ add_index "import_resources", ["import_id"], :name => "index_import_resources_on_import_id"
+
+ create_table "imports", force: true do |t|
+ t.string "status"
+ t.string "current_step_id"
+ t.float "current_step_progress"
+ t.integer "workbench_id"
+ t.integer "referential_id"
+ t.string "name"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ t.string "file"
+ end
+
+ add_index "imports", ["referential_id"], :name => "index_imports_on_referential_id"
+ add_index "imports", ["workbench_id"], :name => "index_imports_on_workbench_id"
+
create_table "journey_frequencies", force: true do |t|
t.integer "vehicle_journey_id", limit: 8
t.time "scheduled_headway_interval", null: false
diff --git a/spec/controllers/imports_controller_spec.rb b/spec/controllers/imports_controller_spec.rb
new file mode 100644
index 000000000..19756b72f
--- /dev/null
+++ b/spec/controllers/imports_controller_spec.rb
@@ -0,0 +1,14 @@
+require 'rails_helper'
+
+RSpec.describe ImportsController, :type => :controller do
+ login_user
+
+ let(:workbench) { create :workbench }
+
+ describe 'GET #new' do
+ it 'should be successful' do
+ get :new, workbench_id: workbench.id
+ expect(response).to be_success
+ end
+ end
+end
diff --git a/spec/controllers/vehicle_journey_imports_controller_spec.rb b/spec/controllers/vehicle_journey_imports_controller_spec.rb
index d91814669..ef1ec882a 100644
--- a/spec/controllers/vehicle_journey_imports_controller_spec.rb
+++ b/spec/controllers/vehicle_journey_imports_controller_spec.rb
@@ -3,5 +3,5 @@ require 'spec_helper'
describe ImportTasksController, :type => :controller do
login_user
-
+
end
diff --git a/spec/factories/import_messages.rb b/spec/factories/import_messages.rb
new file mode 100644
index 000000000..2d26477e6
--- /dev/null
+++ b/spec/factories/import_messages.rb
@@ -0,0 +1,10 @@
+FactoryGirl.define do
+ factory :import_message do
+ criticity 1
+message_key "MyString"
+message_attributs ""
+import nil
+resource nil
+ end
+
+end
diff --git a/spec/factories/import_resources.rb b/spec/factories/import_resources.rb
new file mode 100644
index 000000000..274edab60
--- /dev/null
+++ b/spec/factories/import_resources.rb
@@ -0,0 +1,6 @@
+FactoryGirl.define do
+ factory :import_resource do
+ association :import
+ status :new
+ end
+end
diff --git a/spec/factories/imports.rb b/spec/factories/imports.rb
new file mode 100644
index 000000000..bb9a97c9c
--- /dev/null
+++ b/spec/factories/imports.rb
@@ -0,0 +1,11 @@
+FactoryGirl.define do
+ factory :import do
+ name "MyString"
+ current_step_id "MyString"
+ current_step_progress 1.5
+ association :workbench
+ association :referential
+ file {File.open(File.join(Rails.root, 'spec', 'fixtures', 'terminated_job.json'))}
+ status "MyString"
+ end
+end
diff --git a/spec/models/import_message_spec.rb b/spec/models/import_message_spec.rb
new file mode 100644
index 000000000..2d8aac2b7
--- /dev/null
+++ b/spec/models/import_message_spec.rb
@@ -0,0 +1,7 @@
+require 'rails_helper'
+
+RSpec.describe ImportMessage, :type => :model do
+ it { should validate_presence_of(:criticity) }
+ it { should belong_to(:import) }
+ it { should belong_to(:resource) }
+end
diff --git a/spec/models/import_resource_spec.rb b/spec/models/import_resource_spec.rb
new file mode 100644
index 000000000..a2177979e
--- /dev/null
+++ b/spec/models/import_resource_spec.rb
@@ -0,0 +1,13 @@
+require 'rails_helper'
+
+RSpec.describe ImportResource, :type => :model do
+ it { should belong_to(:import) }
+
+ describe 'states' do
+ let(:import_resource) { create(:import_resource) }
+
+ it 'should initialize with new state' do
+ expect(import_resource.new?).to be_truthy
+ end
+ end
+end
diff --git a/spec/models/import_spec.rb b/spec/models/import_spec.rb
new file mode 100644
index 000000000..4c44eb99c
--- /dev/null
+++ b/spec/models/import_spec.rb
@@ -0,0 +1,8 @@
+require 'rails_helper'
+
+RSpec.describe Import, :type => :model do
+ it { should belong_to(:referential) }
+ it { should belong_to(:workbench) }
+
+ it { should validate_presence_of(:file) }
+end