From 9fe6bf75308b823dc48ba1a0e9b7c57901d98054 Mon Sep 17 00:00:00 2001 From: Benjamin Cousaert Date: Tue, 9 Dec 2014 20:28:50 +0100 Subject: [PATCH] Add dagschotel to users --- app/models/user.rb | 5 ++++- db/migrate/20141209192545_add_dagschotel_to_users.rb | 5 +++++ db/schema.rb | 3 ++- test/fixtures/users.yml | 2 ++ test/models/user_test.rb | 2 ++ 5 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20141209192545_add_dagschotel_to_users.rb diff --git a/app/models/user.rb b/app/models/user.rb index e7a2dad..e6311f4 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -16,6 +16,8 @@ # last_sign_in_at :datetime # current_sign_in_ip :string(255) # last_sign_in_ip :string(255) +# dagschotel :reference +# dagschotel_id :integer # class User < ActiveRecord::Base @@ -23,11 +25,12 @@ class User < ActiveRecord::Base :rememberable, :trackable has_many :orders, -> { includes :products } + belongs_to :dagschotel, class_name: 'Product' validates :nickname, presence: true, uniqueness: true validates :name, presence: true validates :last_name, presence: true - validates :password, length: { in: 8..128 }, confirmation: true + validates :password, length: { in: 8..128 }, confirmation: true, on: :create def full_name "#{name} #{last_name}" diff --git a/db/migrate/20141209192545_add_dagschotel_to_users.rb b/db/migrate/20141209192545_add_dagschotel_to_users.rb new file mode 100644 index 0000000..82509a5 --- /dev/null +++ b/db/migrate/20141209192545_add_dagschotel_to_users.rb @@ -0,0 +1,5 @@ +class AddDagschotelToUsers < ActiveRecord::Migration + def change + add_reference :users, :dagschotel + end +end diff --git a/db/schema.rb b/db/schema.rb index e52179a..002ed1e 100644 --- a/db/schema.rb +++ b/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: 20141209172818) do +ActiveRecord::Schema.define(version: 20141209192545) do create_table "order_products", force: true do |t| t.integer "order_id" @@ -54,6 +54,7 @@ ActiveRecord::Schema.define(version: 20141209172818) do t.datetime "last_sign_in_at" t.string "current_sign_in_ip" t.string "last_sign_in_ip" + t.integer "dagschotel_id" end end diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml index a086a02..4d5b784 100644 --- a/test/fixtures/users.yml +++ b/test/fixtures/users.yml @@ -16,6 +16,8 @@ # last_sign_in_at :datetime # current_sign_in_ip :string(255) # last_sign_in_ip :string(255) +# dagschotel :reference +# dagschotel_id :integer # # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html diff --git a/test/models/user_test.rb b/test/models/user_test.rb index 4682454..1e0afd3 100644 --- a/test/models/user_test.rb +++ b/test/models/user_test.rb @@ -16,6 +16,8 @@ # last_sign_in_at :datetime # current_sign_in_ip :string(255) # last_sign_in_ip :string(255) +# dagschotel :reference +# dagschotel_id :integer # require 'test_helper'