Skip to content

Commit

Permalink
Make dashboard work again
Browse files Browse the repository at this point in the history
  • Loading branch information
hmlON committed Jul 23, 2017
1 parent 1f2bd55 commit 3fe38f7
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 24 deletions.
21 changes: 21 additions & 0 deletions app/controllers/activities_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class ActivitiesController < ApplicationController
before_action :authenticate_user!
before_action :require_room_presence

def create
activity = Activity.new(activity_params)
if activity.save
redirect_to dashboard_path, notice: "Good job, #{current_user.name}, for \"#{activity.name}\"!"
else
redirect_to dashboard_path, alert: activity.errors.full_messages.join(', ')
end
end

private

def activity_params
params.require(:activity)
.permit(:room_activity_id)
.merge(user_id: current_user.id)
end
end
2 changes: 2 additions & 0 deletions app/models/activity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
class Activity < ApplicationRecord
belongs_to :user
belongs_to :room_activity

delegate :name, to: :room_activity
end
13 changes: 6 additions & 7 deletions app/views/dashboard/_submit_done_action_form.html.slim
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
= form_tag(submit_done_action_path, method: :post, class: 'text-center') do
.form-group
= collection_select :user_action, :id,
current_user.user_actions, :id, :name,
{ prompt: 'What have you done today?', disabled: false },
{ class: 'custom-select', required: true }
= submit_tag 'Submit', class: 'btn btn-primary'
= simple_form_for Activity.new do |f|
.card.text-center
.card-block
h5.text-center What have you done today?
= f.input :room_activity_id, collection: @room.room_activities, prompt: '-', label: false
= f.submit 'Submit', class: 'btn btn-primary'
6 changes: 2 additions & 4 deletions app/views/dashboard/index.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ ul.nav.nav-tabs.justify-content-center.m-3 role="tablist"
.tab-content
#status.tab-pane.active role="tabpanel"
= render 'status'

.card.col-sm-4.offset-sm-4.text-center
.card-block
= render 'submit_done_action_form'

= render 'submit_done_action_form'

#progress.tab-pane role="tabpanel"
= render 'progress'
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

scope 'dashboard', controller: :dashboard do
get '/', action: :index, as: 'dashboard'
post 'submit-done-action'
post 'punish', as: 'punish' # TODO: switch to punishments#create
end

Expand All @@ -22,6 +21,7 @@
end

resources :room_activities, only: [:new, :update, :create, :destroy]
resources :activities, only: [:create, :destroy]

resources :punishments, only: [:index]
end
23 changes: 11 additions & 12 deletions spec/features/dashboard_spec.rb
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
RSpec.feature 'Dashboard' do
let(:user) { create(:user) }
let(:room) { create(:room, :with_activities) }
let(:user) { room.users.first }
let!(:room_activity) { create :room_activity, room: room }
let(:room_activity_name) { room_activity.name }

background do
user.join_room(room)
sign_in user
visit dashboard_path
end

scenario 'User submits done action' do
# room_action = room.room_actions.first
scenario 'User submits done activity' do
expect {
select room_activity_name, from: 'activity_room_activity_id'
click_button 'Submit'
}.to change { Activity.count }.by(1)

# expect {
# select room_action.name, from: 'user_action_id'
# click_button 'Submit'
# }.to change { user.user_actions.find_by(room_action_id: room_action.id).value }.by(1)
expect(page).to have_content 'Good job'
expect(user.next_on_room_activities.pluck(:name)).not_to include(room_activity_name)

# expect(page).to have_content 'Good job'
# expect(room_action.next_on_user).not_to eq user

# click_on 'History'
# TODO: turn on this test, it is temporary disabled
# click_on 'History'
# within '#history' do
# expect(page).to have_content "#{user.name} has done \"#{room_action.name}\""
# end
Expand Down

0 comments on commit 3fe38f7

Please sign in to comment.