1
0
Fork 0

Add column CountryState#english_name

This commit is contained in:
Alex Kotov 2019-03-25 01:52:10 +05:00
parent b69c77925a
commit 3820d8d4f2
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
10 changed files with 32 additions and 3 deletions

View File

@ -6,4 +6,6 @@ class CountryState < ApplicationRecord
has_many :membership_apps, dependent: :restrict_with_exception
validates :name, presence: true, uniqueness: true
validates :english_name, presence: true, uniqueness: true
end

View File

@ -5,6 +5,9 @@
<th scope="col">
<%= CountryState.human_attribute_name :name %>
</th>
<th scope="col">
<%= CountryState.human_attribute_name :english_name %>
</th>
<th scope="col"></th>
</tr>
</thead>
@ -13,6 +16,7 @@
<% @country_states.each do |country_state| %>
<tr>
<td><%= country_state.name %></td>
<td><%= country_state.english_name %></td>
<td>
<% if policy(country_state).show? %>
<%= link_to country_state,

View File

@ -1,3 +1,9 @@
<div class="container">
<h1><%= @country_state.name %></h1>
<h1>
<%= @country_state.name %>
<br/>
<small class="text-muted">
<%= @country_state.english_name %>
</small>
</h1>
</div>

View File

@ -36,6 +36,7 @@ en:
id: ID
membership_apps: Membership applications
name: Name
english_name: Name
membership_app:
id: ID
country_state: State

View File

@ -36,6 +36,7 @@ ru:
id: ID
membership_apps: Заявления на вступление
name: Название
english_name: Название
membership_app:
id: ID
country_state: Регион

View File

@ -0,0 +1,10 @@
# frozen_string_literal: true
class AddEnglishNameToCountryStates < ActiveRecord::Migration[6.0]
def change
# rubocop:disable Rails/NotNullColumn
add_column :country_states, :english_name, :string, null: false
add_index :country_states, :english_name, unique: true
# rubocop:enable Rails/NotNullColumn
end
end

View File

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2019_03_24_192022) do
ActiveRecord::Schema.define(version: 2019_03_24_204513) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -63,6 +63,8 @@ ActiveRecord::Schema.define(version: 2019_03_24_192022) do
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "name", null: false
t.string "english_name", null: false
t.index ["english_name"], name: "index_country_states_on_english_name", unique: true
t.index ["name"], name: "index_country_states_on_name", unique: true
end

View File

@ -10,7 +10,7 @@ CSV.foreach country_states_filename, col_sep: '|' do |(name, english_name)|
next if CountryState.where(name: name).exists?
CountryState.create! name: name
CountryState.create! name: name, english_name: english_name
end
Rails.application.settings(:superuser).tap do |config|

View File

@ -7,5 +7,6 @@ FactoryBot.define do
end
name { Faker::Address.unique.state }
english_name { Faker::Address.unique.state }
end
end

View File

@ -20,6 +20,8 @@ RSpec.describe CountryState do
it { is_expected.not_to validate_presence_of :regional_office }
it { is_expected.to validate_presence_of :name }
it { is_expected.to validate_presence_of :english_name }
it { is_expected.to validate_uniqueness_of :name }
it { is_expected.to validate_uniqueness_of :english_name }
end