From 8f1db79df6ebc27279c2486bdad23c0a6f6f3b1c Mon Sep 17 00:00:00 2001 From: Yih Yang Date: Mon, 30 Sep 2019 23:17:59 +0800 Subject: [PATCH 1/8] implemented admin/chapters#index features --- app/controllers/admin/chapters_controller.rb | 24 +++++- app/policies/chapter_policy.rb | 4 + app/views/admin/chapters/index.html.haml | 32 +++++++ config/locales/en.yml | 7 ++ config/routes.rb | 4 + spec/fabricators/chapter_fabricator.rb | 12 ++- spec/features/admin/chapters_spec.rb | 88 ++++++++++++++++++++ 7 files changed, 169 insertions(+), 2 deletions(-) create mode 100644 app/views/admin/chapters/index.html.haml diff --git a/app/controllers/admin/chapters_controller.rb b/app/controllers/admin/chapters_controller.rb index 168d2d5e3..b3e7f704f 100644 --- a/app/controllers/admin/chapters_controller.rb +++ b/app/controllers/admin/chapters_controller.rb @@ -1,7 +1,16 @@ class Admin::ChaptersController < Admin::ApplicationController - before_action :set_chapter, only: [:show, :edit, :update] + before_action :set_chapter, only: [:show, :edit, :update, :toggle_active] after_action :verify_authorized + def index + authorize Chapter + @chapters = Chapter.all.order(:name) + + if chapter_index_params.present? + @chapters = @chapters.where(chapter_index_params) + end + end + def new @chapter = Chapter.new authorize @chapter @@ -59,8 +68,21 @@ def members render plain: @emails end + def toggle_active + authorize @chapter + + @chapter.toggle!(:active) + flash[:notice] = t('.message', name: @chapter.name) + + return redirect_to admin_chapters_path + end + private + def chapter_index_params + @_chapter_index_params ||= params.permit(:active) + end + def chapter_params params.require(:chapter).permit(:name, :email, :city, :time_zone, :twitter, :description, :image) end diff --git a/app/policies/chapter_policy.rb b/app/policies/chapter_policy.rb index 9e380222b..403f18a89 100644 --- a/app/policies/chapter_policy.rb +++ b/app/policies/chapter_policy.rb @@ -3,6 +3,10 @@ def index? show? end + def toggle_active? + is_admin_or_organiser? + end + def create? is_admin_or_organiser? end diff --git a/app/views/admin/chapters/index.html.haml b/app/views/admin/chapters/index.html.haml new file mode 100644 index 000000000..384712c72 --- /dev/null +++ b/app/views/admin/chapters/index.html.haml @@ -0,0 +1,32 @@ +%section#banner + .row + %h1 Chapter + = link_to 'View All Chapters', admin_chapters_path + = link_to 'View Active Chapters', admin_chapters_path(active: true) + = link_to 'View Inactive Chapters', admin_chapters_path(active: false) + .row + %hr + .large-3.columns + Name / City / Slug + .large-3.columns + Email / Twitter + .large-3.columns + Active? + .large-3.columns + Actions + + - @chapters.each do |chapter| + .row + %hr + .large-3.columns + %p= chapter.name + %p= chapter.city + %p= chapter.slug + .large-3.columns + %p= chapter.email + %p= chapter.twitter + .large-3.columns + = chapter.active? ? t('.yes') : t('.no') + .large-3.columns + = link_to t('.toggle_link'), toggle_active_admin_chapter_path(chapter), method: :post + diff --git a/config/locales/en.yml b/config/locales/en.yml index cc5a2eae2..5c8ebd8b3 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -549,6 +549,13 @@ en: admin: dashboard: title: 'Admin' + chapters: + index: + 'yes': 'Yes' + 'no': 'No' + toggle_link: 'Toggle Active Status' + toggle_active: + message: 'Successfully toggled active status for %{name}' jobs: title: Manage jobs info: diff --git a/config/routes.rb b/config/routes.rb index 3a4b7e46f..5c1f5d455 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -119,6 +119,10 @@ resources :member_notes, only: [:create] resources :chapters, only: %i[index new create show edit update] do + member do + post :toggle_active + end + get :members resources :workshops, only: [:index] resources :feedback, only: [:index], controller: 'chapters/feedback' diff --git a/spec/fabricators/chapter_fabricator.rb b/spec/fabricators/chapter_fabricator.rb index 56f825efa..89cd9786c 100644 --- a/spec/fabricators/chapter_fabricator.rb +++ b/spec/fabricators/chapter_fabricator.rb @@ -2,8 +2,10 @@ Fabricator(:chapter) do name { Fabricate.sequence(:name) } - city { Faker::Lorem.word } + city { Faker::Address.city } email { Faker::Internet.email } + slug { Faker::Internet.slug } + twitter { Faker::Internet.url } time_zone { 'London' } after_save do |chapter| @@ -30,3 +32,11 @@ email { Faker::Internet.email } time_zone { 'London' } end + +Fabricator(:active_chapter, from: :chapter) do + active true +end + +Fabricator(:inactive_chapter, from: :chapter) do + active false +end \ No newline at end of file diff --git a/spec/features/admin/chapters_spec.rb b/spec/features/admin/chapters_spec.rb index 9869b5c0b..7c7110951 100644 --- a/spec/features/admin/chapters_spec.rb +++ b/spec/features/admin/chapters_spec.rb @@ -14,6 +14,72 @@ end end + context '#index' do + let!(:active_chapters) { Fabricate.times(3, :active_chapter) } + let!(:inactive_chapters) { Fabricate.times(3, :inactive_chapter) } + + background { login_as_admin(member) } + + scenario "an admin can view all chapters and it's information" do + visit admin_chapters_path + + assert_chapters_exist_on_page(active_chapters) + assert_chapters_exist_on_page(inactive_chapters) + end + + scenario 'an admin can filter and view only active chapters' do + visit admin_chapters_path + click_link 'View Active Chapters' + + assert_chapters_exist_on_page(active_chapters) + assert_chapters_not_exist_on_page(inactive_chapters) + end + + scenario 'an admin can filter and view only inactive chapters' do + visit admin_chapters_path + click_link 'View Inactive Chapters' + + assert_chapters_exist_on_page(inactive_chapters) + assert_chapters_not_exist_on_page(active_chapters) + end + + scenario 'an admin can filter and view all chapters' do + visit admin_chapters_path + click_link 'View All Chapters' + + assert_chapters_exist_on_page(inactive_chapters) + assert_chapters_exist_on_page(active_chapters) + end + + scenario 'an admin can toggle the status of the active chapter' do + visit admin_chapters_path + first_active_chapter = active_chapters.first + + within(all('.row', text: first_active_chapter.email)[0]) do + click_link 'Toggle Active Status' + end + + expect(page).to have_content( + "Successfully toggled active status for #{first_active_chapter.name}" + ) + expect(first_active_chapter.reload).not_to be_active + end + + scenario 'an admin can toggle the status of the inactive chapter' do + visit admin_chapters_path + first_inactive_chapter = inactive_chapters.first + + within(all('.row', text: first_inactive_chapter.email)[0]) do + click_link 'Toggle Active Status' + end + + expect(page).to have_content( + "Successfully toggled active status for #{first_inactive_chapter.name}" + ) + expect(first_inactive_chapter.reload).to be_active + end + end + context '#creating a new chapter' do before do login_as_admin(member) @@ -122,4 +188,26 @@ expect(page).not_to have_content(coach_email) end end + + private + + def assert_chapters_exist_on_page(chapters) + chapters.each do |chapter| + expect(page).to have_content(chapter.name) + expect(page).to have_content(chapter.city) + expect(page).to have_content(chapter.slug) + expect(page).to have_content(chapter.email) + expect(page).to have_content(chapter.twitter) + end + end + + def assert_chapters_not_exist_on_page(chapters) + chapters.each do |chapter| + expect(page).not_to have_content(chapter.name) + expect(page).not_to have_content(chapter.city) + expect(page).not_to have_content(chapter.slug) + expect(page).not_to have_content(chapter.email) + expect(page).not_to have_content(chapter.twitter) + end + end end From d06f63efdf74795dd64e591408e0a4be20c30da9 Mon Sep 17 00:00:00 2001 From: Yih Yang Date: Mon, 30 Sep 2019 23:19:12 +0800 Subject: [PATCH 2/8] fixed title error --- app/views/admin/chapters/index.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/admin/chapters/index.html.haml b/app/views/admin/chapters/index.html.haml index 384712c72..a157e1aa6 100644 --- a/app/views/admin/chapters/index.html.haml +++ b/app/views/admin/chapters/index.html.haml @@ -1,6 +1,6 @@ %section#banner .row - %h1 Chapter + %h1 Chapters = link_to 'View All Chapters', admin_chapters_path = link_to 'View Active Chapters', admin_chapters_path(active: true) = link_to 'View Inactive Chapters', admin_chapters_path(active: false) From 269a950db45dcdc159513c70955cc2e9792e1128 Mon Sep 17 00:00:00 2001 From: Yih Yang Date: Tue, 1 Oct 2019 21:16:34 +0800 Subject: [PATCH 3/8] updated formatting based on codeclimate suggestions --- app/controllers/admin/chapters_controller.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/app/controllers/admin/chapters_controller.rb b/app/controllers/admin/chapters_controller.rb index b3e7f704f..78987de8d 100644 --- a/app/controllers/admin/chapters_controller.rb +++ b/app/controllers/admin/chapters_controller.rb @@ -1,14 +1,12 @@ class Admin::ChaptersController < Admin::ApplicationController - before_action :set_chapter, only: [:show, :edit, :update, :toggle_active] + before_action :set_chapter, only: %i[show edit update toggle_active] after_action :verify_authorized def index authorize Chapter @chapters = Chapter.all.order(:name) - if chapter_index_params.present? - @chapters = @chapters.where(chapter_index_params) - end + @chapters = @chapters.where(chapter_index_params) if chapter_index_params.present? end def new @@ -71,10 +69,11 @@ def members def toggle_active authorize @chapter - @chapter.toggle!(:active) + @chapter.update(active: !@chapter.active) + flash[:notice] = t('.message', name: @chapter.name) - return redirect_to admin_chapters_path + redirect_to admin_chapters_path end private From f2d1698da0772a06d8afa567628993116481c06d Mon Sep 17 00:00:00 2001 From: Yih Yang Date: Tue, 1 Oct 2019 21:21:24 +0800 Subject: [PATCH 4/8] changed labels to translations --- app/views/admin/chapters/index.html.haml | 6 +++--- config/locales/en.yml | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/views/admin/chapters/index.html.haml b/app/views/admin/chapters/index.html.haml index a157e1aa6..575ab9081 100644 --- a/app/views/admin/chapters/index.html.haml +++ b/app/views/admin/chapters/index.html.haml @@ -1,9 +1,9 @@ %section#banner .row %h1 Chapters - = link_to 'View All Chapters', admin_chapters_path - = link_to 'View Active Chapters', admin_chapters_path(active: true) - = link_to 'View Inactive Chapters', admin_chapters_path(active: false) + = link_to t('.view_all_chapters'), admin_chapters_path + = link_to t('.view_active_chapters'), admin_chapters_path(active: true) + = link_to t('.view_inactive_chapters'), admin_chapters_path(active: false) .row %hr .large-3.columns diff --git a/config/locales/en.yml b/config/locales/en.yml index 5c8ebd8b3..33f08662e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -554,6 +554,9 @@ en: 'yes': 'Yes' 'no': 'No' toggle_link: 'Toggle Active Status' + view_all_chapters: 'View All Chapters' + view_active_chapters: 'View Active Chapters' + view_inactive_chapters: 'View Inactive Chapters' toggle_active: message: 'Successfully toggled active status for %{name}' jobs: From 228785b4337149f9dc26c1e6043ff96ddbc6595c Mon Sep 17 00:00:00 2001 From: Yih Yang Date: Sun, 17 May 2020 22:16:48 +0800 Subject: [PATCH 5/8] fixed naming conventioned based on rubocop's comment --- app/controllers/admin/chapters_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/admin/chapters_controller.rb b/app/controllers/admin/chapters_controller.rb index 78987de8d..88fbe727b 100644 --- a/app/controllers/admin/chapters_controller.rb +++ b/app/controllers/admin/chapters_controller.rb @@ -79,7 +79,7 @@ def toggle_active private def chapter_index_params - @_chapter_index_params ||= params.permit(:active) + @chapter_index_params ||= params.permit(:active) end def chapter_params From 26edcf912ea490a3eff68b0c9093910403aeac0f Mon Sep 17 00:00:00 2001 From: Yih Yang Date: Sun, 17 May 2020 23:28:40 +0800 Subject: [PATCH 6/8] updated admin chapters index page toggle --- app/controllers/admin/chapters_controller.rb | 14 ++++---- app/policies/chapter_policy.rb | 2 +- app/views/admin/chapters/index.html.haml | 37 +++++++++++++------- config/routes.rb | 2 +- spec/features/admin/chapters_spec.rb | 26 +++++++------- spec/support/wait_for_ajax.rb | 15 ++++++++ 6 files changed, 64 insertions(+), 32 deletions(-) create mode 100644 spec/support/wait_for_ajax.rb diff --git a/app/controllers/admin/chapters_controller.rb b/app/controllers/admin/chapters_controller.rb index 88fbe727b..5832e8ad3 100644 --- a/app/controllers/admin/chapters_controller.rb +++ b/app/controllers/admin/chapters_controller.rb @@ -1,5 +1,5 @@ class Admin::ChaptersController < Admin::ApplicationController - before_action :set_chapter, only: %i[show edit update toggle_active] + before_action :set_chapter, only: %i[show edit update update_active] after_action :verify_authorized def index @@ -66,14 +66,12 @@ def members render plain: @emails end - def toggle_active + def update_active authorize @chapter - @chapter.update(active: !@chapter.active) + @chapter.update(update_active_params) - flash[:notice] = t('.message', name: @chapter.name) - - redirect_to admin_chapters_path + head :ok end private @@ -89,4 +87,8 @@ def chapter_params def set_chapter @chapter = Chapter.find(params[:id]) end + + def update_active_params + params.permit(:active) + end end diff --git a/app/policies/chapter_policy.rb b/app/policies/chapter_policy.rb index 403f18a89..36b5126ef 100644 --- a/app/policies/chapter_policy.rb +++ b/app/policies/chapter_policy.rb @@ -3,7 +3,7 @@ def index? show? end - def toggle_active? + def update_active? is_admin_or_organiser? end diff --git a/app/views/admin/chapters/index.html.haml b/app/views/admin/chapters/index.html.haml index 575ab9081..2ea041e43 100644 --- a/app/views/admin/chapters/index.html.haml +++ b/app/views/admin/chapters/index.html.haml @@ -2,31 +2,44 @@ .row %h1 Chapters = link_to t('.view_all_chapters'), admin_chapters_path +   = link_to t('.view_active_chapters'), admin_chapters_path(active: true) +   = link_to t('.view_inactive_chapters'), admin_chapters_path(active: false) .row %hr - .large-3.columns + .large-4.columns Name / City / Slug - .large-3.columns + .large-4.columns Email / Twitter - .large-3.columns + .large-1.columns Active? - .large-3.columns - Actions - @chapters.each do |chapter| .row %hr - .large-3.columns - %p= chapter.name + .large-4.columns + = link_to admin_chapter_path(chapter) do + %p= chapter.name %p= chapter.city %p= chapter.slug - .large-3.columns + .large-4.columns %p= chapter.email %p= chapter.twitter - .large-3.columns - = chapter.active? ? t('.yes') : t('.no') - .large-3.columns - = link_to t('.toggle_link'), toggle_active_admin_chapter_path(chapter), method: :post + .large-1.columns + = check_box_tag :chapter_active, 'true', chapter.active?, class: 'chapter_active', data: { 'chapter-id': chapter.id, } +- content_for :page_footer do + :javascript + $('input.chapter_active').on('change', function() { + let element = $(this); + let active = element.is(':checked'); + let chapterId = $(this).data('chapter-id'); + let url = '/admin/chapters/' + chapterId + '/update_active'; + + $.ajax({ + type: "POST", + url: url, + data: { active: active } + }) + }); diff --git a/config/routes.rb b/config/routes.rb index 5c1f5d455..cef0da092 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -120,7 +120,7 @@ resources :chapters, only: %i[index new create show edit update] do member do - post :toggle_active + post :update_active end get :members diff --git a/spec/features/admin/chapters_spec.rb b/spec/features/admin/chapters_spec.rb index 7c7110951..ecea5295c 100644 --- a/spec/features/admin/chapters_spec.rb +++ b/spec/features/admin/chapters_spec.rb @@ -51,31 +51,29 @@ assert_chapters_exist_on_page(active_chapters) end - scenario 'an admin can toggle the status of the active chapter' do + scenario 'an admin can update the status of the active chapter', js: true do visit admin_chapters_path first_active_chapter = active_chapters.first within(all('.row', text: first_active_chapter.email)[0]) do - click_link 'Toggle Active Status' + set_chapter_active_checkbox(first_active_chapter.id, false) end - expect(page).to have_content( - "Successfully toggled active status for #{first_active_chapter.name}" - ) + wait_for_ajax + expect(first_active_chapter.reload).not_to be_active end - scenario 'an admin can toggle the status of the inactive chapter' do + scenario 'an admin can update the status of the inactive chapter', js: true do visit admin_chapters_path first_inactive_chapter = inactive_chapters.first within(all('.row', text: first_inactive_chapter.email)[0]) do - click_link 'Toggle Active Status' + set_chapter_active_checkbox(first_inactive_chapter.id, true) end - expect(page).to have_content( - "Successfully toggled active status for #{first_inactive_chapter.name}" - ) + wait_for_ajax + expect(first_inactive_chapter.reload).to be_active end end @@ -193,7 +191,7 @@ def assert_chapters_exist_on_page(chapters) chapters.each do |chapter| - expect(page).to have_content(chapter.name) + expect(page).to have_link(chapter.name) expect(page).to have_content(chapter.city) expect(page).to have_content(chapter.slug) expect(page).to have_content(chapter.email) @@ -203,11 +201,15 @@ def assert_chapters_exist_on_page(chapters) def assert_chapters_not_exist_on_page(chapters) chapters.each do |chapter| - expect(page).not_to have_content(chapter.name) + expect(page).not_to have_link(chapter.name) expect(page).not_to have_content(chapter.city) expect(page).not_to have_content(chapter.slug) expect(page).not_to have_content(chapter.email) expect(page).not_to have_content(chapter.twitter) end end + + def set_chapter_active_checkbox(id, value) + find("input[data-chapter-id='#{id}']").set(value) + end end diff --git a/spec/support/wait_for_ajax.rb b/spec/support/wait_for_ajax.rb new file mode 100644 index 000000000..3e84d42f5 --- /dev/null +++ b/spec/support/wait_for_ajax.rb @@ -0,0 +1,15 @@ +module WaitForAjax + def wait_for_ajax + Timeout.timeout(Capybara.default_max_wait_time) do + loop until finished_all_ajax_requests? + end + end + + def finished_all_ajax_requests? + page.evaluate_script('jQuery.active').zero? + end +end + +RSpec.configure do |config| + config.include WaitForAjax, type: :feature +end From 91c732db8913a3cc47c6ddbf363486744793194c Mon Sep 17 00:00:00 2001 From: Yih Yang Date: Sun, 17 May 2020 23:30:10 +0800 Subject: [PATCH 7/8] updated grammatical mistakes --- spec/features/admin/chapters_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/features/admin/chapters_spec.rb b/spec/features/admin/chapters_spec.rb index ecea5295c..58a1b018c 100644 --- a/spec/features/admin/chapters_spec.rb +++ b/spec/features/admin/chapters_spec.rb @@ -27,7 +27,7 @@ assert_chapters_exist_on_page(inactive_chapters) end - scenario 'an admin can filter and view only active chapters' do + scenario 'an admin can filter to view only active chapters' do visit admin_chapters_path click_link 'View Active Chapters' @@ -35,7 +35,7 @@ assert_chapters_not_exist_on_page(inactive_chapters) end - scenario 'an admin can filter and view only inactive chapters' do + scenario 'an admin can filter to view only inactive chapters' do visit admin_chapters_path click_link 'View Inactive Chapters' @@ -43,7 +43,7 @@ assert_chapters_not_exist_on_page(active_chapters) end - scenario 'an admin can filter and view all chapters' do + scenario 'an admin can filter to view all chapters' do visit admin_chapters_path click_link 'View All Chapters' From f907ab9e21e4092833a2ef7a367223b76dad8e96 Mon Sep 17 00:00:00 2001 From: Yih Yang Date: Mon, 18 May 2020 02:14:37 +0800 Subject: [PATCH 8/8] updated format, changed page to show confirmation on active change --- app/controllers/admin/chapters_controller.rb | 33 ++++++++--------- app/views/admin/chapters/index.html.haml | 37 ++++++++++++++------ config/locales/en.yml | 2 ++ config/routes.rb | 4 --- spec/features/admin/chapters_spec.rb | 6 +++- 5 files changed, 48 insertions(+), 34 deletions(-) diff --git a/app/controllers/admin/chapters_controller.rb b/app/controllers/admin/chapters_controller.rb index 5832e8ad3..9c97afb15 100644 --- a/app/controllers/admin/chapters_controller.rb +++ b/app/controllers/admin/chapters_controller.rb @@ -43,12 +43,21 @@ def edit def update authorize(@chapter) - if @chapter.update(chapter_params) - flash[:notice] = "Chapter #{@chapter.name} has been successfully updated" - redirect_to [:admin, @chapter] - else - flash[:notice] = @chapter.errors.full_messages - render 'edit' + respond_to do |format| + format.json do + @chapter.update(chapter_params) + + head :ok + end + format.html do + if @chapter.update(chapter_params) + flash[:notice] = "Chapter #{@chapter.name} has been successfully updated" + return redirect_to [:admin, @chapter] + end + + flash[:notice] = @chapter.errors.full_messages + render 'edit' + end end end @@ -66,14 +75,6 @@ def members render plain: @emails end - def update_active - authorize @chapter - - @chapter.update(update_active_params) - - head :ok - end - private def chapter_index_params @@ -87,8 +88,4 @@ def chapter_params def set_chapter @chapter = Chapter.find(params[:id]) end - - def update_active_params - params.permit(:active) - end end diff --git a/app/views/admin/chapters/index.html.haml b/app/views/admin/chapters/index.html.haml index 2ea041e43..479291bef 100644 --- a/app/views/admin/chapters/index.html.haml +++ b/app/views/admin/chapters/index.html.haml @@ -1,13 +1,15 @@ %section#banner .row - %h1 Chapters - = link_to t('.view_all_chapters'), admin_chapters_path -   - = link_to t('.view_active_chapters'), admin_chapters_path(active: true) -   - = link_to t('.view_inactive_chapters'), admin_chapters_path(active: false) + .large-12.columns + %h1 Chapters + = link_to t('.view_all_chapters'), admin_chapters_path +   + = link_to t('.view_active_chapters'), admin_chapters_path(active: true) +   + = link_to t('.view_inactive_chapters'), admin_chapters_path(active: false) .row - %hr + .large-12.columns + %hr .large-4.columns Name / City / Slug .large-4.columns @@ -31,15 +33,28 @@ - content_for :page_footer do :javascript + $('input.chapter_active').on('click', function() { + let active = $(this).is(':checked'); + let message = "#{t('.change_chapter_to_inactive_confirmation')}"; + + if (active) { + message = "#{t('.change_chapter_to_active_confirmation')}"; + } + + if (!confirm(message)) { + return false; + } + }); + $('input.chapter_active').on('change', function() { let element = $(this); + let chapterId = element.data('chapter-id'); let active = element.is(':checked'); - let chapterId = $(this).data('chapter-id'); - let url = '/admin/chapters/' + chapterId + '/update_active'; + let url = '/admin/chapters/' + chapterId; $.ajax({ - type: "POST", + type: "PUT", url: url, - data: { active: active } + data: { chapter: { active: active } } }) }); diff --git a/config/locales/en.yml b/config/locales/en.yml index 33f08662e..6a536e8bb 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -553,6 +553,8 @@ en: index: 'yes': 'Yes' 'no': 'No' + change_chapter_to_active_confirmation: 'Are you sure you want to make this chapter active?' + change_chapter_to_inactive_confirmation: 'Are you sure you want to make this chapter inactive?' toggle_link: 'Toggle Active Status' view_all_chapters: 'View All Chapters' view_active_chapters: 'View Active Chapters' diff --git a/config/routes.rb b/config/routes.rb index cef0da092..3a4b7e46f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -119,10 +119,6 @@ resources :member_notes, only: [:create] resources :chapters, only: %i[index new create show edit update] do - member do - post :update_active - end - get :members resources :workshops, only: [:index] resources :feedback, only: [:index], controller: 'chapters/feedback' diff --git a/spec/features/admin/chapters_spec.rb b/spec/features/admin/chapters_spec.rb index 58a1b018c..0903114e5 100644 --- a/spec/features/admin/chapters_spec.rb +++ b/spec/features/admin/chapters_spec.rb @@ -20,7 +20,7 @@ background { login_as_admin(member) } - scenario "an admin can view all chapters and it's information" do + scenario "an admin can view all chapters and their information" do visit admin_chapters_path assert_chapters_exist_on_page(active_chapters) @@ -59,6 +59,8 @@ set_chapter_active_checkbox(first_active_chapter.id, false) end + page.accept_alert + wait_for_ajax expect(first_active_chapter.reload).not_to be_active @@ -72,6 +74,8 @@ set_chapter_active_checkbox(first_inactive_chapter.id, true) end + page.accept_alert + wait_for_ajax expect(first_inactive_chapter.reload).to be_active