Skip to content
This repository has been archived by the owner on Mar 6, 2020. It is now read-only.

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
Contains a (very) basic, working Todo List Application. You can add
tasks, mark them complete, and mark them incomplete. Functionality such
as deleting is not yet implemented. Basic functionality is tested,
though styling of error message communication is pending.
  • Loading branch information
awood45 committed Jun 18, 2014
1 parent 84ca4b3 commit c2e23d3
Show file tree
Hide file tree
Showing 22 changed files with 268 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ source 'https://rubygems.org'
gem 'rails', '4.1.1'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
# Use SCSS for stylesheets, and use Bootstrap
gem 'sass-rails', '~> 4.0.3'
gem 'bootstrap-sass'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ GEM
thread_safe (~> 0.1)
tzinfo (~> 1.1)
arel (5.0.1.20140414130214)
bootstrap-sass (3.1.1.1)
sass (~> 3.2)
builder (3.2.2)
coffee-rails (4.0.1)
coffee-script (>= 2.2.0)
Expand Down Expand Up @@ -113,6 +115,7 @@ PLATFORMS
ruby

DEPENDENCIES
bootstrap-sass
coffee-rails (~> 4.0.0)
jbuilder (~> 2.0)
jquery-rails
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
# Todo List Example App

This project is intended to be a hands-on demonstration of ways that you can
integrate a Ruby on Rails application with Amazon Web Services. Starting from a
simple example web application, we will show you how it can take advantage of
various AWS offerings. We hope that this will be useful to you as you integrate
your own applications with AWS.

## The Application

The application itself is not complicated - it is a simple Todo List web site,
where you can create tasks, edit details about them, and update their status.

While some additional functionality may be added over time to make the example
more practical, the application is designed to be simple and easy to understand.
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,16 @@
*= require_tree .
*= require_self
*/
@import "bootstrap";

#tasks {
.list-group-item {
font-weight: bold;
&.completed {
background-color: #76EE00;
}
}
.btn {
margin-right: 2em;
}
}
33 changes: 33 additions & 0 deletions app/controllers/tasks_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
class TasksController < ApplicationController
def index
@tasks = Task.all
end

def show
@task = Task.find(params[:id])
end

def create
respond_to do |format|
@task = Task.new(task_create_params)
@task.save
format.html { redirect_to tasks_path }
end
end

def update
respond_to do |format|
@task = Task.find(params[:id])
@task.update(task_update_params)
format.html { redirect_to :back }
end
end

def task_create_params
params.permit(:name)
end

def task_update_params
params.permit(:name, :completed_flag)
end
end
Empty file removed app/models/.keep
Empty file.
3 changes: 3 additions & 0 deletions app/models/task.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Task < ActiveRecord::Base
validates :name, presence: true, uniqueness: true
end
14 changes: 10 additions & 4 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
<!DOCTYPE html>
<html>
<html lang="en">
<head>
<title>TodoApp</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">

<title>Todo Application</title>

<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
</head>
<body>

<%= yield %>
<div class="container">
<%= yield %>
</div>

</body>
</html>
26 changes: 26 additions & 0 deletions app/views/tasks/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<ul class="list-group" id="tasks">
<% @tasks.each do |task| %>
<% if task.completed_flag %>
<li class='list-group-item completed' id="task_<%= task.id %>">
<%= link_to("Mark Incomplete",
task_path(id: task.id, completed_flag: false),
method: "patch",
class: "btn btn-sm btn-danger" ) %>
<%= task.name %>
</li>
<% else %>
<li class='list-group-item' id="task_<%= task.id %>">
<%= link_to('Mark Complete',
task_path(id: task.id, completed_flag: true),
method: 'patch',
:class => 'btn btn-sm btn-success') %>
<%= task.name %>
</li>
<% end %>
<% end %>
</ul>

<%= form_tag("/tasks", method: "post") do %>
<%= text_field_tag(:name) %>
<%= submit_tag("Add Task") %>
<% end %>
9 changes: 9 additions & 0 deletions app/views/tasks/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<%
completed = "No"
completed = "Yes" if @task.completed_flag
%>
<div id="<%= @task.name %>">
<h2><%= @task.name %></h2>
<p>Completed? <%= completed %></p>
</div>

1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

# Example resource route (maps HTTP verbs to controller actions automatically):
# resources :products
resources :tasks, only: [:index, :show, :create, :update]

# Example resource route with options:
# resources :products do
Expand Down
9 changes: 9 additions & 0 deletions db/migrate/20140528171227_create_tasks.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class CreateTasks < ActiveRecord::Migration
def change
create_table :tasks do |t|
t.string :name

t.timestamps
end
end
end
5 changes: 5 additions & 0 deletions db/migrate/20140528233730_add_completed_flag_to_tasks.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddCompletedFlagToTasks < ActiveRecord::Migration
def change
add_column :tasks, :completed_flag, :boolean, default: false
end
end
23 changes: 23 additions & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 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: 20140528233730) do

create_table "tasks", force: true do |t|
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
t.boolean "completed_flag", default: false
end

end
1 change: 1 addition & 0 deletions test/fixtures/tasks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
Empty file removed test/integration/.keep
Empty file.
12 changes: 12 additions & 0 deletions test/integration/creating_tasks_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require 'test_helper'

class CreatingTasksTest < ActionDispatch::IntegrationTest
test 'can create a new task' do
post tasks_path, name: "New Task"
tasks = Task.all
assert_equal(1, tasks.size)
task = tasks.first
assert_equal("New Task", task.name)
assert_not(task.completed_flag)
end
end
24 changes: 24 additions & 0 deletions test/integration/listing_tasks_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require 'test_helper'

class ListingTasksTest < ActionDispatch::IntegrationTest
test 'tasks#index returns a valid response' do
get '/tasks'

assert_equal 200, response.status
refute_empty response.body
end

test '/tasks returns a list of all tasks' do
milk = Task.create!(name: "Remember the Milk")
wash = Task.create!(name: "Wash the Car")

get '/tasks'

assert_equal 200, response.status
assert_select 'ul' do
assert_select 'li' do |elements|
assert_equal 2, elements.size
end
end
end
end
13 changes: 13 additions & 0 deletions test/integration/lookup_task_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require 'test_helper'

class LookupTaskTest < ActionDispatch::IntegrationTest
test 'can get task by ID' do
task = Task.create!(name: "ExTask")

get "/tasks/#{task.id}"

assert_equal 200, response.status
assert_select "div#ExTask"
assert_select "div#ExTask h2", "ExTask"
end
end
53 changes: 53 additions & 0 deletions test/integration/toggling_tasks_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
require 'test_helper'

class TogglingTasksTest < ActionDispatch::IntegrationTest
test 'can mark incomplete task as complete on index page' do
undone = Task.create!(name: "You Must Complete Me!")
get '/tasks'
assert_response :success

patch "/tasks/#{undone.id}", { completed_flag: true }, from_task_index
assert_redirected_to(controller: "tasks", action: "index")
assert(Task.find(undone.id).completed_flag)
end

test 'can mark incomplete task as complete on task page' do
undone = Task.create!(name: "You Must Complete Me!")
get "/tasks/#{undone.id}"
assert_response :success

patch "/tasks/#{undone.id}", { completed_flag: true }, from_task_page(undone)
assert_redirected_to(controller: "tasks", action: "show")
assert(Task.find(undone.id).completed_flag)
end

test 'can mark complete task as incomplete on index page' do
done = Task.create!(name: "I'm not resolved yet!",
completed_flag: true)
get '/tasks'
assert_response :success

patch "/tasks/#{done.id}", { completed_flag: false }, from_task_index
assert_redirected_to(controller: "tasks", action: "index")
assert_not(Task.find(done.id).completed_flag)
end

test 'can mark complete task as incomplete on task page' do
done = Task.create!(name: "I'm not resolved yet!",
completed_flag: true)
get "/tasks/#{done.id}"
assert_response :success

patch "/tasks/#{done.id}", { completed_flag: false }, from_task_page(done)
assert_redirected_to(controller: "tasks", action: "show")
assert_not(Task.find(done.id).completed_flag)
end

def from_task_index
{ 'HTTP_REFERER' => "/tasks" }
end

def from_task_page task
{ 'HTTP_REFERER' => "/tasks/#{task.id}" }
end
end
Empty file removed test/models/.keep
Empty file.
14 changes: 14 additions & 0 deletions test/models/task_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require 'test_helper'

class TaskTest < ActiveSupport::TestCase
test 'invalid without a name' do
t = Task.new
assert !t.valid?, "Name is not being validated!"
end

test 'name is unique' do
assert Task.create(name: "Unique").valid?
assert !Task.create(name: "Unique").valid?,
"Name uniqueness is not being validated!"
end
end

0 comments on commit c2e23d3

Please sign in to comment.