From 3e766a823a144f7e8c799169696e4ac87c68db10 Mon Sep 17 00:00:00 2001 From: Guilherme Rojas + Rafael Manzo Date: Thu, 27 Jun 2013 15:20:03 -0300 Subject: [PATCH] User model --- .gitignore | 2 ++ app/models/user.rb | 5 +++++ db/migrate/20130627170417_create_users.rb | 10 ++++++++++ db/schema.rb | 9 ++++++++- spec/factories/users.rb | 8 ++++++++ spec/models/user_spec.rb | 11 +++++++++++ 6 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 app/models/user.rb create mode 100644 db/migrate/20130627170417_create_users.rb create mode 100644 spec/factories/users.rb create mode 100644 spec/models/user_spec.rb diff --git a/.gitignore b/.gitignore index 8910bf5..8cbbb53 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,5 @@ # Ignore all logfiles and tempfiles. /log/*.log /tmp + +coverage diff --git a/app/models/user.rb b/app/models/user.rb new file mode 100644 index 0000000..bbf772b --- /dev/null +++ b/app/models/user.rb @@ -0,0 +1,5 @@ +class User < ActiveRecord::Base + validates :name, presence: true + validates :email, presence: true + validates :email, uniqueness: true +end diff --git a/db/migrate/20130627170417_create_users.rb b/db/migrate/20130627170417_create_users.rb new file mode 100644 index 0000000..7e0dcd9 --- /dev/null +++ b/db/migrate/20130627170417_create_users.rb @@ -0,0 +1,10 @@ +class CreateUsers < ActiveRecord::Migration + def change + create_table :users do |t| + t.string :name + t.string :email + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 4dfbb16..4cc93f0 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,6 +11,13 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 0) do +ActiveRecord::Schema.define(version: 20130627170417) do + + create_table "users", force: true do |t| + t.string "name" + t.string "email" + t.datetime "created_at" + t.datetime "updated_at" + end end diff --git a/spec/factories/users.rb b/spec/factories/users.rb new file mode 100644 index 0000000..a8976a2 --- /dev/null +++ b/spec/factories/users.rb @@ -0,0 +1,8 @@ +# Read about factories at https://github.com/thoughtbot/factory_girl + +FactoryGirl.define do + factory :user do + name "Diego Martinez" + email "diego@email.com" + end +end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb new file mode 100644 index 0000000..1fa16aa --- /dev/null +++ b/spec/models/user_spec.rb @@ -0,0 +1,11 @@ +require 'spec_helper' + +describe User do + context 'validations' do + subject { FactoryGirl.build(:user) } + + it { should validate_presence_of(:name) } + it { should validate_presence_of(:email) } + it { should validate_uniqueness_of(:email) } + end +end -- libgit2 0.21.2