From f3ee286a8ec400032c8c5aa8b4525cae3bc79b97 Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Wed, 11 Mar 2015 13:38:42 -0500 Subject: [PATCH] Start working on some basic MVC things. --- Gemfile | 35 ++++++++++++------------------- Gemfile.lock | 35 ++----------------------------- app/assets/javascripts/application.js | 1 - app/assets/javascripts/tools.js | 2 ++ app/assets/javascripts/users.js | 2 ++ app/assets/stylesheets/tools.css | 4 ++++ app/assets/stylesheets/users.css | 4 ++++ app/controllers/application_controller.rb | 5 ----- app/controllers/tools_controller.rb | 4 ++++ app/controllers/users_controller.rb | 7 +++++++ app/helpers/application_helper.rb | 5 +++++ app/helpers/tools_helper.rb | 2 ++ app/helpers/users_helper.rb | 2 ++ app/models/user.rb | 2 ++ app/views/layouts/application.html.erb | 8 +++---- app/views/tools/index.html.erb | 2 ++ app/views/users/create.html.erb | 4 ++++ app/views/users/login.html.erb | 4 ++++ config/routes.rb | 8 +++---- db/migrate/20150311175036_create_users.rb | 12 +++++++++++ db/schema.rb | 25 ++++++++++++++++++++++ test/controllers/tools_controller_test.rb | 9 ++++++++ test/controllers/users_controller_test.rb | 14 +++++++++++++ test/fixtures/users.yml | 13 ++++++++++++ test/models/user_test.rb | 7 +++++++ 25 files changed, 147 insertions(+), 69 deletions(-) create mode 100644 app/assets/javascripts/tools.js create mode 100644 app/assets/javascripts/users.js create mode 100644 app/assets/stylesheets/tools.css create mode 100644 app/assets/stylesheets/users.css create mode 100644 app/controllers/tools_controller.rb create mode 100644 app/controllers/users_controller.rb create mode 100644 app/helpers/tools_helper.rb create mode 100644 app/helpers/users_helper.rb create mode 100644 app/models/user.rb create mode 100644 app/views/tools/index.html.erb create mode 100644 app/views/users/create.html.erb create mode 100644 app/views/users/login.html.erb create mode 100644 db/migrate/20150311175036_create_users.rb create mode 100644 db/schema.rb create mode 100644 test/controllers/tools_controller_test.rb create mode 100644 test/controllers/users_controller_test.rb create mode 100644 test/fixtures/users.yml create mode 100644 test/models/user_test.rb diff --git a/Gemfile b/Gemfile index b43fd2f..0b3c36f 100644 --- a/Gemfile +++ b/Gemfile @@ -1,37 +1,29 @@ source 'https://rubygems.org' - -# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '4.2.0' -# Use sqlite3 as the database for Active Record gem 'sqlite3' -# Use SCSS for stylesheets -gem 'sass-rails', '~> 5.0' -# Use Uglifier as compressor for JavaScript assets gem 'uglifier', '>= 1.3.0' -# Use CoffeeScript for .coffee assets and views -gem 'coffee-rails', '~> 4.1.0' +gem 'jquery-rails' + +# At this point, avoid using SASS or CoffeeScript +# gem 'sass-rails', '~> 5.0' +# gem 'coffee-rails', '~> 4.1.0' + +# Avoid Turbolinks for now (https://github.com/rails/turbolinks) +# gem 'turbolinks' + # See https://github.com/sstephenson/execjs#readme for more supported runtimes # gem 'therubyracer', platforms: :ruby -# Use jquery as the JavaScript library -gem 'jquery-rails' -# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks -gem 'turbolinks' # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder -gem 'jbuilder', '~> 2.0' +# gem 'jbuilder', '~> 2.0' + # bundle exec rake doc:rails generates the API under doc/api. -gem 'sdoc', '~> 0.4.0', group: :doc +# gem 'sdoc', '~> 0.4.0', group: :doc # Use ActiveModel has_secure_password # gem 'bcrypt', '~> 3.1.7' -# Use Unicorn as the app server -# gem 'unicorn' - -# Use Capistrano for deployment -# gem 'capistrano-rails', group: :development - group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug' @@ -40,6 +32,5 @@ group :development, :test do gem 'web-console', '~> 2.0' # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring - gem 'spring' + # gem 'spring' end - diff --git a/Gemfile.lock b/Gemfile.lock index 7c2f03a..a9e4335 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -44,13 +44,6 @@ GEM columnize (~> 0.8) debugger-linecache (~> 1.2) slop (~> 3.6) - coffee-rails (4.1.0) - coffee-script (>= 2.2.0) - railties (>= 4.0.0, < 5.0) - coffee-script (2.3.0) - coffee-script-source - execjs - coffee-script-source (1.9.1) columnize (0.9.0) debug_inspector (0.0.2) debugger-linecache (1.2.0) @@ -60,9 +53,6 @@ GEM activesupport (>= 4.1.0) hike (1.2.3) i18n (0.7.0) - jbuilder (2.2.11) - activesupport (>= 3.0.0, < 5) - multi_json (~> 1.2) jquery-rails (4.0.3) rails-dom-testing (~> 1.0) railties (>= 4.2.0) @@ -98,7 +88,7 @@ GEM activesupport (>= 4.2.0.beta, < 5.0) nokogiri (~> 1.6.0) rails-deprecated_sanitizer (>= 1.0.1) - rails-html-sanitizer (1.0.1) + rails-html-sanitizer (1.0.2) loofah (~> 2.0) railties (4.2.0) actionpack (= 4.2.0) @@ -106,20 +96,7 @@ GEM rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) rake (10.4.2) - rdoc (4.2.0) - json (~> 1.4) - sass (3.4.13) - sass-rails (5.0.1) - railties (>= 4.0.0, < 5.0) - sass (~> 3.1) - sprockets (>= 2.8, < 4.0) - sprockets-rails (>= 2.0, < 4.0) - tilt (~> 1.1) - sdoc (0.4.1) - json (~> 1.7, >= 1.7.7) - rdoc (~> 4.0) slop (3.6.0) - spring (1.3.3) sprockets (2.12.3) hike (~> 1.2) multi_json (~> 1.0) @@ -131,10 +108,8 @@ GEM sprockets (>= 2.8, < 4.0) sqlite3 (1.3.10) thor (0.19.1) - thread_safe (0.3.4) + thread_safe (0.3.5) tilt (1.4.1) - turbolinks (2.5.3) - coffee-rails tzinfo (1.2.2) thread_safe (~> 0.1) uglifier (2.7.1) @@ -151,14 +126,8 @@ PLATFORMS DEPENDENCIES byebug - coffee-rails (~> 4.1.0) - jbuilder (~> 2.0) jquery-rails rails (= 4.2.0) - sass-rails (~> 5.0) - sdoc (~> 0.4.0) - spring sqlite3 - turbolinks uglifier (>= 1.3.0) web-console (~> 2.0) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 4a2ae1d..3e5bd21 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -12,5 +12,4 @@ // //= require jquery //= require jquery_ujs -//= require turbolinks //= require_tree . diff --git a/app/assets/javascripts/tools.js b/app/assets/javascripts/tools.js new file mode 100644 index 0000000..dee720f --- /dev/null +++ b/app/assets/javascripts/tools.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/javascripts/users.js b/app/assets/javascripts/users.js new file mode 100644 index 0000000..dee720f --- /dev/null +++ b/app/assets/javascripts/users.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/stylesheets/tools.css b/app/assets/stylesheets/tools.css new file mode 100644 index 0000000..afad32d --- /dev/null +++ b/app/assets/stylesheets/tools.css @@ -0,0 +1,4 @@ +/* + Place all the styles related to the matching controller here. + They will automatically be included in application.css. +*/ diff --git a/app/assets/stylesheets/users.css b/app/assets/stylesheets/users.css new file mode 100644 index 0000000..afad32d --- /dev/null +++ b/app/assets/stylesheets/users.css @@ -0,0 +1,4 @@ +/* + Place all the styles related to the matching controller here. + They will automatically be included in application.css. +*/ diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 1ac0408..d83690e 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,9 +2,4 @@ class ApplicationController < ActionController::Base # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception - - def hello - render text: "hello, world!" - end - end diff --git a/app/controllers/tools_controller.rb b/app/controllers/tools_controller.rb new file mode 100644 index 0000000..9e65046 --- /dev/null +++ b/app/controllers/tools_controller.rb @@ -0,0 +1,4 @@ +class ToolsController < ApplicationController + def index + end +end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb new file mode 100644 index 0000000..d516673 --- /dev/null +++ b/app/controllers/users_controller.rb @@ -0,0 +1,7 @@ +class UsersController < ApplicationController + def create + end + + def login + end +end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index de6be79..ea178ef 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,2 +1,7 @@ module ApplicationHelper + + def get_title(title = '') + base = 'Calefaction' + title.empty? ? base : "#{title} : #{base}" + end end diff --git a/app/helpers/tools_helper.rb b/app/helpers/tools_helper.rb new file mode 100644 index 0000000..6f87959 --- /dev/null +++ b/app/helpers/tools_helper.rb @@ -0,0 +1,2 @@ +module ToolsHelper +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..4a57cf0 --- /dev/null +++ b/app/models/user.rb @@ -0,0 +1,2 @@ +class User < ActiveRecord::Base +end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index d72c2a2..24674fd 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -1,10 +1,10 @@ - Calefaction - <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> - <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> - <%= csrf_meta_tags %> + <%= get_title(yield(:title)) %> + <%= stylesheet_link_tag 'application', media: 'all' %> + <%= javascript_include_tag 'application' %> + <%= csrf_meta_tags %> diff --git a/app/views/tools/index.html.erb b/app/views/tools/index.html.erb new file mode 100644 index 0000000..fcd7c1c --- /dev/null +++ b/app/views/tools/index.html.erb @@ -0,0 +1,2 @@ +

Tools#index

+

Find me in app/views/tools/index.html.erb

diff --git a/app/views/users/create.html.erb b/app/views/users/create.html.erb new file mode 100644 index 0000000..49927e6 --- /dev/null +++ b/app/views/users/create.html.erb @@ -0,0 +1,4 @@ +<% provide(:title, 'Signup') %> + +

Users#create

+

Find me in app/views/users/create.html.erb

diff --git a/app/views/users/login.html.erb b/app/views/users/login.html.erb new file mode 100644 index 0000000..7fe1641 --- /dev/null +++ b/app/views/users/login.html.erb @@ -0,0 +1,4 @@ +<% provide(:title, 'Login') %> + +

Users#login

+

Find me in app/views/users/login.html.erb

diff --git a/config/routes.rb b/config/routes.rb index 2bcfb49..5884244 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,9 +1,9 @@ Rails.application.routes.draw do - # The priority is based upon order of creation: first created -> highest priority. - # See how all your routes lay out with "rake routes". + root 'tools#index' + + get '/signup' => 'users#create' + get '/login' => 'users#login' - # You can have the root of your site routed with "root" - root 'application#hello' # Example of regular route: # get 'products/:id' => 'catalog#view' diff --git a/db/migrate/20150311175036_create_users.rb b/db/migrate/20150311175036_create_users.rb new file mode 100644 index 0000000..a19be02 --- /dev/null +++ b/db/migrate/20150311175036_create_users.rb @@ -0,0 +1,12 @@ +class CreateUsers < ActiveRecord::Migration + def change + create_table :users do |t| + t.string :name + t.string :email + t.string :password_hash + t.boolean :is_admin + + t.timestamps null: false + end + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000..62071db --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,25 @@ +# encoding: UTF-8 +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# Note that this schema.rb definition is the authoritative source for your +# database schema. If you need to create the application database on another +# system, you should be using db:schema:load, not running all the migrations +# from scratch. The latter is a flawed and unsustainable approach (the more migrations +# you'll amass, the slower it'll run and the greater likelihood for issues). +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema.define(version: 20150311175036) do + + create_table "users", force: :cascade do |t| + t.string "name" + t.string "email" + t.string "password_hash" + t.boolean "is_admin" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + +end diff --git a/test/controllers/tools_controller_test.rb b/test/controllers/tools_controller_test.rb new file mode 100644 index 0000000..1ef9461 --- /dev/null +++ b/test/controllers/tools_controller_test.rb @@ -0,0 +1,9 @@ +require 'test_helper' + +class ToolsControllerTest < ActionController::TestCase + test "should get index" do + get :index + assert_response :success + end + +end diff --git a/test/controllers/users_controller_test.rb b/test/controllers/users_controller_test.rb new file mode 100644 index 0000000..ccf7ad1 --- /dev/null +++ b/test/controllers/users_controller_test.rb @@ -0,0 +1,14 @@ +require 'test_helper' + +class UsersControllerTest < ActionController::TestCase + test "should get create" do + get :create + assert_response :success + end + + test "should get login" do + get :login + assert_response :success + end + +end diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml new file mode 100644 index 0000000..bea6138 --- /dev/null +++ b/test/fixtures/users.yml @@ -0,0 +1,13 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + name: MyString + email: MyString + password_hash: MyString + is_admin: false + +two: + name: MyString + email: MyString + password_hash: MyString + is_admin: false diff --git a/test/models/user_test.rb b/test/models/user_test.rb new file mode 100644 index 0000000..82f61e0 --- /dev/null +++ b/test/models/user_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class UserTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end