Skip to content

Commit

Permalink
Change URL of learnings
Browse files Browse the repository at this point in the history
  • Loading branch information
hrysd committed Mar 29, 2013
1 parent d373f1d commit bcde393
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 39 deletions.
6 changes: 3 additions & 3 deletions app/assets/javascripts/practices.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ $ ->
$(document).on 'click', 'button.unstarted', ->
that = this
practice_id = getPracticeId($(this))
$.ajax "/practices/#{practice_id}/start",
$.ajax "/practices/#{practice_id}/learnings",
type: 'POST'
.done ->
$(that)
Expand All @@ -15,7 +15,7 @@ $ ->
$(document).on 'click', 'button.started', ->
that = this
practice_id = getPracticeId($(this))
$.ajax "/practices/#{practice_id}/finish",
$.ajax "/practices/#{practice_id}/learnings",
type: 'PUT'
.done ->
$(that)
Expand All @@ -25,7 +25,7 @@ $ ->
$(document).on 'click', 'button.complete', ->
that = this
practice_id = getPracticeId($(this))
$.ajax "/practices/#{practice_id}/destroy",
$.ajax "/practices/#{practice_id}/learnings",
type: 'DELETE'
.done ->
$(that)
Expand Down
16 changes: 6 additions & 10 deletions app/controllers/learnings_controller.rb
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
class LearningsController < ApplicationController
before_action :set_practice, only: %i(start finish)
before_action :set_practice, only: %w[create update]
layout false

def start
def create
learning = Learning.new(
user_id: current_user.id,
practice_id: params[:practice_id]
)

if Rails.env.production?
notify("#{current_user.last_name} #{current_user.first_name}(#{current_user.login_name})が「#{@practice.title}」を始めました。 #{url_for(@practice)}")
end
notify("#{current_user.full_name}(#{current_user.login_name})が「#{@practice.title}」を始めました。 #{url_for(@practice)}")
head :ok if learning.save
end

def finish
def update
learning = Learning.find_by(
user_id: current_user.id,
practice_id: params[:practice_id]
)

if Rails.env.production?
notify("#{current_user.last_name} #{current_user.first_name}(#{current_user.login_name})が「#{@practice.title}」を完了しました。 #{url_for(@practice)}")
end
notify("#{current_user.full_name}(#{current_user.login_name})が「#{@practice.title}」を完了しました。 #{url_for(@practice)}")
learning.status = :complete
head :ok if learning.save
end
Expand All @@ -47,6 +43,6 @@ def notify(text)
ENV['ROOM_ID'],
ENV['SECRET'],
text
)
) if Rails.env.production?
end
end
2 changes: 1 addition & 1 deletion app/controllers/practices_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class PracticesController < ApplicationController
respond_to :html, :json

def index
@practices = Practice.rank(:row_order).all
@practices = Practice.rank(:row_order).to_a
end

def show
Expand Down
6 changes: 0 additions & 6 deletions app/decorators/user_decorator.rb

This file was deleted.

4 changes: 4 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ def completed_percentage
completed_my_practices_size.to_f / my_practices_size.to_f * 100
end

def full_name
"#{self.last_name} #{self.first_name}"
end

private
def my_practices_size
Practice.where(target_cd: [0, target_cd]).size
Expand Down
6 changes: 1 addition & 5 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
resources :users
resources :user_sessions
resources :practices do
controller :learnings do
post '/start' => :start
put '/finish' => :finish
delete '/destroy' => :destroy
end
resource :learnings, only: %w[create update destroy]
end

get 'login' => 'user_sessions#new', as: :login
Expand Down
14 changes: 0 additions & 14 deletions spec/decorators/user_decorator_spec.rb

This file was deleted.

7 changes: 7 additions & 0 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,11 @@
it { should eq(0) }
end
end

describe '#full_name' do
subject { user.full_name }
let(:user) { FactoryGirl.create(:user, :programmer, last_name: 'Yoshida', first_name: 'Hiroshi') }

it { should eq('Yoshida Hiroshi') }
end
end

0 comments on commit bcde393

Please sign in to comment.