Add model State
This commit is contained in:
parent
1727086fee
commit
b765349175
7 changed files with 55 additions and 1 deletions
5
app/models/state.rb
Normal file
5
app/models/state.rb
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class State < ApplicationRecord
|
||||||
|
validates :name, presence: true, uniqueness: true
|
||||||
|
end
|
|
@ -7,6 +7,9 @@ en:
|
||||||
passport:
|
passport:
|
||||||
one: Passport
|
one: Passport
|
||||||
other: Passports
|
other: Passports
|
||||||
|
state:
|
||||||
|
one: State
|
||||||
|
other: States
|
||||||
user:
|
user:
|
||||||
one: User
|
one: User
|
||||||
other: Users
|
other: Users
|
||||||
|
@ -39,6 +42,9 @@ en:
|
||||||
issued_by: Issued by
|
issued_by: Issued by
|
||||||
unit_code: Unit code
|
unit_code: Unit code
|
||||||
date_of_issue: Date of issue
|
date_of_issue: Date of issue
|
||||||
|
state:
|
||||||
|
id: ID
|
||||||
|
name: Name
|
||||||
passport/confirmed:
|
passport/confirmed:
|
||||||
'true': Confirmed
|
'true': Confirmed
|
||||||
'false': Unconfirmed
|
'false': Unconfirmed
|
||||||
|
|
|
@ -7,6 +7,9 @@ ru:
|
||||||
passport:
|
passport:
|
||||||
one: Паспорт
|
one: Паспорт
|
||||||
other: Паспорта
|
other: Паспорта
|
||||||
|
state:
|
||||||
|
one: Субъект РФ
|
||||||
|
other: Субъекты РФ
|
||||||
user:
|
user:
|
||||||
one: Пользователь
|
one: Пользователь
|
||||||
other: Пользователи
|
other: Пользователи
|
||||||
|
@ -39,6 +42,9 @@ ru:
|
||||||
issued_by: Кем выдан
|
issued_by: Кем выдан
|
||||||
unit_code: Код подразделения
|
unit_code: Код подразделения
|
||||||
date_of_issue: Дата выдачи
|
date_of_issue: Дата выдачи
|
||||||
|
state:
|
||||||
|
id: ID
|
||||||
|
name: Название
|
||||||
passport/confirmed:
|
passport/confirmed:
|
||||||
'true': Подтверждён
|
'true': Подтверждён
|
||||||
'false': Не подтверждён
|
'false': Не подтверждён
|
||||||
|
|
12
db/migrate/20181130161628_create_states.rb
Normal file
12
db/migrate/20181130161628_create_states.rb
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class CreateStates < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
create_table :states do |t|
|
||||||
|
t.timestamps null: false
|
||||||
|
t.string :name, null: false
|
||||||
|
|
||||||
|
t.index :name, unique: true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 2018_11_30_090126) do
|
ActiveRecord::Schema.define(version: 2018_11_30_161628) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
@ -88,6 +88,13 @@ ActiveRecord::Schema.define(version: 2018_11_30_090126) do
|
||||||
t.index ["resource_type", "resource_id"], name: "index_roles_on_resource_type_and_resource_id"
|
t.index ["resource_type", "resource_id"], name: "index_roles_on_resource_type_and_resource_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
create_table "states", force: :cascade do |t|
|
||||||
|
t.datetime "created_at", null: false
|
||||||
|
t.datetime "updated_at", null: false
|
||||||
|
t.string "name", null: false
|
||||||
|
t.index ["name"], name: "index_states_on_name", unique: true
|
||||||
|
end
|
||||||
|
|
||||||
create_table "telegram_bots", force: :cascade do |t|
|
create_table "telegram_bots", force: :cascade do |t|
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
|
|
7
factories/states.rb
Normal file
7
factories/states.rb
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
FactoryBot.define do
|
||||||
|
factory :state do
|
||||||
|
name { Faker::Address.state }
|
||||||
|
end
|
||||||
|
end
|
11
spec/models/state_spec.rb
Normal file
11
spec/models/state_spec.rb
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe State do
|
||||||
|
subject { create :state }
|
||||||
|
|
||||||
|
it { is_expected.to validate_presence_of :name }
|
||||||
|
|
||||||
|
it { is_expected.to validate_uniqueness_of :name }
|
||||||
|
end
|
Reference in a new issue