Skip to content
This repository was archived by the owner on Oct 16, 2018. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/site_problems_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def edit_tags

def update_tags
site_problem = SiteProblem.find_or_create_by(site: site, problem_id: params[:problem_id])
site_problem.tags = params[:tags].map { |tag| Tag.find_by!(name: tag) }
site_problem.tags = (params[:tags] || []).map { |tag| Tag.find_by!(name: tag) }
site_problem.save!
Activity.create(user: @current_user, target: site_problem, kind: :tags_update, parameters: site_problem.tags.pluck(:id))
redirect_to send(:"#{site}_path", params[:problem_id])
Expand Down
12 changes: 11 additions & 1 deletion spec/support/shared_examples/site_problems_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,27 @@ def create_wa(problem, user, submitted_at)
end

context 'with sign-in' do
include SiteProblemsHelper

before do
session[:user_id] = user.id
end

it 'works' do
extend SiteProblemsHelper
post :update_tags, problem_id: problem1.problem_id, tags: [tag1.name, tag2.name]
expect(response).to redirect_to(problem_path(problem1))
problem1.reload
expect(problem1.tags.map(&:name)).to match_array([tag2.name, tag1.name])
end

context 'when no tags are given' do
it 'clears tags' do
post :update_tags, problem_id: problem1.problem_id
expect(response).to redirect_to(problem_path(problem1))
problem1.reload
expect(problem1.tags).to be_empty
end
end
end
end
end