From cecd26452ce1cb2486d926421c1ae6360c973d1b Mon Sep 17 00:00:00 2001 From: Xinhui Date: Thu, 29 Sep 2016 15:44:41 +0200 Subject: Model StopAreaReferentialSyncMessage Refs #1710 --- app/models/stop_area_referential_sync_message.rb | 6 ++++++ config/initializers/apartment.rb | 1 + ...0929133436_create_stop_area_referential_sync_messages.rb | 13 +++++++++++++ db/schema.rb | 13 ++++++++++++- spec/factories/stop_area_referential_sync_messages.rb | 9 +++++++++ spec/models/stop_area_referential_sync_message_spec.rb | 9 +++++++++ 6 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 app/models/stop_area_referential_sync_message.rb create mode 100644 db/migrate/20160929133436_create_stop_area_referential_sync_messages.rb create mode 100644 spec/factories/stop_area_referential_sync_messages.rb create mode 100644 spec/models/stop_area_referential_sync_message_spec.rb diff --git a/app/models/stop_area_referential_sync_message.rb b/app/models/stop_area_referential_sync_message.rb new file mode 100644 index 000000000..e965297da --- /dev/null +++ b/app/models/stop_area_referential_sync_message.rb @@ -0,0 +1,6 @@ +class StopAreaReferentialSyncMessage < ActiveRecord::Base + belongs_to :stop_area_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 0178ff938..db352fa6f 100644 --- a/config/initializers/apartment.rb +++ b/config/initializers/apartment.rb @@ -26,6 +26,7 @@ Apartment.configure do |config| "RuleParameterSet", "StopAreaReferential", "StopAreaReferentialSync", + "StopAreaReferentialSyncMessage", "Chouette::StopArea", "LineReferential", "LineReferentialSync", diff --git a/db/migrate/20160929133436_create_stop_area_referential_sync_messages.rb b/db/migrate/20160929133436_create_stop_area_referential_sync_messages.rb new file mode 100644 index 000000000..a04323233 --- /dev/null +++ b/db/migrate/20160929133436_create_stop_area_referential_sync_messages.rb @@ -0,0 +1,13 @@ +class CreateStopAreaReferentialSyncMessages < ActiveRecord::Migration + def change + create_table :stop_area_referential_sync_messages do |t| + t.integer :criticity + t.string :message_key + t.hstore :message_attributs + t.references :stop_area_referential_sync + + t.timestamps + end + add_index :stop_area_referential_sync_messages, :stop_area_referential_sync_id, name: 'stop_area_referential_sync_id' + end +end diff --git a/db/schema.rb b/db/schema.rb index 83a8beb9e..e519a381d 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: 20160929131958) do +ActiveRecord::Schema.define(version: 20160929133436) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -454,6 +454,17 @@ ActiveRecord::Schema.define(version: 20160929131958) do t.boolean "owner" end + create_table "stop_area_referential_sync_messages", force: true do |t| + t.integer "criticity" + t.string "message_key" + t.hstore "message_attributs" + t.integer "stop_area_referential_sync_id" + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "stop_area_referential_sync_messages", ["stop_area_referential_sync_id"], :name => "stop_area_referential_sync_id" + create_table "stop_area_referential_syncs", force: true do |t| t.integer "stop_area_referential_id" t.datetime "created_at" diff --git a/spec/factories/stop_area_referential_sync_messages.rb b/spec/factories/stop_area_referential_sync_messages.rb new file mode 100644 index 000000000..bd526553d --- /dev/null +++ b/spec/factories/stop_area_referential_sync_messages.rb @@ -0,0 +1,9 @@ +FactoryGirl.define do + factory :stop_area_referential_sync_message do + criticity 1 +message_key "MyString" +message_attributs "" +stop_area_referential_sync nil + end + +end diff --git a/spec/models/stop_area_referential_sync_message_spec.rb b/spec/models/stop_area_referential_sync_message_spec.rb new file mode 100644 index 000000000..ff17482e5 --- /dev/null +++ b/spec/models/stop_area_referential_sync_message_spec.rb @@ -0,0 +1,9 @@ +require 'rails_helper' + +RSpec.describe StopAreaReferentialSyncMessage, :type => :model do + it 'should have a valid factory' do + expect(FactoryGirl.build(:stop_area_referential_sync_message)).to be_valid + end + it { is_expected.to belong_to(:stop_area_referential_sync) } + it { is_expected.to validate_presence_of(:criticity) } +end -- cgit v1.2.3