Commit 34dcbc8
Changed files (6)
app
models
spec
models
app/models/profile.rb
@@ -2,7 +2,7 @@ class Profile < ActiveRecord::Base
belongs_to :user
enum social_tolerance: { low: 0, medium: 1, high: 2 }
enum gender: { other: nil, male: 1, female: 0, transgender: 2 }
-
+
def to_param
user.username
end
app/models/user.rb
@@ -61,7 +61,7 @@ class User < ActiveRecord::Base
private
- def create_profile
- self.profile = Profile.create!(user: self, gender: nil, social_tolerance: nil)
- end
+ def create_profile
+ self.profile = Profile.create!(user: self)
+ end
end
db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20150814004716) do
+ActiveRecord::Schema.define(version: 20151115190853) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -42,11 +42,11 @@ ActiveRecord::Schema.define(version: 20150814004716) do
end
create_table "profiles", id: :uuid, default: "uuid_generate_v4()", force: :cascade do |t|
- t.uuid "user_id", null: false
+ t.uuid "user_id", null: false
t.integer "gender"
- t.integer "social_tolerance", default: 0
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
+ t.integer "social_tolerance"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
end
add_index "profiles", ["user_id"], name: "index_profiles_on_user_id", using: :btree
spec/models/profile_spec.rb
@@ -1,25 +1,23 @@
require 'rails_helper'
describe Profile do
-
let(:user) { create(:user) }
-
+
describe "profile owner" do
it "has profile" do
expect(user.profile).to_not eql(nil)
end
end
-
+
describe "gender" do
it "defaults to unset" do
expect(user.profile.other?).to be_truthy
end
end
-
+
describe "social tolerance" do
it "defaults to unset" do
expect(user.profile.social_tolerance).to eql(nil)
end
end
-
end
spec/models/user_spec.rb
@@ -191,4 +191,14 @@ describe User do
expect(ExerciseSession.all).to be_empty
end
end
+
+ describe "#profile" do
+ let(:user) { create(:user) }
+
+ it "creates a new profile" do
+ expect(user.profile).to be_present
+ expect(user.profile.other?).to be_truthy
+ expect(user.profile.social_tolerance).to be_nil
+ end
+ end
end