up to date readme

master
Matthew F. Short 10 years ago
parent 5a74813ce4
commit e57c97bf3b

2
.gitignore vendored

@ -11,3 +11,5 @@
/log/*
!/log/.keep
/tmp
.DS_Store

@ -1,28 +1,60 @@
== README
This README would normally document whatever steps are necessary to get the
application up and running.
Things you may want to cover:
* 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
* ...
Please feel free to use a different markup language if you do not plan to run
<tt>rake doc:app</tt>.
# API Docs
## Classical
User + Session are all done the 'old fashioned way' via server-rendered erb.
ROOT (/): Renders the Sign In / Sign Up forms.
POST /users will create a new user, redirect to ROOT
POST /session will create a new session, redirect to SPA page
---
## JSON
GET /current_user will return JSON object containing currently logged in user
GET /transgressions will return array of transgressions complete with confessions subarray
```json
{
transgressions: [
{
id: 3,
sin_type: "Gluttony",
description: "I love eating a whole box full of cucumbers, like a 20lb box"
confessions: [
{
description: "Some description",
occurred_at: "3 weeks ago"
}
]
}
]
}
```
POST /transgressions will take a JSON object as such:
```json
{
authenticity_token: "osmeaksdfiohuiHDFIUSDHFUkjadfhjk324",
transgression: {
sin_type: "Some Sin",
description: "Some Description"
}
}
```
And return the created transgression as an object.
POST /transgressions/:id/confessions will take a JSON object as such:
```json
{
authenticity_token: "adsf123i478KJkhajksldfhjk0",
confession: {
description: "I did a thing",
occurred_at: "2015-03-27"
}
}
```

BIN
app/.DS_Store vendored

Binary file not shown.

@ -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://coffeescript.org/

@ -0,0 +1,3 @@
// Place all the styles related to the confessions controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

@ -0,0 +1,2 @@
class ConfessionsController < ApplicationController
end

@ -9,7 +9,9 @@ class TransgressionsController < ApplicationController
@transgression = current_user.transgressions
.new(transgression_params)
if @transgression.save
@confession = @transgression.confessions.new(confession_params)
if @transgression.save && @confession.save
redirect_to transgressions_path
else
flash[:message] = @transgression.errors.full_messages.to_sentence
@ -29,6 +31,8 @@ class TransgressionsController < ApplicationController
def index
@transgressions = current_user.transgressions
.includes(:confessions)
.group_by { |x| x.sin_type }
end
def delete
@ -40,4 +44,9 @@ class TransgressionsController < ApplicationController
return params.require(:transgression)
.permit(:sin_type, :description)
end
def confession_params
return params.require(:confession)
.permit(:description, :occurred_at)
end
end

@ -0,0 +1,2 @@
module ConfessionsHelper
end

@ -0,0 +1,8 @@
class Confession < ActiveRecord::Base
validates :description, presence: true
validates :transgression, presence: true
validates :occurred_at, presence: true
belongs_to :transgression
delegate :sinner, to: :transgression
end

@ -5,10 +5,14 @@ class Transgression < ActiveRecord::Base
]
validates :description, presence: true
validates :user, presence: true
validates :sinner, presence: true
validates :sin_type, inclusion: { in: SIN_TYPES }
belongs_to :user
# belongs_to :sinner, it would assume there is a Sinner Class, as well as a sinner_id column in this table
belongs_to :sinner, class_name: "User", foreign_key: :user_id
has_many :confessions, dependent: :destroy
end
# Transgression::SIN_TYPES

@ -8,5 +8,6 @@ class User < ActiveRecord::Base
minimum: 8, allow_nil: true
}
has_many :transgressions
has_many :transgressions, dependent: :destroy
has_many :confessions, through: :transgressions
end

@ -1,3 +1,22 @@
<% @transgressions.each do |trans| %>
<h5>For the sin of <%= trans.sin_type %>: <%= trans.description %></h5>
<% @transgressions.each do |sin_type, trans| %>
<h4>
For the sin of <em><%= sin_type %></em>, your weaknesses are:
</h4>
<ul>
<% trans.each do |t| %>
<li>
<%= t.description %>, with <%= t.confessions.count %> confessions:
<% if t.confessions.count > 0 %>
<ul>
<% t.confessions.each do |c| %>
<li>
"<%= c.description %>" - <%= c.occurred_at %>
</li>
<% end %>
</ul>
<% end %>
</li>
<% end %>
</ul>
<% end %>

@ -13,5 +13,9 @@
</option>
<% end %>
</select>
<hr/>
<h5>Your first confession!</h5>
<input type="text" name="confession[description]"><br/>
<input type="date" name="confession[occurred_at]"><br/>
<input type="submit" value="Here I am">
</form>

@ -1,4 +1,5 @@
Rails.application.routes.draw do
resources :confessions
resources :transgressions
root 'application#welcome'

@ -0,0 +1,11 @@
class CreateConfessions < ActiveRecord::Migration
def change
create_table :confessions do |t|
t.references :transgression, index: true, foreign_key: true
t.date :occured_at
t.string :description
t.timestamps null: false
end
end
end

@ -0,0 +1,5 @@
class ChangeColumnInConfessions < ActiveRecord::Migration
def change
rename_column :confessions, :occured_at, :occurred_at
end
end

@ -0,0 +1,6 @@
class ChangeColumnsInConfessions < ActiveRecord::Migration
def change
change_column :confessions, :description, :string, null: false
change_column :confessions, :occurred_at, :datetime, null: false, default: Time.now
end
end

@ -11,11 +11,21 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20151029180427) do
ActiveRecord::Schema.define(version: 20151030132812) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
create_table "confessions", force: :cascade do |t|
t.integer "transgression_id"
t.datetime "occurred_at", default: '2015-11-02 14:55:24', null: false
t.string "description", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "confessions", ["transgression_id"], name: "index_confessions_on_transgression_id", using: :btree
create_table "transgressions", force: :cascade do |t|
t.integer "user_id"
t.string "description", null: false
@ -36,5 +46,6 @@ ActiveRecord::Schema.define(version: 20151029180427) do
add_index "users", ["email"], name: "index_users_on_email", using: :btree
add_foreign_key "confessions", "transgressions"
add_foreign_key "transgressions", "users"
end

@ -5,3 +5,11 @@
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first)
joe = User.find_or_initialize_by(email: "joeschmoe@joe.co")
joe.update(password: "i<3potatoes")
sniffing = Transgression.find_or_create_by(description: "I can't stop myself from sniffing other people's hair.", sin_type: "Lust", sinner: joe)
confession = sniffing.confessions.create(description: "Creeped up behind someone in the subway.")

@ -0,0 +1,7 @@
require 'test_helper'
class ConfessionsControllerTest < ActionController::TestCase
# test "the truth" do
# assert true
# end
end

@ -0,0 +1,11 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
transgression:
occurred_at: 2015-10-30
description: MyString
two:
transgression:
occurred_at: 2015-10-30
description: MyString

@ -0,0 +1,9 @@
require 'test_helper'
class ConfessionTest < ActiveSupport::TestCase
test "the truth" do
a = Confession.new
assert_not a.save
end
end
Loading…
Cancel
Save