diff --git a/app/assets/javascripts/tasks.js.coffee b/app/assets/javascripts/tasks.js.coffee new file mode 100644 index 0000000..7615679 --- /dev/null +++ b/app/assets/javascripts/tasks.js.coffee @@ -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://jashkenas.github.com/coffee-script/ diff --git a/app/assets/stylesheets/scaffolds.css.scss b/app/assets/stylesheets/scaffolds.css.scss new file mode 100644 index 0000000..05188f0 --- /dev/null +++ b/app/assets/stylesheets/scaffolds.css.scss @@ -0,0 +1,56 @@ +body { + background-color: #fff; + color: #333; + font-family: verdana, arial, helvetica, sans-serif; + font-size: 13px; + line-height: 18px; } + +p, ol, ul, td { + font-family: verdana, arial, helvetica, sans-serif; + font-size: 13px; + line-height: 18px; } + +pre { + background-color: #eee; + padding: 10px; + font-size: 11px; } + +a { + color: #000; + &:visited { + color: #666; } + &:hover { + color: #fff; + background-color: #000; } } + +div { + &.field, &.actions { + margin-bottom: 10px; } } + +#notice { + color: green; } + +.field_with_errors { + padding: 2px; + background-color: red; + display: table; } + +#error_explanation { + width: 450px; + border: 2px solid red; + padding: 7px; + padding-bottom: 0; + margin-bottom: 20px; + background-color: #f0f0f0; + h2 { + text-align: left; + font-weight: bold; + padding: 5px 5px 5px 15px; + font-size: 12px; + margin: -7px; + margin-bottom: 0px; + background-color: #c00; + color: #fff; } + ul li { + font-size: 12px; + list-style: square; } } diff --git a/app/assets/stylesheets/tasks.css.scss b/app/assets/stylesheets/tasks.css.scss new file mode 100644 index 0000000..c5e7712 --- /dev/null +++ b/app/assets/stylesheets/tasks.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Tasks controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/tasks_controller.rb b/app/controllers/tasks_controller.rb new file mode 100644 index 0000000..1962224 --- /dev/null +++ b/app/controllers/tasks_controller.rb @@ -0,0 +1,101 @@ +class TasksController < ApplicationController + before_filter :authenticate_user!, :except => [:index, :show] + + # GET /tasks + # GET /tasks.json + def index + @tasks = Task.all + + respond_to do |format| + format.html # index.html.erb + format.json { render json: @tasks } + end + end + + # GET /tasks/1 + # GET /tasks/1.json + def show + @task = Task.find(params[:id]) + + respond_to do |format| + format.html # show.html.erb + format.json { render json: @task } + end + end + + # GET /tasks/new + # GET /tasks/new.json + def new + @task = Task.new + + respond_to do |format| + format.html # new.html.erb + format.json { render json: @task } + end + end + + # GET /tasks/1/edit + def edit + @task = Task.find(params[:id]) + end + + # POST /tasks + # POST /tasks.json + def create + @task = Task.new(params[:task]) + @task.user_id = current_user.id + @task.party_id = params[:party_id] + @task.state = "backlog" + + respond_to do |format| + if @task.save + format.html { redirect_to @task.party, notice: 'Task was successfully created.' } + format.json { render json: @task, status: :created, location: @task } + else + format.html { render action: "new" } + format.json { render json: @task.errors, status: :unprocessable_entity } + end + end + end + + # PUT /tasks/1 + # PUT /tasks/1.json + def update + @task = Task.find(params[:id]) + + respond_to do |format| + if @task.update_attributes(params[:task]) + format.html { redirect_to @task, notice: 'Task was successfully updated.' } + format.json { head :no_content } + else + format.html { render action: "edit" } + format.json { render json: @task.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /tasks/1 + # DELETE /tasks/1.json + def destroy + @task = Task.find(params[:id]) + @task.destroy + + respond_to do |format| + format.html { redirect_to tasks_url } + format.json { head :no_content } + end + end + + def start + raise params + end + + def hold + raise params + end + + def finish + raise params + end + +end diff --git a/app/helpers/tasks_helper.rb b/app/helpers/tasks_helper.rb new file mode 100644 index 0000000..ce894d0 --- /dev/null +++ b/app/helpers/tasks_helper.rb @@ -0,0 +1,2 @@ +module TasksHelper +end diff --git a/app/models/task.rb b/app/models/task.rb new file mode 100644 index 0000000..9012cea --- /dev/null +++ b/app/models/task.rb @@ -0,0 +1,9 @@ +class Task < ActiveRecord::Base + attr_accessible :content, :end_time, :start_time, :state, :user_id + belongs_to :user + belongs_to :party + + scope :current, where(state: "current") + scope :backlog, where(state: "backlog").order("created_at desc") + scope :done, where(state: "done").order("created_at desc") +end diff --git a/app/models/user.rb b/app/models/user.rb index 071b641..e836de1 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -3,7 +3,8 @@ class User < ActiveRecord::Base has_many :joins has_many :parties - has_many :invited_parties, :through => :joins +# has_many :invited_parties, :through => :joins + has_many :tasks def self.create_with_omniauth(auth) create! do |user| diff --git a/app/views/parties/show.html.erb b/app/views/parties/show.html.erb index 561f2b1..24f9a48 100644 --- a/app/views/parties/show.html.erb +++ b/app/views/parties/show.html.erb @@ -15,11 +15,41 @@ <%= @party.end_at %>

+
+

Member: -

diff --git a/app/views/tasks/_form.html.erb b/app/views/tasks/_form.html.erb new file mode 100644 index 0000000..df2269a --- /dev/null +++ b/app/views/tasks/_form.html.erb @@ -0,0 +1,37 @@ +<%= form_for(@task) do |f| %> + <% if @task.errors.any? %> +
+

<%= pluralize(@task.errors.count, "error") %> prohibited this task from being saved:

+ + +
+ <% end %> + +
+ <%= f.label :user_id %>
+ <%= f.number_field :user_id %> +
+
+ <%= f.label :content %>
+ <%= f.text_area :content %> +
+
+ <%= f.label :state %>
+ <%= f.text_field :state %> +
+
+ <%= f.label :start_time %>
+ <%= f.time_select :start_time %> +
+
+ <%= f.label :end_time %>
+ <%= f.time_select :end_time %> +
+
+ <%= f.submit %> +
+<% end %> diff --git a/app/views/tasks/edit.html.erb b/app/views/tasks/edit.html.erb new file mode 100644 index 0000000..bde6546 --- /dev/null +++ b/app/views/tasks/edit.html.erb @@ -0,0 +1,6 @@ +

Editing task

+ +<%= render 'form' %> + +<%= link_to 'Show', @task %> | +<%= link_to 'Back', tasks_path %> diff --git a/app/views/tasks/index.html.erb b/app/views/tasks/index.html.erb new file mode 100644 index 0000000..80bba1c --- /dev/null +++ b/app/views/tasks/index.html.erb @@ -0,0 +1,31 @@ +

Listing tasks

+ + + + + + + + + + + + + +<% @tasks.each do |task| %> + + + + + + + + + + +<% end %> +
UserContentStateStart timeEnd time
<%= task.user_id %><%= task.content %><%= task.state %><%= task.start_time %><%= task.end_time %><%= link_to 'Show', task %><%= link_to 'Edit', edit_task_path(task) %><%= link_to 'Destroy', task, confirm: 'Are you sure?', method: :delete %>
+ +
+ +<%= link_to 'New Task', new_task_path %> diff --git a/app/views/tasks/new.html.erb b/app/views/tasks/new.html.erb new file mode 100644 index 0000000..59aa573 --- /dev/null +++ b/app/views/tasks/new.html.erb @@ -0,0 +1,5 @@ +

New task

+ +<%= render 'form' %> + +<%= link_to 'Back', tasks_path %> diff --git a/app/views/tasks/show.html.erb b/app/views/tasks/show.html.erb new file mode 100644 index 0000000..fe517cb --- /dev/null +++ b/app/views/tasks/show.html.erb @@ -0,0 +1,30 @@ +

<%= notice %>

+ +

+ User: + <%= @task.user_id %> +

+ +

+ Content: + <%= @task.content %> +

+ +

+ State: + <%= @task.state %> +

+ +

+ Start time: + <%= @task.start_time %> +

+ +

+ End time: + <%= @task.end_time %> +

+ + +<%= link_to 'Edit', edit_task_path(@task) %> | +<%= link_to 'Back', tasks_path %> diff --git a/config/routes.rb b/config/routes.rb index f0070e0..e72cb0c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,7 +2,13 @@ resources :joins - resources :parties + resources :parties do + resources :tasks do + get "start", :on => :member + get "hold", :on => :member + get "finish", :on => :member + end + end get "sessions/create" diff --git a/db/migrate/20120429045006_create_tasks.rb b/db/migrate/20120429045006_create_tasks.rb new file mode 100644 index 0000000..9088281 --- /dev/null +++ b/db/migrate/20120429045006_create_tasks.rb @@ -0,0 +1,14 @@ +class CreateTasks < ActiveRecord::Migration + def change + create_table :tasks do |t| + t.integer :user_id + t.integer :party_id + t.text :content + t.string :state + t.time :start_time + t.time :end_time + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index bfcb5a2..5830b64 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20120429020930) do +ActiveRecord::Schema.define(:version => 20120429045006) do create_table "joins", :force => true do |t| t.integer "user_id" @@ -29,6 +29,17 @@ t.datetime "updated_at", :null => false end + create_table "tasks", :force => true do |t| + t.integer "user_id" + t.integer "party_id" + t.text "content" + t.string "state" + t.time "start_time" + t.time "end_time" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + create_table "users", :force => true do |t| t.string "name" t.string "image" diff --git a/db/seeds.rb b/db/seeds.rb index 387b869..d408e06 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -8,7 +8,6 @@ User.create(name: 'yoshida') User.create(name: 'naoki') -User.create(name: 'amesel') User.create(name: 'yoshinao0330') User.create(name: 'frasel') diff --git a/test/fixtures/tasks.yml b/test/fixtures/tasks.yml new file mode 100644 index 0000000..a8530a8 --- /dev/null +++ b/test/fixtures/tasks.yml @@ -0,0 +1,15 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html + +one: + user_id: 1 + content: MyText + state: MyString + start_time: 2012-04-29 13:50:06 + end_time: 2012-04-29 13:50:06 + +two: + user_id: 1 + content: MyText + state: MyString + start_time: 2012-04-29 13:50:06 + end_time: 2012-04-29 13:50:06 diff --git a/test/functional/tasks_controller_test.rb b/test/functional/tasks_controller_test.rb new file mode 100644 index 0000000..e09e4e9 --- /dev/null +++ b/test/functional/tasks_controller_test.rb @@ -0,0 +1,49 @@ +require 'test_helper' + +class TasksControllerTest < ActionController::TestCase + setup do + @task = tasks(:one) + end + + test "should get index" do + get :index + assert_response :success + assert_not_nil assigns(:tasks) + end + + test "should get new" do + get :new + assert_response :success + end + + test "should create task" do + assert_difference('Task.count') do + post :create, task: { content: @task.content, end_time: @task.end_time, start_time: @task.start_time, state: @task.state, user_id: @task.user_id } + end + + assert_redirected_to task_path(assigns(:task)) + end + + test "should show task" do + get :show, id: @task + assert_response :success + end + + test "should get edit" do + get :edit, id: @task + assert_response :success + end + + test "should update task" do + put :update, id: @task, task: { content: @task.content, end_time: @task.end_time, start_time: @task.start_time, state: @task.state, user_id: @task.user_id } + assert_redirected_to task_path(assigns(:task)) + end + + test "should destroy task" do + assert_difference('Task.count', -1) do + delete :destroy, id: @task + end + + assert_redirected_to tasks_path + end +end diff --git a/test/unit/helpers/tasks_helper_test.rb b/test/unit/helpers/tasks_helper_test.rb new file mode 100644 index 0000000..440239e --- /dev/null +++ b/test/unit/helpers/tasks_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class TasksHelperTest < ActionView::TestCase +end diff --git a/test/unit/task_test.rb b/test/unit/task_test.rb new file mode 100644 index 0000000..3ca2159 --- /dev/null +++ b/test/unit/task_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class TaskTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end