1
0
Fork 0

Remove column CountryState#name

This commit is contained in:
Alex Kotov 2019-03-25 02:13:56 +05:00
parent e3fad3a7d3
commit 2f67836361
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
11 changed files with 21 additions and 24 deletions

View file

@ -5,8 +5,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
validates :native_name, presence: true, uniqueness: true

View file

@ -28,7 +28,7 @@
<% if @account.person&.regional_office %>
<div class="mb-2">
<i class="fas fa-map-marker-alt"></i>
<%= link_to @account.person.regional_office.country_state.name,
<%= link_to @account.person.regional_office.country_state.native_name,
@account.person.regional_office.country_state %>
</div>
<% end %>

View file

@ -2,9 +2,6 @@
<table class="table">
<thead>
<tr>
<th scope="col">
<%= CountryState.human_attribute_name :name %>
</th>
<th scope="col">
<%= CountryState.human_attribute_name :english_name %>
</th>
@ -18,7 +15,6 @@
<tbody>
<% @country_states.each do |country_state| %>
<tr>
<td><%= country_state.name %></td>
<td><%= country_state.english_name %></td>
<td><%= country_state.native_name %></td>
<td>

View file

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

View file

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

View file

@ -0,0 +1,9 @@
# frozen_string_literal: true
class RemoveNameFromCountryStates < ActiveRecord::Migration[6.0]
def change
# rubocop:disable Rails/ReversibleMigration
remove_column :country_states, :name
# rubocop:enable Rails/ReversibleMigration
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_210722) do
ActiveRecord::Schema.define(version: 2019_03_24_211036) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -62,11 +62,9 @@ ActiveRecord::Schema.define(version: 2019_03_24_210722) do
create_table "country_states", force: :cascade do |t|
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "name", null: false
t.string "english_name", null: false
t.string "native_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
t.index ["native_name"], name: "index_country_states_on_native_name", unique: true
end

View file

@ -4,13 +4,14 @@ require 'csv'
country_states_filename = Rails.root.join 'config', 'country_states.csv'
CSV.foreach country_states_filename, col_sep: '|' do |(name, english_name)|
name.strip!
CSV.foreach country_states_filename,
col_sep: '|' do |(native_name, english_name)|
native_name.strip!
english_name.strip!
next if CountryState.where(name: name).exists?
next if CountryState.where(english_name: english_name).exists?
CountryState.create! name: name, english_name: english_name, native_name: name
CountryState.create! english_name: english_name, native_name: native_name
end
Rails.application.settings(:superuser).tap do |config|

View file

@ -3,11 +3,10 @@
FactoryBot.define do
factory :country_state do
initialize_with do
CountryState.find_or_initialize_by name: name
CountryState.find_or_initialize_by english_name: english_name
end
name { Faker::Address.unique.state }
english_name { Faker::Address.unique.state }
native_name { Faker::Address.unique.state }
native_name { english_name }
end
end

View file

@ -12,7 +12,7 @@ end
When 'there is a supporter account with the following data:' do |table|
options = table.raw.map { |(k, v)| [k.to_sym, v] }.to_h
country_state = create :country_state, name: options[:country_state]
country_state = create :country_state, english_name: options[:country_state]
regional_office = create :regional_office, country_state: country_state
person = create :supporter_person, regional_office: regional_office
@ -26,7 +26,7 @@ end
When 'there is a member account with the following data:' do |table|
options = table.raw.map { |(k, v)| [k.to_sym, v] }.to_h
country_state = create :country_state, name: options[:country_state]
country_state = create :country_state, english_name: options[:country_state]
regional_office = create :regional_office, country_state: country_state
person = create :member_person, regional_office: regional_office
@ -40,7 +40,7 @@ end
When 'there is an excluded member account with the following data:' do |table|
options = table.raw.map { |(k, v)| [k.to_sym, v] }.to_h
country_state = create :country_state, name: options[:country_state]
country_state = create :country_state, english_name: options[:country_state]
regional_office = create :regional_office, country_state: country_state
person = create :excluded_person, regional_office: regional_office

View file

@ -19,11 +19,9 @@ 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_presence_of :native_name }
it { is_expected.to validate_uniqueness_of :name }
it { is_expected.to validate_uniqueness_of :english_name }
it { is_expected.to validate_uniqueness_of :native_name }
end