Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Modify activity to comment

  • Loading branch information...
commit 067ce2fd1f8a4608cc8952a75126857f37a2857c 1 parent 3826a28
Naoki Yoshida amesel authored
Showing with 197 additions and 197 deletions.
  1. 0  app/assets/javascripts/{activities.js.coffee → comments.js.coffee}
  2. +2 −2 app/assets/javascripts/parties.js.coffee
  3. +1 −1  app/assets/stylesheets/sass/parties.css.sass
  4. +0 −76 app/controllers/activities_controller.rb
  5. +76 −0 app/controllers/comments_controller.rb
  6. +0 −2  app/helpers/activities_helper.rb
  7. +2 −0  app/helpers/comments_helper.rb
  8. +1 −1  app/models/{activity.rb → comment.rb}
  9. +1 −1  app/models/task.rb
  10. +1 −1  app/models/user.rb
  11. +0 −7 app/views/activities/_activity.html.haml
  12. +0 −2  app/views/activities/create.js.erb
  13. +0 −1  app/views/activities/destroy.js.erb
  14. +0 −6 app/views/activities/edit.html.erb
  15. +0 −25 app/views/activities/index.html.erb
  16. +0 −5 app/views/activities/new.html.erb
  17. +0 −15 app/views/activities/show.html.erb
  18. +7 −0 app/views/comments/_comment.html.haml
  19. +4 −4 app/views/{activities → comments}/_form.html.erb
  20. +2 −0  app/views/comments/create.js.erb
  21. +1 −0  app/views/comments/destroy.js.erb
  22. +6 −0 app/views/comments/edit.html.erb
  23. +25 −0 app/views/comments/index.html.erb
  24. +5 −0 app/views/comments/new.html.erb
  25. +15 −0 app/views/comments/show.html.erb
  26. +5 −5 app/views/tasks/_task.html.haml
  27. +1 −1  config/initializers/devise.rb
  28. +1 −1  config/routes.rb
  29. +2 −2 db/migrate/{20120519100019_create_activities.rb → 20120519100019_create_comments.rb}
  30. +8 −8 db/schema.rb
  31. +12 −12 public/parties_show.html
  32. +17 −17 test/functional/activities_controller_test.rb
  33. +1 −1  test/unit/activity_test.rb
  34. +1 −1  test/unit/helpers/activities_helper_test.rb
0  app/assets/javascripts/activities.js.coffee → app/assets/javascripts/comments.js.coffee
View
File renamed without changes
4 app/assets/javascripts/parties.js.coffee
View
@@ -18,7 +18,7 @@ $ ->
$(".member .header .selectstate").toggle()
$(".doing").click ->
$(".current .actions").toggle()
- $(".activities .label").click ->
- $(".activities ul").toggle()
+ $(".comments .label").click ->
+ $(".comments ul").toggle()
$("#notice").css "left", $(window).width() / 2 - $("#notice").width() / 2
$("#notice").delay(2000).fadeOut "slow"
2  app/assets/stylesheets/sass/parties.css.sass
View
@@ -234,7 +234,7 @@ body.parties_show
+border-radius(0 4px 4px 0)
border-left: $label_text_shadow 1px solid
- .activities
+ .comments
clear: both
+clearfix
.add
76 app/controllers/activities_controller.rb
View
@@ -1,76 +0,0 @@
-class ActivitiesController < ApplicationController
- before_filter :authenticate_user!
- respond_to :html, :json, :js
-
- # GET /activities
- # GET /activities.json
- def index
- @activities = Activity.all
-
- respond_to do |format|
- format.html # index.html.erb
- format.json { render json: @activities }
- end
- end
-
- # GET /activities/1
- # GET /activities/1.json
- def show
- @activity = Activity.find(params[:id])
-
- respond_to do |format|
- format.html # show.html.erb
- format.json { render json: @activity }
- end
- end
-
- # GET /activities/new
- # GET /activities/new.json
- def new
- @activity = Activity.new
-
- respond_to do |format|
- format.html # new.html.erb
- format.json { render json: @activity }
- end
- end
-
- # GET /activities/1/edit
- def edit
- @activity = Activity.find(params[:id])
- end
-
- # POST /activities
- # POST /activities.json
- def create
- @activity = current_user.activities.build
- @activity.task_id = params[:task_id]
- @activity.content = params[:content]
- @activity.save
- respond_with @activity
- end
-
- # PUT /activities/1
- # PUT /activities/1.json
- def update
- @activity = Activity.find(params[:id])
-
- respond_to do |format|
- if @activity.update_attributes(params[:activity])
- format.html { redirect_to @activity, notice: 'Activity was successfully updated.' }
- format.json { head :no_content }
- else
- format.html { render action: "edit" }
- format.json { render json: @activity.errors, status: :unprocessable_entity }
- end
- end
- end
-
- # DELETE /activities/1
- # DELETE /activities/1.json
- def destroy
- @activity = Activity.find(params[:id])
- @activity.destroy
- respond_with @activity
- end
-end
76 app/controllers/comments_controller.rb
View
@@ -0,0 +1,76 @@
+class CommentsController < ApplicationController
+ before_filter :authenticate_user!
+ respond_to :html, :json, :js
+
+ # GET /comments
+ # GET /comments.json
+ def index
+ @comments = Comment.all
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.json { render json: @comments }
+ end
+ end
+
+ # GET /comments/1
+ # GET /comments/1.json
+ def show
+ @comment = Comment.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render json: @comment }
+ end
+ end
+
+ # GET /comments/new
+ # GET /comments/new.json
+ def new
+ @comment = Comment.new
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.json { render json: @comment }
+ end
+ end
+
+ # GET /comments/1/edit
+ def edit
+ @comment = Comment.find(params[:id])
+ end
+
+ # POST /comments
+ # POST /comments.json
+ def create
+ @comment = current_user.comments.build
+ @comment.task_id = params[:task_id]
+ @comment.content = params[:content]
+ @comment.save
+ respond_with @comment
+ end
+
+ # PUT /comments/1
+ # PUT /comments/1.json
+ def update
+ @comment = Comment.find(params[:id])
+
+ respond_to do |format|
+ if @comment.update_attributes(params[:comment])
+ format.html { redirect_to @comment, notice: 'Comment was successfully updated.' }
+ format.json { head :no_content }
+ else
+ format.html { render action: "edit" }
+ format.json { render json: @comment.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /comments/1
+ # DELETE /comments/1.json
+ def destroy
+ @comment = Comment.find(params[:id])
+ @comment.destroy
+ respond_with @comment
+ end
+end
2  app/helpers/activities_helper.rb
View
@@ -1,2 +0,0 @@
-module ActivitiesHelper
-end
2  app/helpers/comments_helper.rb
View
@@ -0,0 +1,2 @@
+module CommentsHelper
+end
2  app/models/activity.rb → app/models/comment.rb
View
@@ -1,4 +1,4 @@
-class Activity < ActiveRecord::Base
+class Comment < ActiveRecord::Base
attr_accessible :content, :task_id, :user_id
belongs_to :task
2  app/models/task.rb
View
@@ -2,7 +2,7 @@ class Task < ActiveRecord::Base
attr_accessible :content, :finished_at, :started_at, :state, :user_id
belongs_to :user
belongs_to :party
- has_many :activities
+ has_many :comments
validates :content, :user_id, :presence => true
2  app/models/user.rb
View
@@ -6,7 +6,7 @@ class User < ActiveRecord::Base
has_many :joins
has_many :invited_parties, :through => :joins, :source => :party
has_many :tasks
- has_many :activities
+ has_many :comments
validates :name, :presence => true
validates :password, :presence => true, :on => :create
7 app/views/activities/_activity.html.haml
View
@@ -1,7 +0,0 @@
-= content_tag_for :li, activity, :class => "activity" do
- .icon
- %a{:href => ""}
- = image_tag activity.user.image_url(:thumb), alt: activity.user.name, class: "avatar size128"
- %p= nl2br activity.content
- - if user_signed_in? && current_user == activity.user
- %p= link_to "delete", activity_path(activity), :method => :delete, :remote => true
2  app/views/activities/create.js.erb
View
@@ -1,2 +0,0 @@
-$('#<%= dom_id(@activity.task) %> textarea').val("")
-$('#<%= dom_id(@activity.task) %> .activities ul').prepend("<%= j(render @activity) %>").fadeIn()
1  app/views/activities/destroy.js.erb
View
@@ -1 +0,0 @@
-$('#<%= dom_id(@activity) %>').remove().fadeOut()
6 app/views/activities/edit.html.erb
View
@@ -1,6 +0,0 @@
-<h1>Editing activity</h1>
-
-<%= render 'form' %>
-
-<%= link_to 'Show', @activity %> |
-<%= link_to 'Back', activities_path %>
25 app/views/activities/index.html.erb
View
@@ -1,25 +0,0 @@
-<h1>Listing activities</h1>
-
-<table>
- <tr>
- <th>User</th>
- <th>Content</th>
- <th></th>
- <th></th>
- <th></th>
- </tr>
-
-<% @activities.each do |activity| %>
- <tr>
- <td><%= activity.user_id %></td>
- <td><%= activity.content %></td>
- <td><%= link_to 'Show', activity %></td>
- <td><%= link_to 'Edit', edit_activity_path(activity) %></td>
- <td><%= link_to 'Destroy', activity, confirm: 'Are you sure?', method: :delete %></td>
- </tr>
-<% end %>
-</table>
-
-<br />
-
-<%= link_to 'New Activity', new_activity_path %>
5 app/views/activities/new.html.erb
View
@@ -1,5 +0,0 @@
-<h1>New activity</h1>
-
-<%= render 'form' %>
-
-<%= link_to 'Back', activities_path %>
15 app/views/activities/show.html.erb
View
@@ -1,15 +0,0 @@
-<p id="notice"><%= notice %></p>
-
-<p>
- <b>User:</b>
- <%= @activity.user_id %>
-</p>
-
-<p>
- <b>Content:</b>
- <%= @activity.content %>
-</p>
-
-
-<%= link_to 'Edit', edit_activity_path(@activity) %> |
-<%= link_to 'Back', activities_path %>
7 app/views/comments/_comment.html.haml
View
@@ -0,0 +1,7 @@
+= content_tag_for :li, comment, :class => "comment" do
+ .icon
+ %a{:href => ""}
+ = image_tag comment.user.image_url(:thumb), alt: comment.user.name, class: "avatar size128"
+ %p= nl2br comment.content
+ - if user_signed_in? && current_user == comment.user
+ %p= link_to "delete", comment_path(comment), :method => :delete, :remote => true
8 app/views/activities/_form.html.erb → app/views/comments/_form.html.erb
View
@@ -1,10 +1,10 @@
-<%= form_for(@activity) do |f| %>
- <% if @activity.errors.any? %>
+<%= form_for(@comment) do |f| %>
+ <% if @comment.errors.any? %>
<div id="error_explanation">
- <h2><%= pluralize(@activity.errors.count, "error") %> prohibited this activity from being saved:</h2>
+ <h2><%= pluralize(@comment.errors.count, "error") %> prohibited this comment from being saved:</h2>
<ul>
- <% @activity.errors.full_messages.each do |msg| %>
+ <% @comment.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
2  app/views/comments/create.js.erb
View
@@ -0,0 +1,2 @@
+$('#<%= dom_id(@comment.task) %> textarea').val("")
+$('#<%= dom_id(@comment.task) %> .comments ul').prepend("<%= j(render @comment) %>").fadeIn()
1  app/views/comments/destroy.js.erb
View
@@ -0,0 +1 @@
+$('#<%= dom_id(@comment) %>').remove().fadeOut()
6 app/views/comments/edit.html.erb
View
@@ -0,0 +1,6 @@
+<h1>Editing comment</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Show', @comment %> |
+<%= link_to 'Back', comments_path %>
25 app/views/comments/index.html.erb
View
@@ -0,0 +1,25 @@
+<h1>Listing comments</h1>
+
+<table>
+ <tr>
+ <th>User</th>
+ <th>Content</th>
+ <th></th>
+ <th></th>
+ <th></th>
+ </tr>
+
+<% @comments.each do |comment| %>
+ <tr>
+ <td><%= comment.user_id %></td>
+ <td><%= comment.content %></td>
+ <td><%= link_to 'Show', comment %></td>
+ <td><%= link_to 'Edit', edit_comment_path(comment) %></td>
+ <td><%= link_to 'Destroy', comment, confirm: 'Are you sure?', method: :delete %></td>
+ </tr>
+<% end %>
+</table>
+
+<br />
+
+<%= link_to 'New Comment', new_comment_path %>
5 app/views/comments/new.html.erb
View
@@ -0,0 +1,5 @@
+<h1>New comment</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Back', comments_path %>
15 app/views/comments/show.html.erb
View
@@ -0,0 +1,15 @@
+<p id="notice"><%= notice %></p>
+
+<p>
+ <b>User:</b>
+ <%= @comment.user_id %>
+</p>
+
+<p>
+ <b>Content:</b>
+ <%= @comment.content %>
+</p>
+
+
+<%= link_to 'Edit', edit_comment_path(@comment) %> |
+<%= link_to 'Back', comments_path %>
10 app/views/tasks/_task.html.haml
View
@@ -31,10 +31,10 @@
- if user_signed_in?
.add
- = form_tag "/activities", :remote => true do
+ = form_tag "/comments", :remote => true do
= hidden_field_tag :task_id, task.id
- = text_area_tag :content, nil, :rows => 3, :cols => 15, :id => "new_activity_#{dom_id(task)}"
- = submit_tag "new activity"
- .activities
+ = text_area_tag :content, nil, :rows => 3, :cols => 15, :id => "new_comment_#{dom_id(task)}"
+ = submit_tag "new comment"
+ .comments
%ul
- = render task.activities
+ = render task.comments
2  config/initializers/devise.rb
View
@@ -111,7 +111,7 @@
# config.email_regexp = /\A[^@]+@[^@]+\z/
# ==> Configuration for :timeoutable
- # The time you want to timeout the user session without activity. After this
+ # The time you want to timeout the user session without comment. After this
# time the user will be asked for credentials again. Default is 30 minutes.
# config.timeout_in = 30.minutes
2  config/routes.rb
View
@@ -3,7 +3,7 @@
get "settings/edit" => "settings#edit"
put "settings/update" => "settings#update"
- resources :activities
+ resources :comments
resources :joins
4 db/migrate/20120519100019_create_activities.rb → db/migrate/20120519100019_create_comments.rb
View
@@ -1,6 +1,6 @@
-class CreateActivities < ActiveRecord::Migration
+class CreateComments < ActiveRecord::Migration
def change
- create_table :activities do |t|
+ create_table :comments do |t|
t.integer :task_id
t.integer :user_id
t.text :content
16 db/schema.rb
View
@@ -13,14 +13,6 @@
ActiveRecord::Schema.define(:version => 20120527040434) do
- create_table "activities", :force => true do |t|
- t.integer "task_id"
- t.integer "user_id"
- t.text "content"
- t.datetime "created_at", :null => false
- t.datetime "updated_at", :null => false
- end
-
create_table "authentications", :force => true do |t|
t.integer "user_id"
t.string "provider"
@@ -36,6 +28,14 @@
t.datetime "updated_at", :null => false
end
+ create_table "comments", :force => true do |t|
+ t.integer "task_id"
+ t.integer "user_id"
+ t.text "content"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
+
create_table "joins", :force => true do |t|
t.integer "user_id"
t.integer "party_id"
24 public/parties_show.html
View
@@ -61,9 +61,9 @@ <h1 class="icon">
</ul>
</div>
</div>
- <div class="activities">
+ <div class="comments">
<div class="label">
- <h2>Activities</h2>
+ <h2>Comments</h2>
</div>
<div class="add">
<form name="form1">
@@ -169,9 +169,9 @@ <h1 class="icon">
<div class="doing">
<p>『不思議の国のアリス』(ふしぎのくにのアリス)は、イギリスの数学者にして作家チャールズ・ラトウィッジ・ドジソンが、ルイス・35.685753 , 139.765293</p>
</div>
- <div class="activities">
+ <div class="comments">
<div class="label">
- <h2>Activities</h2>
+ <h2>Comments</h2>
</div>
<div class="add">
<form name="form1">
@@ -274,9 +274,9 @@ <h1 class="icon">
<div class="doing">
<p>『不思議の国のアリス』(ふしぎのくにのアリス)は、イギリスの数学者にして作家チャールズ・ラトウィッジ・ドジソンが、ルイス・35.685753 , 139.765293</p>
</div>
- <div class="activities">
+ <div class="comments">
<div class="label">
- <h2>Activities</h2>
+ <h2>Comments</h2>
</div>
<div class="add">
<form name="form1">
@@ -379,9 +379,9 @@ <h1 class="icon">
<div class="doing">
<p>『不思議の国のアリス』(ふしぎのくにのアリス)は、イギリスの数学者にして作家チャールズ・ラトウィッジ・ドジソンが、ルイス・35.685753 , 139.765293</p>
</div>
- <div class="activities">
+ <div class="comments">
<div class="label">
- <h2>Activities</h2>
+ <h2>Comments</h2>
</div>
<div class="add">
<form name="form1">
@@ -484,9 +484,9 @@ <h1 class="icon">
<div class="doing">
<p>『不思議の国のアリス』(ふしぎのくにのアリス)は、イギリスの数学者にして作家チャールズ・ラトウィッジ・ドジソンが、ルイス・35.685753 , 139.765293</p>
</div>
- <div class="activities">
+ <div class="comments">
<div class="label">
- <h2>Activities</h2>
+ <h2>Comments</h2>
</div>
<div class="add">
<form name="form1">
@@ -589,9 +589,9 @@ <h1 class="icon">
<div class="doing">
<p>『不思議の国のアリス』(ふしぎのくにのアリス)は、イギリスの数学者にして作家チャールズ・ラトウィッジ・ドジソンが、ルイス・35.685753 , 139.765293</p>
</div>
- <div class="activities">
+ <div class="comments">
<div class="label">
- <h2>Activities</h2>
+ <h2>Comments</h2>
</div>
<div class="add">
<form name="form1">
34 test/functional/activities_controller_test.rb
View
@@ -1,14 +1,14 @@
require 'test_helper'
-class ActivitiesControllerTest < ActionController::TestCase
+class CommentsControllerTest < ActionController::TestCase
setup do
- @activity = activities(:one)
+ @comment = comments(:one)
end
test "should get index" do
get :index
assert_response :success
- assert_not_nil assigns(:activities)
+ assert_not_nil assigns(:comments)
end
test "should get new" do
@@ -16,34 +16,34 @@ class ActivitiesControllerTest < ActionController::TestCase
assert_response :success
end
- test "should create activity" do
- assert_difference('Activity.count') do
- post :create, activity: { content: @activity.content, user_id: @activity.user_id }
+ test "should create comment" do
+ assert_difference('Comment.count') do
+ post :create, comment: { content: @comment.content, user_id: @comment.user_id }
end
- assert_redirected_to activity_path(assigns(:activity))
+ assert_redirected_to comment_path(assigns(:comment))
end
- test "should show activity" do
- get :show, id: @activity
+ test "should show comment" do
+ get :show, id: @comment
assert_response :success
end
test "should get edit" do
- get :edit, id: @activity
+ get :edit, id: @comment
assert_response :success
end
- test "should update activity" do
- put :update, id: @activity, activity: { content: @activity.content, user_id: @activity.user_id }
- assert_redirected_to activity_path(assigns(:activity))
+ test "should update comment" do
+ put :update, id: @comment, comment: { content: @comment.content, user_id: @comment.user_id }
+ assert_redirected_to comment_path(assigns(:comment))
end
- test "should destroy activity" do
- assert_difference('Activity.count', -1) do
- delete :destroy, id: @activity
+ test "should destroy comment" do
+ assert_difference('Comment.count', -1) do
+ delete :destroy, id: @comment
end
- assert_redirected_to activities_path
+ assert_redirected_to comments_path
end
end
2  test/unit/activity_test.rb
View
@@ -1,6 +1,6 @@
require 'test_helper'
-class ActivityTest < ActiveSupport::TestCase
+class CommentTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
2  test/unit/helpers/activities_helper_test.rb
View
@@ -1,4 +1,4 @@
require 'test_helper'
-class ActivitiesHelperTest < ActionView::TestCase
+class CommentsHelperTest < ActionView::TestCase
end
Please sign in to comment.
Something went wrong with that request. Please try again.