diff options
| author | Xinhui | 2016-09-28 11:42:45 +0200 |
|---|---|---|
| committer | Xinhui | 2016-09-28 12:04:25 +0200 |
| commit | d26ef7aa659b3015ccf4b8525c56b4c139c4a693 (patch) | |
| tree | fed0f96b32bb97cee4dc053dc7a8582a4011b659 | |
| parent | ec95f5866d9876587444f26a85e024ed7828a4e7 (diff) | |
| download | chouette-core-d26ef7aa659b3015ccf4b8525c56b4c139c4a693.tar.bz2 | |
Model LineReferentialSyncMessage
Refs #1707
| -rw-r--r-- | app/models/line_referential_sync.rb | 2 | ||||
| -rw-r--r-- | app/models/line_referential_sync_message.rb | 6 | ||||
| -rw-r--r-- | config/initializers/apartment.rb | 2 | ||||
| -rw-r--r-- | db/migrate/20160928084508_create_line_referential_sync_messages.rb | 13 | ||||
| -rw-r--r-- | db/schema.rb | 15 | ||||
| -rw-r--r-- | spec/factories/line_referential_sync_messages.rb | 5 | ||||
| -rw-r--r-- | spec/models/line_referential_sync_message_spec.rb | 10 |
7 files changed, 51 insertions, 2 deletions
diff --git a/app/models/line_referential_sync.rb b/app/models/line_referential_sync.rb index 5b97010b1..67151c61e 100644 --- a/app/models/line_referential_sync.rb +++ b/app/models/line_referential_sync.rb @@ -42,10 +42,12 @@ class LineReferentialSync < ActiveRecord::Base def log_successful logger.debug "#{self.class.name} sync - done" + update_attribute(:ended_at, Time.now) end def log_failed error logger.debug e.message logger.debug "#{self.class.name} sync - failed" + update_attribute(:ended_at, Time.now) end end diff --git a/app/models/line_referential_sync_message.rb b/app/models/line_referential_sync_message.rb new file mode 100644 index 000000000..c62b77689 --- /dev/null +++ b/app/models/line_referential_sync_message.rb @@ -0,0 +1,6 @@ +class LineReferentialSyncMessage < ActiveRecord::Base + belongs_to :line_referential_sync + enum criticity: [:info, :warn, :error] + + validates :criticity, presence: true +end diff --git a/config/initializers/apartment.rb b/config/initializers/apartment.rb index 93ce2d8c6..b69db2b6d 100644 --- a/config/initializers/apartment.rb +++ b/config/initializers/apartment.rb @@ -27,6 +27,8 @@ Apartment.configure do |config| "StopAreaReferential", "Chouette::StopArea", "LineReferential", + "LineReferentialSync", + "LineReferentialSyncMessage", "Chouette::Line", "Chouette::GroupOfLine", "Chouette::Company", diff --git a/db/migrate/20160928084508_create_line_referential_sync_messages.rb b/db/migrate/20160928084508_create_line_referential_sync_messages.rb new file mode 100644 index 000000000..dfd673ab6 --- /dev/null +++ b/db/migrate/20160928084508_create_line_referential_sync_messages.rb @@ -0,0 +1,13 @@ +class CreateLineReferentialSyncMessages < ActiveRecord::Migration + def change + create_table :line_referential_sync_messages do |t| + t.integer :criticity + t.string :message_key + t.hstore :message_attributs + t.references :line_referential_sync + + t.timestamps + end + add_index :line_referential_sync_messages, :line_referential_sync_id, name: 'line_referential_sync_id' + end +end diff --git a/db/schema.rb b/db/schema.rb index 359e1c5f5..ad71bd9d8 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,12 +11,12 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20160927085857) do +ActiveRecord::Schema.define(version: 20160928084508) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" - enable_extension "hstore" enable_extension "postgis" + enable_extension "hstore" create_table "access_links", force: true do |t| t.integer "access_point_id", limit: 8 @@ -273,6 +273,17 @@ ActiveRecord::Schema.define(version: 20160927085857) do t.boolean "owner" end + create_table "line_referential_sync_messages", force: true do |t| + t.integer "criticity" + t.string "message_key" + t.hstore "message_attributs" + t.integer "line_referential_sync_id" + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "line_referential_sync_messages", ["line_referential_sync_id"], :name => "line_referential_sync_id" + create_table "line_referential_syncs", force: true do |t| t.integer "line_referential_id" t.datetime "created_at" diff --git a/spec/factories/line_referential_sync_messages.rb b/spec/factories/line_referential_sync_messages.rb new file mode 100644 index 000000000..26d0f4daa --- /dev/null +++ b/spec/factories/line_referential_sync_messages.rb @@ -0,0 +1,5 @@ +FactoryGirl.define do + factory :line_referential_sync_message do + criticity :info + end +end diff --git a/spec/models/line_referential_sync_message_spec.rb b/spec/models/line_referential_sync_message_spec.rb new file mode 100644 index 000000000..d15c05ab0 --- /dev/null +++ b/spec/models/line_referential_sync_message_spec.rb @@ -0,0 +1,10 @@ +require 'rails_helper' + +RSpec.describe LineReferentialSyncMessage, :type => :model do + it 'should have a valid factory' do + expect(FactoryGirl.build(:line_referential_sync_message)).to be_valid + end + + it { is_expected.to belong_to(:line_referential_sync) } + it { is_expected.to validate_presence_of(:criticity) } +end |
