okay, so, we have associations rocking
This commit is contained in:
@@ -0,0 +1,4 @@
|
|||||||
|
class Retirement < ActiveRecord::Base
|
||||||
|
attr_accessible :employee_contrib, :employer_contrib, :total, :user_id
|
||||||
|
belongs_to :user
|
||||||
|
end
|
||||||
+3
-2
@@ -10,7 +10,8 @@ class User < ActiveRecord::Base
|
|||||||
validates_format_of :email, :with => /.+@.+\..+/i
|
validates_format_of :email, :with => /.+@.+\..+/i
|
||||||
attr_accessor :skip_user_id_assign
|
attr_accessor :skip_user_id_assign
|
||||||
before_save :assign_user_id, :on => :create
|
before_save :assign_user_id, :on => :create
|
||||||
|
has_one :retirement, :foreign_key => :user_id, :primary_key => :user_id
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def self.authenticate(email, password)
|
def self.authenticate(email, password)
|
||||||
@@ -28,7 +29,7 @@ class User < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
return auth
|
return auth
|
||||||
end
|
end
|
||||||
|
|
||||||
def assign_user_id
|
def assign_user_id
|
||||||
unless @skip_user_id_assign.present?
|
unless @skip_user_id_assign.present?
|
||||||
user = User.order("user_id").last
|
user = User.order("user_id").last
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ class CreateUsers < ActiveRecord::Migration
|
|||||||
t.boolean :admin
|
t.boolean :admin
|
||||||
t.string :first_name
|
t.string :first_name
|
||||||
t.string :last_name
|
t.string :last_name
|
||||||
t.string :user_id
|
t.integer :user_id
|
||||||
|
|
||||||
t.timestamps
|
t.timestamps
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
class CreateRetirements < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
create_table :retirements do |t|
|
||||||
|
t.string :total
|
||||||
|
t.string :employee_contrib
|
||||||
|
t.string :employer_contrib
|
||||||
|
t.integer :user_id
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
+11
-2
@@ -11,7 +11,16 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended to check this file into your version control system.
|
# It's strongly recommended to check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(:version => 20130424220355) do
|
ActiveRecord::Schema.define(:version => 20130524222129) do
|
||||||
|
|
||||||
|
create_table "retirements", :force => true do |t|
|
||||||
|
t.string "total"
|
||||||
|
t.string "employee_contrib"
|
||||||
|
t.string "employer_contrib"
|
||||||
|
t.integer "user_id"
|
||||||
|
t.datetime "created_at", :null => false
|
||||||
|
t.datetime "updated_at", :null => false
|
||||||
|
end
|
||||||
|
|
||||||
create_table "users", :force => true do |t|
|
create_table "users", :force => true do |t|
|
||||||
t.string "email"
|
t.string "email"
|
||||||
@@ -19,7 +28,7 @@ ActiveRecord::Schema.define(:version => 20130424220355) do
|
|||||||
t.boolean "admin"
|
t.boolean "admin"
|
||||||
t.string "first_name"
|
t.string "first_name"
|
||||||
t.string "last_name"
|
t.string "last_name"
|
||||||
t.string "user_id"
|
t.integer "user_id"
|
||||||
t.datetime "created_at", :null => false
|
t.datetime "created_at", :null => false
|
||||||
t.datetime "updated_at", :null => false
|
t.datetime "updated_at", :null => false
|
||||||
end
|
end
|
||||||
|
|||||||
Vendored
+13
@@ -0,0 +1,13 @@
|
|||||||
|
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
|
||||||
|
|
||||||
|
one:
|
||||||
|
total: MyString
|
||||||
|
employee_contrib: MyString
|
||||||
|
employer_contrib: MyString
|
||||||
|
user_id: MyString
|
||||||
|
|
||||||
|
two:
|
||||||
|
total: MyString
|
||||||
|
employee_contrib: MyString
|
||||||
|
employer_contrib: MyString
|
||||||
|
user_id: MyString
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class RetirementTest < ActiveSupport::TestCase
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user