Skip to content

Commit

Permalink
Add undo to activity in history
Browse files Browse the repository at this point in the history
  • Loading branch information
hmlON committed Jul 29, 2017
1 parent d15c910 commit bb19792
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
6 changes: 6 additions & 0 deletions app/assets/stylesheets/history.sass
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@

.no-activities
@extend .text-center

.activity-card
display: flex

.activity-text
flex: 1
9 changes: 9 additions & 0 deletions app/controllers/activities_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ def create
end
end

def destroy
activity = Activity.find(params[:id])
if activity.destroy
redirect_to dashboard_path, notice: "Undone #{activity.name} successfully"
else
redirect_to dashboard_path, alert: activity.errors.full_messages.join(', ')
end
end

private

def activity_params
Expand Down
15 changes: 9 additions & 6 deletions app/views/dashboard/_history.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
- if @activities.empty?
.no-activities There is nothing done yet. Try sumbitting done activity.
- @activities.each do |activity|
.activity.card.card-inverse.card-info
.card-block
.card-text
= "#{activity.user.name} has done "
em = "\"#{activity.name}\" "
= activity_time_tag(activity.created_at)
.activity.card.card-inverse.card-info class="activity_#{activity.id}"
.card-block
.activity-card.card-text
.activity-text
= "#{activity.user.name} has done "
em = "\"#{activity.name}\" "
= activity_time_tag(activity.created_at)
.activity-undo
= button_to 'Undo', activity_path(id: activity.id), method: :delete, class: 'btn btn-warning btn-sm form-inline'
11 changes: 11 additions & 0 deletions spec/features/dashboard_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
let(:user) { room.users.first }
let!(:room_activity) { create :room_activity, room: room }
let(:room_activity_name) { room_activity.name }
let(:undone_activity) { room.activities.last }

background do
sign_in user
Expand All @@ -23,4 +24,14 @@
expect(page).to have_content "#{user.name} has done \"#{room_activity.name}\""
end
end

scenario 'User undoes activity' do
click_on 'History'

expect {
within ".activity_#{undone_activity.id}" do
click_button 'Undo'
end
}.to change { Activity.count }.by(-1)
end
end

0 comments on commit bb19792

Please sign in to comment.