Skip to content

Commit c01a33e

Browse files
committed
added testing for draft deletion when creating tags
1 parent c06cc02 commit c01a33e

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

test/controllers/tags_controller_test.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,21 @@ class TagsControllerTest < ActionController::TestCase
111111

112112
users.each do |user|
113113
sign_in(user)
114-
try_create_tag(category, tag_set, name: "test-tag-#{user.id}")
114+
115+
draft_path = create_tag_path(id: category.id)
116+
tag_name = "test-tag-#{user.id}"
117+
118+
@controller.stub('params', { tag_name: tag_name }) do
119+
@controller.do_save_draft(user, draft_path)
120+
end
121+
122+
try_create_tag(category, tag_set, name: tag_name)
115123

116124
if !@controller.helpers.user_signed_in?
117125
assert_redirected_to_sign_in
118126
elsif user.can_edit_tags?
119127
assert_response(:found, "Expected user '#{user.name}' to be able to create tags")
128+
assert_draft_deleted(user, draft_path, :tag_name)
120129
else
121130
assert_response(:not_found, "Expected user '#{user.name}' to not be able to create tags")
122131
end
@@ -276,6 +285,9 @@ class TagsControllerTest < ActionController::TestCase
276285
# @param category [Category] category to create the tag in
277286
# @param tag_set [TagSet] tag set the tag belongs to
278287
def try_create_tag(tag_set, category, **opts)
288+
# this is needed for draft deletion until we switch from request.referer
289+
@request.set_header('HTTP_REFERER', create_tag_path(id: category.id))
290+
279291
post :create, params: {
280292
id: category.id,
281293
tag: {

test/test_helper.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,16 @@ def copy_abilities(community_id)
129129
end
130130
end
131131

132+
def assert_draft_deleted(user, path, *fields)
133+
base_key = "saved_post.#{user.id}.#{path}"
134+
135+
fields.each do |key|
136+
key_name = DraftManagement::NESTED_DRAFTABLE_FIELDS.include?(key) ? base_key : "#{base_key}.#{key}"
137+
assert_not(RequestContext.redis.exists?(key_name),
138+
"Expected '#{key_name}' draft to be deleted")
139+
end
140+
end
141+
132142
def assert_valid_json_response
133143
assert_nothing_raised do
134144
parsed = JSON.parse(response.body)

0 commit comments

Comments
 (0)