This repository has been archived by the owner on Mar 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
22 changed files
with
268 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |