Skip to content
This repository was archived by the owner on Jun 27, 2023. It is now read-only.

Commit 549d370

Browse files
committed
creating postal address model and removing attribute from users
1 parent c954a2a commit 549d370

File tree

7 files changed

+46
-7
lines changed

7 files changed

+46
-7
lines changed

app/controllers/users_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def user_params
9797
:github_handle, :twitter_handle, :irc_handle,
9898
:name, :email, :homepage, :location, :bio,
9999
:tech_expertise_list, :tech_interest_list,
100-
:tshirt_size, :tshirt_cut, :postal_address, :timezone,
100+
:tshirt_size, :tshirt_cut, :timezone,
101101
:country,
102102
:hide_email,
103103
:is_company, :company_name, :company_info,

app/models/postal_address.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class PostalAddress < ApplicationRecord
2+
belongs_to :user
3+
validates_presence_of :address_line_1, :city, :postal_code, :country
4+
end

app/models/user.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ def student
6565
has_many :applications, through: :teams
6666
has_many :todos, dependent: :destroy
6767
has_many :comments, dependent: :destroy
68+
has_one :postal_address, dependent: :destroy
6869

6970
validates :github_handle, presence: true, uniqueness: { case_sensitive: false }
7071
validates :homepage, format: { with: URL_PREFIX_PATTERN }, allow_blank: true
@@ -73,6 +74,7 @@ def student
7374
validates :name, :email, :country, :location, presence: true, unless: :github_import
7475

7576
accepts_nested_attributes_for :roles, allow_destroy: true
77+
accepts_nested_attributes_for :postal_address, allow_destroy: true
7678

7779
before_save :normalize_location
7880
after_create :complete_from_github
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class CreatePostalAddresses < ActiveRecord::Migration[5.1]
2+
def change
3+
create_table :postal_addresses do |t|
4+
t.string :address_line_1
5+
t.string :address_line_2
6+
t.string :city
7+
t.string :state_or_province
8+
t.string :postal_code
9+
t.string :country
10+
11+
t.references :user, foreign_key: true
12+
t.timestamps
13+
end
14+
end
15+
end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class RemovePostalAddressFromUsers < ActiveRecord::Migration[5.1]
2+
def change
3+
remove_column :users, :postal_address, :text
4+
end
5+
end

db/schema.rb

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema.define(version: 20180714153306) do
13+
ActiveRecord::Schema.define(version: 20181107172409) do
1414

1515
# These are extensions that must be enabled in order to support this database
1616
enable_extension "plpgsql"
@@ -173,6 +173,19 @@
173173
t.index ["user_id"], name: "index_notes_on_user_id"
174174
end
175175

176+
create_table "postal_addresses", force: :cascade do |t|
177+
t.string "address_line_1"
178+
t.string "address_line_2"
179+
t.string "city"
180+
t.string "state_or_province"
181+
t.string "postal_code"
182+
t.string "country"
183+
t.bigint "user_id"
184+
t.datetime "created_at", null: false
185+
t.datetime "updated_at", null: false
186+
t.index ["user_id"], name: "index_postal_addresses_on_user_id"
187+
end
188+
176189
create_table "projects", id: :serial, force: :cascade do |t|
177190
t.string "name", limit: 255
178191
t.datetime "created_at"
@@ -296,7 +309,6 @@
296309
t.string "twitter_handle", limit: 255
297310
t.string "irc_handle", limit: 255
298311
t.string "tshirt_size", limit: 255
299-
t.text "postal_address"
300312
t.string "timezone", limit: 255
301313
t.string "interested_in", limit: 255, default: [], array: true
302314
t.boolean "hide_email"
@@ -339,5 +351,6 @@
339351
t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true
340352
end
341353

354+
add_foreign_key "postal_addresses", "users"
342355
add_foreign_key "teams", "projects"
343356
end

spec/models/postal_address_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
end
77

88
describe 'validations' do
9-
it { should_validate_presence_of(:address_line_1)}
10-
it { should_validate_presence_of(:city)}
11-
it { should_validate_presence_of(:postal_code)}
12-
it { should_validate_presence_of(:country)}
9+
it { is_expected.to validate_presence_of(:address_line_1)}
10+
it { is_expected.to validate_presence_of(:city)}
11+
it { is_expected.to validate_presence_of(:postal_code)}
12+
it { is_expected.to validate_presence_of(:country)}
1313
end
1414
end

0 commit comments

Comments
 (0)