From 40263a06c196e0c99cc13d187228bd62bbcf4a6a Mon Sep 17 00:00:00 2001 From: Vinnie Okada Date: Mon, 6 Oct 2014 19:19:12 -0500 Subject: [PATCH 1/2] Refactor task list tests and coffeescript --- .../behaviors/taskable_behavior.js.coffee | 21 ++++++++++++++ app/assets/javascripts/issue.js.coffee | 26 ++++------------- .../javascripts/merge_request.js.coffee | 28 +++++------------- features/project/issues/issues.feature | 2 +- features/project/merge_requests.feature | 3 +- features/steps/project/issues/issues.rb | 22 ++------------ features/steps/project/merge_requests.rb | 12 +------- features/steps/shared/markdown.rb | 29 ++++++++++++++----- 8 files changed, 61 insertions(+), 82 deletions(-) create mode 100644 app/assets/javascripts/behaviors/taskable_behavior.js.coffee diff --git a/app/assets/javascripts/behaviors/taskable_behavior.js.coffee b/app/assets/javascripts/behaviors/taskable_behavior.js.coffee new file mode 100644 index 00000000000..ddce71c1886 --- /dev/null +++ b/app/assets/javascripts/behaviors/taskable_behavior.js.coffee @@ -0,0 +1,21 @@ +window.updateTaskState = (taskableType) -> + objType = taskableType.data + isChecked = $(this).prop("checked") + if $(this).is(":checked") + stateEvent = "task_check" + else + stateEvent = "task_uncheck" + + taskableUrl = $("form.edit-" + objType).first().attr("action") + taskableNum = taskableUrl.match(/\d+$/) + taskNum = 0 + $("li.task-list-item input:checkbox").each( (index, e) => + if e == this + taskNum = index + 1 + ) + + $.ajax + type: "PATCH" + url: taskableUrl + data: objType + "[state_event]=" + stateEvent + + "&" + objType + "[task_num]=" + taskNum diff --git a/app/assets/javascripts/issue.js.coffee b/app/assets/javascripts/issue.js.coffee index f2b531fb2b1..0e2a2fa792a 100644 --- a/app/assets/javascripts/issue.js.coffee +++ b/app/assets/javascripts/issue.js.coffee @@ -9,25 +9,11 @@ class Issue if $("a.btn-close").length $("li.task-list-item input:checkbox").prop("disabled", false) - $(".task-list-item input:checkbox").on "click", -> - is_checked = $(this).prop("checked") - if $(this).is(":checked") - state_event = "task_check" - else - state_event = "task_uncheck" - - mr_url = $("form.edit-issue").first().attr("action") - mr_num = mr_url.match(/\d+$/) - task_num = 0 - $("li.task-list-item input:checkbox").each( (index, e) => - if e == this - task_num = index + 1 - ) - - $.ajax - type: "PATCH" - url: mr_url - data: "issue[state_event]=" + state_event + - "&issue[task_num]=" + task_num + $(".task-list-item input:checkbox").on( + "click" + null + "issue" + updateTaskState + ) @Issue = Issue diff --git a/app/assets/javascripts/merge_request.js.coffee b/app/assets/javascripts/merge_request.js.coffee index 203c721c30c..3c78e4b5f0e 100644 --- a/app/assets/javascripts/merge_request.js.coffee +++ b/app/assets/javascripts/merge_request.js.coffee @@ -17,7 +17,7 @@ class MergeRequest disableButtonIfEmptyField '#commit_message', '.accept_merge_request' - if $("a.close-mr-link").length + if $("a.btn-close").length $("li.task-list-item input:checkbox").prop("disabled", false) # Local jQuery finder @@ -74,26 +74,12 @@ class MergeRequest this.$('.remove_source_branch_in_progress').hide() this.$('.remove_source_branch_widget.failed').show() - this.$(".task-list-item input:checkbox").on "click", -> - is_checked = $(this).prop("checked") - if $(this).is(":checked") - state_event = "task_check" - else - state_event = "task_uncheck" - - mr_url = $("form.edit-merge_request").first().attr("action") - mr_num = mr_url.match(/\d+$/) - task_num = 0 - $("li.task-list-item input:checkbox").each( (index, e) => - if e == this - task_num = index + 1 - ) - - $.ajax - type: "PATCH" - url: mr_url - data: "merge_request[state_event]=" + state_event + - "&merge_request[task_num]=" + task_num + $(".task-list-item input:checkbox").on( + "click" + null + "merge_request" + updateTaskState + ) activateTab: (action) -> this.$('.merge-request-tabs li').removeClass 'active' diff --git a/features/project/issues/issues.feature b/features/project/issues/issues.feature index e989569ccd4..4db8551559b 100644 --- a/features/project/issues/issues.feature +++ b/features/project/issues/issues.feature @@ -144,7 +144,7 @@ Feature: Project Issues Scenario: Issues list should display task status Given project "Shop" has "Tasks-open" open issue with task markdown When I visit project "Shop" issues page - Then I should see the task status for issue "Tasks-open" + Then I should see the task status for the Taskable # Toggling task items diff --git a/features/project/merge_requests.feature b/features/project/merge_requests.feature index bad83191371..7ac1c91bc8f 100644 --- a/features/project/merge_requests.feature +++ b/features/project/merge_requests.feature @@ -170,11 +170,10 @@ Feature: Project Merge Requests # Task status in issues list - @now Scenario: Merge requests list should display task status Given project "Shop" has "MR-task-open" open MR with task markdown When I visit project "Shop" merge requests page - Then I should see the task status for merge request "MR-task-open" + Then I should see the task status for the Taskable # Toggling task items diff --git a/features/steps/project/issues/issues.rb b/features/steps/project/issues/issues.rb index 26c3c7c14bc..640603562dd 100644 --- a/features/steps/project/issues/issues.rb +++ b/features/steps/project/issues/issues.rb @@ -154,29 +154,11 @@ class Spinach::Features::ProjectIssues < Spinach::FeatureSteps end step 'project "Shop" has "Tasks-open" open issue with task markdown' do - desc_text = < :last-child")[:href].should =~ /##{id}$/ end + def create_taskable(type, title) + desc_text = < Date: Tue, 7 Oct 2014 11:17:04 -0500 Subject: [PATCH 2/2] Rename coffeescript file --- .../behaviors/{taskable_behavior.js.coffee => taskable.js.coffee} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename app/assets/javascripts/behaviors/{taskable_behavior.js.coffee => taskable.js.coffee} (100%) diff --git a/app/assets/javascripts/behaviors/taskable_behavior.js.coffee b/app/assets/javascripts/behaviors/taskable.js.coffee similarity index 100% rename from app/assets/javascripts/behaviors/taskable_behavior.js.coffee rename to app/assets/javascripts/behaviors/taskable.js.coffee