diff --git a/.gitignore b/.gitignore index 6a502e99..ec4d9b29 100644 --- a/.gitignore +++ b/.gitignore @@ -1,16 +1,12 @@ -# See https://help.github.com/articles/ignoring-files for more about ignoring files. -# -# If you find yourself ignoring temporary files generated by your text editor -# or operating system, you probably want to add a global ignore instead: -# git config --global core.excludesfile '~/.gitignore_global' - -# Ignore bundler config. /.bundle -# Ignore the default SQLite database. /db/*.sqlite3 /db/*.sqlite3-journal -# Ignore all logfiles and tempfiles. /log/*.log /tmp + +/config/database.yml +.sass-cache/ +coverage/ +*.swp diff --git a/Gemfile b/Gemfile index a25e45a0..1befa0d9 100644 --- a/Gemfile +++ b/Gemfile @@ -1,49 +1,37 @@ source 'https://rubygems.org' +gem 'rails', '4.1.6' + +gem 'pg', group: :postgres +gem 'mysql2', group: :mysql -# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' -gem 'rails', '4.1.4' -# Use sqlite3 as the database for Active Record -gem 'sqlite3' -# Use SCSS for stylesheets gem 'sass-rails', '~> 4.0.3' -# Use Uglifier as compressor for JavaScript assets gem 'uglifier', '>= 1.3.0' -# Use CoffeeScript for .js.coffee assets and views -gem 'coffee-rails', '~> 4.0.0' -# See https://github.com/sstephenson/execjs#readme for more supported runtimes -# gem 'therubyracer', platforms: :ruby - -# Use jquery as the JavaScript library +gem 'coffee-rails', '~> 4.1.0' 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' -# bundle exec rake doc:rails generates the API under doc/api. -gem 'sdoc', '~> 0.4.0', group: :doc +gem 'jbuilder', '~> 2.2.4' +gem 'sdoc', '~> 0.4.1', group: :doc -# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring -gem 'spring', group: :development +gem 'bcrypt', '~> 3.1.7' -# 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 - -# Use debugger -# gem 'debugger', group: [:development, :test] - -gem 'thin' -gem 'bootstrap-sass', '~> 3.2.0.1' -gem 'bootswatch-rails', '~> 3.2.0' gem 'haml' +gem 'semantic-ui-sass', '~> 0.19.3.0' gem 'will_paginate' -gem 'will_paginate-bootstrap' gem 'http_accept_language' gem 'devise' -gem 'bootstrap_form' +gem 'font-kit-rails' +gem 'nprogress-rails' + +group :development do + gem 'thin' + gem 'spring' +end + +group :production do + gem 'unicorn', group: :production +end + +group :test do + gem 'simplecov' +end diff --git a/Gemfile.lock b/Gemfile.lock index bca0cc26..65bcba8f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,161 +1,173 @@ GEM remote: https://rubygems.org/ specs: - actionmailer (4.1.4) - actionpack (= 4.1.4) - actionview (= 4.1.4) - mail (~> 2.5.4) - actionpack (4.1.4) - actionview (= 4.1.4) - activesupport (= 4.1.4) + actionmailer (4.1.6) + actionpack (= 4.1.6) + actionview (= 4.1.6) + mail (~> 2.5, >= 2.5.4) + actionpack (4.1.6) + actionview (= 4.1.6) + activesupport (= 4.1.6) rack (~> 1.5.2) rack-test (~> 0.6.2) - actionview (4.1.4) - activesupport (= 4.1.4) + actionview (4.1.6) + activesupport (= 4.1.6) builder (~> 3.1) erubis (~> 2.7.0) - activemodel (4.1.4) - activesupport (= 4.1.4) + activemodel (4.1.6) + activesupport (= 4.1.6) builder (~> 3.1) - activerecord (4.1.4) - activemodel (= 4.1.4) - activesupport (= 4.1.4) + activerecord (4.1.6) + activemodel (= 4.1.6) + activesupport (= 4.1.6) arel (~> 5.0.0) - activesupport (4.1.4) + activesupport (4.1.6) i18n (~> 0.6, >= 0.6.9) json (~> 1.7, >= 1.7.7) minitest (~> 5.1) thread_safe (~> 0.1) tzinfo (~> 1.1) arel (5.0.1.20140414130214) - bcrypt (3.1.7) - bootstrap-sass (3.2.0.1) - sass (~> 3.2) - bootstrap_form (2.1.1) - bootswatch-rails (3.2.0) - railties (>= 3.1) + bcrypt (3.1.9) builder (3.2.2) - coffee-rails (4.0.1) + 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.7.1) + coffee-script-source (1.8.0) daemons (1.1.9) - devise (3.2.4) + devise (3.4.0) bcrypt (~> 3.0) orm_adapter (~> 0.1) railties (>= 3.2.6, < 5) + responders thread_safe (~> 0.1) warden (~> 1.2.3) + docile (1.1.5) erubis (2.7.0) eventmachine (1.0.3) - execjs (2.2.1) + execjs (2.2.2) + font-kit-rails (1.0.2) + rails haml (4.0.5) tilt hike (1.2.3) http_accept_language (2.0.2) i18n (0.6.11) - jbuilder (2.1.3) + jbuilder (2.2.4) activesupport (>= 3.0.0, < 5) multi_json (~> 1.2) - jquery-rails (3.1.1) + jquery-rails (3.1.2) railties (>= 3.0, < 5.0) thor (>= 0.14, < 2.0) json (1.8.1) - mail (2.5.4) - mime-types (~> 1.16) - treetop (~> 1.4.8) - mime-types (1.25.1) - minitest (5.4.0) + kgio (2.9.2) + mail (2.6.1) + mime-types (>= 1.16, < 3) + mime-types (2.4.3) + minitest (5.4.2) multi_json (1.10.1) + mysql2 (0.3.16) + nprogress-rails (0.1.6.3) orm_adapter (0.5.0) - polyglot (0.3.5) + pg (0.17.1) rack (1.5.2) rack-test (0.6.2) rack (>= 1.0) - rails (4.1.4) - actionmailer (= 4.1.4) - actionpack (= 4.1.4) - actionview (= 4.1.4) - activemodel (= 4.1.4) - activerecord (= 4.1.4) - activesupport (= 4.1.4) + rails (4.1.6) + actionmailer (= 4.1.6) + actionpack (= 4.1.6) + actionview (= 4.1.6) + activemodel (= 4.1.6) + activerecord (= 4.1.6) + activesupport (= 4.1.6) bundler (>= 1.3.0, < 2.0) - railties (= 4.1.4) + railties (= 4.1.6) sprockets-rails (~> 2.0) - railties (4.1.4) - actionpack (= 4.1.4) - activesupport (= 4.1.4) + railties (4.1.6) + actionpack (= 4.1.6) + activesupport (= 4.1.6) rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) + raindrops (0.13.0) rake (10.3.2) - rdoc (4.1.1) + rdoc (4.1.2) json (~> 1.4) + responders (1.1.1) + railties (>= 3.2, < 4.2) sass (3.2.19) sass-rails (4.0.3) railties (>= 4.0.0, < 5.0) sass (~> 3.2.0) sprockets (~> 2.8, <= 2.11.0) sprockets-rails (~> 2.0) - sdoc (0.4.0) - json (~> 1.8) - rdoc (~> 4.0, < 5.0) + sdoc (0.4.1) + json (~> 1.7, >= 1.7.7) + rdoc (~> 4.0) + semantic-ui-sass (0.19.3.0) + sass (~> 3.2) + simplecov (0.9.1) + docile (~> 1.1.0) + multi_json (~> 1.0) + simplecov-html (~> 0.8.0) + simplecov-html (0.8.0) spring (1.1.3) sprockets (2.11.0) hike (~> 1.2) multi_json (~> 1.0) rack (~> 1.0) tilt (~> 1.1, != 1.3.0) - sprockets-rails (2.1.3) + sprockets-rails (2.2.0) actionpack (>= 3.0) activesupport (>= 3.0) - sprockets (~> 2.8) - sqlite3 (1.3.9) - thin (1.6.2) - daemons (>= 1.0.9) - eventmachine (>= 1.0.0) - rack (>= 1.0.0) + sprockets (>= 2.8, < 4.0) + thin (1.6.3) + daemons (~> 1.0, >= 1.0.9) + eventmachine (~> 1.0) + rack (~> 1.0) thor (0.19.1) thread_safe (0.3.4) tilt (1.4.1) - treetop (1.4.15) - polyglot - polyglot (>= 0.3.1) - turbolinks (2.2.2) + turbolinks (2.4.0) coffee-rails - tzinfo (1.2.1) + tzinfo (1.2.2) thread_safe (~> 0.1) uglifier (2.5.3) execjs (>= 0.3.0) json (>= 1.8.0) + unicorn (4.8.3) + kgio (~> 2.6) + rack + raindrops (~> 0.7) warden (1.2.3) rack (>= 1.0) will_paginate (3.0.7) - will_paginate-bootstrap (1.0.1) - will_paginate (>= 3.0.3) PLATFORMS ruby DEPENDENCIES - bootstrap-sass (~> 3.2.0.1) - bootstrap_form - bootswatch-rails (~> 3.2.0) - coffee-rails (~> 4.0.0) + bcrypt (~> 3.1.7) + coffee-rails (~> 4.1.0) devise + font-kit-rails haml http_accept_language - jbuilder (~> 2.0) + jbuilder (~> 2.2.4) jquery-rails - rails (= 4.1.4) + mysql2 + nprogress-rails + pg + rails (= 4.1.6) sass-rails (~> 4.0.3) - sdoc (~> 0.4.0) + sdoc (~> 0.4.1) + semantic-ui-sass (~> 0.19.3.0) + simplecov spring - sqlite3 thin turbolinks uglifier (>= 1.3.0) + unicorn will_paginate - will_paginate-bootstrap diff --git a/README.md b/README.md index 23566ca4..137608e9 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,105 @@ -# README +# justask [![build status](https://ci.rrerr.net/projects/9/status.png?ref=master)](https://ci.rrerr.net/projects/9?ref=master) -This README would normally document whatever steps are necessary to get the -application up and running. +## Requirements -Things you may want to cover: +- UNIX-like system (Linux, *BSD, ...) +- ruby 1.9.3+ +- Bundler +- PostgreSQL or MySQL -* Ruby version -* System dependencies -* Configuration -* Database creation -* Database initialization -* How to run the test suite -* Services (job queues, cache servers, search engines, etc.) -* Deployment instructions -* ... +## Installation +### Database -Please feel free to use a different markup language if you do not plan to run -`rake doc:app`. +#### PostgreSQL + +``` +$ sudo -u postgres psql -d template1 +template1=# CREATE USER justask CREATEDB; +template1=# CREATE DATABASE justask_production OWNER justask; +template1=# \q +``` + +Try connecting to the database: + +``` +$ psql -U justask -d justask_production +``` + +#### MySQL + +``` +$ mysql -u root -p +# change 'hack me' in the command below to a real password +mysql> CREATE USER 'justask'@'localhost' IDENTIFIED BY 'hack me'; +mysql> SET storage_engine=INNODB; +mysql> CREATE DATABASE IF NOT EXISTS `justask_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`; +mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, LOCK TABLES ON `justask_production`.* TO 'justask'@'localhost'; +mysql> \q +``` + +Try connecting to the database: + +``` +$ mysql -u justask -p -D justask_production +``` + +### justask + +#### Clone the Source + +``` +$ git clone https://git.rrerr.net/nilsding/justask.git justask +``` + +#### Configure It + +``` +# Change into the justask directory +$ cd justask + +# Copy the example config +$ cp config/justask.yml.example config/justask.yml + +# Edit the configuration file +$ vi config/justask.yml +``` + +#### Database Configuration + +``` +# PostgreSQL only: +$ cp config/database.yml.postgres config/database.yml + +# MySQL only: +$ cp config/database.yml.mysql config/database.yml + +# MySQL and remote PostgreSQL only: +$ vi config/database.yml + +# Both: +# Make database.yml readable only for you +chmod o-rwx config/database.yml +``` + +#### Install Gems + +``` +# For PostgreSQL (note: the option says "without ... mysql") +$ bundle install --deployment --without development test mysql + +# Or, if you use MySQL +$ bundle install --deployment --without development test postgres +``` + +#### Initialize Database + +``` +$ bundle exec rake db:migrate RAILS_ENV=production +``` + +#### Compile Assets + +``` +$ bundle exec rake assets:precompile RAILS_ENV=production +``` diff --git a/app/assets/javascripts/application.coffee b/app/assets/javascripts/application.coffee index 4294d310..2711098f 100644 --- a/app/assets/javascripts/application.coffee +++ b/app/assets/javascripts/application.coffee @@ -1,5 +1,9 @@ #= require jquery #= require jquery_ujs #= require turbolinks -#= require bootstrap +#= require semantic-ui #= require_tree . + +$(document).ready -> + $('.ui.dropdown').dropdown + on: "hover" \ No newline at end of file diff --git a/app/assets/stylesheets/application.css.scss b/app/assets/stylesheets/application.css.scss index 87984a7f..60160db8 100644 --- a/app/assets/stylesheets/application.css.scss +++ b/app/assets/stylesheets/application.css.scss @@ -1,9 +1,73 @@ /* - *= require rails_bootstrap_forms + *= require font-kit-rails/open-sans *= require_self */ -@import "bootswatch/flatly/variables"; -@import "bootstrap"; -body { padding-top: $navbar-height; } -@import "bootswatch/flatly/bootswatch"; +@import "semantic-ui"; @import "base"; + +html, +body { + font-size: 15px; + height: 100%; +} + +body { + font-family: "Open Sans", "Helvetica Neue", "Helvetica", "DejaVu Sans", "Arial", sans-serif; + background: #FFFFFF; + margin: 0px; + padding: 0px; + color: #555555; + text-rendering: optimizeLegibility; + min-width: 320px; +} + + +/* mobile only */ + +@media only screen and (max-width : 768px) { + .ui.page.grid.segment { + padding-top: 2rem; + padding-bottom: 2rem; + } + + h1.ui.header { + font-size: 1.5em; + } + + .masthead.segment { + background-size: auto; + } + + .masthead.segment .information { + margin-left: 190px; + } + + .masthead.segment .image { + bottom: -65px; + width: 150px; + } + + .masthead.segment .button { + font-size: 1rem; + } + + .overview .divided.grid .header .icon { + font-size: 1.5em; + } + + .overview .divided.grid .header + p { + min-height: 0px; + } + + .masthead.segment .column { + font-size: 0.7rem; + } + + .masthead.segment .column p { + display: none; + } +} + +@media only screen and (max-width : 1000px) { + +} \ No newline at end of file diff --git a/app/dir/x b/app/dir/x new file mode 100644 index 00000000..e69de29b diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 0f01df3d..d298ed14 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,6 +1,9 @@ module ApplicationHelper - def nav_entry(body, path) - content_tag(:li, link_to(body, path), class: ('active' if current_page? path)) + def nav_entry(body, path, options={}) + options = {class: "", icon: "", label: "", label_color: "red"}.merge options + body = semantic_icon(options[:icon]) + " " + body unless options[:icon].empty? + body = body + " " + content_tag(:div, options[:label], class: "ui #{options[:label_color]} label") unless options[:label].empty? + link_to(body, path, class: "#{'active' if current_page? path} item #{options[:class]}") end ## diff --git a/app/models/answer.rb b/app/models/answer.rb new file mode 100644 index 00000000..901a2342 --- /dev/null +++ b/app/models/answer.rb @@ -0,0 +1,5 @@ +class Answer < ActiveRecord::Base + belongs_to :user + belongs_to :question + has_many :comments +end diff --git a/app/models/comment.rb b/app/models/comment.rb new file mode 100644 index 00000000..ef5cd49c --- /dev/null +++ b/app/models/comment.rb @@ -0,0 +1,4 @@ +class Comment < ActiveRecord::Base + belongs_to :user + belongs_to :answer +end diff --git a/app/models/question.rb b/app/models/question.rb new file mode 100644 index 00000000..c2f8b633 --- /dev/null +++ b/app/models/question.rb @@ -0,0 +1,4 @@ +class Question < ActiveRecord::Base + belongs_to :user + has_one :answer +end diff --git a/app/models/user.rb b/app/models/user.rb index 6ed77699..bd539572 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -7,6 +7,10 @@ class User < ActiveRecord::Base # attr_accessor :login + has_many :questions, dependent: :destroy + has_many :answers, dependent: :destroy + has_many :comments, dependent: :destroy + SCREEN_NAME_REGEX = /\A[a-zA-Z0-9_]{1,16}\z/ validates :screen_name, presence: true, format: { with: SCREEN_NAME_REGEX }, uniqueness: { case_sensitive: false } diff --git a/app/views/devise/confirmations/new.html.haml b/app/views/devise/confirmations/new.html.haml index d967cb74..221f47e0 100644 --- a/app/views/devise/confirmations/new.html.haml +++ b/app/views/devise/confirmations/new.html.haml @@ -1,6 +1,6 @@ .container %h1 Resend confirmation instructions - = bootstrap_form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { method: :post }) do |f| + = form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { method: :post }) do |f| = devise_error_messages! = f.email_field :screen_name, autofocus: true, label: "User name" diff --git a/app/views/devise/passwords/edit.html.haml b/app/views/devise/passwords/edit.html.haml index 2a4e5d0f..bb48dec5 100644 --- a/app/views/devise/passwords/edit.html.haml +++ b/app/views/devise/passwords/edit.html.haml @@ -1,6 +1,6 @@ .container %h1 Change your password - = bootstrap_form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :put }) do |f| + = form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :put }) do |f| = devise_error_messages! = f.hidden_field :reset_password_token diff --git a/app/views/devise/passwords/new.html.haml b/app/views/devise/passwords/new.html.haml index eee273ad..2531b53b 100644 --- a/app/views/devise/passwords/new.html.haml +++ b/app/views/devise/passwords/new.html.haml @@ -1,6 +1,6 @@ .container %h1 Forgot your password? - = bootstrap_form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| + = form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| = devise_error_messages! = f.text_field :screen_name, autofocus: true, "User name" diff --git a/app/views/devise/registrations/edit.html.haml b/app/views/devise/registrations/edit.html.haml index 5bf72700..150fa9f1 100644 --- a/app/views/devise/registrations/edit.html.haml +++ b/app/views/devise/registrations/edit.html.haml @@ -1,6 +1,6 @@ .container %h1 Edit #{resource_name.to_s.humanize} - = bootstrap_form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| + = form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| = devise_error_messages! = f.text_field :screen_name, autofocus: true, label: "User name" diff --git a/app/views/devise/registrations/new.html.haml b/app/views/devise/registrations/new.html.haml index 80d46542..80a57944 100644 --- a/app/views/devise/registrations/new.html.haml +++ b/app/views/devise/registrations/new.html.haml @@ -1,7 +1,7 @@ .container %h1 Sign up - = bootstrap_form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| + = form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| = devise_error_messages! = f.text_field :screen_name, autofocus: true, label: "User name" diff --git a/app/views/devise/sessions/new.html.haml b/app/views/devise/sessions/new.html.haml index a9721102..8caed3d5 100644 --- a/app/views/devise/sessions/new.html.haml +++ b/app/views/devise/sessions/new.html.haml @@ -2,7 +2,7 @@ %h1 Sign in = render 'layouts/messages' - = bootstrap_form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| + = form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| = f.text_field :login, autofocus: true, label: "User name" = f.password_field :password, autocomplete: "off", label: "Password" diff --git a/app/views/devise/unlocks/new.html.haml b/app/views/devise/unlocks/new.html.haml index 487ca679..b59e5b44 100644 --- a/app/views/devise/unlocks/new.html.haml +++ b/app/views/devise/unlocks/new.html.haml @@ -2,7 +2,7 @@ %h1 Resend unlock instructions = render 'layouts/messages' - = bootstrap_form_for(resource, as: resource_name, url: unlock_path(resource_name), html: { method: :post }) do |f| + = form_for(resource, as: resource_name, url: unlock_path(resource_name), html: { method: :post }) do |f| = devise_error_messages! = f.email_field :email, autofocus: true, label: "Email address" diff --git a/app/views/layouts/_header.html.haml b/app/views/layouts/_header.html.haml index 1014359d..704c55bd 100644 --- a/app/views/layouts/_header.html.haml +++ b/app/views/layouts/_header.html.haml @@ -1,26 +1,19 @@ -%nav.navbar.navbar-default.navbar-fixed-top{role: "navigation"} - .container - .navbar-header - %button.navbar-toggle{"data-target" => "#j2-main-navbar-collapse", "data-toggle" => "collapse", type: "button"} - %span.sr-only Toggle navigation - %span.icon-bar - %span.icon-bar - %span.icon-bar - %a.navbar-brand{href: "/"} justask2 - #j2-main-navbar-collapse.collapse.navbar-collapse - %ul.nav.navbar-nav - = nav_entry "Front", "/" - %ul.nav.navbar-nav.navbar-right - - if user_signed_in? - %li.dropdown - %a.dropdown-toggle{href: "#", "data-toggle" => "dropdown"} - = current_user.screen_name - %b.caret - %ul.dropdown-menu - %li= link_to "Profile", edit_user_registration_path - %li= link_to "Settings", "#" - %li.divider - %li= link_to "Logout", destroy_user_session_path, method: :delete - - else - = nav_entry "Sign in", new_user_session_path - = nav_entry "Sign up", new_user_registration_path \ No newline at end of file +%nav.ui.fixed.inverted.main.menu + %h3.header.item justask + = nav_entry "Home", "/", icon: "home" + - if user_signed_in? + = nav_entry "Inbox", "/inbox", icon: "inbox", label: "2" + - else + = nav_entry "About", "/about", icon: "" + .right.menu + - if user_signed_in? + .ui.dropdown.item + = current_user.screen_name + = semantic_icon "dropdown" + .menu + = link_to "Profile", edit_user_registration_path, class: "item" + = link_to "Settings", "#", class: "item" + = link_to "Logout", destroy_user_session_path, method: :delete, class: "item" + - else + = nav_entry "Sign in", new_user_session_path #, "right floated text" + = nav_entry "Sign up", new_user_registration_path #, "right floated text" \ No newline at end of file diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 11b2cb74..a737041a 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -1,7 +1,7 @@ !!! 5 %html %head - %title justask2 + %title justask = stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true = javascript_include_tag 'application', 'data-turbolinks-track' => true = csrf_meta_tags @@ -11,5 +11,5 @@ - if Rails.env.development? %hr .container - %p.text-danger EVIL DEBUG MODE OF DOOM ENABLED!!! + %p.text-danger Debug output: = debug params \ No newline at end of file diff --git a/config/application.rb b/config/application.rb index 1861ab6f..21270043 100644 --- a/config/application.rb +++ b/config/application.rb @@ -6,7 +6,7 @@ require 'rails/all' # you've limited to :test, :development, or :production. Bundler.require(*Rails.groups) -module Justask2 +module Justask class Application < Rails::Application # Settings in config/environments/* take precedence over those specified here. # Application configuration should go into files in config/initializers diff --git a/config/database.yml b/config/database.yml deleted file mode 100644 index 1c1a37ca..00000000 --- a/config/database.yml +++ /dev/null @@ -1,25 +0,0 @@ -# SQLite version 3.x -# gem install sqlite3 -# -# Ensure the SQLite 3 gem is defined in your Gemfile -# gem 'sqlite3' -# -default: &default - adapter: sqlite3 - pool: 5 - timeout: 5000 - -development: - <<: *default - database: db/development.sqlite3 - -# Warning: The database defined as "test" will be erased and -# re-generated from your development database when you run "rake". -# Do not set this db to the same as development or production. -test: - <<: *default - database: db/test.sqlite3 - -production: - <<: *default - database: db/production.sqlite3 diff --git a/config/database.yml.mysql b/config/database.yml.mysql new file mode 100644 index 00000000..9a088f9f --- /dev/null +++ b/config/database.yml.mysql @@ -0,0 +1,42 @@ +# +# PRODUCTION +# +production: + adapter: mysql2 + encoding: utf8 + collation: utf8_general_ci + reconnect: false + database: justask_production + pool: 10 + username: justask + password: "hack me" + # host: localhost + # socket: /tmp/mysql.sock + +# +# Development specific +# +development: + adapter: mysql2 + encoding: utf8 + collation: utf8_general_ci + reconnect: false + database: justask_development + pool: 5 + username: root + password: "hack me twice" + # socket: /tmp/mysql.sock + +# Warning: The database defined as "test" will be erased and +# re-generated from your development database when you run "rake". +# Do not set this db to the same as development or production. +test: &test + adapter: mysql2 + encoding: utf8 + collation: utf8_general_ci + reconnect: false + database: justask_test + pool: 5 + username: root + password: "hack me twice" + # socket: /tmp/mysql.sock diff --git a/config/database.yml.postgres b/config/database.yml.postgres new file mode 100644 index 00000000..596af027 --- /dev/null +++ b/config/database.yml.postgres @@ -0,0 +1,34 @@ +# +# PRODUCTION +# +production: + adapter: postgresql + encoding: unicode + database: justask_production + pool: 10 + # username: justask + # password: + # host: localhost + # port: 5432 + +# +# Development specific +# +development: + adapter: postgresql + encoding: unicode + database: justask_development + pool: 5 + username: postgres + password: + +# Warning: The database defined as "test" will be erased and +# re-generated from your development database when you run "rake". +# Do not set this db to the same as development or production. +test: &test + adapter: postgresql + encoding: unicode + database: justask_test + pool: 5 + username: postgres + password: diff --git a/config/initializers/session_store.rb b/config/initializers/session_store.rb index 2bb73c98..a83e0c70 100644 --- a/config/initializers/session_store.rb +++ b/config/initializers/session_store.rb @@ -1,3 +1,3 @@ # Be sure to restart your server when you modify this file. -Rails.application.config.session_store :cookie_store, key: '_justask2_session' +Rails.application.config.session_store :cookie_store, key: '_justask_session' diff --git a/db/migrate/20140801174930_create_questions.rb b/db/migrate/20140801174930_create_questions.rb new file mode 100644 index 00000000..58714fb9 --- /dev/null +++ b/db/migrate/20140801174930_create_questions.rb @@ -0,0 +1,13 @@ +class CreateQuestions < ActiveRecord::Migration + def change + create_table :questions do |t| + t.string :content + t.boolean :author_is_anonymous + t.string :author_name + t.string :author_email + + t.timestamps + end + add_index :questions, [:user_id, :created_at] + end +end diff --git a/db/migrate/20140801175112_create_answers.rb b/db/migrate/20140801175112_create_answers.rb new file mode 100644 index 00000000..d10e4682 --- /dev/null +++ b/db/migrate/20140801175112_create_answers.rb @@ -0,0 +1,14 @@ +class CreateAnswers < ActiveRecord::Migration + def change + create_table :answers do |t| + t.string :content + t.integer :question_id + t.integer :comments + t.integer :likes + t.integer :user_id + + t.timestamps + end + add_index :answers, [:user_id, :created_at] + end +end diff --git a/db/migrate/20140801175137_create_comments.rb b/db/migrate/20140801175137_create_comments.rb new file mode 100644 index 00000000..7d2e3e4c --- /dev/null +++ b/db/migrate/20140801175137_create_comments.rb @@ -0,0 +1,12 @@ +class CreateComments < ActiveRecord::Migration + def change + create_table :comments do |t| + t.string :content + t.integer :answer_id + t.integer :user_id + + t.timestamps + end + add_index :comments, [:user_id, :created_at] + end +end diff --git a/db/schema.rb b/db/schema.rb index 99ba3dda..b25cca5d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,44 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20140801103309) do +ActiveRecord::Schema.define(version: 20140801175137) do + + # These are extensions that must be enabled in order to support this database + enable_extension "plpgsql" + + create_table "answers", force: true do |t| + t.string "content" + t.integer "question_id" + t.integer "comments" + t.integer "likes" + t.integer "user_id" + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "answers", ["user_id", "created_at"], name: "index_answers_on_user_id_and_created_at", using: :btree + + create_table "comments", force: true do |t| + t.string "content" + t.integer "answer_id" + t.integer "user_id" + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "comments", ["user_id", "created_at"], name: "index_comments_on_user_id_and_created_at", using: :btree + + create_table "questions", force: true do |t| + t.string "content" + t.boolean "author_is_anonymous" + t.string "author_name" + t.string "author_email" + t.integer "user_id" + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "questions", ["user_id", "created_at"], name: "index_questions_on_user_id_and_created_at", using: :btree create_table "users", force: true do |t| t.string "email", default: "", null: false @@ -29,8 +66,8 @@ ActiveRecord::Schema.define(version: 20140801103309) do t.string "screen_name" end - add_index "users", ["email"], name: "index_users_on_email", unique: true - add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true - add_index "users", ["screen_name"], name: "index_users_on_screen_name", unique: true + add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree + add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree + add_index "users", ["screen_name"], name: "index_users_on_screen_name", unique: true, using: :btree end diff --git a/test/test_helper.rb b/test/test_helper.rb index 92e39b2d..05df4b43 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,3 +1,6 @@ +require 'simplecov' +SimpleCov.start + ENV['RAILS_ENV'] ||= 'test' require File.expand_path('../../config/environment', __FILE__) require 'rails/test_help'