diff options
| author | Vlatka Pavisic | 2017-02-28 16:03:59 +0100 |
|---|---|---|
| committer | Vlatka Pavisic | 2017-02-28 16:04:12 +0100 |
| commit | de028f8161d7175f02b9fa4861d9450942b5fd24 (patch) | |
| tree | f7d0fd2d40ee9eeb3a108512fbbc1c78b8ad6f27 | |
| parent | 072e4f76f1c98dca9b4a85efa87052842d880d07 (diff) | |
| download | chouette-core-de028f8161d7175f02b9fa4861d9450942b5fd24.tar.bz2 | |
Refs #2670 : Update Import model
| -rw-r--r-- | app/models/import.rb | 7 | ||||
| -rw-r--r-- | config/locales/enumerize.en.yml | 7 | ||||
| -rw-r--r-- | config/locales/enumerize.fr.yml | 7 | ||||
| -rw-r--r-- | db/migrate/20170228135627_add_dates_and_token_to_import.rb | 7 | ||||
| -rw-r--r-- | db/schema.rb | 5 | ||||
| -rw-r--r-- | spec/factories/imports.rb | 6 | ||||
| -rw-r--r-- | spec/models/import_spec.rb | 2 |
7 files changed, 38 insertions, 3 deletions
diff --git a/app/models/import.rb b/app/models/import.rb index 8ffac5c5e..c407daa78 100644 --- a/app/models/import.rb +++ b/app/models/import.rb @@ -3,5 +3,12 @@ class Import < ActiveRecord::Base belongs_to :workbench belongs_to :referential + extend Enumerize + enumerize :status, in: %i(new pending successful failed canceled) + validates :file, presence: true + + before_create do + self.token_download = SecureRandom.urlsafe_base64 + end end diff --git a/config/locales/enumerize.en.yml b/config/locales/enumerize.en.yml index f98672236..07f31d5f9 100644 --- a/config/locales/enumerize.en.yml +++ b/config/locales/enumerize.en.yml @@ -5,6 +5,13 @@ en: for_boarding: "Undefined" for_alighting: "Undefined" enumerize: + import: + status: + new: New + pending: Pending + successful: Successful + failed: Failed + canceled: Canceled for_boarding: normal: "Regularly scheduled pickup" forbidden: "No pickup available" diff --git a/config/locales/enumerize.fr.yml b/config/locales/enumerize.fr.yml index 9ff4546da..f7449cb44 100644 --- a/config/locales/enumerize.fr.yml +++ b/config/locales/enumerize.fr.yml @@ -5,6 +5,13 @@ fr: for_boarding: "Non défini" for_alighting: "Non défini" enumerize: + import: + status: + new: + pending: + successful: + failed: + canceled: for_boarding: normal: "Montée autorisée" forbidden: "Montée interdite" diff --git a/db/migrate/20170228135627_add_dates_and_token_to_import.rb b/db/migrate/20170228135627_add_dates_and_token_to_import.rb new file mode 100644 index 000000000..fa4be85ed --- /dev/null +++ b/db/migrate/20170228135627_add_dates_and_token_to_import.rb @@ -0,0 +1,7 @@ +class AddDatesAndTokenToImport < ActiveRecord::Migration + def change + add_column :imports, :started_at, :date + add_column :imports, :ended_at, :date + add_column :imports, :token_download, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 0dcd5457c..a05e7b305 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: 20170228135627) 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" @@ -275,6 +275,9 @@ ActiveRecord::Schema.define(version: 20170215163027) do t.datetime "created_at" t.datetime "updated_at" t.string "file" + t.date "started_at" + t.date "ended_at" + t.string "token_download" end add_index "imports", ["referential_id"], :name => "index_imports_on_referential_id" diff --git a/spec/factories/imports.rb b/spec/factories/imports.rb index bb9a97c9c..fc8668606 100644 --- a/spec/factories/imports.rb +++ b/spec/factories/imports.rb @@ -1,11 +1,13 @@ FactoryGirl.define do factory :import do - name "MyString" + sequence(:name) { |n| "Import #{n}" } 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" + status :new + started_at nil + ended_at nil end end diff --git a/spec/models/import_spec.rb b/spec/models/import_spec.rb index 4c44eb99c..e34f368ae 100644 --- a/spec/models/import_spec.rb +++ b/spec/models/import_spec.rb @@ -4,5 +4,7 @@ RSpec.describe Import, :type => :model do it { should belong_to(:referential) } it { should belong_to(:workbench) } + it { should enumerize(:status).in(:new, :pending, :successful, :failed, :canceled) } + it { should validate_presence_of(:file) } end |
