From f4ddebf5c3b6868ca0eac74ee0d00f1c4e8802f1 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Wed, 10 May 2017 01:36:14 +0300 Subject: [PATCH] Remove Address model as unused #480 --- app/models/address.rb | 72 ---------- app/models/version/address_version.rb | 5 - ...09215614_remove_addresses_with_versions.rb | 6 + db/structure.sql | 125 +----------------- doc/models_brief.svg | 23 ---- doc/models_complete.svg | 49 ------- spec/fabricators/address_fabricator.rb | 6 - spec/models/address_spec.rb | 71 ---------- 8 files changed, 8 insertions(+), 349 deletions(-) delete mode 100644 app/models/address.rb delete mode 100644 app/models/version/address_version.rb create mode 100644 db/migrate/20170509215614_remove_addresses_with_versions.rb delete mode 100644 spec/fabricators/address_fabricator.rb delete mode 100644 spec/models/address_spec.rb diff --git a/app/models/address.rb b/app/models/address.rb deleted file mode 100644 index a26b0bd28..000000000 --- a/app/models/address.rb +++ /dev/null @@ -1,72 +0,0 @@ -class Address < ActiveRecord::Base - include Versions # version/address_version.rb - - LOCAL_TYPE_SHORT = 'loc' - INTERNATIONAL_TYPE_SHORT = 'int' - LOCAL_TYPE = 'LocalAddress' - TYPES = [ - LOCAL_TYPE_SHORT, - INTERNATIONAL_TYPE_SHORT - ] - - belongs_to :contact - - def country - Country.new(country_code) - end - - class << self - # def validate_postal_info_types(parsed_frame) - # errors, used = [], [] - # parsed_frame.css('postalInfo').each do |pi| - # attr = pi.attributes['type'].try(:value) - # errors << { - # code: 2003, msg: I18n.t('errors.messages.attr_missing', key: 'type') - # } and next unless attr - # unless TYPES.include?(attr) - # errors << { - # code: 2005, - # msg: I18n.t('errors.messages.invalid_type'), value: { obj: 'type', val: attr } - # } - # next - # end - # errors << { - # code: 2005, - # msg: I18n.t('errors.messages.repeating_postal_info') - # } and next if used.include?(attr) - # used << attr - # end; errors - # end - - def extract_attributes(ah) - address_hash = {} - ah = ah.first if ah.is_a?(Array) - address_hash[:address_attributes] = addr_hash_from_params(ah) - address_hash - end - - private - - # def local?(postal_info) - # return :local_address_attributes if postal_info[:type] == LOCAL_TYPE_SHORT - # :international_address_attributes - # end - - def addr_hash_from_params(addr) - return {} if addr.nil? - return {} unless addr[:addr].is_a?(Hash) - { country_code: Country.new(addr[:addr][:cc]).try(:alpha2), - city: addr[:addr][:city], - street: pretty_street(addr[:addr][:street]), # [0], - # street2: addr[:addr][:street][1], - # street3: addr[:addr][:street][2], - zip: addr[:addr][:pc] - }.delete_if { |_k, v| v.nil? } - end - - def pretty_street(param_street) - return param_street.join(',') if param_street.is_a?(Array) - param_street - end - end -end diff --git a/app/models/version/address_version.rb b/app/models/version/address_version.rb deleted file mode 100644 index 736307c74..000000000 --- a/app/models/version/address_version.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddressVersion < PaperTrail::Version - include VersionSession - self.table_name = :log_addresses - self.sequence_name = :log_addresses_id_seq -end diff --git a/db/migrate/20170509215614_remove_addresses_with_versions.rb b/db/migrate/20170509215614_remove_addresses_with_versions.rb new file mode 100644 index 000000000..8b0dd9f9d --- /dev/null +++ b/db/migrate/20170509215614_remove_addresses_with_versions.rb @@ -0,0 +1,6 @@ +class RemoveAddressesWithVersions < ActiveRecord::Migration + def change + drop_table :addresses + drop_table :log_addresses + end +end diff --git a/db/structure.sql b/db/structure.sql index 2b4890030..a124ca56f 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -357,47 +357,6 @@ CREATE SEQUENCE accounts_id_seq ALTER SEQUENCE accounts_id_seq OWNED BY accounts.id; --- --- Name: addresses; Type: TABLE; Schema: public; Owner: -; Tablespace: --- - -CREATE TABLE addresses ( - id integer NOT NULL, - contact_id integer, - city character varying, - street character varying, - zip character varying, - created_at timestamp without time zone, - updated_at timestamp without time zone, - street2 character varying, - street3 character varying, - creator_str character varying, - updator_str character varying, - country_code character varying, - state character varying, - legacy_contact_id integer -); - - --- --- Name: addresses_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE addresses_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: addresses_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE addresses_id_seq OWNED BY addresses.id; - - -- -- Name: api_users; Type: TABLE; Schema: public; Owner: -; Tablespace: -- @@ -1421,44 +1380,6 @@ CREATE SEQUENCE log_accounts_id_seq ALTER SEQUENCE log_accounts_id_seq OWNED BY log_accounts.id; --- --- Name: log_addresses; Type: TABLE; Schema: public; Owner: -; Tablespace: --- - -CREATE TABLE log_addresses ( - id integer NOT NULL, - item_type character varying NOT NULL, - item_id integer NOT NULL, - event character varying NOT NULL, - whodunnit character varying, - object json, - object_changes json, - created_at timestamp without time zone, - session character varying, - children json, - uuid character varying -); - - --- --- Name: log_addresses_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE log_addresses_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: log_addresses_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE log_addresses_id_seq OWNED BY log_addresses.id; - - -- -- Name: log_api_users; Type: TABLE; Schema: public; Owner: -; Tablespace: -- @@ -2985,13 +2906,6 @@ ALTER TABLE ONLY account_activities ALTER COLUMN id SET DEFAULT nextval('account ALTER TABLE ONLY accounts ALTER COLUMN id SET DEFAULT nextval('accounts_id_seq'::regclass); --- --- Name: id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY addresses ALTER COLUMN id SET DEFAULT nextval('addresses_id_seq'::regclass); - - -- -- Name: id; Type: DEFAULT; Schema: public; Owner: - -- @@ -3167,13 +3081,6 @@ ALTER TABLE ONLY log_account_activities ALTER COLUMN id SET DEFAULT nextval('log ALTER TABLE ONLY log_accounts ALTER COLUMN id SET DEFAULT nextval('log_accounts_id_seq'::regclass); --- --- Name: id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY log_addresses ALTER COLUMN id SET DEFAULT nextval('log_addresses_id_seq'::regclass); - - -- -- Name: id; Type: DEFAULT; Schema: public; Owner: - -- @@ -3463,14 +3370,6 @@ ALTER TABLE ONLY accounts ADD CONSTRAINT accounts_pkey PRIMARY KEY (id); --- --- Name: addresses_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: --- - -ALTER TABLE ONLY addresses - ADD CONSTRAINT addresses_pkey PRIMARY KEY (id); - - -- -- Name: api_users_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: -- @@ -3671,14 +3570,6 @@ ALTER TABLE ONLY log_accounts ADD CONSTRAINT log_accounts_pkey PRIMARY KEY (id); --- --- Name: log_addresses_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: --- - -ALTER TABLE ONLY log_addresses - ADD CONSTRAINT log_addresses_pkey PRIMARY KEY (id); - - -- -- Name: log_api_users_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: -- @@ -4307,20 +4198,6 @@ CREATE INDEX index_log_accounts_on_item_type_and_item_id ON log_accounts USING b CREATE INDEX index_log_accounts_on_whodunnit ON log_accounts USING btree (whodunnit); --- --- Name: index_log_addresses_on_item_type_and_item_id; Type: INDEX; Schema: public; Owner: -; Tablespace: --- - -CREATE INDEX index_log_addresses_on_item_type_and_item_id ON log_addresses USING btree (item_type, item_id); - - --- --- Name: index_log_addresses_on_whodunnit; Type: INDEX; Schema: public; Owner: -; Tablespace: --- - -CREATE INDEX index_log_addresses_on_whodunnit ON log_addresses USING btree (whodunnit); - - -- -- Name: index_log_api_users_on_item_type_and_item_id; Type: INDEX; Schema: public; Owner: -; Tablespace: -- @@ -5257,3 +5134,5 @@ INSERT INTO schema_migrations (version) VALUES ('20170423225333'); INSERT INTO schema_migrations (version) VALUES ('20170424115801'); +INSERT INTO schema_migrations (version) VALUES ('20170509215614'); + diff --git a/doc/models_brief.svg b/doc/models_brief.svg index e7e51b56d..a99210ea9 100644 --- a/doc/models_brief.svg +++ b/doc/models_brief.svg @@ -216,17 +216,6 @@ - -AddressVersion - -AddressVersion - - -AddressVersion->VersionAssociation - - - - BankStatementVersion @@ -1442,18 +1431,6 @@ versions - -Address - -Address - - -Address->AddressVersion - - - -versions - LegalDocument->LegalDocumentVersion diff --git a/doc/models_complete.svg b/doc/models_complete.svg index d7150a9e8..8a1d39a65 100644 --- a/doc/models_complete.svg +++ b/doc/models_complete.svg @@ -423,28 +423,6 @@ - -AddressVersion - -AddressVersion - -id :integer -item_type :string -item_id :integer -event :string -whodunnit :string -object :json -object_changes :json -created_at :datetime -session :string -children :json - - -AddressVersion->VersionAssociation - - - - BankStatementVersion @@ -2276,33 +2254,6 @@ versions - -Address - -Address - -id :integer -contact_id :integer -city :string -street :string -zip :string -created_at :datetime -updated_at :datetime -street2 :string -street3 :string -creator_str :string -updator_str :string -country_code :string -state :string -legacy_contact_id :integer - - -Address->AddressVersion - - - -versions - LegalDocument->LegalDocumentVersion diff --git a/spec/fabricators/address_fabricator.rb b/spec/fabricators/address_fabricator.rb deleted file mode 100644 index ecdb50f58..000000000 --- a/spec/fabricators/address_fabricator.rb +++ /dev/null @@ -1,6 +0,0 @@ -Fabricator(:address) do - city 'test city' - street 'test street' - street2 'test street' - zip 12345 -end diff --git a/spec/models/address_spec.rb b/spec/models/address_spec.rb deleted file mode 100644 index fe63fb38f..000000000 --- a/spec/models/address_spec.rb +++ /dev/null @@ -1,71 +0,0 @@ -require 'rails_helper' - -describe Address do - context 'about class' do - it 'should have versioning enabled?' do - Address.paper_trail_enabled_for_model?.should == true - end - - it 'should have custom log prexied table name for versions table' do - AddressVersion.table_name.should == 'log_addresses' - end - end - - context 'with invalid attribute' do - before :all do - @address = Address.new - end - - it 'should not be valid' do - @address.valid? - @address.errors.full_messages.should match_array([ - ]) - end - - it 'should not have any versions' do - @address.versions.should == [] - end - end - - context 'with valid attributes' do - before :all do - @address = Fabricate(:address) - end - - it 'should be valid' do - @address.valid? - @address.errors.full_messages.should match_array([]) - end - - it 'should be valid twice' do - @address = Fabricate(:address) - @address.valid? - @address.errors.full_messages.should match_array([]) - end - - it 'should have one version' do - with_versioning do - @address.versions.should == [] - @address.zip = 'New zip' - @address.save - @address.errors.full_messages.should match_array([]) - @address.versions.size.should == 1 - end - end - end -end - -# TODO: country issue -# describe Address, '.extract_params' do - # it 'returns params hash' do - # Fabricate(:country, iso: 'EE') - # ph = { postalInfo: { name: 'fred', addr: { cc: 'EE', city: 'Village', street: 'street1' } } } - # expect(Address.extract_attributes(ph[:postalInfo])).to eq({ - # address_attributes: { - # country_id: Country.find_by(iso: 'EE').id, - # city: 'Village', - # street: 'street1' - # } - # }) - # end -# end