From 19e5a4a07659db6d696ecb06271ebc2ecaff7aa4 Mon Sep 17 00:00:00 2001 From: "daniel.hahn" Date: Thu, 23 Feb 2012 11:15:13 +0100 Subject: [PATCH] New user model and controller --- .gitignore | 1 + app/assets/javascripts/users.js.coffee | 3 +++ app/assets/stylesheets/users.css.scss | 3 +++ app/controllers/users_controller.rb | 2 ++ app/helpers/users_helper.rb | 2 ++ app/models/user.rb | 5 +++++ db/migrate/20120223100854_create_users.rb | 10 ++++++++++ db/schema.rb | 16 +++++++++++++++- test/fixtures/users.yml | 9 +++++++++ test/functional/users_controller_test.rb | 7 +++++++ test/unit/helpers/users_helper_test.rb | 4 ++++ test/unit/user_test.rb | 7 +++++++ 12 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 app/assets/javascripts/users.js.coffee create mode 100644 app/assets/stylesheets/users.css.scss create mode 100644 app/controllers/users_controller.rb create mode 100644 app/helpers/users_helper.rb create mode 100644 app/models/user.rb create mode 100644 db/migrate/20120223100854_create_users.rb create mode 100644 test/fixtures/users.yml create mode 100644 test/functional/users_controller_test.rb create mode 100644 test/unit/helpers/users_helper_test.rb create mode 100644 test/unit/user_test.rb diff --git a/.gitignore b/.gitignore index eb3489a..6ae23e2 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ # Ignore all logfiles and tempfiles. /log/*.log /tmp +*~ diff --git a/app/assets/javascripts/users.js.coffee b/app/assets/javascripts/users.js.coffee new file mode 100644 index 0000000..7615679 --- /dev/null +++ b/app/assets/javascripts/users.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/stylesheets/users.css.scss b/app/assets/stylesheets/users.css.scss new file mode 100644 index 0000000..1efc835 --- /dev/null +++ b/app/assets/stylesheets/users.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the users controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb new file mode 100644 index 0000000..3e74dea --- /dev/null +++ b/app/controllers/users_controller.rb @@ -0,0 +1,2 @@ +class UsersController < ApplicationController +end diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb new file mode 100644 index 0000000..2310a24 --- /dev/null +++ b/app/helpers/users_helper.rb @@ -0,0 +1,2 @@ +module UsersHelper +end diff --git a/app/models/user.rb b/app/models/user.rb new file mode 100644 index 0000000..7340ccf --- /dev/null +++ b/app/models/user.rb @@ -0,0 +1,5 @@ +class User < ActiveRecord::Base + validates_presence_of :name, :email + validates_uniqueness_of :email +end + diff --git a/db/migrate/20120223100854_create_users.rb b/db/migrate/20120223100854_create_users.rb new file mode 100644 index 0000000..472eafd --- /dev/null +++ b/db/migrate/20120223100854_create_users.rb @@ -0,0 +1,10 @@ +class CreateUsers < ActiveRecord::Migration + def change + create_table :users do |t| + t.string :email + t.string :name + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 671c0da..4f79aeb 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,6 +10,20 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 0) do +ActiveRecord::Schema.define(:version => 20120223100854) do + + create_table "todos", :force => true do |t| + t.string "description" + t.boolean "done" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + + create_table "users", :force => true do |t| + t.string "email" + t.string "name" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end end diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml new file mode 100644 index 0000000..db420ae --- /dev/null +++ b/test/fixtures/users.yml @@ -0,0 +1,9 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html + +one: + email: MyString + name: MyString + +two: + email: MyString + name: MyString diff --git a/test/functional/users_controller_test.rb b/test/functional/users_controller_test.rb new file mode 100644 index 0000000..d23f182 --- /dev/null +++ b/test/functional/users_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class UsersControllerTest < ActionController::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/unit/helpers/users_helper_test.rb b/test/unit/helpers/users_helper_test.rb new file mode 100644 index 0000000..96af37a --- /dev/null +++ b/test/unit/helpers/users_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class UsersHelperTest < ActionView::TestCase +end diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb new file mode 100644 index 0000000..82f61e0 --- /dev/null +++ b/test/unit/user_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class UserTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end