diff options
| -rw-r--r-- | app/models/import_message.rb | 7 | ||||
| -rw-r--r-- | app/models/import_resource.rb | 23 | ||||
| -rw-r--r-- | app/views/shared/_header.html.slim | 3 | ||||
| -rw-r--r-- | db/migrate/20161228102458_create_import_messages.rb | 13 | ||||
| -rw-r--r-- | db/migrate/20161228103628_create_import_resources.rb | 10 | ||||
| -rw-r--r-- | db/schema.rb | 24 | ||||
| -rw-r--r-- | spec/controllers/imports_controller_spec.rb | 4 | ||||
| -rw-r--r-- | spec/factories/import_messages.rb | 10 | ||||
| -rw-r--r-- | spec/factories/import_resources.rb | 6 | ||||
| -rw-r--r-- | spec/factories/imports.rb | 12 | ||||
| -rw-r--r-- | spec/models/import_message_spec.rb | 7 | ||||
| -rw-r--r-- | spec/models/import_resource_spec.rb | 13 | ||||
| -rw-r--r-- | spec/models/import_spec.rb | 1 | 
13 files changed, 122 insertions, 11 deletions
| 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/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/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 734dde1de..829b235d3 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@  #  # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20161227104741) do +ActiveRecord::Schema.define(version: 20161228103628) do    # These are extensions that must be enabled in order to support this database    enable_extension "plpgsql" @@ -224,6 +224,28 @@ ActiveRecord::Schema.define(version: 20161227104741) 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" diff --git a/spec/controllers/imports_controller_spec.rb b/spec/controllers/imports_controller_spec.rb index f5ccd643a..19756b72f 100644 --- a/spec/controllers/imports_controller_spec.rb +++ b/spec/controllers/imports_controller_spec.rb @@ -3,9 +3,11 @@ 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, referential_id: referential.id +      get :new, workbench_id: workbench.id        expect(response).to be_success      end    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 index 8b2cb223d..bb9a97c9c 100644 --- a/spec/factories/imports.rb +++ b/spec/factories/imports.rb @@ -1,11 +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" -current_step_id "MyString" -current_step_progress 1.5 -workbench nil -referential nil -name "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 index 10a508c71..4c44eb99c 100644 --- a/spec/models/import_spec.rb +++ b/spec/models/import_spec.rb @@ -3,5 +3,6 @@ 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 | 
